Date: Mon, 9 Jan 2017 02:34:26 +0000 (UTC) From: Ngie Cooper <ngie@FreeBSD.org> To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r311737 - projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6 Message-ID: <201701090234.v092YQ3w022289@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ngie Date: Mon Jan 9 02:34:26 2017 New Revision: 311737 URL: https://svnweb.freebsd.org/changeset/base/311737 Log: Start filling in the blanks from contrib/bsnmp/snmp_mibII/mibII_interfaces.c Add XXX comments for WIP items. Table isn't iterable, but at least it no longer blows up an snmpwalk (here at least) Modified: projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/ipv6_ifTable.c Modified: projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/ipv6_ifTable.c ============================================================================== --- projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/ipv6_ifTable.c Mon Jan 9 02:04:54 2017 (r311736) +++ projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/ipv6_ifTable.c Mon Jan 9 02:34:26 2017 (r311737) @@ -43,25 +43,25 @@ int op_ipv6IfTable(struct snmp_context *ctx __unused, struct snmp_value *value, u_int sub, u_int iidx __unused, enum snmp_op op) { + struct mibif *ifp = NULL; asn_subid_t which; + int ret; switch (op) { - case SNMP_OP_GETNEXT: #if 0 - ip = NEXT_OBJECT_INT(&ipv6_interfaces, &value->var, sub); - if (ip == NULL) - return SNMP_ERR_NOSUCHNAME; + case SNMP_OP_GETNEXT: + if ((ifp = NEXT_OBJECT_INT(&mibif_list, &value->var, sub)) == NULL) + return (SNMP_ERR_NOSUCHNAME); value->var.len = sub + 1; - value->var.subs[sub] = ip->index; -#endif + value->var.subs[sub] = ifp->index; break; case SNMP_OP_GET: -#if 0 - ip = FIND_OBJECT_INT(&ipv6_interfaces, &value->var, sub); - if (ip == NULL) + if (value->var.len - sub != 1) + return (SNMP_ERR_NOSUCHNAME); + if ((ifp = mib_find_if(value->var.subs[sub])) == NULL) return (SNMP_ERR_NOSUCHNAME); -#endif break; +#endif case SNMP_OP_SET: case SNMP_OP_COMMIT: case SNMP_OP_ROLLBACK: @@ -72,16 +72,20 @@ op_ipv6IfTable(struct snmp_context *ctx which = value->var.subs[sub - 1]; - switch (which) { - case LEAF_ipv6IfDescr: #if 0 - string_get(value, ip->name, strlen(ip->name)); + /* XXX (ngie): expose mib_fetch_ifmib */ + if (ifp->mibtick < this_tick) + (void)mib_fetch_ifmib(ifp); #endif + + switch (which) { + case LEAF_ipv6IfDescr: + ret = string_get(value, ifp->descr, -1); break; case LEAF_ipv6IfLowerLayer: /* - * TODO: return nullOID until the proper way is figured out. - * For now, use `oid_zeroDotZero`. + * XXX (thor): return nullOID until the proper way is figured + * out. For now, use `oid_zeroDotZero`. */ oid_get(value, &oid_zeroDotZero); break; @@ -89,26 +93,10 @@ op_ipv6IfTable(struct snmp_context *ctx value->v.uint32 = IPV6_MAXPACKET; break; case LEAF_ipv6IfEffectiveMtu: - { -#if 0 - struct ifreq ifr; - int s; - - memset(&ifr, 0, sizeof(ifr)); - ifr.ifr_addr.sa_family = AF_INET6; - strncpy(ifr.ifr_name, ip->name, sizeof(ifr.ifr_name)); - - if ((s = socket(ifr.ifr_addr.sa_family, SOCK_DGRAM, 0)) < 0) - return (SNMP_ERR_RES_UNAVAIL); - - if (ioctl(s, SIOCGIFMTU, (caddr_t) &ifr) != -1) - value->v.uint32 = ifr.ifr_mtu; - - close(s); -#endif + value->v.integer = ifp->mib.ifmd_data.ifi_mtu; break; - } case LEAF_ipv6IfIdentifier: + /* XXX (ngie): implement this */ string_get(value, "", 0); break; case LEAF_ipv6IfIdentifierLength: @@ -116,87 +104,29 @@ op_ipv6IfTable(struct snmp_context *ctx value->v.integer = 0; break; case LEAF_ipv6IfPhysicalAddress: - { -#if 0 - get_physaddr(); - if (tmp == NULL) - string_get(value, "", 0); - else - string_get(value, tmp, strlen(tmp)); -#endif + ret = string_get(value, ifp->physaddr, + ifp->physaddrlen); break; - } case LEAF_ipv6IfAdminStatus: - { -#if 0 - struct ifaddrs *ifap, *ifa; - - if (getifaddrs(&ifap) == -1) { - value->v.integer = 4; /* Unknown */ - break; - } - - value->v.integer = 2; - for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { - if (strcmp(ifa->ifa_name, ip->name) != 0) - continue; - if (ifa->ifa_addr->sa_family != AF_INET6) - continue; - value->v.integer = - (ifa->ifa_flags & IFF_RUNNING) ? 1 : 2; - break; - } - freeifaddrs(ifap); -#endif + value->v.integer = + (ifp->mib.ifmd_flags & IFF_UP) ? 1 : 2; break; - } case LEAF_ipv6IfOperStatus: - { -#if 0 - struct ifaddrs *ifap, *ifa; - if (getifaddrs(&ifap) == -1) { - value->v.integer = 4; /* Unknown */ - break; - } - - value->v.integer = 2; - - for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { - if (strcmp(ifa->ifa_name, ip->name) != 0) - continue; - if (ifa->ifa_addr->sa_family != AF_INET6) - continue; - value->v.integer = (ifa->ifa_flags & IFF_UP) ? 1 : 2; - break; - } - freeifaddrs(ifap); -#endif + if ((ifp->mib.ifmd_flags & IFF_RUNNING) != 0) { + if (ifp->mib.ifmd_data.ifi_link_state != LINK_STATE_UP) + value->v.integer = 5; /* state dormant */ + else + value->v.integer = 1; /* state up */ + } else + value->v.integer = 2; /* state down */ break; - } - case LEAF_ipv6IfLastChange: - { #if 0 - /* - * XXX (ngie): not checking for error code from - * gettimeofday(2). - */ - struct timeval lastchange, now; - struct ifmibdata ifmd; - - if (if_getifmibdata(ip->index, &ifmd) != 0) { - value->v.uint32 = 0; - break; - } - lastchange = ifmd.ifmd_data.ifi_lastchange; - - gettimeofday(&now, (struct timezone*)NULL); + /* XXX (ngie): export from mib-II to somewhere more sensible. */ + case LEAF_ipv6IfLastChange: value->v.uint32 = - (uint32_t)((now.tv_sec - lastchange.tv_sec) * 100); - value->v.uint32 += - (uint32_t)((now.tv_usec - lastchange.tv_usec) / 10000); -#endif + ticks_get_timeval(&ifp->mib.ifmd_data.ifi_lastchange); break; - } +#endif default: return (SNMP_ERR_RES_UNAVAIL); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201701090234.v092YQ3w022289>