]> The Tcpdump Group git mirrors - tcpdump/commitdiff
BGP: Use a 'struct tok' for the flags
authorFrancois-Xavier Le Bail <[email protected]>
Fri, 2 Sep 2022 06:52:13 +0000 (08:52 +0200)
committerFrancois-Xavier Le Bail <[email protected]>
Fri, 2 Sep 2022 06:54:35 +0000 (08:54 +0200)
print-bgp.c

index 76126897ac799e5db73c7e0519b9cf6a3ead1743..c52fff830211472951a59c902f2e69ddcbb83b66 100644 (file)
@@ -1889,6 +1889,14 @@ trunc:   /* we rely on the caller to recognize -2 return value */
        return -2;
 }
 
+static const struct tok bgp_flags[] = {
+       { 0x80, "O"},
+       { 0x40, "T"},
+       { 0x20, "P"},
+       { 0x10, "E"},
+       { 0, NULL }
+};
+
 static int
 bgp_attr_print(netdissect_options *ndo,
                uint8_t atype, const u_char *pptr, u_int len,
@@ -2465,11 +2473,8 @@ bgp_attr_print(netdissect_options *ndo,
                       alen);
 
             if (aflags) {
-                ND_PRINT(", Flags [%s%s%s%s",
-                          aflags & 0x80 ? "O" : "",
-                          aflags & 0x40 ? "T" : "",
-                          aflags & 0x20 ? "P" : "",
-                          aflags & 0x10 ? "E" : "");
+                ND_PRINT(", Flags [%s",
+                         bittok2str_nosep(bgp_flags, "", aflags));
                 if (aflags & 0xf)
                     ND_PRINT("+%x", aflags & 0xf);
                 ND_PRINT("]");
@@ -2886,11 +2891,8 @@ bgp_update_print(netdissect_options *ndo,
                       alen);
 
             if (aflags) {
-                ND_PRINT(", Flags [%s%s%s%s",
-                          aflags & 0x80 ? "O" : "",
-                          aflags & 0x40 ? "T" : "",
-                          aflags & 0x20 ? "P" : "",
-                          aflags & 0x10 ? "E" : "");
+                ND_PRINT(", Flags [%s",
+                         bittok2str_nosep(bgp_flags, "", aflags));
                 if (aflags & 0xf)
                     ND_PRINT("+%x", aflags & 0xf);
                 ND_PRINT("]: ");