]> git.puffer.fish Git - matthieu/frr.git/commitdiff
lib, tests, zebra: keep table routes at vrf disabling
authorLouis Scalbert <louis.scalbert@6wind.com>
Mon, 23 Sep 2024 15:23:51 +0000 (17:23 +0200)
committerLouis Scalbert <louis.scalbert@6wind.com>
Mon, 10 Mar 2025 08:54:18 +0000 (09:54 +0100)
At VRF disabling, keep the route entries that was associated to its
table ID but not to the VRF itself. Kernel flushes these entries so we
need to reinstall them.

To do so, add a flag to mean that a route entry is owned by a table ID
and not by a VRF. If the VRF associated to the table ID is deleted, the
route entry must not be deleted.

Update to tests with new flag. 2057 is in hexa 0x809, meaning that the
new flag has been to some prefix.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
lib/zclient.c
lib/zclient.h
tests/topotests/zebra_rib/r1/import_mrib_table_2.json
tests/topotests/zebra_rib/r1/import_mrib_table_3.json
tests/topotests/zebra_rib/r1/import_mrib_table_4.json
tests/topotests/zebra_rib/r1/import_table_2.json
tests/topotests/zebra_rib/r1/import_table_3.json
tests/topotests/zebra_rib/r1/import_table_4.json
zebra/zebra_vrf.c

index f0476867be64c0b8941b61f02b92d6281645b5fb..bdb62befb9081f64384f60514aca57386ed14f18 100644 (file)
@@ -1362,6 +1362,8 @@ int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api)
        stream_putc(s, api->type);
 
        stream_putw(s, api->instance);
+       if (CHECK_FLAG(api->message, ZAPI_MESSAGE_TABLEID))
+               SET_FLAG(api->flags, ZEBRA_FLAG_TABLEID);
        stream_putl(s, api->flags);
        stream_putl(s, api->message);
 
@@ -1421,6 +1423,8 @@ int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api)
                                return -1;
                        }
 
+                       if (CHECK_FLAG(api->message, ZAPI_MESSAGE_TABLEID))
+                               SET_FLAG(api->flags, ZEBRA_FLAG_TABLEID);
                        if (zapi_nexthop_encode(s, api_nh, api->flags,
                                                api->message)
                            != 0)
@@ -1460,6 +1464,9 @@ int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api)
                                return -1;
                        }
 
+                       if (CHECK_FLAG(api->message, ZAPI_MESSAGE_TABLEID))
+                               SET_FLAG(api->flags, ZEBRA_FLAG_TABLEID);
+
                        if (zapi_nexthop_encode(s, api_nh, api->flags,
                                                api->message)
                            != 0)
index 43521d6e2e3ee46eea5d8b08e0c47d0c6e5b6ecc..8719af1d03c61d04e430b0af46bc15b89b10542a 100644 (file)
@@ -578,6 +578,12 @@ struct zapi_route {
  * kernel (NLM_F_APPEND at the very least )
  */
 #define ZEBRA_FLAG_OUTOFSYNC          0x400
+/*
+ * This flag lets us know that the route entry is
+ * associated to the table ID and must remain when the
+ * table ID is de-associated from a VRF.
+ */
+#define ZEBRA_FLAG_TABLEID 0x800
 
        /* The older XXX_MESSAGE flags live here */
        uint32_t message;
index 61aaaede6e52ffc6815c78149ef39b8a18c8c87c..03e4163269efcfaa5f56a6c62cad0a07bca17141 100644 (file)
@@ -68,7 +68,7 @@
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
@@ -97,7 +97,7 @@
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
index 27a0b9f26470ed4cdad7d790396423a292682a83..dd1774cd840bac9cb96563eed7ebd8f07ae87c15 100644 (file)
@@ -68,7 +68,7 @@
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
@@ -97,7 +97,7 @@
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
index 5a8f0eecd5a40d56fc8b86a01e3a97e7b118490c..9a318f9f00970da02aeb352f2850bb5e0c28e368 100644 (file)
@@ -68,7 +68,7 @@
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
@@ -97,7 +97,7 @@
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
index 61aaaede6e52ffc6815c78149ef39b8a18c8c87c..03e4163269efcfaa5f56a6c62cad0a07bca17141 100644 (file)
@@ -68,7 +68,7 @@
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
@@ -97,7 +97,7 @@
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
index 27a0b9f26470ed4cdad7d790396423a292682a83..dd1774cd840bac9cb96563eed7ebd8f07ae87c15 100644 (file)
@@ -68,7 +68,7 @@
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
@@ -97,7 +97,7 @@
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
index 5a8f0eecd5a40d56fc8b86a01e3a97e7b118490c..9a318f9f00970da02aeb352f2850bb5e0c28e368 100644 (file)
@@ -68,7 +68,7 @@
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
@@ -97,7 +97,7 @@
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
             "installed": true,
             "table": 254,
             "internalStatus": 16,
-            "internalFlags": 9,
+            "internalFlags": 2057,
             "nexthops": [
                 {
                     "flags": 3,
index faafcf7892ece490e319640c8d24f4d1686f3c5e..d652c57388ac29b96ae5d01410510bee88dd1285 100644 (file)
@@ -191,13 +191,19 @@ static void zebra_vrf_disable_update_vrfid(struct zebra_vrf *zvrf, afi_t afi, sa
                /* Assign the kernel route entries to the default VRF,
                 * even though they are not actually owned by it.
                 *
-                * Remove route nodes that have been created by FRR daemons.
-                * They are not needed if the VRF is disabled.
+                * Remove route nodes that were created by FRR daemons,
+                * unless they are associated with the table rather than the VRF.
+                * Routes associated with the VRF are not needed once the VRF is
+                * disabled.
                 */
                rn_delete = true;
                RNODE_FOREACH_RE_SAFE (rn, re, nre) {
-                       if (re->type == ZEBRA_ROUTE_KERNEL) {
+                       if (re->type == ZEBRA_ROUTE_KERNEL ||
+                           CHECK_FLAG(re->flags, ZEBRA_FLAG_TABLEID)) {
                                nexthop_vrf_update(rn, re, VRF_DEFAULT);
+                               if (CHECK_FLAG(re->flags, ZEBRA_FLAG_TABLEID))
+                                       /* reinstall routes */
+                                       rib_install_kernel(rn, re, NULL);
                                rn_delete = false;
                        } else
                                rib_unlink(rn, re);