Skip to content

Commit

Permalink
Merge pull request #3190 from qlyoung/allow-static-onlink
Browse files Browse the repository at this point in the history
staticd: add ability to create onlink static route
  • Loading branch information
rwestphal authored Oct 18, 2018
2 parents 911bd6d + 02dc8ba commit 705d21f
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 33 deletions.
7 changes: 4 additions & 3 deletions staticd/static_routes.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ int static_add_route(afi_t afi, safi_t safi, uint8_t type, struct prefix *p,
const char *ifname, enum static_blackhole_type bh_type,
route_tag_t tag, uint8_t distance, struct static_vrf *svrf,
struct static_vrf *nh_svrf,
struct static_nh_label *snh_label,
uint32_t table_id)
struct static_nh_label *snh_label, uint32_t table_id,
bool onlink)
{
struct route_node *rn;
struct static_route *si;
Expand Down Expand Up @@ -104,7 +104,7 @@ int static_add_route(afi_t afi, safi_t safi, uint8_t type, struct prefix *p,
&& (table_id == si->table_id)
&& !memcmp(&si->snh_label, snh_label,
sizeof(struct static_nh_label))
&& si->bh_type == bh_type) {
&& si->bh_type == bh_type && si->onlink == onlink) {
route_unlock_node(rn);
return 0;
}
Expand All @@ -129,6 +129,7 @@ int static_add_route(afi_t afi, safi_t safi, uint8_t type, struct prefix *p,
si->nh_vrf_id = nh_svrf->vrf->vrf_id;
strcpy(si->nh_vrfname, nh_svrf->vrf->name);
si->table_id = table_id;
si->onlink = onlink;

if (ifname)
strlcpy(si->ifname, ifname, sizeof(si->ifname));
Expand Down
9 changes: 8 additions & 1 deletion staticd/static_routes.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ struct static_route {
struct static_nh_label snh_label;

uint32_t table_id;

/*
* Whether to pretend the nexthop is directly attached to the specified
* link. Only meaningful when both a gateway address and interface name
* are specified.
*/
bool onlink;
};

extern bool mpls_enabled;
Expand All @@ -94,7 +101,7 @@ extern int static_add_route(afi_t afi, safi_t safi, uint8_t type,
uint8_t distance, struct static_vrf *svrf,
struct static_vrf *nh_svrf,
struct static_nh_label *snh_label,
uint32_t table_id);
uint32_t table_id, bool onlink);

extern int static_delete_route(afi_t afi, safi_t safi, uint8_t type,
struct prefix *p, struct prefix_ipv6 *src_p,
Expand Down
70 changes: 41 additions & 29 deletions staticd/static_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct static_hold_route {
char *distance_str;
char *label_str;
char *table_str;
bool onlink;

/* processed & masked destination, used for config display */
struct prefix dest;
Expand Down Expand Up @@ -273,7 +274,8 @@ static int static_route_leak(
afi_t afi, safi_t safi, const char *negate, const char *dest_str,
const char *mask_str, const char *src_str, const char *gate_str,
const char *ifname, const char *flag_str, const char *tag_str,
const char *distance_str, const char *label_str, const char *table_str)
const char *distance_str, const char *label_str, const char *table_str,
bool onlink)
{
int ret;
uint8_t distance;
Expand Down Expand Up @@ -509,7 +511,7 @@ static int static_route_leak(
if (!negate) {
static_add_route(afi, safi, type, &p, src_p, gatep, ifname,
bh_type, tag, distance, svrf, nh_svrf,
&snh_label, table_id);
&snh_label, table_id, onlink);
/* Mark as having FRR configuration */
vrf_set_user_cfged(svrf->vrf);
} else {
Expand Down Expand Up @@ -550,10 +552,10 @@ static int static_route(struct vty *vty, afi_t afi, safi_t safi,
if (!svrf)
return CMD_WARNING_CONFIG_FAILED;
}
return static_route_leak(
vty, svrf, svrf, afi, safi, negate, dest_str, mask_str, src_str,
gate_str, ifname, flag_str, tag_str, distance_str, label_str,
table_str);
return static_route_leak(vty, svrf, svrf, afi, safi, negate, dest_str,
mask_str, src_str, gate_str, ifname, flag_str,
tag_str, distance_str, label_str, table_str,
false);
}

void static_config_install_delayed_routes(struct static_vrf *svrf)
Expand All @@ -578,7 +580,8 @@ void static_config_install_delayed_routes(struct static_vrf *svrf)
NULL, osvrf, nh_svrf, shr->afi, shr->safi, NULL,
shr->dest_str, shr->mask_str, shr->src_str,
shr->gate_str, shr->ifname, shr->flag_str, shr->tag_str,
shr->distance_str, shr->label_str, shr->table_str);
shr->distance_str, shr->label_str, shr->table_str,
shr->onlink);

if (installed != CMD_SUCCESS)
zlog_debug(
Expand Down Expand Up @@ -817,9 +820,10 @@ DEFPY(ip_route_blackhole_vrf,
* valid. Add an assert to make it happy
*/
assert(prefix);
return static_route_leak(vty, svrf, svrf, AFI_IP, SAFI_UNICAST,
no, prefix, mask_str, NULL, NULL, NULL,
flag, tag_str, distance_str, label, table_str);
return static_route_leak(vty, svrf, svrf, AFI_IP, SAFI_UNICAST, no,
prefix, mask_str, NULL, NULL, NULL, flag,
tag_str, distance_str, label, table_str,
false);
}

DEFPY(ip_route_address_interface,
Expand All @@ -835,6 +839,7 @@ DEFPY(ip_route_address_interface,
|label WORD \
|table (1-4294967295) \
|nexthop-vrf NAME \
|onlink$onlink \
}]",
NO_STR IP_STR
"Establish static routes\n"
Expand All @@ -851,7 +856,8 @@ DEFPY(ip_route_address_interface,
MPLS_LABEL_HELPSTR
"Table to configure\n"
"The table number to configure\n"
VRF_CMD_HELP_STR)
VRF_CMD_HELP_STR
"Treat the nexthop as directly attached to the interface")
{
struct static_vrf *svrf;
struct static_vrf *nh_svrf;
Expand Down Expand Up @@ -884,10 +890,10 @@ DEFPY(ip_route_address_interface,
return CMD_WARNING_CONFIG_FAILED;
}

return static_route_leak(
vty, svrf, nh_svrf, AFI_IP, SAFI_UNICAST, no, prefix, mask_str,
NULL, gate_str, ifname, flag, tag_str, distance_str, label,
table_str);
return static_route_leak(vty, svrf, nh_svrf, AFI_IP, SAFI_UNICAST, no,
prefix, mask_str, NULL, gate_str, ifname, flag,
tag_str, distance_str, label, table_str,
!!onlink);
}

DEFPY(ip_route_address_interface_vrf,
Expand All @@ -902,6 +908,7 @@ DEFPY(ip_route_address_interface_vrf,
|label WORD \
|table (1-4294967295) \
|nexthop-vrf NAME \
|onlink$onlink \
}]",
NO_STR IP_STR
"Establish static routes\n"
Expand All @@ -917,7 +924,8 @@ DEFPY(ip_route_address_interface_vrf,
MPLS_LABEL_HELPSTR
"Table to configure\n"
"The table number to configure\n"
VRF_CMD_HELP_STR)
VRF_CMD_HELP_STR
"Treat the nexthop as directly attached to the interface")
{
VTY_DECLVAR_CONTEXT(vrf, vrf);
const char *flag = NULL;
Expand Down Expand Up @@ -945,10 +953,10 @@ DEFPY(ip_route_address_interface_vrf,
return CMD_WARNING_CONFIG_FAILED;
}

return static_route_leak(
vty, svrf, nh_svrf, AFI_IP, SAFI_UNICAST, no, prefix, mask_str,
NULL, gate_str, ifname, flag, tag_str, distance_str, label,
table_str);
return static_route_leak(vty, svrf, nh_svrf, AFI_IP, SAFI_UNICAST, no,
prefix, mask_str, NULL, gate_str, ifname, flag,
tag_str, distance_str, label, table_str,
!!onlink);
}

