udp session: allow dgram ip fragmentation

Type: improvement

Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: Ida8f9e759b4990ea6e34e71dc45bdb3b5eabc27f
diff --git a/src/vnet/ip/ip4.h b/src/vnet/ip/ip4.h
index a7ed5c2..6e13cc8 100644
--- a/src/vnet/ip/ip4.h
+++ b/src/vnet/ip/ip4.h
@@ -363,23 +363,10 @@
 
 #define IP_DF 0x4000		/* don't fragment */
 
-/**
- * Push IPv4 header to buffer
- *
- * This does not support fragmentation.
- *
- * @param vm - vlib_main
- * @param b - buffer to write the header to
- * @param src - source IP
- * @param dst - destination IP
- * @param prot - payload proto
- *
- * @return - pointer to start of IP header
- */
 always_inline void *
-vlib_buffer_push_ip4 (vlib_main_t * vm, vlib_buffer_t * b,
-		      ip4_address_t * src, ip4_address_t * dst, int proto,
-		      u8 csum_offload)
+vlib_buffer_push_ip4_custom (vlib_main_t * vm, vlib_buffer_t * b,
+			     ip4_address_t * src, ip4_address_t * dst,
+			     int proto, u8 csum_offload, u8 is_df)
 {
   ip4_header_t *ih;
 
@@ -391,7 +378,7 @@
   ih->length = clib_host_to_net_u16 (vlib_buffer_length_in_chain (vm, b));
 
   /* No fragments */
-  ih->flags_and_fragment_offset = clib_host_to_net_u16 (IP_DF);
+  ih->flags_and_fragment_offset = is_df ? clib_host_to_net_u16 (IP_DF) : 0;
   ih->ttl = 255;
   ih->protocol = proto;
   ih->src_address.as_u32 = src->as_u32;
@@ -412,6 +399,28 @@
   return ih;
 }
 
+/**
+ * Push IPv4 header to buffer
+ *
+ * This does not support fragmentation.
+ *
+ * @param vm - vlib_main
+ * @param b - buffer to write the header to
+ * @param src - source IP
+ * @param dst - destination IP
+ * @param prot - payload proto
+ *
+ * @return - pointer to start of IP header
+ */
+always_inline void *
+vlib_buffer_push_ip4 (vlib_main_t * vm, vlib_buffer_t * b,
+		      ip4_address_t * src, ip4_address_t * dst, int proto,
+		      u8 csum_offload)
+{
+  return vlib_buffer_push_ip4_custom (vm, b, src, dst, proto, csum_offload,
+				      1 /* is_df */ );
+}
+
 always_inline u32
 vlib_buffer_get_ip4_fib_index (vlib_buffer_t * b)
 {
diff --git a/src/vnet/session/session_node.c b/src/vnet/session/session_node.c
index 573fbe9..464e6a1 100644
--- a/src/vnet/session/session_node.c
+++ b/src/vnet/session/session_node.c
@@ -1030,18 +1030,13 @@
   else
     session_tx_maybe_reschedule (wrk, ctx, elt);
 
-  if (!peek_data
-      && ctx->transport_vft->transport_options.tx_type == TRANSPORT_TX_DGRAM)
+  if (!peek_data)
     {
       /* Fix dgram pre header */
-      if (ctx->max_len_to_snd < ctx->max_dequeue)
+      if (ctx->transport_vft->transport_options.tx_type == TRANSPORT_TX_DGRAM
+	  && ctx->max_len_to_snd < ctx->max_dequeue)
 	svm_fifo_overwrite_head (ctx->s->tx_fifo, (u8 *) & ctx->hdr,
 				 sizeof (session_dgram_pre_hdr_t));
-      /* More data needs to be read */
-      else if (svm_fifo_max_dequeue_cons (ctx->s->tx_fifo) > 0)
-	if (svm_fifo_set_event (ctx->s->tx_fifo))
-	  session_evt_add_old (wrk, elt);
-
       if (svm_fifo_needs_deq_ntf (ctx->s->tx_fifo, ctx->max_len_to_snd))
 	session_dequeue_notify (ctx->s);
     }
diff --git a/src/vnet/udp/udp.c b/src/vnet/udp/udp.c
index daab453..8f26b57 100644
--- a/src/vnet/udp/udp.c
+++ b/src/vnet/udp/udp.c
@@ -241,15 +241,12 @@
 
   vlib_buffer_push_udp (b, uc->c_lcl_port, uc->c_rmt_port, 1);
   if (tc->is_ip4)
-    vlib_buffer_push_ip4 (vm, b, &uc->c_lcl_ip4, &uc->c_rmt_ip4,
-			  IP_PROTOCOL_UDP, 1);
+    vlib_buffer_push_ip4_custom (vm, b, &uc->c_lcl_ip4, &uc->c_rmt_ip4,
+				 IP_PROTOCOL_UDP, 1 /* csum offload */ ,
+				 0 /* is_df */ );
   else
-    {
-      ip6_header_t *ih;
-      ih = vlib_buffer_push_ip6 (vm, b, &uc->c_lcl_ip6, &uc->c_rmt_ip6,
-				 IP_PROTOCOL_UDP);
-      vnet_buffer (b)->l3_hdr_offset = (u8 *) ih - b->data;
-    }
+    vlib_buffer_push_ip6 (vm, b, &uc->c_lcl_ip6, &uc->c_rmt_ip6,
+			  IP_PROTOCOL_UDP);
   vnet_buffer (b)->sw_if_index[VLIB_RX] = 0;
   vnet_buffer (b)->sw_if_index[VLIB_TX] = uc->c_fib_index;
   b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
diff --git a/src/vnet/udp/udp.h b/src/vnet/udp/udp.h
index f7985c9..ddc9a0e 100644
--- a/src/vnet/udp/udp.h
+++ b/src/vnet/udp/udp.h
@@ -308,10 +308,9 @@
   uh->checksum = 0;
   uh->length = clib_host_to_net_u16 (udp_len);
   if (offload_csum)
-    {
-      b->flags |= VNET_BUFFER_F_OFFLOAD_UDP_CKSUM;
-      vnet_buffer (b)->l4_hdr_offset = (u8 *) uh - b->data;
-    }
+    b->flags |= VNET_BUFFER_F_OFFLOAD_UDP_CKSUM;
+  vnet_buffer (b)->l4_hdr_offset = (u8 *) uh - b->data;
+  b->flags |= VNET_BUFFER_F_L4_HDR_OFFSET_VALID;
   return uh;
 }