Skip to content

Commit 9f06f87

Browse files
kuba-moodavem330
authored andcommitted
net: skbuff: generalize the skb->decrypted bit
The ->decrypted bit can be reused for other crypto protocols. Remove the direct dependency on TLS, add helpers to clean up the ifdefs leaking out everywhere. Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: David Ahern <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 0d875bb commit 9f06f87

File tree

8 files changed

+24
-24
lines changed

8 files changed

+24
-24
lines changed

include/linux/skbuff.h

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ struct sk_buff {
992992
#ifdef CONFIG_NETFILTER_SKIP_EGRESS
993993
__u8 nf_skip_egress:1;
994994
#endif
995-
#ifdef CONFIG_TLS_DEVICE
995+
#ifdef CONFIG_SKB_DECRYPTED
996996
__u8 decrypted:1;
997997
#endif
998998
__u8 slow_gro:1;
@@ -1615,17 +1615,26 @@ static inline void skb_copy_hash(struct sk_buff *to, const struct sk_buff *from)
16151615
static inline int skb_cmp_decrypted(const struct sk_buff *skb1,
16161616
const struct sk_buff *skb2)
16171617
{
1618-
#ifdef CONFIG_TLS_DEVICE
1618+
#ifdef CONFIG_SKB_DECRYPTED
16191619
return skb2->decrypted - skb1->decrypted;
16201620
#else
16211621
return 0;
16221622
#endif
16231623
}
16241624

1625+
static inline bool skb_is_decrypted(const struct sk_buff *skb)
1626+
{
1627+
#ifdef CONFIG_SKB_DECRYPTED
1628+
return skb->decrypted;
1629+
#else
1630+
return false;
1631+
#endif
1632+
}
1633+
16251634
static inline void skb_copy_decrypted(struct sk_buff *to,
16261635
const struct sk_buff *from)
16271636
{
1628-
#ifdef CONFIG_TLS_DEVICE
1637+
#ifdef CONFIG_SKB_DECRYPTED
16291638
to->decrypted = from->decrypted;
16301639
#endif
16311640
}

include/net/sock.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2835,12 +2835,10 @@ static inline struct sk_buff *sk_validate_xmit_skb(struct sk_buff *skb,
28352835

28362836
if (sk && sk_fullsock(sk) && sk->sk_validate_xmit_skb) {
28372837
skb = sk->sk_validate_xmit_skb(sk, dev, skb);
2838-
#ifdef CONFIG_TLS_DEVICE
2839-
} else if (unlikely(skb->decrypted)) {
2838+
} else if (unlikely(skb_is_decrypted(skb))) {
28402839
pr_warn_ratelimited("unencrypted skb with no associated socket - dropping\n");
28412840
kfree_skb(skb);
28422841
skb = NULL;
2843-
#endif
28442842
}
28452843
#endif
28462844

net/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ config NET_XGRESS
6060
config NET_REDIRECT
6161
bool
6262

63+
config SKB_DECRYPTED
64+
bool
65+
6366
config SKB_EXTENSIONS
6467
bool
6568

net/core/sock.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2526,13 +2526,12 @@ EXPORT_SYMBOL(skb_set_owner_w);
25262526

25272527
static bool can_skb_orphan_partial(const struct sk_buff *skb)
25282528
{
2529-
#ifdef CONFIG_TLS_DEVICE
25302529
/* Drivers depend on in-order delivery for crypto offload,
25312530
* partial orphan breaks out-of-order-OK logic.
25322531
*/
2533-
if (skb->decrypted)
2532+
if (skb_is_decrypted(skb))
25342533
return false;
2535-
#endif
2534+
25362535
return (skb->destructor == sock_wfree ||
25372536
(IS_ENABLED(CONFIG_INET) && skb->destructor == tcp_wfree));
25382537
}

net/ipv4/tcp_input.c

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4805,10 +4805,8 @@ static bool tcp_try_coalesce(struct sock *sk,
48054805
if (!mptcp_skb_can_collapse(to, from))
48064806
return false;
48074807

4808-
#ifdef CONFIG_TLS_DEVICE
4809-
if (from->decrypted != to->decrypted)
4808+
if (skb_cmp_decrypted(from, to))
48104809
return false;
4811-
#endif
48124810

48134811
if (!skb_try_coalesce(to, from, fragstolen, &delta))
48144812
return false;
@@ -5377,9 +5375,7 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root,
53775375
break;
53785376

53795377
memcpy(nskb->cb, skb->cb, sizeof(skb->cb));
5380-
#ifdef CONFIG_TLS_DEVICE
5381-
nskb->decrypted = skb->decrypted;
5382-
#endif
5378+
skb_copy_decrypted(nskb, skb);
53835379
TCP_SKB_CB(nskb)->seq = TCP_SKB_CB(nskb)->end_seq = start;
53845380
if (list)
53855381
__skb_queue_before(list, skb, nskb);
@@ -5409,10 +5405,8 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root,
54095405
!mptcp_skb_can_collapse(nskb, skb) ||
54105406
(TCP_SKB_CB(skb)->tcp_flags & (TCPHDR_SYN | TCPHDR_FIN)))
54115407
goto end;
5412-
#ifdef CONFIG_TLS_DEVICE
5413-
if (skb->decrypted != nskb->decrypted)
5408+
if (skb_cmp_decrypted(skb, nskb))
54145409
goto end;
5415-
#endif
54165410
}
54175411
}
54185412
}

net/ipv4/tcp_ipv4.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2044,10 +2044,8 @@ bool tcp_add_backlog(struct sock *sk, struct sk_buff *skb,
20442044
TCP_SKB_CB(skb)->tcp_flags) & TCPHDR_ACK) ||
20452045
((TCP_SKB_CB(tail)->tcp_flags ^
20462046
TCP_SKB_CB(skb)->tcp_flags) & (TCPHDR_ECE | TCPHDR_CWR)) ||
2047-
#ifdef CONFIG_TLS_DEVICE
2048-
tail->decrypted != skb->decrypted ||
2049-
#endif
20502047
!mptcp_skb_can_collapse(tail, skb) ||
2048+
skb_cmp_decrypted(tail, skb) ||
20512049
thtail->doff != th->doff ||
20522050
memcmp(thtail + 1, th + 1, hdrlen - sizeof(*th)))
20532051
goto no_coalesce;

net/ipv4/tcp_offload.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,7 @@ struct sk_buff *tcp_gro_receive(struct list_head *head, struct sk_buff *skb)
265265
flush |= (len - 1) >= mss;
266266

267267
flush |= (ntohl(th2->seq) + skb_gro_len(p)) ^ ntohl(th->seq);
268-
#ifdef CONFIG_TLS_DEVICE
269-
flush |= p->decrypted ^ skb->decrypted;
270-
#endif
268+
flush |= skb_cmp_decrypted(p, skb);
271269

272270
if (flush || skb_gro_receive(p, skb)) {
273271
mss = 1;

net/tls/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ config TLS
2020
config TLS_DEVICE
2121
bool "Transport Layer Security HW offload"
2222
depends on TLS
23+
select SKB_DECRYPTED
2324
select SOCK_VALIDATE_XMIT
2425
select SOCK_RX_QUEUE_MAPPING
2526
default n

0 commit comments

Comments
 (0)