session: Add transport vft protocol options
Type: refactor
Change-Id: I4e0afc206e4871596c2ed8a6ca00914a379f1526
Signed-off-by: Nathan Skrzypczak <nathan.skrzypczak@gmail.com>
diff --git a/src/plugins/quic/quic.c b/src/plugins/quic/quic.c
index 4e158bc..f099d07 100644
--- a/src/plugins/quic/quic.c
+++ b/src/plugins/quic/quic.c
@@ -2234,13 +2234,15 @@
.get_listener = quic_listener_get,
.update_time = quic_update_time,
.custom_tx = quic_custom_tx_callback,
- .tx_type = TRANSPORT_TX_INTERNAL,
- .service_type = TRANSPORT_SERVICE_APP,
.format_connection = format_quic_connection,
.format_half_open = format_quic_half_open,
.format_listener = format_quic_listener,
.get_transport_endpoint = quic_get_transport_endpoint,
.get_transport_listener_endpoint = quic_get_transport_listener_endpoint,
+ .transport_options = {
+ .tx_type = TRANSPORT_TX_INTERNAL,
+ .service_type = TRANSPORT_SERVICE_APP,
+ },
};
/* *INDENT-ON* */
diff --git a/src/vnet/sctp/sctp.c b/src/vnet/sctp/sctp.c
index 08285e4..e5d6cca 100644
--- a/src/vnet/sctp/sctp.c
+++ b/src/vnet/sctp/sctp.c
@@ -940,8 +940,8 @@
sctp_flush_frames_to_output (thread_index);
}
-/* *INDENT OFF* */
-const static transport_proto_vft_t sctp_proto = {
+/* *INDENT-OFF* */
+static const transport_proto_vft_t sctp_proto = {
.enable = sctp_enable_disable,
.start_listen = sctp_session_bind,
.stop_listen = sctp_session_unbind,
@@ -958,11 +958,12 @@
.format_connection = format_sctp_session,
.format_listener = format_sctp_listener_session,
.format_half_open = format_sctp_half_open,
- .tx_type = TRANSPORT_TX_DEQUEUE,
- .service_type = TRANSPORT_SERVICE_VC,
+ .transport_options = {
+ .tx_type = TRANSPORT_TX_DEQUEUE,
+ .service_type = TRANSPORT_SERVICE_VC,
+ },
};
-
-/* *INDENT ON* */
+/* *INDENT-ON* */
clib_error_t *
sctp_init (vlib_main_t * vm)
diff --git a/src/vnet/session/application_local.c b/src/vnet/session/application_local.c
index 2fcf070..4a93d3a 100644
--- a/src/vnet/session/application_local.c
+++ b/src/vnet/session/application_local.c
@@ -540,7 +540,7 @@
}
/* *INDENT-OFF* */
-const static transport_proto_vft_t cut_thru_proto = {
+static const transport_proto_vft_t cut_thru_proto = {
.start_listen = ct_start_listen,
.stop_listen = ct_stop_listen,
.get_listener = ct_listener_get,
@@ -549,10 +549,12 @@
.get_connection = ct_session_get,
.custom_tx = ct_custom_tx,
.app_rx_evt = ct_app_rx_evt,
- .tx_type = TRANSPORT_TX_INTERNAL,
- .service_type = TRANSPORT_SERVICE_APP,
.format_listener = format_ct_listener,
.format_connection = format_ct_session,
+ .transport_options = {
+ .tx_type = TRANSPORT_TX_INTERNAL,
+ .service_type = TRANSPORT_SERVICE_APP,
+ },
};
/* *INDENT-ON* */
diff --git a/src/vnet/session/session.c b/src/vnet/session/session.c
index ea52b75..0e5fb8e 100644
--- a/src/vnet/session/session.c
+++ b/src/vnet/session/session.c
@@ -1283,7 +1283,8 @@
/* *INDENT-ON* */
smm->session_type_to_next[session_type] = next_index;
- smm->session_tx_fns[session_type] = session_tx_fns[vft->tx_type];
+ smm->session_tx_fns[session_type] =
+ session_tx_fns[vft->transport_options.tx_type];
}
transport_connection_t *
diff --git a/src/vnet/session/session_node.c b/src/vnet/session/session_node.c
index 067ab58..8d01938 100644
--- a/src/vnet/session/session_node.c
+++ b/src/vnet/session/session_node.c
@@ -395,7 +395,8 @@
}
else
{
- if (ctx->transport_vft->tx_type == TRANSPORT_TX_DGRAM)
+ if (ctx->transport_vft->transport_options.tx_type ==
+ TRANSPORT_TX_DGRAM)
{
svm_fifo_t *f = ctx->s->tx_fifo;
session_dgram_hdr_t *hdr = &ctx->hdr;
@@ -466,7 +467,7 @@
}
else
{
- if (ctx->transport_vft->tx_type == TRANSPORT_TX_DGRAM)
+ if (ctx->transport_vft->transport_options.tx_type == TRANSPORT_TX_DGRAM)
{
session_dgram_hdr_t *hdr = &ctx->hdr;
svm_fifo_t *f = ctx->s->tx_fifo;
@@ -572,7 +573,7 @@
}
else
{
- if (ctx->transport_vft->tx_type == TRANSPORT_TX_DGRAM)
+ if (ctx->transport_vft->transport_options.tx_type == TRANSPORT_TX_DGRAM)
{
if (ctx->max_dequeue <= sizeof (ctx->hdr))
{
@@ -782,7 +783,8 @@
if (svm_fifo_set_event (ctx->s->tx_fifo))
vec_add1 (wrk->pending_event_vector, *e);
- if (!peek_data && ctx->transport_vft->tx_type == TRANSPORT_TX_DGRAM)
+ if (!peek_data
+ && ctx->transport_vft->transport_options.tx_type == TRANSPORT_TX_DGRAM)
{
/* Fix dgram pre header */
if (ctx->max_len_to_snd < ctx->max_dequeue)
diff --git a/src/vnet/session/transport.c b/src/vnet/session/transport.c
index bbd9c35..f971288 100644
--- a/src/vnet/session/transport.c
+++ b/src/vnet/session/transport.c
@@ -291,13 +291,13 @@
transport_service_type_t
transport_protocol_service_type (transport_proto_t tp)
{
- return tp_vfts[tp].service_type;
+ return tp_vfts[tp].transport_options.service_type;
}
transport_tx_fn_type_t
transport_protocol_tx_fn_type (transport_proto_t tp)
{
- return tp_vfts[tp].tx_type;
+ return tp_vfts[tp].transport_options.tx_type;
}
void
@@ -334,7 +334,7 @@
u8
transport_protocol_is_cl (transport_proto_t tp)
{
- return (tp_vfts[tp].service_type == TRANSPORT_SERVICE_CL);
+ return (tp_vfts[tp].transport_options.service_type == TRANSPORT_SERVICE_CL);
}
always_inline void
diff --git a/src/vnet/session/transport.h b/src/vnet/session/transport.h
index fadb02d..978e3f0 100644
--- a/src/vnet/session/transport.h
+++ b/src/vnet/session/transport.h
@@ -19,6 +19,12 @@
#include <vnet/vnet.h>
#include <vnet/session/transport_types.h>
+typedef struct _transport_options_t
+{
+ transport_tx_fn_type_t tx_type;
+ transport_service_type_t service_type;
+} transport_options_t;
+
/*
* Transport protocol virtual function table
*/
@@ -74,8 +80,7 @@
/*
* Properties
*/
- transport_tx_fn_type_t tx_type;
- transport_service_type_t service_type;
+ transport_options_t transport_options;
} transport_proto_vft_t;
/* *INDENT-ON* */
diff --git a/src/vnet/tcp/tcp.c b/src/vnet/tcp/tcp.c
index 03110e5..7b5b553 100644
--- a/src/vnet/tcp/tcp.c
+++ b/src/vnet/tcp/tcp.c
@@ -1227,8 +1227,10 @@
.format_connection = format_tcp_session,
.format_listener = format_tcp_listener_session,
.format_half_open = format_tcp_half_open_session,
- .tx_type = TRANSPORT_TX_PEEK,
- .service_type = TRANSPORT_SERVICE_VC,
+ .transport_options = {
+ .tx_type = TRANSPORT_TX_PEEK,
+ .service_type = TRANSPORT_SERVICE_VC,
+ },
};
/* *INDENT-ON* */
diff --git a/src/vnet/tls/tls.c b/src/vnet/tls/tls.c
index e4e8d43..344fdf4 100644
--- a/src/vnet/tls/tls.c
+++ b/src/vnet/tls/tls.c
@@ -757,7 +757,7 @@
}
/* *INDENT-OFF* */
-const static transport_proto_vft_t tls_proto = {
+static const transport_proto_vft_t tls_proto = {
.connect = tls_connect,
.close = tls_disconnect,
.start_listen = tls_start_listen,
@@ -765,13 +765,15 @@
.get_connection = tls_connection_get,
.get_listener = tls_listener_get,
.custom_tx = tls_custom_tx_callback,
- .tx_type = TRANSPORT_TX_INTERNAL,
- .service_type = TRANSPORT_SERVICE_APP,
.format_connection = format_tls_connection,
.format_half_open = format_tls_half_open,
.format_listener = format_tls_listener,
.get_transport_endpoint = tls_transport_endpoint_get,
.get_transport_listener_endpoint = tls_transport_listener_endpoint_get,
+ .transport_options = {
+ .tx_type = TRANSPORT_TX_INTERNAL,
+ .service_type = TRANSPORT_SERVICE_APP,
+ },
};
/* *INDENT-ON* */
diff --git a/src/vnet/udp/udp.c b/src/vnet/udp/udp.c
index bf91c90..d0c515a 100644
--- a/src/vnet/udp/udp.c
+++ b/src/vnet/udp/udp.c
@@ -320,11 +320,13 @@
/* We don't poll main thread if we have workers */
thread_index = vlib_num_workers ()? 1 : 0;
uc = udp_connection_get (conn_index, thread_index);
+ if (!uc)
+ return 0;
return &uc->connection;
}
/* *INDENT-OFF* */
-const static transport_proto_vft_t udp_proto = {
+static const transport_proto_vft_t udp_proto = {
.start_listen = udp_session_bind,
.connect = udp_open_connection,
.stop_listen = udp_session_unbind,
@@ -339,8 +341,10 @@
.format_connection = format_udp_session,
.format_half_open = format_udp_half_open_session,
.format_listener = format_udp_listener_session,
- .tx_type = TRANSPORT_TX_DGRAM,
- .service_type = TRANSPORT_SERVICE_CL,
+ .transport_options = {
+ .tx_type = TRANSPORT_TX_DGRAM,
+ .service_type = TRANSPORT_SERVICE_CL,
+ },
};
/* *INDENT-ON* */
@@ -354,7 +358,8 @@
u32 uc_index;
uc_index = udp_open_connection (rmt);
uc = udp_connection_get (uc_index, thread_index);
- uc->is_connected = 1;
+ if (uc)
+ uc->is_connected = 1;
return uc_index;
}
@@ -370,7 +375,7 @@
}
/* *INDENT-OFF* */
-const static transport_proto_vft_t udpc_proto = {
+static const transport_proto_vft_t udpc_proto = {
.start_listen = udpc_connection_listen,
.stop_listen = udp_session_unbind,
.connect = udpc_connection_open,
@@ -385,8 +390,10 @@
.format_connection = format_udp_session,
.format_half_open = format_udp_half_open_session,
.format_listener = format_udp_listener_session,
- .tx_type = TRANSPORT_TX_DGRAM,
- .service_type = TRANSPORT_SERVICE_CL,
+ .transport_options = {
+ .tx_type = TRANSPORT_TX_DGRAM,
+ .service_type = TRANSPORT_SERVICE_VC,
+ },
};
/* *INDENT-ON* */