All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] skb: make drop reason booleanable
@ 2022-03-04  4:53 Jakub Kicinski
  2022-03-04  5:22 ` Jakub Kicinski
  0 siblings, 1 reply; 9+ messages in thread
From: Jakub Kicinski @ 2022-03-04  4:53 UTC (permalink / raw)
  To: davem; +Cc: netdev, edumazet, dsahern, menglong8.dong, Jakub Kicinski

We have a number of cases where function returns drop/no drop
decision as a boolean. Now that we want to report the reason
code as well we have to pass extra output arguments.

We can make the reason code evaluate correctly as bool.

I believe we're good to reorder the reasons as they are
reported to user space as strings.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
This patch implements what I suggested in review at some
point but which was not implemented. IDK if it wasn't
understood or the idea is bad?
---
 include/linux/skbuff.h |  1 +
 include/net/tcp.h      | 21 +++++++++++----------
 net/ipv4/tcp.c         | 21 +++++++++------------
 net/ipv4/tcp_ipv4.c    | 12 +++++++-----
 net/ipv6/tcp_ipv6.c    | 11 +++++++----
 5 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 5445860e1ba6..b8e0652c0fb0 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -314,6 +314,7 @@ struct sk_buff;
  * used to translate the reason to string.
  */
 enum skb_drop_reason {
+	SKB_OKAY = 0,
 	SKB_DROP_REASON_NOT_SPECIFIED,	/* drop reason is not specified */
 	SKB_DROP_REASON_NO_SOCKET,	/* socket not found */
 	SKB_DROP_REASON_PKT_TOO_SMALL,	/* packet size is too small */
diff --git a/include/net/tcp.h b/include/net/tcp.h
index d486d7b6112d..467ed2dd32c9 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1674,10 +1674,11 @@ tcp_md5_do_lookup(const struct sock *sk, int l3index,
 		return NULL;
 	return __tcp_md5_do_lookup(sk, l3index, addr, family);
 }
-bool tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
-			  enum skb_drop_reason *reason,
-			  const void *saddr, const void *daddr,
-			  int family, int dif, int sdif);
+
+enum skb_drop_reason
+tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
+		     const void *saddr, const void *daddr,
+		     int family, int dif, int sdif);
 
 
 #define tcp_twsk_md5_key(twsk)	((twsk)->tw_md5_key)
@@ -1688,13 +1689,13 @@ tcp_md5_do_lookup(const struct sock *sk, int l3index,
 {
 	return NULL;
 }
-static inline bool tcp_inbound_md5_hash(const struct sock *sk,
-					const struct sk_buff *skb,
-					enum skb_drop_reason *reason,
-					const void *saddr, const void *daddr,
-					int family, int dif, int sdif)
+
+static inline enum skb_drop_reason
+tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
+		     const void *saddr, const void *daddr,
+		     int family, int dif, int sdif);
 {
-	return false;
+	return __SKB_OKAY;
 }
 #define tcp_twsk_md5_key(twsk)	NULL
 #endif
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 68f1236b2858..33e9e1e4d041 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -4432,10 +4432,10 @@ int tcp_md5_hash_key(struct tcp_md5sig_pool *hp, const struct tcp_md5sig_key *ke
 EXPORT_SYMBOL(tcp_md5_hash_key);
 
 /* Called with rcu_read_lock() */
-bool tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
-			  enum skb_drop_reason *reason,
-			  const void *saddr, const void *daddr,
-			  int family, int dif, int sdif)
+enum skb_drop_reason
+tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
+		     const void *saddr, const void *daddr,
+		     int family, int dif, int sdif)
 {
 	/*
 	 * This gets called for each TCP segment that arrives
@@ -4462,18 +4462,16 @@ bool tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
 
 	/* We've parsed the options - do we have a hash? */
 	if (!hash_expected && !hash_location)
-		return false;
+		return SKB_OKAY;
 
 	if (hash_expected && !hash_location) {
-		*reason = SKB_DROP_REASON_TCP_MD5NOTFOUND;
 		NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5NOTFOUND);
-		return true;
+		return SKB_DROP_REASON_TCP_MD5NOTFOUND;
 	}
 
 	if (!hash_expected && hash_location) {
-		*reason = SKB_DROP_REASON_TCP_MD5UNEXPECTED;
 		NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5UNEXPECTED);
-		return true;
+		return SKB_DROP_REASON_TCP_MD5UNEXPECTED;
 	}
 
 	/* check the signature */
@@ -4481,7 +4479,6 @@ bool tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
 						 NULL, skb);
 
 	if (genhash || memcmp(hash_location, newhash, 16) != 0) {
-		*reason = SKB_DROP_REASON_TCP_MD5FAILURE;
 		NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5FAILURE);
 		if (family == AF_INET) {
 			net_info_ratelimited("MD5 Hash failed for (%pI4, %d)->(%pI4, %d)%s L3 index %d\n",
@@ -4495,9 +4492,9 @@ bool tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
 					saddr, ntohs(th->source),
 					daddr, ntohs(th->dest), l3index);
 		}
-		return true;
+		return SKB_DROP_REASON_TCP_MD5FAILURE;
 	}
-	return false;
+	return SKB_OKAY;
 }
 EXPORT_SYMBOL(tcp_inbound_md5_hash);
 
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 411357ad9757..81694a354110 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1965,9 +1965,10 @@ int tcp_v4_rcv(struct sk_buff *skb)
 		struct sock *nsk;
 
 		sk = req->rsk_listener;
-		if (unlikely(tcp_inbound_md5_hash(sk, skb, &drop_reason,
-						  &iph->saddr, &iph->daddr,
-						  AF_INET, dif, sdif))) {
+		drop_reason = tcp_inbound_md5_hash(sk, skb,
+						   &iph->saddr, &iph->daddr,
+						   AF_INET, dif, sdif);
+		if (unlikely(drop_reason)) {
 			sk_drops_add(sk, skb);
 			reqsk_put(req);
 			goto discard_it;
@@ -2041,8 +2042,9 @@ int tcp_v4_rcv(struct sk_buff *skb)
 		goto discard_and_relse;
 	}
 
-	if (tcp_inbound_md5_hash(sk, skb, &drop_reason, &iph->saddr,
-				 &iph->daddr, AF_INET, dif, sdif))
+	drop_reason = tcp_inbound_md5_hash(sk, skb, &iph->saddr,
+					   &iph->daddr, AF_INET, dif, sdif);
+	if (drop_reason)
 		goto discard_and_relse;
 
 	nf_reset_ct(skb);
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index cb2bb7d2e907..13678d3908fa 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -1632,8 +1632,10 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
 		struct sock *nsk;
 
 		sk = req->rsk_listener;
-		if (tcp_inbound_md5_hash(sk, skb, &drop_reason, &hdr->saddr,
-					 &hdr->daddr, AF_INET6, dif, sdif)) {
+		drop_reason = tcp_inbound_md5_hash(sk, skb,
+						   &hdr->saddr, &hdr->daddr,
+						   AF_INET6, dif, sdif);
+		if (drop_reason) {
 			sk_drops_add(sk, skb);
 			reqsk_put(req);
 			goto discard_it;
@@ -1704,8 +1706,9 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
 		goto discard_and_relse;
 	}
 
-	if (tcp_inbound_md5_hash(sk, skb, &drop_reason, &hdr->saddr,
-				 &hdr->daddr, AF_INET6, dif, sdif))
+	drop_reason = tcp_inbound_md5_hash(sk, skb, &hdr->saddr, &hdr->daddr,
+					   AF_INET6, dif, sdif);
+	if (drop_reason)
 		goto discard_and_relse;
 
 	if (tcp_filter(sk, skb)) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next] skb: make drop reason booleanable
  2022-03-04  4:53 [PATCH net-next] skb: make drop reason booleanable Jakub Kicinski
@ 2022-03-04  5:22 ` Jakub Kicinski
  2022-03-04  6:37   ` Eric Dumazet
  0 siblings, 1 reply; 9+ messages in thread
From: Jakub Kicinski @ 2022-03-04  5:22 UTC (permalink / raw)
  To: davem; +Cc: netdev, edumazet, dsahern, menglong8.dong

On Thu,  3 Mar 2022 20:53:53 -0800 Jakub Kicinski wrote:
> -	return false;
> +	return __SKB_OKAY;

s/__//

I'll send a v2 if I get acks / positive feedback.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next] skb: make drop reason booleanable
  2022-03-04  5:22 ` Jakub Kicinski
