]> git.puffer.fish Git - matthieu/frr.git/commitdiff
snmp: let handlers accept OID from a lesser prefix
authorVincent Bernat <bernat@luffy.cx>
Thu, 31 May 2012 11:30:28 +0000 (13:30 +0200)
committerVincent Bernat <bernat@luffy.cx>
Mon, 25 Jun 2012 17:03:23 +0000 (19:03 +0200)
Most table handlers do not expect to be given an OID whose prefix is
outside what they can handle. This is not a problem with the SMUX
implementation since it always correct the OID such that the prefix
matches. However, this is not the case for the AgentX
implementation. A new function, smux_header_table() is used to do this
normalization.

bgpd/bgp_snmp.c
lib/smux.h
lib/snmp.c
ospf6d/ospf6_snmp.c
ospfd/ospf_snmp.c
ripd/rip_snmp.c
zebra/zebra_snmp.c

index 36fd4ef44d127561c90d1d12dc51c53945749e6a..c8f2aa54b00378dd0f3629008d093b4c589eb654 100644 (file)
@@ -455,7 +455,9 @@ bgpPeerTable (struct variable *v, oid name[], size_t *length,
   static struct in_addr addr;
   struct peer *peer;
 
-  *write_method = NULL;
+  if (smux_header_table(v, name, length, exact, var_len, write_method)
+      == MATCH_FAILED)
+    return NULL;
   memset (&addr, 0, sizeof (struct in_addr));
 
   peer = bgpPeerTable_lookup (v, name, length, &addr, exact);
@@ -765,6 +767,9 @@ bgp4PathAttrTable (struct variable *v, oid name[], size_t *length,
   if (! bgp)
     return NULL;
 
+  if (smux_header_table(v, name, length, exact, var_len, write_method)
+      == MATCH_FAILED)
+    return NULL;
   memset (&addr, 0, sizeof (struct prefix_ipv4));
 
   binfo = bgp4PathAttrLookup (v, name, length, bgp, &addr, exact);
index b29fdc72bce3b9dcd177fec9da9897c81460a9fb..72b4eaf09934d01cd1f7f4d533623fa85f2cf410 100644 (file)
@@ -75,6 +75,8 @@ extern void smux_register_mib(const char *, struct variable *,
                               size_t, int, oid [], size_t);
 extern int smux_header_generic (struct variable *, oid [], size_t *, 
                                 int, size_t *, WriteMethod **);
+extern int smux_header_table (struct variable *, oid *, size_t *, 
+                             int, size_t *, WriteMethod **);
 
 /* For traps, three OID are provided:
 
index d7b1d95396272662bab375bd48348f5c899db299..79595a1ea2175d81d082559f0db1868f29300a39 100644 (file)
@@ -110,4 +110,24 @@ smux_header_generic (struct variable *v, oid *name, size_t *length, int exact,
 
   return MATCH_SUCCEEDED;
 }
+
+int
+smux_header_table (struct variable *v, oid *name, size_t *length, int exact,
+                  size_t *var_len, WriteMethod **write_method)
+{
+  /* If the requested OID name is less than OID prefix we
+     handle, adjust it to our prefix. */
+  if ((oid_compare (name, *length, v->name, v->namelen)) < 0)
+    {
+      if (exact)
+       return MATCH_FAILED;
+      oid_copy(name, v->name, v->namelen);
+      *length = v->namelen;
+    }
+
+  *write_method = 0;
+  *var_len = sizeof(long);
+
+  return MATCH_SUCCEEDED;
+}
 #endif /* HAVE_SNMP */
index 11b733b8cda0c6fb8126e3d1ad1467c2aaa2837a..d252f549f09c7b54388019cb2fbc5ab231926960 100644 (file)
@@ -306,6 +306,10 @@ ospfv3AreaEntry (struct variable *v, oid *name, size_t *length,
   if (ospf6 == NULL)
     return NULL;
 
+  if (smux_header_table(v, name, length, exact, var_len, write_method)
+      == MATCH_FAILED)
+    return NULL;
+
   len = *length - v->namelen;
   len = (len >= sizeof (u_int32_t) ? sizeof (u_int32_t) : 0);
   if (exact && len != sizeof (u_int32_t))
@@ -372,6 +376,10 @@ ospfv3AreaLsdbEntry (struct variable *v, oid *name, size_t *length,
   struct ospf6_area *oa;
   struct listnode *node;
 
+  if (smux_header_table(v, name, length, exact, var_len, write_method)
+      == MATCH_FAILED)
+    return NULL;
+
   memset (&area_id, 0, sizeof (struct in_addr));
   type = 0;
   memset (&id, 0, sizeof (struct in_addr));
index c8416de6fbe391942f97937af4349f677dec3aef..1daf0d6aa5b72c12de3ebd8f772f8190d547f53d 100644 (file)
@@ -704,6 +704,10 @@ ospfAreaEntry (struct variable *v, oid *name, size_t *length, int exact,
   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);
@@ -847,6 +851,10 @@ ospfStubAreaEntry (struct variable *v, oid *name, size_t *length,
   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);
@@ -1078,6 +1086,10 @@ ospfLsdbEntry (struct variable *v, oid *name, size_t *length, int exact,
   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 } */
 
@@ -1240,6 +1252,10 @@ ospfAreaRangeEntry (struct variable *v, oid *name, size_t *length, int exact,
   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)
@@ -1344,6 +1360,10 @@ ospfHostEntry (struct variable *v, oid *name, size_t *length, int exact,
   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)
@@ -1679,6 +1699,10 @@ ospfIfEntry (struct variable *v, oid *name, size_t *length, int exact,
   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));
 
@@ -1847,6 +1871,10 @@ ospfIfMetricEntry (struct variable *v, oid *name, size_t *length, int exact,
   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));
 
@@ -2039,6 +2067,10 @@ ospfVirtIfEntry (struct variable *v, oid *name, size_t *length, int exact,
   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));
 
