From ddd455157e0a390601ecdfd1db0880ec34974965 Mon Sep 17 00:00:00 2001 From: Igor Ryzhov Date: Wed, 17 Feb 2021 13:06:56 +0300 Subject: [PATCH] staticd: fix nexthop validation When checking for local connected address used as a nexthop gateway, we should check nexthop VRF, not route VRF. Signed-off-by: Igor Ryzhov --- staticd/static_nb_config.c | 2 +- staticd/static_routes.c | 12 +++++++++--- staticd/static_routes.h | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/staticd/static_nb_config.c b/staticd/static_nb_config.c index bf669957bf..cbcfea77cc 100644 --- a/staticd/static_nb_config.c +++ b/staticd/static_nb_config.c @@ -140,7 +140,7 @@ static bool static_nexthop_create(struct nb_cb_create_args *args, pn = nb_running_get_entry(args->dnode, NULL, true); rn = nb_running_get_entry(rn_dnode, NULL, true); - if (!static_add_nexthop_validate(info->svrf, nh_type, &ipaddr)) + if (!static_add_nexthop_validate(nh_vrf, nh_type, &ipaddr)) flog_warn( EC_LIB_NB_CB_CONFIG_VALIDATE, "Warning!! Local connected address is configured as Gateway IP((%s))", diff --git a/staticd/static_routes.c b/staticd/static_routes.c index 1c436a66b0..69d424ef57 100644 --- a/staticd/static_routes.c +++ b/staticd/static_routes.c @@ -138,20 +138,26 @@ void static_del_route(struct route_node *rn, safi_t safi, vrf_reset_user_cfged(svrf->vrf); } -bool static_add_nexthop_validate(struct static_vrf *svrf, static_types type, +bool static_add_nexthop_validate(const char *nh_vrf_name, static_types type, struct ipaddr *ipaddr) { + struct vrf *vrf; + + vrf = vrf_lookup_by_name(nh_vrf_name); + if (!vrf) + return true; + switch (type) { case STATIC_IPV4_GATEWAY: case STATIC_IPV4_GATEWAY_IFNAME: if (if_lookup_exact_address(&ipaddr->ipaddr_v4, AF_INET, - svrf->vrf->vrf_id)) + vrf->vrf_id)) return false; break; case STATIC_IPV6_GATEWAY: case STATIC_IPV6_GATEWAY_IFNAME: if (if_lookup_exact_address(&ipaddr->ipaddr_v6, AF_INET6, - svrf->vrf->vrf_id)) + vrf->vrf_id)) return false; break; default: diff --git a/staticd/static_routes.h b/staticd/static_routes.h index 470afb605d..0fbf0674d7 100644 --- a/staticd/static_routes.h +++ b/staticd/static_routes.h @@ -192,7 +192,7 @@ extern void static_del_path(struct route_node *rn, struct static_path *pn, safi_t safi, struct static_vrf *svrf); extern void static_get_nh_type(static_types stype, char *type, size_t size); -extern bool static_add_nexthop_validate(struct static_vrf *svrf, +extern bool static_add_nexthop_validate(const char *nh_vrf_name, static_types type, struct ipaddr *ipaddr); extern struct stable_info *static_get_stable_info(struct route_node *rn); -- 2.39.5