Skip to content

Commit d387c53

Browse files
authored
Merge pull request FRRouting#20311 from mjstapp/fix_staticd_config_keywords
staticd: in route config, reject keywords as ifname
2 parents b85ee07 + 9569593 commit d387c53

2 files changed

Lines changed: 37 additions & 6 deletions

File tree

doc/user/static.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ a static prefix and gateway, with several possible forms.
5050
v6 routes only support v6 next-hops.
5151

5252
IFNAME is the name of the interface to use as next-hop. If only IFNAME is specified
53-
(without GATEWAY), a connected route will be created.
53+
(without GATEWAY), a connected route will be created. Note that
54+
some of the other keywords are not valid interface names: ``vrf``,
55+
``table``, ``label``, ``tag``, ``color``, ``segments``, and ``nexthop-vrf``.
5456

5557
When both IFNAME and GATEWAY are specified together, it binds the route to the specified
5658
interface. In this case, it is also possible to specify ``onlink`` to force the kernel
@@ -289,4 +291,4 @@ SRv6 Static SIDs Commands
289291
sid fcbb:bbbb:1:fe03::/64 locator LOC1 behavior uDT46 vrf Vrf2
290292
sid fcbb:bbbb:1:fe04::/64 locator LOC1 behavior uA interface eth0 nexthop 2001::2
291293
!
292-
...
294+
...

staticd/static_vty.c

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,28 @@ struct static_route_args {
6868
const char *srv6_encap_behavior;
6969
};
7070

71+
/* Reject invalid keywords interpreted as interface names */
72+
static bool staticd_ifname_invalid(const char *ifname)
73+
{
74+
const char *const *cp;
75+
static const char *const invalid_names[] = {
76+
"tag",
77+
"vrf",
78+
"label",
79+
"color",
80+
"table",
81+
"segments",
82+
"nexthop-vrf",
83+
NULL /*End sentinel*/
84+
};
85+
86+
for (cp = invalid_names; cp != NULL && *cp != NULL; cp++)
87+
if (strmatch(*cp, ifname))
88+
return true;
89+
90+
return false;
91+
}
92+
7193
static int static_route_nb_run(struct vty *vty, struct static_route_args *args)
7294
{
7395
int ret;
@@ -116,10 +138,17 @@ static int static_route_nb_run(struct vty *vty, struct static_route_args *args)
116138
if (args->nexthop_vrf == NULL)
117139
args->nexthop_vrf = args->vrf;
118140

119-
if (args->interface_name &&
120-
!strcasecmp(args->interface_name, "Null0")) {
121-
args->flag = "Null0";
122-
args->interface_name = NULL;
141+
/* Interface token validation */
142+
if (args->interface_name) {
143+
if (strcasecmp(args->interface_name, "Null0") == 0) {
144+
args->flag = "Null0";
145+
args->interface_name = NULL;
146+
} else if (staticd_ifname_invalid(args->interface_name)) {
147+
/* Check for prohibited keywords as ifname */
148+
vty_out(vty, "%% Invalid interface name %s\n",
149+
args->interface_name);
150+
return CMD_WARNING_CONFIG_FAILED;
151+
}
123152
}
124153

125154
assert(!!str2prefix(args->prefix, &p));

0 commit comments

Comments
 (0)