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 <[email protected]>
  • Loading branch information
sri-mohan1 committed Sep 26, 2024
1 parent f610ca5 commit 254ca70
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions bgpd/bgp_flowspec_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -305,14 +305,11 @@ int bgp_flowspec_op_decode(enum bgp_flowspec_util_nlri_t type,
break;
mval->value = value;
if (op[5] == 1)
mval->compare_operator |=
OPERATOR_COMPARE_LESS_THAN;
SET_FLAG(mval->compare_operator, OPERATOR_COMPARE_LESS_THAN);
if (op[6] == 1)
mval->compare_operator |=
OPERATOR_COMPARE_GREATER_THAN;
SET_FLAG(mval->compare_operator, OPERATOR_COMPARE_GREATER_THAN);
if (op[7] == 1)
mval->compare_operator |=
OPERATOR_COMPARE_EQUAL_TO;
SET_FLAG(mval->compare_operator, OPERATOR_COMPARE_EQUAL_TO);
if (op[1] == 1)
mval->unary_operator = OPERATOR_UNARY_AND;
else
Expand Down Expand Up @@ -413,16 +410,12 @@ int bgp_flowspec_bitmask_decode(enum bgp_flowspec_util_nlri_t type,
mval->value = value;
if (op[6] == 1) {
/* different from */
mval->compare_operator |=
OPERATOR_COMPARE_LESS_THAN;
mval->compare_operator |=
OPERATOR_COMPARE_GREATER_THAN;
SET_FLAG(mval->compare_operator, OPERATOR_COMPARE_LESS_THAN);
SET_FLAG(mval->compare_operator, OPERATOR_COMPARE_GREATER_THAN);
} else
mval->compare_operator |=
OPERATOR_COMPARE_EQUAL_TO;
SET_FLAG(mval->compare_operator, OPERATOR_COMPARE_EQUAL_TO);
if (op[7] == 1)
mval->compare_operator |=
OPERATOR_COMPARE_EXACT_MATCH;
SET_FLAG(mval->compare_operator, OPERATOR_COMPARE_EXACT_MATCH);
if (op[1] == 1)
mval->unary_operator =
OPERATOR_UNARY_AND;
Expand Down Expand Up @@ -467,11 +460,11 @@ int bgp_flowspec_match_rules_fill(uint8_t *nlri_content, int len,
case FLOWSPEC_SRC_PREFIX:
bitmask = 0;
if (type == FLOWSPEC_DEST_PREFIX) {
bitmask |= PREFIX_DST_PRESENT;
SET_FLAG(bitmask, PREFIX_DST_PRESENT);
prefix = &bpem->dst_prefix;
prefix_offset = &bpem->dst_prefix_offset;
} else {
bitmask |= PREFIX_SRC_PRESENT;
SET_FLAG(bitmask, PREFIX_SRC_PRESENT);
prefix = &bpem->src_prefix;
prefix_offset = &bpem->src_prefix_offset;
}
Expand All @@ -491,14 +484,14 @@ int bgp_flowspec_match_rules_fill(uint8_t *nlri_content, int len,
*/
if (prefix->family == AF_INET
&& prefix->u.prefix4.s_addr == INADDR_ANY)
bpem->match_bitmask_iprule |= bitmask;
SET_FLAG(bpem->match_bitmask_iprule, bitmask);
else if (prefix->family == AF_INET6
&& !memcmp(&prefix->u.prefix6,
&in6addr_any,
sizeof(struct in6_addr)))
bpem->match_bitmask_iprule |= bitmask;
SET_FLAG(bpem->match_bitmask_iprule, bitmask);
else
bpem->match_bitmask |= bitmask;
SET_FLAG(bpem->match_bitmask, bitmask);
}
offset += ret;
break;
Expand Down Expand Up @@ -640,8 +633,8 @@ int bgp_flowspec_match_rules_fill(uint8_t *nlri_content, int len,
|| bpem->match_dst_port_num || bpem->match_protocol_num
|| bpem->match_bitmask || bpem->match_flowlabel_num)
bpem->type = BGP_PBR_IPSET;
else if ((bpem->match_bitmask_iprule & PREFIX_SRC_PRESENT) ||
(bpem->match_bitmask_iprule & PREFIX_DST_PRESENT))
else if (CHECK_FLAG(bpem->match_bitmask_iprule, PREFIX_SRC_PRESENT) ||
CHECK_FLAG(bpem->match_bitmask_iprule, PREFIX_DST_PRESENT))
/* the extracted policy rule may not need an
* iptables/ipset filtering. check this may not be
* a standard ip rule : permit any to any ( eg)
Expand Down

0 comments on commit 254ca70

Please sign in to comment.