Date: Fri, 15 Aug 2014 19:26:51 GMT From: shonali@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r272475 - in soc2014/shonali/head/contrib/bsnmp: lib snmpd Message-ID: <201408151926.s7FJQpE2077802@socsvn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: shonali Date: Fri Aug 15 19:26:50 2014 New Revision: 272475 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=272475 Log: Fixes for trap and trap related function calls Modified: soc2014/shonali/head/contrib/bsnmp/lib/snmp.h soc2014/shonali/head/contrib/bsnmp/snmpd/main.c soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.h soc2014/shonali/head/contrib/bsnmp/snmpd/snmpmod.h soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c Modified: soc2014/shonali/head/contrib/bsnmp/lib/snmp.h ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/lib/snmp.h Fri Aug 15 17:55:12 2014 (r272474) +++ soc2014/shonali/head/contrib/bsnmp/lib/snmp.h Fri Aug 15 19:26:50 2014 (r272475) @@ -173,6 +173,7 @@ /* trap only */ struct asn_oid enterprise; u_char agent_addr[4]; + u_char agent_addr6[16]; int32_t generic_trap; int32_t specific_trap; uint32_t time_stamp; Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/main.c ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/main.c Fri Aug 15 17:55:12 2014 (r272474) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/main.c Fri Aug 15 19:26:50 2014 (r272475) @@ -372,7 +372,7 @@ * on the user credentials against the configured User groups & VACM views. */ enum snmp_code -snmp_pdu_auth_access(struct snmp_pdu *pdu, int32_t *ip) +snmp_pdu_auth_access(struct snmp_pdu *pdu, int8_t *ip) { const char *uname; int32_t suboid, smodel; Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.h ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.h Fri Aug 15 17:55:12 2014 (r272474) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/snmpd.h Fri Aug 15 19:26:50 2014 (r272475) @@ -315,6 +315,7 @@ int socket; u_char comm[SNMP_COMMUNITY_MAXLEN]; int version; + int addrtype; }; enum { TRAPSINK_ACTIVE = 1, @@ -324,6 +325,9 @@ TRAPSINK_V1 = 1, TRAPSINK_V2 = 2, + + TRAPSINK_IPv4 = 1, + TRAPSINK_IPv6 = 2, }; TAILQ_HEAD(trapsink_list, trapsink); extern struct trapsink_list trapsink_list; Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/snmpmod.h ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/snmpmod.h Fri Aug 15 17:55:12 2014 (r272474) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/snmpmod.h Fri Aug 15 19:26:50 2014 (r272475) @@ -599,7 +599,7 @@ void snmp_output(struct snmp_pdu *, u_char *, size_t *, const char *); void snmp_send_port(void *, const struct asn_oid *, struct snmp_pdu *, const struct sockaddr *, socklen_t); -enum snmp_code snmp_pdu_auth_access(struct snmp_pdu *, int32_t *); +enum snmp_code snmp_pdu_auth_access(struct snmp_pdu *, int8_t *); /* sending traps */ void snmp_send_trap(const struct asn_oid *, ...); @@ -619,6 +619,11 @@ void ip_commit(struct snmp_context *); int ip_get(struct snmp_value *, u_char *); +int ip6_save(struct snmp_value *, struct snmp_context *, u_char *); +void ip6_rollback(struct snmp_context *, u_char *); +void ip6_commit(struct snmp_context *); +int ip6_get(struct snmp_value *, u_char *); + int oid_save(struct snmp_value *, struct snmp_context *, struct asn_oid *); void oid_rollback(struct snmp_context *, struct asn_oid *); void oid_commit(struct snmp_context *); Modified: soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c ============================================================================== --- soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c Fri Aug 15 17:55:12 2014 (r272474) +++ soc2014/shonali/head/contrib/bsnmp/snmpd/trap.c Fri Aug 15 19:26:50 2014 (r272475) @@ -57,8 +57,6 @@ #include "tree.h" #include "oid.h" -#define RowStatus_active 1 - struct trapsink_list trapsink_list = TAILQ_HEAD_INITIALIZER(trapsink_list); @@ -87,15 +85,18 @@ u_int status; u_char comm[SNMP_COMMUNITY_MAXLEN + 1]; u_int version; + u_int addrtype; u_int rb; u_int rb_status; u_int rb_version; + u_int rb_addrtype; u_char rb_comm[SNMP_COMMUNITY_MAXLEN + 1]; }; enum { TDEP_STATUS = 0x0001, TDEP_COMM = 0x0002, TDEP_VERSION = 0x0004, + TDEP_ADDRTYPE = 0x0004, TDEP_CREATE = 0x0001, TDEP_MODIFY = 0x0002, @@ -176,8 +177,6 @@ (void)close(t->socket); free(t); } - - } static void trapsink_create_sockv6(struct trapsink *t) @@ -201,9 +200,6 @@ (void)close(t->socket); free(t); } - - - } static void @@ -220,6 +216,7 @@ { tdep->rb_status = t->status; tdep->rb_version = t->version; + tdep->rb_addrtype = t->addrtype; strcpy(tdep->rb_comm, t->comm); if (tdep->set & TDEP_STATUS) { @@ -233,6 +230,8 @@ if (tdep->set & TDEP_VERSION) t->version = tdep->version; + if (tdep->set & TDEP_ADDRTYPE) + t->addrtype = tdep->addrtype; if (tdep->set & TDEP_COMM) strcpy(t->comm, tdep->comm); @@ -242,6 +241,7 @@ if (t->comm[0] == '\0') { t->status = tdep->rb_status; t->version = tdep->rb_version; + t->addrtype = tdep->rb_addrtype; strcpy(t->comm, tdep->rb_comm); return (SNMP_ERR_INCONS_VALUE); } @@ -259,6 +259,8 @@ t->status = tdep->rb_status; if (tdep->set & TDEP_VERSION) t->version = tdep->rb_version; + if (tdep->set & TDEP_ADDRTYPE) + t->addrtype = tdep->rb_addrtype; if (tdep->set & TDEP_COMM) strcpy(t->comm, tdep->rb_comm); @@ -436,6 +438,16 @@ tdep->version = value->v.integer; tdep->set |= TDEP_VERSION; return (SNMP_ERR_NOERROR); + + case LEAF_begemotTrapSinkAddrType: + if (tdep->set & TDEP_ADDRTYPE) + return (SNMP_ERR_INCONS_VALUE); + if (value->v.integer != TRAPSINK_IPv4 && + value->v.integer != TRAPSINK_IPv6) + return (SNMP_ERR_WRONG_VALUE); + tdep->addrtype = value->v.integer; + tdep->set |= TDEP_ADDRTYPE; + return (SNMP_ERR_NOERROR); } if (t == NULL) return (SNMP_ERR_INCONS_NAME); @@ -461,6 +473,10 @@ value->v.integer = t->version; break; + case LEAF_begemotTrapSinkAddrType: + value->v.integer = t->addrtype; + break; + } return (SNMP_ERR_NOERROR); } @@ -483,6 +499,23 @@ } static void +snmp_create_v1_trapv6(struct snmp_pdu *pdu, char *com, + const struct asn_oid *trap_oid) +{ + memset(pdu, 0, sizeof(*pdu)); + strcpy(pdu->community, com); + + pdu->version = SNMP_V1; + pdu->type = SNMP_PDU_TRAP; + pdu->enterprise = systemg.object_id; + memcpy(pdu->agent_addr6, snmpd.trap1addr6, 16); + pdu->generic_trap = trap_oid->subs[trap_oid->len - 1] - 1; + pdu->specific_trap = 0; + pdu->time_stamp = get_ticks() - start_tick; + pdu->nbindings = 0; +} + +static void snmp_create_v2_trap(struct snmp_pdu *pdu, char *com, const struct asn_oid *trap_oid) { @@ -589,14 +622,18 @@ char *tag; size_t sndlen; ssize_t len; - int32_t ip; + int8_t ip[16]; TAILQ_FOREACH(t, &trapsink_list, link) { if (t->status != TRAPSINK_ACTIVE) continue; - if (t->version == TRAPSINK_V1) - snmp_create_v1_trap(&pdu, t->comm, trap_oid); + if (t->version == TRAPSINK_V1) { + if (t->addrtype == TRAPSINK_IPv4) + snmp_create_v1_trap(&pdu, t->comm, trap_oid); + else if (t->addrtype == TRAPSINK_IPv6) + snmp_create_v1_trapv6(&pdu, t->comm, trap_oid); + } else snmp_create_v2_trap(&pdu, t->comm, trap_oid); @@ -652,7 +689,10 @@ switch (tp->mpmodel) { case SNMP_MPM_SNMP_V1: - snmp_create_v1_trap(&pdu, tp->secname, trap_oid); + if (t->addrtype == TRAPSINK_IPv4) + snmp_create_v1_trap(&pdu, tp->secname, trap_oid); + else if (t->addrtype == TRAPSINK_IPv6) + snmp_create_v1_trapv6(&pdu, tp->secname, trap_oid); break; case SNMP_MPM_SNMP_V2c:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201408151926.s7FJQpE2077802>