Merge pull request #1093 from opensourcerouting/static_blackhole_display

zebra: display static blackhole routes consistently
This commit is contained in:
Daniel Walton 2017-09-05 12:54:05 -04:00 committed by GitHub
commit 41bcc4a91e
3 changed files with 46 additions and 20 deletions

View File

@ -45,6 +45,7 @@ void static_install_route(afi_t afi, safi_t safi, struct prefix *p,
struct route_table *table; struct route_table *table;
struct prefix nh_p; struct prefix nh_p;
struct nexthop *nexthop = NULL; struct nexthop *nexthop = NULL;
enum blackhole_type bh_type = 0;
/* Lookup table. */ /* Lookup table. */
table = zebra_vrf_table(afi, safi, si->vrf_id); table = zebra_vrf_table(afi, safi, si->vrf_id);
@ -52,6 +53,17 @@ void static_install_route(afi_t afi, safi_t safi, struct prefix *p,
return; return;
memset(&nh_p, 0, sizeof(nh_p)); memset(&nh_p, 0, sizeof(nh_p));
if (si->type == STATIC_BLACKHOLE) {
switch (si->bh_type) {
case STATIC_BLACKHOLE_DROP:
case STATIC_BLACKHOLE_NULL:
bh_type = BLACKHOLE_NULL;
break;
case STATIC_BLACKHOLE_REJECT:
bh_type = BLACKHOLE_REJECT;
break;
}
}
/* Lookup existing route */ /* Lookup existing route */
rn = srcdest_rnode_get(table, p, src_p); rn = srcdest_rnode_get(table, p, src_p);
@ -92,7 +104,7 @@ void static_install_route(afi_t afi, safi_t safi, struct prefix *p,
break; break;
case STATIC_BLACKHOLE: case STATIC_BLACKHOLE:
nexthop = route_entry_nexthop_blackhole_add( nexthop = route_entry_nexthop_blackhole_add(
re, si->bh_type); re, bh_type);
break; break;
case STATIC_IPV6_GATEWAY: case STATIC_IPV6_GATEWAY:
nexthop = route_entry_nexthop_ipv6_add(re, nexthop = route_entry_nexthop_ipv6_add(re,
@ -168,7 +180,7 @@ void static_install_route(afi_t afi, safi_t safi, struct prefix *p,
break; break;
case STATIC_BLACKHOLE: case STATIC_BLACKHOLE:
nexthop = route_entry_nexthop_blackhole_add( nexthop = route_entry_nexthop_blackhole_add(
re, si->bh_type); re, bh_type);
break; break;
case STATIC_IPV6_GATEWAY: case STATIC_IPV6_GATEWAY:
nexthop = route_entry_nexthop_ipv6_add(re, nexthop = route_entry_nexthop_ipv6_add(re,
@ -363,7 +375,7 @@ void static_uninstall_route(afi_t afi, safi_t safi, struct prefix *p,
int static_add_route(afi_t afi, safi_t safi, u_char type, struct prefix *p, int static_add_route(afi_t afi, safi_t safi, u_char type, struct prefix *p,
struct prefix_ipv6 *src_p, union g_addr *gate, struct prefix_ipv6 *src_p, union g_addr *gate,
const char *ifname, enum blackhole_type bh_type, const char *ifname, enum static_blackhole_type bh_type,
route_tag_t tag, u_char distance, struct zebra_vrf *zvrf, route_tag_t tag, u_char distance, struct zebra_vrf *zvrf,
struct static_nh_label *snh_label) struct static_nh_label *snh_label)
{ {

View File

@ -31,6 +31,12 @@ struct static_nh_label {
mpls_label_t label[MPLS_MAX_LABELS]; mpls_label_t label[MPLS_MAX_LABELS];
}; };
enum static_blackhole_type {
STATIC_BLACKHOLE_DROP = 0,
STATIC_BLACKHOLE_NULL,
STATIC_BLACKHOLE_REJECT
};
typedef enum { typedef enum {
STATIC_IFNAME, STATIC_IFNAME,
STATIC_IPV4_GATEWAY, STATIC_IPV4_GATEWAY,
@ -61,7 +67,7 @@ struct static_route {
/* /*
* Nexthop value. * Nexthop value.
*/ */
enum blackhole_type bh_type; enum static_blackhole_type bh_type;
union g_addr addr; union g_addr addr;
ifindex_t ifindex; ifindex_t ifindex;
@ -80,9 +86,9 @@ extern void static_uninstall_route(afi_t afi, safi_t safi, struct prefix *p,
extern int static_add_route(afi_t, safi_t safi, u_char type, struct prefix *p, extern int static_add_route(afi_t, safi_t safi, u_char type, struct prefix *p,
struct prefix_ipv6 *src_p, union g_addr *gate, struct prefix_ipv6 *src_p, union g_addr *gate,
const char *ifname, enum blackhole_type bh_type, const char *ifname,
route_tag_t tag, u_char distance, enum static_blackhole_type bh_type, route_tag_t tag,
struct zebra_vrf *zvrf, u_char distance, struct zebra_vrf *zvrf,
struct static_nh_label *snh_label); struct static_nh_label *snh_label);
extern int static_delete_route(afi_t, safi_t safi, u_char type, extern int static_delete_route(afi_t, safi_t safi, u_char type,

View File

@ -74,7 +74,7 @@ static int zebra_static_route(struct vty *vty, afi_t afi, safi_t safi,
union g_addr gate; union g_addr gate;
union g_addr *gatep = NULL; union g_addr *gatep = NULL;
struct in_addr mask; struct in_addr mask;
enum blackhole_type bh_type = 0; enum static_blackhole_type bh_type = 0;
route_tag_t tag = 0; route_tag_t tag = 0;
struct zebra_vrf *zvrf; struct zebra_vrf *zvrf;
u_char type; u_char type;
@ -165,18 +165,21 @@ static int zebra_static_route(struct vty *vty, afi_t afi, safi_t safi,
} }
} }
/* Null0 static route. */
if ((ifname != NULL)
&& (strncasecmp(ifname, "Null0", strlen(ifname)) == 0)) {
bh_type = STATIC_BLACKHOLE_NULL;
ifname = NULL;
}
/* Route flags */ /* Route flags */
if (flag_str) { if (flag_str) {
switch (flag_str[0]) { switch (flag_str[0]) {
case 'r': case 'r':
case 'R': /* XXX */ bh_type = STATIC_BLACKHOLE_REJECT;
bh_type = BLACKHOLE_REJECT;
break; break;
case 'n':
case 'N' /* XXX */:
case 'b': case 'b':
case 'B': /* XXX */ bh_type = STATIC_BLACKHOLE_DROP;
bh_type = BLACKHOLE_NULL;
break; break;
default: default:
vty_out(vty, "%% Malformed flag %s \n", flag_str); vty_out(vty, "%% Malformed flag %s \n", flag_str);
@ -335,7 +338,8 @@ DEFPY(ip_route, ip_route_cmd,
<A.B.C.D/M$prefix|A.B.C.D$prefix A.B.C.D$mask>\ <A.B.C.D/M$prefix|A.B.C.D$prefix A.B.C.D$mask>\
<\ <\
{A.B.C.D$gate|INTERFACE$ifname}\ {A.B.C.D$gate|INTERFACE$ifname}\
|<null0|reject|blackhole>$flag\ |null0$ifname\
|<reject|blackhole>$flag\
>\ >\
[{\ [{\
tag (1-4294967295)\ tag (1-4294967295)\
@ -1712,12 +1716,15 @@ static int static_config(struct vty *vty, afi_t afi, safi_t safi,
break; break;
case STATIC_BLACKHOLE: case STATIC_BLACKHOLE:
switch (si->bh_type) { switch (si->bh_type) {
case BLACKHOLE_REJECT: case STATIC_BLACKHOLE_DROP:
vty_out(vty, " reject");
break;
default:
vty_out(vty, " blackhole"); vty_out(vty, " blackhole");
break; break;
case STATIC_BLACKHOLE_NULL:
vty_out(vty, " Null0");
break;
case STATIC_BLACKHOLE_REJECT:
vty_out(vty, " reject");
break;
} }
break; break;
case STATIC_IPV4_GATEWAY_IFNAME: case STATIC_IPV4_GATEWAY_IFNAME:
@ -1770,7 +1777,8 @@ DEFPY(ipv6_route,
"[no] ipv6 route X:X::X:X/M$prefix [from X:X::X:X/M]\ "[no] ipv6 route X:X::X:X/M$prefix [from X:X::X:X/M]\
<\ <\
{X:X::X:X$gate|INTERFACE$ifname}\ {X:X::X:X$gate|INTERFACE$ifname}\
|<null0|reject|blackhole>$flag\ |null0$ifname\
|<reject|blackhole>$flag\
>\ >\
[{\ [{\
tag (1-4294967295)\ tag (1-4294967295)\