]> git.puffer.fish Git - matthieu/frr.git/commitdiff
zebra: fix wrong check for mpls label
authoranlan_cs <anlan_cs@tom.com>
Fri, 5 Apr 2024 07:03:15 +0000 (15:03 +0800)
committeranlan_cs <anlan_cs@tom.com>
Sat, 6 Apr 2024 01:01:39 +0000 (09:01 +0800)
Add a parameter for `zebra_mpls_fec_for_label()`, as before if it is `NULL`,
otherwise exclude what this parameter represents.

Before:
```
anlan(config)# mpls label bind 1.1.1.2/32 88
anlan(config)# mpls label bind 1.1.1.2/32 88
% Label already bound to a FEC
anlan(config)# mpls label bind 1.1.1.3/32 88
% Label already bound to a FEC
```

After:
```
anlan(config)# mpls label bind 1.1.1.2/32 88
anlan(config)# mpls label bind 1.1.1.2/32 88
anlan(config)# mpls label bind 1.1.1.3/32 88
% Label already bound to a FEC
```

Signed-off-by: anlan_cs <anlan_cs@tom.com>
zebra/zebra_mpls.c
zebra/zebra_mpls.h
zebra/zebra_mpls_vty.c

index cc2cf9b9ff0ff2ed50e654b080d898396465a65c..4cc85d461f4a2f699303619eba0c2eaa3808fc6e 100644 (file)
@@ -2476,7 +2476,7 @@ static int zebra_mpls_cleanup_zclient_labels(struct zserv *client)
  * hash..
  */
 struct zebra_fec *zebra_mpls_fec_for_label(struct zebra_vrf *zvrf,
-                                          mpls_label_t label)
+                                          struct prefix *p, mpls_label_t label)
 {
        struct route_node *rn;
        struct zebra_fec *fec;
@@ -2491,8 +2491,11 @@ struct zebra_fec *zebra_mpls_fec_for_label(struct zebra_vrf *zvrf,
                        if (!rn->info)
                                continue;
                        fec = rn->info;
-                       if (fec->label == label)
+                       if (fec->label == label) {
+                               if (p && prefix_same(p, &rn->p))
+                                       return NULL;
                                return fec;
+                       }
                }
        }
 
@@ -2502,9 +2505,10 @@ struct zebra_fec *zebra_mpls_fec_for_label(struct zebra_vrf *zvrf,
 /*
  * Inform if specified label is currently bound to a FEC or not.
  */
-int zebra_mpls_label_already_bound(struct zebra_vrf *zvrf, mpls_label_t label)
+int zebra_mpls_label_already_bound(struct zebra_vrf *zvrf, struct prefix *p,
+                                  mpls_label_t label)
 {
-       return (zebra_mpls_fec_for_label(zvrf, label) ? 1 : 0);
+       return (zebra_mpls_fec_for_label(zvrf, p, label) ? 1 : 0);
 }
 
 /*
index 1ed2f9b41c5b571b406d21dbae997a35e6e779ee..dd6f9601468a7c54238d9c01708801331511e909 100644 (file)
@@ -203,12 +203,13 @@ int zebra_mpls_fec_unregister(struct zebra_vrf *zvrf, struct prefix *p,
  * hash..
  */
 struct zebra_fec *zebra_mpls_fec_for_label(struct zebra_vrf *zvrf,
-                                          mpls_label_t label);
+                                          struct prefix *p, mpls_label_t label);
 
 /*
  * Inform if specified label is currently bound to a FEC or not.
  */
-int zebra_mpls_label_already_bound(struct zebra_vrf *zvrf, mpls_label_t label);
+int zebra_mpls_label_already_bound(struct zebra_vrf *zvrf, struct prefix *p,
+                                  mpls_label_t label);
 
 /*
  * Add static FEC to label binding. If there are clients registered for this
index fd09e6b444464f5c4a22c633a63b2d34714f4dd2..8248d4a555350b3afec5d6775f84a844e826d97b 100644 (file)
@@ -210,7 +210,7 @@ static int zebra_mpls_bind(struct vty *vty, int add_cmd, const char *prefix,
                                vty_out(vty, "%% Invalid label\n");
                                return CMD_WARNING_CONFIG_FAILED;
                        }
-                       if (zebra_mpls_label_already_bound(zvrf, label)) {
+                       if (zebra_mpls_label_already_bound(zvrf, &p, label)) {
                                vty_out(vty,
                                        "%% Label already bound to a FEC\n");
                                return CMD_WARNING_CONFIG_FAILED;