Index: projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/util.c =================================================================== --- projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/util.c (revision 311280) +++ projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/util.c (nonexistent) @@ -1,70 +0,0 @@ -/* - * - * Copyright 1989, 1991, 1992 by Carnegie Mellon University - * - * Derivative Work - 1996, 1998-2000 - * Copyright 1996, 1998-2000 The Regents of the University of California - * - * All Rights Reserved - * - * Permission to use, copy, modify and distribute this software and its - * documentation for any purpose and without fee is hereby granted, - * provided that the above copyright notice appears in all copies and - * that both that copyright notice and this permission notice appear in - * supporting documentation, and that the name of CMU and The Regents of - * the University of California not be used in advertising or publicity - * pertaining to distribution of the software without specific written - * permission. - * - * CMU AND THE REGENTS OF THE UNIVERSITY OF CALIFORNIA DISCLAIM ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL CMU OR - * THE REGENTS OF THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY SPECIAL, - * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM THE LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -#include - -__FBSDID("$FreeBSD$"); - -/* - * From /agent/mibgroup/mibII/ipv6.c, and maybe originally from the - * Kame project - */ - -/* - * TODO (ngie): replace with network_get_interfaces(..) from - * snmp_hostres/hostres_network_tbl.c so we can ditch this completely. - */ - -/* $FreeBSD$ */ - -#include - -#include "util.h" - -int -if_getifmibdata(int idx, struct ifmibdata *result) -{ - int mib[] = { - CTL_NET, - PF_LINK, - NETLINK_GENERIC, - IFMIB_IFDATA, - 0, - IFDATA_GENERAL - }; - size_t len; - struct ifmibdata tmp; - - mib[4] = idx; - len = sizeof(struct ifmibdata); - if (sysctl(mib, sizeof(mib)/sizeof(mib[0]), &tmp, &len, 0, 0) < 0) - return -1; - memcpy(result, &tmp, sizeof(tmp)); - return 0; -} Property changes on: projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/util.c ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/util.h =================================================================== --- projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/util.h (revision 311280) +++ projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/util.h (nonexistent) @@ -1,46 +0,0 @@ -/* - * - * Copyright 1989, 1991, 1992 by Carnegie Mellon University - * - * Derivative Work - 1996, 1998-2000 - * Copyright 1996, 1998-2000 The Regents of the University of California - * - * All Rights Reserved - * - * Permission to use, copy, modify and distribute this software and its - * documentation for any purpose and without fee is hereby granted, - * provided that the above copyright notice appears in all copies and - * that both that copyright notice and this permission notice appear in - * supporting documentation, and that the name of CMU and The Regents of - * the University of California not be used in advertising or publicity - * pertaining to distribution of the software without specific written - * permission. - * - * CMU AND THE REGENTS OF THE UNIVERSITY OF CALIFORNIA DISCLAIM ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL CMU OR - * THE REGENTS OF THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY SPECIAL, - * INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING - * FROM THE LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF - * CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN - * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - */ - -/* See util.c for comments about licensing */ - -#ifndef __SNMP_IPV6__UTIL_H__ -#define __SNMP_IPV6__UTIL_H__ - -#include - -__FBSDID("$FreeBSD$"); - -#include "ipv6.h" - -#include -#include - -int if_getifmibdata(int idx, struct ifmibdata *result); - -#endif Property changes on: projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/util.h ___________________________________________________________________ Deleted: svn:eol-style ## -1 +0,0 ## -native \ No newline at end of property Deleted: svn:keywords ## -1 +0,0 ## -FreeBSD=%H \ No newline at end of property Deleted: svn:mime-type ## -1 +0,0 ## -text/plain \ No newline at end of property Index: projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/Makefile =================================================================== --- projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/Makefile (revision 311280) +++ projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/Makefile (revision 311281) @@ -1,23 +1,22 @@ # $FreeBSD$ # MOD= ipv6MIB SRCS+= ipv6.c SRCS+= ipv6_addrPrefixTable.c SRCS+= ipv6_addrTable.c SRCS+= ipv6_ifStatsTable.c SRCS+= ipv6_ifTable.c SRCS+= ipv6_netToMediaTable.c SRCS+= ipv6_routeTable.c -SRCS+= util.c XSYM= ${MOD} BMIBS= IPV6-MIB.txt MAN= snmp_${MOD}.3 DEFS= ${MOD}_tree.def CFLAGS+= -DSNMPTREE_TYPES .include Index: projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/ipv6.c =================================================================== --- projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/ipv6.c (revision 311280) +++ projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/ipv6.c (revision 311281) @@ -1,206 +1,140 @@ /* * Copyright (c) 2016 Dell EMC Isilon * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include "ipv6.h" #include "ipv6MIB_oid.h" /* * XXX (ngie): mibII implements a lot of this already. Probably should * converge the two modules. */ static struct lmodule *module; -struct ipv6_interface_list ipv6_interfaces = - TAILQ_HEAD_INITIALIZER(ipv6_interfaces); - static const struct asn_oid oid_ipv6MIB = OIDX_ipv6MIB; static u_int ipv6_reg; int -load_ipv6_interface_table(void) -{ - struct ipv6_interface *ip = NULL; - struct if_nameindex *p = NULL, *ifnames = NULL; - - ifnames = if_nameindex(); - - for (p = ifnames; p != NULL && p->if_index; p++) { - ip = calloc(1, sizeof(struct ipv6_interface)); - if (ip == NULL) { - free_ipv6_interface_table(); - if_freenameindex(ifnames); - return (-1); - } - - ip->index = p->if_index; - - if ((ip->name = strdup(p->if_name)) == NULL) { - free_ipv6_interface_table(); - if_freenameindex(ifnames); - return (-1); - } - - INSERT_OBJECT_INT(ip, &ipv6_interfaces); - } - - if_freenameindex(ifnames); - - return (0); -} - -void -free_ipv6_interface_table(void) -{ - struct ipv6_interface *ip; - - /* - * XXX (ngie): TAILQ_FOREACH_SAFE would be better, but using mibII - * would be the best - */ - while ((ip = TAILQ_FIRST(&ipv6_interfaces)) != NULL) { - TAILQ_REMOVE(&ipv6_interfaces, ip, link); - free(ip->name); - free(ip); - ip = NULL; - } -} - -static int -if_countifindex(void) -{ - struct ipv6_interface *ip; - int count = 0; - - TAILQ_FOREACH(ip, &ipv6_interfaces, link) { - count++; - } - return count; -} - -int op_ipv6MIBObjects(struct snmp_context *ctx __unused, struct snmp_value *value, u_int sub, u_int iidx __unused, enum snmp_op op) { const char *namestr = NULL; int name[] = { CTL_NET, PF_INET6, IPPROTO_IPV6, 0 }; int result = 0; size_t resultsiz = sizeof(result); switch (op) { case SNMP_OP_GETNEXT: case SNMP_OP_GET: break; case SNMP_OP_SET: /* XXX (ngie): this is a lie. It's not implemented. */ return (SNMP_ERR_NOT_WRITEABLE); case SNMP_OP_ROLLBACK: case SNMP_OP_COMMIT: return (SNMP_ERR_NOERROR); } switch (value->var.subs[sub - 1]) { case LEAF_ipv6Forwarding: name[3] = IPV6CTL_FORWARDING; namestr = "IPV6CTL_FORWARDING"; if (sysctl(name, nitems(name), &result, &resultsiz, NULL, 0) < 0) return (SNMP_ERR_GENERR); /* XXX (ngie): hardcoded value. */ value->v.integer = (result) ? 1 : 2; break; case LEAF_ipv6DefaultHopLimit: name[3] = IPV6CTL_DEFHLIM; namestr = "IPV6CTL_DEFHLIM"; if (sysctl(name, nitems(name), &result, &resultsiz, NULL, 0) < 0) return (SNMP_ERR_GENERR); value->v.integer = result; break; case LEAF_ipv6IfTableLastChange: { /* XXX (ngie): this needs to be implemented */ value->v.uint32 = 0; break; } case LEAF_ipv6Interfaces: /* * XXX (ngie): this incorrectly assumes that all interfaces * are IPv6 enabled. */ - value->v.integer = if_countifindex(); + /*value->v.integer = if_countifindex()*/; break; default: return (SNMP_ERR_NOSUCHNAME); } return (SNMP_ERR_NOERROR); } static void ipv6MIB_start(void) { - load_ipv6_interface_table(); ipv6_reg = or_register(&oid_ipv6MIB, "The (incomplete) MIB module for RFC 2465.", module); } static int ipv6MIB_init(struct lmodule *mod, int argc __unused, char *argv[] __unused) { module = mod; return (0); } static int ipv6MIB_fini(void) { - free_ipv6_interface_table(); or_unregister(ipv6_reg); return (0); } const struct snmp_module config = { "This module implements RFC 2465.", ipv6MIB_init, ipv6MIB_fini, NULL, NULL, NULL, ipv6MIB_start, NULL, ipv6MIB_ctree, ipv6MIB_CTREE_SIZE, NULL }; Index: projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/ipv6.h =================================================================== --- projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/ipv6.h (revision 311280) +++ projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/ipv6.h (revision 311281) @@ -1,68 +1,55 @@ /* * Copyright (c) 2016 Dell EMC Isilon * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef __SNMP_IPV6__IPV6_H__ #define __SNMP_IPV6__IPV6_H__ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "ipv6MIB_tree.h" -struct ipv6_interface { - TAILQ_ENTRY(ipv6_interface) link; - - char *name; /* The interface name */ - int index; /* The interface number */ -}; -TAILQ_HEAD(ipv6_interface_list, ipv6_interface); - -extern struct ipv6_interface_list ipv6_interfaces; - -int load_ipv6_interface_table(void); -void free_ipv6_interface_table(void); - #endif Index: 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 (revision 311280) +++ projects/bsnmp-ipv6-mib/usr.sbin/bsnmpd/modules/snmp_ipv6/ipv6_ifTable.c (revision 311281) @@ -1,233 +1,205 @@ /*- * Copyright (c) 2016 Dell EMC Isilon * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include __FBSDID("$FreeBSD$"); #include +#include +#include #include #include +#include +#include + #include "ipv6.h" -#include "util.h" int op_ipv6IfTable(struct snmp_context *ctx __unused, struct snmp_value *value, u_int sub, u_int iidx __unused, enum snmp_op op) { - struct ipv6_interface *ip; asn_subid_t which; switch (op) { case SNMP_OP_GETNEXT: +#if 0 ip = NEXT_OBJECT_INT(&ipv6_interfaces, &value->var, sub); if (ip == NULL) return SNMP_ERR_NOSUCHNAME; value->var.len = sub + 1; value->var.subs[sub] = ip->index; +#endif break; case SNMP_OP_GET: +#if 0 ip = FIND_OBJECT_INT(&ipv6_interfaces, &value->var, sub); if (ip == NULL) return (SNMP_ERR_NOSUCHNAME); +#endif break; case SNMP_OP_SET: case SNMP_OP_COMMIT: case SNMP_OP_ROLLBACK: return (SNMP_ERR_NOERROR); default: return (SNMP_ERR_RES_UNAVAIL); } which = value->var.subs[sub - 1]; switch (which) { case LEAF_ipv6IfDescr: +#if 0 string_get(value, ip->name, strlen(ip->name)); +#endif break; case LEAF_ipv6IfLowerLayer: /* * TODO: return nullOID until the proper way is figured out. * For now, use `oid_zeroDotZero`. */ oid_get(value, &oid_zeroDotZero); break; case LEAF_ipv6IfReasmMaxSize: 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 break; } case LEAF_ipv6IfIdentifier: string_get(value, "", 0); break; case LEAF_ipv6IfIdentifierLength: /* XXX (ngie): get the length of LEAF_ipv6IfIdentifier */ value->v.integer = 0; break; case LEAF_ipv6IfPhysicalAddress: { - char *c, *tmp = NULL; - struct ifaddrs *ifap, *ifa; - struct sockaddr_dl sdl; - - if (getifaddrs(&ifap) == -1) { - string_get(value, "", 0); - break; - } - - 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_LINK) - continue; - - /* - * XXX (ngie): the following string manipulation seems - * really hacky. This should emulate what ifconfig(8) - * does by opening a socket and throbbing a few ioctls - * to get the MAC address for an interface. - */ - memcpy(&sdl, ifa->ifa_addr, - sizeof(*(ifa->ifa_addr))); - - tmp = link_ntoa(&sdl); - - /* - * link_ntoa returns a string with the follow format - * :, - * e.g. "em0:0.50.56.30.1.26". - * - * We need the MAC address in colon-separated octet - * format. - */ - tmp = strchr(tmp, ':'); - if (tmp == NULL) - break; - tmp++; - /* convert the '.' to ':' */ - while ((c = strchr(tmp, '.')) != NULL) - *c = ':'; - /* now tmp == "0:50:56:30:1:26" */ - break; - } +#if 0 + get_physaddr(); if (tmp == NULL) string_get(value, "", 0); else string_get(value, tmp, strlen(tmp)); - - freeifaddrs(ifap); +#endif 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 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 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); 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 break; } default: return (SNMP_ERR_RES_UNAVAIL); } return (SNMP_ERR_NOERROR); }