diff options
author | Donald Sharp <sharpd@cumulusnetworks.com> | 2016-08-24 11:02:22 +0200 |
---|---|---|
committer | Donald Sharp <sharpd@cumulusnetworks.com> | 2016-09-01 13:20:18 +0200 |
commit | 954a34c67ba5988557b6aa121e32c1d48e7f76a6 (patch) | |
tree | ce7e58afbdb9142db62d068e5c1e26043af33adf /zebra | |
parent | zebra: Remove unused function reference. (diff) | |
download | frr-954a34c67ba5988557b6aa121e32c1d48e7f76a6.tar.xz frr-954a34c67ba5988557b6aa121e32c1d48e7f76a6.zip |
zebra: refactor zsend_ipv[4|6]_nexthop_lookup
These two functions are functionally equivalent refactor.
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'zebra')
-rw-r--r-- | zebra/zserv.c | 94 |
1 files changed, 21 insertions, 73 deletions
diff --git a/zebra/zserv.c b/zebra/zserv.c index e72683afd..c09cb1750 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -712,96 +712,35 @@ zsend_redistribute_route (int cmd, struct zserv *client, struct prefix *p, return zebra_server_send_message(client); } -#ifdef HAVE_IPV6 static int -zsend_ipv6_nexthop_lookup (struct zserv *client, struct in6_addr *addr, - vrf_id_t vrf_id) +zsend_nexthop_lookup (struct zserv *client, afi_t afi, safi_t safi, + vrf_id_t vrf_id, union g_addr *addr) { struct stream *s; struct rib *rib; unsigned long nump; u_char num; struct nexthop *nexthop; - union g_addr gaddr = { .ipv6 = *addr }; /* Lookup nexthop. */ - rib = rib_match (AFI_IP6, SAFI_UNICAST, vrf_id, &gaddr, NULL); + rib = rib_match (afi, safi, vrf_id, addr, NULL); /* Get output stream. */ s = client->obuf; stream_reset (s); /* Fill in result. */ - zserv_create_header (s, ZEBRA_IPV6_NEXTHOP_LOOKUP, vrf_id); - stream_put (s, addr, 16); - - if (rib) + if (afi == AFI_IP) { - stream_putl (s, rib->metric); - num = 0; - nump = stream_get_endp(s); - stream_putc (s, 0); - /* Only non-recursive routes are elegible to resolve nexthop we - * are looking up. Therefore, we will just iterate over the top - * chain of nexthops. */ - for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next) - if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_FIB)) - { - stream_putc (s, nexthop->type); - switch (nexthop->type) - { - case ZEBRA_NEXTHOP_IPV6: - stream_put (s, &nexthop->gate.ipv6, 16); - break; - case ZEBRA_NEXTHOP_IPV6_IFINDEX: - stream_put (s, &nexthop->gate.ipv6, 16); - stream_putl (s, nexthop->ifindex); - break; - case ZEBRA_NEXTHOP_IFINDEX: - stream_putl (s, nexthop->ifindex); - break; - default: - /* do nothing */ - break; - } - num++; - } - stream_putc_at (s, nump, num); + zserv_create_header (s, ZEBRA_IPV4_NEXTHOP_LOOKUP, vrf_id); + stream_put_in_addr (s, &addr->ipv4); } else { - stream_putl (s, 0); - stream_putc (s, 0); + zserv_create_header (s, ZEBRA_IPV6_NEXTHOP_LOOKUP, vrf_id); + stream_put (s, &addr->ipv6, 16); } - stream_putw_at (s, 0, stream_get_endp (s)); - - return zebra_server_send_message(client); -} -#endif /* HAVE_IPV6 */ - -static int -zsend_ipv4_nexthop_lookup (struct zserv *client, struct in_addr addr, - vrf_id_t vrf_id) -{ - struct stream *s; - struct rib *rib; - unsigned long nump; - u_char num; - struct nexthop *nexthop; - union g_addr gaddr = { .ipv4 = addr }; - - /* Lookup nexthop. */ - rib = rib_match (AFI_IP, SAFI_UNICAST, vrf_id, &gaddr, NULL); - - /* Get output stream. */ - s = client->obuf; - stream_reset (s); - - /* Fill in result. */ - zserv_create_header (s, ZEBRA_IPV4_NEXTHOP_LOOKUP, vrf_id); - stream_put_in_addr (s, &addr); - if (rib) { if (IS_ZEBRA_DEBUG_PACKET && IS_ZEBRA_DEBUG_RECV) @@ -810,7 +749,7 @@ zsend_ipv4_nexthop_lookup (struct zserv *client, struct in_addr addr, num = 0; nump = stream_get_endp(s); stream_putc (s, 0); - /* Only non-recursive routes are elegible to resolve the nexthop we + /* Only non-recursive routes are elegible to resolve nexthop we * are looking up. Therefore, we will just iterate over the top * chain of nexthops. */ for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next) @@ -826,6 +765,13 @@ zsend_ipv4_nexthop_lookup (struct zserv *client, struct in_addr addr, stream_put_in_addr (s, &nexthop->gate.ipv4); stream_putl (s, nexthop->ifindex); break; + case ZEBRA_NEXTHOP_IPV6: + stream_put (s, &nexthop->gate.ipv6, 16); + break; + case ZEBRA_NEXTHOP_IPV6_IFINDEX: + stream_put (s, &nexthop->gate.ipv6, 16); + stream_putl (s, nexthop->ifindex); + break; case ZEBRA_NEXTHOP_IFINDEX: stream_putl (s, nexthop->ifindex); break; @@ -846,7 +792,7 @@ zsend_ipv4_nexthop_lookup (struct zserv *client, struct in_addr addr, } stream_putw_at (s, 0, stream_get_endp (s)); - + return zebra_server_send_message(client); } @@ -1387,7 +1333,8 @@ zread_ipv4_nexthop_lookup (struct zserv *client, u_short length, if (IS_ZEBRA_DEBUG_PACKET && IS_ZEBRA_DEBUG_RECV) zlog_debug("%s: looking up %s", __func__, inet_ntop (AF_INET, &addr, buf, BUFSIZ)); - return zsend_ipv4_nexthop_lookup (client, addr, zvrf->vrf_id); + return zsend_nexthop_lookup (client, AFI_IP, SAFI_UNICAST, + zvrf->vrf_id, (union g_addr *)&addr); } /* MRIB Nexthop lookup for IPv4. */ @@ -1759,7 +1706,8 @@ zread_ipv6_nexthop_lookup (struct zserv *client, u_short length, zlog_debug("%s: looking up %s", __func__, inet_ntop (AF_INET6, &addr, buf, BUFSIZ)); - return zsend_ipv6_nexthop_lookup (client, &addr, zvrf->vrf_id); + return zsend_nexthop_lookup (client, AFI_IP6, SAFI_UNICAST, + zvrf->vrf_id, (union g_addr *)&addr); } /* Register zebra server router-id information. Send current router-id */ |