From 994710f1ae309334ef368e7af0f919fbb1b44592 Mon Sep 17 00:00:00 2001 From: glebius Date: Thu, 25 Apr 2013 16:23:22 +0000 Subject: [PATCH] Restore the ipNetToMedia MIB, that was broken with new ARP commit in the r186119. Submitted by: Konstantin Kukushkin --- contrib/bsnmp/snmp_mibII/mibII.c | 45 ++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/contrib/bsnmp/snmp_mibII/mibII.c b/contrib/bsnmp/snmp_mibII/mibII.c index 27ebeded6a1f..d3fe27a8ac3c 100644 --- a/contrib/bsnmp/snmp_mibII/mibII.c +++ b/contrib/bsnmp/snmp_mibII/mibII.c @@ -933,6 +933,34 @@ mib_find_ifa(struct in_addr addr) return (NULL); } +/* + * Process a new ARP entry + */ +static void +process_arp(const struct rt_msghdr *rtm, const struct sockaddr_dl *sdl, + const struct sockaddr_in *sa) +{ + struct mibif *ifp; + struct mibarp *at; + + /* IP arp table entry */ + if (sdl->sdl_alen == 0) + return; + if ((ifp = mib_find_if_sys(sdl->sdl_index)) == NULL) + return; + /* have a valid entry */ + if ((at = mib_find_arp(ifp, sa->sin_addr)) == NULL && + (at = mib_arp_create(ifp, sa->sin_addr, + sdl->sdl_data + sdl->sdl_nlen, sdl->sdl_alen)) == NULL) + return; + + if (rtm->rtm_rmx.rmx_expire == 0) + at->flags |= MIBARP_PERM; + else + at->flags &= ~MIBARP_PERM; + at->flags |= MIBARP_FOUND; +} + /* * Handle a routing socket message. */ @@ -1075,6 +1103,23 @@ handle_rtmsg(struct rt_msghdr *rtm) #endif case RTM_GET: case RTM_ADD: + mib_extract_addrs(rtm->rtm_addrs, (u_char *)(rtm + 1), addrs); + if (rtm->rtm_flags & RTF_LLINFO) { + if (addrs[RTAX_DST] == NULL || + addrs[RTAX_GATEWAY] == NULL || + addrs[RTAX_DST]->sa_family != AF_INET || + addrs[RTAX_GATEWAY]->sa_family != AF_LINK) + break; + process_arp(rtm, + (struct sockaddr_dl *)(void *)addrs[RTAX_GATEWAY], + (struct sockaddr_in *)(void *)addrs[RTAX_DST]); + } else { + if (rtm->rtm_errno == 0 && (rtm->rtm_flags & RTF_UP)) + mib_sroute_process(rtm, addrs[RTAX_GATEWAY], + addrs[RTAX_DST], addrs[RTAX_NETMASK]); + } + break; + case RTM_DELETE: mib_extract_addrs(rtm->rtm_addrs, (u_char *)(rtm + 1), addrs);