summaryrefslogtreecommitdiff
path: root/staticd/static_nb_config.c
diff options
context:
space:
mode:
authorDonatas Abraitis <donatas@opensourcerouting.org>2023-08-24 18:06:17 +0300
committerDonatas Abraitis <donatas@opensourcerouting.org>2023-08-25 12:00:33 +0300
commit76b2bc97e73874d882d5cf021972cfca84656cef (patch)
treed8b24ee33d916f5cefba4aecc1fe6439ecfdc341 /staticd/static_nb_config.c
parent673a11a54fc6948641fe56e41720d0f900c9353c (diff)
staticd: Accept full blackhole typed keywords for ip_route_cmd
Before this patch we allow entering next-hop interface address as any string. Like, we can type: `ip route 10.10.10.10/32 bla`, but this will create a blackhole route instead of using an interface `bla`. The same is with reject. After the patch: ``` $ vtysh -c 'con' -c 'ip route 10.10.10.100/32 bla' ERROR: SET_CONFIG request failed, Error: nexthop interface name must be (reject, blackhole) $ ip link show dev bla 472: bla: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000 link/ether fa:45:bd:f1:f8:f0 brd ff:ff:ff:ff:ff:ff $ vtysh -c 'sh run | include ip route' $ vtysh -c 'con' -c 'ip route 10.10.10.100/32 blac' $ vtysh -c 'sh run | include ip route' ip route 10.10.10.100/32 blackhole $ vtysh -c 'con' -c 'no ip route 10.10.10.100/32 blac' $ vtysh -c 'sh run | include ip route' $ vtysh -c 'con' -c 'ip route 10.10.10.100/32 blackhole' $ vtysh -c 'sh run | include ip route' ip route 10.10.10.100/32 blackhole $ vtysh -c 'con' -c 'no ip route 10.10.10.100/32 blackhole' $ vtysh -c 'sh run | include ip route' $ vtysh -c 'con' -c 'ip route 10.10.10.100/32 Null0' $ vtysh -c 'sh run | include ip route' ip route 10.10.10.100/32 Null0 $ vtysh -c 'con' -c 'no ip route 10.10.10.100/32 Null0' $ vtysh -c 'sh run | include ip route' $ ``` Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
Diffstat (limited to 'staticd/static_nb_config.c')
-rw-r--r--staticd/static_nb_config.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/staticd/static_nb_config.c b/staticd/static_nb_config.c
index 01cd281d9c..6673cce108 100644
--- a/staticd/static_nb_config.c
+++ b/staticd/static_nb_config.c
@@ -135,7 +135,8 @@ static bool static_nexthop_create(struct nb_cb_create_args *args)
switch (args->event) {
case NB_EV_VALIDATE:
ifname = yang_dnode_get_string(args->dnode, "./interface");
- if (ifname != NULL) {
+ nh_type = yang_dnode_get_enum(args->dnode, "./nh-type");
+ if (ifname != NULL && nh_type != STATIC_BLACKHOLE) {
if (strcasecmp(ifname, "Null0") == 0
|| strcasecmp(ifname, "reject") == 0
|| strcasecmp(ifname, "blackhole") == 0) {
@@ -371,10 +372,26 @@ static int static_nexthop_bh_type_modify(struct nb_cb_modify_args *args)
{
struct static_nexthop *nh;
enum static_nh_type nh_type;
+ const char *nh_ifname;
+ const char *nh_vrf;
switch (args->event) {
case NB_EV_VALIDATE:
nh_type = yang_dnode_get_enum(args->dnode, "../nh-type");
+ nh_ifname = yang_dnode_get_string(args->dnode, "../interface");
+ nh_vrf = yang_dnode_get_string(args->dnode, "../vrf");
+ if (nh_ifname && nh_vrf) {
+ struct vrf *vrf = vrf_lookup_by_name(nh_vrf);
+ struct interface *ifp = if_lookup_by_name(nh_ifname,
+ vrf->vrf_id);
+
+ if (ifp && (!strmatch(nh_ifname, "blackhole") ||
+ !strmatch(nh_ifname, "reject"))) {
+ snprintf(args->errmsg, args->errmsg_len,
+ "nexthop interface name must be (reject, blackhole)");
+ return NB_ERR_VALIDATION;
+ }
+ }
if (nh_type != STATIC_BLACKHOLE) {
snprintf(args->errmsg, args->errmsg_len,
"nexthop type is not the blackhole type");