Hi, I'm Mitsuo.

I found a problem that causes net-snmp to respond
IF-MIB::ifPhysAddress with wrong value.

More specifically 1st octet of MAC addres(00:xx:xx:xx:xx:xx)
bacomes always 00.

My environment is NetBSD 3 on Virtualbox.
Though I use the net-snmp 5.6.1.1 on it, as far as I take a look
the latest one it seems to have a same problem.

A patch for fixing this is below.

|
|struct sockaddr_dl {
|       u_char      sdl_len;    /* Total length of sockaddr */
|       sa_family_t sdl_family; /* AF_LINK */
|       u_int16_t   sdl_index;  /* if != 0, system given index for interface */
|       u_char      sdl_type;   /* interface type */
|       u_char      sdl_nlen;   /* interface name length, no trailing 0 reqd. */
|       u_char      sdl_alen;   /* link level address length */
|       u_char      sdl_slen;   /* link layer selector length */
|       char        sdl_data[24]; /* minimum work area, can be larger;
|                                    contains both if name and ll address */
|};
|

The sdl_data contains both if name and ll address so filling \0
isn't right.

Regards,

--
Kuroishi Mitsuo



Index: agent/mibgroup/if-mib/data_access/interface_sysctl.c
===================================================================
--- agent/mibgroup/if-mib/data_access/interface_sysctl.c
+++ agent/mibgroup/if-mib/data_access/interface_sysctl.c
@@ -325,7 +325,7 @@
     struct sockaddr *a;
     struct sockaddr_dl *adl;
     int amask;
-    char *if_name;
+    char if_name[64];
     int flags;
 
     DEBUGMSGTL(("access:interface:container:sysctl",
@@ -363,7 +363,6 @@
     for (cp = if_list; cp < if_list + if_list_size; cp += ifp->ifm_msglen) {
 
         ifp = (struct if_msghdr *) cp;
-        if_name = NULL;
         flags = 0;
         adl = NULL;
 
@@ -386,8 +385,13 @@
                 }
             }
             adl = (struct sockaddr_dl *) a;
-            if_name = (char *) adl->sdl_data;
-            if_name[adl->sdl_nlen] = '\0';
+
+           if (sizeof(if_name) < adl->sdl_nlen + 1) {
+                snmp_log(LOG_ERR, "no space for interface name"
+                                   "(sdl_nlen: %lu bytes)\n", adl->sdl_nlen);
+                return -3;
+           }
+            snprintf(if_name, adl->sdl_nlen + 1, "%s", adl->sdl_data);
         }
         if (!(ifp->ifm_addrs & RTA_IFP) || if_name == NULL) {
             snmp_log(LOG_ERR, "ifm_index %u: no interface name
                 in message, "

------------------------------------------------------------------------------
_______________________________________________
Net-snmp-users mailing list
Net-snmp-users@lists.sourceforge.net
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users

Reply via email to