From: Atul Gupta <atul.gupta@chelsio.com>
To: davejwatson@fb.com, davem@davemloft.net, herbert@gondor.apana.org.au
Cc: linux-crypto@vger.kernel.org, netdev@vger.kernel.org,
ganeshgr@chelsio.com
Subject: [crypto v8 03/12] tls: support for inline tls
Date: Thu, 1 Mar 2018 11:19:34 +0530 [thread overview]
Message-ID: <1519883383-4911-3-git-send-email-atul.gupta@chelsio.com> (raw)
In-Reply-To: <1519883383-4911-1-git-send-email-atul.gupta@chelsio.com>
Facility to register Inline TLS drivers to net/tls. Setup
TLS_FULL_HW prot to listen on offload device.
Cases handled
1. Inline TLS device exists, setup prot for TLS_FULL_HW
2. Atleast one Inline TLS exists, sets TLS_FULL_HW. If
non-inline capable device establish connection move to TLS_SW_TX
Signed-off-by: Atul Gupta <atul.gupta@chelsio.com>
---
net/tls/tls_main.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 80 insertions(+), 7 deletions(-)
diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c
index b0d5fce..2ac9510 100644
--- a/net/tls/tls_main.c
+++ b/net/tls/tls_main.c
@@ -38,6 +38,7 @@
#include <linux/highmem.h>
#include <linux/netdevice.h>
#include <linux/sched/signal.h>
+#include <linux/inetdevice.h>
#include <net/tls.h>
@@ -45,13 +46,9 @@
MODULE_DESCRIPTION("Transport Layer Security Support");
MODULE_LICENSE("Dual BSD/GPL");
-enum {
- TLS_BASE_TX,
- TLS_SW_TX,
- TLS_NUM_CONFIG,
-};
-
-static struct proto tls_prots[TLS_NUM_CONFIG];
+static LIST_HEAD(device_list);
+static DEFINE_MUTEX(device_mutex);
+struct proto tls_prots[TLS_NUM_CONFIG];
static inline void update_sk_prot(struct sock *sk, struct tls_context *ctx)
{
@@ -450,6 +447,58 @@ static int tls_setsockopt(struct sock *sk, int level, int optname,
return do_tls_setsockopt(sk, optname, optval, optlen);
}
+static int tls_hw_prot(struct sock *sk)
+{
+ struct tls_context *ctx = tls_get_ctx(sk);
+ struct tls_device *dev;
+
+ mutex_lock(&device_mutex);
+ list_for_each_entry(dev, &device_list, dev_list) {
+ if (dev->feature && dev->feature(dev)) {
+ ctx->hash = sk->sk_prot->hash;
+ ctx->unhash = sk->sk_prot->unhash;
+ ctx->tx_conf = TLS_FULL_HW;
+ update_sk_prot(sk, ctx);
+ break;
+ }
+ }
+ mutex_unlock(&device_mutex);
+ return ctx->tx_conf;
+}
+
+static void tls_hw_unhash(struct sock *sk)
+{
+ struct tls_context *ctx = tls_get_ctx(sk);
+ struct tls_device *dev;
+
+ mutex_lock(&device_mutex);
+ list_for_each_entry(dev, &device_list, dev_list) {
+ if (dev->unhash)
+ dev->unhash(dev, sk);
+ }
+ mutex_unlock(&device_mutex);
+ ctx->unhash(sk);
+}
+
+static int tls_hw_hash(struct sock *sk)
+{
+ struct tls_context *ctx = tls_get_ctx(sk);
+ struct tls_device *dev;
+ int err;
+
+ err = ctx->hash(sk);
+ mutex_lock(&device_mutex);
+ list_for_each_entry(dev, &device_list, dev_list) {
+ if (dev->hash)
+ err |= dev->hash(dev, sk);
+ }
+ mutex_unlock(&device_mutex);
+
+ if (err)
+ tls_hw_unhash(sk);
+ return err;
+}
+
static int tls_init(struct sock *sk)
{
struct inet_connection_sock *icsk = inet_csk(sk);
@@ -477,6 +526,9 @@ static int tls_init(struct sock *sk)
ctx->sk_proto_close = sk->sk_prot->close;
ctx->tx_conf = TLS_BASE_TX;
+ if (tls_hw_prot(sk) == TLS_FULL_HW)
+ goto out;
+
update_sk_prot(sk, ctx);
out:
return rc;
@@ -500,7 +552,27 @@ static void build_protos(struct proto *prot, struct proto *base)
prot[TLS_SW_TX] = prot[TLS_BASE_TX];
prot[TLS_SW_TX].sendmsg = tls_sw_sendmsg;
prot[TLS_SW_TX].sendpage = tls_sw_sendpage;
+
+ prot[TLS_FULL_HW] = prot[TLS_BASE_TX];
+ prot[TLS_FULL_HW].hash = tls_hw_hash;
+ prot[TLS_FULL_HW].unhash = tls_hw_unhash;
+}
+
+void tls_register_device(struct tls_device *device)
+{
+ mutex_lock(&device_mutex);
+ list_add_tail(&device->dev_list, &device_list);
+ mutex_unlock(&device_mutex);
+}
+EXPORT_SYMBOL(tls_register_device);
+
+void tls_unregister_device(struct tls_device *device)
+{
+ mutex_lock(&device_mutex);
+ list_del(&device->dev_list);
+ mutex_unlock(&device_mutex);
}
+EXPORT_SYMBOL(tls_unregister_device);
static int __init tls_register(void)
{
@@ -510,6 +582,7 @@ static int __init tls_register(void)
return 0;
}
+EXPORT_SYMBOL(tls_prots);
static void __exit tls_unregister(void)
{
--
1.8.3.1
next prev parent reply other threads:[~2018-03-01 5:50 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-01 5:49 [crypto v8 01/12] tls: tls_device struct to register TLS drivers Atul Gupta
2018-03-01 5:49 ` [crypto v8 02/12] ethtool: enable Inline TLS in HW Atul Gupta
2018-03-01 5:49 ` Atul Gupta [this message]
2018-03-01 5:49 ` [crypto v8 04/12] chtls: structure and macro definiton Atul Gupta
2018-03-04 19:45 ` David Miller
2018-03-01 5:49 ` [crypto v8 05/12] cxgb4: Inline TLS FW Interface Atul Gupta
2018-03-01 5:49 ` [crypto v8 06/12] cxgb4: LLD driver changes to enable TLS Atul Gupta
2018-03-01 5:49 ` [crypto v8 07/12] chcr: Key Macro Atul Gupta
2018-03-01 5:49 ` [crypto v8 08/12] chtls: Key program Atul Gupta
2018-03-01 5:49 ` [crypto v8 09/12] chtls: CPL handler definition Atul Gupta
2018-03-01 5:49 ` [crypto v8 10/12] chtls: Inline crypto request Tx/Rx Atul Gupta
2018-03-01 5:49 ` [crypto v8 11/12] chtls: Register chtls Inline TLS with net tls Atul Gupta
2018-03-01 5:49 ` [crypto v8 12/12] Makefile Kconfig Atul Gupta
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1519883383-4911-3-git-send-email-atul.gupta@chelsio.com \
--to=atul.gupta@chelsio.com \
--cc=davejwatson@fb.com \
--cc=davem@davemloft.net \
--cc=ganeshgr@chelsio.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-crypto@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).