DEFPY(ip_route,
Expand Down Expand Up @@ -1014,7 +1022,7 @@ DEFPY(ip_route,
return static_route_leak(
vty, svrf, nh_svrf, AFI_IP, SAFI_UNICAST, no, prefix, mask_str,
NULL, gate_str, ifname, flag, tag_str, distance_str, label,
table_str);
table_str, false);
}

DEFPY(ip_route_vrf,
Expand Down Expand Up @@ -1073,7 +1081,7 @@ DEFPY(ip_route_vrf,
return static_route_leak(
vty, svrf, nh_svrf, AFI_IP, SAFI_UNICAST, no, prefix, mask_str,
NULL, gate_str, ifname, flag, tag_str, distance_str, label,
table_str);
table_str, false);
}

DEFPY(ipv6_route_blackhole,
Expand Down Expand Up @@ -1159,7 +1167,7 @@ DEFPY(ipv6_route_blackhole_vrf,
return static_route_leak(
vty, svrf, svrf, AFI_IP6, SAFI_UNICAST, no, prefix_str, NULL,
from_str, NULL, NULL, flag, tag_str, distance_str, label,
table_str);
table_str, false);
}

DEFPY(ipv6_route_address_interface,
Expand All @@ -1174,6 +1182,7 @@ DEFPY(ipv6_route_address_interface,
|label WORD \
|table (1-4294967295) \
|nexthop-vrf NAME \
|onlink$onlink \
}]",
NO_STR
IPV6_STR
Expand All @@ -1190,7 +1199,8 @@ DEFPY(ipv6_route_address_interface,
MPLS_LABEL_HELPSTR
"Table to configure\n"
"The table number to configure\n"
VRF_CMD_HELP_STR)
VRF_CMD_HELP_STR
"Treat the nexthop as directly attached to the interface")
{
struct static_vrf *svrf;
struct static_vrf *nh_svrf;
Expand Down Expand Up @@ -1220,7 +1230,7 @@ DEFPY(ipv6_route_address_interface,
return static_route_leak(
vty, svrf, nh_svrf, AFI_IP6, SAFI_UNICAST, no, prefix_str, NULL,
from_str, gate_str, ifname, NULL, tag_str, distance_str, label,
table_str);
table_str, !!onlink);
}

