--- embedaddon/quagga/ospfd/ospf_snmp.c 2012/02/21 17:26:12 1.1 +++ embedaddon/quagga/ospfd/ospf_snmp.c 2016/11/02 10:09:12 1.1.1.4 @@ -25,14 +25,8 @@ #include #ifdef HAVE_SNMP -#ifdef HAVE_NETSNMP #include #include -#else -#include -#include -#include -#endif #include "if.h" #include "log.h" @@ -54,7 +48,7 @@ #include "ospfd/ospf_ism.h" #include "ospfd/ospf_dump.h" #include "ospfd/ospf_snmp.h" - + /* OSPF2-MIB. */ #define OSPF2MIB 1,3,6,1,2,1,14 @@ -210,15 +204,16 @@ #define TIMETICKS ASN_TIMETICKS #define IPADDRESS ASN_IPADDRESS #define STRING ASN_OCTET_STR - + /* Declare static local variables for convenience. */ SNMP_LOCAL_VARIABLES /* OSPF-MIB instances. */ oid ospf_oid [] = { OSPF2MIB }; +oid ospf_trap_oid [] = { OSPF2MIB, 16, 2 }; /* Not reverse mappable! */ /* IP address 0.0.0.0. */ -static struct in_addr ospf_empty_addr = {0}; +static struct in_addr ospf_empty_addr = { .s_addr = 0 }; /* Hook functions. */ static u_char *ospfGeneralGroup (struct variable *, oid *, size_t *, @@ -506,7 +501,7 @@ struct variable ospf_variables[] = {OSPFAREAAGGREGATEEFFECT, INTEGER, RWRITE, ospfAreaAggregateEntry, 3, {14, 1, 6}} }; - + /* The administrative status of OSPF. When OSPF is enbled on at least one interface return 1. */ static int @@ -709,6 +704,10 @@ ospfAreaEntry (struct variable *v, oid *name, size_t * struct ospf_area *area; struct in_addr addr; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + memset (&addr, 0, sizeof (struct in_addr)); area = ospfAreaLookup (v, name, length, &addr, exact); @@ -852,6 +851,10 @@ ospfStubAreaEntry (struct variable *v, oid *name, size struct ospf_area *area; struct in_addr addr; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + memset (&addr, 0, sizeof (struct in_addr)); area = ospfStubAreaLookup (v, name, length, &addr, exact); @@ -934,7 +937,7 @@ ospfLsdbLookup (struct variable *v, oid *name, size_t struct ospf *ospf; struct ospf_area *area; struct ospf_lsa *lsa; - unsigned int len; + int len; int type_next; int ls_id_next; int router_id_next; @@ -983,7 +986,7 @@ ospfLsdbLookup (struct variable *v, oid *name, size_t offsetlen = *length - v->namelen; len = offsetlen; - if (len > IN_ADDR_SIZE) + if (len > (int)IN_ADDR_SIZE) len = IN_ADDR_SIZE; oid2in_addr (offset, len, area_id); @@ -992,7 +995,7 @@ ospfLsdbLookup (struct variable *v, oid *name, size_t if (len == IN_ADDR_SIZE) area = ospf_area_lookup_by_area_id (ospf, *area_id); else - area = ospf_area_lookup_next (ospf, area_id, len == 0 ? 1 : 0); + area = ospf_area_lookup_next (ospf, area_id, 1); if (area == NULL) return NULL; @@ -1000,8 +1003,8 @@ ospfLsdbLookup (struct variable *v, oid *name, size_t do { /* Next we lookup type. */ - offset += IN_ADDR_SIZE; - offsetlen -= IN_ADDR_SIZE; + offset += len; + offsetlen -= len; len = offsetlen; if (len <= 0) @@ -1023,7 +1026,7 @@ ospfLsdbLookup (struct variable *v, oid *name, size_t else { ls_id_next = 0; - if (len > IN_ADDR_SIZE) + if (len > (int)IN_ADDR_SIZE) len = IN_ADDR_SIZE; oid2in_addr (offset, len, ls_id); @@ -1039,7 +1042,7 @@ ospfLsdbLookup (struct variable *v, oid *name, size_t else { router_id_next = 0; - if (len > IN_ADDR_SIZE) + if (len > (int)IN_ADDR_SIZE) len = IN_ADDR_SIZE; oid2in_addr (offset, len, router_id); @@ -1083,6 +1086,10 @@ ospfLsdbEntry (struct variable *v, oid *name, size_t * struct in_addr router_id; struct ospf *ospf; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + /* INDEX { ospfLsdbAreaId, ospfLsdbType, ospfLsdbLsid, ospfLsdbRouterId } */ @@ -1145,7 +1152,7 @@ ospfAreaRangeLookup (struct variable *v, oid *name, si { oid *offset; int offsetlen; - unsigned int len; + int len; struct ospf *ospf; struct ospf_area *area; struct ospf_area_range *range; @@ -1186,7 +1193,7 @@ ospfAreaRangeLookup (struct variable *v, oid *name, si offsetlen = *length - v->namelen; len = offsetlen; - if (len > IN_ADDR_SIZE) + if (len > (int)IN_ADDR_SIZE) len = IN_ADDR_SIZE; oid2in_addr (offset, len, area_id); @@ -1208,7 +1215,7 @@ ospfAreaRangeLookup (struct variable *v, oid *name, si if (len < 0) len = 0; - if (len > IN_ADDR_SIZE) + if (len > (int)IN_ADDR_SIZE) len = IN_ADDR_SIZE; oid2in_addr (offset, len, range_net); @@ -1245,6 +1252,10 @@ ospfAreaRangeEntry (struct variable *v, oid *name, siz struct in_addr mask; struct ospf *ospf; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + /* Check OSPF instance. */ ospf = ospf_lookup (); if (ospf == NULL) @@ -1349,6 +1360,10 @@ ospfHostEntry (struct variable *v, oid *name, size_t * struct in_addr addr; struct ospf *ospf; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + /* Check OSPF instance. */ ospf = ospf_lookup (); if (ospf == NULL) @@ -1392,13 +1407,13 @@ ospfHostEntry (struct variable *v, oid *name, size_t * } return NULL; } - + struct list *ospf_snmp_iflist; struct ospf_snmp_if { struct in_addr addr; - unsigned int ifindex; + ifindex_t ifindex; struct interface *ifp; }; @@ -1440,7 +1455,7 @@ ospf_snmp_if_update (struct interface *ifp) struct prefix *p; struct ospf_snmp_if *osif; struct in_addr *addr; - unsigned int ifindex; + ifindex_t ifindex; ospf_snmp_if_delete (ifp); @@ -1515,7 +1530,7 @@ ospf_snmp_is_if_have_addr (struct interface *ifp) } static struct ospf_interface * -ospf_snmp_if_lookup (struct in_addr *ifaddr, unsigned int *ifindex) +ospf_snmp_if_lookup (struct in_addr *ifaddr, ifindex_t *ifindex) { struct listnode *node; struct ospf_snmp_if *osif; @@ -1539,8 +1554,8 @@ ospf_snmp_if_lookup (struct in_addr *ifaddr, unsigned } static struct ospf_interface * -ospf_snmp_if_lookup_next (struct in_addr *ifaddr, unsigned int *ifindex, - int ifaddr_next, int ifindex_next) +ospf_snmp_if_lookup_next (struct in_addr *ifaddr, ifindex_t *ifindex, + int ifaddr_next, ifindex_t ifindex_next) { struct ospf_snmp_if *osif; struct listnode *nn; @@ -1623,11 +1638,11 @@ ospf_snmp_iftype (struct interface *ifp) static struct ospf_interface * ospfIfLookup (struct variable *v, oid *name, size_t *length, - struct in_addr *ifaddr, unsigned int *ifindex, int exact) + struct in_addr *ifaddr, ifindex_t *ifindex, int exact) { unsigned int len; int ifaddr_next = 0; - int ifindex_next = 0; + ifindex_t ifindex_next = 0; struct ospf_interface *oi; oid *offset; @@ -1679,11 +1694,15 @@ static u_char * ospfIfEntry (struct variable *v, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { - unsigned int ifindex; + ifindex_t ifindex; struct in_addr ifaddr; struct ospf_interface *oi; struct ospf *ospf; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + ifindex = 0; memset (&ifaddr, 0, sizeof (struct in_addr)); @@ -1783,11 +1802,11 @@ ospfIfEntry (struct variable *v, oid *name, size_t *le static struct ospf_interface * ospfIfMetricLookup (struct variable *v, oid *name, size_t *length, - struct in_addr *ifaddr, unsigned int *ifindex, int exact) + struct in_addr *ifaddr, ifindex_t *ifindex, int exact) { unsigned int len; int ifaddr_next = 0; - int ifindex_next = 0; + ifindex_t ifindex_next = 0; struct ospf_interface *oi; oid *offset; int metric; @@ -1847,11 +1866,15 @@ ospfIfMetricEntry (struct variable *v, oid *name, size size_t *var_len, WriteMethod **write_method) { /* Currently we support metric 1 only. */ - unsigned int ifindex; + ifindex_t ifindex; struct in_addr ifaddr; struct ospf_interface *oi; struct ospf *ospf; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + ifindex = 0; memset (&ifaddr, 0, sizeof (struct in_addr)); @@ -1888,7 +1911,7 @@ ospfIfMetricEntry (struct variable *v, oid *name, size } return NULL; } - + struct route_table *ospf_snmp_vl_table; void @@ -1904,6 +1927,9 @@ ospf_snmp_vl_add (struct ospf_vl_data *vl_data) lp.adv_router = vl_data->vl_peer; rn = route_node_get (ospf_snmp_vl_table, (struct prefix *) &lp); + if (rn->info) + route_unlock_node (rn); + rn->info = vl_data; } @@ -2044,6 +2070,10 @@ ospfVirtIfEntry (struct variable *v, oid *name, size_t struct in_addr area_id; struct in_addr neighbor; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + memset (&area_id, 0, sizeof (struct in_addr)); memset (&neighbor, 0, sizeof (struct in_addr)); @@ -2100,10 +2130,10 @@ ospfVirtIfEntry (struct variable *v, oid *name, size_t } return NULL; } - + static struct ospf_neighbor * ospf_snmp_nbr_lookup (struct ospf *ospf, struct in_addr *nbr_addr, - unsigned int *ifindex) + ifindex_t *ifindex) { struct listnode *node, *nnode; struct ospf_interface *oi; @@ -2131,7 +2161,7 @@ ospf_snmp_nbr_lookup (struct ospf *ospf, struct in_add } static struct ospf_neighbor * -ospf_snmp_nbr_lookup_next (struct in_addr *nbr_addr, unsigned int *ifindex, +ospf_snmp_nbr_lookup_next (struct in_addr *nbr_addr, ifindex_t *ifindex, int first) { struct listnode *nn; @@ -2178,7 +2208,7 @@ ospf_snmp_nbr_lookup_next (struct in_addr *nbr_addr, u static struct ospf_neighbor * ospfNbrLookup (struct variable *v, oid *name, size_t *length, - struct in_addr *nbr_addr, unsigned int *ifindex, int exact) + struct in_addr *nbr_addr, ifindex_t *ifindex, int exact) { unsigned int len; int first; @@ -2273,10 +2303,14 @@ ospfNbrEntry (struct variable *v, oid *name, size_t *l size_t *var_len, WriteMethod **write_method) { struct in_addr nbr_addr; - unsigned int ifindex; + ifindex_t ifindex; struct ospf_neighbor *nbr; struct ospf_interface *oi; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + memset (&nbr_addr, 0, sizeof (struct in_addr)); ifindex = 0; @@ -2329,7 +2363,7 @@ ospfNbrEntry (struct variable *v, oid *name, size_t *l } return NULL; } - + static u_char * ospfVirtNbrEntry (struct variable *v, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) @@ -2339,6 +2373,10 @@ ospfVirtNbrEntry (struct variable *v, oid *name, size_ struct in_addr neighbor; struct ospf *ospf; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + memset (&area_id, 0, sizeof (struct in_addr)); memset (&neighbor, 0, sizeof (struct in_addr)); @@ -2384,7 +2422,7 @@ ospfVirtNbrEntry (struct variable *v, oid *name, size_ } return NULL; } - + static struct ospf_lsa * ospfExtLsdbLookup (struct variable *v, oid *name, size_t *length, u_char *type, struct in_addr *ls_id, struct in_addr *router_id, int exact) @@ -2487,6 +2525,10 @@ ospfExtLsdbEntry (struct variable *v, oid *name, size_ struct in_addr router_id; struct ospf *ospf; + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + type = OSPF_AS_EXTERNAL_LSA; memset (&ls_id, 0, sizeof (struct in_addr)); memset (&router_id, 0, sizeof (struct in_addr)); @@ -2533,11 +2575,15 @@ ospfExtLsdbEntry (struct variable *v, oid *name, size_ } return NULL; } - + static u_char * ospfAreaAggregateEntry (struct variable *v, oid *name, size_t *length, int exact, size_t *var_len, WriteMethod **write_method) { + if (smux_header_table(v, name, length, exact, var_len, write_method) + == MATCH_FAILED) + return NULL; + /* Return the current value of the variable */ switch (v->magic) { @@ -2565,7 +2611,7 @@ ospfAreaAggregateEntry (struct variable *v, oid *name, } return NULL; } - + /* OSPF Traps. */ #define IFSTATECHANGE 16 #define VIRTIFSTATECHANGE 1 @@ -2574,35 +2620,35 @@ ospfAreaAggregateEntry (struct variable *v, oid *name, struct trap_object ospfNbrTrapList[] = { - {ospfGeneralGroup, -2, {1, OSPFROUTERID}}, - {ospfNbrEntry, 3, {10, 1, OSPFNBRIPADDR}}, - {ospfNbrEntry, 3, {10, 1, OSPFNBRRTRID}}, - {ospfNbrEntry, 3, {10, 1, OSPFNBRSTATE}} + {-2, {1, OSPFROUTERID}}, + {3, {10, 1, OSPFNBRIPADDR}}, + {3, {10, 1, OSPFNBRRTRID}}, + {3, {10, 1, OSPFNBRSTATE}} }; struct trap_object ospfVirtNbrTrapList[] = { - {ospfGeneralGroup, -2, {1, 1}}, - {ospfVirtNbrEntry, 3, {11, 1, OSPFVIRTNBRAREA}}, - {ospfVirtNbrEntry, 3, {11, 1, OSPFVIRTNBRRTRID}}, - {ospfVirtNbrEntry, 3, {11, 1, OSPFVIRTNBRSTATE}} + {-2, {1, 1}}, + {3, {11, 1, OSPFVIRTNBRAREA}}, + {3, {11, 1, OSPFVIRTNBRRTRID}}, + {3, {11, 1, OSPFVIRTNBRSTATE}} }; struct trap_object ospfIfTrapList[] = { - {ospfGeneralGroup, -2, {1, OSPFROUTERID}}, - {ospfIfEntry, 3, {7, 1, OSPFIFIPADDRESS}}, - {ospfIfEntry, 3, {7, 1, OSPFADDRESSLESSIF}}, - {ospfIfEntry, 3, {7, 1, OSPFIFSTATE}} + {-2, {1, OSPFROUTERID}}, + {3, {7, 1, OSPFIFIPADDRESS}}, + {3, {7, 1, OSPFADDRESSLESSIF}}, + {3, {7, 1, OSPFIFSTATE}} }; struct trap_object ospfVirtIfTrapList[] = { - {ospfGeneralGroup, -2, {1, OSPFROUTERID}}, - {ospfVirtIfEntry, 3, {9, 1, OSPFVIRTIFAREAID}}, - {ospfVirtIfEntry, 3, {9, 1, OSPFVIRTIFNEIGHBOR}}, - {ospfVirtIfEntry, 3, {9, 1, OSPFVIRTIFSTATE}} + {-2, {1, OSPFROUTERID}}, + {3, {9, 1, OSPFVIRTIFAREAID}}, + {3, {9, 1, OSPFVIRTIFNEIGHBOR}}, + {3, {9, 1, OSPFVIRTIFSTATE}} }; void @@ -2618,11 +2664,13 @@ ospfTrapNbrStateChange (struct ospf_neighbor *on) oid_copy_addr (index, &(on->address.u.prefix4), IN_ADDR_SIZE); index[IN_ADDR_SIZE] = 0; - smux_trap (ospf_oid, sizeof ospf_oid / sizeof (oid), + smux_trap (ospf_variables, sizeof ospf_variables / sizeof (struct variable), + ospf_trap_oid, sizeof ospf_trap_oid / sizeof (oid), + ospf_oid, sizeof ospf_oid / sizeof (oid), index, IN_ADDR_SIZE + 1, ospfNbrTrapList, sizeof ospfNbrTrapList / sizeof (struct trap_object), - time (NULL), NBRSTATECHANGE); + NBRSTATECHANGE); } void @@ -2635,11 +2683,13 @@ ospfTrapVirtNbrStateChange (struct ospf_neighbor *on) oid_copy_addr (index, &(on->address.u.prefix4), IN_ADDR_SIZE); index[IN_ADDR_SIZE] = 0; - smux_trap (ospf_oid, sizeof ospf_oid / sizeof (oid), + smux_trap (ospf_variables, sizeof ospf_variables / sizeof (struct variable), + ospf_trap_oid, sizeof ospf_trap_oid / sizeof (oid), + ospf_oid, sizeof ospf_oid / sizeof (oid), index, IN_ADDR_SIZE + 1, ospfVirtNbrTrapList, sizeof ospfVirtNbrTrapList / sizeof (struct trap_object), - time (NULL), VIRTNBRSTATECHANGE); + VIRTNBRSTATECHANGE); } void @@ -2654,11 +2704,13 @@ ospfTrapIfStateChange (struct ospf_interface *oi) oid_copy_addr (index, &(oi->address->u.prefix4), IN_ADDR_SIZE); index[IN_ADDR_SIZE] = 0; - smux_trap (ospf_oid, sizeof ospf_oid / sizeof (oid), + smux_trap (ospf_variables, sizeof ospf_variables / sizeof (struct variable), + ospf_trap_oid, sizeof ospf_trap_oid / sizeof (oid), + ospf_oid, sizeof ospf_oid / sizeof (oid), index, IN_ADDR_SIZE + 1, ospfIfTrapList, sizeof ospfIfTrapList / sizeof (struct trap_object), - time (NULL), IFSTATECHANGE); + IFSTATECHANGE); } void @@ -2671,11 +2723,13 @@ ospfTrapVirtIfStateChange (struct ospf_interface *oi) oid_copy_addr (index, &(oi->address->u.prefix4), IN_ADDR_SIZE); index[IN_ADDR_SIZE] = 0; - smux_trap (ospf_oid, sizeof ospf_oid / sizeof (oid), + smux_trap (ospf_variables, sizeof ospf_variables / sizeof (struct variable), + ospf_trap_oid, sizeof ospf_trap_oid / sizeof (oid), + ospf_oid, sizeof ospf_oid / sizeof (oid), index, IN_ADDR_SIZE + 1, ospfVirtIfTrapList, sizeof ospfVirtIfTrapList / sizeof (struct trap_object), - time (NULL), VIRTIFSTATECHANGE); + VIRTIFSTATECHANGE); } /* Register OSPF2-MIB. */ void