]> git.proxmox.com Git - mirror_frr.git/commitdiff
bgpd: Check and extract link bandwidth value
authorvivek <vivek@cumulusnetworks.com>
Tue, 24 Mar 2020 19:17:19 +0000 (12:17 -0700)
committervivek <vivek@cumulusnetworks.com>
Tue, 31 Mar 2020 03:12:31 +0000 (20:12 -0700)
Extract link bandwidth value into attribute from the extended
community, if present.

Signed-off-by: Vivek Venkatraman <vivek@cumulusnetworks.com>
bgpd/bgp_attr.c
bgpd/bgp_attr.h
bgpd/bgp_ecommunity.c
bgpd/bgp_ecommunity.h

index 221386e38de8fbc58568f1a698f88d11640a7e2a..d6eb6beddb441f4179197d925140177259d24943 100644 (file)
@@ -2246,6 +2246,9 @@ bgp_attr_ext_communities(struct bgp_attr_parser_args *args)
        bgp_attr_extcom_tunnel_type(attr,
                (bgp_encap_types *)&attr->encap_tunneltype);
 
+       /* Extract link bandwidth, if any. */
+       (void)ecommunity_linkbw_present(attr->ecommunity, &attr->link_bw);
+
        return BGP_ATTR_PARSE_PROCEED;
 }
 
index 98a9a620f76a372c488b2859a0af3e4e146cedf2..5fec4be29c467b5e19b101181902ce01bfe03961 100644 (file)
@@ -250,6 +250,9 @@ struct attr {
 
        /* rmap set table */
        uint32_t rmap_table_id;
+
+       /* Link bandwidth value, if any. */
+       uint32_t link_bw;
 };
 
 /* rmap_change_flags definition */
@@ -409,5 +412,4 @@ static inline uint32_t mac_mobility_seqnum(struct attr *attr)
 {
        return (attr) ? attr->mm_seqnum : 0;
 }
-
 #endif /* _QUAGGA_BGP_ATTR_H */
index 5e5a32d420cb4c1f228d351b81cc4e977872d4d2..dd97a3d21377be997dceb0aa7c838c63e922fb55 100644 (file)
@@ -1203,3 +1203,42 @@ void bgp_remove_ecomm_from_aggregate_hash(struct bgp_aggregate *aggregate,
                }
        }
 }
+
+/*
+ * return the BGP link bandwidth extended community, if present;
+ * the actual bandwidth is returned via param
+ */
+const uint8_t *ecommunity_linkbw_present(struct ecommunity *ecom, uint32_t *bw)
+{
+       const uint8_t *eval;
+       int i;
+
+       if (bw)
+               *bw = 0;
+
+       if (!ecom || !ecom->size)
+               return NULL;
+
+       for (i = 0; i < ecom->size; i++) {
+               const uint8_t *pnt;
+               uint8_t type, sub_type;
+               uint32_t bwval;
+
+               eval = pnt = (ecom->val + (i * ECOMMUNITY_SIZE));
+               type = *pnt++;
+               sub_type = *pnt++;
+
+               if ((type == ECOMMUNITY_ENCODE_AS ||
+                    type == ECOMMUNITY_ENCODE_AS_NON_TRANS) &&
+                   sub_type == ECOMMUNITY_LINK_BANDWIDTH) {
+                       pnt += 2; /* bandwidth is encoded as AS:val */
+                       pnt = ptr_get_be32(pnt, &bwval);
+                       (void)pnt; /* consume value */
+                       if (bw)
+                               *bw = bwval;
+                       return eval;
+               }
+       }
+
+       return NULL;
+}
index b61deba922d5cd4d82b51229d6276098a58f818b..3aeafb75eaf65352666d17812a4c3c9a2c304bf3 100644 (file)
@@ -236,7 +236,8 @@ extern void bgp_remove_ecomm_from_aggregate_hash(
                                        struct bgp_aggregate *aggregate,
                                        struct ecommunity *ecommunity);
 extern void bgp_aggr_ecommunity_remove(void *arg);
-
+extern const uint8_t *ecommunity_linkbw_present(struct ecommunity *ecom,
+                                               uint32_t *bw);
 
 static inline void ecommunity_strip_rts(struct ecommunity *ecom)
 {