summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDonatas Abraitis <donatas.abraitis@gmail.com>2020-04-08 17:09:25 +0200
committerDonatas Abraitis <donatas.abraitis@gmail.com>2020-04-08 17:09:25 +0200
commit11400e739e7a8f00522812b9ccc9ff7323080af1 (patch)
tree8e6cc323356da8c8cb96092f8ec4a599cb1ac0d3
parentMerge pull request #5928 from xThaid/rt_link_cleanup (diff)
downloadfrr-11400e739e7a8f00522812b9ccc9ff7323080af1.tar.xz
frr-11400e739e7a8f00522812b9ccc9ff7323080af1.zip
bgpd: Use COMMUNITY_SIZE instead of just 4
Easier to maintain and read. Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
-rw-r--r--bgpd/bgp_community.c23
-rw-r--r--bgpd/bgp_community.h4
2 files changed, 16 insertions, 11 deletions
diff --git a/bgpd/bgp_community.c b/bgpd/bgp_community.c
index 195c0f394..02aeebcb2 100644
--- a/bgpd/bgp_community.c
+++ b/bgpd/bgp_community.c
@@ -146,7 +146,7 @@ uint32_t community_val_get(struct community *com, int i)
uint32_t val;
p = (uint8_t *)com->val;
- p += (i * 4);
+ p += (i * COMMUNITY_SIZE);
memcpy(&val, p, sizeof(uint32_t));
@@ -514,11 +514,11 @@ struct community *community_parse(uint32_t *pnt, unsigned short length)
struct community *new;
/* If length is malformed return NULL. */
- if (length % 4)
+ if (length % COMMUNITY_SIZE)
return NULL;
/* Make temporary community for hash look up. */
- tmp.size = length / 4;
+ tmp.size = length / COMMUNITY_SIZE;
tmp.val = pnt;
new = community_uniq_sort(&tmp);
@@ -533,8 +533,9 @@ struct community *community_dup(struct community *com)
new = XCALLOC(MTYPE_COMMUNITY, sizeof(struct community));
new->size = com->size;
if (new->size) {
- new->val = XMALLOC(MTYPE_COMMUNITY_VAL, com->size * 4);
- memcpy(new->val, com->val, com->size * 4);
+ new->val = XMALLOC(MTYPE_COMMUNITY_VAL,
+ com->size * COMMUNITY_SIZE);
+ memcpy(new->val, com->val, com->size * COMMUNITY_SIZE);
} else
new->val = NULL;
return new;
@@ -600,7 +601,8 @@ bool community_cmp(const struct community *com1, const struct community *com2)
return false;
if (com1->size == com2->size)
- if (memcmp(com1->val, com2->val, com1->size * 4) == 0)
+ if (memcmp(com1->val, com2->val, com1->size * COMMUNITY_SIZE)
+ == 0)
return true;
return false;
}
@@ -610,13 +612,14 @@ struct community *community_merge(struct community *com1,
struct community *com2)
{
if (com1->val)
- com1->val = XREALLOC(MTYPE_COMMUNITY_VAL, com1->val,
- (com1->size + com2->size) * 4);
+ com1->val =
+ XREALLOC(MTYPE_COMMUNITY_VAL, com1->val,
+ (com1->size + com2->size) * COMMUNITY_SIZE);
else
com1->val = XMALLOC(MTYPE_COMMUNITY_VAL,
- (com1->size + com2->size) * 4);
+ (com1->size + com2->size) * COMMUNITY_SIZE);
- memcpy(com1->val + com1->size, com2->val, com2->size * 4);
+ memcpy(com1->val + com1->size, com2->val, com2->size * COMMUNITY_SIZE);
com1->size += com2->size;
return com1;
diff --git a/bgpd/bgp_community.h b/bgpd/bgp_community.h
index 31a061370..b99f38ab6 100644
--- a/bgpd/bgp_community.h
+++ b/bgpd/bgp_community.h
@@ -61,8 +61,10 @@ struct community {
#define COMMUNITY_LOCAL_AS 0xFFFFFF03
#define COMMUNITY_NO_PEER 0xFFFFFF04
+#define COMMUNITY_SIZE 4
+
/* Macros of community attribute. */
-#define com_length(X) ((X)->size * 4)
+#define com_length(X) ((X)->size * COMMUNITY_SIZE)
#define com_lastval(X) ((X)->val + (X)->size - 1)
#define com_nthval(X,n) ((X)->val + (n))