Skip to content

Commit a5bd6b7

Browse files
author
Mark Stapp
committed
staticd: in route config, reject keywords as ifname
Reject cli keywords from the various 'ip route' configs if the vty code interprets them as interface names. Signed-off-by: Mark Stapp <mjs@cisco.com>
1 parent 628a463 commit a5bd6b7

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

staticd/static_vty.c

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

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

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

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

0 commit comments

Comments
 (0)