babeld: changes for code maintainability

these changes are for improving the code maintainability and readability

Signed-off-by: sri-mohan1 <sri.mohan@samsung.com>
This commit is contained in:
sri-mohan1 2024-09-06 07:02:51 +05:30
parent 340d51fc3a
commit 53819c298b
5 changed files with 21 additions and 20 deletions

View file

@ -1351,7 +1351,7 @@ babel_interface_allocate (void)
/* All flags are unset */ /* All flags are unset */
babel_ifp->bucket_time = babel_now.tv_sec; babel_ifp->bucket_time = babel_now.tv_sec;
babel_ifp->bucket = BUCKET_TOKENS_MAX; babel_ifp->bucket = BUCKET_TOKENS_MAX;
babel_ifp->hello_seqno = (frr_weak_random() & 0xFFFF); babel_ifp->hello_seqno = CHECK_FLAG(frr_weak_random(), 0xFFFF);
babel_ifp->rtt_decay = BABEL_DEFAULT_RTT_DECAY; babel_ifp->rtt_decay = BABEL_DEFAULT_RTT_DECAY;
babel_ifp->rtt_min = BABEL_DEFAULT_RTT_MIN; babel_ifp->rtt_min = BABEL_DEFAULT_RTT_MIN;
babel_ifp->rtt_max = BABEL_DEFAULT_RTT_MAX; babel_ifp->rtt_max = BABEL_DEFAULT_RTT_MAX;

View file

