fib: reduce save_rewrite_length to u8

This is a preparation step for migrating NAT to use SVR (shallow virtual
reassembly) to conserve space in vnet_buffer. Since max rewrite length
is currently pre-data size (128), u8 is sufficient to hold that value.

Type: refactor

Change-Id: I5374bb396e178245b870cb0bbf1370d2a54230bc
Signed-off-by: Klement Sekera <ksekera@cisco.com>
diff --git a/src/vnet/adj/adj.h b/src/vnet/adj/adj.h
index 37389c3..9d1577f 100644
--- a/src/vnet/adj/adj.h
+++ b/src/vnet/adj/adj.h
@@ -316,7 +316,7 @@
   CLIB_CACHE_LINE_ALIGN_MARK (cacheline1);
 
   /* Rewrite in second/third cache lines */
-  vnet_declare_rewrite (VLIB_BUFFER_PRE_DATA_SIZE);
+  VNET_DECLARE_REWRITE;
 
   /**
    * more control plane members that do not fit on the first cacheline
diff --git a/src/vnet/adj/rewrite.h b/src/vnet/adj/rewrite.h
index 9b83b5a..c2084ea 100644
--- a/src/vnet/adj/rewrite.h
+++ b/src/vnet/adj/rewrite.h
@@ -105,12 +105,14 @@
       vnet_rewrite_declare(64 - 2*sizeof(int)) rw;
     } my_adjacency_t;
 */
-#define vnet_declare_rewrite(total_bytes)				\
-struct {								\
-  vnet_rewrite_header_t rewrite_header;  			        \
-									\
-  u8 rewrite_data[(total_bytes) - sizeof (vnet_rewrite_header_t)];	\
-}
+#define VNET_DECLARE_REWRITE                         \
+  struct                                             \
+  {                                                  \
+    vnet_rewrite_header_t rewrite_header;            \
+                                                     \
+    u8 rewrite_data[(VNET_REWRITE_TOTAL_BYTES) -     \
+                    sizeof (vnet_rewrite_header_t)]; \
+  }
 
 always_inline void
 vnet_rewrite_clear_data_internal (vnet_rewrite_header_t * rw, int max_size)
diff --git a/src/vnet/buffer.h b/src/vnet/buffer.h
index aed72c5..59a8256 100644
--- a/src/vnet/buffer.h
+++ b/src/vnet/buffer.h
@@ -168,7 +168,7 @@
 	  };
 
 	  /* Rewrite length */
-	  u32 save_rewrite_length;
+	  u8 save_rewrite_length;
 
 	  /* MFIB RPF ID */
 	  u32 rpf_id;
@@ -250,7 +250,7 @@
       u8 pyld_proto:3;		/* dpo_proto_t */
       u8 rsvd:5;
       /* Rewrite length */
-      u32 save_rewrite_length;
+      u8 save_rewrite_length;
       /* Save the mpls header length including all label stack */
       u8 mpls_hdr_length;
       /*
@@ -380,6 +380,16 @@
   };
 } vnet_buffer_opaque_t;
 
+#define VNET_REWRITE_TOTAL_BYTES (VLIB_BUFFER_PRE_DATA_SIZE)
+
+STATIC_ASSERT (STRUCT_SIZE_OF (vnet_buffer_opaque_t, ip.save_rewrite_length)
+	       == STRUCT_SIZE_OF (vnet_buffer_opaque_t,
+				  mpls.save_rewrite_length)
+	       && STRUCT_SIZE_OF (vnet_buffer_opaque_t,
+				  mpls.save_rewrite_length) == 1
+	       && VNET_REWRITE_TOTAL_BYTES < UINT8_MAX,
+	       "save_rewrite_length member must be able to hold the max value of rewrite length");
+
 /*
  * The opaque field of the vlib_buffer_t is interpreted as a
  * vnet_buffer_opaque_t. Hence it should be big enough to accommodate one.
diff --git a/src/vnet/l2/l2_xcrw.h b/src/vnet/l2/l2_xcrw.h
index e21c884..fbb2c80 100644
--- a/src/vnet/l2/l2_xcrw.h
+++ b/src/vnet/l2/l2_xcrw.h
@@ -31,7 +31,7 @@
    * Let: rewrite_header.sw_if_index = tx_fib_index or ~0.
    *      rewrite_header.next_index = L2_XCRW_NEXT_XXX
    */
-  vnet_declare_rewrite (VLIB_BUFFER_PRE_DATA_SIZE);
+  VNET_DECLARE_REWRITE;
 } l2_xcrw_adjacency_t;
 
 typedef struct
diff --git a/src/vnet/vxlan-gbp/vxlan_gbp.h b/src/vnet/vxlan-gbp/vxlan_gbp.h
index af2e180..d17f757 100644
--- a/src/vnet/vxlan-gbp/vxlan_gbp.h
+++ b/src/vnet/vxlan-gbp/vxlan_gbp.h
@@ -127,7 +127,7 @@
   u32 dev_instance;		/* Real device instance in tunnel vector */
   u32 user_instance;		/* Instance name being shown to user */
 
-    vnet_declare_rewrite (VLIB_BUFFER_PRE_DATA_SIZE);
+    VNET_DECLARE_REWRITE;
 } vxlan_gbp_tunnel_t;
 
 #define foreach_vxlan_gbp_input_next         \
diff --git a/src/vnet/vxlan/vxlan.h b/src/vnet/vxlan/vxlan.h
index 7ade7c0..e8fc15b 100644
--- a/src/vnet/vxlan/vxlan.h
+++ b/src/vnet/vxlan/vxlan.h
@@ -129,7 +129,7 @@
   u32 dev_instance;		/* Real device instance in tunnel vector */
   u32 user_instance;		/* Instance name being shown to user */
 
-    vnet_declare_rewrite (VLIB_BUFFER_PRE_DATA_SIZE);
+    VNET_DECLARE_REWRITE;
 } vxlan_tunnel_t;
 
 #define foreach_vxlan_input_next        \