acl-plugin: introduce a format function for l4 session key 16/15516/1
authorAndrew Yourtchenko <ayourtch@gmail.com>
Wed, 24 Oct 2018 18:51:30 +0000 (20:51 +0200)
committerAndrew Yourtchenko <ayourtch@gmail.com>
Wed, 24 Oct 2018 19:21:19 +0000 (21:21 +0200)
Abstracting out the internal format function
for L4 session key type makes the other
acl plugin format/print functions more maintainable.

Change-Id: Ica1302263a42981555462b5338d18d9a9f9c8342
Signed-off-by: Andrew Yourtchenko <ayourtch@gmail.com>
src/plugins/acl/dataplane_node.c
src/plugins/acl/fa_node.h
src/plugins/acl/sess_mgmt_node.c

index fef3551..53176fd 100644 (file)
@@ -630,31 +630,38 @@ static u8 *
 format_fa_5tuple (u8 * s, va_list * args)
 {
   fa_5tuple_t *p5t = va_arg (*args, fa_5tuple_t *);
+  void *paddr0;
+  void *paddr1;
+  void *format_address_func;
+  void *ip_af;
+  void *ip_frag_txt =
+    p5t->pkt.is_nonfirst_fragment ? " non-initial fragment" : "";
 
   if (p5t->pkt.is_ip6)
-    return format (s, "lc_index %d (lsb16 of sw_if_index %d) l3 %s%s %U -> %U"
-                  " l4 proto %d l4_valid %d port %d -> %d tcp flags (%s) %02x rsvd %x",
-                  p5t->pkt.lc_index, p5t->l4.lsb_of_sw_if_index,
-                  "ip6",
-                  p5t->
-                  pkt.is_nonfirst_fragment ? " non-initial fragment" : "",
-                  format_ip6_address, &p5t->ip6_addr[0], format_ip6_address,
-                  &p5t->ip6_addr[1], p5t->l4.proto, p5t->pkt.l4_valid,
-                  p5t->l4.port[0], p5t->l4.port[1],
-                  p5t->pkt.tcp_flags_valid ? "valid" : "invalid",
-                  p5t->pkt.tcp_flags, p5t->pkt.flags_reserved);
+    {
+      ip_af = "ip6";
+      format_address_func = format_ip6_address;
+      paddr0 = &p5t->ip6_addr[0];
+      paddr1 = &p5t->ip6_addr[1];
+    }
   else
-    return format (s, "lc_index %d (lsb16 of sw_if_index %d) l3 %s%s %U -> %U"
-                  " l4 proto %d l4_valid %d port %d -> %d tcp flags (%s) %02x rsvd %x",
-                  p5t->pkt.lc_index, p5t->l4.lsb_of_sw_if_index,
-                  "ip4",
-                  p5t->
-                  pkt.is_nonfirst_fragment ? " non-initial fragment" : "",
-                  format_ip4_address, &p5t->ip4_addr[0], format_ip4_address,
-                  &p5t->ip4_addr[1], p5t->l4.proto, p5t->pkt.l4_valid,
-                  p5t->l4.port[0], p5t->l4.port[1],
-                  p5t->pkt.tcp_flags_valid ? "valid" : "invalid",
-                  p5t->pkt.tcp_flags, p5t->pkt.flags_reserved);
+    {
+      ip_af = "ip4";
+      format_address_func = format_ip4_address;
+      paddr0 = &p5t->ip4_addr[0];
+      paddr1 = &p5t->ip4_addr[1];
+    }
+
+  s =
+    format (s, "lc_index %d l3 %s%s ", p5t->pkt.lc_index, ip_af, ip_frag_txt);
+  s =
+    format (s, "%U -> %U ", format_address_func, paddr0, format_address_func,
+           paddr1);
+  s = format (s, "%U ", format_fa_session_l4_key, &p5t->l4);
+  s = format (s, "tcp flags (%s) %02x rsvd %x",
+             p5t->pkt.tcp_flags_valid ? "valid" : "invalid",
+             p5t->pkt.tcp_flags, p5t->pkt.flags_reserved);
+  return s;
 }
 
 #ifndef CLIB_MARCH_VARIANT
index 74b71b9..57e1027 100644 (file)
@@ -79,6 +79,17 @@ typedef union {
   };
 } fa_5tuple_t;
 
