net: icmp: add skb drop reasons to icmp
Subsystems (5)
v3 cover net: icmp: add skb drop reasons to icmp
From: Menglong Dong <[email protected]>
In the commit c504e5c2f964 ("net: skb: introduce kfree_skb_reason()"), we added the support of reporting the reasons of skb drops to kfree_skb tracepoint. And in this series patches, reasons for skb drops are added to ICMP protocol.
In order to report the reasons of skb drops in 'sock_queue_rcv_skb()', the function 'sock_queue_rcv_skb_reason()' is introduced in the 1th patch, which is used in the 2th patch.
In the 2th patch, we introduce the new function __ping_queue_rcv_skb() to report drop reasons by its return value.
In the 3th patch, we make ICMP message handler functions return drop reasons, which means we change the return type of 'handler()' in 'struct icmp_control' from 'bool' to 'enum skb_drop_reason'. This changed its original intention, as 'false' means failure, but 'SKB_NOT_DROPPED_YET', which is 0, means success now. Therefore, we have to change all usages of these handler. Following "handler" functions are involved:
icmp_unreach()icmp_redirect()icmp_echo()icmp_timestamp()icmp_discard()
And following drop reasons are added(what they mean can be see in the document for them):
SKB_DROP_REASON_ICMP_CSUMSKB_DROP_REASON_ICMP_TYPESKB_DROP_REASON_ICMP_BROADCAST
Changes since v2:
- fix aliegnment problem in the 2th patch
Changes since v1:
- introduce __ping_queue_rcv_skb() instead of change the return value of ping_queue_rcv_skb() in the 2th patch, as Paolo suggested
Menglong Dong (3):
net: sock: introduce sock_queue_rcv_skb_reason()
net: icmp: introduce __ping_queue_rcv_skb() to report drop reasons
net: icmp: add reasons of the skb drops to icmp protocol
include/linux/skbuff.h | 5 +++ include/net/ping.h | 2 +- include/net/sock.h | 9 ++++- include/trace/events/skb.h | 3 ++ net/core/sock.c | 30 ++++++++++++--- net/ipv4/icmp.c | 75 ++++++++++++++++++++++---------------- net/ipv4/ping.c | 32 ++++++++++------ net/ipv6/icmp.c | 24 +++++++----- 8 files changed, 121 insertions(+), 59 deletions(-)
Signature · 1 line
2.35.1
PATCH v3 1/3 net: sock: introduce sock_queue_rcv_skb_reason()
From: Menglong Dong <[email protected]>
In order to report the reasons of skb drops in 'sock_queue_rcv_skb()', introduce the function 'sock_queue_rcv_skb_reason()'.
As the return value of 'sock_queue_rcv_skb()' is used as the error code, we can't make it as drop reason and have to pass extra output argument. 'sock_queue_rcv_skb()' is used in many places, so we can't change it directly.
Introduce the new function 'sock_queue_rcv_skb_reason()' and make 'sock_queue_rcv_skb()' an inline call to it.
--- include/net/sock.h | 9 ++++++++- net/core/sock.c | 30 ++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 7 deletions(-)
include/net/sock.h +8 -1
@@ -2392,7 +2392,14 @@ int __sk_queue_drop_skb(struct sock *sk, struct sk_buff_head *sk_queue,void (*destructor)(struct sock *sk, struct sk_buff *skb));int __sock_queue_rcv_skb (struct sock *sk,struct sk_buff *skb); -int sock_queue_rcv_skb (struct sock *sk,struct sk_buff *skb); + +int sock_queue_rcv_skb_reason (struct sock *sk,struct sk_buff *skb, +enum skb_drop_reason *reason); + +static inline int sock_queue_rcv_skb (struct sock *sk,struct sk_buff *skb) +{ +return sock_queue_rcv_skb_reason (sk, skb,NULL ); +}int sock_queue_err_skb (struct sock *sk,struct sk_buff *skb);struct sk_buff *sock_dequeue_err_skb (struct sock *sk);
net/core/sock.c +24 -6
@@ -503,17 +503,35 @@ int __sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb) }EXPORT_SYMBOL (__sock_queue_rcv_skb); -int sock_queue_rcv_skb (struct sock *sk,struct sk_buff *skb) +int sock_queue_rcv_skb_reason (struct sock *sk,struct sk_buff *skb, +enum skb_drop_reason *reason) { +enum skb_drop_reason drop_reason;int err; err =sk_filter (sk, skb); -if (err) -return err; - -return __sock_queue_rcv_skb (sk, skb); +if (err) { + drop_reason =SKB_DROP_REASON_SOCKET_FILTER ; + goto out; + } + err =__sock_queue_rcv_skb (sk, skb); +switch (err) { +case -ENOMEM : + drop_reason =SKB_DROP_REASON_SOCKET_RCVBUFF ; +break ; +case -ENOBUFS : + drop_reason =SKB_DROP_REASON_PROTO_MEM ; +break ; +default : + drop_reason =SKB_NOT_DROPPED_YET ; +break ; + } +out: +if (reason) + *reason = drop_reason; +return err; } -EXPORT_SYMBOL (sock_queue_rcv_skb); +EXPORT_SYMBOL (sock_queue_rcv_skb_reason);int __sk_receive_skb (struct sock *sk,struct sk_buff *skb,const int nested,unsigned int trim_cap,bool refcounted)
Signature · 1 line
2.35.1
PATCH v3 2/3 net: icmp: introduce __ping_queue_rcv_skb() to report drop reasons
In reply to [email protected]From: Menglong Dong <[email protected]>
In order to avoid to change the return value of ping_queue_rcv_skb(), introduce the function __ping_queue_rcv_skb(), which is able to report the reasons of skb drop as its return value, as Paolo suggested.
Meanwhile, make ping_queue_rcv_skb() a simple call to __ping_queue_rcv_skb().
The kfree_skb() and sock_queue_rcv_skb() used in ping_queue_rcv_skb() are replaced with kfree_skb_reason() and sock_queue_rcv_skb_reason() now.
---
v3:
- fix aligenment problem
v2:
- introduce __ping_queue_rcv_skb() instead of change the return value of ping_queue_rcv_skb()
--- net/ipv4/ping.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-)
net/ipv4/ping.c +13 -5
@@ -934,16 +934,24 @@ int ping_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int noblock, }EXPORT_SYMBOL_GPL (ping_recvmsg); -int ping_queue_rcv_skb (struct sock *sk,struct sk_buff *skb) +static enum skb_drop_reason __ping_queue_rcv_skb (struct sock *sk, +struct sk_buff *skb) { +enum skb_drop_reason reason; +pr_debug ("ping_queue_rcv_skb(sk=%p,sk->num=%d,skb=%p)\n" ,inet_sk (sk),inet_sk (sk)->inet_num, skb); -if (sock_queue_rcv_skb (sk, skb) <0 ) { -kfree_skb (skb); +if (sock_queue_rcv_skb_reason (sk, skb, &reason) <0 ) { +kfree_skb_reason (skb, reason);pr_debug ("ping_queue_rcv_skb -> failed\n" ); -return -1 ; +return reason; } -return 0 ; +return SKB_NOT_DROPPED_YET ; +} + +int ping_queue_rcv_skb (struct sock *sk,struct sk_buff *skb) +{ +return __ping_queue_rcv_skb (sk, skb) ?:-1 ; }EXPORT_SYMBOL_GPL (ping_queue_rcv_skb);
Signature · 1 line
2.35.1
David Ahern
maintainerRe: [PATCH net-next v3 2/3] net: icmp: introduce __ping_queue_rcv_skb() to report drop reasons
Quoted 24 lines · On 3/16/22 12:31 AM, [email protected] wrote:
net/ipv4/ping.c +7
-4@@ -934,16 +934,24 @@ int ping_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int noblock, }EXPORT_SYMBOL_GPL (ping_recvmsg); -int ping_queue_rcv_skb (struct sock *sk,struct sk_buff *skb) +static enum skb_drop_reason __ping_queue_rcv_skb (struct sock *sk, +struct sk_buff *skb) { +enum skb_drop_reason reason; +pr_debug ("ping_queue_rcv_skb(sk=%p,sk->num=%d,skb=%p)\n" ,inet_sk (sk),inet_sk (sk)->inet_num, skb); -if (sock_queue_rcv_skb (sk, skb) <0 ) { -kfree_skb (skb); +if (sock_queue_rcv_skb_reason (sk, skb, &reason) <0 ) { +kfree_skb_reason (skb, reason);pr_debug ("ping_queue_rcv_skb -> failed\n" ); -return -1 ; +return reason; }
net/ipv4/ping.c int ping_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int noblock, · line 957
Quoted 10 lines
net/ipv4/ping.c +6
-1-return 0 ; +return SKB_NOT_DROPPED_YET ; +} + +int ping_queue_rcv_skb (struct sock *sk,struct sk_buff *skb) +{ +return __ping_queue_rcv_skb (sk, skb) ?:-1 ; }EXPORT_SYMBOL_GPL (ping_queue_rcv_skb);
This is a generic proto callback and you are now changing its return code in a way that seems to conflict with existing semantics
Re: [PATCH net-next v3 2/3] net: icmp: introduce __ping_queue_rcv_skb() to report drop reasons
Quoted 31 lines · David Ahern
Quoted 29 lines · On 3/16/22 12:31 AM, [email protected] wrote:
net/ipv4/ping.c +11
-5@@ -934,16 +934,24 @@ int ping_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int noblock, }EXPORT_SYMBOL_GPL (ping_recvmsg); -int ping_queue_rcv_skb (struct sock *sk,struct sk_buff *skb) +static enum skb_drop_reason __ping_queue_rcv_skb (struct sock *sk, +struct sk_buff *skb) { +enum skb_drop_reason reason; +pr_debug ("ping_queue_rcv_skb(sk=%p,sk->num=%d,skb=%p)\n" ,inet_sk (sk),inet_sk (sk)->inet_num, skb); -if (sock_queue_rcv_skb (sk, skb) <0 ) { -kfree_skb (skb); +if (sock_queue_rcv_skb_reason (sk, skb, &reason) <0 ) { +kfree_skb_reason (skb, reason);pr_debug ("ping_queue_rcv_skb -> failed\n" ); -return -1 ; +return reason; } -return 0 ; +return SKB_NOT_DROPPED_YET ; +} + +int ping_queue_rcv_skb (struct sock *sk,struct sk_buff *skb)
Quoted 8 lines
net/ipv4/ping.c int ping_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int noblock, · line 957
Quoted 5 lines
net/ipv4/ping.c +2
-0+{ +return __ping_queue_rcv_skb (sk, skb) ?:-1 ; }EXPORT_SYMBOL_GPL (ping_queue_rcv_skb);This is a generic proto callback and you are now changing its return code in a way that seems to conflict with existing semantics
The return value of ping_queue_rcv_skb() seems not changed. In the previous code, -1 is returned on failure and 0 for success. This logic isn't changed, giving __ping_queue_rcv_skb() != 0 means failure and -1 is returned. Isn't it?
Paolo Abeni
maintainerRe: [PATCH net-next v3 2/3] net: icmp: introduce __ping_queue_rcv_skb() to report drop reasons
Quoted 41 lines · Menglong Dong
Quoted 31 lines · David Ahern
Quoted 29 lines · On 3/16/22 12:31 AM, [email protected] wrote:
net/ipv4/ping.c +11
-5@@ -934,16 +934,24 @@ int ping_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int noblock, }EXPORT_SYMBOL_GPL (ping_recvmsg); -int ping_queue_rcv_skb (struct sock *sk,struct sk_buff *skb) +static enum skb_drop_reason __ping_queue_rcv_skb (struct sock *sk, +struct sk_buff *skb) { +enum skb_drop_reason reason; +pr_debug ("ping_queue_rcv_skb(sk=%p,sk->num=%d,skb=%p)\n" ,inet_sk (sk),inet_sk (sk)->inet_num, skb); -if (sock_queue_rcv_skb (sk, skb) <0 ) { -kfree_skb (skb); +if (sock_queue_rcv_skb_reason (sk, skb, &reason) <0 ) { +kfree_skb_reason (skb, reason);pr_debug ("ping_queue_rcv_skb -> failed\n" ); -return -1 ; +return reason; } -return 0 ; +return SKB_NOT_DROPPED_YET ; +} + +int ping_queue_rcv_skb (struct sock *sk,struct sk_buff *skb)Quoted 8 lines
net/ipv4/ping.c int ping_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int noblock, · line 957
Quoted 5 lines
net/ipv4/ping.c +2
-0+{ +return __ping_queue_rcv_skb (sk, skb) ?:-1 ; }EXPORT_SYMBOL_GPL (ping_queue_rcv_skb);This is a generic proto callback and you are now changing its return code in a way that seems to conflict with existing semantics
Quoted 4 lines
The return value of
ping_queue_rcv_skb()seems not changed. In the previous code, -1 is returned on failure and 0 for success. This logic isn't changed, giving__ping_queue_rcv_skb()!= 0 means failure and -1 is returned. Isn't it?
With this patch, on failure __ping_queue_rcv_skb() returns 'reason' (>
0) and ping_queue_rcv_skb() returns the same value.
On success __ping_queue_rcv_skb() returns SKB_NOT_DROPPED_YET (==0) and ping_queue_rcv_skb() return -1.
You need to preserve the old ping_queue_rcv_skb() return values, under the same circumstances.
Thanks,
Paolo
Re: [PATCH net-next v3 2/3] net: icmp: introduce __ping_queue_rcv_skb() to report drop reasons
Quoted 48 lines · Paolo Abeni
Quoted 41 lines · Menglong Dong
Quoted 31 lines · David Ahern
Quoted 29 lines · On 3/16/22 12:31 AM, [email protected] wrote:
net/ipv4/ping.c +11
-5@@ -934,16 +934,24 @@ int ping_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int noblock, }EXPORT_SYMBOL_GPL (ping_recvmsg); -int ping_queue_rcv_skb (struct sock *sk,struct sk_buff *skb) +static enum skb_drop_reason __ping_queue_rcv_skb (struct sock *sk, +struct sk_buff *skb) { +enum skb_drop_reason reason; +pr_debug ("ping_queue_rcv_skb(sk=%p,sk->num=%d,skb=%p)\n" ,inet_sk (sk),inet_sk (sk)->inet_num, skb); -if (sock_queue_rcv_skb (sk, skb) <0 ) { -kfree_skb (skb); +if (sock_queue_rcv_skb_reason (sk, skb, &reason) <0 ) { +kfree_skb_reason (skb, reason);pr_debug ("ping_queue_rcv_skb -> failed\n" ); -return -1 ; +return reason; } -return 0 ; +return SKB_NOT_DROPPED_YET ; +} + +int ping_queue_rcv_skb (struct sock *sk,struct sk_buff *skb)Quoted 8 lines
net/ipv4/ping.c int ping_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int noblock, · line 957
Quoted 5 lines
net/ipv4/ping.c +2
-0+{ +return __ping_queue_rcv_skb (sk, skb) ?:-1 ; }EXPORT_SYMBOL_GPL (ping_queue_rcv_skb);This is a generic proto callback and you are now changing its return code in a way that seems to conflict with existing semantics
Quoted 4 lines
The return value of
ping_queue_rcv_skb()seems not changed. In the previous code, -1 is returned on failure and 0 for success. This logic isn't changed, giving__ping_queue_rcv_skb()!= 0 means failure and -1 is returned. Isn't it?
Quoted 8 lines
With this patch, on failure
__ping_queue_rcv_skb()returns 'reason' (>
0) andping_queue_rcv_skb()returns the same value.On success
__ping_queue_rcv_skb()returnsSKB_NOT_DROPPED_YET(==0) andping_queue_rcv_skb()return -1.You need to preserve the old
ping_queue_rcv_skb()return values, under the same circumstances.
Oops...my mistake....:)
Thanks for your explanation!
Menglong Dong
Quoted 5 lines
Thanks,
Paolo
PATCH v3 3/3 net: icmp: add reasons of the skb drops to icmp protocol
In reply to [email protected]From: Menglong Dong <[email protected]>
Replace kfree_skb() used in icmp_rcv() and icmpv6_rcv() with kfree_skb_reason().
In order to get the reasons of the skb drops after icmp message handle, we change the return type of 'handler()' in 'struct icmp_control' from 'bool' to 'enum skb_drop_reason'. This may change its original intention, as 'false' means failure, but 'SKB_NOT_DROPPED_YET' means success now. Therefore, all 'handler' and the call of them need to be handled. Following 'handler' functions are involved:
icmp_unreach()icmp_redirect()icmp_echo()icmp_timestamp()icmp_discard()
And following new drop reasons are added:
SKB_DROP_REASON_ICMP_CSUMSKB_DROP_REASON_ICMP_TYPESKB_DROP_REASON_ICMP_BROADCAST
--- include/linux/skbuff.h | 5 +++ include/net/ping.h | 2 +- include/trace/events/skb.h | 3 ++ net/ipv4/icmp.c | 75 ++++++++++++++++++++++---------------- net/ipv4/ping.c | 14 ++++--- net/ipv6/icmp.c | 24 +++++++----- 6 files changed, 76 insertions(+), 47 deletions(-)
include/linux/skbuff.h +5 -0
@@ -444,6 +444,11 @@ enum skb_drop_reason {SKB_DROP_REASON_TAP_TXFILTER ,/* dropped by tx filter implemented * at tun/tap, e.g., check_filter() */ +SKB_DROP_REASON_ICMP_CSUM ,/* ICMP checksum error */ +SKB_DROP_REASON_ICMP_TYPE ,/* unknown ICMP type */ +SKB_DROP_REASON_ICMP_BROADCAST ,/* unacceptable broadcast(multicast) +* ICMP message +*/ SKB_DROP_REASON_MAX, };
include/net/ping.h +1 -1
@@ -76,7 +76,7 @@ int ping_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int noblock,int ping_common_sendmsg (int family,struct msghdr *msg,size_t len,void *user_icmph,size_t icmph_len);int ping_queue_rcv_skb (struct sock *sk,struct sk_buff *skb); -bool ping_rcv (struct sk_buff *skb); +enum skb_drop_reason ping_rcv (struct sk_buff *skb);#ifdef CONFIG_PROC_FS void *ping_seq_start (struct seq_file *seq,loff_t *pos,sa_family_t family);
include/trace/events/skb.h +3 -0
@@ -61,6 +61,9 @@ EM(SKB_DROP_REASON_HDR_TRUNC, HDR_TRUNC) \ EM(SKB_DROP_REASON_TAP_FILTER, TAP_FILTER) \ EM(SKB_DROP_REASON_TAP_TXFILTER, TAP_TXFILTER) \ + EM(SKB_DROP_REASON_ICMP_CSUM, ICMP_CSUM) \ + EM(SKB_DROP_REASON_ICMP_TYPE, ICMP_TYPE) \ + EM(SKB_DROP_REASON_ICMP_BROADCAST, ICMP_BROADCAST) \ EMe(SKB_DROP_REASON_MAX, MAX)#undef EM
net/ipv4/icmp.c +44 -31
219 lines not on this page · raw message
net/ipv4/ping.c +8 -6
@@ -960,12 +960,12 @@ EXPORT_SYMBOL_GPL(ping_queue_rcv_skb);* All we need to do is get the socket. */ -bool ping_rcv (struct sk_buff *skb) +enum skb_drop_reason ping_rcv (struct sk_buff *skb) { +enum skb_drop_reason reason =SKB_DROP_REASON_NO_SOCKET ;struct sock *sk;struct net *net =dev_net (skb->dev);struct icmphdr *icmph =icmp_hdr (skb); -bool rc = false;/* We assume the packet has already been checked by icmp_rcv */
@@ -980,15 +980,17 @@ bool ping_rcv(struct sk_buff *skb)struct sk_buff *skb2 =skb_clone (skb,GFP_ATOMIC );pr_debug ("rcv on socket %p\n" , sk); -if (skb2 && !ping_queue_rcv_skb (sk, skb2)) - rc = true; +if (skb2) + reason =__ping_queue_rcv_skb (sk, skb2); +else + reason =SKB_DROP_REASON_NOMEM ;sock_put (sk); } -if (!rc) +if (reason)pr_debug ("no socket, dropping\n" ); -return rc; +return reason; }EXPORT_SYMBOL_GPL (ping_rcv);
net/ipv6/icmp.c +15 -9
@@ -864,21 +864,23 @@ void icmpv6_notify(struct sk_buff *skb, u8 type, u8 code, __be32 info)static int icmpv6_rcv (struct sk_buff *skb) { +enum skb_drop_reason reason =SKB_DROP_REASON_NOT_SPECIFIED ;struct net *net =dev_net (skb->dev);struct net_device *dev =icmp6_dev (skb);struct inet6_dev *idev =__in6_dev_get (dev);const struct in6_addr *saddr, *daddr;struct icmp6hdr *hdr;u8 type; -bool success = false;if (!xfrm6_policy_check (NULL ,XFRM_POLICY_IN , skb)) {struct sec_path *sp =skb_sec_path (skb);int nh;if (!(sp && sp->xvec[sp->len -1 ]->props.flags & -XFRM_STATE_ICMP )) +XFRM_STATE_ICMP )) { + reason =SKB_DROP_REASON_XFRM_POLICY ; goto drop_no_count; + }if (!pskb_may_pull (skb,sizeof (*hdr) +sizeof (struct ipv6hdr ))) goto drop_no_count;
@@ -886,8 +888,11 @@ static int icmpv6_rcv(struct sk_buff *skb) nh =skb_network_offset (skb);skb_set_network_header (skb,sizeof (*hdr)); -if (!xfrm6_policy_check_reverse (NULL ,XFRM_POLICY_IN , skb)) +if (!xfrm6_policy_check_reverse (NULL ,XFRM_POLICY_IN , + skb)) { + reason =SKB_DROP_REASON_XFRM_POLICY ; goto drop_no_count; + }skb_set_network_header (skb, nh); }
@@ -924,11 +929,11 @@ static int icmpv6_rcv(struct sk_buff *skb)break ;case ICMPV6_ECHO_REPLY : - success =ping_rcv (skb); + reason =ping_rcv (skb);break ;case ICMPV6_EXT_ECHO_REPLY : - success =ping_rcv (skb); + reason =ping_rcv (skb);break ;case ICMPV6_PKT_TOOBIG :
@@ -994,19 +999,20 @@ static int icmpv6_rcv(struct sk_buff *skb)/* until the v6 path can be better sorted assume failure and * preserve the status quo behaviour for the rest of the paths to here */ -if (success) -consume_skb (skb); +if (reason) +kfree_skb_reason (skb, reason);else -kfree_skb (skb); +consume_skb (skb);return 0 ; csum_error: + reason =SKB_DROP_REASON_ICMP_CSUM ;__ICMP6_INC_STATS (dev_net (dev), idev,ICMP6_MIB_CSUMERRORS ); discard_it:__ICMP6_INC_STATS (dev_net (dev), idev,ICMP6_MIB_INERRORS ); drop_no_count: -kfree_skb (skb); +kfree_skb_reason (skb, reason);return 0 ; }
Signature · 1 line
2.35.1
Jakub Kicinski
maintainerRe: [PATCH net-next v3 3/3] net: icmp: add reasons of the skb drops to icmp protocol
Quoted 20 lines · On Wed, 16 Mar 2022 14:31:48 +0800 [email protected] wrote:
From: Menglong Dong <[email protected]>
Replace
kfree_skb()used inicmp_rcv()andicmpv6_rcv()withkfree_skb_reason().In order to get the reasons of the skb drops after icmp message handle, we change the return type of '
handler()' in 'structicmp_control' from 'bool' to 'enumskb_drop_reason'. This may change its original intention, as 'false' means failure, but 'SKB_NOT_DROPPED_YET' means success now. Therefore, all 'handler' and the call of them need to be handled. Following 'handler' functions are involved:
icmp_unreach()icmp_redirect()icmp_echo()icmp_timestamp()icmp_discard()And following new drop reasons are added:
Quoted 7 lines
SKB_DROP_REASON_ICMP_CSUMSKB_DROP_REASON_ICMP_TYPESKB_DROP_REASON_ICMP_BROADCASTReviewed-by Hao Peng <[email protected]>Reviewed-by Jiang Biao <[email protected]>Signed-off-by Menglong Dong <[email protected]>
I guess this set raises the follow up question to Dave if adding drop reasons to places with MIB exception stats means improving the granularity or one MIB stat == one reason?
Quoted 17 lines
net/ipv4/ping.c +2
-4-bool ping_rcv (struct sk_buff *skb) +enum skb_drop_reason ping_rcv (struct sk_buff *skb) { +enum skb_drop_reason reason =SKB_DROP_REASON_NO_SOCKET ;struct sock *sk;struct net *net =dev_net (skb->dev);struct icmphdr *icmph =icmp_hdr (skb); -bool rc = false;/* We assume the packet has already been checked by icmp_rcv */ @@ -980,15 +980,17 @@ bool ping_rcv(struct sk_buff *skb)struct sk_buff *skb2 =skb_clone (skb,GFP_ATOMIC );pr_debug ("rcv on socket %p\n" , sk); -if (skb2 && !ping_queue_rcv_skb (sk, skb2)) - rc = true;
net/ipv4/ping.c bool ping_rcv(struct sk_buff *skb) · line 991
Quoted 10 lines
net/ipv4/ping.c +5
-1+if (skb2) + reason =__ping_queue_rcv_skb (sk, skb2); +else + reason =SKB_DROP_REASON_NOMEM ;sock_put (sk); } -if (!rc) +if (reason)pr_debug ("no socket, dropping\n" );
This is going to be printed on memory allocation failures now as well.
David Ahern
maintainerRe: [PATCH net-next v3 3/3] net: icmp: add reasons of the skb drops to icmp protocol
Quoted 5 lines · Jakub Kicinski
I guess this set raises the follow up question to Dave if adding drop reasons to places with MIB exception stats means improving the granularity or one MIB stat == one reason?
There are a few examples where multiple MIB stats are bumped on a drop, but the reason code should always be set based on first failure. Did you mean something else with your question?
Jakub Kicinski
maintainerRe: [PATCH net-next v3 3/3] net: icmp: add reasons of the skb drops to icmp protocol
Quoted 9 lines · On Wed, 16 Mar 2022 21:35:47 -0600 David Ahern wrote:
Quoted 4 lines · Jakub Kicinski
I guess this set raises the follow up question to Dave if adding drop reasons to places with MIB exception stats means improving the granularity or one MIB stat == one reason?
There are a few examples where multiple MIB stats are bumped on a drop, but the reason code should always be set based on first failure. Did you mean something else with your question?
I meant whether we want to differentiate between TYPE, and BROADCAST or whatever other possible invalid protocol cases we can get here or just dump them all into a single protocol error code.
Re: [PATCH net-next v3 3/3] net: icmp: add reasons of the skb drops to icmp protocol
Quoted 8 lines · Jakub Kicinski
Quoted 6 lines · On Wed, 16 Mar 2022 21:35:47 -0600 David Ahern wrote:
Quoted 4 lines · Jakub Kicinski
I guess this set raises the follow up question to Dave if adding drop reasons to places with MIB exception stats means improving the granularity or one MIB stat == one reason?
Quoted 7 lines
Quoted 3 lines
There are a few examples where multiple MIB stats are bumped on a drop, but the reason code should always be set based on first failure. Did you mean something else with your question?
I meant whether we want to differentiate between TYPE, and BROADCAST or whatever other possible invalid protocol cases we can get here or just dump them all into a single protocol error code.
Such as a SKB_DROP_REASON_PROTO_NOTSUPPORTED? and apply
it to 'GRE_VERSION' such cases too? Which means the data is not supported by current protocol.
David Ahern
maintainerRe: [PATCH net-next v3 3/3] net: icmp: add reasons of the skb drops to icmp protocol
In reply to Jakub KicinskiQuoted 7 lines · Jakub Kicinski
Quoted 6 lines · On Wed, 16 Mar 2022 21:35:47 -0600 David Ahern wrote:
Quoted 4 lines · Jakub Kicinski
I guess this set raises the follow up question to Dave if adding drop reasons to places with MIB exception stats means improving the granularity or one MIB stat == one reason?
Quoted 7 lines
Quoted 3 lines
There are a few examples where multiple MIB stats are bumped on a drop, but the reason code should always be set based on first failure. Did you mean something else with your question?
I meant whether we want to differentiate between TYPE, and BROADCAST or whatever other possible invalid protocol cases we can get here or just dump them all into a single protocol error code.
I think a single one is a good starting point.
RE: [PATCH net-next v3 3/3] net: icmp: add reasons of the skb drops to icmp protocol
From: David Ahern
Quoted 14 lines
Sent: 17 March 2022 14:49
Quoted 11 lines · Jakub Kicinski
Quoted 9 lines · On Wed, 16 Mar 2022 21:35:47 -0600 David Ahern wrote:
Quoted 4 lines · Jakub Kicinski
I guess this set raises the follow up question to Dave if adding drop reasons to places with MIB exception stats means improving the granularity or one MIB stat == one reason?
There are a few examples where multiple MIB stats are bumped on a drop, but the reason code should always be set based on first failure. Did you mean something else with your question?
Quoted 5 lines
Quoted 3 lines
I meant whether we want to differentiate between TYPE, and BROADCAST or whatever other possible invalid protocol cases we can get here or just dump them all into a single protocol error code.
I think a single one is a good starting point.
I remember looking at (I think) the packet drop stats a while back. Two machines on the same LAN were reporting rather different values. Basically 0 v quite a few.
It turned out that passing the packets to dhcp was deemed enough to stop them being reported as 'dropped'.
And I think that version of dhcp fed every packed into its BPF? filter. (I never did decide whether that caused every skb to be duplicated.)
David
-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK Registration No: 1397386 (Wales)
David Ahern
maintainerRe: [PATCH net-next v3 3/3] net: icmp: add reasons of the skb drops to icmp protocol
Quoted 21 lines · David Laight
From: David Ahern
Quoted 14 lines
Sent: 17 March 2022 14:49
Quoted 11 lines · Jakub Kicinski
Quoted 9 lines · On Wed, 16 Mar 2022 21:35:47 -0600 David Ahern wrote:
Quoted 4 lines · Jakub Kicinski
I guess this set raises the follow up question to Dave if adding drop reasons to places with MIB exception stats means improving the granularity or one MIB stat == one reason?
There are a few examples where multiple MIB stats are bumped on a drop, but the reason code should always be set based on first failure. Did you mean something else with your question?
Quoted 5 lines
Quoted 3 lines
I meant whether we want to differentiate between TYPE, and BROADCAST or whatever other possible invalid protocol cases we can get here or just dump them all into a single protocol error code.
I think a single one is a good starting point.
Quoted 9 lines
I remember looking at (I think) the packet drop stats a while back. Two machines on the same LAN were reporting rather different values. Basically 0 v quite a few.
It turned out that passing the packets to dhcp was deemed enough to stop them being reported as 'dropped'.
And I think that version of dhcp fed every packed into its BPF? filter. (I never did decide whether that caused every skb to be duplicated.)
I believe it depends on the type of socket. Packet sockets - e.g., running lldpd or tcpdump - do cause every packet to be cloned and kills performance.
Re: [PATCH net-next v3 3/3] net: icmp: add reasons of the skb drops to icmp protocol
In reply to David AhernQuoted 13 lines · David Ahern
Quoted 11 lines · Jakub Kicinski
Quoted 9 lines · On Wed, 16 Mar 2022 21:35:47 -0600 David Ahern wrote:
Quoted 4 lines · Jakub Kicinski
I guess this set raises the follow up question to Dave if adding drop reasons to places with MIB exception stats means improving the granularity or one MIB stat == one reason?
There are a few examples where multiple MIB stats are bumped on a drop, but the reason code should always be set based on first failure. Did you mean something else with your question?
Quoted 5 lines
Quoted 3 lines
I meant whether we want to differentiate between TYPE, and BROADCAST or whatever other possible invalid protocol cases we can get here or just dump them all into a single protocol error code.
I think a single one is a good starting point.
Ok, I'll try my best to make a V4 base this way...Is there any inspiration?
Such as we make SKB_DROP_REASON_PTYPE_ABSENT to SKB_DROP_REASON_L2_PROTO, which means the L2 protocol is not supported or invalied.
And use SKB_DROP_REASON_L4_PROTO for the L4 protocol problem, such as GRE version not supported, ICMP type not supported, etc.
Sounds nice, isn't it?
David Ahern
maintainerRe: [PATCH net-next v3 3/3] net: icmp: add reasons of the skb drops to icmp protocol
Quoted 18 lines · Menglong Dong
Quoted 17 lines · David Ahern
Quoted 14 lines · Jakub Kicinski
Quoted 9 lines · On Wed, 16 Mar 2022 21:35:47 -0600 David Ahern wrote:
Quoted 4 lines · Jakub Kicinski
I guess this set raises the follow up question to Dave if adding drop reasons to places with MIB exception stats means improving the granularity or one MIB stat == one reason?
There are a few examples where multiple MIB stats are bumped on a drop, but the reason code should always be set based on first failure. Did you mean something else with your question?
I meant whether we want to differentiate between TYPE, and BROADCAST or whatever other possible invalid protocol cases we can get here or just dump them all into a single protocol error code.
Quoted 7 lines
Quoted 1 line
I think a single one is a good starting point.
Ok, I'll try my best to make a V4 base this way...Is there any inspiration?
Such as we make
SKB_DROP_REASON_PTYPE_ABSENTtoSKB_DROP_REASON_L2_PROTO, which means the L2 protocol is not supported or invalied.
not following. PTYPE is a Linux name. That means nothing to a user.
I am not sure where you want to use L2_PROTO.
Quoted 5 lines
And use
SKB_DROP_REASON_L4_PROTOfor the L4 protocol problem, such as GRE version not supported, ICMP type not supported, etc.Sounds nice, isn't it?
Re: [PATCH net-next v3 3/3] net: icmp: add reasons of the skb drops to icmp protocol
Quoted 24 lines · David Ahern
Quoted 22 lines · Menglong Dong
Quoted 13 lines · David Ahern
Quoted 11 lines · Jakub Kicinski
Quoted 9 lines · On Wed, 16 Mar 2022 21:35:47 -0600 David Ahern wrote:
Quoted 4 lines · Jakub Kicinski
I guess this set raises the follow up question to Dave if adding drop reasons to places with MIB exception stats means improving the granularity or one MIB stat == one reason?
There are a few examples where multiple MIB stats are bumped on a drop, but the reason code should always be set based on first failure. Did you mean something else with your question?
Quoted 5 lines
Quoted 3 lines
I meant whether we want to differentiate between TYPE, and BROADCAST or whatever other possible invalid protocol cases we can get here or just dump them all into a single protocol error code.
I think a single one is a good starting point.
Ok, I'll try my best to make a V4 base this way...Is there any inspiration?
Quoted 7 lines
Quoted 3 lines
Such as we make
SKB_DROP_REASON_PTYPE_ABSENTtoSKB_DROP_REASON_L2_PROTO, which means the L2 protocol is not supported or invalied.not following. PTYPE is a Linux name. That means nothing to a user.
I am not sure where you want to use
L2_PROTO.
Yeah, PTYPE seems not suitable. I mean that replace SKB_DROP_REASON_PTYPE_ABSENT that is used in __netif_receive_skb_core() with L3_PROTO, which means no L3 protocol handler (or other device handler) is not found for the packet. This seems more
friendly and not code based.
Quoted 4 lines
Quoted 4 lines
And use
SKB_DROP_REASON_L4_PROTOfor the L4 protocol problem, such as GRE version not supported, ICMP type not supported, etc.
Is this L4_PROTO followed by anyone?
Thanks!
Menglong Dong
Quoted 3 lines
Quoted 2 lines
Sounds nice, isn't it?
David Ahern
maintainerRe: [PATCH net-next v3 3/3] net: icmp: add reasons of the skb drops to icmp protocol
Quoted 9 lines · Menglong Dong
Yeah, PTYPE seems not suitable. I mean that replace
SKB_DROP_REASON_PTYPE_ABSENTthat is used in__netif_receive_skb_core()withL3_PROTO, which means no L3 protocol handler (or other device handler) is not found for the packet. This seems more
friendly and not code based.Quoted 2 lines
Quoted 2 lines
And use
SKB_DROP_REASON_L4_PROTOfor the L4 protocol problem, such as GRE version not supported, ICMP type not supported, etc.Is this
L4_PROTOfollowed by anyone?
how about just a generic
SKB_DROP_REASON_UNHANDLED_PROTO /* protocol not implemented
* or not supported */
in place of current PTYPE_ABSENT (so a rename to remove a Linux code reference), and then use it for no L3 protocol handler, no L4 protocol handler, version extensions etc. The instruction pointer to symbol gives the context of the unsupported protocol.
Re: [PATCH net-next v3 3/3] net: icmp: add reasons of the skb drops to icmp protocol
Quoted 17 lines · David Ahern
Quoted 9 lines · Menglong Dong
Yeah, PTYPE seems not suitable. I mean that replace
SKB_DROP_REASON_PTYPE_ABSENTthat is used in__netif_receive_skb_core()withL3_PROTO, which means no L3 protocol handler (or other device handler) is not found for the packet. This seems more
friendly and not code based.Quoted 2 lines
Quoted 2 lines
And use
SKB_DROP_REASON_L4_PROTOfor the L4 protocol problem, such as GRE version not supported, ICMP type not supported, etc.Is this
L4_PROTOfollowed by anyone?how about just a generic
SKB_DROP_REASON_UNHANDLED_PROTO/* protocol not implemented
* or not supported */
Quoted 4 lines
in place of current
PTYPE_ABSENT(so a rename to remove a Linux code reference), and then use it for no L3 protocol handler, no L4 protocol handler, version extensions etc. The instruction pointer to symbol gives the context of the unsupported protocol.
Yeah, I think it's a good idea :)
Thanks!
Menglong Dong
Re: [PATCH net-next v3 3/3] net: icmp: add reasons of the skb drops to icmp protocol
In reply to Jakub KicinskiQuoted 1 line · Jakub Kicinski
[......]
Quoted 24 lines
Quoted 24 lines
net/ipv4/ping.c +6
-4-bool ping_rcv (struct sk_buff *skb) +enum skb_drop_reason ping_rcv (struct sk_buff *skb) { +enum skb_drop_reason reason =SKB_DROP_REASON_NO_SOCKET ;struct sock *sk;struct net *net =dev_net (skb->dev);struct icmphdr *icmph =icmp_hdr (skb); -bool rc = false;/* We assume the packet has already been checked by icmp_rcv */ @@ -980,15 +980,17 @@ bool ping_rcv(struct sk_buff *skb)struct sk_buff *skb2 =skb_clone (skb,GFP_ATOMIC );pr_debug ("rcv on socket %p\n" , sk); -if (skb2 && !ping_queue_rcv_skb (sk, skb2)) - rc = true; +if (skb2) + reason =__ping_queue_rcv_skb (sk, skb2); +else + reason =SKB_DROP_REASON_NOMEM ;sock_put (sk); }
Quoted 5 lines
net/ipv4/ping.c bool ping_rcv(struct sk_buff *skb) · line 991
Quoted 3 lines
net/ipv4/ping.c +1
-1-if (!rc) +if (reason)pr_debug ("no socket, dropping\n" );This is going to be printed on memory allocation failures now as well.
Enn...This logic is not changed. In the previous, skb2==NULL means rc is false, and this message is printed too.
Seems this can be optimized by the way? Printing the message only for no socket found.