diff options
author | David Carlier <[email protected]> | 2019-03-29 10:53:23 +0000 |
---|---|---|
committer | David Carlier <[email protected]> | 2019-03-29 11:44:04 +0000 |
commit | caccce8221aed34f5acf5db54f13b9c678f11c0f (patch) | |
tree | ac4b04b787baadebe250d68e2e53cadfc3c38469 /src | |
parent | a8316c17d3db4087bf4933502f205a92c9232c79 (diff) |
Tracing socket feature for the CLI TLS server.
For now FreeBSD DTrace support.
Diffstat (limited to 'src')
-rw-r--r-- | src/cli/tls_server.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/cli/tls_server.cpp b/src/cli/tls_server.cpp index cf1f7a8ff..2146ab7f7 100644 --- a/src/cli/tls_server.cpp +++ b/src/cli/tls_server.cpp @@ -12,6 +12,12 @@ #if defined(BOTAN_HAS_TLS) && defined(BOTAN_TARGET_OS_HAS_FILESYSTEM) && \ (defined(BOTAN_TARGET_OS_HAS_SOCKETS) || defined(BOTAN_TARGET_OS_HAS_WINSOCK2)) +#if defined(SO_USER_COOKIE) +#define SOCKET_ID 1 +#else +#define SOCKET_ID 0 +#endif + #include <botan/tls_server.h> #include <botan/tls_policy.h> #include <botan/hex.h> @@ -28,7 +34,11 @@ namespace Botan_CLI { class TLS_Server final : public Command, public Botan::TLS::Callbacks { public: +#if SOCKET_ID + TLS_Server() : Command("tls_server cert key --port=443 --type=tcp --policy= --dump-traces= --max-clients=0 -socket-id=0") +#else TLS_Server() : Command("tls_server cert key --port=443 --type=tcp --policy= --dump-traces= --max-clients=0") +#endif { init_sockets(); } @@ -56,6 +66,9 @@ class TLS_Server final : public Command, public Botan::TLS::Callbacks const size_t max_clients = get_arg_sz("max-clients"); const std::string transport = get_arg("type"); const std::string dump_traces_to = get_arg("dump-traces"); +#if SOCKET_ID + m_socket_id = get_arg_sz("socket-id"); +#endif if(transport != "tcp" && transport != "udp") { @@ -244,6 +257,19 @@ class TLS_Server final : public Command, public Botan::TLS::Callbacks throw CLI_Error("listen failed"); } } + if(m_socket_id > 0) + { +#if SOCKET_ID +// Other oses could have other means to trace sockets +#if defined(SO_USER_COOKIE) + if(::setsockopt(fd, SOL_SOCKET, SO_USER_COOKIE, reinterpret_cast<const void *>(&m_socket_id), sizeof(m_socket_id)) != 0) + { + // Failed but not world-ending issue + output() << "set socket cookie id failed" << std::endl; + } +#endif +#endif + } return fd; } @@ -331,6 +357,7 @@ class TLS_Server final : public Command, public Botan::TLS::Callbacks int m_socket = -1; bool m_is_tcp = false; + uint32_t m_socket_id = 0; std::string m_line_buf; std::list<std::string> m_pending_output; Sandbox m_sandbox; |