udp session: allow dgram ip fragmentation 96/26396/3
authorFlorin Coras <fcoras@cisco.com>
Tue, 7 Apr 2020 03:46:07 +0000 (03:46 +0000)
committerDave Barach <openvpp@barachs.net>
Tue, 7 Apr 2020 14:46:47 +0000 (14:46 +0000)
Type: improvement

Signed-off-by: Florin Coras <fcoras@cisco.com>
Change-Id: Ida8f9e759b4990ea6e34e71dc45bdb3b5eabc27f

src/vnet/ip/ip4.h
src/vnet/session/session_node.c
src/vnet/udp/udp.c
src/vnet/udp/udp.h

index a7ed5c2..6e13cc8 100644 (file)
@@ -363,23 +363,10 @@ u32 ip4_tcp_udp_validate_checksum (vlib_main_t * vm, vlib_buffer_t * p0);
 
 #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 @@ vlib_buffer_push_ip4 (vlib_main_t * vm, vlib_buffer_t * b,
   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 @@ vlib_buffer_push_ip4 (vlib_main_t * vm, vlib_buffer_t * b,
   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)
 {
index 573fbe9..464e6a1 100644 (file)
@@ -1030,18 +1030,13 @@ session_tx_fifo_read_and_snd_i (session_worker_t * wrk,
   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);
     }
index daab453..8f26b57 100644 (file)
@@ -241,15 +241,12 @@ udp_push_header (transport_connection_t * tc, vlib_buffer_t * b)
 
   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;
index f7985c9..ddc9a0e 100644 (file)
@@ -308,10 +308,9 @@ vlib_buffer_push_udp (vlib_buffer_t * b, u16 sp, u16 dp, u8 offload_csum)
   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;
 }