diff options
Diffstat (limited to 'src/vnet/udp')
-rw-r--r-- | src/vnet/udp/udp.c | 50 | ||||
-rw-r--r-- | src/vnet/udp/udp.h | 1 | ||||
-rw-r--r-- | src/vnet/udp/udp_error.def | 1 | ||||
-rw-r--r-- | src/vnet/udp/udp_inlines.h | 4 | ||||
-rw-r--r-- | src/vnet/udp/udp_input.c | 1 | ||||
-rw-r--r-- | src/vnet/udp/udp_local.h | 71 |
6 files changed, 76 insertions, 52 deletions
diff --git a/src/vnet/udp/udp.c b/src/vnet/udp/udp.c index b3c02510232..1fc055f8d50 100644 --- a/src/vnet/udp/udp.c +++ b/src/vnet/udp/udp.c @@ -232,18 +232,43 @@ udp_session_get_listener (u32 listener_index) return &us->connection; } +always_inline u16 +udp_compute_checksum (vlib_main_t *vm, vlib_buffer_t *b, u8 csum_offload, + u8 is_ip4) +{ + u16 csum = 0; + + if (csum_offload) + vnet_buffer_offload_flags_set (b, VNET_BUFFER_OFFLOAD_F_UDP_CKSUM); + else + { + if (is_ip4) + csum = + ip4_tcp_udp_compute_checksum (vm, b, vlib_buffer_get_current (b)); + else + { + int bogus = 0; + csum = ip6_tcp_udp_icmp_compute_checksum ( + vm, b, vlib_buffer_get_current (b), &bogus); + } + } + + return csum; +} + always_inline u32 udp_push_one_header (vlib_main_t *vm, udp_connection_t *uc, vlib_buffer_t *b, u8 is_cless) { + udp_header_t *uh; + b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED; /* reuse tcp medatada for now */ vnet_buffer (b)->tcp.connection_index = uc->c_c_index; if (!is_cless) { - vlib_buffer_push_udp (b, uc->c_lcl_port, uc->c_rmt_port, - udp_csum_offload (uc)); + uh = vlib_buffer_push_udp (b, uc->c_lcl_port, uc->c_rmt_port); if (uc->c_is_ip4) vlib_buffer_push_ip4_custom (vm, b, &uc->c_lcl_ip4, &uc->c_rmt_ip4, @@ -263,8 +288,7 @@ udp_push_one_header (vlib_main_t *vm, udp_connection_t *uc, vlib_buffer_t *b, hdr = *(session_dgram_hdr_t *) (data - sizeof (hdr)); /* Local port assumed to be bound, not overwriting it */ - vlib_buffer_push_udp (b, uc->c_lcl_port, hdr.rmt_port, - udp_csum_offload (uc)); + uh = vlib_buffer_push_udp (b, uc->c_lcl_port, hdr.rmt_port); if (uc->c_is_ip4) vlib_buffer_push_ip4_custom (vm, b, &hdr.lcl_ip.ip4, &hdr.rmt_ip.ip4, @@ -279,6 +303,9 @@ udp_push_one_header (vlib_main_t *vm, udp_connection_t *uc, vlib_buffer_t *b, vnet_buffer (b)->tcp.flags |= UDP_CONN_F_LISTEN; } + uh->checksum = + udp_compute_checksum (vm, b, udp_csum_offload (uc), uc->c_is_ip4); + return 0; } @@ -440,16 +467,7 @@ udp_open_connection (transport_endpoint_cfg_t * rmt) uc->mss = rmt->mss ? rmt->mss : udp_default_mtu (um, uc->c_is_ip4); if (rmt->peer.sw_if_index != ENDPOINT_INVALID_INDEX) uc->sw_if_index = rmt->peer.sw_if_index; - uc->flags |= UDP_CONN_F_OWNS_PORT; - if (rmt->transport_flags & TRANSPORT_CFG_F_CONNECTED) - { - uc->flags |= UDP_CONN_F_CONNECTED; - } - else - { - clib_spinlock_init (&uc->rx_lock); - uc->c_flags |= TRANSPORT_CONNECTION_F_CLESS; - } + uc->flags |= UDP_CONN_F_OWNS_PORT | UDP_CONN_F_CONNECTED; if (!um->csum_offload) uc->cfg_flags |= UDP_CFG_F_NO_CSUM_OFFLOAD; uc->next_node_index = rmt->next_node_index; @@ -563,6 +581,9 @@ udp_enable_disable (vlib_main_t *vm, u8 is_en) { udp_main_t *um = &udp_main; + if (!is_en || um->is_init) + return 0; + /* Not ideal. The sparse vector used to map ports to next nodes assumes * only a few ports are ever used. When udp transport is enabled this does * not hold and, to make matters worse, ports are consumed in a random @@ -583,6 +604,7 @@ udp_enable_disable (vlib_main_t *vm, u8 is_en) vec_validate (um->transport_ports_refcnt[0], 65535); vec_validate (um->transport_ports_refcnt[1], 65535); + um->is_init = 1; return 0; } diff --git a/src/vnet/udp/udp.h b/src/vnet/udp/udp.h index 8e4e87f85a8..c6f867500e0 100644 --- a/src/vnet/udp/udp.h +++ b/src/vnet/udp/udp.h @@ -154,6 +154,7 @@ typedef struct u16 default_mtu; u16 msg_id_base; u8 csum_offload; + u8 is_init; u8 icmp_send_unreachable_disabled; } udp_main_t; diff --git a/src/vnet/udp/udp_error.def b/src/vnet/udp/udp_error.def index ef19970ce72..843aacfc6ef 100644 --- a/src/vnet/udp/udp_error.def +++ b/src/vnet/udp/udp_error.def @@ -28,3 +28,4 @@ udp_error (CREATE_SESSION, create_session, ERROR, "Failed to create session") udp_error (MQ_FULL, mq_full, ERROR, "Application msg queue full") udp_error (INVALID_CONNECTION, invalid_connection, ERROR, "Invalid connection") udp_error (PKTS_SENT, pkts_sent, INFO, "Packets sent") +udp_error (CONNECTED, connected, INFO, "Connected session") diff --git a/src/vnet/udp/udp_inlines.h b/src/vnet/udp/udp_inlines.h index f0dd44f48b5..ceec0b191b1 100644 --- a/src/vnet/udp/udp_inlines.h +++ b/src/vnet/udp/udp_inlines.h @@ -26,7 +26,7 @@ #include <vnet/udp/udp_encap.h> always_inline void * -vlib_buffer_push_udp (vlib_buffer_t * b, u16 sp, u16 dp, u8 offload_csum) +vlib_buffer_push_udp (vlib_buffer_t *b, u16 sp, u16 dp) { udp_header_t *uh; u16 udp_len = sizeof (udp_header_t) + b->current_length; @@ -38,8 +38,6 @@ vlib_buffer_push_udp (vlib_buffer_t * b, u16 sp, u16 dp, u8 offload_csum) uh->dst_port = dp; uh->checksum = 0; uh->length = clib_host_to_net_u16 (udp_len); - if (offload_csum) - vnet_buffer_offload_flags_set (b, VNET_BUFFER_OFFLOAD_F_UDP_CKSUM); vnet_buffer (b)->l4_hdr_offset = (u8 *) uh - b->data; b->flags |= VNET_BUFFER_F_L4_HDR_OFFSET_VALID; return uh; diff --git a/src/vnet/udp/udp_input.c b/src/vnet/udp/udp_input.c index a90461186c1..693824f9628 100644 --- a/src/vnet/udp/udp_input.c +++ b/src/vnet/udp/udp_input.c @@ -272,6 +272,7 @@ udp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node, uc0->sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_RX]; if (uc0->flags & UDP_CONN_F_CONNECTED) { + error0 = UDP_ERROR_CONNECTED; if (s0->thread_index != thread_index) { /* diff --git a/src/vnet/udp/udp_local.h b/src/vnet/udp/udp_local.h index 16286824ef2..06c7b3f1758 100644 --- a/src/vnet/udp/udp_local.h +++ b/src/vnet/udp/udp_local.h @@ -18,42 +18,43 @@ #include <vnet/vnet.h> -#define foreach_udp4_dst_port \ -_ (53, dns) \ -_ (67, dhcp_to_server) \ -_ (68, dhcp_to_client) \ -_ (500, ikev2) \ -_ (2152, GTPU) \ -_ (3784, bfd4) \ -_ (3785, bfd_echo4) \ -_ (4341, lisp_gpe) \ -_ (4342, lisp_cp) \ -_ (4500, ipsec) \ -_ (4739, ipfix) \ -_ (4789, vxlan) \ -_ (4789, vxlan6) \ -_ (48879, vxlan_gbp) \ -_ (4790, VXLAN_GPE) \ -_ (6633, vpath_3) \ -_ (6081, geneve) \ -_ (53053, dns_reply) +#define foreach_udp4_dst_port \ + _ (53, dns) \ + _ (67, dhcp_to_server) \ + _ (68, dhcp_to_client) \ + _ (500, ikev2) \ + _ (2152, GTPU) \ + _ (3784, bfd4) \ + _ (3785, bfd_echo4) \ + _ (4341, lisp_gpe) \ + _ (4342, lisp_cp) \ + _ (4500, ipsec) \ + _ (4739, ipfix) \ + _ (4784, bfd4_mh) \ + _ (4789, vxlan) \ + _ (4789, vxlan6) \ + _ (48879, vxlan_gbp) \ + _ (4790, VXLAN_GPE) \ + _ (6633, vpath_3) \ + _ (6081, geneve) \ + _ (53053, dns_reply) - -#define foreach_udp6_dst_port \ -_ (53, dns6) \ -_ (547, dhcpv6_to_server) \ -_ (546, dhcpv6_to_client) \ -_ (2152, GTPU6) \ -_ (3784, bfd6) \ -_ (3785, bfd_echo6) \ -_ (4341, lisp_gpe6) \ -_ (4342, lisp_cp6) \ -_ (48879, vxlan6_gbp) \ -_ (4790, VXLAN6_GPE) \ -_ (6633, vpath6_3) \ -_ (6081, geneve6) \ -_ (8138, BIER) \ -_ (53053, dns_reply6) +#define foreach_udp6_dst_port \ + _ (53, dns6) \ + _ (547, dhcpv6_to_server) \ + _ (546, dhcpv6_to_client) \ + _ (2152, GTPU6) \ + _ (3784, bfd6) \ + _ (3785, bfd_echo6) \ + _ (4341, lisp_gpe6) \ + _ (4342, lisp_cp6) \ + _ (48879, vxlan6_gbp) \ + _ (4784, bfd6_mh) \ + _ (4790, VXLAN6_GPE) \ + _ (6633, vpath6_3) \ + _ (6081, geneve6) \ + _ (8138, BIER) \ + _ (53053, dns_reply6) typedef enum { |