/* Nexthop, ifindex, distance and metric information. */
if (CHECK_FLAG (api->message, ZAPI_MESSAGE_NEXTHOP))
{
- stream_putc (s, api->nexthop_num + api->ifindex_num);
-
+ if (CHECK_FLAG (api->flags, ZEBRA_FLAG_BLACKHOLE))
+ {
+ stream_putc (s, 1);
+ stream_putc (s, ZEBRA_NEXTHOP_BLACKHOLE);
+ }
+ else
+ stream_putc (s, api->nexthop_num + api->ifindex_num);
+
for (i = 0; i < api->nexthop_num; i++)
- {
- stream_putc (s, ZEBRA_NEXTHOP_IPV4);
- stream_put_in_addr (s, api->nexthop[i]);
- }
+ {
+ stream_putc (s, ZEBRA_NEXTHOP_IPV4);
+ stream_put_in_addr (s, api->nexthop[i]);
+ }
for (i = 0; i < api->ifindex_num; i++)
- {
- stream_putc (s, ZEBRA_NEXTHOP_IFINDEX);
- stream_putl (s, api->ifindex[i]);
- }
+ {
+ stream_putc (s, ZEBRA_NEXTHOP_IFINDEX);
+ stream_putl (s, api->ifindex[i]);
+ }
}
if (CHECK_FLAG (api->message, ZAPI_MESSAGE_DISTANCE))
/* Nexthop, ifindex, distance and metric information. */
if (CHECK_FLAG (api->message, ZAPI_MESSAGE_NEXTHOP))
{
- stream_putc (s, api->nexthop_num + api->ifindex_num);
+ if (CHECK_FLAG (api->flags, ZEBRA_FLAG_BLACKHOLE))
+ {
+ stream_putc (s, 1);
+ stream_putc (s, ZEBRA_NEXTHOP_BLACKHOLE);
+ }
+ else
+ stream_putc (s, api->nexthop_num + api->ifindex_num);
for (i = 0; i < api->nexthop_num; i++)
- {
- stream_putc (s, ZEBRA_NEXTHOP_IPV4);
- stream_put_in_addr (s, api->nexthop[i]);
- }
+ {
+ stream_putc (s, ZEBRA_NEXTHOP_IPV4);
+ stream_put_in_addr (s, api->nexthop[i]);
+ }
for (i = 0; i < api->ifindex_num; i++)
- {
- stream_putc (s, ZEBRA_NEXTHOP_IFINDEX);
- stream_putl (s, api->ifindex[i]);
- }
+ {
+ stream_putc (s, ZEBRA_NEXTHOP_IFINDEX);
+ stream_putl (s, api->ifindex[i]);
+ }
}
if (CHECK_FLAG (api->message, ZAPI_MESSAGE_DISTANCE))
req.r.rtm_protocol = RTPROT_ZEBRA;
req.r.rtm_scope = RT_SCOPE_UNIVERSE;
- if (discard) {
- if (zebra_flags & ZEBRA_FLAG_BLACKHOLE)
- req.r.rtm_type = RTN_BLACKHOLE;
- else if (zebra_flags & ZEBRA_FLAG_REJECT)
- req.r.rtm_type = RTN_UNREACHABLE;
- else assert(RTN_BLACKHOLE != RTN_UNREACHABLE); /* false */
- } else
- req.r.rtm_type = RTN_UNICAST;
+ if (discard)
+ {
+ if (zebra_flags & ZEBRA_FLAG_BLACKHOLE)
+ req.r.rtm_type = RTN_BLACKHOLE;
+ else if (zebra_flags & ZEBRA_FLAG_REJECT)
+ req.r.rtm_type = RTN_UNREACHABLE;
+ else assert(RTN_BLACKHOLE != RTN_UNREACHABLE); /* false */
+ }
+ else
+ req.r.rtm_type = RTN_UNICAST;
}
if (dest)
req.r.rtm_protocol = RTPROT_ZEBRA;
req.r.rtm_scope = RT_SCOPE_UNIVERSE;
- if (discard) {
- if (rib->flags & ZEBRA_FLAG_BLACKHOLE)
- req.r.rtm_type = RTN_BLACKHOLE;
- else if (rib->flags & ZEBRA_FLAG_REJECT)
- req.r.rtm_type = RTN_UNREACHABLE;
- else assert(RTN_BLACKHOLE != RTN_UNREACHABLE); /* false */
- } else
- req.r.rtm_type = RTN_UNICAST;
+ if (discard)
+ {
+ if (rib->flags & ZEBRA_FLAG_BLACKHOLE)
+ req.r.rtm_type = RTN_BLACKHOLE;
+ else if (rib->flags & ZEBRA_FLAG_REJECT)
+ req.r.rtm_type = RTN_UNREACHABLE;
+ else assert(RTN_BLACKHOLE != RTN_UNREACHABLE); /* false */
+ }
+ else
+ req.r.rtm_type = RTN_UNICAST;
}
addattr_l (&req.n, sizeof req, RTA_DST, &p->u.prefix, bytelen);
}
#endif /* HAVE_IPV6 */
+struct nexthop *
+nexthop_blackhole_add (struct rib *rib)
+{
+ struct nexthop *nexthop;
+
+ nexthop = XMALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop));
+ memset (nexthop, 0, sizeof (struct nexthop));
+ nexthop->type = NEXTHOP_TYPE_BLACKHOLE;
+ SET_FLAG (rib->flags, ZEBRA_FLAG_BLACKHOLE);
+
+ nexthop_add (rib, nexthop);
+
+ return nexthop;
+}
+
/* If force flag is not set, do not modify falgs at all for uninstall
the route from FIB. */
int
}
break;
#endif /* HAVE_IPV6 */
+ case NEXTHOP_TYPE_BLACKHOLE:
+ SET_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE);
+ break;
default:
break;
}
case STATIC_IPV4_IFNAME:
nexthop_ifname_add (rib, si->gate.ifname);
break;
+ case STATIC_IPV4_BLACKHOLE:
+ nexthop_blackhole_add (rib);
+ break;
}
rib_process (rn, NULL);
}
case STATIC_IPV4_IFNAME:
nexthop_ifname_add (rib, si->gate.ifname);
break;
+ case STATIC_IPV4_BLACKHOLE:
+ nexthop_blackhole_add (rib);
+ break;
}
/* Save the flags of this static routes (reject, blackhole) */
&& si->type == STATIC_IPV4_IFNAME
&& strcmp (nexthop->ifname, si->gate.ifname) == 0)
return 1;
+ if (nexthop->type == NEXTHOP_TYPE_BLACKHOLE
+ && si->type == STATIC_IPV4_BLACKHOLE)
+ return 1;
return 0;;
}
type = STATIC_IPV4_GATEWAY;
if (ifname)
type = STATIC_IPV4_IFNAME;
+ else
+ type = STATIC_IPV4_BLACKHOLE;
/* Do nothing if there is a same static route. */
for (si = rn->info; si; si = si->next)
type = STATIC_IPV4_GATEWAY;
else if (ifname)
type = STATIC_IPV4_IFNAME;
+ else
+ type = STATIC_IPV4_BLACKHOLE;
/* Find same static route is the tree */
for (si = rn->info; si; si = si->next)
{
ret = inet_aton (mask_str, &mask);
if (ret == 0)
- {
- vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
- return CMD_WARNING;
- }
+ {
+ vty_out (vty, "%% Malformed address%s", VTY_NEWLINE);
+ return CMD_WARNING;
+ }
p.prefixlen = ip_masklen (mask);
}
/* Apply mask for given prefix. */
apply_mask (&p);
+ /* Administrative distance. */
+ if (distance_str)
+ distance = atoi (distance_str);
+ else
+ distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
+
+ /* Null0 static route. */
+ if (strncasecmp (gate_str, "Null0", strlen (gate_str)) == 0)
+ {
+ if (flag_str)
+ {
+ vty_out (vty, "%% can not have flag %s with Null0%s", flag_str, VTY_NEWLINE);
+ return CMD_WARNING;
+ }
+ if (add_cmd)
+ static_add_ipv4 (&p, NULL, NULL, 0, distance, 0);
+ else
+ static_delete_ipv4 (&p, NULL, NULL, distance, 0);
+ return CMD_SUCCESS;
+ }
+
/* Route flags */
if (flag_str) {
switch(flag_str[0]) {
break;
default:
vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
- break;
+ return CMD_WARNING;
}
}
- /* Administrative distance. */
- if (distance_str)
- distance = atoi (distance_str);
- else
- distance = ZEBRA_STATIC_DISTANCE_DEFAULT;
-
/* When gateway is A.B.C.D format, gate is treated as nexthop
address other case gate is treated as interface name. */
ret = inet_aton (gate_str, &gate);
/* Static route configuration. */
DEFUN (ip_route,
ip_route_cmd,
- "ip route A.B.C.D/M (A.B.C.D|INTERFACE)",
+ "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
IP_STR
"Establish static routes\n"
"IP destination prefix (e.g. 10.0.0.0/8)\n"
"IP gateway address\n"
- "IP gateway interface name\n")
+ "IP gateway interface name\n"
+ "Null interface\n")
{
return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, NULL);
}
/* Mask as A.B.C.D format. */
DEFUN (ip_route_mask,
ip_route_mask_cmd,
- "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE)",
+ "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
IP_STR
"Establish static routes\n"
"IP destination prefix\n"
"IP destination prefix mask\n"
"IP gateway address\n"
- "IP gateway interface name\n")
+ "IP gateway interface name\n"
+ "Null interface\n")
{
return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, NULL);
}
/* Distance option value. */
DEFUN (ip_route_distance,
ip_route_distance_cmd,
- "ip route A.B.C.D/M (A.B.C.D|INTERFACE) <1-255>",
+ "ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
IP_STR
"Establish static routes\n"
"IP destination prefix (e.g. 10.0.0.0/8)\n"
"IP gateway address\n"
"IP gateway interface name\n"
+ "Null interface\n"
"Distance value for this route\n")
{
return zebra_static_ipv4 (vty, 1, argv[0], NULL, argv[1], NULL, argv[2]);
DEFUN (ip_route_mask_distance,
ip_route_mask_distance_cmd,
- "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) <1-255>",
+ "ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
IP_STR
"Establish static routes\n"
"IP destination prefix\n"
"IP destination prefix mask\n"
"IP gateway address\n"
"IP gateway interface name\n"
+ "Null interface\n"
"Distance value for this route\n")
{
return zebra_static_ipv4 (vty, 1, argv[0], argv[1], argv[2], NULL, argv[3]);
DEFUN (no_ip_route,
no_ip_route_cmd,
- "no ip route A.B.C.D/M (A.B.C.D|INTERFACE)",
+ "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0)",
NO_STR
IP_STR
"Establish static routes\n"
"IP destination prefix (e.g. 10.0.0.0/8)\n"
"IP gateway address\n"
- "IP gateway interface name\n")
+ "IP gateway interface name\n"
+ "Null interface\n")
{
return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, NULL);
}
DEFUN (no_ip_route_mask,
no_ip_route_mask_cmd,
- "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE)",
+ "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0)",
NO_STR
IP_STR
"Establish static routes\n"
"IP destination prefix\n"
"IP destination prefix mask\n"
"IP gateway address\n"
- "IP gateway interface name\n")
+ "IP gateway interface name\n"
+ "Null interface\n")
{
return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, NULL);
}
DEFUN (no_ip_route_distance,
no_ip_route_distance_cmd,
- "no ip route A.B.C.D/M (A.B.C.D|INTERFACE) <1-255>",
+ "no ip route A.B.C.D/M (A.B.C.D|INTERFACE|null0) <1-255>",
NO_STR
IP_STR
"Establish static routes\n"
"IP destination prefix (e.g. 10.0.0.0/8)\n"
"IP gateway address\n"
"IP gateway interface name\n"
+ "Null interface\n"
"Distance value for this route\n")
{
return zebra_static_ipv4 (vty, 0, argv[0], NULL, argv[1], NULL, argv[2]);
DEFUN (no_ip_route_mask_distance,
no_ip_route_mask_distance_cmd,
- "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE) <1-255>",
+ "no ip route A.B.C.D A.B.C.D (A.B.C.D|INTERFACE|null0) <1-255>",
NO_STR
IP_STR
"Establish static routes\n"
"IP destination prefix mask\n"
"IP gateway address\n"
"IP gateway interface name\n"
+ "Null interface\n"
"Distance value for this route\n")
{
return zebra_static_ipv4 (vty, 0, argv[0], argv[1], argv[2], NULL, argv[3]);
case NEXTHOP_TYPE_IFNAME:
vty_out (vty, " directly connected, %s", nexthop->ifname);
break;
+ case NEXTHOP_TYPE_BLACKHOLE:
+ vty_out (vty, " directly connected, via Null0");
+ break;
default:
break;
}
case NEXTHOP_TYPE_IFNAME:
vty_out (vty, " is directly connected, %s", nexthop->ifname);
break;
+ case NEXTHOP_TYPE_BLACKHOLE:
+ vty_out (vty, " is directly connected, Null0");
+ break;
default:
break;
}
case STATIC_IPV4_IFNAME:
vty_out (vty, " %s", si->gate.ifname);
break;
+ case STATIC_IPV4_BLACKHOLE:
+ vty_out (vty, " Null0");
+ break;
}
if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT))
break;
default:
vty_out (vty, "%% Malformed flag %s %s", flag_str, VTY_NEWLINE);
- break;
+ return CMD_WARNING;
}
}
return static_ipv6_func (vty, 0, argv[0], argv[1], argv[2], argv[3], argv[4]);
}
-/* New RIB. Detailed information for IPv4 route. */
+/* New RIB. Detailed information for IPv6 route. */
void
vty_show_ipv6_route_detail (struct vty *vty, struct route_node *rn)
{