DEFPY(ipv6_route_address_interface_vrf,
Expand All @@ -1234,6 +1244,7 @@ DEFPY(ipv6_route_address_interface_vrf,
|label WORD \
|table (1-4294967295) \
|nexthop-vrf NAME \
|onlink$onlink \
}]",
NO_STR
IPV6_STR
Expand All @@ -1249,7 +1260,8 @@ DEFPY(ipv6_route_address_interface_vrf,
MPLS_LABEL_HELPSTR
"Table to configure\n"
"The table number to configure\n"
VRF_CMD_HELP_STR)
VRF_CMD_HELP_STR
"Treat the nexthop as directly attached to the interface")
{
VTY_DECLVAR_CONTEXT(vrf, vrf);
struct static_vrf *svrf = vrf->info;
Expand All @@ -1274,7 +1286,7 @@ DEFPY(ipv6_route_address_interface_vrf,
return static_route_leak(
vty, svrf, nh_svrf, AFI_IP6, SAFI_UNICAST, no, prefix_str, NULL,
from_str, gate_str, ifname, NULL, tag_str, distance_str, label,
table_str);
table_str, !!onlink);
}

DEFPY(ipv6_route,
Expand Down Expand Up @@ -1334,7 +1346,7 @@ DEFPY(ipv6_route,
return static_route_leak(
vty, svrf, nh_svrf, AFI_IP6, SAFI_UNICAST, no, prefix_str, NULL,
from_str, gate_str, ifname, NULL, tag_str, distance_str, label,
table_str);
table_str, false);
}

DEFPY(ipv6_route_vrf,
Expand Down Expand Up @@ -1387,7 +1399,7 @@ DEFPY(ipv6_route_vrf,
return static_route_leak(
vty, svrf, nh_svrf, AFI_IP6, SAFI_UNICAST, no, prefix_str, NULL,
from_str, gate_str, ifname, NULL, tag_str, distance_str, label,
table_str);
table_str, false);
}

DEFUN_NOSH (show_debugging_staticd,
Expand Down
2 changes: 2 additions & 0 deletions staticd/static_zebra.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ extern void static_zebra_route_add(struct route_node *rn,
memcpy(&api.src_prefix, src_pp, sizeof(api.src_prefix));
}
SET_FLAG(api.flags, ZEBRA_FLAG_RR_USE_DISTANCE);
if (si_changed->onlink)
SET_FLAG(api.flags, ZEBRA_FLAG_ONLINK);
SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
if (si_changed->distance) {
SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE);
Expand Down

0 comments on commit 705d21f

Please sign in to comment.