diff options
author | Atul Gupta <atul.gupta@chelsio.com> | 2019-01-17 23:55:53 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2019-01-22 14:30:54 -0500 |
commit | 63a6b3fee428aeb0288670fc061fa9559b5aca1b (patch) | |
tree | 5316d8b47a4733045ad0d73a3b336a2b0739f7a6 /net/tls/tls_main.c | |
parent | 856c395cfa63b94a1d8215182f0243c222f6f927 (diff) |
net/tls: build_protos moved to common routine
build protos is required for tls_hw_prot also hence moved to
'tls_build_proto' and called as required from tls_init
and tls_hw_proto. This is required since build_protos
for v4 is moved from tls_register to tls_init in
commit <28cb6f1eaffdc5a6a9707cac55f4a43aa3fd7895>
Signed-off-by: Atul Gupta <atul.gupta@chelsio.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/tls/tls_main.c')
-rw-r--r-- | net/tls/tls_main.c | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/net/tls/tls_main.c b/net/tls/tls_main.c index 78cb4a584080..fc97a105ebc2 100644 --- a/net/tls/tls_main.c +++ b/net/tls/tls_main.c | |||
@@ -61,6 +61,8 @@ static LIST_HEAD(device_list); | |||
61 | static DEFINE_SPINLOCK(device_spinlock); | 61 | static DEFINE_SPINLOCK(device_spinlock); |
62 | static struct proto tls_prots[TLS_NUM_PROTS][TLS_NUM_CONFIG][TLS_NUM_CONFIG]; | 62 | static struct proto tls_prots[TLS_NUM_PROTS][TLS_NUM_CONFIG][TLS_NUM_CONFIG]; |
63 | static struct proto_ops tls_sw_proto_ops; | 63 | static struct proto_ops tls_sw_proto_ops; |
64 | static void build_protos(struct proto prot[TLS_NUM_CONFIG][TLS_NUM_CONFIG], | ||
65 | struct proto *base); | ||
64 | 66 | ||
65 | static void update_sk_prot(struct sock *sk, struct tls_context *ctx) | 67 | static void update_sk_prot(struct sock *sk, struct tls_context *ctx) |
66 | { | 68 | { |
@@ -551,6 +553,32 @@ static struct tls_context *create_ctx(struct sock *sk) | |||
551 | return ctx; | 553 | return ctx; |
552 | } | 554 | } |
553 | 555 | ||
556 | static void tls_build_proto(struct sock *sk) | ||
557 | { | ||
558 | int ip_ver = sk->sk_family == AF_INET6 ? TLSV6 : TLSV4; | ||
559 | |||
560 | /* Build IPv6 TLS whenever the address of tcpv6 _prot changes */ | ||
561 | if (ip_ver == TLSV6 && | ||
562 | unlikely(sk->sk_prot != smp_load_acquire(&saved_tcpv6_prot))) { | ||
563 | mutex_lock(&tcpv6_prot_mutex); | ||
564 | if (likely(sk->sk_prot != saved_tcpv6_prot)) { | ||
565 | build_protos(tls_prots[TLSV6], sk->sk_prot); | ||
566 | smp_store_release(&saved_tcpv6_prot, sk->sk_prot); | ||
567 | } | ||
568 | mutex_unlock(&tcpv6_prot_mutex); | ||
569 | } | ||
570 | |||
571 | if (ip_ver == TLSV4 && | ||
572 | unlikely(sk->sk_prot != smp_load_acquire(&saved_tcpv4_prot))) { | ||
573 | mutex_lock(&tcpv4_prot_mutex); | ||
574 | if (likely(sk->sk_prot != saved_tcpv4_prot)) { | ||
575 | build_protos(tls_prots[TLSV4], sk->sk_prot); | ||
576 | smp_store_release(&saved_tcpv4_prot, sk->sk_prot); | ||
577 | } | ||
578 | mutex_unlock(&tcpv4_prot_mutex); | ||
579 | } | ||
580 | } | ||
581 | |||
554 | static int tls_hw_prot(struct sock *sk) | 582 | static int tls_hw_prot(struct sock *sk) |
555 | { | 583 | { |
556 | struct tls_context *ctx; | 584 | struct tls_context *ctx; |
@@ -564,12 +592,15 @@ static int tls_hw_prot(struct sock *sk) | |||
564 | if (!ctx) | 592 | if (!ctx) |
565 | goto out; | 593 | goto out; |
566 | 594 | ||
595 | spin_unlock_bh(&device_spinlock); | ||
596 | tls_build_proto(sk); | ||
567 | ctx->hash = sk->sk_prot->hash; | 597 | ctx->hash = sk->sk_prot->hash; |
568 | ctx->unhash = sk->sk_prot->unhash; | 598 | ctx->unhash = sk->sk_prot->unhash; |
569 | ctx->sk_proto_close = sk->sk_prot->close; | 599 | ctx->sk_proto_close = sk->sk_prot->close; |
570 | ctx->rx_conf = TLS_HW_RECORD; | 600 | ctx->rx_conf = TLS_HW_RECORD; |
571 | ctx->tx_conf = TLS_HW_RECORD; | 601 | ctx->tx_conf = TLS_HW_RECORD; |
572 | update_sk_prot(sk, ctx); | 602 | update_sk_prot(sk, ctx); |
603 | spin_lock_bh(&device_spinlock); | ||
573 | rc = 1; | 604 | rc = 1; |
574 | break; | 605 | break; |
575 | } | 606 | } |
@@ -668,7 +699,6 @@ static void build_protos(struct proto prot[TLS_NUM_CONFIG][TLS_NUM_CONFIG], | |||
668 | 699 | ||
669 | static int tls_init(struct sock *sk) | 700 | static int tls_init(struct sock *sk) |
670 | { | 701 | { |
671 | int ip_ver = sk->sk_family == AF_INET6 ? TLSV6 : TLSV4; | ||
672 | struct tls_context *ctx; | 702 | struct tls_context *ctx; |
673 | int rc = 0; | 703 | int rc = 0; |
674 | 704 | ||
@@ -691,27 +721,7 @@ static int tls_init(struct sock *sk) | |||
691 | goto out; | 721 | goto out; |
692 | } | 722 | } |
693 | 723 | ||
694 | /* Build IPv6 TLS whenever the address of tcpv6 _prot changes */ | 724 | tls_build_proto(sk); |
695 | if (ip_ver == TLSV6 && | ||
696 | unlikely(sk->sk_prot != smp_load_acquire(&saved_tcpv6_prot))) { | ||
697 | mutex_lock(&tcpv6_prot_mutex); | ||
698 | if (likely(sk->sk_prot != saved_tcpv6_prot)) { | ||
699 | build_protos(tls_prots[TLSV6], sk->sk_prot); | ||
700 | smp_store_release(&saved_tcpv6_prot, sk->sk_prot); | ||
701 | } | ||
702 | mutex_unlock(&tcpv6_prot_mutex); | ||
703 | } | ||
704 | |||
705 | if (ip_ver == TLSV4 && | ||
706 | unlikely(sk->sk_prot != smp_load_acquire(&saved_tcpv4_prot))) { | ||
707 | mutex_lock(&tcpv4_prot_mutex); | ||
708 | if (likely(sk->sk_prot != saved_tcpv4_prot)) { | ||
709 | build_protos(tls_prots[TLSV4], sk->sk_prot); | ||
710 | smp_store_release(&saved_tcpv4_prot, sk->sk_prot); | ||
711 | } | ||
712 | mutex_unlock(&tcpv4_prot_mutex); | ||
713 | } | ||
714 | |||
715 | ctx->tx_conf = TLS_BASE; | 725 | ctx->tx_conf = TLS_BASE; |
716 | ctx->rx_conf = TLS_BASE; | 726 | ctx->rx_conf = TLS_BASE; |
717 | update_sk_prot(sk, ctx); | 727 | update_sk_prot(sk, ctx); |