]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: add bgp_path_info_labels_same()
authorLouis Scalbert <louis.scalbert@6wind.com>
Mon, 26 Feb 2024 11:10:16 +0000 (12:10 +0100)
committerLouis Scalbert <louis.scalbert@6wind.com>
Wed, 5 Jun 2024 09:08:46 +0000 (11:08 +0200)
Add bgp_path_info_labels_same() to compare labels with labels from
path_info. Remove labels_same() that was used for mplsvpn only.

Signed-off-by: Louis Scalbert <louis.scalbert@6wind.com>
bgpd/bgp_mplsvpn.c
bgpd/bgp_route.c
bgpd/bgp_route.h

index c58c67e6ac281ea2454ec2adb173d9561cb12a4a..6e4f93f1ea73e30ed210f4c07d0e74c753a2228f 100644 (file)
@@ -964,21 +964,6 @@ void transpose_sid(struct in6_addr *sid, uint32_t label, uint8_t offset,
        }
 }
 
-static bool labels_same(struct bgp_path_info *bpi, mpls_label_t *label,
-                       uint32_t n)
-{
-       if (!bpi->extra) {
-               if (!n)
-                       return true;
-               else
-                       return false;
-       }
-
-       return bgp_labels_same((const mpls_label_t *)bpi->extra->label,
-                              bpi->extra->num_labels,
-                              (const mpls_label_t *)label, n);
-}
-
 /*
  * make encoded route labels match specified encoded label set
  */
@@ -1129,7 +1114,8 @@ leak_update(struct bgp *to_bgp, struct bgp_dest *bn,
        }
 
        if (bpi) {
-               bool labelssame = labels_same(bpi, label, num_labels);
+               bool labelssame = bgp_path_info_labels_same(bpi, label,
+                                                           num_labels);
 
                if (CHECK_FLAG(source_bpi->flags, BGP_PATH_REMOVED)
                    && CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED)) {
index 8da30e789563d02fd226c6e81a94f8e60e8bc2de..bf3ffaedfeade025ca5438e0ccf34be4c6256911 100644 (file)
@@ -332,6 +332,19 @@ bool bgp_path_info_has_valid_label(const struct bgp_path_info *path)
        return bgp_is_valid_label(&path->extra->label[0]);
 }
 
+bool bgp_path_info_labels_same(const struct bgp_path_info *bpi,
+                              const mpls_label_t *label, uint32_t n)
+{
+       uint32_t bpi_num_labels;
+       const mpls_label_t *bpi_label;
+
+       bpi_num_labels = bpi->extra ? bpi->extra->num_labels : 0;
+       bpi_label = bpi_num_labels ? bpi->extra->label : NULL;
+
+       return bgp_labels_same(bpi_label, bpi_num_labels,
+                              (const mpls_label_t *)label, n);
+}
+
 /* Free bgp route information. */
 void bgp_path_info_free_with_caller(const char *name,
                                    struct bgp_path_info *path)
@@ -4851,10 +4864,7 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
                /* Same attribute comes in. */
                if (!CHECK_FLAG(pi->flags, BGP_PATH_REMOVED) && same_attr &&
                    (!has_valid_label ||
-                    (bgp_path_info_extra_get(pi) &&
-                     bgp_labels_same((const mpls_label_t *)pi->extra->label,
-                                     pi->extra->num_labels, label,
-                                     num_labels)))) {
+                    bgp_path_info_labels_same(pi, label, num_labels))) {
                        if (get_active_bdc_from_pi(pi, afi, safi) &&
                            peer->sort == BGP_PEER_EBGP &&
                            CHECK_FLAG(pi->flags, BGP_PATH_HISTORY)) {
@@ -5038,9 +5048,7 @@ void bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id,
                /* Update MPLS label */
                if (has_valid_label) {
                        extra = bgp_path_info_extra_get(pi);
-                       if (!bgp_labels_same((const mpls_label_t *)extra->label,
-                                            extra->num_labels, label,
-                                            num_labels)) {
+                       if (!bgp_path_info_labels_same(pi, label, num_labels)) {
                                memcpy(&extra->label, label,
                                       num_labels * sizeof(mpls_label_t));
                                extra->num_labels = num_labels;
index 7afd77cf6b97c633d8228e3536fdc4bb5a902918..2aa721a3b65a026aac60c04c6547a3e42e21a00a 100644 (file)
@@ -760,6 +760,8 @@ extern void bgp_path_info_unset_flag(struct bgp_dest *dest,
                                     struct bgp_path_info *path, uint32_t flag);
 extern void bgp_path_info_path_with_addpath_rx_str(struct bgp_path_info *pi,
                                                   char *buf, size_t buf_len);
+extern bool bgp_path_info_labels_same(const struct bgp_path_info *bpi,
+                                     const mpls_label_t *label, uint32_t n);
 
 extern int bgp_nlri_parse_ip(struct peer *, struct attr *, struct bgp_nlri *);