summaryrefslogtreecommitdiffstats
path: root/src/vnet/udp
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2017-10-02 00:18:51 -0700
committerDave Barach <openvpp@barachs.net>2017-10-16 21:41:11 +0000
commit3cbc04bea02fc60471dfe0c671ede3ca42c118c3 (patch)
tree6128beab7dfb01c6221da2f675078078170e75ac /src/vnet/udp
parent0cb01bde499979066389975ba81670764914cbc2 (diff)
udp: refactor udp code
Change-Id: I44d5c9df7c49b8d4d5677c6d319033b2da3e6b80 Signed-off-by: Florin Coras <fcoras@cisco.com>
Diffstat (limited to 'src/vnet/udp')
-rw-r--r--src/vnet/udp/builtin_server.c1
-rw-r--r--src/vnet/udp/udp.c393
-rw-r--r--src/vnet/udp/udp.h177
-rw-r--r--src/vnet/udp/udp_error.def6
-rw-r--r--src/vnet/udp/udp_input.c348
-rw-r--r--src/vnet/udp/udp_local.c117
6 files changed, 574 insertions, 468 deletions
diff --git a/src/vnet/udp/builtin_server.c b/src/vnet/udp/builtin_server.c
index 23f0854fb53..593642cb09c 100644
--- a/src/vnet/udp/builtin_server.c
+++ b/src/vnet/udp/builtin_server.c
@@ -73,7 +73,6 @@ builtin_server_rx_callback (stream_session_t * s)
/* Fabricate TX event, send to ourselves */
evt.fifo = tx_fifo;
evt.event_type = FIFO_EVENT_APP_TX;
- evt.event_id = 0;
q = session_manager_get_vpp_event_queue (s->thread_index);
unix_shared_memory_queue_add (q, (u8 *) & evt,
0 /* do wait for mutex */ );
diff --git a/src/vnet/udp/udp.c b/src/vnet/udp/udp.c
index 0e0336b5919..c12e837a74a 100644
--- a/src/vnet/udp/udp.c
+++ b/src/vnet/udp/udp.c
@@ -22,61 +22,92 @@
#include <vnet/dpo/load_balance.h>
#include <vnet/fib/ip4_fib.h>
-udp_uri_main_t udp_uri_main;
-
-u32
-udp_session_bind_ip4 (u32 session_index, transport_endpoint_t * lcl)
+udp_connection_t *
+udp_connection_alloc (u32 thread_index)
{
- udp_uri_main_t *um = vnet_get_udp_main ();
- udp_connection_t *listener;
+ udp_main_t *um = &udp_main;
+ udp_connection_t *uc;
+ u32 will_expand = 0;
+ pool_get_aligned_will_expand (um->connections[thread_index], will_expand,
+ CLIB_CACHE_LINE_BYTES);
- pool_get (um->udp_listeners, listener);
- memset (listener, 0, sizeof (udp_connection_t));
- listener->c_lcl_port = lcl->port;
- listener->c_lcl_ip4.as_u32 = lcl->ip.ip4.as_u32;
- listener->c_transport_proto = TRANSPORT_PROTO_UDP;
- udp_register_dst_port (um->vlib_main, clib_net_to_host_u16 (lcl->port),
- udp4_uri_input_node.index, 1 /* is_ipv4 */ );
- return 0;
+ if (PREDICT_FALSE (will_expand))
+ {
+ clib_spinlock_lock_if_init (&udp_main.peekers_write_locks
+ [thread_index]);
+ pool_get_aligned (udp_main.connections[thread_index], uc,
+ CLIB_CACHE_LINE_BYTES);
+ clib_spinlock_unlock_if_init (&udp_main.peekers_write_locks
+ [thread_index]);
+ }
+ else
+ {
+ pool_get_aligned (um->connections[thread_index], uc,
+ CLIB_CACHE_LINE_BYTES);
+ }
+ memset (uc, 0, sizeof (*uc));
+ uc->c_c_index = uc - um->connections[thread_index];
+ uc->c_thread_index = thread_index;
+ uc->c_proto = TRANSPORT_PROTO_UDP;
+ return uc;
}
-u32
-udp_session_bind_ip6 (u32 session_index, transport_endpoint_t * lcl)
+void
+udp_connection_free (udp_connection_t * uc)
{
- udp_uri_main_t *um = vnet_get_udp_main ();
- udp_connection_t *listener;
-
- pool_get (um->udp_listeners, listener);
- listener->c_lcl_port = lcl->port;
- clib_memcpy (&listener->c_lcl_ip6, &lcl->ip.ip6, sizeof (ip6_address_t));
- listener->c_transport_proto = TRANSPORT_PROTO_UDP;
- udp_register_dst_port (um->vlib_main, clib_net_to_host_u16 (lcl->port),
- udp4_uri_input_node.index, 0 /* is_ipv4 */ );
- return 0;
+ pool_put (udp_main.connections[uc->c_thread_index], uc);
+ if (CLIB_DEBUG)
+ memset (uc, 0xFA, sizeof (*uc));
}
u32
-udp_session_unbind_ip4 (u32 listener_index)
+udp_session_bind (u32 session_index, transport_endpoint_t * lcl)
{
+ udp_main_t *um = vnet_get_udp_main ();
vlib_main_t *vm = vlib_get_main ();
udp_connection_t *listener;
- listener = udp_listener_get (listener_index);
+ u32 node_index;
+ void *iface_ip;
+ udp_dst_port_info_t *pi;
- /* deregister the udp_local mapping */
- udp_unregister_dst_port (vm, listener->c_lcl_port, 1 /* is_ipv4 */ );
- return 0;
+ pi = udp_get_dst_port_info (um, lcl->port, lcl->is_ip4);
+ if (pi)
+ return -1;
+
+ pool_get (um->listener_pool, listener);
+ memset (listener, 0, sizeof (udp_connection_t));
+
+ listener->c_lcl_port = lcl->port;
+ listener->c_c_index = listener - um->listener_pool;
+
+ /* If we are provided a sw_if_index, bind using one of its ips */
+ if (ip_is_zero (&lcl->ip, 1) && lcl->sw_if_index != ENDPOINT_INVALID_INDEX)
+ {
+ if ((iface_ip = ip_interface_get_first_ip (lcl->sw_if_index,
+ lcl->is_ip4)))
+ ip_set (&lcl->ip, iface_ip, lcl->is_ip4);
+ }
+ ip_copy (&listener->c_lcl_ip, &lcl->ip, lcl->is_ip4);
+ listener->c_is_ip4 = lcl->is_ip4;
+ listener->c_proto = TRANSPORT_PROTO_UDP;
+ listener->c_s_index = session_index;
+ listener->c_fib_index = lcl->fib_index;
+
+ node_index = lcl->is_ip4 ? udp4_input_node.index : udp6_input_node.index;
+ udp_register_dst_port (vm, clib_net_to_host_u16 (lcl->port), node_index,
+ 1 /* is_ipv4 */ );
+ return listener->c_c_index;
}
u32
-udp_session_unbind_ip6 (u32 listener_index)
+udp_session_unbind (u32 listener_index)
{
vlib_main_t *vm = vlib_get_main ();
- udp_connection_t *listener;
+ udp_connection_t *listener;
listener = udp_listener_get (listener_index);
-
- /* deregister the udp_local mapping */
- udp_unregister_dst_port (vm, listener->c_lcl_port, 0 /* is_ipv4 */ );
+ udp_unregister_dst_port (vm, clib_net_to_host_u16 (listener->c_lcl_port),
+ listener->c_is_ip4);
return 0;
}
@@ -90,214 +121,220 @@ udp_session_get_listener (u32 listener_index)
}
u32
-udp_push_header (transport_connection_t * tconn, vlib_buffer_t * b)
+udp_push_header (transport_connection_t * tc, vlib_buffer_t * b)
{
- udp_connection_t *us;
- u8 *data;
- udp_header_t *udp;
+ udp_connection_t *uc;
+ vlib_main_t *vm = vlib_get_main ();
- us = (udp_connection_t *) tconn;
+ uc = udp_get_connection_from_transport (tc);
- if (tconn->is_ip4)
- {
- ip4_header_t *ip;
-
- data = vlib_buffer_get_current (b);
- udp = (udp_header_t *) (data - sizeof (udp_header_t));
- ip = (ip4_header_t *) ((u8 *) udp - sizeof (ip4_header_t));
-
- /* Build packet header, swap rx key src + dst fields */
- ip->src_address.as_u32 = us->c_lcl_ip4.as_u32;
- ip->dst_address.as_u32 = us->c_rmt_ip4.as_u32;
- ip->ip_version_and_header_length = 0x45;
- ip->ttl = 254;
- ip->protocol = IP_PROTOCOL_UDP;
- ip->length = clib_host_to_net_u16 (b->current_length + sizeof (*udp));
- ip->checksum = ip4_header_checksum (ip);
-
- udp->src_port = us->c_lcl_port;
- udp->dst_port = us->c_rmt_port;
- udp->length = clib_host_to_net_u16 (b->current_length);
- udp->checksum = 0;
-
- b->current_length = sizeof (*ip) + sizeof (*udp);
- return SESSION_QUEUE_NEXT_IP4_LOOKUP;
- }
+ 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);
else
{
- vlib_main_t *vm = vlib_get_main ();
- ip6_header_t *ip;
- u16 payload_length;
- int bogus = ~0;
-
- data = vlib_buffer_get_current (b);
- udp = (udp_header_t *) (data - sizeof (udp_header_t));
- ip = (ip6_header_t *) ((u8 *) udp - sizeof (ip6_header_t));
-
- /* Build packet header, swap rx key src + dst fields */
- clib_memcpy (&ip->src_address, &us->c_lcl_ip6, sizeof (ip6_address_t));
- clib_memcpy (&ip->dst_address, &us->c_rmt_ip6, sizeof (ip6_address_t));
-
- ip->ip_version_traffic_class_and_flow_label =
- clib_host_to_net_u32 (0x6 << 28);
-
- ip->hop_limit = 0xff;
- ip->protocol = IP_PROTOCOL_UDP;
-
- payload_length = vlib_buffer_length_in_chain (vm, b);
- payload_length -= sizeof (*ip);
-
- ip->payload_length = clib_host_to_net_u16 (payload_length);
-
- udp->checksum = ip6_tcp_udp_icmp_compute_checksum (vm, b, ip, &bogus);
- ASSERT (!bogus);
-
- udp->src_port = us->c_lcl_port;
- udp->dst_port = us->c_rmt_port;
- udp->length = clib_host_to_net_u16 (b->current_length);
- udp->checksum = 0;
-
- b->current_length = sizeof (*ip) + sizeof (*udp);
-
- return SESSION_QUEUE_NEXT_IP6_LOOKUP;
+ 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;
}
+ vnet_buffer (b)->sw_if_index[VLIB_RX] = 0;
+ vnet_buffer (b)->sw_if_index[VLIB_TX] = ~0;
+ b->flags |= VNET_BUFFER_F_LOCALLY_ORIGINATED;
+
+ return 0;
}
transport_connection_t *
-udp_session_get (u32 connection_index, u32 my_thread_index)
+udp_session_get (u32 connection_index, u32 thread_index)
{
- udp_uri_main_t *um = vnet_get_udp_main ();
+ udp_connection_t *uc;
+ uc = udp_connection_get (connection_index, thread_index);
+ if (uc)
+ return &uc->connection;
+ return 0;
+}
- udp_connection_t *us;
- us =
- pool_elt_at_index (um->udp_sessions[my_thread_index], connection_index);
- return &us->connection;
+void
+udp_session_close (u32 connection_index, u32 thread_index)
+{
+ vlib_main_t *vm = vlib_get_main ();
+ udp_connection_t *uc;
+ uc = udp_connection_get (connection_index, thread_index);
+ if (uc)
+ {
+ udp_unregister_dst_port (vm, clib_net_to_host_u16 (uc->c_lcl_port),
+ uc->c_is_ip4);
+ stream_session_delete_notify (&uc->connection);
+ udp_connection_free (uc);
+ }
}
void
-udp_session_close (u32 connection_index, u32 my_thread_index)
+udp_session_cleanup (u32 connection_index, u32 thread_index)
{
- udp_uri_main_t *um = vnet_get_udp_main ();
- pool_put_index (um->udp_sessions[my_thread_index], connection_index);
+ udp_connection_t *uc;
+ uc = udp_connection_get (connection_index, thread_index);
+ if (uc)
+ udp_connection_free (uc);
}
u8 *
-format_udp_session_ip4 (u8 * s, va_list * args)
+format_udp_connection_id (u8 * s, va_list * args)
{
- u32 uci = va_arg (*args, u32);
- u32 thread_index = va_arg (*args, u32);
- udp_connection_t *u4;
-
- u4 = udp_connection_get (uci, thread_index);
+ udp_connection_t *uc = va_arg (*args, udp_connection_t *);
+ if (!uc)
+ return s;
+ if (uc->c_is_ip4)
+ s = format (s, "[#%d][%s] %U:%d->%U:%d", uc->c_thread_index, "U",
+ format_ip4_address, &uc->c_lcl_ip4,
+ clib_net_to_host_u16 (uc->c_lcl_port), format_ip4_address,
+ &uc->c_rmt_ip4, clib_net_to_host_u16 (uc->c_rmt_port));
+ else
+ s = format (s, "[#%d][%s] %U:%d->%U:%d", uc->c_thread_index, "U",
+ format_ip6_address, &uc->c_lcl_ip6,
+ clib_net_to_host_u16 (uc->c_lcl_port), format_ip6_address,
+ &uc->c_rmt_ip6, clib_net_to_host_u16 (uc->c_rmt_port));
+ return s;
+}
- s = format (s, "[%s] %U:%d->%U:%d", "udp", format_ip4_address,
- &u4->c_lcl_ip4, clib_net_to_host_u16 (u4->c_lcl_port),
- format_ip4_address, &u4->c_rmt_ip4,
- clib_net_to_host_u16 (u4->c_rmt_port));
+u8 *
+format_udp_connection (u8 * s, va_list * args)
+{
+ udp_connection_t *uc = va_arg (*args, udp_connection_t *);
+ u32 verbose = va_arg (*args, u32);
+ if (!uc)
+ return s;
+ s = format (s, "%-50U", format_udp_connection_id, uc);
+ if (verbose)
+ {
+ if (verbose == 1)
+ s = format (s, "%-15s", "-");
+ else
+ s = format (s, "\n");
+ }
return s;
}
u8 *
-format_udp_session_ip6 (u8 * s, va_list * args)
+format_udp_session (u8 * s, va_list * args)
{
u32 uci = va_arg (*args, u32);
u32 thread_index = va_arg (*args, u32);
- udp_connection_t *tc = udp_connection_get (uci, thread_index);
- s = format (s, "[%s] %U:%d->%U:%d", "udp", format_ip6_address,
- &tc->c_lcl_ip6, clib_net_to_host_u16 (tc->c_lcl_port),
- format_ip6_address, &tc->c_rmt_ip6,
- clib_net_to_host_u16 (tc->c_rmt_port));
- return s;
+ u32 verbose = va_arg (*args, u32);
+ udp_connection_t *uc;
+
+ uc = udp_connection_get (uci, thread_index);
+ return format (s, "%U", format_udp_connection, uc, verbose);
}
u8 *
-format_udp_listener_session_ip4 (u8 * s, va_list * args)
+format_udp_half_open_session (u8 * s, va_list * args)
{
- u32 tci = va_arg (*args, u32);
- udp_connection_t *tc = udp_listener_get (tci);
- s = format (s, "[%s] %U:%d->%U:%d", "udp", format_ip4_address,
- &tc->c_lcl_ip4, clib_net_to_host_u16 (tc->c_lcl_port),
- format_ip4_address, &tc->c_rmt_ip4,
- clib_net_to_host_u16 (tc->c_rmt_port));
- return s;
+ clib_warning ("BUG");
+ return 0;
}
u8 *
-format_udp_listener_session_ip6 (u8 * s, va_list * args)
+format_udp_listener_session (u8 * s, va_list * args)
{
u32 tci = va_arg (*args, u32);
- udp_connection_t *tc = udp_listener_get (tci);
- s = format (s, "[%s] %U:%d->%U:%d", "udp", format_ip6_address,
- &tc->c_lcl_ip6, clib_net_to_host_u16 (tc->c_lcl_port),
- format_ip6_address, &tc->c_rmt_ip6,
- clib_net_to_host_u16 (tc->c_rmt_port));
- return s;
+ udp_connection_t *uc = udp_listener_get (tci);
+ return format (s, "%U", format_udp_connection, uc);
}
u16
-udp_send_mss_uri (transport_connection_t * t)
+udp_send_mss (transport_connection_t * t)
{
/* TODO figure out MTU of output interface */
- return 400;
+ return 1460;
}
u32
-udp_send_space_uri (transport_connection_t * t)
+udp_send_space (transport_connection_t * t)
{
/* No constraint on TX window */
return ~0;
}
int
-udp_open_connection (transport_endpoint_t * tep)
+udp_open_connection (transport_endpoint_t * rmt)
{
- clib_warning ("Not implemented");
- return 0;
+ udp_main_t *um = vnet_get_udp_main ();
+ vlib_main_t *vm = vlib_get_main ();
+ u32 thread_index = vlib_get_thread_index ();
+ udp_connection_t *uc;
+ ip46_address_t lcl_addr;
+ u32 node_index;
+ u16 lcl_port;
+
+ if (transport_alloc_local_endpoint (TRANSPORT_PROTO_UDP, rmt, &lcl_addr,
+ &lcl_port))
+ return -1;
+
+ while (udp_get_dst_port_info (um, lcl_port, rmt->is_ip4))
+ {
+ lcl_port = transport_alloc_local_port (TRANSPORT_PROTO_UDP, &lcl_addr);
+ if (lcl_port < 1)
+ {
+ clib_warning ("Failed to allocate src port");
+ return -1;
+ }
+ }
+
+ node_index = rmt->is_ip4 ? udp4_input_node.index : udp6_input_node.index;
+ udp_register_dst_port (vm, lcl_port, node_index, 1 /* is_ipv4 */ );
+
+ uc = udp_connection_alloc (thread_index);
+ ip_copy (&uc->c_rmt_ip, &rmt->ip, rmt->is_ip4);
+ ip_copy (&uc->c_lcl_ip, &lcl_addr, rmt->is_ip4);
+ uc->c_rmt_port = rmt->port;
+ uc->c_lcl_port = clib_host_to_net_u16 (lcl_port);
+ uc->c_is_ip4 = rmt->is_ip4;
+ uc->c_proto = TRANSPORT_PROTO_UDP;
+ uc->c_fib_index = rmt->fib_index;
+
+ return uc->c_c_index;
}
-/* *INDENT-OFF* */
-const static transport_proto_vft_t udp4_proto = {
- .bind = udp_session_bind_ip4,
- .open = udp_open_connection,
- .unbind = udp_session_unbind_ip4,
- .push_header = udp_push_header,
- .get_connection = udp_session_get,
- .get_listener = udp_session_get_listener,
- .close = udp_session_close,
- .send_mss = udp_send_mss_uri,
- .send_space = udp_send_space_uri,
- .format_connection = format_udp_session_ip4,
- .format_listener = format_udp_listener_session_ip4
-};
+transport_connection_t *
+udp_half_open_session_get_transport (u32 conn_index)
+{
+ udp_connection_t *uc;
+ uc = udp_connection_get (conn_index, vlib_get_thread_index ());
+ return &uc->connection;
+}
-const static transport_proto_vft_t udp6_proto = {
- .bind = udp_session_bind_ip6,
+/* *INDENT-OFF* */
+const static transport_proto_vft_t udp_proto = {
+ .bind = udp_session_bind,
.open = udp_open_connection,
- .unbind = udp_session_unbind_ip6,
+ .unbind = udp_session_unbind,
.push_header = udp_push_header,
.get_connection = udp_session_get,
.get_listener = udp_session_get_listener,
+ .get_half_open = udp_half_open_session_get_transport,
.close = udp_session_close,
- .send_mss = udp_send_mss_uri,
- .send_space = udp_send_space_uri,
- .format_connection = format_udp_session_ip6,
- .format_listener = format_udp_listener_session_ip6
+ .cleanup = udp_session_cleanup,
+ .send_mss = udp_send_mss,
+ .send_space = udp_send_space,
+ .format_connection = format_udp_session,
+ .format_half_open = format_udp_half_open_session,
+ .format_listener = format_udp_listener_session
};
/* *INDENT-ON* */
static clib_error_t *
udp_init (vlib_main_t * vm)
{
- udp_uri_main_t *um = vnet_get_udp_main ();
+ udp_main_t *um = vnet_get_udp_main ();
ip_main_t *im = &ip_main;
vlib_thread_main_t *tm = vlib_get_thread_main ();
u32 num_threads;
clib_error_t *error = 0;
ip_protocol_info_t *pi;
- um->vlib_main = vm;
- um->vnet_main = vnet_get_main ();
-
if ((error = vlib_call_init_function (vm, ip_main_init)))
return error;
if ((error = vlib_call_init_function (vm, ip4_lookup_init)))
@@ -318,16 +355,18 @@ udp_init (vlib_main_t * vm)
/* Register as transport with URI */
- session_register_transport (TRANSPORT_PROTO_UDP, 1, &udp4_proto);
- session_register_transport (TRANSPORT_PROTO_UDP, 0, &udp6_proto);
+ transport_register_protocol (TRANSPORT_PROTO_UDP, 1, &udp_proto);
+ transport_register_protocol (TRANSPORT_PROTO_UDP, 0, &udp_proto);
/*
* Initialize data structures
*/
num_threads = 1 /* main thread */ + tm->n_threads;
- vec_validate (um->udp_sessions, num_threads - 1);
-
+ vec_validate (um->connections, num_threads - 1);
+ vec_validate (um->connection_peekers, num_threads - 1);
+ vec_validate (um->peekers_readers_locks, num_threads - 1);
+ vec_validate (um->peekers_write_locks, num_threads - 1);
return error;
}
diff --git a/src/vnet/udp/udp.h b/src/vnet/udp/udp.h
index aa37701106c..920ef963ace 100644
--- a/src/vnet/udp/udp.h
+++ b/src/vnet/udp/udp.h
@@ -26,49 +26,6 @@
#include <vnet/ip/ip.h>
#include <vnet/session/transport.h>
-typedef struct
-{
- transport_connection_t connection; /** must be first */
-
- /** ersatz MTU to limit fifo pushes to test data size */
- u32 mtu;
-} udp_connection_t;
-
-typedef struct _udp_uri_main
-{
- /* Per-worker thread udp connection pools */
- udp_connection_t **udp_sessions;
- udp_connection_t *udp_listeners;
-
- /* convenience */
- vlib_main_t *vlib_main;
- vnet_main_t *vnet_main;
- ip4_main_t *ip4_main;
- ip6_main_t *ip6_main;
-} udp_uri_main_t;
-
-extern udp_uri_main_t udp_uri_main;
-extern vlib_node_registration_t udp4_uri_input_node;
-
-always_inline udp_uri_main_t *
-vnet_get_udp_main ()
-{
- return &udp_uri_main;
-}
-
-always_inline udp_connection_t *
-udp_connection_get (u32 conn_index, u32 thread_index)
-{
- return pool_elt_at_index (udp_uri_main.udp_sessions[thread_index],
- conn_index);
-}
-
-always_inline udp_connection_t *
-udp_listener_get (u32 conn_index)
-{
- return pool_elt_at_index (udp_uri_main.udp_listeners, conn_index);
-}
-
typedef enum
{
#define udp_error(n,s) UDP_ERROR_##n,
@@ -77,6 +34,13 @@ typedef enum
UDP_N_ERROR,
} udp_error_t;
+typedef struct
+{
+ transport_connection_t connection; /** must be first */
+ /** ersatz MTU to limit fifo pushes to test data size */
+ u32 mtu;
+} udp_connection_t;
+
#define foreach_udp4_dst_port \
_ (53, dns) \
_ (67, dhcp_to_server) \
@@ -161,10 +125,108 @@ typedef struct
u8 punt_unknown4;
u8 punt_unknown6;
- /* convenience */
- vlib_main_t *vlib_main;
+ /*
+ * Per-worker thread udp connection pools used with session layer
+ */
+ udp_connection_t **connections;
+ u32 *connection_peekers;
+ clib_spinlock_t *peekers_readers_locks;
+ clib_spinlock_t *peekers_write_locks;
+ udp_connection_t *listener_pool;
+
} udp_main_t;
+extern udp_main_t udp_main;
+extern vlib_node_registration_t udp4_input_node;
+extern vlib_node_registration_t udp6_input_node;
+
+always_inline udp_connection_t *
+udp_connection_get (u32 conn_index, u32 thread_index)
+{
+ if (pool_is_free_index (udp_main.connections[thread_index], conn_index))
+ return 0;
+ return pool_elt_at_index (udp_main.connections[thread_index], conn_index);
+}
+
+always_inline udp_connection_t *
+udp_listener_get (u32 conn_index)
+{
+ return pool_elt_at_index (udp_main.listener_pool, conn_index);
+}
+
+always_inline udp_main_t *
+vnet_get_udp_main ()
+{
+ return &udp_main;
+}
+
+always_inline udp_connection_t *
+udp_get_connection_from_transport (transport_connection_t * tc)
+{
+ return ((udp_connection_t *) tc);
+}
+
+always_inline u32
+udp_connection_index (udp_connection_t * uc)
+{
+ return (uc - udp_main.connections[uc->c_thread_index]);
+}
+
+udp_connection_t *udp_connection_alloc (u32 thread_index);
+
+/**
+ * Acquires a lock that blocks a connection pool from expanding.
+ */
+always_inline void
+udp_pool_add_peeker (u32 thread_index)
+{
+ if (thread_index != vlib_get_thread_index ())
+ return;
+ clib_spinlock_lock_if_init (&udp_main.peekers_readers_locks[thread_index]);
+ udp_main.connection_peekers[thread_index] += 1;
+ if (udp_main.connection_peekers[thread_index] == 1)
+ clib_spinlock_lock_if_init (&udp_main.peekers_write_locks[thread_index]);
+ clib_spinlock_unlock_if_init (&udp_main.peekers_readers_locks
+ [thread_index]);
+}
+
+always_inline void
+udp_pool_remove_peeker (u32 thread_index)
+{
+ if (thread_index != vlib_get_thread_index ())
+ return;
+ ASSERT (udp_main.connection_peekers[thread_index] > 0);
+ clib_spinlock_lock_if_init (&udp_main.peekers_readers_locks[thread_index]);
+ udp_main.connection_peekers[thread_index] -= 1;
+ if (udp_main.connection_peekers[thread_index] == 0)
+ clib_spinlock_unlock_if_init (&udp_main.peekers_write_locks
+ [thread_index]);
+ clib_spinlock_unlock_if_init (&udp_main.peekers_readers_locks
+ [thread_index]);
+}
+
+always_inline udp_connection_t *
+udp_conenction_clone_safe (u32 connection_index, u32 thread_index)
+{
+ udp_connection_t *old_c, *new_c;
+ u32 current_thread_index = vlib_get_thread_index ();
+ new_c = udp_connection_alloc (current_thread_index);
+
+ /* If during the memcpy pool is reallocated AND the memory allocator
+ * decides to give the old chunk of memory to somebody in a hurry to
+ * scribble something on it, we have a problem. So add this thread as
+ * a session pool peeker.
+ */
+ udp_pool_add_peeker (thread_index);
+ old_c = udp_main.connections[thread_index] + connection_index;
+ clib_memcpy (new_c, old_c, sizeof (*new_c));
+ udp_pool_remove_peeker (thread_index);
+ new_c->c_thread_index = current_thread_index;
+ new_c->c_c_index = udp_connection_index (new_c);
+ return new_c;
+}
+
+
always_inline udp_dst_port_info_t *
udp_get_dst_port_info (udp_main_t * um, udp_dst_port_t dst_port, u8 is_ip4)
{
@@ -174,19 +236,34 @@ udp_get_dst_port_info (udp_main_t * um, udp_dst_port_t dst_port, u8 is_ip4)
format_function_t format_udp_header;
format_function_t format_udp_rx_trace;
-
unformat_function_t unformat_udp_header;
void udp_register_dst_port (vlib_main_t * vm,
udp_dst_port_t dst_port,
u32 node_index, u8 is_ip4);
-
-void
-udp_unregister_dst_port (vlib_main_t * vm,
- udp_dst_port_t dst_port, u8 is_ip4);
+void udp_unregister_dst_port (vlib_main_t * vm,
+ udp_dst_port_t dst_port, u8 is_ip4);
void udp_punt_unknown (vlib_main_t * vm, u8 is_ip4, u8 is_add);
+always_inline void *
+vlib_buffer_push_udp (vlib_buffer_t * b, u16 sp, u16 dp, u8 offload_csum)
+{
+ udp_header_t *uh;
+
+ uh = vlib_buffer_push_uninit (b, sizeof (udp_header_t));
+ uh->src_port = sp;
+ uh->dst_port = dp;
+ uh->checksum = 0;
+ uh->length = clib_host_to_net_u16 (b->current_length);
+ if (offload_csum)
+ {
+ b->flags |= VNET_BUFFER_F_OFFLOAD_UDP_CKSUM;
+ vnet_buffer (b)->l4_hdr_offset = (u8 *) uh - b->data;
+ }
+ return uh;
+}
+
always_inline void
ip_udp_fixup_one (vlib_main_t * vm, vlib_buffer_t * b0, u8 is_ip4)
{
diff --git a/src/vnet/udp/udp_error.def b/src/vnet/udp/udp_error.def
index bfdae0acc77..488e7bee7df 100644
--- a/src/vnet/udp/udp_error.def
+++ b/src/vnet/udp/udp_error.def
@@ -19,3 +19,9 @@ udp_error (NONE, "no error")
udp_error (NO_LISTENER, "no listener for dst port")
udp_error (LENGTH_ERROR, "UDP packets with length errors")
udp_error (PUNT, "no listener punt")
+udp_error (ENQUEUED, "UDP packets enqueued")
+udp_error (FIFO_FULL, "UDP fifo full")
+udp_error (NOT_READY, "UDP connection not ready")
+udp_error (LISTENER, "UDP connected session")
+udp_error (CREATE_SESSION, "Failed to create UDP session")
+udp_error (EVENT_FIFO_FULL, "UDP session event fifo full")
diff --git a/src/vnet/udp/udp_input.c b/src/vnet/udp/udp_input.c
index 5d3a1855269..8170cfbe49a 100644
--- a/src/vnet/udp/udp_input.c
+++ b/src/vnet/udp/udp_input.c
@@ -28,55 +28,62 @@
#include <vlibmemory/api.h>
#include "../session/application_interface.h"
-vlib_node_registration_t udp4_uri_input_node;
+static char *udp_error_strings[] = {
+#define udp_error(n,s) s,
+#include "udp_error.def"
+#undef udp_error
+};
typedef struct
{
- u32 session;
+ u32 connection;
u32 disposition;
u32 thread_index;
-} udp4_uri_input_trace_t;
+} udp_input_trace_t;
/* packet trace format function */
static u8 *
-format_udp4_uri_input_trace (u8 * s, va_list * args)
+format_udp_input_trace (u8 * s, va_list * args)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
- udp4_uri_input_trace_t *t = va_arg (*args, udp4_uri_input_trace_t *);
+ udp_input_trace_t *t = va_arg (*args, udp_input_trace_t *);
- s = format (s, "UDP4_URI_INPUT: session %d, disposition %d, thread %d",
- t->session, t->disposition, t->thread_index);
+ s = format (s, "UDP_INPUT: connection %d, disposition %d, thread %d",
+ t->connection, t->disposition, t->thread_index);
return s;
}
+#define foreach_udp_input_next \
+ _ (DROP, "error-drop")
+
typedef enum
{
- UDP4_URI_INPUT_NEXT_DROP,
- UDP4_URI_INPUT_N_NEXT,
-} udp4_uri_input_next_t;
-
-static char *udp4_uri_input_error_strings[] = {
-#define _(sym,string) string,
- foreach_session_input_error
+#define _(s, n) UDP_INPUT_NEXT_##s,
+ foreach_udp_input_next
#undef _
-};
+ UDP_INPUT_N_NEXT,
+} udp_input_next_t;
-static uword
-udp4_uri_input_node_fn (vlib_main_t * vm,
- vlib_node_runtime_t * node, vlib_frame_t * frame)
+always_inline void
+udp_input_inc_counter (vlib_main_t * vm, u8 is_ip4, u8 evt, u8 val)
+{
+ if (PREDICT_TRUE (!val))
+ return;
+
+ if (is_ip4)
+ vlib_node_increment_counter (vm, udp4_input_node.index, evt, val);
+ else
+ vlib_node_increment_counter (vm, udp6_input_node.index, evt, val);
+}
+
+always_inline uword
+udp46_input_inline (vlib_main_t * vm, vlib_node_runtime_t * node,
+ vlib_frame_t * frame, u8 is_ip4)
{
u32 n_left_from, *from, *to_next;
- udp4_uri_input_next_t next_index;
- udp_uri_main_t *um = vnet_get_udp_main ();
- session_manager_main_t *smm = vnet_get_session_manager_main ();
+ u32 next_index, errors;
u32 my_thread_index = vm->thread_index;
- u8 my_enqueue_epoch;
- u32 *session_indices_to_enqueue;
- static u32 serial_number;
- int i;
-
- my_enqueue_epoch = ++smm->current_enqueue_epoch[my_thread_index];
from = vlib_frame_vector_args (frame);
n_left_from = frame->n_vectors;
@@ -90,16 +97,18 @@ udp4_uri_input_node_fn (vlib_main_t * vm,
while (n_left_from > 0 && n_left_to_next > 0)
{
- u32 bi0;
+ u32 bi0, fib_index0;
vlib_buffer_t *b0;
- u32 next0 = UDP4_URI_INPUT_NEXT_DROP;
- u32 error0 = SESSION_ERROR_ENQUEUED;
+ u32 next0 = UDP_INPUT_NEXT_DROP;
+ u32 error0 = UDP_ERROR_ENQUEUED;
udp_header_t *udp0;
- ip4_header_t *ip0;
- stream_session_t *s0;
- svm_fifo_t *f0;
- u16 udp_len0;
+ ip4_header_t *ip40;
+ ip6_header_t *ip60;
u8 *data0;
+ stream_session_t *s0;
+ transport_connection_t *tc0 = 0;
+ udp_connection_t *child0, *new_uc0;
+ int written0;
/* speculatively enqueue b0 to the current next frame */
bi0 = from[0];
@@ -112,89 +121,97 @@ udp4_uri_input_node_fn (vlib_main_t * vm,
b0 = vlib_get_buffer (vm, bi0);
/* udp_local hands us a pointer to the udp data */
-
data0 = vlib_buffer_get_current (b0);
udp0 = (udp_header_t *) (data0 - sizeof (*udp0));
+ fib_index0 = vnet_buffer (b0)->ip.fib_index;
- /* $$$$ fixme: udp_local doesn't do ip options correctly anyhow */
- ip0 = (ip4_header_t *) (((u8 *) udp0) - sizeof (*ip0));
- s0 = 0;
-
- /* lookup session */
- s0 = session_lookup4 (0, &ip0->dst_address, &ip0->src_address,
- udp0->dst_port, udp0->src_port,
- TRANSPORT_PROTO_UDP);
+ if (is_ip4)
+ {
+ /* $$$$ fixme: udp_local doesn't do ip options correctly anyhow */
+ ip40 = (ip4_header_t *) (((u8 *) udp0) - sizeof (*ip40));
+ s0 = session_lookup_safe4 (fib_index0, &ip40->dst_address,
+ &ip40->src_address, udp0->dst_port,
+ udp0->src_port, TRANSPORT_PROTO_UDP);
+ }
+ else
+ {
+ ip60 = (ip6_header_t *) (((u8 *) udp0) - sizeof (*ip60));
+ s0 = session_lookup_safe6 (fib_index0, &ip60->dst_address,
+ &ip60->src_address, udp0->dst_port,
+ udp0->src_port, TRANSPORT_PROTO_UDP);
+ }
- /* no listener */
if (PREDICT_FALSE (s0 == 0))
{
- error0 = SESSION_ERROR_NO_LISTENER;
+ error0 = UDP_ERROR_NO_LISTENER;
goto trace0;
}
- f0 = s0->server_rx_fifo;
-
- /* established hit */
if (PREDICT_TRUE (s0->session_state == SESSION_STATE_READY))
{
- udp_len0 = clib_net_to_host_u16 (udp0->length);
-
- if (PREDICT_FALSE (udp_len0 > svm_fifo_max_enqueue (f0)))
- {
- error0 = SESSION_ERROR_FIFO_FULL;
- goto trace0;
- }
-
- svm_fifo_enqueue_nowait (f0, udp_len0 - sizeof (*udp0),
- (u8 *) (udp0 + 1));
-
- b0->error = node->errors[SESSION_ERROR_ENQUEUED];
-
- /* We need to send an RX event on this fifo */
- if (s0->enqueue_epoch != my_enqueue_epoch)
- {
- s0->enqueue_epoch = my_enqueue_epoch;
-
- vec_add1 (smm->session_indices_to_enqueue_by_thread
- [my_thread_index],
- s0 - smm->sessions[my_thread_index]);
- }
+ tc0 = session_get_transport (s0);
}
- /* listener hit */
- else if (s0->session_state == SESSION_STATE_LISTENING)
+ else if (s0->session_state == SESSION_STATE_CONNECTING_READY)
{
- udp_connection_t *us;
- int rv;
-
- error0 = SESSION_ERROR_NOT_READY;
-
/*
- * create udp transport session
+ * Clone the transport. It will be cleaned up with the
+ * session once we notify the session layer.
*/
- pool_get (um->udp_sessions[my_thread_index], us);
-
- us->mtu = 1024; /* $$$$ policy */
-
- us->c_lcl_ip4.as_u32 = ip0->dst_address.as_u32;
- us->c_rmt_ip4.as_u32 = ip0->src_address.as_u32;
- us->c_lcl_port = udp0->dst_port;
- us->c_rmt_port = udp0->src_port;
- us->c_transport_proto = TRANSPORT_PROTO_UDP;
- us->c_c_index = us - um->udp_sessions[my_thread_index];
+ new_uc0 = udp_conenction_clone_safe (s0->connection_index,
+ s0->thread_index);
+ ASSERT (s0->session_index == new_uc0->c_s_index);
/*
- * create stream session and attach the udp session to it
+ * Drop the 'lock' on pool resize
*/
- rv = stream_session_accept (&us->connection, s0->session_index,
- 1 /*notify */ );
- if (rv)
- error0 = rv;
+ session_pool_remove_peeker (s0->thread_index);
+ session_dgram_connect_notify (&new_uc0->connection,
+ s0->thread_index, &s0);
+ tc0 = &new_uc0->connection;
+ }
+ else if (s0->session_state == SESSION_STATE_LISTENING)
+ {
+ tc0 = listen_session_get_transport (s0);
+
+ child0 = udp_connection_alloc (my_thread_index);
+ if (is_ip4)
+ {
+ ip_set (&child0->c_lcl_ip, &ip40->dst_address, 1);
+ ip_set (&child0->c_rmt_ip, &ip40->src_address, 1);
+ }
+ else
+ {
+ ip_set (&child0->c_lcl_ip, &ip60->dst_address, 0);
+ ip_set (&child0->c_rmt_ip, &ip60->src_address, 0);
+ }
+ child0->c_lcl_port = udp0->dst_port;
+ child0->c_rmt_port = udp0->src_port;
+ child0->c_is_ip4 = is_ip4;
+ child0->mtu = 1460; /* $$$$ policy */
+
+ if (stream_session_accept
+ (&child0->connection, tc0->s_index, 1))
+ {
+ error0 = UDP_ERROR_CREATE_SESSION;
+ goto trace0;
+ }
+ s0 = session_get (child0->c_s_index, child0->c_thread_index);
+ s0->session_state = SESSION_STATE_READY;
+ tc0 = &child0->connection;
+ error0 = UDP_ERROR_LISTENER;
}
else
{
+ error0 = UDP_ERROR_NOT_READY;
+ goto trace0;
+ }
- error0 = SESSION_ERROR_NOT_READY;
+ written0 = session_enqueue_dgram_connection (s0, b0, tc0->proto,
+ 1 /* queue evt */ );
+ if (PREDICT_FALSE (written0 < 0))
+ {
+ error0 = UDP_ERROR_FIFO_FULL;
goto trace0;
}
@@ -204,17 +221,14 @@ udp4_uri_input_node_fn (vlib_main_t * vm,
if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)
&& (b0->flags & VLIB_BUFFER_IS_TRACED)))
{
- udp4_uri_input_trace_t *t =
- vlib_add_trace (vm, node, b0, sizeof (*t));
+ udp_input_trace_t *t = vlib_add_trace (vm, node, b0,
+ sizeof (*t));
- t->session = ~0;
- if (s0)
- t->session = s0 - smm->sessions[my_thread_index];
+ t->connection = tc0 ? tc0->c_index : ~0;
t->disposition = error0;
t->thread_index = my_thread_index;
}
- /* verify speculative enqueue, maybe switch current next frame */
vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
to_next, n_left_to_next,
bi0, next0);
@@ -223,94 +237,66 @@ udp4_uri_input_node_fn (vlib_main_t * vm,
vlib_put_next_frame (vm, node, next_index, n_left_to_next);
}
- /* Send enqueue events */
-
- session_indices_to_enqueue =
- smm->session_indices_to_enqueue_by_thread[my_thread_index];
-
- for (i = 0; i < vec_len (session_indices_to_enqueue); i++)
- {
- session_fifo_event_t evt;
- unix_shared_memory_queue_t *q;
- stream_session_t *s0;
- application_t *server0;
-
- /* Get session */
- s0 = pool_elt_at_index (smm->sessions[my_thread_index],
- session_indices_to_enqueue[i]);
-
- /* Get session's server */
- server0 = application_get (s0->app_index);
-
- /* Built-in server? Deliver the goods... */
- if (server0->cb_fns.builtin_server_rx_callback)
- {
- server0->cb_fns.builtin_server_rx_callback (s0);
- continue;
- }
-
- if (svm_fifo_set_event (s0->server_rx_fifo))
- {
- /* Fabricate event */
- evt.fifo = s0->server_rx_fifo;
- evt.event_type = FIFO_EVENT_APP_RX;
- evt.event_id = serial_number++;
-
- /* Add event to server's event queue */
- q = server0->event_queue;
-
- /* Don't block for lack of space */
- if (PREDICT_TRUE (q->cursize < q->maxsize))
- {
- unix_shared_memory_queue_add (server0->event_queue,
- (u8 *) & evt,
- 0 /* do wait for mutex */ );
- }
- else
- {
- vlib_node_increment_counter (vm, udp4_uri_input_node.index,
- SESSION_ERROR_FIFO_FULL, 1);
- }
- }
- /* *INDENT-OFF* */
- if (1)
- {
- ELOG_TYPE_DECLARE (e) =
- {
- .format = "evt-enqueue: id %d length %d",
- .format_args = "i4i4",};
- struct
- {
- u32 data[2];
- } *ed;
- ed = ELOG_DATA (&vlib_global_main.elog_main, e);
- ed->data[0] = evt.event_id;
- ed->data[1] = svm_fifo_max_dequeue (s0->server_rx_fifo);
- }
- /* *INDENT-ON* */
+ errors = session_manager_flush_enqueue_events (TRANSPORT_PROTO_UDP,
+ my_thread_index);
+ udp_input_inc_counter (vm, is_ip4, UDP_ERROR_EVENT_FIFO_FULL, errors);
+ return frame->n_vectors;
+}
- }
+vlib_node_registration_t udp4_input_node;
+vlib_node_registration_t udp6_input_node;
- vec_reset_length (session_indices_to_enqueue);
+static uword
+udp4_input (vlib_main_t * vm, vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
+{
+ return udp46_input_inline (vm, node, frame, 1);
+}
- smm->session_indices_to_enqueue_by_thread[my_thread_index] =
- session_indices_to_enqueue;
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (udp4_input_node) =
+{
+ .function = udp4_input,
+ .name = "udp4-input",
+ .vector_size = sizeof (u32),
+ .format_trace = format_udp_input_trace,
+ .type = VLIB_NODE_TYPE_INTERNAL,
+ .n_errors = ARRAY_LEN (udp_error_strings),
+ .error_strings = udp_error_strings,
+ .n_next_nodes = UDP_INPUT_N_NEXT,
+ .next_nodes = {
+#define _(s, n) [UDP_INPUT_NEXT_##s] = n,
+ foreach_udp_input_next
+#undef _
+ },
+};
+/* *INDENT-ON* */
- return frame->n_vectors;
+static uword
+udp6_input (vlib_main_t * vm, vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
+{
+ return udp46_input_inline (vm, node, frame, 0);
}
-VLIB_REGISTER_NODE (udp4_uri_input_node) =
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (udp6_input_node) =
{
- .function = udp4_uri_input_node_fn,.name = "udp4-uri-input",.vector_size =
- sizeof (u32),.format_trace = format_udp4_uri_input_trace,.type =
- VLIB_NODE_TYPE_INTERNAL,.n_errors =
- ARRAY_LEN (udp4_uri_input_error_strings),.error_strings =
- udp4_uri_input_error_strings,.n_next_nodes = UDP4_URI_INPUT_N_NEXT,
- /* edit / add dispositions here */
- .next_nodes =
- {
- [UDP4_URI_INPUT_NEXT_DROP] = "error-drop",}
-,};
+ .function = udp6_input,
+ .name = "udp6-input",
+ .vector_size = sizeof (u32),
+ .format_trace = format_udp_input_trace,
+ .type = VLIB_NODE_TYPE_INTERNAL,
+ .n_errors = ARRAY_LEN (udp_error_strings),
+ .error_strings = udp_error_strings,
+ .n_next_nodes = UDP_INPUT_N_NEXT,
+ .next_nodes = {
+#define _(s, n) [UDP_INPUT_NEXT_##s] = n,
+ foreach_udp_input_next
+#undef _
+ },
+};
+/* *INDENT-ON* */
/*
* fd.io coding-style-patch-verification: ON
diff --git a/src/vnet/udp/udp_local.c b/src/vnet/udp/udp_local.c
index 8c0ac465e04..ce9bb029788 100644
--- a/src/vnet/udp/udp_local.c
+++ b/src/vnet/udp/udp_local.c
@@ -23,7 +23,7 @@
udp_main_t udp_main;
-#define foreach_udp_input_next \
+#define foreach_udp_local_next \
_ (PUNT, "error-punt") \
_ (DROP, "error-drop") \
_ (ICMP4_ERROR, "ip4-icmp-error") \
@@ -31,25 +31,25 @@ udp_main_t udp_main;
typedef enum
{
-#define _(s,n) UDP_INPUT_NEXT_##s,
- foreach_udp_input_next
+#define _(s,n) UDP_LOCAL_NEXT_##s,
+ foreach_udp_local_next
#undef _
- UDP_INPUT_N_NEXT,
-} udp_input_next_t;
+ UDP_LOCAL_N_NEXT,
+} udp_local_next_t;
typedef struct
{
u16 src_port;
u16 dst_port;
u8 bound;
-} udp_rx_trace_t;
+} udp_local_rx_trace_t;
u8 *
format_udp_rx_trace (u8 * s, va_list * args)
{
CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
- udp_rx_trace_t *t = va_arg (*args, udp_rx_trace_t *);
+ udp_local_rx_trace_t *t = va_arg (*args, udp_local_rx_trace_t *);
s = format (s, "UDP: src-port %d dst-port %d%s",
clib_net_to_host_u16 (t->src_port),
@@ -58,11 +58,11 @@ format_udp_rx_trace (u8 * s, va_list * args)
return s;
}
-vlib_node_registration_t udp4_input_node;
-vlib_node_registration_t udp6_input_node;
+vlib_node_registration_t udp4_local_node;
+vlib_node_registration_t udp6_local_node;
always_inline uword
-udp46_input_inline (vlib_main_t * vm,
+udp46_local_inline (vlib_main_t * vm,
vlib_node_runtime_t * node,
vlib_frame_t * from_frame, int is_ip4)
{
@@ -132,7 +132,7 @@ udp46_input_inline (vlib_main_t * vm,
if (PREDICT_FALSE (b0->current_length < advance0 + sizeof (*h0)))
{
error0 = UDP_ERROR_LENGTH_ERROR;
- next0 = UDP_INPUT_NEXT_DROP;
+ next0 = UDP_LOCAL_NEXT_DROP;
}
else
{
@@ -143,14 +143,14 @@ udp46_input_inline (vlib_main_t * vm,
vlib_buffer_length_in_chain (vm, b0)))
{
error0 = UDP_ERROR_LENGTH_ERROR;
- next0 = UDP_INPUT_NEXT_DROP;
+ next0 = UDP_LOCAL_NEXT_DROP;
}
}
if (PREDICT_FALSE (b1->current_length < advance1 + sizeof (*h1)))
{
error1 = UDP_ERROR_LENGTH_ERROR;
- next1 = UDP_INPUT_NEXT_DROP;
+ next1 = UDP_LOCAL_NEXT_DROP;
}
else
{
@@ -161,7 +161,7 @@ udp46_input_inline (vlib_main_t * vm,
vlib_buffer_length_in_chain (vm, b1)))
{
error1 = UDP_ERROR_LENGTH_ERROR;
- next1 = UDP_INPUT_NEXT_DROP;
+ next1 = UDP_LOCAL_NEXT_DROP;
}
}
@@ -187,7 +187,7 @@ udp46_input_inline (vlib_main_t * vm,
if (PREDICT_FALSE (punt_unknown))
{
b0->error = node->errors[UDP_ERROR_PUNT];
- next0 = UDP_INPUT_NEXT_PUNT;
+ next0 = UDP_LOCAL_NEXT_PUNT;
}
else if (is_ip4)
{
@@ -195,7 +195,7 @@ udp46_input_inline (vlib_main_t * vm,
ICMP4_destination_unreachable,
ICMP4_destination_unreachable_port_unreachable,
0);
- next0 = UDP_INPUT_NEXT_ICMP4_ERROR;
+ next0 = UDP_LOCAL_NEXT_ICMP4_ERROR;
n_no_listener++;
}
else
@@ -204,7 +204,7 @@ udp46_input_inline (vlib_main_t * vm,
ICMP6_destination_unreachable,
ICMP6_destination_unreachable_port_unreachable,
0);
- next0 = UDP_INPUT_NEXT_ICMP6_ERROR;
+ next0 = UDP_LOCAL_NEXT_ICMP6_ERROR;
n_no_listener++;
}
}
@@ -224,7 +224,7 @@ udp46_input_inline (vlib_main_t * vm,
if (PREDICT_FALSE (punt_unknown))
{
b1->error = node->errors[UDP_ERROR_PUNT];
- next1 = UDP_INPUT_NEXT_PUNT;
+ next1 = UDP_LOCAL_NEXT_PUNT;
}
else if (is_ip4)
{
@@ -232,7 +232,7 @@ udp46_input_inline (vlib_main_t * vm,
ICMP4_destination_unreachable,
ICMP4_destination_unreachable_port_unreachable,
0);
- next1 = UDP_INPUT_NEXT_ICMP4_ERROR;
+ next1 = UDP_LOCAL_NEXT_ICMP4_ERROR;
n_no_listener++;
}
else
@@ -241,7 +241,7 @@ udp46_input_inline (vlib_main_t * vm,
ICMP6_destination_unreachable,
ICMP6_destination_unreachable_port_unreachable,
0);
- next1 = UDP_INPUT_NEXT_ICMP6_ERROR;
+ next1 = UDP_LOCAL_NEXT_ICMP6_ERROR;
n_no_listener++;
}
}
@@ -254,26 +254,26 @@ udp46_input_inline (vlib_main_t * vm,
if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
{
- udp_rx_trace_t *tr = vlib_add_trace (vm, node,
- b0, sizeof (*tr));
+ udp_local_rx_trace_t *tr = vlib_add_trace (vm, node,
+ b0, sizeof (*tr));
if (b0->error != node->errors[UDP_ERROR_LENGTH_ERROR])
{
tr->src_port = h0 ? h0->src_port : 0;
tr->dst_port = h0 ? h0->dst_port : 0;
- tr->bound = (next0 != UDP_INPUT_NEXT_ICMP4_ERROR &&
- next0 != UDP_INPUT_NEXT_ICMP6_ERROR);
+ tr->bound = (next0 != UDP_LOCAL_NEXT_ICMP4_ERROR &&
+ next0 != UDP_LOCAL_NEXT_ICMP6_ERROR);
}
}
if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
{
- udp_rx_trace_t *tr = vlib_add_trace (vm, node,
- b1, sizeof (*tr));
+ udp_local_rx_trace_t *tr = vlib_add_trace (vm, node,
+ b1, sizeof (*tr));
if (b1->error != node->errors[UDP_ERROR_LENGTH_ERROR])
{
tr->src_port = h1 ? h1->src_port : 0;
tr->dst_port = h1 ? h1->dst_port : 0;
- tr->bound = (next1 != UDP_INPUT_NEXT_ICMP4_ERROR &&
- next1 != UDP_INPUT_NEXT_ICMP6_ERROR);
+ tr->bound = (next1 != UDP_LOCAL_NEXT_ICMP4_ERROR &&
+ next1 != UDP_LOCAL_NEXT_ICMP6_ERROR);
}
}
@@ -308,7 +308,7 @@ udp46_input_inline (vlib_main_t * vm,
if (PREDICT_FALSE (b0->current_length < advance0 + sizeof (*h0)))
{
b0->error = node->errors[UDP_ERROR_LENGTH_ERROR];
- next0 = UDP_INPUT_NEXT_DROP;
+ next0 = UDP_LOCAL_NEXT_DROP;
goto trace_x1;
}
@@ -333,7 +333,7 @@ udp46_input_inline (vlib_main_t * vm,
if (PREDICT_FALSE (punt_unknown))
{
b0->error = node->errors[UDP_ERROR_PUNT];
- next0 = UDP_INPUT_NEXT_PUNT;
+ next0 = UDP_LOCAL_NEXT_PUNT;
}
else if (is_ip4)
{
@@ -341,7 +341,7 @@ udp46_input_inline (vlib_main_t * vm,
ICMP4_destination_unreachable,
ICMP4_destination_unreachable_port_unreachable,
0);
- next0 = UDP_INPUT_NEXT_ICMP4_ERROR;
+ next0 = UDP_LOCAL_NEXT_ICMP4_ERROR;
n_no_listener++;
}
else
@@ -350,7 +350,7 @@ udp46_input_inline (vlib_main_t * vm,
ICMP6_destination_unreachable,
ICMP6_destination_unreachable_port_unreachable,
0);
- next0 = UDP_INPUT_NEXT_ICMP6_ERROR;
+ next0 = UDP_LOCAL_NEXT_ICMP6_ERROR;
n_no_listener++;
}
}
@@ -364,20 +364,20 @@ udp46_input_inline (vlib_main_t * vm,
else
{
b0->error = node->errors[UDP_ERROR_LENGTH_ERROR];
- next0 = UDP_INPUT_NEXT_DROP;
+ next0 = UDP_LOCAL_NEXT_DROP;
}
trace_x1:
if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
{
- udp_rx_trace_t *tr = vlib_add_trace (vm, node,
- b0, sizeof (*tr));
+ udp_local_rx_trace_t *tr = vlib_add_trace (vm, node,
+ b0, sizeof (*tr));
if (b0->error != node->errors[UDP_ERROR_LENGTH_ERROR])
{
tr->src_port = h0->src_port;
tr->dst_port = h0->dst_port;
- tr->bound = (next0 != UDP_INPUT_NEXT_ICMP4_ERROR &&
- next0 != UDP_INPUT_NEXT_ICMP6_ERROR);
+ tr->bound = (next0 != UDP_LOCAL_NEXT_ICMP4_ERROR &&
+ next0 != UDP_LOCAL_NEXT_ICMP6_ERROR);
}
}
@@ -400,23 +400,22 @@ static char *udp_error_strings[] = {
};
static uword
-udp4_input (vlib_main_t * vm,
+udp4_local (vlib_main_t * vm,
vlib_node_runtime_t * node, vlib_frame_t * from_frame)
{
- return udp46_input_inline (vm, node, from_frame, 1 /* is_ip4 */ );
+ return udp46_local_inline (vm, node, from_frame, 1 /* is_ip4 */ );
}
static uword
-udp6_input (vlib_main_t * vm,
+udp6_local (vlib_main_t * vm,
vlib_node_runtime_t * node, vlib_frame_t * from_frame)
{
- return udp46_input_inline (vm, node, from_frame, 0 /* is_ip4 */ );
+ return udp46_local_inline (vm, node, from_frame, 0 /* is_ip4 */ );
}
-
/* *INDENT-OFF* */
-VLIB_REGISTER_NODE (udp4_input_node) = {
- .function = udp4_input,
+VLIB_REGISTER_NODE (udp4_local_node) = {
+ .function = udp4_local,
.name = "ip4-udp-lookup",
/* Takes a vector of packets. */
.vector_size = sizeof (u32),
@@ -424,10 +423,10 @@ VLIB_REGISTER_NODE (udp4_input_node) = {
.n_errors = UDP_N_ERROR,
.error_strings = udp_error_strings,
- .n_next_nodes = UDP_INPUT_N_NEXT,
+ .n_next_nodes = UDP_LOCAL_N_NEXT,
.next_nodes = {
-#define _(s,n) [UDP_INPUT_NEXT_##s] = n,
- foreach_udp_input_next
+#define _(s,n) [UDP_LOCAL_NEXT_##s] = n,
+ foreach_udp_local_next
#undef _
},
@@ -437,11 +436,11 @@ VLIB_REGISTER_NODE (udp4_input_node) = {
};
/* *INDENT-ON* */
-VLIB_NODE_FUNCTION_MULTIARCH (udp4_input_node, udp4_input);
+VLIB_NODE_FUNCTION_MULTIARCH (udp4_local_node, udp4_local);
/* *INDENT-OFF* */
-VLIB_REGISTER_NODE (udp6_input_node) = {
- .function = udp6_input,
+VLIB_REGISTER_NODE (udp6_local_node) = {
+ .function = udp6_local,
.name = "ip6-udp-lookup",
/* Takes a vector of packets. */
.vector_size = sizeof (u32),
@@ -449,10 +448,10 @@ VLIB_REGISTER_NODE (udp6_input_node) = {
.n_errors = UDP_N_ERROR,
.error_strings = udp_error_strings,
- .n_next_nodes = UDP_INPUT_N_NEXT,
+ .n_next_nodes = UDP_LOCAL_N_NEXT,
.next_nodes = {
-#define _(s,n) [UDP_INPUT_NEXT_##s] = n,
- foreach_udp_input_next
+#define _(s,n) [UDP_LOCAL_NEXT_##s] = n,
+ foreach_udp_local_next
#undef _
},
@@ -462,7 +461,7 @@ VLIB_REGISTER_NODE (udp6_input_node) = {
};
/* *INDENT-ON* */
-VLIB_NODE_FUNCTION_MULTIARCH (udp6_input_node, udp6_input);
+VLIB_NODE_FUNCTION_MULTIARCH (udp6_local_node, udp6_local);
static void
add_dst_port (udp_main_t * um,
@@ -508,8 +507,8 @@ udp_register_dst_port (vlib_main_t * vm,
pi->node_index = node_index;
pi->next_index = vlib_node_add_next (vm,
- is_ip4 ? udp4_input_node.index
- : udp6_input_node.index, node_index);
+ is_ip4 ? udp4_local_node.index
+ : udp6_local_node.index, node_index);
/* Setup udp protocol -> next index sparse vector mapping. */
if (is_ip4)
@@ -620,8 +619,8 @@ udp_local_init (vlib_main_t * vm)
um->dst_port_info_by_dst_port[i] = hash_create (0, sizeof (uword));
}
- udp_setup_node (vm, udp4_input_node.index);
- udp_setup_node (vm, udp6_input_node.index);
+ udp_setup_node (vm, udp4_local_node.index);
+ udp_setup_node (vm, udp6_local_node.index);
um->punt_unknown4 = 0;
um->punt_unknown6 = 0;
@@ -640,7 +639,7 @@ udp_local_init (vlib_main_t * vm)
#define _(n,s) add_dst_port (um, UDP_DST_PORT_##s, #s, 0 /* is_ip4 */);
foreach_udp6_dst_port
#undef _
- ip4_register_protocol (IP_PROTOCOL_UDP, udp4_input_node.index);
+ ip4_register_protocol (IP_PROTOCOL_UDP, udp4_local_node.index);
/* Note: ip6 differs from ip4, UDP is hotwired to ip6-udp-lookup */
return 0;
}