diff options
author | Florin Coras <fcoras@cisco.com> | 2017-07-27 00:34:12 -0700 |
---|---|---|
committer | Dave Barach <openvpp@barachs.net> | 2017-08-02 00:03:45 +0000 |
commit | fdbc38249a8c672937a74667dcfaafa2cfd292e7 (patch) | |
tree | 266d4b90330e508163c560ba01226c3248d5a39c /src | |
parent | a0a908f1dfb679c384ab34ee3c1a2a63ba2448df (diff) |
Make ip csum configurable in vlib buffer functions
Also fixes csum computation for lisp control plane 4o6 encapsulated control
messages.
Change-Id: I991e0b5c0d16dc51e0b5bdc79e1d752270b34765
Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/vnet/interface_output.c | 1 | ||||
-rw-r--r-- | src/vnet/ip/ip4.h | 5 | ||||
-rw-r--r-- | src/vnet/ip/ip6.h | 1 | ||||
-rw-r--r-- | src/vnet/lisp-cp/control.c | 9 | ||||
-rw-r--r-- | src/vnet/lisp-cp/lisp_msg_serdes.c | 2 | ||||
-rw-r--r-- | src/vnet/lisp-cp/packets.c | 16 | ||||
-rw-r--r-- | src/vnet/lisp-cp/packets.h | 5 | ||||
-rw-r--r-- | src/vnet/tcp/tcp_output.c | 13 |
8 files changed, 28 insertions, 24 deletions
diff --git a/src/vnet/interface_output.c b/src/vnet/interface_output.c index c95f08b1a1e..06f1c7dd08b 100644 --- a/src/vnet/interface_output.c +++ b/src/vnet/interface_output.c @@ -188,7 +188,6 @@ calc_checksums (vlib_main_t * vm, vlib_buffer_t * b) if (is_ip6) { int bogus; - ASSERT (b->flags & VNET_BUFFER_F_OFFLOAD_IP_CKSUM); if (b->flags & VNET_BUFFER_F_OFFLOAD_TCP_CKSUM) th->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b, ip6, &bogus); if (b->flags & VNET_BUFFER_F_OFFLOAD_UDP_CKSUM) diff --git a/src/vnet/ip/ip4.h b/src/vnet/ip/ip4.h index 872b516cfa9..8f9a8e27bf5 100644 --- a/src/vnet/ip/ip4.h +++ b/src/vnet/ip/ip4.h @@ -329,7 +329,8 @@ u32 ip4_tcp_udp_validate_checksum (vlib_main_t * vm, vlib_buffer_t * p0); */ 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) + ip4_address_t * src, ip4_address_t * dst, int proto, + u8 csum_offload) { ip4_header_t *ih; @@ -348,7 +349,7 @@ vlib_buffer_push_ip4 (vlib_main_t * vm, vlib_buffer_t * b, ih->dst_address.as_u32 = dst->as_u32; /* Offload ip4 header checksum generation */ - if (1) + if (csum_offload) { ih->checksum = 0; b->flags |= VNET_BUFFER_F_OFFLOAD_IP_CKSUM | VNET_BUFFER_F_IS_IP4; diff --git a/src/vnet/ip/ip6.h b/src/vnet/ip/ip6.h index cf52994e720..fa922725d4a 100644 --- a/src/vnet/ip/ip6.h +++ b/src/vnet/ip/ip6.h @@ -576,6 +576,7 @@ vlib_buffer_push_ip6 (vlib_main_t * vm, vlib_buffer_t * b, sizeof (ip6h->src_address)); clib_memcpy (ip6h->dst_address.as_u8, dst->as_u8, sizeof (ip6h->src_address)); + b->flags |= VNET_BUFFER_F_IS_IP6; return ip6h; } diff --git a/src/vnet/lisp-cp/control.c b/src/vnet/lisp-cp/control.c index d8a1372d7f0..fc860e14d89 100644 --- a/src/vnet/lisp-cp/control.c +++ b/src/vnet/lisp-cp/control.c @@ -2257,7 +2257,7 @@ build_map_request (lisp_cp_main_t * lcm, gid_address_t * deid, /* push outer ip header */ pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, sloc, - rloc); + rloc, 1); bi_res[0] = bi; @@ -2283,6 +2283,7 @@ build_encapsulated_map_request (lisp_cp_main_t * lcm, } b = vlib_get_buffer (vm, bi); + b->flags = 0; /* leave some space for the encap headers */ vlib_buffer_make_headroom (b, MAX_LISP_MSG_ENCAP_LEN); @@ -2311,7 +2312,7 @@ build_encapsulated_map_request (lisp_cp_main_t * lcm, /* push outer ip header */ pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, sloc, - mr_ip); + mr_ip, 1); bi_res[0] = bi; @@ -2466,7 +2467,7 @@ build_map_register (lisp_cp_main_t * lcm, ip_address_t * sloc, /* push outer ip header */ pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, LISP_CONTROL_PORT, sloc, - ms_ip); + ms_ip, 1); bi_res[0] = bi; return b; @@ -3650,7 +3651,7 @@ build_map_reply (lisp_cp_main_t * lcm, ip_address_t * sloc, lisp_msg_put_map_reply (b, records, nonce, probe_bit); /* push outer ip header */ - pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, dst_port, sloc, dst); + pkt_push_udp_and_ip (vm, b, LISP_CONTROL_PORT, dst_port, sloc, dst, 1); bi_res[0] = bi; return b; diff --git a/src/vnet/lisp-cp/lisp_msg_serdes.c b/src/vnet/lisp-cp/lisp_msg_serdes.c index 6c0a7219f31..aee4f25e6a6 100644 --- a/src/vnet/lisp-cp/lisp_msg_serdes.c +++ b/src/vnet/lisp-cp/lisp_msg_serdes.c @@ -229,7 +229,7 @@ lisp_msg_push_ecm (vlib_main_t * vm, vlib_buffer_t * b, int lp, int rp, } /* Push inner ip and udp */ - pkt_push_udp_and_ip (vm, b, lp, rp, src_ip, dst_ip); + pkt_push_udp_and_ip (vm, b, lp, rp, src_ip, dst_ip, 0); /* Push lisp ecm hdr */ h = pkt_push_ecm_hdr (b); diff --git a/src/vnet/lisp-cp/packets.c b/src/vnet/lisp-cp/packets.c index a3d6f1cdf06..25086b8e7d9 100644 --- a/src/vnet/lisp-cp/packets.c +++ b/src/vnet/lisp-cp/packets.c @@ -143,7 +143,7 @@ pkt_push_udp (vlib_main_t * vm, vlib_buffer_t * b, u16 sp, u16 dp) void * pkt_push_ip (vlib_main_t * vm, vlib_buffer_t * b, ip_address_t * src, - ip_address_t * dst, u32 proto) + ip_address_t * dst, u32 proto, u8 csum_offload) { if (ip_addr_version (src) != ip_addr_version (dst)) { @@ -156,7 +156,7 @@ pkt_push_ip (vlib_main_t * vm, vlib_buffer_t * b, ip_address_t * src, { case IP4: return vlib_buffer_push_ip4 (vm, b, &ip_addr_v4 (src), - &ip_addr_v4 (dst), proto); + &ip_addr_v4 (dst), proto, csum_offload); break; case IP6: return vlib_buffer_push_ip6 (vm, b, &ip_addr_v6 (src), @@ -167,11 +167,9 @@ pkt_push_ip (vlib_main_t * vm, vlib_buffer_t * b, ip_address_t * src, return 0; } -#define UDP_CHECKSUM_OFFLOAD 1 - void * pkt_push_udp_and_ip (vlib_main_t * vm, vlib_buffer_t * b, u16 sp, u16 dp, - ip_address_t * sip, ip_address_t * dip) + ip_address_t * sip, ip_address_t * dip, u8 csum_offload) { u16 udpsum; udp_header_t *uh; @@ -179,10 +177,9 @@ pkt_push_udp_and_ip (vlib_main_t * vm, vlib_buffer_t * b, u16 sp, u16 dp, uh = pkt_push_udp (vm, b, sp, dp); - ih = pkt_push_ip (vm, b, sip, dip, IP_PROTOCOL_UDP); - - if (UDP_CHECKSUM_OFFLOAD) + if (csum_offload) { + ih = pkt_push_ip (vm, b, sip, dip, IP_PROTOCOL_UDP, 1); b->flags |= VNET_BUFFER_F_OFFLOAD_UDP_CKSUM; vnet_buffer (b)->l3_hdr_offset = (u8 *) ih - b->data; vnet_buffer (b)->l4_hdr_offset = (u8 *) uh - b->data; @@ -190,6 +187,7 @@ pkt_push_udp_and_ip (vlib_main_t * vm, vlib_buffer_t * b, u16 sp, u16 dp, } else { + ih = pkt_push_ip (vm, b, sip, dip, IP_PROTOCOL_UDP, 0); udpsum = udp_checksum (uh, clib_net_to_host_u16 (uh->length), ih, ip_addr_version (sip)); if (udpsum == (u16) ~ 0) @@ -197,6 +195,8 @@ pkt_push_udp_and_ip (vlib_main_t * vm, vlib_buffer_t * b, u16 sp, u16 dp, clib_warning ("Failed UDP checksum! Discarding"); return 0; } + /* clear flags used for csum since we're not offloading */ + b->flags &= ~(VNET_BUFFER_F_IS_IP4 | VNET_BUFFER_F_IS_IP6); uh->checksum = udpsum; } return ih; diff --git a/src/vnet/lisp-cp/packets.h b/src/vnet/lisp-cp/packets.h index f6da3bf4b87..eb9871bf9c0 100644 --- a/src/vnet/lisp-cp/packets.h +++ b/src/vnet/lisp-cp/packets.h @@ -19,10 +19,11 @@ #define IP_DF 0x4000 /* don't fragment */ void *pkt_push_ip (vlib_main_t * vm, vlib_buffer_t * b, ip_address_t * src, - ip_address_t * dst, u32 proto); + ip_address_t * dst, u32 proto, u8 csum_offload); void *pkt_push_udp_and_ip (vlib_main_t * vm, vlib_buffer_t * b, u16 sp, - u16 dp, ip_address_t * sip, ip_address_t * dip); + u16 dp, ip_address_t * sip, ip_address_t * dip, + u8 cksum_offload); void *pkt_push_ecm_hdr (vlib_buffer_t * b); diff --git a/src/vnet/tcp/tcp_output.c b/src/vnet/tcp/tcp_output.c index 1ecb6ce6071..ad13493a14c 100644 --- a/src/vnet/tcp/tcp_output.c +++ b/src/vnet/tcp/tcp_output.c @@ -675,7 +675,7 @@ tcp_make_reset_in_place (vlib_main_t * vm, vlib_buffer_t * b0, if (is_ip4) { ih4 = vlib_buffer_push_ip4 (vm, b0, &dst_ip40, &src_ip40, - IP_PROTOCOL_TCP); + IP_PROTOCOL_TCP, 1); th0->checksum = ip4_tcp_udp_compute_checksum (vm, b0, ih4); } else @@ -747,7 +747,7 @@ tcp_send_reset (tcp_connection_t * tc, vlib_buffer_t * pkt, u8 is_ip4) { ASSERT ((pkt_ih4->ip_version_and_header_length & 0xF0) == 0x40); ih4 = vlib_buffer_push_ip4 (vm, b, &pkt_ih4->dst_address, - &pkt_ih4->src_address, IP_PROTOCOL_TCP); + &pkt_ih4->src_address, IP_PROTOCOL_TCP, 1); th->checksum = ip4_tcp_udp_compute_checksum (vm, b, ih4); } else @@ -776,7 +776,7 @@ tcp_push_ip_hdr (tcp_main_t * tm, tcp_connection_t * tc, vlib_buffer_t * b) { ip4_header_t *ih; ih = vlib_buffer_push_ip4 (vm, b, &tc->c_lcl_ip4, - &tc->c_rmt_ip4, IP_PROTOCOL_TCP); + &tc->c_rmt_ip4, IP_PROTOCOL_TCP, 1); th->checksum = ip4_tcp_udp_compute_checksum (vm, b, ih); } else @@ -1508,9 +1508,10 @@ tcp46_output_inline (vlib_main_t * vm, { ip4_header_t *ih0; ih0 = vlib_buffer_push_ip4 (vm, b0, &tc0->c_lcl_ip4, - &tc0->c_rmt_ip4, IP_PROTOCOL_TCP); - b0->flags |= VNET_BUFFER_F_IS_IP4 | - VNET_BUFFER_F_OFFLOAD_IP_CKSUM | + &tc0->c_rmt_ip4, IP_PROTOCOL_TCP, + 1); + b0->flags |= + VNET_BUFFER_F_IS_IP4 | VNET_BUFFER_F_OFFLOAD_IP_CKSUM | VNET_BUFFER_F_OFFLOAD_TCP_CKSUM; vnet_buffer (b0)->l3_hdr_offset = (u8 *) ih0 - b0->data; vnet_buffer (b0)->l4_hdr_offset = (u8 *) th0 - b0->data; |