summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsri-mohan1 <sri.mohan@samsung.com>2024-09-06 03:32:51 +0200
committersri-mohan1 <sri.mohan@samsung.com>2024-09-06 03:32:51 +0200
commit53819c298b663af926fdad8d3a816b4bb937417f (patch)
treec1f7acfe08fa3eef96b613917750771fe855318b
parentMerge pull request #16751 from opensourcerouting/fix/solo_peer-group (diff)
downloadfrr-53819c298b663af926fdad8d3a816b4bb937417f.tar.xz
frr-53819c298b663af926fdad8d3a816b4bb937417f.zip
babeld: changes for code maintainability
these changes are for improving the code maintainability and readability Signed-off-by: sri-mohan1 <sri.mohan@samsung.com>
-rw-r--r--babeld/babel_interface.c2
-rw-r--r--babeld/babeld.c6
-rw-r--r--babeld/message.c16
-rw-r--r--babeld/util.c9
-rw-r--r--babeld/util.h8
5 files changed, 21 insertions, 20 deletions
diff --git a/babeld/babel_interface.c b/babeld/babel_interface.c
index 943ae9def..b83c7b190 100644
--- a/babeld/babel_interface.c
+++ b/babeld/babel_interface.c
@@ -1351,7 +1351,7 @@ babel_interface_allocate (void)
/* All flags are unset */
babel_ifp->bucket_time = babel_now.tv_sec;
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_min = BABEL_DEFAULT_RTT_MIN;
babel_ifp->rtt_max = BABEL_DEFAULT_RTT_MAX;
diff --git a/babeld/babeld.c b/babeld/babeld.c
index 73deb1dd9..b562f0b70 100644
--- a/babeld/babeld.c
+++ b/babeld/babeld.c
@@ -204,7 +204,7 @@ static void babel_read_protocol(struct event *thread)
making these inits have sense. */
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_load_state_file();
debugf(BABEL_DEBUG_COMMON, "My ID is : %s.", format_eui64(myid));
@@ -443,8 +443,8 @@ babel_fill_with_next_timeout(struct timeval *tv)
#if (defined NO_DEBUG)
#define printIfMin(a,b,c,d)
#else
-#define printIfMin(a, b, c, d) \
- if (unlikely(debug & BABEL_DEBUG_TIMEOUT)) { \
+#define printIfMin(a, b, c, d) \
+ if (unlikely(CHECK_FLAG(debug, BABEL_DEBUG_TIMEOUT))) { \
printIfMin(a, b, c, d); \
}
diff --git a/babeld/message.c b/babeld/message.c
index 1b83eb9eb..5a33d5c28 100644
--- a/babeld/message.c
+++ b/babeld/message.c
@@ -324,8 +324,8 @@ parse_request_subtlv(int ae, const unsigned char *a, int alen,
have_src_prefix = 1;
} else {
debugf(BABEL_DEBUG_COMMON,"Received unknown%s Route Request sub-TLV %d.",
- ((type & 0x80) != 0) ? " mandatory" : "", type);
- if((type & 0x80) != 0)
+ (CHECK_FLAG(type, 0x80) != 0) ? " mandatory" : "", type);
+ if(CHECK_FLAG(type, 0x80) != 0)
return -1;
}
@@ -588,7 +588,7 @@ parse_packet(const unsigned char *from, struct interface *ifp,
else
rc = -1;
if(rc < 0) {
- if(message[3] & 0x80)
+ if(CHECK_FLAG(message[3], 0x80))
have_v4_prefix = have_v6_prefix = 0;
goto fail;
}
@@ -596,7 +596,7 @@ parse_packet(const unsigned char *from, struct interface *ifp,
plen = message[4] + (message[2] == 1 ? 96 : 0);
- if(message[3] & 0x80) {
+ if(CHECK_FLAG(message[3], 0x80)) {
if(message[2] == 1) {
memcpy(v4_prefix, prefix, 16);
have_v4_prefix = 1;
@@ -605,7 +605,7 @@ parse_packet(const unsigned char *from, struct interface *ifp,
have_v6_prefix = 1;
}
}
- if(message[3] & 0x40) {
+ if(CHECK_FLAG(message[3], 0x40)) {
if(message[2] == 1) {
memset(router_id, 0, 4);
memcpy(router_id + 4, prefix + 12, 4);
@@ -620,8 +620,8 @@ parse_packet(const unsigned char *from, struct interface *ifp,
goto fail;
}
debugf(BABEL_DEBUG_COMMON,"Received update%s%s for %s from %s on %s.",
- (message[3] & 0x80) ? "/prefix" : "",
- (message[3] & 0x40) ? "/id" : "",
+ ((CHECK_FLAG(message[3], 0x80)) ? "/prefix" : ""),
+ ((CHECK_FLAG(message[3], 0x40)) ? "/id" : ""),
format_prefix(prefix, plen),
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);
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;
accumulate_short(ifp, 0);
accumulate_short(ifp, babel_ifp->hello_seqno);
diff --git a/babeld/util.c b/babeld/util.c
index 4facdabbc..f5edb0ed1 100644
--- a/babeld/util.c
+++ b/babeld/util.c
@@ -211,8 +211,8 @@ mask_prefix(unsigned char *restrict ret,
memset(ret, 0, 16);
memcpy(ret, prefix, plen / 8);
if(plen % 8 != 0)
- ret[plen / 8] =
- (prefix[plen / 8] & ((0xFF << (8 - (plen % 8))) & 0xFF));
+ ret[plen / 8] = CHECK_FLAG(prefix[plen / 8],
+ CHECK_FLAG((0xFF << (8 - (plen % 8))), 0xFF));
return ret;
}
@@ -353,12 +353,13 @@ martian_prefix(const unsigned char *prefix, int plen)
{
return
(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 &&
(prefix[15] == 0 || prefix[15] == 1)) ||
(plen >= 96 && v4mapped(prefix) &&
((plen >= 104 && (prefix[12] == 127 || prefix[12] == 0)) ||
- (plen >= 100 && (prefix[12] & 0xE0) == 0xE0)));
+ (plen >= 100 && CHECK_FLAG(prefix[12], 0xE0) == 0xE0)));
}
int
diff --git a/babeld/util.h b/babeld/util.h
index ddc6a70d4..2242032c4 100644
--- a/babeld/util.h
+++ b/babeld/util.h
@@ -47,19 +47,19 @@ seqno_compare(unsigned short s1, unsigned short s2)
if(s1 == s2)
return 0;
else
- return ((s2 - s1) & 0x8000) ? 1 : -1;
+ return (CHECK_FLAG((s2 - s1), 0x8000)) ? 1 : -1;
}
static inline short
seqno_minus(unsigned short s1, unsigned short s2)
{
- return (short)((s1 - s2) & 0xFFFF);
+ return (short)(CHECK_FLAG((s1 - s2), 0xFFFF));
}
static inline unsigned short
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,
@@ -130,7 +130,7 @@ is_default(const unsigned char *prefix, int plen)
#define debugf(level, ...) \
do { \
- if (unlikely(debug & level)) \
+ if (unlikely(CHECK_FLAG(debug, level))) \
zlog_debug(__VA_ARGS__); \
} while (0)