vlib: fix offload flags value reset

When a buffer is freed and re-allocated for a new packet, opaque2 is
not reset, so the offload flags can be set to a stale value.
Make sure the offload flags are reset to the current value on 1st set.

Type: fix
Fixes: 6809538e646bf86c000dc1faba60b0a4157ad898

Change-Id: I4048febedf25b9995dbd080a11495ee7dbe59153
Signed-off-by: Benoît Ganne <bganne@cisco.com>
diff --git a/src/vnet/buffer.h b/src/vnet/buffer.h
index fb734d5..bd70ea2 100644
--- a/src/vnet/buffer.h
+++ b/src/vnet/buffer.h
@@ -524,8 +524,17 @@
 static_always_inline void
 vnet_buffer_offload_flags_set (vlib_buffer_t *b, u32 oflags)
 {
-  vnet_buffer2 (b)->oflags |= oflags;
-  b->flags |= VNET_BUFFER_F_OFFLOAD;
+  if (b->flags & VNET_BUFFER_F_OFFLOAD)
+    {
+      /* add a flag to existing offload */
+      vnet_buffer2 (b)->oflags |= oflags;
+    }
+  else
+    {
+      /* no offload yet: reset offload flags to new value */
+      vnet_buffer2 (b)->oflags = oflags;
+      b->flags |= VNET_BUFFER_F_OFFLOAD;
+    }
 }
 
 static_always_inline void