From e15c0118b0cff08d444d51153300e20869cc323f Mon Sep 17 00:00:00 2001 From: Susan Hinrichs Date: Thu, 31 Aug 2023 20:26:51 +0000 Subject: [PATCH 1/3] Add TSVConnSslFdGet api --- .../api/functions/TSVConnSslFdGet.en.rst | 34 +++++++++++++++++++ include/ts/ts.h | 2 ++ src/traffic_server/InkAPI.cc | 14 ++++++++ 3 files changed, 50 insertions(+) create mode 100644 doc/developer-guide/api/functions/TSVConnSslFdGet.en.rst diff --git a/doc/developer-guide/api/functions/TSVConnSslFdGet.en.rst b/doc/developer-guide/api/functions/TSVConnSslFdGet.en.rst new file mode 100644 index 00000000000..dec27794276 --- /dev/null +++ b/doc/developer-guide/api/functions/TSVConnSslFdGet.en.rst @@ -0,0 +1,34 @@ +.. Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed + with this work for additional information regarding copyright + ownership. The ASF licenses this file to you 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. + + +TSVConnSslFdGet +=============== + +Synopsis +-------- + +.. code-block:: cpp + + #include + +.. c:function:: int TSVConnSslFdGet(TSVConn sslp) + + +Description +----------- +Returns the file descriptor associated with the SSL connection :arg:`sslp`. +It returns -1 on error. diff --git a/include/ts/ts.h b/include/ts/ts.h index 3191f236173..94312d041d3 100644 --- a/include/ts/ts.h +++ b/include/ts/ts.h @@ -1315,6 +1315,8 @@ namespace c TSReturnCode TSVConnTunnel(TSVConn sslp); /* Return the SSL object associated with the connection */ TSSslConnection TSVConnSslConnectionGet(TSVConn sslp); + /* Return the file descriptoer associated with the ssl connection */ + int TSVConnSslFdGet(TSVConn sslp); /* Return the intermediate X509StoreCTX object that references the certificate being validated */ TSSslVerifyCTX TSVConnSslVerifyCTXGet(TSVConn sslp); /* Fetch a SSL context from the global lookup table */ diff --git a/src/traffic_server/InkAPI.cc b/src/traffic_server/InkAPI.cc index 035aaa64823..f5575e48c60 100644 --- a/src/traffic_server/InkAPI.cc +++ b/src/traffic_server/InkAPI.cc @@ -9132,6 +9132,20 @@ tsapi::c::TSVConnSslConnectionGet(TSVConn sslp) return ssl; } +int +tsapi::c::TSVConnSslFdGet(TSVConn sslp) +{ + TSSslConnection sslvc = TSVConnSslConnectionGet(sslp); + int fd = -1; + if (sslvc != nullptr) { + SSL *sslObj = reinterpret_cast(sslvc); + if (sslObj != nullptr) { + fd = SSL_get_wfd(sslObj); + } + } + return fd; +} + const char * tsapi::c::TSVConnSslSniGet(TSVConn sslp, int *length) { From a306a2e646b00e26df82966ee738e7cbe7daa652 Mon Sep 17 00:00:00 2001 From: Susan Hinrichs Date: Wed, 6 Sep 2023 20:01:10 +0000 Subject: [PATCH 2/3] Generalize the FdGet() call --- ...SVConnSslFdGet.en.rst => TSVConnFdGet.en.rst} | 8 ++++---- include/ts/ts.h | 2 +- src/traffic_server/InkAPI.cc | 16 ++++++---------- 3 files changed, 11 insertions(+), 15 deletions(-) rename doc/developer-guide/api/functions/{TSVConnSslFdGet.en.rst => TSVConnFdGet.en.rst} (85%) diff --git a/doc/developer-guide/api/functions/TSVConnSslFdGet.en.rst b/doc/developer-guide/api/functions/TSVConnFdGet.en.rst similarity index 85% rename from doc/developer-guide/api/functions/TSVConnSslFdGet.en.rst rename to doc/developer-guide/api/functions/TSVConnFdGet.en.rst index dec27794276..7e5a808115f 100644 --- a/doc/developer-guide/api/functions/TSVConnSslFdGet.en.rst +++ b/doc/developer-guide/api/functions/TSVConnFdGet.en.rst @@ -15,8 +15,8 @@ permissions and limitations under the License. -TSVConnSslFdGet -=============== +TSVConnFdGet +============ Synopsis -------- @@ -25,10 +25,10 @@ Synopsis #include -.. c:function:: int TSVConnSslFdGet(TSVConn sslp) +.. c:function:: int TSVConnFdGet(TSVConn vconnp) Description ----------- -Returns the file descriptor associated with the SSL connection :arg:`sslp`. +Returns the file descriptor associated with the network connection :arg:`sslp`. It returns -1 on error. diff --git a/include/ts/ts.h b/include/ts/ts.h index 94312d041d3..9c3ab8e2fdf 100644 --- a/include/ts/ts.h +++ b/include/ts/ts.h @@ -1316,7 +1316,7 @@ namespace c /* Return the SSL object associated with the connection */ TSSslConnection TSVConnSslConnectionGet(TSVConn sslp); /* Return the file descriptoer associated with the ssl connection */ - int TSVConnSslFdGet(TSVConn sslp); + int TSVConnFdGet(TSVConn sslp); /* Return the intermediate X509StoreCTX object that references the certificate being validated */ TSSslVerifyCTX TSVConnSslVerifyCTXGet(TSVConn sslp); /* Fetch a SSL context from the global lookup table */ diff --git a/src/traffic_server/InkAPI.cc b/src/traffic_server/InkAPI.cc index f5575e48c60..c1421b8ae83 100644 --- a/src/traffic_server/InkAPI.cc +++ b/src/traffic_server/InkAPI.cc @@ -9133,17 +9133,13 @@ tsapi::c::TSVConnSslConnectionGet(TSVConn sslp) } int -tsapi::c::TSVConnSslFdGet(TSVConn sslp) -{ - TSSslConnection sslvc = TSVConnSslConnectionGet(sslp); - int fd = -1; - if (sslvc != nullptr) { - SSL *sslObj = reinterpret_cast(sslvc); - if (sslObj != nullptr) { - fd = SSL_get_wfd(sslObj); - } +tsapi::c::TSVConnFdGet(TSVConn vconnp) +{ + NetVConnection *vc = reinterpret_cast(vconnp); + if (vc != nullptr) { + return vc->get_socket(); } - return fd; + return -1; } const char * From eb65c1c8d130b3fd492028e8ed424f9e8798f613 Mon Sep 17 00:00:00 2001 From: Susan Hinrichs Date: Mon, 11 Sep 2023 19:18:44 +0000 Subject: [PATCH 3/3] Address comments --- include/ts/ts.h | 2 +- src/traffic_server/InkAPI.cc | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/include/ts/ts.h b/include/ts/ts.h index 9c3ab8e2fdf..6d94342a2d6 100644 --- a/include/ts/ts.h +++ b/include/ts/ts.h @@ -1315,7 +1315,7 @@ namespace c TSReturnCode TSVConnTunnel(TSVConn sslp); /* Return the SSL object associated with the connection */ TSSslConnection TSVConnSslConnectionGet(TSVConn sslp); - /* Return the file descriptoer associated with the ssl connection */ + /* Return the file descriptoer associated with the connection */ int TSVConnFdGet(TSVConn sslp); /* Return the intermediate X509StoreCTX object that references the certificate being validated */ TSSslVerifyCTX TSVConnSslVerifyCTXGet(TSVConn sslp); diff --git a/src/traffic_server/InkAPI.cc b/src/traffic_server/InkAPI.cc index c1421b8ae83..a4ab9709fba 100644 --- a/src/traffic_server/InkAPI.cc +++ b/src/traffic_server/InkAPI.cc @@ -9135,11 +9135,9 @@ tsapi::c::TSVConnSslConnectionGet(TSVConn sslp) int tsapi::c::TSVConnFdGet(TSVConn vconnp) { + sdk_assert(sdk_sanity_check_null_ptr(vconnp) == TS_SUCCESS); NetVConnection *vc = reinterpret_cast(vconnp); - if (vc != nullptr) { - return vc->get_socket(); - } - return -1; + return vc->get_socket(); } const char *