@ -204,7 +204,7 @@ static void babel_read_protocol(struct event *thread)
making these inits have sense. */ making these inits have sense. */
static void babel_init_routing_process(struct event *thread) static void babel_init_routing_process(struct event *thread)
{ {
myseqno = (frr_weak_random() & 0xFFFF); myseqno = CHECK_FLAG(frr_weak_random(), 0xFFFF);
babel_get_myid(); babel_get_myid();
babel_load_state_file(); babel_load_state_file();
debugf(BABEL_DEBUG_COMMON, "My ID is : %s.", format_eui64(myid)); debugf(BABEL_DEBUG_COMMON, "My ID is : %s.", format_eui64(myid));
@ -444,7 +444,7 @@ babel_fill_with_next_timeout(struct timeval *tv)
#define printIfMin(a,b,c,d) #define printIfMin(a,b,c,d)
#else #else
#define printIfMin(a, b, c, d) \ #define printIfMin(a, b, c, d) \
if (unlikely(debug & BABEL_DEBUG_TIMEOUT)) { \ if (unlikely(CHECK_FLAG(debug, BABEL_DEBUG_TIMEOUT))) { \
printIfMin(a, b, c, d); \ printIfMin(a, b, c, d); \
} }

View file

@ -324,8 +324,8 @@ parse_request_subtlv(int ae, const unsigned char *a, int alen,
have_src_prefix = 1; have_src_prefix = 1;
} else { } else {
debugf(BABEL_DEBUG_COMMON,"Received unknown%s Route Request sub-TLV %d.", debugf(BABEL_DEBUG_COMMON,"Received unknown%s Route Request sub-TLV %d.",
((type & 0x80) != 0) ? " mandatory" : "", type); (CHECK_FLAG(type, 0x80) != 0) ? " mandatory" : "", type);
if((type & 0x80) != 0) if(CHECK_FLAG(type, 0x80) != 0)
return -1; return -1;
} }
@ -588,7 +588,7 @@ parse_packet(const unsigned char *from, struct interface *ifp,
else else
rc = -1; rc = -1;
if(rc < 0) { if(rc < 0) {
if(message[3] & 0x80) if(CHECK_FLAG(message[3], 0x80))
have_v4_prefix = have_v6_prefix = 0; have_v4_prefix = have_v6_prefix = 0;
goto fail; goto fail;
} }
@ -596,7 +596,7 @@ parse_packet(const unsigned char *from, struct interface *ifp,
plen = message[4] + (message[2] == 1 ? 96 : 0); plen = message[4] + (message[2] == 1 ? 96 : 0);
if(message[3] & 0x80) { if(CHECK_FLAG(message[3], 0x80)) {
if(message[2] == 1) { if(message[2] == 1) {
memcpy(v4_prefix, prefix, 16); memcpy(v4_prefix, prefix, 16);
have_v4_prefix = 1; have_v4_prefix = 1;
@ -605,7 +605,7 @@ parse_packet(const unsigned char *from, struct interface *ifp,
have_v6_prefix = 1; have_v6_prefix = 1;
} }
} }
if(message[3] & 0x40) { if(CHECK_FLAG(message[3], 0x40)) {
if(message[2] == 1) { if(message[2] == 1) {
memset(router_id, 0, 4); memset(router_id, 0, 4);
memcpy(router_id + 4, prefix + 12, 4); memcpy(router_id + 4, prefix + 12, 4);
@ -620,8 +620,8 @@ parse_packet(const unsigned char *from, struct interface *ifp,
goto fail; goto fail;
} }
debugf(BABEL_DEBUG_COMMON,"Received update%s%s for %s from %s on %s.", debugf(BABEL_DEBUG_COMMON,"Received update%s%s for %s from %s on %s.",
(message[3] & 0x80) ? "/prefix" : "", ((CHECK_FLAG(message[3], 0x80)) ? "/prefix" : ""),
(message[3] & 0x40) ? "/id" : "", ((CHECK_FLAG(message[3], 0x40)) ? "/id" : ""),
format_prefix(prefix, plen), format_prefix(prefix, plen),
format_address(from), ifp->name); format_address(from), ifp->name);
@ -1059,7 +1059,7 @@ void send_hello_noupdate(struct interface *ifp, unsigned interval)
babel_ifp->hello_seqno, interval, ifp->name); babel_ifp->hello_seqno, interval, ifp->name);
start_message(ifp, MESSAGE_HELLO, start_message(ifp, MESSAGE_HELLO,
(babel_ifp->flags & BABEL_IF_TIMESTAMPS) ? 12 : 6); (CHECK_FLAG(babel_ifp->flags, BABEL_IF_TIMESTAMPS) ? 12 : 6));
babel_ifp->buffered_hello = babel_ifp->buffered - 2; babel_ifp->buffered_hello = babel_ifp->buffered - 2;
accumulate_short(ifp, 0); accumulate_short(ifp, 0);
accumulate_short(ifp, babel_ifp->hello_seqno); accumulate_short(ifp, babel_ifp->hello_seqno);

View file

@ -211,8 +211,8 @@ mask_prefix(unsigned char *restrict ret,
memset(ret, 0, 16); memset(ret, 0, 16);
memcpy(ret, prefix, plen / 8); memcpy(ret, prefix, plen / 8);
if(plen % 8 != 0) if(plen % 8 != 0)
ret[plen / 8] = ret[plen / 8] = CHECK_FLAG(prefix[plen / 8],
(prefix[plen / 8] & ((0xFF << (8 - (plen % 8))) & 0xFF)); CHECK_FLAG((0xFF << (8 - (plen % 8))), 0xFF));
return ret; return ret;
} }
@ -353,12 +353,13 @@ martian_prefix(const unsigned char *prefix, int plen)
{ {
return return
(plen >= 8 && prefix[0] == 0xFF) || (plen >= 8 && prefix[0] == 0xFF) ||
(plen >= 10 && prefix[0] == 0xFE && (prefix[1] & 0xC0) == 0x80) || (plen >= 10 && prefix[0] == 0xFE &&
(CHECK_FLAG(prefix[1], 0xC0) == 0x80)) ||
(plen >= 128 && memcmp(prefix, zeroes, 15) == 0 && (plen >= 128 && memcmp(prefix, zeroes, 15) == 0 &&
(prefix[15] == 0 || prefix[15] == 1)) || (prefix[15] == 0 || prefix[15] == 1)) ||
(plen >= 96 && v4mapped(prefix) && (plen >= 96 && v4mapped(prefix) &&
((plen >= 104 && (prefix[12] == 127 || prefix[12] == 0)) || ((plen >= 104 && (prefix[12] == 127 || prefix[12] == 0)) ||
(plen >= 100 && (prefix[12] & 0xE0) == 0xE0))); (plen >= 100 && CHECK_FLAG(prefix[12], 0xE0) == 0xE0)));
} }
int int

View file

@ -47,19 +47,19 @@ seqno_compare(unsigned short s1, unsigned short s2)
if(s1 == s2) if(s1 == s2)
return 0; return 0;
else else
return ((s2 - s1) & 0x8000) ? 1 : -1; return (CHECK_FLAG((s2 - s1), 0x8000)) ? 1 : -1;
} }
static inline short static inline short
seqno_minus(unsigned short s1, unsigned short s2) seqno_minus(unsigned short s1, unsigned short s2)
{ {
return (short)((s1 - s2) & 0xFFFF); return (short)(CHECK_FLAG((s1 - s2), 0xFFFF));
} }
static inline unsigned short static inline unsigned short
seqno_plus(unsigned short s, int plus) seqno_plus(unsigned short s, int plus)
{ {
return ((s + plus) & 0xFFFF); return CHECK_FLAG((s + plus), 0xFFFF);
} }
/* Returns a time in microseconds on 32 bits (thus modulo 2^32, /* Returns a time in microseconds on 32 bits (thus modulo 2^32,
@ -130,7 +130,7 @@ is_default(const unsigned char *prefix, int plen)
#define debugf(level, ...) \ #define debugf(level, ...) \
do { \ do { \
if (unlikely(debug & level)) \ if (unlikely(CHECK_FLAG(debug, level))) \
zlog_debug(__VA_ARGS__); \ zlog_debug(__VA_ARGS__); \
} while (0) } while (0)