Skip to content

Commit

Permalink
bgpd: changes for code maintainability
Browse files Browse the repository at this point in the history
these changes are for improving the code maintainability and readability

Signed-off-by: sri-mohan1 <sri.mohan@samsung.com>
  • Loading branch information
sri-mohan1 authored and zice312963205 committed Nov 28, 2024
1 parent c1808a7 commit 51a0764
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions bgpd/bgp_ecommunity.c
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ static int ecommunity_encode_internal(uint8_t type, uint8_t sub_type,
/* Fill in the values. */
eval->val[0] = type;
if (!trans)
eval->val[0] |= ECOMMUNITY_FLAG_NON_TRANSITIVE;
SET_FLAG(eval->val[0], ECOMMUNITY_FLAG_NON_TRANSITIVE);
eval->val[1] = sub_type;
if (type == ECOMMUNITY_ENCODE_AS) {
encode_route_target_as(as, val, eval, trans);
Expand Down Expand Up @@ -1293,11 +1293,12 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
== ECOMMUNITY_EVPN_SUBTYPE_ESI_LABEL) {
uint8_t flags = *++pnt;

snprintf(encbuf,
sizeof(encbuf), "ESI-label-Rt:%s",
(flags &
ECOMMUNITY_EVPN_SUBTYPE_ESI_SA_FLAG) ?
"SA":"AA");
snprintf(encbuf, sizeof(encbuf),
"ESI-label-Rt:%s",
CHECK_FLAG(flags,
ECOMMUNITY_EVPN_SUBTYPE_ESI_SA_FLAG)
? "SA"
: "AA");
} else if (*pnt
== ECOMMUNITY_EVPN_SUBTYPE_DF_ELECTION) {
uint8_t alg;
Expand Down Expand Up @@ -1337,38 +1338,37 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
char buf[ECOMMUNITY_STRLEN];

memset(buf, 0, sizeof(buf));
ecommunity_rt_soo_str_internal(buf, sizeof(buf),
(const uint8_t *)pnt,
type &
~ECOMMUNITY_ENCODE_TRANS_EXP,
ECOMMUNITY_ROUTE_TARGET,
format,
ecom->unit_size);
ecommunity_rt_soo_str_internal(
buf, sizeof(buf), (const uint8_t *)pnt,
CHECK_FLAG(type,
~ECOMMUNITY_ENCODE_TRANS_EXP),
ECOMMUNITY_ROUTE_TARGET, format,
ecom->unit_size);
snprintf(encbuf, sizeof(encbuf), "%s", buf);
} else if (sub_type ==
ECOMMUNITY_FLOWSPEC_REDIRECT_IPV6) {
char buf[64];

memset(buf, 0, sizeof(buf));
ecommunity_rt_soo_str_internal(buf, sizeof(buf),
(const uint8_t *)pnt,
type &
~ECOMMUNITY_ENCODE_TRANS_EXP,
ECOMMUNITY_ROUTE_TARGET,
ECOMMUNITY_FORMAT_DISPLAY,
ecom->unit_size);
ecommunity_rt_soo_str_internal(
buf, sizeof(buf), (const uint8_t *)pnt,
CHECK_FLAG(type,
~ECOMMUNITY_ENCODE_TRANS_EXP),
ECOMMUNITY_ROUTE_TARGET,
ECOMMUNITY_FORMAT_DISPLAY,
ecom->unit_size);
snprintf(encbuf, sizeof(encbuf),
"FS:redirect VRF %s", buf);
} else if (sub_type == ECOMMUNITY_REDIRECT_VRF) {
char buf[16];

memset(buf, 0, sizeof(buf));
ecommunity_rt_soo_str(buf, sizeof(buf),
(const uint8_t *)pnt,
type &
~ECOMMUNITY_ENCODE_TRANS_EXP,
ECOMMUNITY_ROUTE_TARGET,
ECOMMUNITY_FORMAT_DISPLAY);
ecommunity_rt_soo_str(
buf, sizeof(buf), (const uint8_t *)pnt,
CHECK_FLAG(type,
~ECOMMUNITY_ENCODE_TRANS_EXP),
ECOMMUNITY_ROUTE_TARGET,
ECOMMUNITY_FORMAT_DISPLAY);
snprintf(encbuf, sizeof(encbuf),
"FS:redirect VRF %s", buf);
snprintf(encbuf, sizeof(encbuf),
Expand Down Expand Up @@ -1640,12 +1640,13 @@ int ecommunity_fill_pbr_action(struct ecommunity_val *ecom_eval,
} else if (ecom_eval->val[1] == ECOMMUNITY_TRAFFIC_ACTION) {
api->action = ACTION_TRAFFIC_ACTION;
/* else distribute code is set by default */
if (ecom_eval->val[5] & (1 << FLOWSPEC_TRAFFIC_ACTION_TERMINAL))
api->u.za.filter |= TRAFFIC_ACTION_TERMINATE;
if (CHECK_FLAG(ecom_eval->val[5],
(1 << FLOWSPEC_TRAFFIC_ACTION_TERMINAL)))
SET_FLAG(api->u.za.filter, TRAFFIC_ACTION_TERMINATE);
else
api->u.za.filter |= TRAFFIC_ACTION_DISTRIBUTE;
SET_FLAG(api->u.za.filter, TRAFFIC_ACTION_DISTRIBUTE);
if (ecom_eval->val[5] == 1 << FLOWSPEC_TRAFFIC_ACTION_SAMPLE)
api->u.za.filter |= TRAFFIC_ACTION_SAMPLE;
SET_FLAG(api->u.za.filter, TRAFFIC_ACTION_SAMPLE);

} else if (ecom_eval->val[1] == ECOMMUNITY_TRAFFIC_MARKING) {
api->action = ACTION_MARKING;
Expand Down Expand Up @@ -1940,7 +1941,7 @@ struct ecommunity *ecommunity_replace_linkbw(as_t as, struct ecommunity *ecom,
return new;

type = *eval;
if (type & ECOMMUNITY_FLAG_NON_TRANSITIVE)
if (CHECK_FLAG(type, ECOMMUNITY_FLAG_NON_TRANSITIVE))
return new;

/* Transitive link-bandwidth exists, replace with the passed
Expand Down

0 comments on commit 51a0764

Please sign in to comment.