]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: fix vni configuration in default vrf
authorIgor Ryzhov <iryzhov@nfware.com>
Sun, 14 Feb 2021 02:39:00 +0000 (05:39 +0300)
committerIgor Ryzhov <iryzhov@nfware.com>
Wed, 24 Mar 2021 15:55:56 +0000 (18:55 +0300)
VNI configuration is done without NB layer in default VRF. It leads to
the following problems:

```
vtysh -c "conf" -c "vni 1"
vtysh -c "conf" -c "vrf default" -c "no vni"
```
Second command does nothing, because the NB node is not created by the
first command.

```
vtysh -c "conf" -c "vrf default" -c "vni 1"
vtysh -c "conf" -c "no vni 1"
```
Second command doesn't delete the NB node created by the first command.

Signed-off-by: Igor Ryzhov <iryzhov@nfware.com>
zebra/zebra_vty.c

index fe75d845933e040b49d4298c6b84158478e04e00..be820992967b512441a9a75016a8f7124b7dc223 100644 (file)
@@ -2376,10 +2376,8 @@ DEFUN (default_vrf_vni_mapping,
        "VNI-ID\n"
        "Prefix routes only \n")
 {
-       int ret = 0;
-       char err[ERR_STR_SZ];
+       char xpath[XPATH_MAXLEN];
        struct zebra_vrf *zvrf = NULL;
-       vni_t vni = strtoul(argv[1]->arg, NULL, 10);
        int filter = 0;
 
        zvrf = vrf_info_lookup(VRF_DEFAULT);
@@ -2389,25 +2387,35 @@ DEFUN (default_vrf_vni_mapping,
        if (argc == 3)
                filter = 1;
 
-       ret = zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ,
-                                             filter, 1);
-       if (ret != 0) {
-               vty_out(vty, "%s\n", err);
-               return CMD_WARNING;
+       snprintf(xpath, sizeof(xpath), FRR_VRF_KEY_XPATH "/frr-zebra:zebra",
+                VRF_DEFAULT_NAME);
+       nb_cli_enqueue_change(vty, xpath, NB_OP_CREATE, NULL);
+
+       snprintf(xpath, sizeof(xpath),
+                FRR_VRF_KEY_XPATH "/frr-zebra:zebra/l3vni-id",
+                VRF_DEFAULT_NAME);
+       nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, argv[1]->arg);
+
+       if (filter) {
+               snprintf(xpath, sizeof(xpath),
+                        FRR_VRF_KEY_XPATH "/frr-zebra:zebra/prefix-only",
+                        VRF_DEFAULT_NAME);
+               nb_cli_enqueue_change(vty, xpath, NB_OP_MODIFY, "true");
        }
 
-       return CMD_SUCCESS;
+       return nb_cli_apply_changes(vty, NULL);
 }
 
 DEFUN (no_default_vrf_vni_mapping,
        no_default_vrf_vni_mapping_cmd,
-       "no vni " CMD_VNI_RANGE,
+       "no vni " CMD_VNI_RANGE "[prefix-routes-only]",
        NO_STR
        "VNI corresponding to DEFAULT VRF\n"
-       "VNI-ID")
+       "VNI-ID\n"
+       "Prefix routes only \n")
 {
-       int ret = 0;
-       char err[ERR_STR_SZ];
+       char xpath[XPATH_MAXLEN];
+       int filter = 0;
        vni_t vni = strtoul(argv[2]->arg, NULL, 10);
        struct zebra_vrf *zvrf = NULL;
 
@@ -2415,13 +2423,32 @@ DEFUN (no_default_vrf_vni_mapping,
        if (!zvrf)
                return CMD_WARNING;
 
-       ret = zebra_vxlan_process_vrf_vni_cmd(zvrf, vni, err, ERR_STR_SZ, 0, 0);
-       if (ret != 0) {
-               vty_out(vty, "%s\n", err);
+       if (argc == 4)
+               filter = 1;
+
+       if (zvrf->l3vni != vni) {
+               vty_out(vty, "VNI %d doesn't exist in VRF: %s \n", vni,
+                       zvrf->vrf->name);
                return CMD_WARNING;
        }
 
-       return CMD_SUCCESS;
+       snprintf(xpath, sizeof(xpath),
+                FRR_VRF_KEY_XPATH "/frr-zebra:zebra/l3vni-id",
+                VRF_DEFAULT_NAME);
+       nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, argv[2]->arg);
+
+       if (filter) {
+               snprintf(xpath, sizeof(xpath),
+                        FRR_VRF_KEY_XPATH "/frr-zebra:zebra/prefix-only",
+                        VRF_DEFAULT_NAME);
+               nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, "true");
+       }
+
+       snprintf(xpath, sizeof(xpath), FRR_VRF_KEY_XPATH "/frr-zebra:zebra",
+                VRF_DEFAULT_NAME);
+       nb_cli_enqueue_change(vty, xpath, NB_OP_DESTROY, NULL);
+
+       return nb_cli_apply_changes(vty, NULL);
 }
 
 DEFUN (vrf_vni_mapping,
@@ -2449,9 +2476,7 @@ DEFUN (vrf_vni_mapping,
                nb_cli_enqueue_change(vty, "./frr-zebra:zebra/prefix-only",
                                      NB_OP_MODIFY, "true");
 
-       nb_cli_apply_changes(vty, NULL);
-
-       return CMD_SUCCESS;
+       return nb_cli_apply_changes(vty, NULL);
 }
 
 DEFUN (no_vrf_vni_mapping,
@@ -2488,9 +2513,7 @@ DEFUN (no_vrf_vni_mapping,
 
        nb_cli_enqueue_change(vty, "./frr-zebra:zebra", NB_OP_DESTROY, NULL);
 
-       nb_cli_apply_changes(vty, NULL);
-
-       return CMD_SUCCESS;
+       return nb_cli_apply_changes(vty, NULL);
 }
 
 /* show vrf */