@@ -2272,6 +2304,10 @@ ospfNbrEntry (struct variable *v, oid *name, size_t *length, int exact,
   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;
   
@@ -2334,6 +2370,10 @@ ospfVirtNbrEntry (struct variable *v, oid *name, size_t *length, int exact,
   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));
 
@@ -2482,6 +2522,10 @@ ospfExtLsdbEntry (struct variable *v, oid *name, size_t *length, int exact,
   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,6 +2577,10 @@ 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) 
     {
index 803ac856a19de35d568120cce88e0c4d3899328b..090ebfae2efd2a40fce2036ebfe22cb610aa82e0 100644 (file)
@@ -345,6 +345,10 @@ rip2IfStatEntry (struct variable *v, oid name[], size_t *length,
   static struct in_addr addr;
   static long valid = SNMP_VALID;
 
+  if (smux_header_table(v, name, length, exact, var_len, write_method)
+      == MATCH_FAILED)
+    return NULL;
+
   memset (&addr, 0, sizeof (struct in_addr));
   
   /* Lookup interface. */
@@ -448,6 +452,10 @@ rip2IfConfAddress (struct variable *v, oid name[], size_t *length,
   struct interface *ifp;
   struct rip_interface *ri;
 
+  if (smux_header_table(v, name, length, exact, val_len, write_method)
+      == MATCH_FAILED)
+    return NULL;
+
   memset (&addr, 0, sizeof (struct in_addr));
   
   /* Lookup interface. */
@@ -518,6 +526,10 @@ rip2PeerTable (struct variable *v, oid name[], size_t *length,
 
   struct rip_peer *peer;
 
+  if (smux_header_table(v, name, length, exact, val_len, write_method)
+      == MATCH_FAILED)
+    return NULL;
+
   memset (&addr, 0, sizeof (struct in_addr));
   
   /* Lookup interface. */
index 3dbfb5875192956c074bf7cb66cc6429bc2e1e10..f52bbcb8dbed6866e3653f205bd69ef75085b23f 100644 (file)
@@ -451,6 +451,10 @@ ipFwTable (struct variable *v, oid objid[], size_t *objid_len,
   static struct in_addr netmask;
   struct nexthop *nexthop;
 
+  if (smux_header_table(v, objid, objid_len, exact, val_len, write_method)
+      == MATCH_FAILED)
+    return NULL;
+
   get_fwtable_route_node(v, objid, objid_len, exact, &np, &rib);
   if (!np)
     return NULL;
@@ -549,6 +553,10 @@ static u_char *
 ipCidrTable (struct variable *v, oid objid[], size_t *objid_len,
             int exact, size_t *val_len, WriteMethod **write_method)
 {
+  if (smux_header_table(v, objid, objid_len, exact, val_len, write_method)
+      == MATCH_FAILED)
+    return NULL;
+
   switch (v->magic)
     {
     case IPCIDRROUTEDEST: