From 2d68a0f2dac8a33651595345ccf9613d0bc45e01 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 4 Sep 2018 20:56:42 -0400 Subject: [PATCH 1/3] zebra: Fix _route_entry_dump to handle nexthop family as appropriate The _route_entry_dump function was not handling the nexthop as passed in from an upper level protocol appropriate and as such not displaying the v4/v6 nexthop right in the case where we have both going. Additionally dump the nexthop vrf as well. Signed-off-by: Donald Sharp --- zebra/zebra_rib.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index ab07549ec2..49d2f26943 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -2209,7 +2209,6 @@ void _route_entry_dump(const char *func, union prefixconstptr pp, union prefixconstptr src_pp, const struct route_entry *re) { - const struct prefix *p = pp.p; const struct prefix *src_p = src_pp.p; bool is_srcdst = src_p && src_p->prefixlen; char straddr[PREFIX_STRLEN]; @@ -2232,10 +2231,34 @@ void _route_entry_dump(const char *func, union prefixconstptr pp, re->nexthop_num, re->nexthop_active_num); for (ALL_NEXTHOPS(re->ng, nexthop)) { - inet_ntop(p->family, &nexthop->gate, straddr, INET6_ADDRSTRLEN); - zlog_debug("%s: %s %s[%u] vrf %u with flags %s%s%s", func, + struct interface *ifp; + struct vrf *vrf = vrf_lookup_by_id(nexthop->vrf_id); + + switch (nexthop->type) { + case NEXTHOP_TYPE_BLACKHOLE: + sprintf(straddr, "Blackhole"); + break; + case NEXTHOP_TYPE_IFINDEX: + ifp = if_lookup_by_index(nexthop->ifindex, + nexthop->vrf_id); + sprintf(straddr, "%s", ifp ? ifp->name : "Unknown"); + break; + case NEXTHOP_TYPE_IPV4: + /* fallthrough */ + case NEXTHOP_TYPE_IPV4_IFINDEX: + inet_ntop(AF_INET, &nexthop->gate, straddr, + INET6_ADDRSTRLEN); + break; + case NEXTHOP_TYPE_IPV6: + case NEXTHOP_TYPE_IPV6_IFINDEX: + inet_ntop(AF_INET6, &nexthop->gate, straddr, + INET6_ADDRSTRLEN); + break; + } + zlog_debug("%s: %s %s[%u] vrf %s(%u) with flags %s%s%s", func, (nexthop->rparent ? " NH" : "NH"), straddr, - nexthop->ifindex, nexthop->vrf_id, + nexthop->ifindex, vrf ? vrf->name : "Unknown", + nexthop->vrf_id, (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE) ? "ACTIVE " : ""), From ba041beaae736a509a1e288e749703eed307935b Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 4 Sep 2018 21:00:04 -0400 Subject: [PATCH 2/3] sharpd: Modify route install to allow v6 nexthops Allow the user to create a v4 route with a v6 nexthop. Signed-off-by: Donald Sharp --- sharpd/sharp_vty.c | 16 +++++++++++----- sharpd/sharp_zebra.c | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c index 956da9d4ed..9462eb575c 100644 --- a/sharpd/sharp_vty.c +++ b/sharpd/sharp_vty.c @@ -81,13 +81,14 @@ DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd, DEFPY (install_routes, install_routes_cmd, - "sharp install routes A.B.C.D$start nexthop A.B.C.D$nexthop (1-1000000)$routes [instance (0-255)$instance]", + "sharp install routes A.B.C.D$start nexthop (1-1000000)$routes [instance (0-255)$instance]", "Sharp routing Protocol\n" "install some routes\n" "Routes to install\n" "Address to start /32 generation at\n" - "Nexthop to use\n" - "Nexthop address\n" + "Nexthop to use(Can be an IPv4 or IPv6 address)\n" + "V4 Nexthop address to use\n" + "V6 Nexthop address to use\n" "How many to create\n" "Instance to use\n" "Instance\n") @@ -107,8 +108,13 @@ DEFPY (install_routes, p.prefixlen = 32; p.u.prefix4 = start; - nhop.gate.ipv4 = nexthop; - nhop.type = NEXTHOP_TYPE_IPV4; + if (nexthop4.s_addr != INADDR_ANY) { + nhop.gate.ipv4 = nexthop4; + nhop.type = NEXTHOP_TYPE_IPV4; + } else { + memcpy(&nhop.gate.ipv6, &nexthop6, IPV6_MAX_BYTELEN); + nhop.type = NEXTHOP_TYPE_IPV6; + } zlog_debug("Inserting %ld routes", routes); diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index fcb555170b..286f320874 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -193,7 +193,7 @@ void route_add(struct prefix *p, uint8_t instance, struct nexthop *nh) api_nh = &api.nexthops[0]; api_nh->vrf_id = VRF_DEFAULT; - api_nh->gate.ipv4 = nh->gate.ipv4; + api_nh->gate = nh->gate; api_nh->type = nh->type; api_nh->ifindex = nh->ifindex; api.nexthop_num = 1; From fa83edf08b224a98b40201b8d04607170f674b5c Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 4 Sep 2018 21:02:33 -0400 Subject: [PATCH 3/3] doc: Update sharp documentation Update the sharp documentation to note v6 nexthops are able to be installed now. Signed-off-by: Donald Sharp --- doc/user/sharp.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/doc/user/sharp.rst b/doc/user/sharp.rst index e27da63b53..8831c0159b 100644 --- a/doc/user/sharp.rst +++ b/doc/user/sharp.rst @@ -33,13 +33,14 @@ All sharp commands are under the enable node and preceeded by the ``sharp`` keyword. At present, no sharp commands will be preserved in the config. .. index:: sharp install -.. clicmd:: sharp install routes A.B.C.D nexthop E.F.G.H (1-1000000) +.. clicmd:: sharp install routes A.B.C.D nexthop (1-1000000) Install up to 1,000,000 (one million) /32 routes starting at ``A.B.C.D`` - with specified nexthop ``E.F.G.H``. The nexthop is a ``NEXTHOP_TYPE_IPV4`` - and must be reachable to be installed into the kernel. The routes are - installed into zebra as ``ZEBRA_ROUTE_SHARP`` and can be used as part of a - normal route redistribution. Route installation time is noted in the debug + with specified nexthop ``E.F.G.H`` or ``X:X::X:X``. The nexthop is + a ``NEXTHOP_TYPE_IPV4`` or ``NEXTHOP_TYPE_IPV6`` and must be reachable + to be installed into the kernel. The routes are installed into zebra as + ``ZEBRA_ROUTE_SHARP`` and can be used as part of a normal route + redistribution. Route installation time is noted in the debug log. When zebra successfully installs a route into the kernel and SHARP receives success notifications for all routes this is logged as well.