mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-09 03:27:39 +00:00
bgpd: Use COMMUNITY_SIZE instead of just 4
Easier to maintain and read. Signed-off-by: Donatas Abraitis <donatas.abraitis@gmail.com>
This commit is contained in:
parent
c0d4a6d852
commit
11400e739e
@ -146,7 +146,7 @@ uint32_t community_val_get(struct community *com, int i)
|
|||||||
uint32_t val;
|
uint32_t val;
|
||||||
|
|
||||||
p = (uint8_t *)com->val;
|
p = (uint8_t *)com->val;
|
||||||
p += (i * 4);
|
p += (i * COMMUNITY_SIZE);
|
||||||
|
|
||||||
memcpy(&val, p, sizeof(uint32_t));
|
memcpy(&val, p, sizeof(uint32_t));
|
||||||
|
|
||||||
@ -514,11 +514,11 @@ struct community *community_parse(uint32_t *pnt, unsigned short length)
|
|||||||
struct community *new;
|
struct community *new;
|
||||||
|
|
||||||
/* If length is malformed return NULL. */
|
/* If length is malformed return NULL. */
|
||||||
if (length % 4)
|
if (length % COMMUNITY_SIZE)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
/* Make temporary community for hash look up. */
|
/* Make temporary community for hash look up. */
|
||||||
tmp.size = length / 4;
|
tmp.size = length / COMMUNITY_SIZE;
|
||||||
tmp.val = pnt;
|
tmp.val = pnt;
|
||||||
|
|
||||||
new = community_uniq_sort(&tmp);
|
new = community_uniq_sort(&tmp);
|
||||||
@ -533,8 +533,9 @@ struct community *community_dup(struct community *com)
|
|||||||
new = XCALLOC(MTYPE_COMMUNITY, sizeof(struct community));
|
new = XCALLOC(MTYPE_COMMUNITY, sizeof(struct community));
|
||||||
new->size = com->size;
|
new->size = com->size;
|
||||||
if (new->size) {
|
if (new->size) {
|
||||||
new->val = XMALLOC(MTYPE_COMMUNITY_VAL, com->size * 4);
|
new->val = XMALLOC(MTYPE_COMMUNITY_VAL,
|
||||||
memcpy(new->val, com->val, com->size * 4);
|
com->size * COMMUNITY_SIZE);
|
||||||
|
memcpy(new->val, com->val, com->size * COMMUNITY_SIZE);
|
||||||
} else
|
} else
|
||||||
new->val = NULL;
|
new->val = NULL;
|
||||||
return new;
|
return new;
|
||||||
@ -600,7 +601,8 @@ bool community_cmp(const struct community *com1, const struct community *com2)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (com1->size == com2->size)
|
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 true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -610,13 +612,14 @@ struct community *community_merge(struct community *com1,
|
|||||||
struct community *com2)
|
struct community *com2)
|
||||||
{
|
{
|
||||||
if (com1->val)
|
if (com1->val)
|
||||||
com1->val = XREALLOC(MTYPE_COMMUNITY_VAL, com1->val,
|
com1->val =
|
||||||
(com1->size + com2->size) * 4);
|
XREALLOC(MTYPE_COMMUNITY_VAL, com1->val,
|
||||||
|
(com1->size + com2->size) * COMMUNITY_SIZE);
|
||||||
else
|
else
|
||||||
com1->val = XMALLOC(MTYPE_COMMUNITY_VAL,
|
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;
|
com1->size += com2->size;
|
||||||
|
|
||||||
return com1;
|
return com1;
|
||||||
|
@ -61,8 +61,10 @@ struct community {
|
|||||||
#define COMMUNITY_LOCAL_AS 0xFFFFFF03
|
#define COMMUNITY_LOCAL_AS 0xFFFFFF03
|
||||||
#define COMMUNITY_NO_PEER 0xFFFFFF04
|
#define COMMUNITY_NO_PEER 0xFFFFFF04
|
||||||
|
|
||||||
|
#define COMMUNITY_SIZE 4
|
||||||
|
|
||||||
/* Macros of community attribute. */
|
/* 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_lastval(X) ((X)->val + (X)->size - 1)
|
||||||
#define com_nthval(X,n) ((X)->val + (n))
|
#define com_nthval(X,n) ((X)->val + (n))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user