summaryrefslogtreecommitdiffstats
path: root/contrib/bsnmp/snmp_mibII
diff options
context:
space:
mode:
authorharti <harti@FreeBSD.org>2005-10-04 14:41:06 +0000
committerharti <harti@FreeBSD.org>2005-10-04 14:41:06 +0000
commitefb2dfa1774240830b3f74b7fe4ab8050cc1cda0 (patch)
tree939b9a00cfa4d79510a088859c9352b689740218 /contrib/bsnmp/snmp_mibII
parent2b366eef52ee173d11c8c3b0570cd771e5c0044a (diff)
downloadFreeBSD-src-efb2dfa1774240830b3f74b7fe4ab8050cc1cda0.zip
FreeBSD-src-efb2dfa1774240830b3f74b7fe4ab8050cc1cda0.tar.gz
Virgin import of bsnmpd 1.11
Diffstat (limited to 'contrib/bsnmp/snmp_mibII')
-rw-r--r--contrib/bsnmp/snmp_mibII/mibII.c67
-rw-r--r--contrib/bsnmp/snmp_mibII/mibII.h13
-rw-r--r--contrib/bsnmp/snmp_mibII/mibII_ipaddr.c11
-rw-r--r--contrib/bsnmp/snmp_mibII/mibII_route.c428
-rw-r--r--contrib/bsnmp/snmp_mibII/snmp_mibII.396
5 files changed, 462 insertions, 153 deletions
diff --git a/contrib/bsnmp/snmp_mibII/mibII.c b/contrib/bsnmp/snmp_mibII/mibII.c
index 7de7fbe..2f7881f 100644
--- a/contrib/bsnmp/snmp_mibII/mibII.c
+++ b/contrib/bsnmp/snmp_mibII/mibII.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Begemot: bsnmp/snmp_mibII/mibII.c,v 1.22 2005/05/23 09:03:37 brandt_h Exp $
+ * $Begemot: bsnmp/snmp_mibII/mibII.c,v 1.23 2005/06/09 12:36:52 brandt_h Exp $
*
* Implementation of the standard interfaces and ip MIB.
*/
@@ -941,6 +941,10 @@ handle_rtmsg(struct rt_msghdr *rtm)
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;
@@ -955,9 +959,68 @@ handle_rtmsg(struct rt_msghdr *rtm)
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);
+ if (rtm->rtm_errno == 0 && !(rtm->rtm_flags & RTF_LLINFO))
+ mib_sroute_process(rtm, addrs[RTAX_GATEWAY],
+ addrs[RTAX_DST], addrs[RTAX_NETMASK]);
+ break;
+ }
+}
+
+/*
+ * send a routing message
+ */
+void
+mib_send_rtmsg(struct rt_msghdr *rtm, struct sockaddr *gw,
+ struct sockaddr *dst, struct sockaddr *mask)
+{
+ size_t len;
+ struct rt_msghdr *msg;
+ char *cp;
+ ssize_t sent;
+
+ len = sizeof(*rtm) + SA_SIZE(gw) + SA_SIZE(dst) + SA_SIZE(mask);
+ if ((msg = malloc(len)) == NULL) {
+ syslog(LOG_ERR, "%s: %m", __func__);
+ return;
+ }
+ cp = (char *)(msg + 1);
+
+ memset(msg, 0, sizeof(*msg));
+ msg->rtm_flags = 0;
+ msg->rtm_version = RTM_VERSION;
+ msg->rtm_addrs = RTA_DST | RTA_GATEWAY;
+
+ memcpy(cp, dst, SA_SIZE(dst));
+ cp += SA_SIZE(dst);
+ memcpy(cp, gw, SA_SIZE(gw));
+ cp += SA_SIZE(gw);
+ if (mask != NULL) {
+ memcpy(cp, mask, SA_SIZE(mask));
+ cp += SA_SIZE(mask);
+ msg->rtm_addrs |= RTA_NETMASK;
+ }
+ msg->rtm_msglen = cp - (char *)msg;
+ msg->rtm_type = RTM_GET;
+ if ((sent = write(route, msg, msg->rtm_msglen)) == -1) {
+ syslog(LOG_ERR, "%s: write: %m", __func__);
+ free(msg);
+ return;
+ }
+ if (sent != msg->rtm_msglen) {
+ syslog(LOG_ERR, "%s: short write", __func__);
+ free(msg);
+ return;
}
+ free(msg);
}
/*
@@ -1428,6 +1491,7 @@ mibII_start(void)
mib_refresh_iflist();
update_ifa_info();
mib_arp_update();
+ (void)mib_fetch_route();
mib_iftable_last_change = 0;
mib_ifstack_last_change = 0;
@@ -1474,7 +1538,6 @@ mibII_init(struct lmodule *mod, int argc __unused, char *argv[] __unused)
syslog(LOG_ERR, "PF_ROUTE: %m");
return (-1);
}
- (void)shutdown(route, SHUT_WR);
if ((mib_netsock = socket(PF_INET, SOCK_DGRAM, 0)) == -1) {
syslog(LOG_ERR, "PF_INET: %m");
diff --git a/contrib/bsnmp/snmp_mibII/mibII.h b/contrib/bsnmp/snmp_mibII/mibII.h
index 7a83df4..4b0803d 100644
--- a/contrib/bsnmp/snmp_mibII/mibII.h
+++ b/contrib/bsnmp/snmp_mibII/mibII.h
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Begemot: bsnmp/snmp_mibII/mibII.h,v 1.14 2005/05/23 09:03:38 brandt_h Exp $
+ * $Begemot: bsnmp/snmp_mibII/mibII.h,v 1.15 2005/06/09 12:36:53 brandt_h Exp $
*
* Implementation of the interfaces and IP groups of MIB-II.
*/
@@ -230,5 +230,16 @@ void mib_arp_update(void);
/* fetch routing table */
u_char *mib_fetch_rtab(int af, int info, int arg, size_t *lenp);
+/* process routing message */
+void mib_sroute_process(struct rt_msghdr *, struct sockaddr *,
+ struct sockaddr *, struct sockaddr *);
+
+/* send a routing message */
+void mib_send_rtmsg(struct rt_msghdr *, struct sockaddr *,
+ struct sockaddr *, struct sockaddr *);
+
/* extract addresses from routing message */
void mib_extract_addrs(int, u_char *, struct sockaddr **);
+
+/* fetch routing table */
+int mib_fetch_route(void);
diff --git a/contrib/bsnmp/snmp_mibII/mibII_ipaddr.c b/contrib/bsnmp/snmp_mibII/mibII_ipaddr.c
index 6ed449f..d1821ec 100644
--- a/contrib/bsnmp/snmp_mibII/mibII_ipaddr.c
+++ b/contrib/bsnmp/snmp_mibII/mibII_ipaddr.c
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Begemot: bsnmp/snmp_mibII/mibII_ipaddr.c,v 1.9 2004/08/06 08:47:02 brandt Exp $
+ * $Begemot: bsnmp/snmp_mibII/mibII_ipaddr.c,v 1.10 2005/10/04 11:21:35 brandt_h Exp $
*
* IP address table. This table is writeable!
*
@@ -84,10 +84,13 @@ create(struct update *upd)
}
bcast.s_addr = upd->addr.s_addr & upd->mask.s_addr;
- if (!(upd->set & UPD_BCAST) || upd->bcast)
- bcast.s_addr |= htonl(0xffffffff & ~ntohl(upd->mask.s_addr));
+ if (!(upd->set & UPD_BCAST) || upd->bcast) {
+ uint32_t tmp = ~ntohl(upd->mask.s_addr);
+ bcast.s_addr |= htonl(0xffffffff & ~tmp);
+ }
- if ((ifa = mib_create_ifa(upd->ifindex, upd->addr, upd->mask, bcast)) == NULL)
+ if ((ifa = mib_create_ifa(upd->ifindex, upd->addr, upd->mask, bcast))
+ == NULL)
return (SNMP_ERR_GENERR);
upd->rb |= RB_CREATE;
diff --git a/contrib/bsnmp/snmp_mibII/mibII_route.c b/contrib/bsnmp/snmp_mibII/mibII_route.c
index 9375be3..feb33c9 100644
--- a/contrib/bsnmp/snmp_mibII/mibII_route.c
+++ b/contrib/bsnmp/snmp_mibII/mibII_route.c
@@ -26,41 +26,218 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Begemot: bsnmp/snmp_mibII/mibII_route.c,v 1.6 2005/05/23 09:03:41 brandt_h Exp $
+ * $Begemot: bsnmp/snmp_mibII/mibII_route.c,v 1.7 2005/06/09 12:36:53 brandt_h Exp $
*
* Routing table
*/
+#include <sys/tree.h>
#include "mibII.h"
#include "mibII_oid.h"
struct sroute {
- TAILQ_ENTRY(sroute) link;
- struct asn_oid index;
- u_int ifindex;
- u_int type;
- u_int proto;
+ RB_ENTRY(sroute) link;
+ uint32_t ifindex;
+ uint8_t index[13];
+ uint8_t type;
+ uint8_t proto;
};
-static TAILQ_HEAD(, sroute) sroute_list = TAILQ_HEAD_INITIALIZER(sroute_list);
+RB_HEAD(sroutes, sroute) sroutes = RB_INITIALIZER(&sroutes);
+RB_PROTOTYPE(sroutes, sroute, link, sroute_compare);
+
+#define ROUTE_UPDATE_INTERVAL (100 * 60 * 10) /* 10 min */
static uint64_t route_tick;
static u_int route_total;
+/*
+ * Compare two routes
+ */
static int
-fetch_route(void)
+sroute_compare(struct sroute *s1, struct sroute *s2)
+{
+
+ return (memcmp(s1->index, s2->index, 13));
+}
+
+static void
+sroute_index_append(struct asn_oid *oid, u_int sub, const struct sroute *s)
+{
+ int i;
+
+ oid->len = sub + 13;
+ for (i = 0; i < 13; i++)
+ oid->subs[sub + i] = s->index[i];
+}
+
+#if 0
+static void
+sroute_print(const struct sroute *r)
+{
+ u_int i;
+
+ for (i = 0; i < 13 - 1; i++)
+ printf("%u.", r->index[i]);
+ printf("%u proto=%u type=%u", r->index[i], r->proto, r->type);
+}
+#endif
+
+/*
+ * process routing message
+ */
+void
+mib_sroute_process(struct rt_msghdr *rtm, struct sockaddr *gw,
+ struct sockaddr *dst, struct sockaddr *mask)
+{
+ struct sockaddr_in *in_dst, *in_gw;
+ struct in_addr in_mask;
+ struct mibif *ifp;
+ struct sroute key;
+ struct sroute *r, *r1;
+ in_addr_t ha;
+
+ if (dst == NULL || gw == NULL || dst->sa_family != AF_INET ||
+ gw->sa_family != AF_INET)
+ return;
+
+ in_dst = (struct sockaddr_in *)(void *)dst;
+ in_gw = (struct sockaddr_in *)(void *)gw;
+
+ if (rtm->rtm_flags & RTF_HOST)
+ in_mask.s_addr = 0xffffffff;
+ else if (mask == NULL || mask->sa_len == 0)
+ in_mask.s_addr = 0;
+ else
+ in_mask = ((struct sockaddr_in *)(void *)mask)->sin_addr;
+
+ /* build the index */
+ ha = ntohl(in_dst->sin_addr.s_addr);
+ key.index[0] = (ha >> 24) & 0xff;
+ key.index[1] = (ha >> 16) & 0xff;
+ key.index[2] = (ha >> 8) & 0xff;
+ key.index[3] = (ha >> 0) & 0xff;
+
+ ha = ntohl(in_mask.s_addr);
+ key.index[4] = (ha >> 24) & 0xff;
+ key.index[5] = (ha >> 16) & 0xff;
+ key.index[6] = (ha >> 8) & 0xff;
+ key.index[7] = (ha >> 0) & 0xff;
+
+ /* ToS */
+ key.index[8] = 0;
+
+ ha = ntohl(in_gw->sin_addr.s_addr);
+ key.index[9] = (ha >> 24) & 0xff;
+ key.index[10] = (ha >> 16) & 0xff;
+ key.index[11] = (ha >> 8) & 0xff;
+ key.index[12] = (ha >> 0) & 0xff;
+
+ if (rtm->rtm_type == RTM_DELETE) {
+ r = RB_FIND(sroutes, &sroutes, &key);
+ if (r == 0) {
+#ifdef DEBUG_ROUTE
+ syslog(LOG_WARNING, "%s: DELETE: %u.%u.%u.%u "
+ "%u.%u.%u.%u %u %u.%u.%u.%u not found", __func__,
+ key.index[0], key.index[1], key.index[2],
+ key.index[3], key.index[4], key.index[5],
+ key.index[6], key.index[7], key.index[8],
+ key.index[9], key.index[10], key.index[11],
+ key.index[12]);
+#endif
+ return;
+ }
+ RB_REMOVE(sroutes, &sroutes, r);
+ free(r);
+ route_total--;
+#ifdef DEBUG_ROUTE
+ printf("%s: DELETE: %u.%u.%u.%u "
+ "%u.%u.%u.%u %u %u.%u.%u.%u\n", __func__,
+ key.index[0], key.index[1], key.index[2],
+ key.index[3], key.index[4], key.index[5],
+ key.index[6], key.index[7], key.index[8],
+ key.index[9], key.index[10], key.index[11],
+ key.index[12]);
+#endif
+ return;
+ }
+
+ /* GET or ADD */
+ ifp = NULL;
+ if ((ifp = mib_find_if_sys(rtm->rtm_index)) == NULL) {
+ if (rtm->rtm_type == RTM_ADD) {
+ /* make it a get so the kernel fills the index */
+ mib_send_rtmsg(rtm, gw, dst, mask);
+ return;
+ }
+ mib_iflist_bad = 1;
+ }
+
+ if ((r = malloc(sizeof(*r))) == NULL) {
+ syslog(LOG_ERR, "%m");
+ return;
+ }
+
+ memcpy(r->index, key.index, sizeof(r->index));
+ r->ifindex = (ifp == NULL) ? 0 : ifp->index;
+
+ r->type = (rtm->rtm_flags & RTF_LLINFO) ? 3 :
+ (rtm->rtm_flags & RTF_REJECT) ? 2 : 4;
+
+ /* cannot really know, what protocol it runs */
+ r->proto = (rtm->rtm_flags & RTF_LOCAL) ? 2 :
+ (rtm->rtm_flags & RTF_STATIC) ? 3 :
+ (rtm->rtm_flags & RTF_DYNAMIC) ? 4 : 10;
+
+ r1 = RB_INSERT(sroutes, &sroutes, r);
+ if (r1 != NULL) {
+#ifdef DEBUG_ROUTE
+ syslog(LOG_WARNING, "%s: %u.%u.%u.%u "
+ "%u.%u.%u.%u %u %u.%u.%u.%u duplicate route", __func__,
+ key.index[0], key.index[1], key.index[2],
+ key.index[3], key.index[4], key.index[5],
+ key.index[6], key.index[7], key.index[8],
+ key.index[9], key.index[10], key.index[11],
+ key.index[12]);
+#endif
+ r1->ifindex = r->ifindex;
+ r1->type = r->type;
+ r1->proto = r->proto;
+ free(r);
+ return;
+ }
+
+ route_total++;
+#ifdef DEBUG_ROUTE
+ printf("%s: ADD/GET: %u.%u.%u.%u "
+ "%u.%u.%u.%u %u %u.%u.%u.%u\n", __func__,
+ key.index[0], key.index[1], key.index[2],
+ key.index[3], key.index[4], key.index[5],
+ key.index[6], key.index[7], key.index[8],
+ key.index[9], key.index[10], key.index[11],
+ key.index[12]);
+#endif
+}
+
+int
+mib_fetch_route(void)
{
u_char *rtab, *next;
size_t len;
- struct sroute *r;
+ struct sroute *r, *r1;
struct rt_msghdr *rtm;
struct sockaddr *addrs[RTAX_MAX];
- struct sockaddr_in *sa, *gw;
- struct in_addr mask, nhop;
- in_addr_t ha;
- struct mibif *ifp;
- while ((r = TAILQ_FIRST(&sroute_list)) != NULL) {
- TAILQ_REMOVE(&sroute_list, r, link);
+ if (route_tick != 0 && route_tick + ROUTE_UPDATE_INTERVAL > this_tick)
+ return (0);
+
+ /*
+ * Remove all routes
+ */
+ r = RB_MIN(sroutes, &sroutes);
+ while (r != NULL) {
+ r1 = RB_NEXT(sroutes, &sroutes, r);
+ RB_REMOVE(sroutes, &sroutes, r);
free(r);
+ r = r1;
}
route_total = 0;
@@ -75,81 +252,118 @@ fetch_route(void)
continue;
mib_extract_addrs(rtm->rtm_addrs, (u_char *)(rtm + 1), addrs);
- if (addrs[RTAX_DST] == NULL || addrs[RTAX_GATEWAY] == NULL ||
- addrs[RTAX_DST]->sa_family != AF_INET)
- continue;
-
- sa = (struct sockaddr_in *)(void *)addrs[RTAX_DST];
-
- if (rtm->rtm_flags & RTF_HOST) {
- mask.s_addr = 0xffffffff;
- } else {
- if (addrs[RTAX_NETMASK] == NULL ||
- addrs[RTAX_NETMASK]->sa_len == 0)
- mask.s_addr = 0;
- else
- mask = ((struct sockaddr_in *)(void *)
- addrs[RTAX_NETMASK])->sin_addr;
- }
- if (addrs[RTAX_GATEWAY] == NULL) {
- nhop.s_addr = 0;
- } else if (rtm->rtm_flags & RTF_LLINFO) {
- nhop = sa->sin_addr;
- } else {
- gw = (struct sockaddr_in *)(void *)addrs[RTAX_GATEWAY];
- if (gw->sin_family != AF_INET)
- continue;
- nhop = gw->sin_addr;
- }
- if ((ifp = mib_find_if_sys(rtm->rtm_index)) == NULL) {
- mib_iflist_bad = 1;
- continue;
- }
-
- if ((r = malloc(sizeof(*r))) == NULL) {
- syslog(LOG_ERR, "%m");
- continue;
- }
-
- route_total++;
+
+ mib_sroute_process(rtm, addrs[RTAX_GATEWAY], addrs[RTAX_DST],
+ addrs[RTAX_NETMASK]);
+ }
- r->index.len = 13;
- ha = ntohl(sa->sin_addr.s_addr);
- r->index.subs[0] = (ha >> 24) & 0xff;
- r->index.subs[1] = (ha >> 16) & 0xff;
- r->index.subs[2] = (ha >> 8) & 0xff;
- r->index.subs[3] = (ha >> 0) & 0xff;
- ha = ntohl(mask.s_addr);
- r->index.subs[4] = (ha >> 24) & 0xff;
- r->index.subs[5] = (ha >> 16) & 0xff;
- r->index.subs[6] = (ha >> 8) & 0xff;
- r->index.subs[7] = (ha >> 0) & 0xff;
+#if 0
+ u_int n = 0;
+ r = RB_MIN(sroutes, &sroutes);
+ while (r != NULL) {
+ printf("%u: ", n++);
+ sroute_print(r);
+ printf("\n");
+ r = RB_NEXT(sroutes, &sroutes, r);
+ }
+#endif
+ free(rtab);
+ route_tick = get_ticks();
- r->index.subs[8] = 0;
+ return (0);
+}
- ha = ntohl(nhop.s_addr);
- r->index.subs[9] = (ha >> 24) & 0xff;
- r->index.subs[10] = (ha >> 16) & 0xff;
- r->index.subs[11] = (ha >> 8) & 0xff;
- r->index.subs[12] = (ha >> 0) & 0xff;
+/**
+ * Find a route in the table.
+ */
+static struct sroute *
+sroute_get(const struct asn_oid *oid, u_int sub)
+{
+ struct sroute key;
+ int i;
+
+ if (oid->len - sub != 13)
+ return (NULL);
+ for (i = 0; i < 13; i++)
+ key.index[i] = oid->subs[sub + i];
+ return (RB_FIND(sroutes, &sroutes, &key));
+}
- r->ifindex = ifp->index;
+/**
+ * Find next route in the table. There is no such RB_ macro, so must
+ * dig into the innards of the RB stuff.
+ */
+static struct sroute *
+sroute_getnext(struct asn_oid *oid, u_int sub)
+{
+ u_int i;
+ int comp;
+ struct sroute key;
+ struct sroute *best;
+ struct sroute *s;
+
+ /*
+ * We now, that the OID is at least the tableEntry OID. If it is,
+ * the user wants the first route.
+ */
+ if (oid->len == sub)
+ return (RB_MIN(sroutes, &sroutes));
+
+ /*
+ * This is also true for any index that consists of zeros and is
+ * shorter than the full index.
+ */
+ if (oid->len < sub + 13) {
+ for (i = sub; i < oid->len; i++)
+ if (oid->subs[i] != 0)
+ break;
+ if (i == oid->len)
+ return (RB_MIN(sroutes, &sroutes));
+
+ /*
+ * Now if the index is too short, we fill it with zeros and then
+ * subtract one from the index. We can do this, because we now,
+ * that there is at least one index element that is not zero.
+ */
+ for (i = oid->len; i < sub + 13; i++)
+ oid->subs[i] = 0;
+
+ for (i = sub + 13 - 1; i >= sub; i--) {
+ if (oid->subs[i] != 0) {
+ oid->subs[i]--;
+ break;
+ }
+ oid->subs[i] = ASN_MAXID;
+ }
+ oid->len = sub + 13;
+ }
- r->type = (rtm->rtm_flags & RTF_LLINFO) ? 3 :
- (rtm->rtm_flags & RTF_REJECT) ? 2 : 4;
+ /* build the index */
+ for (i = sub; i < sub + 13; i++)
+ key.index[i - sub] = oid->subs[i];
- /* cannot really know, what protocol it runs */
- r->proto = (rtm->rtm_flags & RTF_LOCAL) ? 2 :
- (rtm->rtm_flags & RTF_STATIC) ? 3 :
- (rtm->rtm_flags & RTF_DYNAMIC) ? 4 : 10;
+ /* now find the element */
+ best = NULL;
+ s = RB_ROOT(&sroutes);
- INSERT_OBJECT_OID(r, &sroute_list);
+ while (s != NULL) {
+ comp = sroute_compare(&key, s);
+ if (comp >= 0) {
+ /* The current element is smaller than what we search.
+ * Forget about it and move to the right subtree. */
+ s = RB_RIGHT(s, link);
+ continue;
+ }
+ /* the current element is larger than what we search.
+ * forget about the right subtree (its even larger), but
+ * the current element may be what we need. */
+ if (best == NULL || sroute_compare(s, best) < 0)
+ /* this one's better */
+ best = s;
+
+ s = RB_LEFT(s, link);
}
-
- free(rtab);
- route_tick = get_ticks();
-
- return (0);
+ return (best);
}
/*
@@ -159,28 +373,27 @@ int
op_route_table(struct snmp_context *ctx __unused, struct snmp_value *value,
u_int sub, u_int iidx __unused, enum snmp_op op)
{
- static struct sroute *r;
+ struct sroute *r;
- if (route_tick < this_tick)
- if (fetch_route() == -1)
- return (SNMP_ERR_GENERR);
+ if (mib_fetch_route() == -1)
+ return (SNMP_ERR_GENERR);
switch (op) {
case SNMP_OP_GETNEXT:
- if ((r = NEXT_OBJECT_OID(&sroute_list, &value->var, sub)) == NULL)
+ if ((r = sroute_getnext(&value->var, sub)) == NULL)
return (SNMP_ERR_NOSUCHNAME);
- index_append(&value->var, sub, &r->index);
+ sroute_index_append(&value->var, sub, r);
break;
case SNMP_OP_GET:
- if ((r = FIND_OBJECT_OID(&sroute_list, &value->var, sub)) == NULL)
+ if ((r = sroute_get(&value->var, sub)) == NULL)
return (SNMP_ERR_NOSUCHNAME);
break;
case SNMP_OP_SET:
- if ((r = FIND_OBJECT_OID(&sroute_list, &value->var, sub)) == NULL)
- return (SNMP_ERR_NO_CREATION);
+ if ((r = sroute_get(&value->var, sub)) == NULL)
+ return (SNMP_ERR_NOSUCHNAME);
return (SNMP_ERR_NOT_WRITEABLE);
case SNMP_OP_ROLLBACK:
@@ -194,28 +407,28 @@ op_route_table(struct snmp_context *ctx __unused, struct snmp_value *value,
switch (value->var.subs[sub - 1]) {
case LEAF_ipCidrRouteDest:
- value->v.ipaddress[0] = r->index.subs[0];
- value->v.ipaddress[1] = r->index.subs[1];
- value->v.ipaddress[2] = r->index.subs[2];
- value->v.ipaddress[3] = r->index.subs[3];
+ value->v.ipaddress[0] = r->index[0];
+ value->v.ipaddress[1] = r->index[1];
+ value->v.ipaddress[2] = r->index[2];
+ value->v.ipaddress[3] = r->index[3];
break;
case LEAF_ipCidrRouteMask:
- value->v.ipaddress[0] = r->index.subs[4];
- value->v.ipaddress[1] = r->index.subs[5];
- value->v.ipaddress[2] = r->index.subs[6];
- value->v.ipaddress[3] = r->index.subs[7];
+ value->v.ipaddress[0] = r->index[4];
+ value->v.ipaddress[1] = r->index[5];
+ value->v.ipaddress[2] = r->index[6];
+ value->v.ipaddress[3] = r->index[7];
break;
case LEAF_ipCidrRouteTos:
- value->v.integer = r->index.subs[8];
+ value->v.integer = r->index[8];
break;
case LEAF_ipCidrRouteNextHop:
- value->v.ipaddress[0] = r->index.subs[9];
- value->v.ipaddress[1] = r->index.subs[10];
- value->v.ipaddress[2] = r->index.subs[11];
- value->v.ipaddress[3] = r->index.subs[12];
+ value->v.ipaddress[0] = r->index[9];
+ value->v.ipaddress[1] = r->index[10];
+ value->v.ipaddress[2] = r->index[11];
+ value->v.ipaddress[3] = r->index[12];
break;
case LEAF_ipCidrRouteIfIndex:
@@ -280,9 +493,8 @@ op_route(struct snmp_context *ctx __unused, struct snmp_value *value,
abort();
}
- if (route_tick < this_tick)
- if (fetch_route() == -1)
- return (SNMP_ERR_GENERR);
+ if (mib_fetch_route() == -1)
+ return (SNMP_ERR_GENERR);
switch (value->var.subs[sub - 1]) {
@@ -293,3 +505,5 @@ op_route(struct snmp_context *ctx __unused, struct snmp_value *value,
}
return (SNMP_ERR_NOERROR);
}
+
+RB_GENERATE(sroutes, sroute, link, sroute_compare);
diff --git a/contrib/bsnmp/snmp_mibII/snmp_mibII.3 b/contrib/bsnmp/snmp_mibII/snmp_mibII.3
index 64ce6af..ff05de4 100644
--- a/contrib/bsnmp/snmp_mibII/snmp_mibII.3
+++ b/contrib/bsnmp/snmp_mibII/snmp_mibII.3
@@ -1,4 +1,7 @@
.\"
+.\" Copyright (c) 2004-2005
+.\" Hartmut Brandt
+.\" All rights reserved.
.\" Copyright (c) 2001-2003
.\" Fraunhofer Institute for Open Communication Systems (FhG Fokus).
.\" All rights reserved.
@@ -26,9 +29,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $Begemot: bsnmp/snmp_mibII/snmp_mibII.3,v 1.7 2005/05/23 09:11:21 brandt_h Exp $
+.\" $Begemot: bsnmp/snmp_mibII/snmp_mibII.3,v 1.10 2005/10/04 08:46:52 brandt_h Exp $
.\"
-.Dd May 23, 2005
+.Dd October 4, 2005
.Dt SNMP_MIBII 3
.Os
.Sh NAME
@@ -56,7 +59,7 @@
.Nm mib_rcvaddr_delete ,
.Nm mibif_notify ,
.Nm mibif_unnotify
-.Nd "mib-2 module for snmpd.
+.Nd "mib-2 module for bsnmpd."
.Sh LIBRARY
.Pq begemotSnmpdModulePath."mibII" = "@MODPATH@snmp_mibII.so"
.Sh SYNOPSIS
@@ -110,27 +113,31 @@
.Sh DESCRIPTION
The
.Nm snmp_mibII
-module implements parts of the internet standard MIB-2. Most of the relevant
-MIBs are implemented. Some of the tables are restricted to be read-only
-instead of read-write. The exact current implementation can be found in
+module implements parts of the internet standard MIB-2.
+Most of the relevant MIBs are implemented.
+Some of the tables are restricted to be read-only instead of read-write.
+The exact current implementation can be found in
.Pa @DEFPATH@mibII_tree.def .
The module also exports a number of functions and global variables for use
-by other modules, that need to handle network interfaces. This man page describes
-these functions.
+by other modules, that need to handle network interfaces.
+This man page describes these functions.
.Ss DIRECT NETWORK ACCESS
The
.Nm
module opens a socket that is used to execute all network related
.Xr ioctl 2
-functions. This socket is globally available under the name
+functions.
+This socket is globally available under the name
.Va mib_netsock .
.Ss NETWORK INTERFACES
The
.Nm
-module handles a list of all currently existing network interfaces. It allows
+module handles a list of all currently existing network interfaces.
+It allows
other modules to handle their own interface lists with special information
by providing a mechanism to register to events that change the interface list
-(see below). The basic data structure is the interface structure:
+(see below).
+The basic data structure is the interface structure:
.Bd -literal -offset indent
struct mibif {
TAILQ_ENTRY(mibif) link;
@@ -159,35 +166,39 @@ The
.Nm
module tries to implement the semantic if
.Va ifIndex
-as described in RFC-2863. This RFC states, that an interface indexes may not
-be reused. That means, for example, if
+as described in RFC-2863.
+This RFC states, that an interface indexes may not be reused.
+That means, for example, if
.Pa tun
is a synthetic interface type and the system creates the interface
.Pa tun0 ,
destroys this interfaces and again creates a
.Pa tun 0 ,
then these interfaces must have different interface indexes, because in fact
-they are different interfaces. If, on the other hand, there is a hardware
-interface
+they are different interfaces.
+If, on the other hand, there is a hardware interface
.Pa xl0
and this interface disappears, because its driver is unloaded and appears
again, because the driver is loaded again, the interface index must stay
the same.
.Nm
implements this by differentiating between real and synthetic (dynamic)
-interfaces. An interface type can be declared dynamic by calling the function
+interfaces.
+An interface type can be declared dynamic by calling the function
.Fn mib_if_set_dyn
with the name if the interface type (for example
.Qq tun ).
For real interfaces, the module keeps the mapping between the interface name
and its
.Va ifIndex
-in a special list, if the interface is unloaded. For dynamic interfaces
+in a special list, if the interface is unloaded.
+For dynamic interfaces
a new
.Va ifIndex
-is generated each time the interface comes into existance. This
-means, that the interface index as seen by SNMP is not the same index
-as used by the system. The SNMP
+is generated each time the interface comes into existence.
+This means, that the interface index as seen by SNMP is not the same index
+as used by the system.
+The SNMP
.Va ifIndex
is held in field
.Va index ,
@@ -212,8 +223,8 @@ finds an interface by searching for an SNMP
.Fn mib_find_if_sys
finds an interface by searching for a system interface index and
.Fn mib_find_if_name
-finds an interface by looking for an interface name. Each of the
-function returns
+finds an interface by looking for an interface name.
+Each of the function returns
.Li NULL
if the interface cannot be found.
.Pp
@@ -227,17 +238,18 @@ can be used to change the interface administrative state to up
(argument is 1) or down (argument is 0).
.Ss INTERFACE EVENTS
A module can register itself to receive a notification when a new entry is
-created in the interface list. This is done by calling
+created in the interface list.
+This is done by calling
.Fn mib_register_newif .
A module can register only one function, a second call to
.Fn mib_register_newif
-causes the registration to be overwritten. The registration can be removed
-with a call to
+causes the registration to be overwritten.
+The registration can be removed with a call to
.Fn mib_unregister_newif .
-If is unregistered automatically, when the registering module is unloaded.
+It is unregistered automatically, when the registering module is unloaded.
.Pp
-A module can also register to events on a specific interface. This is done
-by calling
+A module can also register to events on a specific interface.
+This is done by calling
.Fn mibif_notify .
This causes the given callback
.Fa func
@@ -251,7 +263,8 @@ The interface is destroyed.
.El
.Pp
This mechanism can be used to implement interface type specific MIB parts
-in other modules. The registration can be removed with
+in other modules.
+The registration can be removed with
.Fn mib_unnotify
which the return value from
.Fa mib_notify .
@@ -261,8 +274,8 @@ is destroyed or the registering module is unloaded.
.Ss INTERFACE ADDRESSES
The
.Nm
-module handles a table of interface IP-addresses. These addresses are held
-in a
+module handles a table of interface IP-addresses.
+These addresses are held in a
.Bd -literal -offset indent
struct mibifa {
TAILQ_ENTRY(mibifa) link;
@@ -282,8 +295,8 @@ and
.Fn mib_next_ififa .
The list should not be considered read-only.
.Ss INTERFACE RECEIVE ADDRESSES
-The internet MIB-2 contains a table of interface receive addresses. These
-addresses are handled in:
+The internet MIB-2 contains a table of interface receive addresses.
+These addresses are handled in:
.Bd -literal -offset indent
struct mibrcvaddr {
TAILQ_ENTRY(mibrcvaddr) link;
@@ -302,8 +315,9 @@ enum {
.Pp
Note, that the assignment of
.Li MIBRCVADDR_BCAST
-is based on a list of known interface types. The flags should be handled
-by modules inplementing interface type specific MIBs.
+is based on a list of known interface types.
+The flags should be handled
+by modules implementing interface type specific MIBs.
.Pp
A receive address can be created with
.Fn mib_rcvaddr_create
@@ -317,9 +331,11 @@ A receive address can be found with
.Ss INTERFACE STACK TABLE
The
.Nm
-module maintains also the interface stack table. Because for complex stacks,
+module maintains also the interface stack table.
+Because for complex stacks,
there is no system supported generic way of getting this information, interface
-type specific modules need to help setting up stack entries. The
+type specific modules need to help setting up stack entries.
+The
.Nm
module handles only the top and bottom entries.
.Pp
@@ -327,8 +343,10 @@ A table entry is created with
.Fn mib_ifstack_create
and deleted with
.Fn mib_ifstack_delete .
-Both functions need the pointers to the interfaces. Entries are automatically
-deleted if any of the interfaces of the entry is destroyed. The functions handle
+Both functions need the pointers to the interfaces.
+Entries are automatically
+deleted if any of the interfaces of the entry is destroyed.
+The functions handle
both the stack table and the reverse stack table.
.Sh FILES
.Bl -tag -width ".It Pa @DEFPATH@mibII_tree.def" -compact
OpenPOWER on IntegriCloud