]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: Use uint32_t for size value instead of int in ecommunity struct
authorDonald Sharp <sharpd@nvidia.com>
Sun, 17 Jan 2021 21:08:03 +0000 (16:08 -0500)
committerDonald Sharp <sharpd@nvidia.com>
Mon, 18 Jan 2021 14:06:49 +0000 (09:06 -0500)
The `struct ecommunity` structure is using an int for a size value.
Let's switch it over to a uint32_t for size values since a size
value for data can never be negative.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
bgpd/bgp_attr.c
bgpd/bgp_attr_evpn.c
bgpd/bgp_ecommunity.c
bgpd/bgp_ecommunity.h
bgpd/bgp_evpn.c
bgpd/bgp_mplsvpn.c
bgpd/bgp_pbr.c
bgpd/rfapi/rfapi_import.c
bgpd/rfapi/vnc_export_bgp.c

index ce22e8404d41eb90bac32454ddc0c250a2ea3fc0..c25d0e269a7b42dc09299d90d080c024dfb2d7dd 100644 (file)
@@ -3395,7 +3395,8 @@ void bgp_attr_extcom_tunnel_type(struct attr *attr,
                                 bgp_encap_types *tunnel_type)
 {
        struct ecommunity *ecom;
-       int i;
+       uint32_t i;
+
        if (!attr)
                return;
 
@@ -4021,7 +4022,7 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer,
                        uint8_t *pnt;
                        int tbit;
                        int ecom_tr_size = 0;
-                       int i;
+                       uint32_t i;
 
                        for (i = 0; i < attr->ecommunity->size; i++) {
                                pnt = attr->ecommunity->val + (i * 8);
index 7cc9ecd79edfc4a03bccda858e9e1bb84693bd1a..1df646c34652622e6f1388e55dcb5c0fb9c704a2 100644 (file)
@@ -89,7 +89,7 @@ char *ecom_mac2str(char *ecom_mac)
 /* Fetch router-mac from extended community */
 bool bgp_attr_rmac(struct attr *attr, struct ethaddr *rmac)
 {
-       int i = 0;
+       uint32_t i = 0;
        struct ecommunity *ecom;
 
        ecom = attr->ecommunity;
@@ -122,7 +122,7 @@ bool bgp_attr_rmac(struct attr *attr, struct ethaddr *rmac)
 uint8_t bgp_attr_default_gw(struct attr *attr)
 {
        struct ecommunity *ecom;
-       int i;
+       uint32_t i;
 
        ecom = attr->ecommunity;
        if (!ecom || !ecom->size)
@@ -153,7 +153,7 @@ uint8_t bgp_attr_default_gw(struct attr *attr)
 uint16_t bgp_attr_df_pref_from_ec(struct attr *attr, uint8_t *alg)
 {
        struct ecommunity *ecom;
-       int i;
+       uint32_t i;
        uint16_t df_pref = 0;
 
        *alg = EVPN_MH_DF_ALG_SERVICE_CARVING;
@@ -190,7 +190,7 @@ uint16_t bgp_attr_df_pref_from_ec(struct attr *attr, uint8_t *alg)
 uint32_t bgp_attr_mac_mobility_seqnum(struct attr *attr, uint8_t *sticky)
 {
        struct ecommunity *ecom;
-       int i;
+       uint32_t i;
        uint8_t flags = 0;
 
        ecom = attr->ecommunity;
@@ -237,7 +237,7 @@ void bgp_attr_evpn_na_flag(struct attr *attr,
                uint8_t *router_flag, bool *proxy)
 {
        struct ecommunity *ecom;
-       int i;
+       uint32_t i;
        uint8_t val;
 
        ecom = attr->ecommunity;
index 43bfb3e2bc82a25435947a35f05d6724ea05a976..c358d4203ed4f2cb4a18466fe420affc3ec42b4d 100644 (file)
@@ -95,7 +95,7 @@ static bool ecommunity_add_val_internal(struct ecommunity *ecom,
                                        bool unique, bool overwrite,
                                        uint8_t ecom_size)
 {
-       int c, ins_idx;
+       uint32_t c, ins_idx;
        const struct ecommunity_val *eval4 = (struct ecommunity_val *)eval;
        const struct ecommunity_val_ipv6 *eval6 =
                (struct ecommunity_val_ipv6 *)eval;
@@ -113,7 +113,7 @@ static bool ecommunity_add_val_internal(struct ecommunity *ecom,
        /* check also if the extended community itself exists. */
        c = 0;
 
-       ins_idx = -1;
+       ins_idx = UINT32_MAX;
        for (uint8_t *p = ecom->val; c < ecom->size;
             p += ecom_size, c++) {
                if (unique) {
@@ -145,12 +145,12 @@ static bool ecommunity_add_val_internal(struct ecommunity *ecom,
                if (ret > 0) {
                        if (!unique)
                                break;
-                       if (ins_idx == -1)
+                       if (ins_idx == UINT32_MAX)
                                ins_idx = c;
                }
        }
 
-       if (ins_idx == -1)
+       if (ins_idx == UINT32_MAX)
                ins_idx = c;
 
        /* Add the value to the structure with numerical sorting.  */
@@ -193,7 +193,7 @@ static struct ecommunity *
 ecommunity_uniq_sort_internal(struct ecommunity *ecom,
                              unsigned short ecom_size)
 {
-       int i;
+       uint32_t i;
        struct ecommunity *new;
        const void *eval;
 
@@ -895,7 +895,7 @@ static int ecommunity_lb_str(char *buf, size_t bufsz, const uint8_t *pnt)
 */
 char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
 {
-       int i;
+       uint32_t i;
        uint8_t *pnt;
        uint8_t type = 0;
        uint8_t sub_type = 0;
@@ -1176,8 +1176,8 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
 bool ecommunity_match(const struct ecommunity *ecom1,
                      const struct ecommunity *ecom2)
 {
-       int i = 0;
-       int j = 0;
+       uint32_t i = 0;
+       uint32_t j = 0;
 
        if (ecom1 == NULL && ecom2 == NULL)
                return true;
@@ -1209,7 +1209,7 @@ extern struct ecommunity_val *ecommunity_lookup(const struct ecommunity *ecom,
                                                uint8_t type, uint8_t subtype)
 {
        uint8_t *p;
-       int c;
+       uint32_t c;
 
        /* If the value already exists in the structure return 0.  */
        c = 0;
@@ -1230,7 +1230,7 @@ bool ecommunity_strip(struct ecommunity *ecom, uint8_t type,
                      uint8_t subtype)
 {
        uint8_t *p, *q, *new;
-       int c, found = 0;
+       uint32_t c, found = 0;
        /* When this is fist value, just add it.  */
        if (ecom == NULL || ecom->val == NULL)
                return false;
@@ -1278,7 +1278,7 @@ bool ecommunity_strip(struct ecommunity *ecom, uint8_t type,
 bool ecommunity_del_val(struct ecommunity *ecom, struct ecommunity_val *eval)
 {
        uint8_t *p;
-       int c, found = 0;
+       uint32_t c, found = 0;
 
        /* Make sure specified value exists. */
        if (ecom == NULL || ecom->val == NULL)
@@ -1512,7 +1512,7 @@ void bgp_remove_ecomm_from_aggregate_hash(struct bgp_aggregate *aggregate,
 const uint8_t *ecommunity_linkbw_present(struct ecommunity *ecom, uint32_t *bw)
 {
        const uint8_t *eval;
-       int i;
+       uint32_t i;
 
        if (bw)
                *bw = 0;
index 6318e7edb1e3081994048a72636ad8aed9de662d..6d0275a0c3bab9a8b94c52207803cf39fd1184c9 100644 (file)
@@ -114,7 +114,7 @@ struct ecommunity {
        uint8_t unit_size;
 
        /* Size of Extended Communities attribute.  */
-       int size;
+       uint32_t size;
 
        /* Extended Communities value.  */
        uint8_t *val;
index 96f4b0aa780e86342bb6cd33a8754d9ccdd61dbb..88747b14b158c4d3c1f1a598dcab0a5b7af5acc1 100644 (file)
@@ -870,7 +870,7 @@ static void add_mac_mobility_to_attr(uint32_t seq_num, struct attr *attr)
        struct ecommunity ecom_tmp;
        struct ecommunity_val eval;
        uint8_t *ecom_val_ptr;
-       int i;
+       uint32_t i;
        uint8_t *pnt;
        int type = 0;
        int sub_type = 0;
@@ -2710,7 +2710,7 @@ static int is_route_matching_for_vrf(struct bgp *bgp_vrf,
 {
        struct attr *attr = pi->attr;
        struct ecommunity *ecom;
-       int i;
+       uint32_t i;
 
        assert(attr);
        /* Route should have valid RT to be even considered. */
@@ -2777,7 +2777,7 @@ static int is_route_matching_for_vni(struct bgp *bgp, struct bgpevpn *vpn,
 {
        struct attr *attr = pi->attr;
        struct ecommunity *ecom;
-       int i;
+       uint32_t i;
 
        assert(attr);
        /* Route should have valid RT to be even considered. */
@@ -3260,7 +3260,7 @@ static int bgp_evpn_install_uninstall_table(struct bgp *bgp, afi_t afi,
        struct prefix_evpn *evp = (struct prefix_evpn *)p;
        struct attr *attr = pi->attr;
        struct ecommunity *ecom;
-       int i;
+       uint32_t i;
        struct prefix_evpn ad_evp;
 
        assert(attr);
@@ -4906,7 +4906,7 @@ int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr,
  */
 void bgp_evpn_map_vrf_to_its_rts(struct bgp *bgp_vrf)
 {
-       int i = 0;
+       uint32_t i = 0;
        struct ecommunity_val *eval = NULL;
        struct listnode *node = NULL, *nnode = NULL;
        struct ecommunity *ecom = NULL;
@@ -4926,7 +4926,7 @@ void bgp_evpn_map_vrf_to_its_rts(struct bgp *bgp_vrf)
  */
 void bgp_evpn_unmap_vrf_from_its_rts(struct bgp *bgp_vrf)
 {
-       int i;
+       uint32_t i;
        struct ecommunity_val *eval;
        struct listnode *node, *nnode;
        struct ecommunity *ecom;
@@ -4963,7 +4963,7 @@ void bgp_evpn_unmap_vrf_from_its_rts(struct bgp *bgp_vrf)
  */
 void bgp_evpn_map_vni_to_its_rts(struct bgp *bgp, struct bgpevpn *vpn)
 {
-       int i;
+       uint32_t i;
        struct ecommunity_val *eval;
        struct listnode *node, *nnode;
        struct ecommunity *ecom;
@@ -4983,7 +4983,7 @@ void bgp_evpn_map_vni_to_its_rts(struct bgp *bgp, struct bgpevpn *vpn)
  */
 void bgp_evpn_unmap_vni_from_its_rts(struct bgp *bgp, struct bgpevpn *vpn)
 {
-       int i;
+       uint32_t i;
        struct ecommunity_val *eval;
        struct listnode *node, *nnode;
        struct ecommunity *ecom;
index 3bc4c0323371867a2fa3a8be2e5829db4a0faadf..1d66d75288ef36e4cb5389d1a13063e216c2dedb 100644 (file)
@@ -419,8 +419,7 @@ int vpn_leak_label_callback(
 
 static bool ecom_intersect(struct ecommunity *e1, struct ecommunity *e2)
 {
-       int i;
-       int j;
+       uint32_t i, j;
 
        if (!e1 || !e2)
                return false;
index a3f1eb8401ff2ec1cac69083042ce5e123626417..4f22f5bcfeb9a93b526453bf44d7e164cf9a946a 100644 (file)
@@ -754,7 +754,7 @@ int bgp_pbr_build_and_validate_entry(const struct prefix *p,
                                     struct bgp_pbr_entry_main *api)
 {
        int ret;
-       int i, action_count = 0;
+       uint32_t i, action_count = 0;
        struct ecommunity *ecom;
        struct ecommunity_val *ecom_eval;
        struct bgp_pbr_entry_action *api_action;
index 3d87b6354238aee121cb18a00eef15f80ca3ee14..b2732a40b4857cc1fd698a4d6bddacfc622d1c05 100644 (file)
@@ -984,7 +984,7 @@ static int rfapiEcommunitiesMatchBeec(struct ecommunity *ecom,
 
 int rfapiEcommunitiesIntersect(struct ecommunity *e1, struct ecommunity *e2)
 {
-       int i, j;
+       uint32_t i, j;
 
        if (!e1 || !e2)
                return 0;
@@ -1014,7 +1014,8 @@ int rfapiEcommunitiesIntersect(struct ecommunity *e1, struct ecommunity *e2)
 int rfapiEcommunityGetLNI(struct ecommunity *ecom, uint32_t *lni)
 {
        if (ecom) {
-               int i;
+               uint32_t i;
+
                for (i = 0; i < ecom->size; ++i) {
                        uint8_t *p = ecom->val + (i * ECOMMUNITY_SIZE);
 
@@ -1034,7 +1035,8 @@ int rfapiEcommunityGetEthernetTag(struct ecommunity *ecom, uint16_t *tag_id)
        struct bgp *bgp = bgp_get_default();
        *tag_id = 0; /* default to untagged */
        if (ecom) {
-               int i;
+               uint32_t i;
+
                for (i = 0; i < ecom->size; ++i) {
                        as_t as = 0;
                        int encode = 0;
index 762cd2596f853d74632038b3aacf844d738ed940..bc29f05aebe73ead11cb5af3aecdb6715b1230d4 100644 (file)
@@ -134,7 +134,7 @@ static void encap_attr_export_ce(struct attr *new, struct attr *orig,
 static int getce(struct bgp *bgp, struct attr *attr, struct prefix *pfx_ce)
 {
        uint8_t *ecp;
-       int i;
+       uint32_t i;
        uint16_t localadmin = bgp->rfapi_cfg->resolve_nve_roo_local_admin;
 
        for (ecp = attr->ecommunity->val, i = 0; i < attr->ecommunity->size;