aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/session
diff options
context:
space:
mode:
Diffstat (limited to 'src/vnet/session')
-rw-r--r--src/vnet/session/application.h44
-rw-r--r--src/vnet/session/session.c41
-rw-r--r--src/vnet/session/session.h78
-rw-r--r--src/vnet/session/session_types.h260
-rw-r--r--src/vnet/session/transport.c13
-rw-r--r--src/vnet/session/transport.h19
-rw-r--r--src/vnet/session/transport_interface.h24
7 files changed, 245 insertions, 234 deletions
diff --git a/src/vnet/session/application.h b/src/vnet/session/application.h
index 54f998996e9..f0c0a0d2403 100644
--- a/src/vnet/session/application.h
+++ b/src/vnet/session/application.h
@@ -316,50 +316,6 @@ int app_worker_local_session_disconnect_w_index (u32 app_or_wrk,
void app_worker_format_local_sessions (app_worker_t * app_wrk, int verbose);
void app_worker_format_local_connects (app_worker_t * app, int verbose);
-always_inline u32
-local_session_id (local_session_t * ls)
-{
- ASSERT (ls->session_index < (2 << 16));
- u32 app_or_wrk_index;
-
- if (ls->session_state == SESSION_STATE_LISTENING)
- {
- ASSERT (ls->app_index < (2 << 16));
- app_or_wrk_index = ls->app_index;
- }
- else
- {
- ASSERT (ls->app_wrk_index < (2 << 16));
- app_or_wrk_index = ls->app_wrk_index;
- }
-
- return ((u32) app_or_wrk_index << 16 | (u32) ls->session_index);
-}
-
-always_inline void
-local_session_parse_id (u32 ls_id, u32 * app_or_wrk, u32 * session_index)
-{
- *app_or_wrk = ls_id >> 16;
- *session_index = ls_id & 0xFF;
-}
-
-always_inline void
-local_session_parse_handle (session_handle_t handle, u32 * app_or_wrk_index,
- u32 * session_index)
-{
- u32 bottom;
- ASSERT ((handle >> 32) == SESSION_LOCAL_HANDLE_PREFIX);
- bottom = (handle & 0xFFFFFFFF);
- local_session_parse_id (bottom, app_or_wrk_index, session_index);
-}
-
-always_inline session_handle_t
-application_local_session_handle (local_session_t * ls)
-{
- return ((u64) SESSION_LOCAL_HANDLE_PREFIX << 32)
- | (u64) local_session_id (ls);
-}
-
always_inline local_session_t *
application_get_local_listen_session (application_t * app, u32 session_index)
{
diff --git a/src/vnet/session/session.c b/src/vnet/session/session.c
index 520d329f742..7b1c754d31c 100644
--- a/src/vnet/session/session.c
+++ b/src/vnet/session/session.c
@@ -1235,28 +1235,6 @@ session_transport_cleanup (session_t * s)
session_free_w_fifos (s);
}
-transport_service_type_t
-session_transport_service_type (session_t * s)
-{
- transport_proto_t tp;
- tp = session_get_transport_proto (s);
- return transport_protocol_service_type (tp);
-}
-
-transport_tx_fn_type_t
-session_transport_tx_fn_type (session_t * s)
-{
- transport_proto_t tp;
- tp = session_get_transport_proto (s);
- return transport_protocol_tx_fn_type (tp);
-}
-
-u8
-session_tx_is_dgram (session_t * s)
-{
- return (session_transport_tx_fn_type (s) == TRANSPORT_TX_DGRAM);
-}
-
/**
* Allocate event queues in the shared-memory segment
*
@@ -1385,30 +1363,27 @@ session_register_transport (transport_proto_t transport_proto,
transport_connection_t *
session_get_transport (session_t * s)
{
- transport_proto_t tp;
if (s->session_state != SESSION_STATE_LISTENING)
- {
- tp = session_get_transport_proto (s);
- return tp_vfts[tp].get_connection (s->connection_index,
- s->thread_index);
- }
- return 0;
+ return transport_get_connection (session_get_transport_proto (s),
+ s->connection_index, s->thread_index);
+ else
+ return transport_get_listener (session_get_transport_proto (s),
+ s->connection_index);
}
transport_connection_t *
listen_session_get_transport (session_t * s)
{
- transport_proto_t tp = session_get_transport_proto (s);
- return tp_vfts[tp].get_listener (s->connection_index);
+ return transport_get_listener (session_get_transport_proto (s),
+ s->connection_index);
}
int
listen_session_get_local_session_endpoint (session_t * listener,
session_endpoint_t * sep)
{
- transport_proto_t tp = session_get_transport_proto (listener);
transport_connection_t *tc;
- tc = tp_vfts[tp].get_listener (listener->connection_index);
+ tc = listen_session_get_transport (listener);
if (!tc)
{
clib_warning ("no transport");
diff --git a/src/vnet/session/session.h b/src/vnet/session/session.h
index 6ae901c656b..68d82761dcd 100644
--- a/src/vnet/session/session.h
+++ b/src/vnet/session/session.h
@@ -23,7 +23,6 @@
#include <svm/message_queue.h>
#define SESSION_PROXY_LISTENER_INDEX ((u8)~0 - 1)
-#define SESSION_LOCAL_HANDLE_PREFIX 0x7FFFFFFF
/* TODO decide how much since we have pre-data as well */
#define MAX_HDRS_LEN 100 /* Max number of bytes for headers */
@@ -106,8 +105,6 @@ typedef struct
void *arg;
} session_rpc_args_t;
-typedef u64 session_handle_t;
-
/* *INDENT-OFF* */
typedef struct
{
@@ -358,32 +355,6 @@ session_get_if_valid (u64 si, u32 thread_index)
si);
}
-always_inline session_handle_t
-session_handle (session_t * s)
-{
- return ((u64) s->thread_index << 32) | (u64) s->session_index;
-}
-
-always_inline u32
-session_index_from_handle (session_handle_t handle)
-{
- return handle & 0xFFFFFFFF;
-}
-
-always_inline u32
-session_thread_from_handle (session_handle_t handle)
-{
- return handle >> 32;
-}
-
-always_inline void
-session_parse_handle (session_handle_t handle, u32 * index,
- u32 * thread_index)
-{
- *index = session_index_from_handle (handle);
- *thread_index = session_thread_from_handle (handle);
-}
-
always_inline session_t *
session_get_from_handle (session_handle_t handle)
{
@@ -401,45 +372,6 @@ session_get_from_handle_if_valid (session_handle_t handle)
return session_get_if_valid (session_index, thread_index);
}
-always_inline u8
-session_handle_is_local (session_handle_t handle)
-{
- if ((handle >> 32) == SESSION_LOCAL_HANDLE_PREFIX)
- return 1;
- return 0;
-}
-
-always_inline transport_proto_t
-session_type_transport_proto (session_type_t st)
-{
- return (st >> 1);
-}
-
-always_inline u8
-session_type_is_ip4 (session_type_t st)
-{
- return (st & 1);
-}
-
-always_inline transport_proto_t
-session_get_transport_proto (session_t * s)
-{
- return (s->session_type >> 1);
-}
-
-always_inline fib_protocol_t
-session_get_fib_proto (session_t * s)
-{
- u8 is_ip4 = s->session_type & 1;
- return (is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
-}
-
-always_inline session_type_t
-session_type_from_proto_and_ip (transport_proto_t proto, u8 is_ip4)
-{
- return (proto << 1 | is_ip4);
-}
-
always_inline u64
session_segment_handle (session_t * s)
{
@@ -453,16 +385,6 @@ session_segment_handle (session_t * s)
f->segment_index);
}
-always_inline u8
-session_has_transport (session_t * s)
-{
- return (session_get_transport_proto (s) != TRANSPORT_PROTO_NONE);
-}
-
-transport_service_type_t session_transport_service_type (session_t *);
-transport_tx_fn_type_t session_transport_tx_fn_type (session_t *);
-u8 session_tx_is_dgram (session_t * s);
-
/**
* Acquires a lock that blocks a session pool from expanding.
*
diff --git a/src/vnet/session/session_types.h b/src/vnet/session/session_types.h
index ec5841f5ea4..b334c3c9f69 100644
--- a/src/vnet/session/session_types.h
+++ b/src/vnet/session/session_types.h
@@ -19,7 +19,80 @@
#include <svm/svm_fifo.h>
#include <vnet/session/transport.h>
+#define SESSION_LOCAL_HANDLE_PREFIX 0x7FFFFFFF
+
+#define foreach_session_endpoint_fields \
+ foreach_transport_endpoint_cfg_fields \
+ _(u8, transport_proto) \
+
+typedef struct _session_endpoint
+{
+#define _(type, name) type name;
+ foreach_session_endpoint_fields
+#undef _
+} session_endpoint_t;
+
+typedef struct _session_endpoint_cfg
+{
+#define _(type, name) type name;
+ foreach_session_endpoint_fields
+#undef _
+ u32 app_wrk_index;
+ u32 opaque;
+ u8 *hostname;
+} session_endpoint_cfg_t;
+
+#define SESSION_IP46_ZERO \
+{ \
+ .ip6 = { \
+ { 0, 0, }, \
+ }, \
+}
+
+#define TRANSPORT_ENDPOINT_NULL \
+{ \
+ .sw_if_index = ENDPOINT_INVALID_INDEX, \
+ .ip = SESSION_IP46_ZERO, \
+ .fib_index = ENDPOINT_INVALID_INDEX, \
+ .is_ip4 = 0, \
+ .port = 0, \
+}
+#define SESSION_ENDPOINT_NULL \
+{ \
+ .sw_if_index = ENDPOINT_INVALID_INDEX, \
+ .ip = SESSION_IP46_ZERO, \
+ .fib_index = ENDPOINT_INVALID_INDEX, \
+ .is_ip4 = 0, \
+ .port = 0, \
+ .peer = TRANSPORT_ENDPOINT_NULL, \
+ .transport_proto = 0, \
+}
+#define SESSION_ENDPOINT_CFG_NULL \
+{ \
+ .sw_if_index = ENDPOINT_INVALID_INDEX, \
+ .ip = SESSION_IP46_ZERO, \
+ .fib_index = ENDPOINT_INVALID_INDEX, \
+ .is_ip4 = 0, \
+ .port = 0, \
+ .peer = TRANSPORT_ENDPOINT_NULL, \
+ .transport_proto = 0, \
+ .app_wrk_index = ENDPOINT_INVALID_INDEX, \
+ .opaque = ENDPOINT_INVALID_INDEX, \
+ .hostname = 0, \
+}
+
+#define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
+#define session_endpoint_to_transport_cfg(_sep) \
+ ((transport_endpoint_cfg_t *)_sep)
+
+always_inline u8
+session_endpoint_fib_proto (session_endpoint_t * sep)
+{
+ return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
+}
+
typedef u8 session_type_t;
+typedef u64 session_handle_t;
/*
* Application session state
@@ -101,6 +174,99 @@ typedef struct session_
CLIB_CACHE_LINE_ALIGN_MARK (pad);
} session_t;
+always_inline session_type_t
+session_type_from_proto_and_ip (transport_proto_t proto, u8 is_ip4)
+{
+ return (proto << 1 | is_ip4);
+}
+
+always_inline transport_proto_t
+session_type_transport_proto (session_type_t st)
+{
+ return (st >> 1);
+}
+
+always_inline u8
+session_type_is_ip4 (session_type_t st)
+{
+ return (st & 1);
+}
+
+always_inline transport_proto_t
+session_get_transport_proto (session_t * s)
+{
+ return (s->session_type >> 1);
+}
+
+always_inline fib_protocol_t
+session_get_fib_proto (session_t * s)
+{
+ u8 is_ip4 = s->session_type & 1;
+ return (is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6);
+}
+
+always_inline u8
+session_has_transport (session_t * s)
+{
+ return (session_get_transport_proto (s) != TRANSPORT_PROTO_NONE);
+}
+
+static inline transport_service_type_t
+session_transport_service_type (session_t * s)
+{
+ transport_proto_t tp;
+ tp = session_get_transport_proto (s);
+ return transport_protocol_service_type (tp);
+}
+
+static inline transport_tx_fn_type_t
+session_transport_tx_fn_type (session_t * s)
+{
+ transport_proto_t tp;
+ tp = session_get_transport_proto (s);
+ return transport_protocol_tx_fn_type (tp);
+}
+
+static inline u8
+session_tx_is_dgram (session_t * s)
+{
+ return (session_transport_tx_fn_type (s) == TRANSPORT_TX_DGRAM);
+}
+
+always_inline session_handle_t
+session_handle (session_t * s)
+{
+ return ((u64) s->thread_index << 32) | (u64) s->session_index;
+}
+
+always_inline u32
+session_index_from_handle (session_handle_t handle)
+{
+ return handle & 0xFFFFFFFF;
+}
+
+always_inline u32
+session_thread_from_handle (session_handle_t handle)
+{
+ return handle >> 32;
+}
+
+always_inline void
+session_parse_handle (session_handle_t handle, u32 * index,
+ u32 * thread_index)
+{
+ *index = session_index_from_handle (handle);
+ *thread_index = session_thread_from_handle (handle);
+}
+
+always_inline u8
+session_handle_is_local (session_handle_t handle)
+{
+ if ((handle >> 32) == SESSION_LOCAL_HANDLE_PREFIX)
+ return 1;
+ return 0;
+}
+
typedef struct local_session_
{
/** fifo pointers. Once allocated, these do not move */
@@ -154,74 +320,48 @@ typedef struct local_session_
CLIB_CACHE_LINE_ALIGN_MARK (pad);
} local_session_t;
-#define foreach_session_endpoint_fields \
- foreach_transport_endpoint_cfg_fields \
- _(u8, transport_proto) \
-
-typedef struct _session_endpoint
+always_inline u32
+local_session_id (local_session_t * ls)
{
-#define _(type, name) type name;
- foreach_session_endpoint_fields
-#undef _
-} session_endpoint_t;
+ ASSERT (ls->session_index < (2 << 16));
+ u32 app_or_wrk_index;
+
+ if (ls->session_state == SESSION_STATE_LISTENING)
+ {
+ ASSERT (ls->app_index < (2 << 16));
+ app_or_wrk_index = ls->app_index;
+ }
+ else
+ {
+ ASSERT (ls->app_wrk_index < (2 << 16));
+ app_or_wrk_index = ls->app_wrk_index;
+ }
+
+ return ((u32) app_or_wrk_index << 16 | (u32) ls->session_index);
+}
-typedef struct _session_endpoint_cfg
+always_inline void
+local_session_parse_id (u32 ls_id, u32 * app_or_wrk, u32 * session_index)
{
-#define _(type, name) type name;
- foreach_session_endpoint_fields
-#undef _
- u32 app_wrk_index;
- u32 opaque;
- u8 *hostname;
-} session_endpoint_cfg_t;
-
-#define SESSION_IP46_ZERO \
-{ \
- .ip6 = { \
- { 0, 0, }, \
- }, \
+ *app_or_wrk = ls_id >> 16;
+ *session_index = ls_id & 0xFF;
}
-#define TRANSPORT_ENDPOINT_NULL \
-{ \
- .sw_if_index = ENDPOINT_INVALID_INDEX, \
- .ip = SESSION_IP46_ZERO, \
- .fib_index = ENDPOINT_INVALID_INDEX, \
- .is_ip4 = 0, \
- .port = 0, \
-}
-#define SESSION_ENDPOINT_NULL \
-{ \
- .sw_if_index = ENDPOINT_INVALID_INDEX, \
- .ip = SESSION_IP46_ZERO, \
- .fib_index = ENDPOINT_INVALID_INDEX, \
- .is_ip4 = 0, \
- .port = 0, \
- .peer = TRANSPORT_ENDPOINT_NULL, \
- .transport_proto = 0, \
-}
-#define SESSION_ENDPOINT_CFG_NULL \
-{ \
- .sw_if_index = ENDPOINT_INVALID_INDEX, \
- .ip = SESSION_IP46_ZERO, \
- .fib_index = ENDPOINT_INVALID_INDEX, \
- .is_ip4 = 0, \
- .port = 0, \
- .peer = TRANSPORT_ENDPOINT_NULL, \
- .transport_proto = 0, \
- .app_wrk_index = ENDPOINT_INVALID_INDEX, \
- .opaque = ENDPOINT_INVALID_INDEX, \
- .hostname = 0, \
+always_inline void
+local_session_parse_handle (session_handle_t handle, u32 * app_or_wrk_index,
+ u32 * session_index)
+{
+ u32 bottom;
+ ASSERT ((handle >> 32) == SESSION_LOCAL_HANDLE_PREFIX);
+ bottom = (handle & 0xFFFFFFFF);
+ local_session_parse_id (bottom, app_or_wrk_index, session_index);
}
-#define session_endpoint_to_transport(_sep) ((transport_endpoint_t *)_sep)
-#define session_endpoint_to_transport_cfg(_sep) \
- ((transport_endpoint_cfg_t *)_sep)
-
-always_inline u8
-session_endpoint_fib_proto (session_endpoint_t * sep)
+always_inline session_handle_t
+application_local_session_handle (local_session_t * ls)
{
- return sep->is_ip4 ? FIB_PROTOCOL_IP4 : FIB_PROTOCOL_IP6;
+ return ((u64) SESSION_LOCAL_HANDLE_PREFIX << 32)
+ | (u64) local_session_id (ls);
}
#endif /* SRC_VNET_SESSION_SESSION_TYPES_H_ */
diff --git a/src/vnet/session/transport.c b/src/vnet/session/transport.c
index 0f86f9e916a..df5282cc43a 100644
--- a/src/vnet/session/transport.c
+++ b/src/vnet/session/transport.c
@@ -271,6 +271,19 @@ transport_protocol_tx_fn_type (transport_proto_t tp)
return tp_vfts[tp].tx_type;
}
+transport_connection_t *
+transport_get_connection (transport_proto_t tp, u32 conn_index,
+ u8 thread_index)
+{
+ return tp_vfts[tp].get_connection (conn_index, thread_index);
+}
+
+transport_connection_t *
+transport_get_listener (transport_proto_t tp, u32 conn_index)
+{
+ return tp_vfts[tp].get_listener (conn_index);
+}
+
u8
transport_protocol_is_cl (transport_proto_t tp)
{
diff --git a/src/vnet/session/transport.h b/src/vnet/session/transport.h
index 71e70e14289..a82dc3d8493 100644
--- a/src/vnet/session/transport.h
+++ b/src/vnet/session/transport.h
@@ -20,6 +20,23 @@
#include <vnet/ip/ip.h>
#include <vnet/tcp/tcp_debug.h>
+typedef enum transport_dequeue_type_
+{
+ TRANSPORT_TX_PEEK, /**< reliable transport protos */
+ TRANSPORT_TX_DEQUEUE, /**< unreliable transport protos */
+ TRANSPORT_TX_INTERNAL, /**< apps acting as transports */
+ TRANSPORT_TX_DGRAM, /**< datagram mode */
+ TRANSPORT_TX_N_FNS
+} transport_tx_fn_type_t;
+
+typedef enum transport_service_type_
+{
+ TRANSPORT_SERVICE_VC, /**< virtual circuit service */
+ TRANSPORT_SERVICE_CL, /**< connectionless service */
+ TRANSPORT_SERVICE_APP, /**< app transport service */
+ TRANSPORT_N_SERVICES
+} transport_service_type_t;
+
typedef struct _transport_stats
{
u64 tx_bytes;
@@ -169,6 +186,8 @@ int transport_alloc_local_endpoint (u8 proto, transport_endpoint_cfg_t * rmt,
u16 * lcl_port);
void transport_endpoint_cleanup (u8 proto, ip46_address_t * lcl_ip, u16 port);
u8 transport_protocol_is_cl (transport_proto_t tp);
+transport_service_type_t transport_protocol_service_type (transport_proto_t);
+transport_tx_fn_type_t transport_protocol_tx_fn_type (transport_proto_t tp);
void transport_init (void);
#endif /* VNET_VNET_URI_TRANSPORT_H_ */
diff --git a/src/vnet/session/transport_interface.h b/src/vnet/session/transport_interface.h
index a287e4f27d5..123048613bf 100644
--- a/src/vnet/session/transport_interface.h
+++ b/src/vnet/session/transport_interface.h
@@ -19,23 +19,6 @@
#include <vnet/vnet.h>
#include <vnet/session/transport.h>
-typedef enum transport_dequeue_type_
-{
- TRANSPORT_TX_PEEK, /**< reliable transport protos */
- TRANSPORT_TX_DEQUEUE, /**< unreliable transport protos */
- TRANSPORT_TX_INTERNAL, /**< apps acting as transports */
- TRANSPORT_TX_DGRAM, /**< datagram mode */
- TRANSPORT_TX_N_FNS
-} transport_tx_fn_type_t;
-
-typedef enum transport_service_type_
-{
- TRANSPORT_SERVICE_VC, /**< virtual circuit service */
- TRANSPORT_SERVICE_CL, /**< connectionless service */
- TRANSPORT_SERVICE_APP, /**< app transport service */
- TRANSPORT_N_SERVICES
-} transport_service_type_t;
-
/*
* Transport protocol virtual function table
*/
@@ -98,9 +81,12 @@ void transport_register_protocol (transport_proto_t transport_proto,
const transport_proto_vft_t * vft,
fib_protocol_t fib_proto, u32 output_node);
transport_proto_vft_t *transport_protocol_get_vft (transport_proto_t tp);
-transport_service_type_t transport_protocol_service_type (transport_proto_t);
-transport_tx_fn_type_t transport_protocol_tx_fn_type (transport_proto_t tp);
void transport_update_time (f64 time_now, u8 thread_index);
+transport_connection_t *transport_get_connection (transport_proto_t tp,
+ u32 conn_index,
+ u8 thread_index);
+transport_connection_t *transport_get_listener (transport_proto_t tp,
+ u32 conn_index);
void transport_enable_disable (vlib_main_t * vm, u8 is_en);
always_inline u32