diff mbox series

[net-next,4/6] net: ipv4: use kfree_skb_reason() in ip_protocol_deliver_rcu()

Message ID 20220124131538.1453657-5-imagedong@tencent.com
State Handled Elsewhere
Delegated to: Pablo Neira
Headers show
Series net: use kfree_skb_reason() for ip/udp packet receive | expand

Commit Message

Menglong Dong Jan. 24, 2022, 1:15 p.m. UTC
From: Menglong Dong <imagedong@tencent.com>

Replace kfree_skb() with kfree_skb_reason() in ip_protocol_deliver_rcu().
Following new drop reasons are introduced:

SKB_DROP_REASON_XFRM_POLICY
SKB_DROP_REASON_IP_NOPROTO

Signed-off-by: Menglong Dong <imagedong@tencent.com>
---
 include/linux/skbuff.h     | 2 ++
 include/trace/events/skb.h | 2 ++
 net/ipv4/ip_input.c        | 5 +++--
 3 files changed, 7 insertions(+), 2 deletions(-)

Comments

David Ahern Jan. 26, 2022, 2:21 a.m. UTC | #1
On 1/24/22 6:15 AM, menglong8.dong@gmail.com wrote:
> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> index 8942d32c0657..603f77ef2170 100644
> --- a/include/linux/skbuff.h
> +++ b/include/linux/skbuff.h
> @@ -328,6 +328,8 @@ enum skb_drop_reason {

It would be worthwhile to document the meaning of these as you add them
-- long description of the enum.

>  	SKB_DROP_REASON_IP_RPFILTER,
>  	SKB_DROP_REASON_EARLY_DEMUX,
>  	SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST,

	/* xfrm policy check failed */
> +	SKB_DROP_REASON_XFRM_POLICY,

	/* no support for IP protocol */
> +	SKB_DROP_REASON_IP_NOPROTO,
>  	SKB_DROP_REASON_MAX,
>  };
>  


If the enum is 1:1 with an SNMP counter, just state that.
Menglong Dong Jan. 26, 2022, 2:39 a.m. UTC | #2
On Wed, Jan 26, 2022 at 10:21 AM David Ahern <dsahern@gmail.com> wrote:
>
> On 1/24/22 6:15 AM, menglong8.dong@gmail.com wrote:
> > diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> > index 8942d32c0657..603f77ef2170 100644
> > --- a/include/linux/skbuff.h
> > +++ b/include/linux/skbuff.h
> > @@ -328,6 +328,8 @@ enum skb_drop_reason {
>
> It would be worthwhile to document the meaning of these as you add them
> -- long description of the enum.

Yeah, I realize it later. I'll complete these documents.

>
> >       SKB_DROP_REASON_IP_RPFILTER,
> >       SKB_DROP_REASON_EARLY_DEMUX,
> >       SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST,
>
>         /* xfrm policy check failed */
> > +     SKB_DROP_REASON_XFRM_POLICY,
>
>         /* no support for IP protocol */
> > +     SKB_DROP_REASON_IP_NOPROTO,
> >       SKB_DROP_REASON_MAX,
> >  };
> >
>
>
> If the enum is 1:1 with an SNMP counter, just state that.
diff mbox series

Patch

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 8942d32c0657..603f77ef2170 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -328,6 +328,8 @@  enum skb_drop_reason {
 	SKB_DROP_REASON_IP_RPFILTER,
 	SKB_DROP_REASON_EARLY_DEMUX,
 	SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST,
+	SKB_DROP_REASON_XFRM_POLICY,
+	SKB_DROP_REASON_IP_NOPROTO,
 	SKB_DROP_REASON_MAX,
 };
 
diff --git a/include/trace/events/skb.h b/include/trace/events/skb.h
index 1dcdcc92cf08..e8369b8e8430 100644
--- a/include/trace/events/skb.h
+++ b/include/trace/events/skb.h
@@ -25,6 +25,8 @@ 
 	EM(SKB_DROP_REASON_EARLY_DEMUX, EARLY_DEMUX)		\
 	EM(SKB_DROP_REASON_UNICAST_IN_L2_MULTICAST,		\
 	   UNICAST_IN_L2_MULTICAST)				\
+	EM(SKB_DROP_REASON_XFRM_POLICY, XFRM_POLICY)		\
+	EM(SKB_DROP_REASON_IP_NOPROTO, IP_NOPROTO)		\
 	EMe(SKB_DROP_REASON_MAX, MAX)
 
 #undef EM
diff --git a/net/ipv4/ip_input.c b/net/ipv4/ip_input.c
index a4afb367cf02..376c96cfd5d1 100644
--- a/net/ipv4/ip_input.c
+++ b/net/ipv4/ip_input.c
@@ -196,7 +196,8 @@  void ip_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int protocol)
 	if (ipprot) {
 		if (!ipprot->no_policy) {
 			if (!xfrm4_policy_check(NULL, XFRM_POLICY_IN, skb)) {
-				kfree_skb(skb);
+				kfree_skb_reason(skb,
+						 SKB_DROP_REASON_XFRM_POLICY);
 				return;
 			}
 			nf_reset_ct(skb);
@@ -215,7 +216,7 @@  void ip_protocol_deliver_rcu(struct net *net, struct sk_buff *skb, int protocol)
 				icmp_send(skb, ICMP_DEST_UNREACH,
 					  ICMP_PROT_UNREACH, 0);
 			}
-			kfree_skb(skb);
+			kfree_skb_reason(skb, SKB_DROP_REASON_IP_NOPROTO);
 		} else {
 			__IP_INC_STATS(net, IPSTATS_MIB_INDELIVERS);
 			consume_skb(skb);