]> git.proxmox.com Git - mirror_frr.git/commitdiff
zebra: nht resolution default configurable per vrf
authorPhilippe Guibert <philippe.guibert@6wind.com>
Wed, 28 Aug 2019 14:01:38 +0000 (16:01 +0200)
committerPhilippe Guibert <philippe.guibert@6wind.com>
Wed, 28 Aug 2019 14:19:34 +0000 (16:19 +0200)
even if vty commands were available, the default resolution command was
working only for the first vrf configured. others were ignored. Also,
for nexthop, resolution was working for all vrfs, and not the specific
one.

Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
zebra/zebra_nhg.c
zebra/zebra_rnh.c
zebra/zebra_rnh.h
zebra/zebra_vrf.c
zebra/zebra_vrf.h
zebra/zebra_vty.c

index f4b86f3cfe96dd064ddce855f05e3f91a46406ef..be6fa30ebd24b3e73c9d83705dd00bbe1c41dcb0 100644 (file)
@@ -120,6 +120,7 @@ static int nexthop_active(afi_t afi, struct route_entry *re,
        struct nexthop *newhop;
        struct interface *ifp;
        rib_dest_t *dest;
+       struct zebra_vrf *zvrf;
 
        if ((nexthop->type == NEXTHOP_TYPE_IPV4)
            || nexthop->type == NEXTHOP_TYPE_IPV6)
@@ -194,7 +195,9 @@ static int nexthop_active(afi_t afi, struct route_entry *re,
        }
        /* Lookup table.  */
        table = zebra_vrf_table(afi, SAFI_UNICAST, nexthop->vrf_id);
-       if (!table) {
+       /* get zvrf */
+       zvrf = zebra_vrf_lookup_by_id(nexthop->vrf_id);
+       if (!table || !zvrf) {
                if (IS_ZEBRA_DEBUG_RIB_DETAILED)
                        zlog_debug("\t%s: Table not found",
                                   __PRETTY_FUNCTION__);
@@ -224,7 +227,7 @@ static int nexthop_active(afi_t afi, struct route_entry *re,
                /* However, do not resolve over default route unless explicitly
                 * allowed. */
                if (is_default_prefix(&rn->p)
-                   && !rnh_resolve_via_default(p.family)) {
+                   && !rnh_resolve_via_default(zvrf, p.family)) {
                        if (IS_ZEBRA_DEBUG_RIB_DETAILED)
                                zlog_debug(
                                        "\t:%s: Resolved against default route",
index da2fe4a30cd2dbfcbd7664ae39e3770a95a20aa9..666ebb70e82f0bded0413e34417f0052c696e509 100644 (file)
@@ -62,9 +62,6 @@ static int send_client(struct rnh *rnh, struct zserv *client, rnh_type_t type,
 static void print_rnh(struct route_node *rn, struct vty *vty);
 static int zebra_client_cleanup_rnh(struct zserv *client);
 
-int zebra_rnh_ip_default_route = 0;
-int zebra_rnh_ipv6_default_route = 0;
-
 void zebra_rnh_init(void)
 {
        hook_register(zserv_client_close, zebra_client_cleanup_rnh);
@@ -656,7 +653,7 @@ zebra_rnh_resolve_nexthop_entry(struct zebra_vrf *zvrf, afi_t afi,
                 * match route to be exact if so specified
                 */
                if (is_default_prefix(&rn->p)
-                   && !rnh_resolve_via_default(rn->p.family)) {
+                   && !rnh_resolve_via_default(zvrf, rn->p.family)) {
                        if (IS_ZEBRA_DEBUG_NHT_DETAILED)
                                zlog_debug(
                                        "\tNot allowed to resolve through default prefix");
@@ -1213,3 +1210,12 @@ static int zebra_client_cleanup_rnh(struct zserv *client)
 
        return 0;
 }
+
+int rnh_resolve_via_default(struct zebra_vrf *zvrf, int family)
+{
+       if (((family == AF_INET) && zvrf->zebra_rnh_ip_default_route)
+           || ((family == AF_INET6) && zvrf->zebra_rnh_ipv6_default_route))
+               return 1;
+       else
+               return 0;
+}
index c7d2c0d2984a6fa7f26f812810ce0ec7ba5d6e8b..6e2dab8d9ff232da4f22295e10add575838430c2 100644 (file)
 extern "C" {
 #endif
 
-extern int zebra_rnh_ip_default_route;
-extern int zebra_rnh_ipv6_default_route;
-
 extern void zebra_rnh_init(void);
 
-static inline int rnh_resolve_via_default(int family)
-{
-       if (((family == AF_INET) && zebra_rnh_ip_default_route)
-           || ((family == AF_INET6) && zebra_rnh_ipv6_default_route))
-               return 1;
-       else
-               return 0;
-}
-
 static inline const char *rnh_type2str(rnh_type_t type)
 {
        switch (type) {
@@ -72,6 +60,8 @@ extern void zebra_print_rnh_table(vrf_id_t vrfid, afi_t afi, struct vty *vty,
                                  rnh_type_t type, struct prefix *p);
 extern char *rnh_str(struct rnh *rnh, char *buf, int size);
 
+extern int rnh_resolve_via_default(struct zebra_vrf *zvrf, int family);
+
 #ifdef __cplusplus
 }
 #endif
index fcc94a7be906827bbd0392f5077c6c66c90a58a0..72d0b6866db800c0dc8f61e10e73cfce7ac3ad53 100644 (file)
@@ -488,6 +488,11 @@ static int vrf_config_write(struct vty *vty)
                if (zvrf_id(zvrf) == VRF_DEFAULT) {
                        if (zvrf->l3vni)
                                vty_out(vty, "vni %u\n", zvrf->l3vni);
+                       if (zvrf->zebra_rnh_ip_default_route)
+                               vty_out(vty, "ip nht resolve-via-default\n");
+
+                       if (zvrf->zebra_rnh_ipv6_default_route)
+                               vty_out(vty, "ipv6 nht resolve-via-default\n");
                } else {
                        vty_frame(vty, "vrf %s\n", zvrf_name(zvrf));
                        if (zvrf->l3vni)
@@ -497,8 +502,14 @@ static int vrf_config_write(struct vty *vty)
                                                ? " prefix-routes-only"
                                                : "");
                        zebra_ns_config_write(vty, (struct ns *)vrf->ns_ctxt);
+                       if (zvrf->zebra_rnh_ip_default_route)
+                               vty_out(vty, " ip nht resolve-via-default\n");
+
+                       if (zvrf->zebra_rnh_ipv6_default_route)
+                               vty_out(vty, " ipv6 nht resolve-via-default\n");
                }
 
+
                zebra_routemap_config_write_protocol(vty, zvrf);
 
                if (zvrf_id(zvrf) != VRF_DEFAULT)
index f92e1a010b01f8c53183503d4d0ba441f808c9e9..6c80f9bcb449ac502da809a91cda1bc7326c3601 100644 (file)
@@ -174,6 +174,9 @@ struct zebra_vrf {
 #if defined(HAVE_RTADV)
        struct rtadv rtadv;
 #endif /* HAVE_RTADV */
+
+       int zebra_rnh_ip_default_route;
+       int zebra_rnh_ipv6_default_route;
 };
 #define PROTO_RM_NAME(zvrf, afi, rtype) zvrf->proto_rm[afi][rtype].name
 #define NHT_RM_NAME(zvrf, afi, rtype) zvrf->nht_rm[afi][rtype].name
index 5c0dc2738019f3a2754cb58455dd4bcf07714680..ac28f38121cfcc2b0c8de97c9c94543bae99f530 100644 (file)
@@ -1086,10 +1086,10 @@ DEFUN (ip_nht_default_route,
        if (!zvrf)
                return CMD_WARNING;
 
-       if (zebra_rnh_ip_default_route)
+       if (zvrf->zebra_rnh_ip_default_route)
                return CMD_SUCCESS;
 
-       zebra_rnh_ip_default_route = 1;
+       zvrf->zebra_rnh_ip_default_route = 1;
 
        zebra_evaluate_rnh(zvrf, AFI_IP, 1, RNH_NEXTHOP_TYPE, NULL);
        return CMD_SUCCESS;
@@ -1108,10 +1108,10 @@ DEFUN (no_ip_nht_default_route,
        if (!zvrf)
                return CMD_WARNING;
 
-       if (!zebra_rnh_ip_default_route)
+       if (!zvrf->zebra_rnh_ip_default_route)
                return CMD_SUCCESS;
 
-       zebra_rnh_ip_default_route = 0;
+       zvrf->zebra_rnh_ip_default_route = 0;
        zebra_evaluate_rnh(zvrf, AFI_IP, 1, RNH_NEXTHOP_TYPE, NULL);
        return CMD_SUCCESS;
 }
@@ -1128,10 +1128,10 @@ DEFUN (ipv6_nht_default_route,
        if (!zvrf)
                return CMD_WARNING;
 
-       if (zebra_rnh_ipv6_default_route)
+       if (zvrf->zebra_rnh_ipv6_default_route)
                return CMD_SUCCESS;
 
-       zebra_rnh_ipv6_default_route = 1;
+       zvrf->zebra_rnh_ipv6_default_route = 1;
        zebra_evaluate_rnh(zvrf, AFI_IP6, 1, RNH_NEXTHOP_TYPE, NULL);
        return CMD_SUCCESS;
 }
@@ -1150,10 +1150,10 @@ DEFUN (no_ipv6_nht_default_route,
        if (!zvrf)
                return CMD_WARNING;
 
-       if (!zebra_rnh_ipv6_default_route)
+       if (!zvrf->zebra_rnh_ipv6_default_route)
                return CMD_SUCCESS;
 
-       zebra_rnh_ipv6_default_route = 0;
+       zvrf->zebra_rnh_ipv6_default_route = 0;
        zebra_evaluate_rnh(zvrf, AFI_IP6, 1, RNH_NEXTHOP_TYPE, NULL);
        return CMD_SUCCESS;
 }
@@ -2625,12 +2625,6 @@ static int config_write_protocol(struct vty *vty)
        if (allow_delete)
                vty_out(vty, "allow-external-route-update\n");
 
-       if (zebra_rnh_ip_default_route)
-               vty_out(vty, "ip nht resolve-via-default\n");
-
-       if (zebra_rnh_ipv6_default_route)
-               vty_out(vty, "ipv6 nht resolve-via-default\n");
-
        if (zrouter.ribq->spec.hold != ZEBRA_RIB_PROCESS_HOLD_TIME)
                vty_out(vty, "zebra work-queue %u\n", zrouter.ribq->spec.hold);