summaryrefslogtreecommitdiffstats
path: root/src/vnet/tls
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2021-05-13 08:36:56 -0700
committerDamjan Marion <dmarion@me.com>2021-05-14 08:44:47 +0000
commitbab6c52f4544ebe352a1a9f832137d9b4069ae6c (patch)
treea323f61fda3dc631981d74fad0f53749dad22989 /src/vnet/tls
parent9f07085ab37d9bc27d2f2ccc4d651d7295f9b33c (diff)
tls: switch dtls to vc and track half-opens
Also adds support for half-open support transport migration. Type: improvement Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: Id04c194138956336f93246bbed0332a7030c67e2
Diffstat (limited to 'src/vnet/tls')
-rw-r--r--src/vnet/tls/tls.c63
1 files changed, 59 insertions, 4 deletions
diff --git a/src/vnet/tls/tls.c b/src/vnet/tls/tls.c
index 09fc8c62325..acaeb02f73c 100644
--- a/src/vnet/tls/tls.c
+++ b/src/vnet/tls/tls.c
@@ -234,6 +234,8 @@ tls_notify_app_connected (tls_ctx_t * ctx, session_error_t err)
if (ctx->tls_type == TRANSPORT_PROTO_DTLS)
{
session_type_t st;
+ /* Cleanup half-open session as we don't get notification from udp */
+ session_half_open_delete_notify (&ctx->connection);
app_session = session_alloc (ctx->c_thread_index);
app_session->session_state = SESSION_STATE_CREATED;
ctx->c_s_index = app_session->session_index;
@@ -647,6 +649,15 @@ dtls_migrate_ctx (void *arg)
us = session_get_from_handle (ctx->tls_session_handle);
us->opaque = ctx_handle;
us->flags &= ~SESSION_F_IS_MIGRATING;
+
+ /* Probably the app detached while the session was migrating. Cleanup */
+ if (session_half_open_migrated_notify (&ctx->connection))
+ {
+ ctx->no_app_session = 1;
+ tls_disconnect (ctx->tls_ctx_handle, vlib_get_thread_index ());
+ return;
+ }
+
if (svm_fifo_max_dequeue (us->tx_fifo))
session_send_io_evt_to_thread (us->tx_fifo, SESSION_IO_EVT_TX);
}
@@ -662,6 +673,7 @@ dtls_session_migrate_callback (session_t *us, session_handle_t new_sh)
ctx->tls_session_handle = new_sh;
cloned_ctx = tls_ctx_detach (ctx);
ctx->is_migrated = 1;
+ session_half_open_migrate_notify (&ctx->connection);
session_send_rpc_evt_to_thread (new_thread, dtls_migrate_ctx,
(void *) cloned_ctx);
@@ -905,10 +917,14 @@ static void
tls_cleanup_ho (u32 ho_index)
{
tls_main_t *tm = &tls_main;
+ session_handle_t tcp_sh;
tls_ctx_t *ctx;
+
ctx = tls_ctx_half_open_get (ho_index);
+ tcp_sh = ctx->tls_session_handle;
clib_rwlock_reader_unlock (&tm->half_open_rwlock);
- session_cleanup_half_open (ctx->tls_session_handle);
+ session_cleanup_half_open (tcp_sh);
+ tls_ctx_half_open_free (ho_index);
}
int
@@ -1182,6 +1198,8 @@ dtls_connect (transport_endpoint_cfg_t *tep)
ctx->ckpair_index = ccfg->ckpair_index;
ctx->tls_type = sep->transport_proto;
ctx->tls_ctx_handle = ctx_handle;
+ ctx->c_proto = TRANSPORT_PROTO_DTLS;
+ ctx->c_flags |= TRANSPORT_CONNECTION_F_NO_LOOKUP;
if (ccfg->hostname[0])
{
ctx->srv_hostname = format (0, "%s", ccfg->hostname);
@@ -1201,7 +1219,15 @@ dtls_connect (transport_endpoint_cfg_t *tep)
TLS_DBG (1, "New DTLS connect request %x engine %d", ctx_handle,
engine_type);
- return 0;
+ return ctx_handle;
+}
+
+static transport_connection_t *
+dtls_half_open_get (u32 ho_index)
+{
+ tls_ctx_t *ho_ctx;
+ ho_ctx = tls_ctx_get_w_thread (ho_index, 1 /* udp connects */);
+ return &ho_ctx->connection;
}
static void
@@ -1210,6 +1236,33 @@ dtls_cleanup_callback (u32 ctx_index, u32 thread_index)
/* No op */
}
+static void
+dtls_cleanup_ho (u32 ho_index)
+{
+ tls_ctx_t *ctx;
+ ctx = tls_ctx_get_w_thread (ho_index, 1 /* udp connects */);
+ tls_ctx_free (ctx);
+}
+
+u8 *
+format_dtls_half_open (u8 *s, va_list *args)
+{
+ u32 ho_index = va_arg (*args, u32);
+ u32 __clib_unused thread_index = va_arg (*args, u32);
+ tls_ctx_t *ho_ctx;
+ session_t *us;
+
+ ho_ctx = tls_ctx_get_w_thread (ho_index, 1 /* udp connects */);
+
+ us = session_get_from_handle (ho_ctx->tls_session_handle);
+ s = format (s, "[%d:%d][%s] half-open app_wrk %u engine %u us %d:%d",
+ ho_ctx->c_thread_index, ho_ctx->c_s_index, "DTLS",
+ ho_ctx->parent_app_wrk_index, ho_ctx->tls_ctx_engine,
+ us->thread_index, us->session_index);
+
+ return s;
+}
+
static const transport_proto_vft_t dtls_proto = {
.enable = 0,
.connect = dtls_connect,
@@ -1218,10 +1271,12 @@ static const transport_proto_vft_t dtls_proto = {
.stop_listen = tls_stop_listen,
.get_connection = tls_connection_get,
.get_listener = tls_listener_get,
+ .get_half_open = dtls_half_open_get,
.custom_tx = tls_custom_tx_callback,
.cleanup = dtls_cleanup_callback,
+ .cleanup_ho = dtls_cleanup_ho,
.format_connection = format_tls_connection,
- .format_half_open = format_tls_half_open,
+ .format_half_open = format_dtls_half_open,
.format_listener = format_tls_listener,
.get_transport_endpoint = tls_transport_endpoint_get,
.get_transport_listener_endpoint = tls_transport_listener_endpoint_get,
@@ -1229,7 +1284,7 @@ static const transport_proto_vft_t dtls_proto = {
.name = "dtls",
.short_name = "D",
.tx_type = TRANSPORT_TX_INTERNAL,
- .service_type = TRANSPORT_SERVICE_APP,
+ .service_type = TRANSPORT_SERVICE_VC,
},
};
6db74 } /* Literal.String.Single */ .highlight .ss { color: #e6db74 } /* Literal.String.Symbol */ .highlight .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #a6e22e } /* Name.Function.Magic */ .highlight .vc { color: #f8f8f2 } /* Name.Variable.Class */ .highlight .vg { color: #f8f8f2 } /* Name.Variable.Global */ .highlight .vi { color: #f8f8f2 } /* Name.Variable.Instance */ .highlight .vm { color: #f8f8f2 } /* Name.Variable.Magic */ .highlight .il { color: #ae81ff } /* Literal.Number.Integer.Long */ } @media (prefers-color-scheme: light) { .highlight .hll { background-color: #ffffcc } .highlight .c { color: #888888 } /* Comment */ .highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */ .highlight .k { color: #008800; font-weight: bold } /* Keyword */ .highlight .ch { color: #888888 } /* Comment.Hashbang */ .highlight .cm { color: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */ }
#!/usr/bin/env bash

# Copyright (c) 2021 Cisco and/or its affiliates.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# CSIT SRIOV VF initialization and isolation.

set -euo pipefail

case "${1:-start}" in
    "start" )
        # Run TG
        for cnt in $(seq 1 ${2:-1}); do
            docker network create --driver bridge csit-nw-tg${cnt} || true
            # If the IMAGE is not already loaded then docker run will pull the
            # IMAGE, and all image dependencies, before it starts the container.
            dcr_image="csit_sut-ubuntu2004:local"
            # Run the container in the background and print the new container
            # ID.
            dcr_stc_params="--detach=true "
            # Give extended privileges to this container. A "privileged"
            # container is given access to all devices and able to run nested
            # containers.
            dcr_stc_params+="--privileged "
            # Publish all exposed ports to random ports on the host interfaces.
            dcr_stc_params+="--publish 600${cnt}:2222 "
            # Automatically remove the container when it exits.
            dcr_stc_params+="--rm "
            # Size of /dev/shm.
            dcr_stc_params+="--shm-size 4G "
            # Mount vfio to be able to bind to see binded interfaces. We cannot
            # use --device=/dev/vfio as this does not see newly binded
            # interfaces.
            dcr_stc_params+="--volume /dev:/dev "
            # Mount /opt/boot/ where VM kernel and initrd are located.
            dcr_stc_params+="--volume /opt:/opt "
            # Mount host hugepages for VMs.
            dcr_stc_params+="--volume /dev/hugepages:/dev/hugepages "

            params=(${dcr_stc_params} --name csit-tg-"${cnt}" "${dcr_image}")
            docker run --network=csit-nw-tg${cnt} "${params[@]}"
        done
        ;;
    "stop" )
        docker rm --force $(docker ps --all --quiet --filter name=csit)
        docker network rm $(docker network ls --filter name=csit --quiet)
        ;;
esac