+static_always_inline u8 *
+format_fa_session_l4_key(u8 * s, va_list * args)
+{
+  fa_session_l4_key_t *l4 = va_arg (*args, fa_session_l4_key_t *);
+
+  return (format (s, "l4 lsb_of_sw_if_index %d proto %d l4_is_input %d l4_slow_path %d reserved0 0x%02x port %d -> %d",
+                  l4->lsb_of_sw_if_index,
+                  l4->proto, l4->is_input, l4->is_slowpath,
+                  l4->reserved0, l4->port[0], l4->port[1]));
+}
+
 typedef struct {
   fa_5tuple_t info; /* (5+1)*8 = 48 bytes */
   u64 last_active_time;   /* +8 bytes = 56 */
index a6c5e80..7da6da4 100644 (file)
 #include <plugins/acl/public_inlines.h>
 #include <plugins/acl/session_inlines.h>
 
-static u8 *
-format_ip6_session_bihash_kv (u8 * s, va_list * args)
+
+
+static_always_inline u8 *
+format_ip46_session_bihash_kv (u8 * s, va_list * args, int is_ip6)
 {
-  clib_bihash_kv_40_8_t *kv_40_8 = va_arg (*args, clib_bihash_kv_40_8_t *);
   fa_5tuple_t a5t;
+  void *paddr0;
+  void *paddr1;
+  void *format_addr_func;
+
+  if (is_ip6)
+    {
+      clib_bihash_kv_40_8_t *kv_40_8 =
+       va_arg (*args, clib_bihash_kv_40_8_t *);
+      a5t.kv_40_8 = *kv_40_8;
+      paddr0 = &a5t.ip6_addr[0];
+      paddr1 = &a5t.ip6_addr[1];
+      format_addr_func = format_ip6_address;
+    }
+  else
+    {
+      clib_bihash_kv_16_8_t *kv_16_8 =
+       va_arg (*args, clib_bihash_kv_16_8_t *);
+      a5t.kv_16_8 = *kv_16_8;
+      paddr0 = &a5t.ip4_addr[0];
+      paddr1 = &a5t.ip4_addr[1];
+      format_addr_func = format_ip4_address;
+    }
 
-  a5t.kv_40_8 = *kv_40_8;
   fa_full_session_id_t *sess = (fa_full_session_id_t *) & a5t.pkt;
 
-  return (format (s, "l3 %U -> %U"
-                 " l4 lsb_of_sw_if_index %d proto %d l4_is_input %d l4_slow_path %d l4_reserved0 %d port %d -> %d | sess id %d thread id %d epoch %04x",
-                 format_ip6_address, &a5t.ip6_addr[0],
-                 format_ip6_address, &a5t.ip6_addr[1],
-                 a5t.l4.lsb_of_sw_if_index,
-                 a5t.l4.proto, a5t.l4.is_input, a5t.l4.is_slowpath,
-                 a5t.l4.reserved0, a5t.l4.port[0], a5t.l4.port[1],
+  return (format (s, "l3 %U -> %U %U | sess id %d thread id %d epoch %04x",
+                 format_addr_func, paddr0,
+                 format_addr_func, paddr1,
+                 format_fa_session_l4_key, &a5t.l4,
                  sess->session_index, sess->thread_index,
                  sess->intf_policy_epoch));
 }
 
 static u8 *
-format_ip4_session_bihash_kv (u8 * s, va_list * args)
+format_ip6_session_bihash_kv (u8 * s, va_list * args)
 {
-  clib_bihash_kv_16_8_t *kv_16_8 = va_arg (*args, clib_bihash_kv_16_8_t *);
-  fa_5tuple_t a5t;
-
-  a5t.kv_16_8 = *kv_16_8;
-  fa_full_session_id_t *sess = (fa_full_session_id_t *) & a5t.pkt;
+  return format_ip46_session_bihash_kv (s, args, 1);
+}
 
-  return (format (s, "l3 %U -> %U"
-                 " l4 lsb_of_sw_if_index %d proto %d l4_is_input %d l4_slow_path %d l4_reserved0 %d port %d -> %d | sess id %d thread id %d epoch %04x",
-                 format_ip4_address, &a5t.ip4_addr[0],
-                 format_ip4_address, &a5t.ip4_addr[1],
-                 a5t.l4.lsb_of_sw_if_index,
-                 a5t.l4.proto, a5t.l4.is_input, a5t.l4.is_slowpath,
-                 a5t.l4.reserved0, a5t.l4.port[0], a5t.l4.port[1],
-                 sess->session_index, sess->thread_index,
-                 sess->intf_policy_epoch));
+static u8 *
+format_ip4_session_bihash_kv (u8 * s, va_list * args)
+{
+  return format_ip46_session_bihash_kv (s, args, 0);
 }