From: Donald Sharp Date: Wed, 11 May 2016 22:52:30 +0000 (-0400) Subject: lib: refactor connected_lookup_prefix X-Git-Tag: frr-2.0-rc1~924 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=bd40c341ee28aa73ffc1eee576a209366cf16271;p=matthieu%2Ffrr.git lib: refactor connected_lookup_prefix 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 Reviewed-by: Vivek Venkatraman Reviewed-by: Daniel Walton --- diff --git a/lib/if.c b/lib/if.c index dd70ac2d45..ebd8f5e02d 100644 --- 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; } diff --git a/lib/if.h b/lib/if.h index 9c57cf769d..78a73fadaf 100644 --- 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 *); diff --git a/ripd/ripd.c b/ripd/ripd.c index d16abcf724..eed1956f88 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -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. */