@ 2022-03-04  6:37   ` Eric Dumazet
  2022-03-04 15:31     ` David Ahern
  0 siblings, 1 reply; 9+ messages in thread
From: Eric Dumazet @ 2022-03-04  6:37 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: David Miller, netdev, David Ahern, Menglong Dong

On Thu, Mar 3, 2022 at 9:22 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Thu,  3 Mar 2022 20:53:53 -0800 Jakub Kicinski wrote:
> > -     return false;
> > +     return __SKB_OKAY;
>
> s/__//
>
> I'll send a v2 if I get acks / positive feedback.


I am not a big fan of SKB_OKAY ?

Maybe SKB_NOT_DROPPED_YET, or SKB_VALID_SO_FAR.

Oh well, I am not good at names.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next] skb: make drop reason booleanable
  2022-03-04  6:37   ` Eric Dumazet
@ 2022-03-04 15:31     ` David Ahern
  2022-03-04 16:36       ` Eric Dumazet
  0 siblings, 1 reply; 9+ messages in thread
From: David Ahern @ 2022-03-04 15:31 UTC (permalink / raw)
  To: Eric Dumazet, Jakub Kicinski; +Cc: David Miller, netdev, Menglong Dong

On 3/3/22 11:37 PM, Eric Dumazet wrote:
> On Thu, Mar 3, 2022 at 9:22 PM Jakub Kicinski <kuba@kernel.org> wrote:
>>
>> On Thu,  3 Mar 2022 20:53:53 -0800 Jakub Kicinski wrote:
>>> -     return false;
>>> +     return __SKB_OKAY;
>>
>> s/__//
>>
>> I'll send a v2 if I get acks / positive feedback.
> 
> 
> I am not a big fan of SKB_OKAY ?
> 
> Maybe SKB_NOT_DROPPED_YET, or SKB_VALID_SO_FAR.
> 
> Oh well, I am not good at names.

SKB_DROP_EXPECTED or SKB_DROP_NORMAL? That said I thought consume_skb is
for normal, release path and then kfree_skb is when an skb is dropped
for unexpected reasons.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next] skb: make drop reason booleanable
  2022-03-04 15:31     ` David Ahern
