[netmagis] Re: Search on MAC address

  • From: Benoit Mandy <Benoit.Mandy@xxxxxxxxxxxxxx>
  • To: netmagis@xxxxxxxxxxxxx
  • Date: Fri, 20 Apr 2012 10:55:01 +0200

We need to search by MAC Address. An issue was created. that's great.
Just for information, my patches for doing that.
Benoit Mandy


Le 17/04/2012 22:35, Jean Benoit a écrit :
MAC Address search  :

I think you are refering to the "Search" option in
the menu. Yes, it can be done (search on MAC address).
I created an issue      (https://github.com/pdav/netmagis/issues/61)

DNS views :

You are correct concerning the role of field "critère"
Its purpose is to select records to include in a zone.
For normal zones, it selects the matching domain name.
For reverse zones, it selects IP addresses matching a CIDR.
In theory, it could be used to select hosts belonging to a particular view.
(https://github.com/pdav/netmagis/issues/62)

--
Jean Benoit


*** libnetmagis.tcl.p1  2012-03-23 15:25:13.000000000 +0100
--- libnetmagis.tcl     2012-04-20 10:25:23.330247637 +0200
*************** proc read-rr-by-ip {dbfd addr _trr} {
*** 2658,2663 ****
--- 2658,2697 ----
  }
  
  #
+ # Get all informations associated with a RR given by the MAC Address
+ #
+ # Input:
+ #   - parameters:
+ #       - dbfd : database handle
+ #       - addr : address to search for
+ #       - _trr : empty array
+ # Output:
+ #   - return value: 1 if ok, 0 if not found
+ #   - _trr parameter : see read-rr-by-id
+ #
+ # Note: the given address is supposed to be syntaxically correct.
+ #
+ # History
+ #
+ 
+ proc read-rr-by-mac {dbfd addr _trr} {
+     upvar $_trr trr
+ 
+     set found 0
+     set sql "SELECT idrr FROM dns.rr WHERE mac = '$addr'"
+     pg_select $dbfd $sql tab {
+         set found 1
+         set idrr $tab(idrr)
+     }
+ 
+     if {$found} then {
+         set found [read-rr-by-id $dbfd $idrr trr]
+     }
+ 
+     return $found
+ }
+ 
+ #
  # Get all informations associated with a RR.
  #
  # Input:
*** search.orig 2012-02-10 10:56:39.197201935 +0100
--- search      2012-04-20 10:39:48.509688701 +0200
*************** d cgi-register {crit .+} {} {
*** 218,224 ****
      # Is criterion an IP address, a host name, anything else?
      #
  
!     if {[check-ip-syntax $dbfd $crit "inet"] eq ""} then {
        #
        # IP address
        #
--- 218,239 ----
      # Is criterion an IP address, a host name, anything else?
      #
  
!     if {[check-mac-syntax $dbfd $crit] eq ""} then {
!         #
!         # MAC address
!         #
!         # set addr $crit
!       set addr ""
! 
!         #
!         # Attempt to search for the host. It if exists, trr will
!         # be filled. If it does not exists, trr will not be created.
!         # We don't test result, since existence of trr(idrr) will
!         # suffice for next steps.
!         #
!         read-rr-by-mac $dbfd $crit trr
! 
!     } elseif {[check-ip-syntax $dbfd $crit "inet"] eq ""} then {
        #
        # IP address
        #

Other related posts: