Skip to content

Commit 51a0764

Browse files
sri-mohan1zice312963205
authored andcommitted
bgpd: changes for code maintainability
these changes are for improving the code maintainability and readability Signed-off-by: sri-mohan1 <[email protected]>
1 parent c1808a7 commit 51a0764

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

bgpd/bgp_ecommunity.c

+32-31
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ static int ecommunity_encode_internal(uint8_t type, uint8_t sub_type,
515515
/* Fill in the values. */
516516
eval->val[0] = type;
517517
if (!trans)
518-
eval->val[0] |= ECOMMUNITY_FLAG_NON_TRANSITIVE;
518+
SET_FLAG(eval->val[0], ECOMMUNITY_FLAG_NON_TRANSITIVE);
519519
eval->val[1] = sub_type;
520520
if (type == ECOMMUNITY_ENCODE_AS) {
521521
encode_route_target_as(as, val, eval, trans);
@@ -1293,11 +1293,12 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
12931293
== ECOMMUNITY_EVPN_SUBTYPE_ESI_LABEL) {
12941294
uint8_t flags = *++pnt;
12951295

1296-
snprintf(encbuf,
1297-
sizeof(encbuf), "ESI-label-Rt:%s",
1298-
(flags &
1299-
ECOMMUNITY_EVPN_SUBTYPE_ESI_SA_FLAG) ?
1300-
"SA":"AA");
1296+
snprintf(encbuf, sizeof(encbuf),
1297+
"ESI-label-Rt:%s",
1298+
CHECK_FLAG(flags,
1299+
ECOMMUNITY_EVPN_SUBTYPE_ESI_SA_FLAG)
1300+
? "SA"
1301+
: "AA");
13011302
} else if (*pnt
13021303
== ECOMMUNITY_EVPN_SUBTYPE_DF_ELECTION) {
13031304
uint8_t alg;
@@ -1337,38 +1338,37 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter)
13371338
char buf[ECOMMUNITY_STRLEN];
13381339

13391340
memset(buf, 0, sizeof(buf));
1340-
ecommunity_rt_soo_str_internal(buf, sizeof(buf),
1341-
(const uint8_t *)pnt,
1342-
type &
1343-
~ECOMMUNITY_ENCODE_TRANS_EXP,
1344-
ECOMMUNITY_ROUTE_TARGET,
1345-
format,
1346-
ecom->unit_size);
1341+
ecommunity_rt_soo_str_internal(
1342+
buf, sizeof(buf), (const uint8_t *)pnt,
1343+
CHECK_FLAG(type,
1344+
~ECOMMUNITY_ENCODE_TRANS_EXP),
1345+
ECOMMUNITY_ROUTE_TARGET, format,
1346+
ecom->unit_size);
13471347
snprintf(encbuf, sizeof(encbuf), "%s", buf);
13481348
} else if (sub_type ==
13491349
ECOMMUNITY_FLOWSPEC_REDIRECT_IPV6) {
13501350
char buf[64];
13511351

13521352
memset(buf, 0, sizeof(buf));
1353-
ecommunity_rt_soo_str_internal(buf, sizeof(buf),
1354-
(const uint8_t *)pnt,
1355-
type &
1356-
~ECOMMUNITY_ENCODE_TRANS_EXP,
1357-
ECOMMUNITY_ROUTE_TARGET,
1358-
ECOMMUNITY_FORMAT_DISPLAY,
1359-
ecom->unit_size);
1353+
ecommunity_rt_soo_str_internal(
1354+
buf, sizeof(buf), (const uint8_t *)pnt,
1355+
CHECK_FLAG(type,
1356+
~ECOMMUNITY_ENCODE_TRANS_EXP),
1357+
ECOMMUNITY_ROUTE_TARGET,
1358+
ECOMMUNITY_FORMAT_DISPLAY,
1359+
ecom->unit_size);
13601360
snprintf(encbuf, sizeof(encbuf),
13611361
"FS:redirect VRF %s", buf);
13621362
} else if (sub_type == ECOMMUNITY_REDIRECT_VRF) {
13631363
char buf[16];
13641364

13651365
memset(buf, 0, sizeof(buf));
1366-
ecommunity_rt_soo_str(buf, sizeof(buf),
1367-
(const uint8_t *)pnt,
1368-
type &
1369-
~ECOMMUNITY_ENCODE_TRANS_EXP,
1370-
ECOMMUNITY_ROUTE_TARGET,
1371-
ECOMMUNITY_FORMAT_DISPLAY);
1366+
ecommunity_rt_soo_str(
1367+
buf, sizeof(buf), (const uint8_t *)pnt,
1368+
CHECK_FLAG(type,
1369+
~ECOMMUNITY_ENCODE_TRANS_EXP),
1370+
ECOMMUNITY_ROUTE_TARGET,
1371+
ECOMMUNITY_FORMAT_DISPLAY);
13721372
snprintf(encbuf, sizeof(encbuf),
13731373
"FS:redirect VRF %s", buf);
13741374
snprintf(encbuf, sizeof(encbuf),
@@ -1640,12 +1640,13 @@ int ecommunity_fill_pbr_action(struct ecommunity_val *ecom_eval,
16401640
} else if (ecom_eval->val[1] == ECOMMUNITY_TRAFFIC_ACTION) {
16411641
api->action = ACTION_TRAFFIC_ACTION;
16421642
/* else distribute code is set by default */
1643-
if (ecom_eval->val[5] & (1 << FLOWSPEC_TRAFFIC_ACTION_TERMINAL))
1644-
api->u.za.filter |= TRAFFIC_ACTION_TERMINATE;
1643+
if (CHECK_FLAG(ecom_eval->val[5],
1644+
(1 << FLOWSPEC_TRAFFIC_ACTION_TERMINAL)))
1645+
SET_FLAG(api->u.za.filter, TRAFFIC_ACTION_TERMINATE);
16451646
else
1646-
api->u.za.filter |= TRAFFIC_ACTION_DISTRIBUTE;
1647+
SET_FLAG(api->u.za.filter, TRAFFIC_ACTION_DISTRIBUTE);
16471648
if (ecom_eval->val[5] == 1 << FLOWSPEC_TRAFFIC_ACTION_SAMPLE)
1648-
api->u.za.filter |= TRAFFIC_ACTION_SAMPLE;
1649+
SET_FLAG(api->u.za.filter, TRAFFIC_ACTION_SAMPLE);
16491650

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

19421943
type = *eval;
1943-
if (type & ECOMMUNITY_FLAG_NON_TRANSITIVE)
1944+
if (CHECK_FLAG(type, ECOMMUNITY_FLAG_NON_TRANSITIVE))
19441945
return new;
19451946

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

0 commit comments

Comments
 (0)