Skip to content

Commit

Permalink
bgpd: Handle non-transitive opaque extended communities also for eBGP…
Browse files Browse the repository at this point in the history
… peers

Fixes: 765a085 ("bgpd: Rework extended community transitiviness")

Signed-off-by: Donatas Abraitis <[email protected]>
  • Loading branch information
ton31337 committed Oct 17, 2024
1 parent ee3e803 commit aefea72
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
30 changes: 15 additions & 15 deletions bgpd/bgp_ecommunity.c
Original file line number Diff line number Diff line change
Expand Up @@ -1408,10 +1408,12 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
"FS:marking %u", *(pnt + 5));
} else
unk_ecom = true;
} else if (CHECK_FLAG(type, ECOMMUNITY_ENCODE_AS_NON_TRANS) ||
CHECK_FLAG(type, ECOMMUNITY_FLAG_NON_TRANSITIVE)) {
} else if (CHECK_FLAG(type, ECOMMUNITY_FLAG_NON_TRANSITIVE) ||
type == ECOMMUNITY_ENCODE_OPAQUE_NON_TRANS) {
sub_type = *pnt++;
if (sub_type == ECOMMUNITY_LINK_BANDWIDTH)
if (sub_type == ECOMMUNITY_ORIGIN_VALIDATION_STATE)
ecommunity_origin_validation_state_str(encbuf, sizeof(encbuf), pnt);
else if (sub_type == ECOMMUNITY_LINK_BANDWIDTH)
ecommunity_lb_str(encbuf, sizeof(encbuf), pnt,
ecom->disable_ieee_floating);
else if (sub_type == ECOMMUNITY_EXTENDED_LINK_BANDWIDTH)
Expand All @@ -1426,13 +1428,6 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
encbuf, sizeof(encbuf), pnt, format);
else
unk_ecom = true;
} else if (type == ECOMMUNITY_ENCODE_OPAQUE_NON_TRANS) {
sub_type = *pnt++;
if (sub_type == ECOMMUNITY_ORIGIN_VALIDATION_STATE)
ecommunity_origin_validation_state_str(
encbuf, sizeof(encbuf), pnt);
else
unk_ecom = true;
} else {
sub_type = *pnt++;
unk_ecom = true;
Expand Down Expand Up @@ -1588,6 +1583,13 @@ bool ecommunity_strip(struct ecommunity *ecom, uint8_t type,
return true;
}

static bool ecommunity_non_transitive(uint8_t type)
{
return (CHECK_FLAG(type, ECOMMUNITY_FLAG_NON_TRANSITIVE) ||
CHECK_FLAG(type, ECOMMUNITY_ENCODE_IP_NON_TRANS) ||
type == ECOMMUNITY_ENCODE_OPAQUE_NON_TRANS);
}

/* Delete all non-transitive extended communities */
bool ecommunity_strip_non_transitive(struct ecommunity *ecom)
{
Expand All @@ -1602,7 +1604,7 @@ bool ecommunity_strip_non_transitive(struct ecommunity *ecom)
*/
c = 0;
for (p = ecom->val; c < ecom->size; p += ecom->unit_size, c++)
if (CHECK_FLAG(*p, ECOMMUNITY_FLAG_NON_TRANSITIVE))
if (ecommunity_non_transitive(*p))
found++;

if (!found)
Expand All @@ -1619,7 +1621,7 @@ bool ecommunity_strip_non_transitive(struct ecommunity *ecom)
new = XMALLOC(MTYPE_ECOMMUNITY_VAL, (ecom->size - found) * ecom->unit_size);
q = new;
for (c = 0, p = ecom->val; c < ecom->size; c++, p += ecom->unit_size) {
if (!CHECK_FLAG(*p, ECOMMUNITY_FLAG_NON_TRANSITIVE)) {
if (!ecommunity_non_transitive(*p)) {
memcpy(q, p, ecom->unit_size);
q += ecom->unit_size;
}
Expand Down Expand Up @@ -1928,9 +1930,7 @@ const uint8_t *ecommunity_linkbw_present(struct ecommunity *ecom, uint64_t *bw)
if (len < ecom->unit_size)
return NULL;

if ((type == ECOMMUNITY_ENCODE_AS ||
type == ECOMMUNITY_ENCODE_AS_NON_TRANS) &&
sub_type == ECOMMUNITY_LINK_BANDWIDTH) {
if ((type == ECOMMUNITY_ENCODE_AS) && sub_type == ECOMMUNITY_LINK_BANDWIDTH) {
uint32_t bwval;

pnt += 2; /* bandwidth is encoded as AS:val */
Expand Down
2 changes: 0 additions & 2 deletions bgpd/bgp_ecommunity.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@
#define ECOMMUNITY_EXTENDED_COMMUNITY_PART_3 0x82

/* Non-transitive extended community types. */
#define ECOMMUNITY_ENCODE_AS_NON_TRANS 0x40
#define ECOMMUNITY_ENCODE_IP_NON_TRANS 0x41
#define ECOMMUNITY_ENCODE_AS4_NON_TRANS 0x42
#define ECOMMUNITY_ENCODE_OPAQUE_NON_TRANS 0x43

/* Low-order octet of the Extended Communities type field. */
Expand Down

0 comments on commit aefea72

Please sign in to comment.