]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: refactor connected_lookup_prefix
authorDonald Sharp <sharpd@cumulusnetworks.com>
Wed, 11 May 2016 22:52:30 +0000 (18:52 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 12 May 2016 14:03:44 +0000 (10:03 -0400)
The connected_lookup_address function should really
be a connected_lookup_prefix function.  Refactor
the code to use it.

Ticket: CM-10890
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Reviewed-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
Reviewed-by: Daniel Walton <dwalton@cumulusnetworks.com>
lib/if.c
lib/if.h
ripd/ripd.c

index dd70ac2d45345e1106e963cf40542b08added78b..ebd8f5e02db656d89f67e71d7d45dd4c681d254c 100644 (file)
--- a/lib/if.c
+++ b/lib/if.c
@@ -1103,26 +1103,21 @@ connected_delete_by_prefix (struct interface *ifp, struct prefix *p)
   return NULL;
 }
 
-/* Find the IPv4 address on our side that will be used when packets
+/* Find the address on our side that will be used when packets
    are sent to dst. */
 struct connected *
-connected_lookup_address (struct interface *ifp, struct in_addr dst)
+connected_lookup_prefix (struct interface *ifp, struct prefix *addr)
 {
-  struct prefix addr;
   struct listnode *cnode;
   struct connected *c;
   struct connected *match;
 
-  addr.family = AF_INET;
-  addr.u.prefix4 = dst;
-  addr.prefixlen = IPV4_MAX_BITLEN;
-
   match = NULL;
 
   for (ALL_LIST_ELEMENTS_RO (ifp->connected, cnode, c))
     {
-      if (c->address && (c->address->family == AF_INET) &&
-         prefix_match(CONNECTED_PREFIX(c), &addr) &&
+      if (c->address && (c->address->family == addr->family) &&
+         prefix_match(CONNECTED_PREFIX(c), addr) &&
          (!match || (c->address->prefixlen > match->address->prefixlen)))
        match = c;
     }
index 9c57cf769d33ccf5aa4e36f02f8a8c8099f85950..78a73fadaf15a4671cef61f9061037b0f728ceee 100644 (file)
--- a/lib/if.h
+++ b/lib/if.h
@@ -350,8 +350,8 @@ extern struct connected  *connected_add_by_prefix (struct interface *,
                                             struct prefix *);
 extern struct connected  *connected_delete_by_prefix (struct interface *, 
                                                struct prefix *);
-extern struct connected  *connected_lookup_address (struct interface *, 
-                                             struct in_addr);
+extern struct connected  *connected_lookup_prefix (struct interface *,
+                                                   struct prefix *);
 extern struct nbr_connected *nbr_connected_new (void);
 extern void nbr_connected_free (struct nbr_connected *);
 struct nbr_connected *nbr_connected_check (struct interface *, struct prefix *);
index d16abcf72474a97de75c2ead182d7cff2a2c338f..eed1956f88b7d76ba171c102c7db183fef6ed00a 100644 (file)
@@ -1817,6 +1817,7 @@ rip_read (struct thread *t)
   struct interface *ifp;
   struct connected *ifc;
   struct rip_interface *ri;
+  struct prefix p;
 
   /* Fetch socket then register myself. */
   sock = THREAD_FD (t);
@@ -1861,8 +1862,12 @@ rip_read (struct thread *t)
                 inet_ntoa(from.sin_addr), ntohs (from.sin_port));
       return -1;
     }
-  
-  ifc = connected_lookup_address (ifp, from.sin_addr);
+
+  p.family = AF_INET;
+  p.u.prefix4 = from.sin_addr;
+  p.prefixlen = IPV4_MAX_BITLEN;
+
+  ifc = connected_lookup_prefix (ifp, &p);
   
   if (ifc == NULL)
     {
@@ -2476,7 +2481,7 @@ rip_update_process (int route_type)
   struct rip_interface *ri;
   struct route_node *rp;
   struct sockaddr_in to;
-  struct prefix_ipv4 *p;
+  struct prefix *p;
 
   /* Send RIP update to each interface. */
   for (ALL_LIST_ELEMENTS_RO (vrf_iflist (VRF_DEFAULT), node, ifp))
@@ -2526,26 +2531,26 @@ rip_update_process (int route_type)
   for (rp = route_top (rip->neighbor); rp; rp = route_next (rp))
     if (rp->info != NULL)
       {
-       p = (struct prefix_ipv4 *) &rp->p;
+       p = &rp->p;
 
-       ifp = if_lookup_address ((void *)&p->prefix, AF_INET);
+       ifp = if_lookup_prefix (p);
        if (! ifp)
          {
            zlog_warn ("Neighbor %s doesnt have connected interface!",
-                      inet_ntoa (p->prefix));
+                      inet_ntoa (p->u.prefix4));
            continue;
          }
         
-        if ( (connected = connected_lookup_address (ifp, p->prefix)) == NULL)
+        if ( (connected = connected_lookup_prefix (ifp, p)) == NULL)
           {
             zlog_warn ("Neighbor %s doesnt have connected network",
-                       inet_ntoa (p->prefix));
+                       inet_ntoa (p->u.prefix4));
             continue;
           }
         
        /* Set destination address and port */
        memset (&to, 0, sizeof (struct sockaddr_in));
-       to.sin_addr = p->prefix;
+       to.sin_addr = p->u.prefix4;
        to.sin_port = htons (RIP_PORT_DEFAULT);
 
        /* RIP version is rip's configuration. */