]> git.puffer.fish Git - mirror/frr.git/commitdiff
babeld: changes for code maintainability 16754/head
authorsri-mohan1 <sri.mohan@samsung.com>
Fri, 6 Sep 2024 01:32:51 +0000 (07:02 +0530)
committersri-mohan1 <sri.mohan@samsung.com>
Fri, 6 Sep 2024 01:32:51 +0000 (07:02 +0530)
these changes are for improving the code maintainability and readability

Signed-off-by: sri-mohan1 <sri.mohan@samsung.com>
babeld/babel_interface.c
babeld/babeld.c
babeld/message.c
babeld/util.c
babeld/util.h

index 943ae9def1c239709d52beac5ec2c4dc96c421cb..b83c7b1908ec20455e14dd7c7236249b8fa38439 100644 (file)
@@ -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;
index 73deb1dd92545ac79e3c86045404abd2ed12f482..b562f0b70c39b074bfe63880c69fb29f5ed5538d 100644 (file)
@@ -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);                                        \
        }
 
index 1b83eb9ebb905f96b0f4416dd2bd1ba23a13a6c7..5a33d5c288ac6d6885143720f338ca99ba2f3e71 100644 (file)
@@ -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);
index 4facdabbc6e34deb3fbfc90f2f89d989267ad9ce..f5edb0ed1f5f5953f5c545b4b362b82a455408de 100644 (file)
@@ -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
index ddc6a70d43b5de8bb38bc49c2d1627006c800e41..2242032c4b82197f24f223f95e3da841924c65ef 100644 (file)
@@ -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)