net/tls: clean up the number of #ifdefs for CONFIG_TLS_DEVICE
TLS code has a number of #ifdefs which make the code a little harder to follow. Recent fixes removed the ifdef around the TLS_HW define, so we can switch to the often used pattern of defining tls_device functions as empty static inlines in the header when CONFIG_TLS_DEVICE=n. Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com> Reviewed-by: John Hurley <john.hurley@netronome.com> Reviewed-by: Dirk van der Merwe <dirk.vandermerwe@netronome.com> Acked-by: John Fastabend <john.fastabend@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
3544c98acd
commit
be2fbc155f
|
@ -366,13 +366,9 @@ ssize_t tls_sw_splice_read(struct socket *sock, loff_t *ppos,
|
||||||
struct pipe_inode_info *pipe,
|
struct pipe_inode_info *pipe,
|
||||||
size_t len, unsigned int flags);
|
size_t len, unsigned int flags);
|
||||||
|
|
||||||
int tls_set_device_offload(struct sock *sk, struct tls_context *ctx);
|
|
||||||
int tls_device_sendmsg(struct sock *sk, struct msghdr *msg, size_t size);
|
int tls_device_sendmsg(struct sock *sk, struct msghdr *msg, size_t size);
|
||||||
int tls_device_sendpage(struct sock *sk, struct page *page,
|
int tls_device_sendpage(struct sock *sk, struct page *page,
|
||||||
int offset, size_t size, int flags);
|
int offset, size_t size, int flags);
|
||||||
void tls_device_free_resources_tx(struct sock *sk);
|
|
||||||
void tls_device_init(void);
|
|
||||||
void tls_device_cleanup(void);
|
|
||||||
int tls_tx_records(struct sock *sk, int flags);
|
int tls_tx_records(struct sock *sk, int flags);
|
||||||
|
|
||||||
struct tls_record_info *tls_get_record(struct tls_offload_context_tx *context,
|
struct tls_record_info *tls_get_record(struct tls_offload_context_tx *context,
|
||||||
|
@ -649,7 +645,6 @@ int tls_proccess_cmsg(struct sock *sk, struct msghdr *msg,
|
||||||
unsigned char *record_type);
|
unsigned char *record_type);
|
||||||
void tls_register_device(struct tls_device *device);
|
void tls_register_device(struct tls_device *device);
|
||||||
void tls_unregister_device(struct tls_device *device);
|
void tls_unregister_device(struct tls_device *device);
|
||||||
int tls_device_decrypted(struct sock *sk, struct sk_buff *skb);
|
|
||||||
int decrypt_skb(struct sock *sk, struct sk_buff *skb,
|
int decrypt_skb(struct sock *sk, struct sk_buff *skb,
|
||||||
struct scatterlist *sgout);
|
struct scatterlist *sgout);
|
||||||
struct sk_buff *tls_encrypt_skb(struct sk_buff *skb);
|
struct sk_buff *tls_encrypt_skb(struct sk_buff *skb);
|
||||||
|
@ -662,9 +657,40 @@ int tls_sw_fallback_init(struct sock *sk,
|
||||||
struct tls_offload_context_tx *offload_ctx,
|
struct tls_offload_context_tx *offload_ctx,
|
||||||
struct tls_crypto_info *crypto_info);
|
struct tls_crypto_info *crypto_info);
|
||||||
|
|
||||||
|
#ifdef CONFIG_TLS_DEVICE
|
||||||
|
void tls_device_init(void);
|
||||||
|
void tls_device_cleanup(void);
|
||||||
|
int tls_set_device_offload(struct sock *sk, struct tls_context *ctx);
|
||||||
|
void tls_device_free_resources_tx(struct sock *sk);
|
||||||
int tls_set_device_offload_rx(struct sock *sk, struct tls_context *ctx);
|
int tls_set_device_offload_rx(struct sock *sk, struct tls_context *ctx);
|
||||||
|
|
||||||
void tls_device_offload_cleanup_rx(struct sock *sk);
|
void tls_device_offload_cleanup_rx(struct sock *sk);
|
||||||
void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq);
|
void tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq);
|
||||||
|
int tls_device_decrypted(struct sock *sk, struct sk_buff *skb);
|
||||||
|
#else
|
||||||
|
static inline void tls_device_init(void) {}
|
||||||
|
static inline void tls_device_cleanup(void) {}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
tls_set_device_offload(struct sock *sk, struct tls_context *ctx)
|
||||||
|
{
|
||||||
|
return -EOPNOTSUPP;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void tls_device_free_resources_tx(struct sock *sk) {}
|
||||||
|
|
||||||
|
static inline int
|
||||||
|
tls_set_device_offload_rx(struct sock *sk, struct tls_context *ctx)
|
||||||
|
{
|
||||||
|
return -EOPNOTSUPP;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline void tls_device_offload_cleanup_rx(struct sock *sk) {}
|
||||||
|
static inline void
|
||||||
|
tls_device_rx_resync_new_rec(struct sock *sk, u32 rcd_len, u32 seq) {}
|
||||||
|
|
||||||
|
static inline int tls_device_decrypted(struct sock *sk, struct sk_buff *skb)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
#endif /* _TLS_OFFLOAD_H */
|
#endif /* _TLS_OFFLOAD_H */
|
||||||
|
|
|
@ -286,19 +286,14 @@ static void tls_sk_proto_cleanup(struct sock *sk,
|
||||||
kfree(ctx->tx.rec_seq);
|
kfree(ctx->tx.rec_seq);
|
||||||
kfree(ctx->tx.iv);
|
kfree(ctx->tx.iv);
|
||||||
tls_sw_release_resources_tx(sk);
|
tls_sw_release_resources_tx(sk);
|
||||||
#ifdef CONFIG_TLS_DEVICE
|
|
||||||
} else if (ctx->tx_conf == TLS_HW) {
|
} else if (ctx->tx_conf == TLS_HW) {
|
||||||
tls_device_free_resources_tx(sk);
|
tls_device_free_resources_tx(sk);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx->rx_conf == TLS_SW)
|
if (ctx->rx_conf == TLS_SW)
|
||||||
tls_sw_release_resources_rx(sk);
|
tls_sw_release_resources_rx(sk);
|
||||||
|
else if (ctx->rx_conf == TLS_HW)
|
||||||
#ifdef CONFIG_TLS_DEVICE
|
|
||||||
if (ctx->rx_conf == TLS_HW)
|
|
||||||
tls_device_offload_cleanup_rx(sk);
|
tls_device_offload_cleanup_rx(sk);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void tls_sk_proto_close(struct sock *sk, long timeout)
|
static void tls_sk_proto_close(struct sock *sk, long timeout)
|
||||||
|
@ -537,26 +532,18 @@ static int do_tls_setsockopt_conf(struct sock *sk, char __user *optval,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tx) {
|
if (tx) {
|
||||||
#ifdef CONFIG_TLS_DEVICE
|
|
||||||
rc = tls_set_device_offload(sk, ctx);
|
rc = tls_set_device_offload(sk, ctx);
|
||||||
conf = TLS_HW;
|
conf = TLS_HW;
|
||||||
if (rc) {
|
if (rc) {
|
||||||
#else
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
rc = tls_set_sw_offload(sk, ctx, 1);
|
rc = tls_set_sw_offload(sk, ctx, 1);
|
||||||
if (rc)
|
if (rc)
|
||||||
goto err_crypto_info;
|
goto err_crypto_info;
|
||||||
conf = TLS_SW;
|
conf = TLS_SW;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
#ifdef CONFIG_TLS_DEVICE
|
|
||||||
rc = tls_set_device_offload_rx(sk, ctx);
|
rc = tls_set_device_offload_rx(sk, ctx);
|
||||||
conf = TLS_HW;
|
conf = TLS_HW;
|
||||||
if (rc) {
|
if (rc) {
|
||||||
#else
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
rc = tls_set_sw_offload(sk, ctx, 0);
|
rc = tls_set_sw_offload(sk, ctx, 0);
|
||||||
if (rc)
|
if (rc)
|
||||||
goto err_crypto_info;
|
goto err_crypto_info;
|
||||||
|
@ -920,9 +907,7 @@ static int __init tls_register(void)
|
||||||
tls_sw_proto_ops = inet_stream_ops;
|
tls_sw_proto_ops = inet_stream_ops;
|
||||||
tls_sw_proto_ops.splice_read = tls_sw_splice_read;
|
tls_sw_proto_ops.splice_read = tls_sw_splice_read;
|
||||||
|
|
||||||
#ifdef CONFIG_TLS_DEVICE
|
|
||||||
tls_device_init();
|
tls_device_init();
|
||||||
#endif
|
|
||||||
tcp_register_ulp(&tcp_tls_ulp_ops);
|
tcp_register_ulp(&tcp_tls_ulp_ops);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -931,9 +916,7 @@ static int __init tls_register(void)
|
||||||
static void __exit tls_unregister(void)
|
static void __exit tls_unregister(void)
|
||||||
{
|
{
|
||||||
tcp_unregister_ulp(&tcp_tls_ulp_ops);
|
tcp_unregister_ulp(&tcp_tls_ulp_ops);
|
||||||
#ifdef CONFIG_TLS_DEVICE
|
|
||||||
tls_device_cleanup();
|
tls_device_cleanup();
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module_init(tls_register);
|
module_init(tls_register);
|
||||||
|
|
|
@ -1489,13 +1489,12 @@ static int decrypt_skb_update(struct sock *sk, struct sk_buff *skb,
|
||||||
int pad, err = 0;
|
int pad, err = 0;
|
||||||
|
|
||||||
if (!ctx->decrypted) {
|
if (!ctx->decrypted) {
|
||||||
#ifdef CONFIG_TLS_DEVICE
|
|
||||||
if (tls_ctx->rx_conf == TLS_HW) {
|
if (tls_ctx->rx_conf == TLS_HW) {
|
||||||
err = tls_device_decrypted(sk, skb);
|
err = tls_device_decrypted(sk, skb);
|
||||||
if (err < 0)
|
if (err < 0)
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
/* Still not decrypted after tls_device */
|
/* Still not decrypted after tls_device */
|
||||||
if (!ctx->decrypted) {
|
if (!ctx->decrypted) {
|
||||||
err = decrypt_internal(sk, skb, dest, NULL, chunk, zc,
|
err = decrypt_internal(sk, skb, dest, NULL, chunk, zc,
|
||||||
|
@ -2014,10 +2013,9 @@ static int tls_read_size(struct strparser *strp, struct sk_buff *skb)
|
||||||
ret = -EINVAL;
|
ret = -EINVAL;
|
||||||
goto read_failure;
|
goto read_failure;
|
||||||
}
|
}
|
||||||
#ifdef CONFIG_TLS_DEVICE
|
|
||||||
tls_device_rx_resync_new_rec(strp->sk, data_len + TLS_HEADER_SIZE,
|
tls_device_rx_resync_new_rec(strp->sk, data_len + TLS_HEADER_SIZE,
|
||||||
TCP_SKB_CB(skb)->seq + rxm->offset);
|
TCP_SKB_CB(skb)->seq + rxm->offset);
|
||||||
#endif
|
|
||||||
return data_len + TLS_HEADER_SIZE;
|
return data_len + TLS_HEADER_SIZE;
|
||||||
|
|
||||||
read_failure:
|
read_failure:
|
||||||
|
|
Loading…
Reference in New Issue