]> git.proxmox.com Git - mirror_frr.git/blobdiff - ospf6d/ospf6_snmp.c
zebra: The mask and sin_mask are a bit redundant for kernel_rtm
[mirror_frr.git] / ospf6d / ospf6_snmp.c
index 3affa12a92dd76731b3bd7b0d99ef47ea74723bf..376950e84a25f46b8cf8992b56325adbd59a4c43 100644 (file)
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with GNU Zebra; see the file COPYING.  If not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <zebra.h>
@@ -210,16 +209,16 @@ static oid ospfv3_oid[] = {OSPFv3MIB};
 static oid ospfv3_trap_oid[] = {OSPFv3MIB, 0};
 
 /* Hook functions. */
-static u_char *ospfv3GeneralGroup(struct variable *, oid *, size_t *, int,
+static uint8_t *ospfv3GeneralGroup(struct variable *, oid *, size_t *, int,
+                                  size_t *, WriteMethod **);
+static uint8_t *ospfv3AreaEntry(struct variable *, oid *, size_t *, int,
+                               size_t *, WriteMethod **);
+static uint8_t *ospfv3WwLsdbEntry(struct variable *, oid *, size_t *, int,
                                  size_t *, WriteMethod **);
-static u_char *ospfv3AreaEntry(struct variable *, oid *, size_t *, int,
+static uint8_t *ospfv3NbrEntry(struct variable *, oid *, size_t *, int,
                               size_t *, WriteMethod **);
-static u_char *ospfv3WwLsdbEntry(struct variable *, oid *, size_t *, int,
-                                size_t *, WriteMethod **);
-static u_char *ospfv3NbrEntry(struct variable *, oid *, size_t *, int, size_t *,
+static uint8_t *ospfv3IfEntry(struct variable *, oid *, size_t *, int, size_t *,
                              WriteMethod **);
-static u_char *ospfv3IfEntry(struct variable *, oid *, size_t *, int, size_t *,
-                            WriteMethod **);
 
 static struct variable ospfv3_variables[] = {
        /* OSPF general variables */
@@ -632,12 +631,12 @@ static struct variable ospfv3_variables[] = {
         {1, 9, 1, 15}},
 };
 
-static u_char *ospfv3GeneralGroup(struct variable *v, oid *name, size_t *length,
-                                 int exact, size_t *var_len,
-                                 WriteMethod **write_method)
+static uint8_t *ospfv3GeneralGroup(struct variable *v, oid *name,
+                                  size_t *length, int exact, size_t *var_len,
+                                  WriteMethod **write_method)
 {
-       u_int16_t sum;
-       u_int32_t count;
+       uint16_t sum;
+       uint32_t count;
        struct ospf6_lsa *lsa = NULL;
 
        /* Check whether the instance identifier is valid */
@@ -679,8 +678,8 @@ static u_char *ospfv3GeneralGroup(struct variable *v, oid *name, size_t *length,
                return SNMP_INTEGER(0);
        case OSPFv3ASSCOPELSACHECKSUMSUM:
                if (ospf6) {
-                       for (sum = 0, lsa = ospf6_lsdb_head(ospf6->lsdb); lsa;
-                            lsa = ospf6_lsdb_next(lsa))
+                       sum = 0;
+                       for (ALL_LSDB(ospf6->lsdb, lsa))
                                sum += ntohs(lsa->header->checksum);
                        return SNMP_INTEGER(sum);
                }
@@ -693,12 +692,10 @@ static u_char *ospfv3GeneralGroup(struct variable *v, oid *name, size_t *length,
                        0); /* Don't know where to get this value... */
        case OSPFv3EXTLSACOUNT:
                if (ospf6) {
-                       for (count = 0,
-                           lsa = ospf6_lsdb_type_head(
-                                   htons(OSPF6_LSTYPE_AS_EXTERNAL),
-                                   ospf6->lsdb);
-                            lsa; lsa = ospf6_lsdb_type_next(
-                                         htons(OSPF6_LSTYPE_AS_EXTERNAL), lsa))
+                       count = 0;
+                       for (ALL_LSDB_TYPED(ospf6->lsdb,
+                                           htons(OSPF6_LSTYPE_AS_EXTERNAL),
+                                           lsa))
                                count += 1;
                        return SNMP_INTEGER(count);
                }
@@ -713,6 +710,7 @@ static u_char *ospfv3GeneralGroup(struct variable *v, oid *name, size_t *length,
                if (ospf6)
                        return SNMP_INTEGER(ospf6->ref_bandwidth);
        /* Otherwise, like for "not implemented". */
+       /* fallthru */
        case OSPFv3RESTARTSUPPORT:
        case OSPFv3RESTARTINTERVAL:
        case OSPFv3RESTARTSTRICTLSACHECKING:
@@ -730,15 +728,15 @@ static u_char *ospfv3GeneralGroup(struct variable *v, oid *name, size_t *length,
        return NULL;
 }
 
-static u_char *ospfv3AreaEntry(struct variable *v, oid *name, size_t *length,
-                              int exact, size_t *var_len,
-                              WriteMethod **write_method)
+static uint8_t *ospfv3AreaEntry(struct variable *v, oid *name, size_t *length,
+                               int exact, size_t *var_len,
+                               WriteMethod **write_method)
 {
        struct ospf6_area *oa, *area = NULL;
        struct ospf6_lsa *lsa = NULL;
-       u_int32_t area_id = 0;
-       u_int32_t count;
-       u_int16_t sum;
+       uint32_t area_id = 0;
+       uint32_t count;
+       uint16_t sum;
        struct listnode *node;
        unsigned int len;
        char a[16];
@@ -760,7 +758,7 @@ static u_char *ospfv3AreaEntry(struct variable *v, oid *name, size_t *length,
 
        inet_ntop(AF_INET, &area_id, a, sizeof(a));
        zlog_debug("SNMP access by area: %s, exact=%d len=%d length=%lu", a,
-                  exact, len, (u_long)*length);
+                  exact, len, (unsigned long)*length);
 
        for (ALL_LIST_ELEMENTS_RO(ospf6->area_list, node, oa)) {
                if (area == NULL) {
@@ -781,7 +779,7 @@ static u_char *ospfv3AreaEntry(struct variable *v, oid *name, size_t *length,
 
        inet_ntop(AF_INET, &area->area_id, a, sizeof(a));
        zlog_debug("SNMP found area: %s, exact=%d len=%d length=%lu", a, exact,
-                  len, (u_long)*length);
+                  len, (unsigned long)*length);
 
        switch (v->magic) {
        case OSPFv3IMPORTASEXTERN:
@@ -809,8 +807,8 @@ static u_char *ospfv3AreaEntry(struct variable *v, oid *name, size_t *length,
        case OSPFv3AREASCOPELSACOUNT:
                return SNMP_INTEGER(area->lsdb->count);
        case OSPFv3AREASCOPELSACKSUMSUM:
-               for (sum = 0, lsa = ospf6_lsdb_head(area->lsdb); lsa;
-                    lsa = ospf6_lsdb_next(lsa))
+               sum = 0;
+               for (ALL_LSDB(area->lsdb, lsa))
                        sum += ntohs(lsa->header->checksum);
                return SNMP_INTEGER(sum);
        case OSPFv3AREASUMMARY:
@@ -835,14 +833,15 @@ static int if_icmp_func(struct interface *ifp1, struct interface *ifp2)
        return (ifp1->ifindex - ifp2->ifindex);
 }
 
-static u_char *ospfv3WwLsdbEntry(struct variable *v, oid *name, size_t *length,
-                                int exact, size_t *var_len,
-                                WriteMethod **write_method)
+static uint8_t *ospfv3WwLsdbEntry(struct variable *v, oid *name, size_t *length,
+                                 int exact, size_t *var_len,
+                                 WriteMethod **write_method)
 {
+       struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
        struct ospf6_lsa *lsa = NULL;
        ifindex_t ifindex;
        uint32_t area_id, id, instid, adv_router;
-       u_int16_t type;
+       uint16_t type;
        int len;
        oid *offset;
        int offsetlen;
@@ -915,7 +914,7 @@ static u_char *ospfv3WwLsdbEntry(struct variable *v, oid *name, size_t *length,
        if (len)
                id = htonl(*offset);
        offset += len;
-       offsetlen -= len;
+       // offsetlen -= len;  // Add back in if we need it again
 
        if (exact) {
                if (v->magic & OSPFv3WWASTABLE) {
@@ -957,8 +956,7 @@ static u_char *ospfv3WwLsdbEntry(struct variable *v, oid *name, size_t *length,
                        if (!ifslist)
                                return NULL;
                        ifslist->cmp = (int (*)(void *, void *))if_icmp_func;
-                       for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), node,
-                                                 iif))
+                       FOR_ALL_INTERFACES (vrf, iif)
                                listnode_add_sort(ifslist, iif);
 
                        for (ALL_LIST_ELEMENTS_RO(ifslist, node, iif)) {
@@ -1029,7 +1027,7 @@ static u_char *ospfv3WwLsdbEntry(struct variable *v, oid *name, size_t *length,
                break;
        case OSPFv3WWLSDBADVERTISEMENT:
                *var_len = ntohs(lsa->header->length);
-               return (u_char *)lsa->header;
+               return (uint8_t *)lsa->header;
                break;
        case OSPFv3WWLSDBTYPEKNOWN:
                return SNMP_INTEGER(OSPF6_LSA_IS_KNOWN(lsa->header->type)
@@ -1040,10 +1038,11 @@ static u_char *ospfv3WwLsdbEntry(struct variable *v, oid *name, size_t *length,
        return NULL;
 }
 
-static u_char *ospfv3IfEntry(struct variable *v, oid *name, size_t *length,
-                            int exact, size_t *var_len,
-                            WriteMethod **write_method)
+static uint8_t *ospfv3IfEntry(struct variable *v, oid *name, size_t *length,
+                             int exact, size_t *var_len,
+                             WriteMethod **write_method)
 {
+       struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
        ifindex_t ifindex = 0;
        unsigned int instid = 0;
        struct ospf6_interface *oi = NULL;
@@ -1053,7 +1052,7 @@ static u_char *ospfv3IfEntry(struct variable *v, oid *name, size_t *length,
        struct list *ifslist;
        oid *offset;
        int offsetlen, len;
-       u_int32_t sum;
+       uint32_t sum;
 
        if (smux_header_table(v, name, length, exact, var_len, write_method)
            == MATCH_FAILED)
@@ -1081,8 +1080,8 @@ static u_char *ospfv3IfEntry(struct variable *v, oid *name, size_t *length,
        len = (offsetlen < 1 ? 0 : 1);
        if (len)
                instid = *offset;
-       offset += len;
-       offsetlen -= len;
+       // offset += len; // Add back in if we ever start using again
+       // offsetlen -= len;
 
        if (exact) {
                oi = ospf6_interface_lookup_by_ifindex(ifindex);
@@ -1094,7 +1093,7 @@ static u_char *ospfv3IfEntry(struct variable *v, oid *name, size_t *length,
                if (!ifslist)
                        return NULL;
                ifslist->cmp = (int (*)(void *, void *))if_icmp_func;
-               for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), i, iif))
+               FOR_ALL_INTERFACES (vrf, iif)
                        listnode_add_sort(ifslist, iif);
 
                for (ALL_LIST_ELEMENTS_RO(ifslist, i, iif)) {
@@ -1171,8 +1170,8 @@ static u_char *ospfv3IfEntry(struct variable *v, oid *name, size_t *length,
        case OSPFv3IFLINKSCOPELSACOUNT:
                return SNMP_INTEGER(oi->lsdb->count);
        case OSPFv3IFLINKLSACKSUMSUM:
-               for (sum = 0, lsa = ospf6_lsdb_head(oi->lsdb); lsa;
-                    lsa = ospf6_lsdb_next(lsa))
+               sum = 0;
+               for (ALL_LSDB(oi->lsdb, lsa))
                        sum += ntohs(lsa->header->checksum);
                return SNMP_INTEGER(sum);
        case OSPFv3IFDEMANDNBRPROBE:
@@ -1192,10 +1191,11 @@ static u_char *ospfv3IfEntry(struct variable *v, oid *name, size_t *length,
        return NULL;
 }
 
-static u_char *ospfv3NbrEntry(struct variable *v, oid *name, size_t *length,
-                             int exact, size_t *var_len,
-                             WriteMethod **write_method)
+static uint8_t *ospfv3NbrEntry(struct variable *v, oid *name, size_t *length,
+                              int exact, size_t *var_len,
+                              WriteMethod **write_method)
 {
+       struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT);
        ifindex_t ifindex = 0;
        unsigned int instid, rtrid;
        struct ospf6_interface *oi = NULL;
@@ -1241,8 +1241,8 @@ static u_char *ospfv3NbrEntry(struct variable *v, oid *name, size_t *length,
        len = (offsetlen < 1 ? 0 : 1);
        if (len)
                rtrid = htonl(*offset);
-       offset += len;
-       offsetlen -= len;
+       // offset += len; // Add back in if we ever start looking at data
+       // offsetlen -= len;
 
        if (exact) {
                oi = ospf6_interface_lookup_by_ifindex(ifindex);
@@ -1255,7 +1255,7 @@ static u_char *ospfv3NbrEntry(struct variable *v, oid *name, size_t *length,
                if (!ifslist)
                        return NULL;
                ifslist->cmp = (int (*)(void *, void *))if_icmp_func;
-               for (ALL_LIST_ELEMENTS_RO(vrf_iflist(VRF_DEFAULT), i, iif))
+               FOR_ALL_INTERFACES (vrf, iif)
                        listnode_add_sort(ifslist, iif);
 
                for (ALL_LIST_ELEMENTS_RO(ifslist, i, iif)) {
@@ -1301,7 +1301,7 @@ static u_char *ospfv3NbrEntry(struct variable *v, oid *name, size_t *length,
                return SNMP_INTEGER(2); /* IPv6 only */
        case OSPFv3NBRADDRESS:
                *var_len = sizeof(struct in6_addr);
-               return (u_char *)&on->linklocal_addr;
+               return (uint8_t *)&on->linklocal_addr;
        case OSPFv3NBROPTIONS:
                return SNMP_INTEGER(on->options[2]);
        case OSPFv3NBRPRIORITY: