]> git.puffer.fish Git - mirror/frr.git/commitdiff
lib: Ignore duplicate alist/plist entries in CLI 11125/head
authorDonatas Abraitis <donatas@opensourcerouting.org>
Mon, 25 Apr 2022 16:06:49 +0000 (19:06 +0300)
committerMergify <37929162+mergify[bot]@users.noreply.github.com>
Fri, 29 Apr 2022 15:00:25 +0000 (15:00 +0000)
If duplicate value is entered, the whole plist/alist just dropped.

Before:
```
$ grep prefix-list /etc/frr/frr.conf
ip prefix-list test seq 5 permit 1.1.1.1/32
ip prefix-list test seq 10 permit 1.1.1.1/32
$ systemctl restart frr
$ vtysh -c 'show run | include prefix-list'
$
```

After:
```
$ grep prefix-list /etc/frr/frr.conf
ip prefix-list test seq 5 permit 1.1.1.1/32
ip prefix-list test seq 10 permit 1.1.1.1/32
$ systemctl restart frr
$ vtysh -c 'show run | include prefix-list'
ip prefix-list test seq 5 permit 1.1.1.1/32
```

Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
(cherry picked from commit 1db0e0c6c8aba5023f807a1be03ca97d20f3c20d)

lib/filter_cli.c

index fb40c527dda7ff9a91b4649a84690405bc2d3602..9a877a57041d8778ac0b6ad1ad7fd53cb8b68385 100644 (file)
@@ -151,28 +151,25 @@ DEFPY_YANG(
         * Backward compatibility: don't complain about duplicated values,
         * just silently accept.
         */
-       if (seq_str == NULL) {
-               ada.ada_type = "ipv4";
-               ada.ada_name = name;
-               ada.ada_action = action;
-               if (host_str && mask_str == NULL) {
-                       ada.ada_xpath[0] = "./host";
-                       ada.ada_value[0] = host_str;
-               } else if (host_str && mask_str) {
-                       ada.ada_xpath[0] = "./network/address";
-                       ada.ada_value[0] = host_str;
-                       ada.ada_xpath[1] = "./network/mask";
-                       ada.ada_value[1] = mask_str;
-               } else {
-                       ada.ada_xpath[0] = "./source-any";
-                       ada.ada_value[0] = "";
-               }
-
-               /* Duplicated entry without sequence, just quit. */
-               if (acl_is_dup(vty->candidate_config->dnode, &ada))
-                       return CMD_SUCCESS;
+       ada.ada_type = "ipv4";
+       ada.ada_name = name;
+       ada.ada_action = action;
+       if (host_str && mask_str == NULL) {
+               ada.ada_xpath[0] = "./host";
+               ada.ada_value[0] = host_str;
+       } else if (host_str && mask_str) {
+               ada.ada_xpath[0] = "./network/address";
+               ada.ada_value[0] = host_str;
+               ada.ada_xpath[1] = "./network/mask";
+               ada.ada_value[1] = mask_str;
+       } else {
+               ada.ada_xpath[0] = "./source-any";
+               ada.ada_value[0] = "";
        }
 
+       if (acl_is_dup(vty->candidate_config->dnode, &ada))
+               return CMD_SUCCESS;
+
        /*
         * Create the access-list first, so we can generate sequence if
         * none given (backward compatibility).
@@ -280,49 +277,46 @@ DEFPY_YANG(
         * Backward compatibility: don't complain about duplicated values,
         * just silently accept.
         */
-       if (seq_str == NULL) {
-               ada.ada_type = "ipv4";
-               ada.ada_name = name;
-               ada.ada_action = action;
-               if (src_str && src_mask_str == NULL) {
-                       ada.ada_xpath[idx] = "./host";
-                       ada.ada_value[idx] = src_str;
-                       idx++;
-               } else if (src_str && src_mask_str) {
-                       ada.ada_xpath[idx] = "./network/address";
-                       ada.ada_value[idx] = src_str;
-                       idx++;
-                       ada.ada_xpath[idx] = "./network/mask";
-                       ada.ada_value[idx] = src_mask_str;
-                       idx++;
-               } else {
-                       ada.ada_xpath[idx] = "./source-any";
-                       ada.ada_value[idx] = "";
-                       idx++;
-               }
-
-               if (dst_str && dst_mask_str == NULL) {
-                       ada.ada_xpath[idx] = "./destination-host";
-                       ada.ada_value[idx] = dst_str;
-                       idx++;
-               } else if (dst_str && dst_mask_str) {
-                       ada.ada_xpath[idx] = "./destination-network/address";
-                       ada.ada_value[idx] = dst_str;
-                       idx++;
-                       ada.ada_xpath[idx] = "./destination-network/mask";
-                       ada.ada_value[idx] = dst_mask_str;
-                       idx++;
-               } else {
-                       ada.ada_xpath[idx] = "./destination-any";
-                       ada.ada_value[idx] = "";
-                       idx++;
-               }
+       ada.ada_type = "ipv4";
+       ada.ada_name = name;
+       ada.ada_action = action;
+       if (src_str && src_mask_str == NULL) {
+               ada.ada_xpath[idx] = "./host";
+               ada.ada_value[idx] = src_str;
+               idx++;
+       } else if (src_str && src_mask_str) {
+               ada.ada_xpath[idx] = "./network/address";
+               ada.ada_value[idx] = src_str;
+               idx++;
+               ada.ada_xpath[idx] = "./network/mask";
+               ada.ada_value[idx] = src_mask_str;
+               idx++;
+       } else {
+               ada.ada_xpath[idx] = "./source-any";
+               ada.ada_value[idx] = "";
+               idx++;
+       }
 
-               /* Duplicated entry without sequence, just quit. */
-               if (acl_is_dup(vty->candidate_config->dnode, &ada))
-                       return CMD_SUCCESS;
+       if (dst_str && dst_mask_str == NULL) {
+               ada.ada_xpath[idx] = "./destination-host";
+               ada.ada_value[idx] = dst_str;
+               idx++;
+       } else if (dst_str && dst_mask_str) {
+               ada.ada_xpath[idx] = "./destination-network/address";
+               ada.ada_value[idx] = dst_str;
+               idx++;
+               ada.ada_xpath[idx] = "./destination-network/mask";
+               ada.ada_value[idx] = dst_mask_str;
+               idx++;
+       } else {
+               ada.ada_xpath[idx] = "./destination-any";
+               ada.ada_value[idx] = "";
+               idx++;
        }
 
+       if (acl_is_dup(vty->candidate_config->dnode, &ada))
+               return CMD_SUCCESS;
+
        /*
         * Create the access-list first, so we can generate sequence if
         * none given (backward compatibility).
@@ -466,28 +460,25 @@ DEFPY_YANG(
         * Backward compatibility: don't complain about duplicated values,
         * just silently accept.
         */
-       if (seq_str == NULL) {
-               ada.ada_type = "ipv4";
-               ada.ada_name = name;
-               ada.ada_action = action;
-
-               if (prefix_str) {
-                       ada.ada_xpath[0] = "./ipv4-prefix";
-                       ada.ada_value[0] = prefix_str;
-                       if (exact) {
-                               ada.ada_xpath[1] = "./ipv4-exact-match";
-                               ada.ada_value[1] = "true";
-                       }
-               } else {
-                       ada.ada_xpath[0] = "./any";
-                       ada.ada_value[0] = "";
-               }
+       ada.ada_type = "ipv4";
+       ada.ada_name = name;
+       ada.ada_action = action;
 
-               /* Duplicated entry without sequence, just quit. */
-               if (acl_is_dup(vty->candidate_config->dnode, &ada))
-                       return CMD_SUCCESS;
+       if (prefix_str) {
+               ada.ada_xpath[0] = "./ipv4-prefix";
+               ada.ada_value[0] = prefix_str;
+               if (exact) {
+                       ada.ada_xpath[1] = "./ipv4-exact-match";
+                       ada.ada_value[1] = "true";
+               }
+       } else {
+               ada.ada_xpath[0] = "./any";
+               ada.ada_value[0] = "";
        }
 
+       if (acl_is_dup(vty->candidate_config->dnode, &ada))
+               return CMD_SUCCESS;
+
        /*
         * Create the access-list first, so we can generate sequence if
         * none given (backward compatibility).
@@ -656,28 +647,25 @@ DEFPY_YANG(
         * Backward compatibility: don't complain about duplicated values,
         * just silently accept.
         */
-       if (seq_str == NULL) {
-               ada.ada_type = "ipv6";
-               ada.ada_name = name;
-               ada.ada_action = action;
-
-               if (prefix_str) {
-                       ada.ada_xpath[0] = "./ipv6-prefix";
-                       ada.ada_value[0] = prefix_str;
-                       if (exact) {
-                               ada.ada_xpath[1] = "./ipv6-exact-match";
-                               ada.ada_value[1] = "true";
-                       }
-               } else {
-                       ada.ada_xpath[0] = "./any";
-                       ada.ada_value[0] = "";
-               }
+       ada.ada_type = "ipv6";
+       ada.ada_name = name;
+       ada.ada_action = action;
 
-               /* Duplicated entry without sequence, just quit. */
-               if (acl_is_dup(vty->candidate_config->dnode, &ada))
-                       return CMD_SUCCESS;
+       if (prefix_str) {
+               ada.ada_xpath[0] = "./ipv6-prefix";
+               ada.ada_value[0] = prefix_str;
+               if (exact) {
+                       ada.ada_xpath[1] = "./ipv6-exact-match";
+                       ada.ada_value[1] = "true";
+               }
+       } else {
+               ada.ada_xpath[0] = "./any";
+               ada.ada_value[0] = "";
        }
 
+       if (acl_is_dup(vty->candidate_config->dnode, &ada))
+               return CMD_SUCCESS;
+
        /*
         * Create the access-list first, so we can generate sequence if
         * none given (backward compatibility).
@@ -850,24 +838,21 @@ DEFPY_YANG(
         * Backward compatibility: don't complain about duplicated values,
         * just silently accept.
         */
-       if (seq_str == NULL) {
-               ada.ada_type = "mac";
-               ada.ada_name = name;
-               ada.ada_action = action;
-
-               if (mac_str) {
-                       ada.ada_xpath[0] = "./mac";
-                       ada.ada_value[0] = mac_str;
-               } else {
-                       ada.ada_xpath[0] = "./any";
-                       ada.ada_value[0] = "";
-               }
+       ada.ada_type = "mac";
+       ada.ada_name = name;
+       ada.ada_action = action;
 
-               /* Duplicated entry without sequence, just quit. */
-               if (acl_is_dup(vty->candidate_config->dnode, &ada))
-                       return CMD_SUCCESS;
+       if (mac_str) {
+               ada.ada_xpath[0] = "./mac";
+               ada.ada_value[0] = mac_str;
+       } else {
+               ada.ada_xpath[0] = "./any";
+               ada.ada_value[0] = "";
        }
 
+       if (acl_is_dup(vty->candidate_config->dnode, &ada))
+               return CMD_SUCCESS;
+
        /*
         * Create the access-list first, so we can generate sequence if
         * none given (backward compatibility).
@@ -1272,23 +1257,20 @@ DEFPY_YANG(
         * Backward compatibility: don't complain about duplicated values,
         * just silently accept.
         */
-       if (seq_str == NULL) {
-               pda.pda_type = "ipv4";
-               pda.pda_name = name;
-               pda.pda_action = action;
-               if (prefix_str) {
-                       prefix_copy(&pda.prefix, prefix);
-                       pda.ge = ge;
-                       pda.le = le;
-               } else {
-                       pda.any = true;
-               }
-
-               /* Duplicated entry without sequence, just quit. */
-               if (plist_is_dup(vty->candidate_config->dnode, &pda))
-                       return CMD_SUCCESS;
+       pda.pda_type = "ipv4";
+       pda.pda_name = name;
+       pda.pda_action = action;
+       if (prefix_str) {
+               prefix_copy(&pda.prefix, prefix);
+               pda.ge = ge;
+               pda.le = le;
+       } else {
+               pda.any = true;
        }
 
+       if (plist_is_dup(vty->candidate_config->dnode, &pda))
+               return CMD_SUCCESS;
+
        /*
         * Create the prefix-list first, so we can generate sequence if
         * none given (backward compatibility).
@@ -1476,23 +1458,20 @@ DEFPY_YANG(
         * Backward compatibility: don't complain about duplicated values,
         * just silently accept.
         */
-       if (seq_str == NULL) {
-               pda.pda_type = "ipv6";
-               pda.pda_name = name;
-               pda.pda_action = action;
-               if (prefix_str) {
-                       prefix_copy(&pda.prefix, prefix);
-                       pda.ge = ge;
-                       pda.le = le;
-               } else {
-                       pda.any = true;
-               }
-
-               /* Duplicated entry without sequence, just quit. */
-               if (plist_is_dup(vty->candidate_config->dnode, &pda))
-                       return CMD_SUCCESS;
+       pda.pda_type = "ipv6";
+       pda.pda_name = name;
+       pda.pda_action = action;
+       if (prefix_str) {
+               prefix_copy(&pda.prefix, prefix);
+               pda.ge = ge;
+               pda.le = le;
+       } else {
+               pda.any = true;
        }
 
+       if (plist_is_dup(vty->candidate_config->dnode, &pda))
+               return CMD_SUCCESS;
+
        /*
         * Create the prefix-list first, so we can generate sequence if
         * none given (backward compatibility).