@ 2022-03-04 16:36       ` Eric Dumazet
  0 siblings, 0 replies; 9+ messages in thread
From: Eric Dumazet @ 2022-03-04 16:36 UTC (permalink / raw)
  To: David Ahern; +Cc: Jakub Kicinski, David Miller, netdev, Menglong Dong

On Fri, Mar 4, 2022 at 7:31 AM David Ahern <dsahern@gmail.com> wrote:
>
> On 3/3/22 11:37 PM, Eric Dumazet wrote:
> > On Thu, Mar 3, 2022 at 9:22 PM Jakub Kicinski <kuba@kernel.org> wrote:
> >>
> >> On Thu,  3 Mar 2022 20:53:53 -0800 Jakub Kicinski wrote:
> >>> -     return false;
> >>> +     return __SKB_OKAY;
> >>
> >> s/__//
> >>
> >> I'll send a v2 if I get acks / positive feedback.
> >
> >
> > I am not a big fan of SKB_OKAY ?
> >
> > Maybe SKB_NOT_DROPPED_YET, or SKB_VALID_SO_FAR.
> >
> > Oh well, I am not good at names.
>
> SKB_DROP_EXPECTED or SKB_DROP_NORMAL? That said I thought consume_skb is
> for normal, release path and then kfree_skb is when an skb is dropped
> for unexpected reasons.

Jakub wanted to use a special value in the enum, so that md5 function
can return this value to tell to the caller :
(To remove the extra "enum skb_drop_reason *reason" parameter  )

    "Please proceed with this packet, md5 layer found nothing wrong with it."

Other TCP checks need to apply after this, we do not know yet if skb
is going to be dropped or consumed.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next] skb: make drop reason booleanable
  2022-03-08  0:44 Jakub Kicinski
  2022-03-08 13:57 ` Toke Høiland-Jørgensen
  2022-03-08 16:35 ` David Ahern
@ 2022-03-09 11:30 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 9+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-03-09 11:30 UTC (permalink / raw)
  To: Jakub Kicinski; +Cc: davem, netdev, edumazet, dsahern

Hello:

This patch was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:

On Mon,  7 Mar 2022 16:44:21 -0800 you wrote:
> We have a number of cases where function returns drop/no drop
> decision as a boolean. Now that we want to report the reason
> code as well we have to pass extra output arguments.
> 
> We can make the reason code evaluate correctly as bool.
> 
> I believe we're good to reorder the reasons as they are
> reported to user space as strings.
> 
> [...]

Here is the summary with links:
  - [net-next] skb: make drop reason booleanable
    https://git.kernel.org/netdev/net-next/c/1330b6ef3313

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next] skb: make drop reason booleanable
  2022-03-08  0:44 Jakub Kicinski
  2022-03-08 13:57 ` Toke Høiland-Jørgensen
