Merge pull request #2974 from donaldsharp/v4_and_v6

V4 and v6
This commit is contained in:
Renato Westphal 2018-09-06 12:33:26 -03:00 committed by GitHub
commit f9ecc65d03
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 15 deletions

View File

@ -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. keyword. At present, no sharp commands will be preserved in the config.
.. index:: sharp install .. 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 <E.F.G.H|X:X::X:X> (1-1000000)
Install up to 1,000,000 (one million) /32 routes starting at ``A.B.C.D`` 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`` with specified nexthop ``E.F.G.H`` or ``X:X::X:X``. The nexthop is
and must be reachable to be installed into the kernel. The routes are a ``NEXTHOP_TYPE_IPV4`` or ``NEXTHOP_TYPE_IPV6`` and must be reachable
installed into zebra as ``ZEBRA_ROUTE_SHARP`` and can be used as part of a to be installed into the kernel. The routes are installed into zebra as
normal route redistribution. Route installation time is noted in the debug ``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 log. When zebra successfully installs a route into the kernel and SHARP
receives success notifications for all routes this is logged as well. receives success notifications for all routes this is logged as well.

View File

@ -81,13 +81,14 @@ DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd,
DEFPY (install_routes, DEFPY (install_routes,
install_routes_cmd, 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 <A.B.C.D$nexthop4|X:X::X:X$nexthop6> (1-1000000)$routes [instance (0-255)$instance]",
"Sharp routing Protocol\n" "Sharp routing Protocol\n"
"install some routes\n" "install some routes\n"
"Routes to install\n" "Routes to install\n"
"Address to start /32 generation at\n" "Address to start /32 generation at\n"
"Nexthop to use\n" "Nexthop to use(Can be an IPv4 or IPv6 address)\n"
"Nexthop address\n" "V4 Nexthop address to use\n"
"V6 Nexthop address to use\n"
"How many to create\n" "How many to create\n"
"Instance to use\n" "Instance to use\n"
"Instance\n") "Instance\n")
@ -107,8 +108,13 @@ DEFPY (install_routes,
p.prefixlen = 32; p.prefixlen = 32;
p.u.prefix4 = start; p.u.prefix4 = start;
nhop.gate.ipv4 = nexthop; if (nexthop4.s_addr != INADDR_ANY) {
nhop.type = NEXTHOP_TYPE_IPV4; 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); zlog_debug("Inserting %ld routes", routes);

View File

@ -193,7 +193,7 @@ void route_add(struct prefix *p, uint8_t instance, struct nexthop *nh)
api_nh = &api.nexthops[0]; api_nh = &api.nexthops[0];
api_nh->vrf_id = VRF_DEFAULT; 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->type = nh->type;
api_nh->ifindex = nh->ifindex; api_nh->ifindex = nh->ifindex;
api.nexthop_num = 1; api.nexthop_num = 1;

View File

@ -2209,7 +2209,6 @@ void _route_entry_dump(const char *func, union prefixconstptr pp,
union prefixconstptr src_pp, union prefixconstptr src_pp,
const struct route_entry *re) const struct route_entry *re)
{ {
const struct prefix *p = pp.p;
const struct prefix *src_p = src_pp.p; const struct prefix *src_p = src_pp.p;
bool is_srcdst = src_p && src_p->prefixlen; bool is_srcdst = src_p && src_p->prefixlen;
char straddr[PREFIX_STRLEN]; 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); re->nexthop_num, re->nexthop_active_num);
for (ALL_NEXTHOPS(re->ng, nexthop)) { for (ALL_NEXTHOPS(re->ng, nexthop)) {
inet_ntop(p->family, &nexthop->gate, straddr, INET6_ADDRSTRLEN); struct interface *ifp;
zlog_debug("%s: %s %s[%u] vrf %u with flags %s%s%s", func, 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->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) (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE)
? "ACTIVE " ? "ACTIVE "
: ""), : ""),