net: extend drop reasons
Subsystems (4)
Johannes Berg
maintainerv4 cover net: extend drop reasons
Hi,
Here's v4 of the extended drop reasons, with fixes to kernel-doc and checkpatch.
johannes
Johannes Berg
maintainerPATCH v4 1/3 net: move dropreason.h to dropreason-core.h
From: Johannes Berg <[email protected]>
This will, after the next patch, hold only the core drop reasons and minimal infrastructure. Fix a small kernel-doc issue while at it, to avoid the move triggering a checker.
---
v3: new patch
v4: fix a kernel-doc issue
---
include/linux/netdevice.h | 2 +-
include/linux/skbuff.h | 2 +-
include/net/{dropreason.h => dropreason-core.h} | 7 ++++---
include/net/inet_frag.h | 2 +-
4 files changed, 7 insertions(+), 6 deletions(-)
rename include/net/{dropreason.h => dropreason-core.h} (98%)include/linux/netdevice.h +1 -1
@@ -52,7 +52,7 @@#include <linux/rbtree.h> #include <net/net_trackers.h> #include <net/net_debug.h> -#include <net/dropreason.h> +#include <net/dropreason-core.h> struct netpoll_info ;struct device ;
include/linux/skbuff.h +1 -1
@@ -37,7 +37,7 @@#include <linux/netfilter/nf_conntrack_common.h> #endif #include <net/net_debug.h> -#include <net/dropreason.h> +#include <net/dropreason-core.h> /** * DOC: skb checksums
include/net/dropreason-core.h renamed from include/net/dropreason.h +4 -3
@@ -1,7 +1,7 @@/* SPDX-License-Identifier: GPL-2.0-or-later */ -#ifndef _LINUX_DROPREASON_H -#define _LINUX_DROPREASON_H +#ifndef _LINUX_DROPREASON_CORE_H +#define _LINUX_DROPREASON_CORE_H#define DEFINE_DROP_REASON (FN , FNe) \ FN(NOT_SPECIFIED) \
@@ -334,7 +334,8 @@ enum skb_drop_reason {SKB_DROP_REASON_IPV6_NDISC_BAD_CODE ,/** @SKB_DROP_REASON_IPV6_NDISC_BAD_OPTIONS: invalid NDISC options. */ SKB_DROP_REASON_IPV6_NDISC_BAD_OPTIONS , -/** @SKB_DROP_REASON_IPV6_NDISC_NS_OTHERHOST: NEIGHBOUR SOLICITATION +/** +* @SKB_DROP_REASON_IPV6_NDISC_NS_OTHERHOST: NEIGHBOUR SOLICITATION * for another host. */ SKB_DROP_REASON_IPV6_NDISC_NS_OTHERHOST,
include/net/inet_frag.h +1 -1
@@ -7,7 +7,7 @@#include <linux/in6.h> #include <linux/rbtree_types.h> #include <linux/refcount.h> -#include <net/dropreason.h> +#include <net/dropreason-core.h> /* Per netns frag queues directory */ struct fqdir {
Signature · 1 line
2.40.0
Johannes Berg
maintainerPATCH v4 2/3 net: extend drop reasons for multiple subsystems
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
Extend drop reasons to make them usable by subsystems other than core by reserving the high 16 bits for a new subsystem ID, of which 0 of course is used for the existing reasons immediately.
To still be able to have string reasons, restructure that code a bit to make the loopup under RCU, the only user of this (right now) is drop_monitor.
---
v3:
- new dropreason.h now that core codes are in dropreason-core.h
- annotate RCU pointer init for sparse
v4:
- fix kernel-doc, indentation
--- include/net/dropreason-core.h | 14 ++++++--- include/net/dropreason.h | 31 ++++++++++++++++++ net/core/drop_monitor.c | 33 ++++++++++++++------ net/core/skbuff.c | 59 +++++++++++++++++++++++++++++++++-- 4 files changed, 121 insertions(+), 16 deletions(-) create mode 100644 include/net/dropreason.h
include/net/dropreason-core.h +10 -4
@@ -340,12 +340,20 @@ enum skb_drop_reason {*/ SKB_DROP_REASON_IPV6_NDISC_NS_OTHERHOST ,/** -* @SKB_DROP_REASON_MAX: the maximum of drop reason, which shouldn't be -* used as a real 'reason' +* @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which +* shouldn't be used as a real 'reason' - only for tracing code gen */ SKB_DROP_REASON_MAX , + +/** +* @SKB_DROP_REASON_SUBSYS_MASK: subsystem mask in drop reasons, +* see &enum skb_drop_reason_subsys +*/ + SKB_DROP_REASON_SUBSYS_MASK = 0xffff0000, }; +#define SKB_DROP_REASON_SUBSYS_SHIFT 16 +#define SKB_DR_INIT (name, reason) \ enum skb_drop_reason name = SKB_DROP_REASON_##reason#define SKB_DR (name) \
@@ -359,6 +367,4 @@ enum skb_drop_reason {SKB_DR_SET (name, reason); \ } while (0) -extern const char * const drop_reasons[]; -#endif
include/net/dropreason.h new file +31 -0
@@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ + +#ifndef _LINUX_DROPREASON_H +#define _LINUX_DROPREASON_H +#include <net/dropreason-core.h> + +/** +* enum skb_drop_reason_subsys - subsystem tag for (extended) drop reasons +*/ +enum skb_drop_reason_subsys { +/** @SKB_DROP_REASON_SUBSYS_CORE: core drop reasons defined above */ +SKB_DROP_REASON_SUBSYS_CORE , + +/** @SKB_DROP_REASON_SUBSYS_NUM: number of subsystems defined */ +SKB_DROP_REASON_SUBSYS_NUM +}; + +struct drop_reason_list { +const char *const *reasons; +size_t n_reasons; +}; + +/* Note: due to dynamic registrations, access must be under RCU */ +extern const struct drop_reason_list __rcu * +drop_reasons_by_subsys[SKB_DROP_REASON_SUBSYS_NUM ]; + +void drop_reasons_register_subsys (enum skb_drop_reason_subsys subsys, +const struct drop_reason_list *list); +void drop_reasons_unregister_subsys (enum skb_drop_reason_subsys subsys); + +#endif
net/core/drop_monitor.c +24 -9
@@ -21,6 +21,7 @@#include <linux/workqueue.h> #include <linux/netlink.h> #include <linux/net_dropmon.h> +#include <linux/bitfield.h> #include <linux/percpu.h> #include <linux/timer.h> #include <linux/bitops.h>
@@ -29,6 +30,7 @@#include <net/genetlink.h> #include <net/netevent.h> #include <net/flow_offload.h> +#include <net/dropreason.h> #include <net/devlink.h> #include <trace/events/skb.h>
@@ -504,8 +506,6 @@ static void net_dm_packet_trace_kfree_skb_hit(void *ignore,if (!nskb)return ; -if (unlikely (reason >=SKB_DROP_REASON_MAX || reason <=0 )) - reason =SKB_DROP_REASON_NOT_SPECIFIED ; cb =NET_DM_SKB_CB (nskb); cb->reason = reason; cb->pc = location;
@@ -552,9 +552,9 @@ static size_t net_dm_in_port_size(void) }#define NET_DM_MAX_SYMBOL_LEN 40 +#define NET_DM_MAX_REASON_LEN 50 -static size_t net_dm_packet_report_size (size_t payload_len, -enum skb_drop_reason reason) +static size_t net_dm_packet_report_size (size_t payload_len) {size_t size;
@@ -576,7 +576,7 @@ static size_t net_dm_packet_report_size(size_t payload_len,/* NET_DM_ATTR_PROTO */ nla_total_size (sizeof (u16)) +/* NET_DM_ATTR_REASON */ -nla_total_size (strlen (drop_reasons[reason]) +1 ) + +nla_total_size (NET_DM_MAX_REASON_LEN +1 ) +/* NET_DM_ATTR_PAYLOAD */ nla_total_size (payload_len); }
@@ -610,6 +610,8 @@ static int net_dm_packet_report_fill(struct sk_buff *msg, struct sk_buff *skb, size_t payload_len) {struct net_dm_skb_cb *cb =NET_DM_SKB_CB (skb); +const struct drop_reason_list *list =NULL ; +unsigned int subsys, subsys_reason;char buf[NET_DM_MAX_SYMBOL_LEN ];struct nlattr *attr;void *hdr;
@@ -627,9 +629,24 @@ static int net_dm_packet_report_fill(struct sk_buff *msg, struct sk_buff *skb, NET_DM_ATTR_PAD)) goto nla_put_failure; +rcu_read_lock (); + subsys =u32_get_bits (cb->reason,SKB_DROP_REASON_SUBSYS_MASK ); +if (subsys <SKB_DROP_REASON_SUBSYS_NUM ) + list =rcu_dereference (drop_reasons_by_subsys[subsys]); + subsys_reason = cb->reason & ~SKB_DROP_REASON_SUBSYS_MASK ; +if (!list || + subsys_reason >= list->n_reasons || + !list->reasons[subsys_reason] || +strlen (list->reasons[subsys_reason]) >NET_DM_MAX_REASON_LEN ) { + list =rcu_dereference (drop_reasons_by_subsys[SKB_DROP_REASON_SUBSYS_CORE ]); + subsys_reason =SKB_DROP_REASON_NOT_SPECIFIED ; + }if (nla_put_string (msg,NET_DM_ATTR_REASON , - drop_reasons[cb->reason])) + list->reasons[subsys_reason])) { +rcu_read_unlock (); goto nla_put_failure; + } +rcu_read_unlock ();snprintf (buf,sizeof (buf),"%pS" , cb->pc);if (nla_put_string (msg,NET_DM_ATTR_SYMBOL , buf))
@@ -687,9 +704,7 @@ static void net_dm_packet_report(struct sk_buff *skb)if (net_dm_trunc_len) payload_len =min_t (size_t, net_dm_trunc_len, payload_len); - msg =nlmsg_new (net_dm_packet_report_size (payload_len, -NET_DM_SKB_CB (skb)->reason), -GFP_KERNEL ); + msg =nlmsg_new (net_dm_packet_report_size (payload_len),GFP_KERNEL );if (!msg) goto out;
net/core/skbuff.c +56 -3
86 lines not on this page · raw message
Signature · 1 line
2.40.0
Re: [PATCH net-next v4 2/3] net: extend drop reasons for multiple subsystems
Quoted 10 lines · Johannes Berg
From: Johannes Berg <[email protected]>
Extend drop reasons to make them usable by subsystems other than core by reserving the high 16 bits for a new subsystem ID, of which 0 of course is used for the existing reasons immediately.
To still be able to have string reasons, restructure that code a bit to make the loopup under RCU, the only user of this (right now) is
drop_monitor.
Hi Johannes,
a minor nit from my side that you may want to address if you need to re-spin for some other reason:
s/loopup/lookup/
Johannes Berg
maintainerPATCH v4 3/3 mac80211: use the new drop reasons infrastructure
In reply to Johannes BergFrom: Johannes Berg <[email protected]>
It can be really hard to analyse or debug why packets are going missing in mac80211, so add the needed infrastructure to use use the new per-subsystem drop reasons.
We actually use two drop reason subsystems here because of the different handling of frames that are dropped but still go to monitor for old versions of hostapd, and those that are just completely unusable (e.g. crypto failed.)
Annotate a few reasons here just to illustrate this, we'll need to go through and annotate more of them later.
---
v4: fix kernel-doc
--- include/net/dropreason.h | 12 ++++++++ net/mac80211/drop.h | 56 ++++++++++++++++++++++++++++++++++ net/mac80211/ieee80211_i.h | 8 +---- net/mac80211/main.c | 31 +++++++++++++++++++ net/mac80211/rx.c | 61 ++++++++++++++++++-------------------- net/mac80211/wpa.c | 24 +++++++-------- 6 files changed, 141 insertions(+), 51 deletions(-) create mode 100644 net/mac80211/drop.h
include/net/dropreason.h +12 -0
@@ -11,6 +11,18 @@ enum skb_drop_reason_subsys {/** @SKB_DROP_REASON_SUBSYS_CORE: core drop reasons defined above */ SKB_DROP_REASON_SUBSYS_CORE , +/** +* @SKB_DROP_REASON_SUBSYS_MAC80211_UNUSABLE: mac80211 drop reasons +* for unusable frames, see net/mac80211/drop.h +*/ +SKB_DROP_REASON_SUBSYS_MAC80211_UNUSABLE , + +/** +* @SKB_DROP_REASON_SUBSYS_MAC80211_MONITOR: mac80211 drop reasons +* for frames still going to monitor, see net/mac80211/drop.h +*/ +SKB_DROP_REASON_SUBSYS_MAC80211_MONITOR , +/** @SKB_DROP_REASON_SUBSYS_NUM: number of subsystems defined */ SKB_DROP_REASON_SUBSYS_NUM };
net/mac80211/drop.h new file +56 -0
56 lines not on this page · raw message
net/mac80211/ieee80211_i.h +1 -7
@@ -33,6 +33,7 @@#include "key.h" #include "sta_info.h" #include "debug.h" +#include "drop.h" extern const struct cfg80211_ops mac80211_config_ops;
@@ -170,13 +171,6 @@ struct ieee80211_tx_data {unsigned int flags; }; - -typedef unsigned __bitwise ieee80211_rx_result ; -#define RX_CONTINUE ((__force ieee80211_rx_result) 0u) -#define RX_DROP_UNUSABLE ((__force ieee80211_rx_result) 1u) -#define RX_DROP_MONITOR ((__force ieee80211_rx_result) 2u) -#define RX_QUEUED ((__force ieee80211_rx_result) 3u) -/** * enum ieee80211_packet_rx_flags - packet RX flags * @IEEE80211_RX_AMSDU: a-MSDU packet
net/mac80211/main.c +31 -0
@@ -22,6 +22,7 @@#include <linux/bitmap.h> #include <linux/inetdevice.h> #include <net/net_namespace.h> +#include <net/dropreason.h> #include <net/cfg80211.h> #include <net/addrconf.h>
@@ -1542,6 +1543,28 @@ void ieee80211_free_hw(struct ieee80211_hw *hw) }EXPORT_SYMBOL (ieee80211_free_hw); +static const char *const drop_reasons_monitor[] = { +#define V(x) #x, + [0 ] ="RX_DROP_MONITOR" , +MAC80211_DROP_REASONS_MONITOR (V ) +}; + +static struct drop_reason_list drop_reason_list_monitor = { + .reasons = drop_reasons_monitor, + .n_reasons =ARRAY_SIZE (drop_reasons_monitor), +}; + +static const char *const drop_reasons_unusable[] = { + [0 ] ="RX_DROP_UNUSABLE" , +MAC80211_DROP_REASONS_UNUSABLE (V ) +#undef V +}; + +static struct drop_reason_list drop_reason_list_unusable = { + .reasons = drop_reasons_unusable, + .n_reasons =ARRAY_SIZE (drop_reasons_unusable), +}; +static int __init ieee80211_init (void ) {struct sk_buff *skb;
@@ -1559,6 +1582,11 @@ static int __init ieee80211_init(void)if (ret) goto err_netdev; +drop_reasons_register_subsys (SKB_DROP_REASON_SUBSYS_MAC80211_MONITOR , + &drop_reason_list_monitor); +drop_reasons_register_subsys (SKB_DROP_REASON_SUBSYS_MAC80211_UNUSABLE , + &drop_reason_list_unusable); +return 0 ; err_netdev:rc80211_minstrel_exit ();
@@ -1574,6 +1602,9 @@ static void __exit ieee80211_exit(void)ieee80211_iface_exit (); +drop_reasons_unregister_subsys (SKB_DROP_REASON_SUBSYS_MAC80211_MONITOR ); +drop_reasons_unregister_subsys (SKB_DROP_REASON_SUBSYS_MAC80211_UNUSABLE ); +rcu_barrier (); }
net/mac80211/rx.c +29 -32
99 lines not on this page · raw message
net/mac80211/wpa.c +12 -12
@@ -550,7 +550,7 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx,if (res <0 || (!res && !(status->flag &RX_FLAG_ALLOW_SAME_PN ))) { key->u.ccmp.replays++; -return RX_DROP_UNUSABLE ; +return RX_DROP_U_REPLAY ; }if (!(status->flag &RX_FLAG_DECRYPTED )) {
@@ -564,7 +564,7 @@ ieee80211_crypto_ccmp_decrypt(struct ieee80211_rx_data *rx, skb->data + hdrlen +IEEE80211_CCMP_HDR_LEN , data_len, skb->data + skb->len - mic_len)) - return RX_DROP_UNUSABLE; + return RX_DROP_U_MIC_FAIL; }memcpy (key->u.ccmp.rx_pn[queue], pn,IEEE80211_CCMP_PN_LEN );
@@ -746,7 +746,7 @@ ieee80211_crypto_gcmp_decrypt(struct ieee80211_rx_data *rx)if (res <0 || (!res && !(status->flag &RX_FLAG_ALLOW_SAME_PN ))) { key->u.gcmp.replays++; -return RX_DROP_UNUSABLE ; +return RX_DROP_U_REPLAY ; }if (!(status->flag &RX_FLAG_DECRYPTED )) {
@@ -761,7 +761,7 @@ ieee80211_crypto_gcmp_decrypt(struct ieee80211_rx_data *rx) data_len, skb->data + skb->len - IEEE80211_GCMP_MIC_LEN)) -return RX_DROP_UNUSABLE ; +return RX_DROP_U_MIC_FAIL ; }memcpy (key->u.gcmp.rx_pn[queue], pn,IEEE80211_GCMP_PN_LEN );
@@ -930,13 +930,13 @@ ieee80211_crypto_aes_cmac_decrypt(struct ieee80211_rx_data *rx) (skb->data + skb->len -sizeof (*mmie));if (mmie->element_id !=WLAN_EID_MMIE || mmie->length !=sizeof (*mmie) -2 ) -return RX_DROP_UNUSABLE ;/* Invalid MMIE */ +return RX_DROP_U_BAD_MMIE ;/* Invalid MMIE */ bip_ipn_swap (ipn, mmie->sequence_number);if (memcmp (ipn, key->u.aes_cmac.rx_pn,6 ) <=0 ) { key->u.aes_cmac.replays++; -return RX_DROP_UNUSABLE ; +return RX_DROP_U_REPLAY ; }if (!(status->flag &RX_FLAG_DECRYPTED )) {
@@ -946,7 +946,7 @@ ieee80211_crypto_aes_cmac_decrypt(struct ieee80211_rx_data *rx) skb->data + 24, skb->len - 24, mic);if (crypto_memneq (mic, mmie->mic,sizeof (mmie->mic))) { key->u.aes_cmac.icverrors++; -return RX_DROP_UNUSABLE ; +return RX_DROP_U_MIC_FAIL ; } }
@@ -986,7 +986,7 @@ ieee80211_crypto_aes_cmac_256_decrypt(struct ieee80211_rx_data *rx)if (memcmp (ipn, key->u.aes_cmac.rx_pn,6 ) <=0 ) { key->u.aes_cmac.replays++; -return RX_DROP_UNUSABLE ; +return RX_DROP_U_REPLAY ; }if (!(status->flag &RX_FLAG_DECRYPTED )) {
@@ -996,7 +996,7 @@ ieee80211_crypto_aes_cmac_256_decrypt(struct ieee80211_rx_data *rx) skb->data + 24, skb->len - 24, mic);if (crypto_memneq (mic, mmie->mic,sizeof (mmie->mic))) { key->u.aes_cmac.icverrors++; -return RX_DROP_UNUSABLE ; +return RX_DROP_U_MIC_FAIL ; } }
@@ -1079,13 +1079,13 @@ ieee80211_crypto_aes_gmac_decrypt(struct ieee80211_rx_data *rx) (skb->data + skb->len -sizeof (*mmie));if (mmie->element_id !=WLAN_EID_MMIE || mmie->length !=sizeof (*mmie) -2 ) -return RX_DROP_UNUSABLE ;/* Invalid MMIE */ +return RX_DROP_U_BAD_MMIE ;/* Invalid MMIE */ bip_ipn_swap (ipn, mmie->sequence_number);if (memcmp (ipn, key->u.aes_gmac.rx_pn,6 ) <=0 ) { key->u.aes_gmac.replays++; -return RX_DROP_UNUSABLE ; +return RX_DROP_U_REPLAY ; }if (!(status->flag &RX_FLAG_DECRYPTED )) {
@@ -1104,7 +1104,7 @@ ieee80211_crypto_aes_gmac_decrypt(struct ieee80211_rx_data *rx) crypto_memneq(mic, mmie->mic, sizeof(mmie->mic))) { key->u.aes_gmac.icverrors++;kfree (mic); -return RX_DROP_UNUSABLE ; +return RX_DROP_U_MIC_FAIL ; }kfree (mic); }
Signature · 1 line
2.40.0
Re: [PATCH net-next v4 3/3] mac80211: use the new drop reasons infrastructure
Quoted 5 lines · Johannes Berg
From: Johannes Berg <[email protected]>
It can be really hard to analyse or debug why packets are going missing in mac80211, so add the needed infrastructure to use use the new per-subsystem drop reasons.
Hi Johannes,
a minor nit from my side that you may want to address if you need to re-spin for some other reason:
s/use use/use/
...
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 6 lines · On Wed, 19 Apr 2023 14:52:51 +0200 you wrote:
Hi,
Here's v4 of the extended drop reasons, with fixes to kernel-doc and checkpatch.
johannes
Here is the summary with links:
- [net-next,v4,1/3] net: move dropreason.h to dropreason-core.h
https://git.kernel.org/netdev/net-next/c/5b8285cca6fe - [net-next,v4,2/3] net: extend drop reasons for multiple subsystems https://git.kernel.org/netdev/net-next/c/071c0fc6fb91
- [net-next,v4,3/3] mac80211: use the new drop reasons infrastructure (no matching commit)
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html