@ 2022-03-08 16:35 ` David Ahern
  2022-03-09 11:30 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 9+ messages in thread
From: David Ahern @ 2022-03-08 16:35 UTC (permalink / raw)
  To: Jakub Kicinski, davem; +Cc: netdev, edumazet

On 3/7/22 5:44 PM, Jakub Kicinski wrote:
> We have a number of cases where function returns drop/no drop
> decision as a boolean. Now that we want to report the reason
> code as well we have to pass extra output arguments.
> 
> We can make the reason code evaluate correctly as bool.
> 
> I believe we're good to reorder the reasons as they are
> reported to user space as strings.
> 
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> v2: use Eric's suggestion for the name, indeed better than mine
> ---
>  include/linux/skbuff.h |  1 +
>  include/net/tcp.h      | 21 +++++++++++----------
>  net/ipv4/tcp.c         | 21 +++++++++------------
>  net/ipv4/tcp_ipv4.c    | 12 +++++++-----
>  net/ipv6/tcp_ipv6.c    | 11 +++++++----
>  5 files changed, 35 insertions(+), 31 deletions(-)
> 
> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> index 34f572271c0c..26538ceb4b01 100644
> --- a/include/linux/skbuff.h
> +++ b/include/linux/skbuff.h
> @@ -314,6 +314,7 @@ struct sk_buff;
>   * used to translate the reason to string.
>   */
>  enum skb_drop_reason {
> +	SKB_NOT_DROPPED_YET = 0,
>  	SKB_DROP_REASON_NOT_SPECIFIED,	/* drop reason is not specified */
>  	SKB_DROP_REASON_NO_SOCKET,	/* socket not found */
>  	SKB_DROP_REASON_PKT_TOO_SMALL,	/* packet size is too small */

This change looks ok to me, so:
Reviewed-by: David Ahern <dsahern@kernel.org>

I am a little nervous that some of the earlier code with jumps does not
properly do 'if (reason != SKB_DROP_REASON_NOT_SPECIFIED) reason = ...'
but rather 'if (!reason) reason = ...'


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH net-next] skb: make drop reason booleanable
  2022-03-08  0:44 Jakub Kicinski
@ 2022-03-08 13:57 ` Toke Høiland-Jørgensen
  2022-03-08 16:35 ` David Ahern
  2022-03-09 11:30 ` patchwork-bot+netdevbpf
  2 siblings, 0 replies; 9+ messages in thread
From: Toke Høiland-Jørgensen @ 2022-03-08 13:57 UTC (permalink / raw)
  To: Jakub Kicinski, davem; +Cc: netdev, edumazet, dsahern, Jakub Kicinski

Jakub Kicinski <kuba@kernel.org> writes:

