]> git.puffer.fish Git - mirror/frr.git/commitdiff
bgpd: Cleaned up the lcom->size * LCOMMUNITY_SIZE with lcom_length()
authorNigel Kukard <nkukard@lbsd.net>
Wed, 30 Aug 2017 05:53:37 +0000 (05:53 +0000)
committerNigel Kukard <nkukard@lbsd.net>
Thu, 31 Aug 2017 23:39:53 +0000 (23:39 +0000)
Signed-off-by: Nigel Kukard <nkukard@lbsd.net>
bgpd/bgp_attr.c
bgpd/bgp_lcommunity.c

index da5d1e8d9c7da214ce8ed6ec4e7fe7d86d77a8b7..42cf45c88a2129970b05384200fb7e178dff23df 100644 (file)
@@ -3058,20 +3058,20 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer,
        if (CHECK_FLAG(peer->af_flags[afi][safi],
                       PEER_FLAG_SEND_LARGE_COMMUNITY)
            && (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES))) {
-               if (attr->lcommunity->size * LCOMMUNITY_SIZE > 255) {
+               if (lcom_length(attr->lcommunity) > 255) {
                        stream_putc(s, BGP_ATTR_FLAG_OPTIONAL
                                               | BGP_ATTR_FLAG_TRANS
                                               | BGP_ATTR_FLAG_EXTLEN);
                        stream_putc(s, BGP_ATTR_LARGE_COMMUNITIES);
-                       stream_putw(s, attr->lcommunity->size * LCOMMUNITY_SIZE);
+                       stream_putw(s, lcom_length(attr->lcommunity));
                } else {
                        stream_putc(s, BGP_ATTR_FLAG_OPTIONAL
                                               | BGP_ATTR_FLAG_TRANS);
                        stream_putc(s, BGP_ATTR_LARGE_COMMUNITIES);
-                       stream_putc(s, attr->lcommunity->size * LCOMMUNITY_SIZE);
+                       stream_putc(s, lcom_length(attr->lcommunity));
                }
                stream_put(s, attr->lcommunity->val,
-                          attr->lcommunity->size * LCOMMUNITY_SIZE);
+                          lcom_length(attr->lcommunity));
        }
 
        /* Route Reflector. */
@@ -3422,21 +3422,20 @@ void bgp_dump_routes_attr(struct stream *s, struct attr *attr,
 
        /* Large Community attribute. */
        if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)) {
-               if (attr->lcommunity->size * LCOMMUNITY_SIZE > 255) {
+               if (lcom_length(attr->lcommunity) > 255) {
                        stream_putc(s, BGP_ATTR_FLAG_OPTIONAL
                                               | BGP_ATTR_FLAG_TRANS
                                               | BGP_ATTR_FLAG_EXTLEN);
                        stream_putc(s, BGP_ATTR_LARGE_COMMUNITIES);
-                       stream_putw(s, attr->lcommunity->size * LCOMMUNITY_SIZE);
+                       stream_putw(s, lcom_length(attr->lcommunity));
                } else {
                        stream_putc(s, BGP_ATTR_FLAG_OPTIONAL
                                               | BGP_ATTR_FLAG_TRANS);
                        stream_putc(s, BGP_ATTR_LARGE_COMMUNITIES);
-                       stream_putc(s, attr->lcommunity->size * LCOMMUNITY_SIZE);
+                       stream_putc(s, lcom_length(attr->lcommunity));
                }
 
-               stream_put(s, attr->lcommunity->val,
-                          attr->lcommunity->size * LCOMMUNITY_SIZE);
+               stream_put(s, attr->lcommunity->val, lcom_length(attr->lcommunity));
        }
 
        /* Add a MP_NLRI attribute to dump the IPv6 next hop */
index 344a25dfa6320c1a730a5f91e45e96feba440db4..fd734b2c5b639dffda56763fae249db177d44f21 100644 (file)
@@ -151,9 +151,8 @@ struct lcommunity *lcommunity_dup(struct lcommunity *lcom)
        new = XCALLOC(MTYPE_LCOMMUNITY, sizeof(struct lcommunity));
        new->size = lcom->size;
        if (new->size) {
-               new->val = XMALLOC(MTYPE_LCOMMUNITY_VAL,
-                                  lcom->size * LCOMMUNITY_SIZE);
-               memcpy(new->val, lcom->val, lcom->size * LCOMMUNITY_SIZE);
+               new->val = XMALLOC(MTYPE_LCOMMUNITY_VAL, lcom_length(lcom));
+               memcpy(new->val, lcom->val, lcom_length(lcom));
        } else
                new->val = NULL;
        return new;
@@ -175,14 +174,13 @@ struct lcommunity *lcommunity_merge(struct lcommunity *lcom1,
        if (lcom1->val)
                lcom1->val =
                        XREALLOC(MTYPE_LCOMMUNITY_VAL, lcom1->val,
-                                (lcom1->size + lcom2->size) * LCOMMUNITY_SIZE);
+                                lcom_length(lcom1) + lcom_length(lcom2));
        else
                lcom1->val =
                        XMALLOC(MTYPE_LCOMMUNITY_VAL,
-                               (lcom1->size + lcom2->size) * LCOMMUNITY_SIZE);
+                               lcom_length(lcom1) + lcom_length(lcom2));
 
-       memcpy(lcom1->val + (lcom1->size * LCOMMUNITY_SIZE), lcom2->val,
-              lcom2->size * LCOMMUNITY_SIZE);
+       memcpy(lcom1->val + lcom_length(lcom1), lcom2->val, lcom_length(lcom2));
        lcom1->size += lcom2->size;
 
        return lcom1;
@@ -231,7 +229,7 @@ void lcommunity_unintern(struct lcommunity **lcom)
 unsigned int lcommunity_hash_make(void *arg)
 {
        const struct lcommunity *lcom = arg;
-       int size = lcom->size * LCOMMUNITY_SIZE;
+       int size = lcom_length(lcom);
        u_int8_t *pnt = lcom->val;
        unsigned int key = 0;
        int c;
@@ -261,7 +259,7 @@ int lcommunity_cmp(const void *arg1, const void *arg2)
        const struct lcommunity *lcom2 = arg2;
 
        return (lcom1->size == lcom2->size
-               && memcmp(lcom1->val, lcom2->val, lcom1->size * LCOMMUNITY_SIZE)
+               && memcmp(lcom1->val, lcom2->val, lcom_length(lcom1))
                           == 0);
 }