diff options
author | Stuart Henderson <sthen@cvs.openbsd.org> | 2018-05-30 18:17:21 +0000 |
---|---|---|
committer | Stuart Henderson <sthen@cvs.openbsd.org> | 2018-05-30 18:17:21 +0000 |
commit | 7e97791df3343f7e795d7f864564659d43f74d65 (patch) | |
tree | 8f919e62d8d855c4cbf3819fd1f020ff661d053b | |
parent | f6a03861dd0e165a998e18dbb3f83064e61f4cd6 (diff) |
Use new SIOCGIFGLIST to provide carpGroupTable, showing "demote" values
for interface groups on the system. From Jan Klemkow.
-rw-r--r-- | share/snmp/OPENBSD-CARP-MIB.txt | 58 | ||||
-rw-r--r-- | usr.sbin/snmpd/mib.c | 104 | ||||
-rw-r--r-- | usr.sbin/snmpd/mib.h | 12 |
3 files changed, 170 insertions, 4 deletions
diff --git a/share/snmp/OPENBSD-CARP-MIB.txt b/share/snmp/OPENBSD-CARP-MIB.txt index 4b6a3e33733..b97c2e820e1 100644 --- a/share/snmp/OPENBSD-CARP-MIB.txt +++ b/share/snmp/OPENBSD-CARP-MIB.txt @@ -1,4 +1,4 @@ --- $OpenBSD: OPENBSD-CARP-MIB.txt,v 1.3 2012/09/28 09:21:48 jj Exp $ +-- $OpenBSD: OPENBSD-CARP-MIB.txt,v 1.4 2018/05/30 18:17:20 sthen Exp $ -- -- Copyright (c) 2006-2011 Joel Knight <knight.joel@gmail.com> -- @@ -32,7 +32,7 @@ IMPORTS FROM SNMPv2-CONF; carpMIBObjects MODULE-IDENTITY - LAST-UPDATED "201201310000Z" + LAST-UPDATED "201805140000Z" ORGANIZATION "OpenBSD" CONTACT-INFO " Author: Joel Knight @@ -41,6 +41,8 @@ carpMIBObjects MODULE-IDENTITY " DESCRIPTION "The MIB module for gathering information about Common Address Redundancy Protocol (CARP) interfaces." + REVISION "201805140000Z" + DESCRIPTION "Add the carpGroupTable to OPENBSD-CARP-MIB." REVISION "201201310000Z" DESCRIPTION "Add the OPENBSD-CARP-MIB to snmpd." ::= { openBSD 6 } @@ -176,6 +178,58 @@ carpIfState OBJECT-TYPE ::= { carpIfEntry 7 } +-- carpGroup + +carpGroupTable OBJECT-TYPE + SYNTAX SEQUENCE OF CarpGroupEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "A list of interface groups." + ::= { carpMIBObjects 4 } + +carpGroupEntry OBJECT-TYPE + SYNTAX CarpGroupEntry + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "An entry containing management information applicable to a + particular interface group." + INDEX { carpGroupIndex } + ::= { carpGroupTable 1 } + +CarpGroupEntry ::= + SEQUENCE { + carpGroupIndex Integer32, + carpGroupName OCTET STRING, + carpGroupDemote Integer32 + } + +carpGroupIndex OBJECT-TYPE + SYNTAX Integer32 (1..2147483647) + MAX-ACCESS not-accessible + STATUS current + DESCRIPTION + "The demote value of the interface group." + ::= { carpGroupEntry 1 } + +carpGroupName OBJECT-TYPE + SYNTAX OCTET STRING + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The name of the interface group." + ::= { carpGroupEntry 2 } + +carpGroupDemote OBJECT-TYPE + SYNTAX Integer32 (1..2147483647) + MAX-ACCESS read-only + STATUS current + DESCRIPTION + "The demote value of the interface group." + ::= { carpGroupEntry 3 } + + -- carpStats carpIpPktsRecv OBJECT-TYPE diff --git a/usr.sbin/snmpd/mib.c b/usr.sbin/snmpd/mib.c index 75bba320dab..3c99a082f6b 100644 --- a/usr.sbin/snmpd/mib.c +++ b/usr.sbin/snmpd/mib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mib.c,v 1.87 2018/05/25 08:23:15 gerhard Exp $ */ +/* $OpenBSD: mib.c,v 1.88 2018/05/30 18:17:20 sthen Exp $ */ /* * Copyright (c) 2012 Joel Knight <joel@openbsd.org> @@ -1454,6 +1454,7 @@ char *mib_sensorvalue(struct sensor *); int mib_carpsysctl(struct oid *, struct ber_oid *, struct ber_element **); int mib_carpstats(struct oid *, struct ber_oid *, struct ber_element **); int mib_carpiftable(struct oid *, struct ber_oid *, struct ber_element **); +int mib_carpgrouptable(struct oid *, struct ber_oid *, struct ber_element **); int mib_carpifnum(struct oid *, struct ber_oid *, struct ber_element **); struct carpif *mib_carpifget(u_int); @@ -1669,6 +1670,8 @@ static struct oid openbsd_mib[] = { { MIB(carpIfAdvbase), OID_TRD, mib_carpiftable }, { MIB(carpIfAdvskew), OID_TRD, mib_carpiftable }, { MIB(carpIfState), OID_TRD, mib_carpiftable }, + { MIB(carpGroupName), OID_TRD, mib_carpgrouptable }, + { MIB(carpGroupDemote), OID_TRD, mib_carpgrouptable }, { MIB(memMIBObjects), OID_MIB }, { MIB(memMIBVersion), OID_RD, mps_getint, NULL, NULL, OIDVER_OPENBSD_MEM }, @@ -2906,6 +2909,105 @@ mib_carpiftable(struct oid *oid, struct ber_oid *o, struct ber_element **elm) return (0); } +static struct ifg_req * +mib_carpgroupget(u_int idx) +{ + struct ifgroupreq ifgr; + struct ifg_req *ifg = NULL; + u_int len; + int s = -1; + + bzero(&ifgr, sizeof(ifgr)); + + if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { + log_warn("socket"); + return (NULL); + } + + if (ioctl(s, SIOCGIFGLIST, (caddr_t)&ifgr) == -1) { + log_warn("SIOCGIFGLIST"); + goto err; + } + len = ifgr.ifgr_len; + + if (len / sizeof(*ifgr.ifgr_groups) <= idx-1) + goto err; + + if ((ifgr.ifgr_groups = calloc(1, len)) == NULL) { + log_warn("alloc"); + return (NULL); + } + if (ioctl(s, SIOCGIFGLIST, (caddr_t)&ifgr) == -1) { + log_warn("SIOCGIFGLIST"); + free(ifgr.ifgr_groups); + goto err; + } + close(s); + + if ((ifg = calloc(1, sizeof *ifg)) == NULL) { + log_warn("alloc"); + goto err; + } + + memcpy(ifg, &ifgr.ifgr_groups[idx-1], sizeof *ifg); + free(ifgr.ifgr_groups); + return ifg; + err: + free(ifgr.ifgr_groups); + close(s); + return (NULL); +} + +int +mib_carpgrouptable(struct oid *oid, struct ber_oid *o, struct ber_element **elm) +{ + struct ifgroupreq ifgr; + struct ifg_req *ifg; + uint32_t idx; + int s; + + /* Get and verify the current row index */ + idx = o->bo_id[OIDIDX_carpGroupIndex]; + + if ((ifg = mib_carpgroupget(idx)) == NULL) + return (1); + + /* Tables need to prepend the OID on their own */ + o->bo_id[OIDIDX_carpGroupIndex] = idx; + *elm = ber_add_oid(*elm, o); + + switch (o->bo_id[OIDIDX_carpGroupEntry]) { + case 2: + *elm = ber_add_string(*elm, ifg->ifgrq_group); + break; + case 3: + if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { + log_warn("socket"); + free(ifg); + return (1); + } + + bzero(&ifgr, sizeof(ifgr)); + strlcpy(ifgr.ifgr_name, ifg->ifgrq_group, sizeof(ifgr.ifgr_name)); + if (ioctl(s, SIOCGIFGATTR, (caddr_t)&ifgr) == -1) { + log_warn("SIOCGIFGATTR"); + close(s); + free(ifg); + return (1); + } + + close(s); + *elm = ber_add_integer(*elm, ifgr.ifgr_attrib.ifg_carp_demoted); + break; + default: + free(ifg); + return (1); + } + + free(ifg); + return (0); +} + int mib_memiftable(struct oid *oid, struct ber_oid *o, struct ber_element **elm) { diff --git a/usr.sbin/snmpd/mib.h b/usr.sbin/snmpd/mib.h index a8b78aba66d..b338bad7b61 100644 --- a/usr.sbin/snmpd/mib.h +++ b/usr.sbin/snmpd/mib.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mib.h,v 1.38 2016/03/07 19:33:26 mmcc Exp $ */ +/* $OpenBSD: mib.h,v 1.39 2018/05/30 18:17:20 sthen Exp $ */ /* * Copyright (c) 2007, 2008 Reyk Floeter <reyk@openbsd.org> @@ -722,6 +722,12 @@ #define MIB_carpIp6PktsSent MIB_carpStats, 13 #define MIB_carpNoMemory MIB_carpStats, 14 #define MIB_carpTransitionsToMaster MIB_carpStats, 15 +#define MIB_carpGroupTable MIB_carpMIBObjects, 4 +#define MIB_carpGroupEntry MIB_carpGroupTable, 1 +#define OIDIDX_carpGroupEntry 10 +#define OIDIDX_carpGroupIndex 11 +#define MIB_carpGroupName MIB_carpGroupEntry, 2 +#define MIB_carpGroupDemote MIB_carpGroupEntry, 3 #define MIB_localSystem MIB_openBSD, 23 #define MIB_SYSOID_DEFAULT MIB_openBSD, 23, 1 #define MIB_localTest MIB_openBSD, 42 @@ -1272,6 +1278,10 @@ { MIBDECL(carpIp6PktsSent) }, \ { MIBDECL(carpNoMemory) }, \ { MIBDECL(carpTransitionsToMaster) }, \ + { MIBDECL(carpGroupTable) }, \ + { MIBDECL(carpGroupEntry) }, \ + { MIBDECL(carpGroupName) }, \ + { MIBDECL(carpGroupDemote) }, \ { MIBDECL(localSystem) }, \ { MIBDECL(localTest) }, \ \ |