> We have a number of cases where function returns drop/no drop
> decision as a boolean. Now that we want to report the reason
> code as well we have to pass extra output arguments.
>
> We can make the reason code evaluate correctly as bool.
>
> I believe we're good to reorder the reasons as they are
> reported to user space as strings.
>
> Signed-off-by: Jakub Kicinski <kuba@kernel.org>
> ---
> v2: use Eric's suggestion for the name, indeed better than mine
> ---
>  include/linux/skbuff.h |  1 +
>  include/net/tcp.h      | 21 +++++++++++----------
>  net/ipv4/tcp.c         | 21 +++++++++------------
>  net/ipv4/tcp_ipv4.c    | 12 +++++++-----
>  net/ipv6/tcp_ipv6.c    | 11 +++++++----
>  5 files changed, 35 insertions(+), 31 deletions(-)
>
> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> index 34f572271c0c..26538ceb4b01 100644
> --- a/include/linux/skbuff.h
> +++ b/include/linux/skbuff.h
> @@ -314,6 +314,7 @@ struct sk_buff;
>   * used to translate the reason to string.
>   */
>  enum skb_drop_reason {
> +	SKB_NOT_DROPPED_YET = 0,

Haha, nice! Even feels like this is touching on some deep philosophical
truth about the state of packets - the best they can hope for is to be
not dropped... yet! :D

-Toke


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH net-next] skb: make drop reason booleanable
@ 2022-03-08  0:44 Jakub Kicinski
  2022-03-08 13:57 ` Toke Høiland-Jørgensen
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Jakub Kicinski @ 2022-03-08  0:44 UTC (permalink / raw)
  To: davem; +Cc: netdev, edumazet, dsahern, Jakub Kicinski

We have a number of cases where function returns drop/no drop
decision as a boolean. Now that we want to report the reason
code as well we have to pass extra output arguments.

We can make the reason code evaluate correctly as bool.

I believe we're good to reorder the reasons as they are
reported to user space as strings.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
v2: use Eric's suggestion for the name, indeed better than mine
---
 include/linux/skbuff.h |  1 +
 include/net/tcp.h      | 21 +++++++++++----------
 net/ipv4/tcp.c         | 21 +++++++++------------
 net/ipv4/tcp_ipv4.c    | 12 +++++++-----
 net/ipv6/tcp_ipv6.c    | 11 +++++++----
 5 files changed, 35 insertions(+), 31 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 34f572271c0c..26538ceb4b01 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -314,6 +314,7 @@ struct sk_buff;
  * used to translate the reason to string.
  */
 enum skb_drop_reason {
+	SKB_NOT_DROPPED_YET = 0,
 	SKB_DROP_REASON_NOT_SPECIFIED,	/* drop reason is not specified */
 	SKB_DROP_REASON_NO_SOCKET,	/* socket not found */
 	SKB_DROP_REASON_PKT_TOO_SMALL,	/* packet size is too small */
diff --git a/include/net/tcp.h b/include/net/tcp.h
index d486d7b6112d..ee8237b58e1d 100644
--- a/include/net/tcp.h
+++ b/include/net/tcp.h
@@ -1674,10 +1674,11 @@ tcp_md5_do_lookup(const struct sock *sk, int l3index,
 		return NULL;
 	return __tcp_md5_do_lookup(sk, l3index, addr, family);
 }
-bool tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
-			  enum skb_drop_reason *reason,
-			  const void *saddr, const void *daddr,
-			  int family, int dif, int sdif);
+
+enum skb_drop_reason
+tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
+		     const void *saddr, const void *daddr,
+		     int family, int dif, int sdif);
 
 
 #define tcp_twsk_md5_key(twsk)	((twsk)->tw_md5_key)
@@ -1688,13 +1689,13 @@ tcp_md5_do_lookup(const struct sock *sk, int l3index,
 {
 	return NULL;
 }
-static inline bool tcp_inbound_md5_hash(const struct sock *sk,
-					const struct sk_buff *skb,
-					enum skb_drop_reason *reason,
-					const void *saddr, const void *daddr,
-					int family, int dif, int sdif)
+
+static inline enum skb_drop_reason
+tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
+		     const void *saddr, const void *daddr,
+		     int family, int dif, int sdif);
 {
-	return false;
+	return SKB_NOT_DROPPED_YET;
 }
 #define tcp_twsk_md5_key(twsk)	NULL
 #endif
diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
index 33f20134e3f1..b5f032958b2c 100644
--- a/net/ipv4/tcp.c
+++ b/net/ipv4/tcp.c
@@ -4434,10 +4434,10 @@ int tcp_md5_hash_key(struct tcp_md5sig_pool *hp, const struct tcp_md5sig_key *ke
 EXPORT_SYMBOL(tcp_md5_hash_key);
 
 /* Called with rcu_read_lock() */
-bool tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
-			  enum skb_drop_reason *reason,
-			  const void *saddr, const void *daddr,
-			  int family, int dif, int sdif)
+enum skb_drop_reason
+tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
+		     const void *saddr, const void *daddr,
+		     int family, int dif, int sdif)
 {
 	/*
 	 * This gets called for each TCP segment that arrives
@@ -4464,18 +4464,16 @@ bool tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
 
 	/* We've parsed the options - do we have a hash? */
 	if (!hash_expected && !hash_location)
-		return false;
+		return SKB_NOT_DROPPED_YET;
 
 	if (hash_expected && !hash_location) {
-		*reason = SKB_DROP_REASON_TCP_MD5NOTFOUND;
 		NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5NOTFOUND);
-		return true;
+		return SKB_DROP_REASON_TCP_MD5NOTFOUND;
 	}
 
 	if (!hash_expected && hash_location) {
-		*reason = SKB_DROP_REASON_TCP_MD5UNEXPECTED;
 		NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5UNEXPECTED);
-		return true;
+		return SKB_DROP_REASON_TCP_MD5UNEXPECTED;
 	}
 
 	/* check the signature */
@@ -4483,7 +4481,6 @@ bool tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
 						 NULL, skb);
 
 	if (genhash || memcmp(hash_location, newhash, 16) != 0) {
-		*reason = SKB_DROP_REASON_TCP_MD5FAILURE;
 		NET_INC_STATS(sock_net(sk), LINUX_MIB_TCPMD5FAILURE);
 		if (family == AF_INET) {
 			net_info_ratelimited("MD5 Hash failed for (%pI4, %d)->(%pI4, %d)%s L3 index %d\n",
@@ -4497,9 +4494,9 @@ bool tcp_inbound_md5_hash(const struct sock *sk, const struct sk_buff *skb,
 					saddr, ntohs(th->source),
 					daddr, ntohs(th->dest), l3index);
 		}
-		return true;
+		return SKB_DROP_REASON_TCP_MD5FAILURE;
 	}
-	return false;
+	return SKB_NOT_DROPPED_YET;
 }
 EXPORT_SYMBOL(tcp_inbound_md5_hash);
 
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 411357ad9757..81694a354110 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1965,9 +1965,10 @@ int tcp_v4_rcv(struct sk_buff *skb)
 		struct sock *nsk;
 
 		sk = req->rsk_listener;
-		if (unlikely(tcp_inbound_md5_hash(sk, skb, &drop_reason,
-						  &iph->saddr, &iph->daddr,
-						  AF_INET, dif, sdif))) {
+		drop_reason = tcp_inbound_md5_hash(sk, skb,
+						   &iph->saddr, &iph->daddr,
+						   AF_INET, dif, sdif);
+		if (unlikely(drop_reason)) {
 			sk_drops_add(sk, skb);
 			reqsk_put(req);
 			goto discard_it;
@@ -2041,8 +2042,9 @@ int tcp_v4_rcv(struct sk_buff *skb)
 		goto discard_and_relse;
 	}
 
-	if (tcp_inbound_md5_hash(sk, skb, &drop_reason, &iph->saddr,
-				 &iph->daddr, AF_INET, dif, sdif))
+	drop_reason = tcp_inbound_md5_hash(sk, skb, &iph->saddr,
+					   &iph->daddr, AF_INET, dif, sdif);
+	if (drop_reason)
 		goto discard_and_relse;
 
 	nf_reset_ct(skb);
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index cb2bb7d2e907..13678d3908fa 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -1632,8 +1632,10 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
 		struct sock *nsk;
 
 		sk = req->rsk_listener;
-		if (tcp_inbound_md5_hash(sk, skb, &drop_reason, &hdr->saddr,
-					 &hdr->daddr, AF_INET6, dif, sdif)) {
+		drop_reason = tcp_inbound_md5_hash(sk, skb,
+						   &hdr->saddr, &hdr->daddr,
+						   AF_INET6, dif, sdif);
+		if (drop_reason) {
 			sk_drops_add(sk, skb);
 			reqsk_put(req);
 			goto discard_it;
@@ -1704,8 +1706,9 @@ INDIRECT_CALLABLE_SCOPE int tcp_v6_rcv(struct sk_buff *skb)
 		goto discard_and_relse;
 	}
 
-	if (tcp_inbound_md5_hash(sk, skb, &drop_reason, &hdr->saddr,
-				 &hdr->daddr, AF_INET6, dif, sdif))
+	drop_reason = tcp_inbound_md5_hash(sk, skb, &hdr->saddr, &hdr->daddr,
+					   AF_INET6, dif, sdif);
+	if (drop_reason)
 		goto discard_and_relse;
 
 	if (tcp_filter(sk, skb)) {
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-03-09 11:30 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-04  4:53 [PATCH net-next] skb: make drop reason booleanable Jakub Kicinski
2022-03-04  5:22 ` Jakub Kicinski
2022-03-04  6:37   ` Eric Dumazet
2022-03-04 15:31     ` David Ahern
2022-03-04 16:36       ` Eric Dumazet
2022-03-08  0:44 Jakub Kicinski
2022-03-08 13:57 ` Toke Høiland-Jørgensen
2022-03-08 16:35 ` David Ahern
2022-03-09 11:30 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.