net: vxlan: add skb drop reasons support
Subsystems (3)
v2 cover net: vxlan: add skb drop reasons support
In this series, we add skb drop reasons to the vxlan module. After the commit 071c0fc6fb91 ("net: extend drop reasons for multiple subsystems"), we can add the skb drop reasons as a subsystem.
So, we now add a new skb drop reason subsystem for vxlan, and following new skb drop reasons are introduced to vxlan:
VXLAN_DROP_INVALID_SMAC
VXLAN_DROP_ENTRY_EXISTS
VXLAN_DROP_INVALID_HDR
VXLAN_DROP_VNI_NOT_FOUND
VXLAN_DROP_NO_REMOTE
And we add the following drop reasons to enum skb_drop_reason:
IP_TUNNEL_ECN
TUNNEL_TXINFO
Changes since v1:
- document all the drop reaons that we introduce
- rename the drop reasons to make them more descriptive, as Ido advised
- remove the 2nd patch, which introduce the SKB_DR_RESET
- add the 4th patch, which adds skb_vlan_inet_prepare_reason() helper
- introduce the 6th patch, which make vxlan_set_mac return drop reasons
- introduce the 10th patch, which uses VXLAN_DROP_NO_REMOTE as the drop reasons, as Ido advised
Menglong Dong (12):
net: vxlan: add vxlan to the drop reason subsystem
net: skb: add pskb_network_may_pull_reason() helper
net: tunnel: add pskb_inet_may_pull_reason() helper
net: tunnel: add skb_vlan_inet_prepare_reason() helper
net: vxlan: make vxlan_remcsum() return drop reasons
net: vxlan: make vxlan_set_mac() return drop reasons
net: vxlan: add skb drop reasons to vxlan_rcv()
net: vxlan: use vxlan_kfree_skb() in vxlan_xmit()
net: vxlan: add drop reasons support to vxlan_xmit_one()
net: vxlan: use kfree_skb_reason in vxlan_mdb_xmit
net: vxlan: use kfree_skb_reason in vxlan_encap_bypass
net: vxlan: use vxlan_kfree_skb in encap_bypass_if_local
drivers/net/vxlan/drop.h | 47 ++++++++++++++ drivers/net/vxlan/vxlan_core.c | 104 +++++++++++++++++++++--------- drivers/net/vxlan/vxlan_mdb.c | 2 +- drivers/net/vxlan/vxlan_private.h | 1 + include/linux/skbuff.h | 8 ++- include/net/dropreason-core.h | 9 +++ include/net/dropreason.h | 6 ++ include/net/ip_tunnels.h | 31 ++++++--- 8 files changed, 168 insertions(+), 40 deletions(-) create mode 100644 drivers/net/vxlan/drop.h
Signature · 1 line
2.39.2
PATCH v2 1/12 net: vxlan: add vxlan to the drop reason subsystem
In this commit, we introduce the SKB_DROP_REASON_SUBSYS_VXLAN to make the vxlan support skb drop reasons.
--- drivers/net/vxlan/drop.h | 25 +++++++++++++++++++++++++ drivers/net/vxlan/vxlan_core.c | 15 +++++++++++++++ drivers/net/vxlan/vxlan_private.h | 1 + include/net/dropreason.h | 6 ++++++ 4 files changed, 47 insertions(+) create mode 100644 drivers/net/vxlan/drop.h
drivers/net/vxlan/drop.h new file +25 -0
@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* VXLAN drop reason list. +*/ + +#ifndef VXLAN_DROP_H +#define VXLAN_DROP_H +#include <linux/skbuff.h> +#include <net/dropreason.h> + +#define VXLAN_DROP_REASONS (R ) \ +/* deliberate comment for trailing \ */ + +enum vxlan_drop_reason { + __VXLAN_DROP_REASON =SKB_DROP_REASON_SUBSYS_VXLAN << +SKB_DROP_REASON_SUBSYS_SHIFT , +}; + +static inline void +vxlan_kfree_skb (struct sk_buff *skb,enum vxlan_drop_reason reason) +{ +kfree_skb_reason (skb, (u32 )reason); +} + +#endif /* VXLAN_DROP_H */
drivers/net/vxlan/vxlan_core.c +15 -0
@@ -4833,6 +4833,17 @@ static int vxlan_nexthop_event(struct notifier_block *nb,return NOTIFY_DONE ; } +static const char *const vxlan_drop_reasons[] = { +#define S(x) [(x) & ~SKB_DROP_REASON_SUBSYS_MASK] = (#x), + VXLAN_DROP_REASONS(S) +#undef S +}; + +static struct drop_reason_list drop_reason_list_vxlan = { + .reasons = vxlan_drop_reasons, + .n_reasons =ARRAY_SIZE (vxlan_drop_reasons), +}; +static __net_init int vxlan_init_net (struct net *net) {struct vxlan_net *vn =net_generic (net, vxlan_net_id);
@@ -4914,6 +4925,9 @@ static int __init vxlan_init_module(void)vxlan_vnifilter_init (); +drop_reasons_register_subsys (SKB_DROP_REASON_SUBSYS_VXLAN , + &drop_reason_list_vxlan); +return 0 ; out4:unregister_switchdev_notifier (&vxlan_switchdev_notifier_block);
@@ -4928,6 +4942,7 @@ late_initcall(vxlan_init_module); static void __exit vxlan_cleanup_module(void) { +drop_reasons_unregister_subsys (SKB_DROP_REASON_SUBSYS_VXLAN );vxlan_vnifilter_uninit ();rtnl_link_unregister (&vxlan_link_ops);unregister_switchdev_notifier (&vxlan_switchdev_notifier_block);
drivers/net/vxlan/vxlan_private.h +1 -0
@@ -8,6 +8,7 @@#define _VXLAN_PRIVATE_H#include <linux/rhashtable.h> +#include "drop.h" extern unsigned int vxlan_net_id;extern const u8 all_zeros_mac[ETH_ALEN +2 ];
include/net/dropreason.h +6 -0
@@ -29,6 +29,12 @@ enum skb_drop_reason_subsys {*/ SKB_DROP_REASON_SUBSYS_OPENVSWITCH , +/** +* @SKB_DROP_REASON_SUBSYS_VXLAN: vxlan drop reason, see +* drivers/net/vxlan/drop.h +*/ +SKB_DROP_REASON_SUBSYS_VXLAN , +/** @SKB_DROP_REASON_SUBSYS_NUM: number of subsystems defined */ SKB_DROP_REASON_SUBSYS_NUM };
Signature · 1 line
2.39.2
Re: [PATCH net-next v2 01/12] net: vxlan: add vxlan to the drop reason subsystem
From: Menglong Dong <[email protected]>
Date: Fri, 30 Aug 2024 09:59:50 +0800
Quoted 18 lines
In this commit, we introduce the
SKB_DROP_REASON_SUBSYS_VXLANto make the vxlan support skb drop reasons.Signed-off-by Menglong Dong <[email protected]>--- drivers/net/vxlan/drop.h | 25 +++++++++++++++++++++++++ drivers/net/vxlan/vxlan_core.c | 15 +++++++++++++++ drivers/net/vxlan/vxlan_private.h | 1 + include/net/dropreason.h | 6 ++++++ 4 files changed, 47 insertions(+) create mode 100644 drivers/net/vxlan/drop.hdrivers/net/vxlan/drop.h new file +0
-0
drivers/net/vxlan/drop.h line 7
Quoted 7 lines
drivers/net/vxlan/drop.h new file +7
-0@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* VXLAN drop reason list. +*/ + +#ifndef VXLAN_DROP_H +#define VXLAN_DROP_H
Empty newline here please after the guard.
drivers/net/vxlan/drop.h line 16
Quoted 9 lines
drivers/net/vxlan/drop.h new file +9
-0+#include <linux/skbuff.h> +#include <net/dropreason.h> + +#define VXLAN_DROP_REASONS (R ) \ +/* deliberate comment for trailing \ */ + +enum vxlan_drop_reason { + __VXLAN_DROP_REASON =SKB_DROP_REASON_SUBSYS_VXLAN << +SKB_DROP_REASON_SUBSYS_SHIFT ,
Maybe make SHIFT start at the same position as VXLAN, i.e. align the former to the latter?
[...]
drivers/net/vxlan/vxlan_private.h line 10
Quoted 8 lines
drivers/net/vxlan/vxlan_private.h +0
-0@@ -8,6 +8,7 @@#define _VXLAN_PRIVATE_H#include <linux/rhashtable.h>
Also an empty newline here.
Quoted 9 lines
drivers/net/vxlan/vxlan_private.h +1
-0+#include "drop.h" extern unsigned int vxlan_net_id;extern const u8 all_zeros_mac[ETH_ALEN +2 ];include/net/dropreason.h +0
-0
include/net/dropreason.h enum skb_drop_reason_subsys { · line 33
Quoted 5 lines
include/net/dropreason.h +2
-0@@ -29,6 +29,12 @@ enum skb_drop_reason_subsys {*/ SKB_DROP_REASON_SUBSYS_OPENVSWITCH, +/** +* @SKB_DROP_REASON_SUBSYS_VXLAN: vxlan drop reason, see
"VXLAN", uppercase?
include/net/dropreason.h enum skb_drop_reason_subsys { · line 40
Quoted 7 lines
include/net/dropreason.h +4
-0+* drivers/net/vxlan/drop.h +*/ +SKB_DROP_REASON_SUBSYS_VXLAN , +/** @SKB_DROP_REASON_SUBSYS_NUM: number of subsystems defined */ SKB_DROP_REASON_SUBSYS_NUM };
Thanks,
Olek
Re: [PATCH net-next v2 01/12] net: vxlan: add vxlan to the drop reason subsystem
Quoted 32 lines · Alexander Lobakin
From: Menglong Dong <[email protected]>
Date: Fri, 30 Aug 2024 09:59:50 +0800Quoted 18 lines
In this commit, we introduce the
SKB_DROP_REASON_SUBSYS_VXLANto make the vxlan support skb drop reasons.Signed-off-by Menglong Dong <[email protected]>--- drivers/net/vxlan/drop.h | 25 +++++++++++++++++++++++++ drivers/net/vxlan/vxlan_core.c | 15 +++++++++++++++ drivers/net/vxlan/vxlan_private.h | 1 + include/net/dropreason.h | 6 ++++++ 4 files changed, 47 insertions(+) create mode 100644 drivers/net/vxlan/drop.hdrivers/net/vxlan/drop.h new file +0
-0drivers/net/vxlan/drop.h line 7
Quoted 7 lines
drivers/net/vxlan/drop.h new file +7
-0@@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* VXLAN drop reason list. +*/ + +#ifndef VXLAN_DROP_H +#define VXLAN_DROP_H Empty newline here please after the guard.
Quoted 13 lines
drivers/net/vxlan/drop.h line 16
Quoted 9 lines
drivers/net/vxlan/drop.h new file +9
-0+#include <linux/skbuff.h> +#include <net/dropreason.h> + +#define VXLAN_DROP_REASONS (R ) \ +/* deliberate comment for trailing \ */ + +enum vxlan_drop_reason { + __VXLAN_DROP_REASON =SKB_DROP_REASON_SUBSYS_VXLAN << +SKB_DROP_REASON_SUBSYS_SHIFT ,Maybe make SHIFT start at the same position as VXLAN, i.e. align the former to the latter?
Yeah, that looks better.
Quoted 25 lines
[...]
drivers/net/vxlan/vxlan_private.h line 10
Quoted 8 lines
drivers/net/vxlan/vxlan_private.h +0
-0@@ -8,6 +8,7 @@#define _VXLAN_PRIVATE_H#include <linux/rhashtable.h> Also an empty newline here.
Quoted 12 lines
drivers/net/vxlan/vxlan_private.h +1
-0+#include "drop.h" extern unsigned int vxlan_net_id;extern const u8 all_zeros_mac[ETH_ALEN +2 ];include/net/dropreason.h +0
-0@@ -29,6 +29,12 @@ enum skb_drop_reason_subsys {*/ SKB_DROP_REASON_SUBSYS_OPENVSWITCH,
Quoted 5 lines
include/net/dropreason.h enum skb_drop_reason_subsys { · line 33
Quoted 2 lines
include/net/dropreason.h +2
-0+/** +* @SKB_DROP_REASON_SUBSYS_VXLAN: vxlan drop reason, see "VXLAN", uppercase?
Okay! I'll change this commit as you advised.
Thanks!
Menglong Dong
Quoted 10 lines
include/net/dropreason.h enum skb_drop_reason_subsys { · line 40
Quoted 7 lines
include/net/dropreason.h +4
-0+* drivers/net/vxlan/drop.h +*/ +SKB_DROP_REASON_SUBSYS_VXLAN , +/** @SKB_DROP_REASON_SUBSYS_NUM: number of subsystems defined */ SKB_DROP_REASON_SUBSYS_NUM };Thanks,
Olek
PATCH v2 2/12 net: skb: add pskb_network_may_pull_reason() helper
In reply to Menglong DongIntroduce the function pskb_network_may_pull_reason() and make pskb_network_may_pull() a simple inline call to it. The drop reasons of it just come from pskb_may_pull_reason.
--- include/linux/skbuff.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
include/linux/skbuff.h +7 -1
@@ -3114,9 +3114,15 @@ static inline int skb_inner_network_offset(const struct sk_buff *skb)return skb_inner_network_header (skb) - skb->data; } +static inline enum skb_drop_reason +pskb_network_may_pull_reason (struct sk_buff *skb,unsigned int len) +{ +return pskb_may_pull_reason (skb,skb_network_offset (skb) + len); +} +static inline int pskb_network_may_pull (struct sk_buff *skb,unsigned int len) { -return pskb_may_pull (skb,skb_network_offset (skb) + len); +return pskb_network_may_pull_reason (skb, len) ==SKB_NOT_DROPPED_YET ; }/*
Signature · 1 line
2.39.2
Re: [PATCH net-next v2 02/12] net: skb: add pskb_network_may_pull_reason() helper
From: Menglong Dong <[email protected]>
Date: Fri, 30 Aug 2024 09:59:51 +0800
Quoted 3 lines
Introduce the function
pskb_network_may_pull_reason()and makepskb_network_may_pull()a simple inline call to it. The drop reasons of it just come frompskb_may_pull_reason.
No object code changes I guess? Have you checked it via scripts/bloat-o-meter?
Quoted 17 lines
Signed-off-by Menglong Dong <[email protected]>--- include/linux/skbuff.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)include/linux/skbuff.h +3
-0@@ -3114,9 +3114,15 @@ static inline int skb_inner_network_offset(const struct sk_buff *skb)return skb_inner_network_header (skb) - skb->data; } +static inline enum skb_drop_reason +pskb_network_may_pull_reason (struct sk_buff *skb,unsigned int len) +{
include/linux/skbuff.h static inline int skb_inner_network_offset(const struct sk_buff *skb) · line 3128
Quoted 10 lines
include/linux/skbuff.h +4
-1+return pskb_may_pull_reason (skb,skb_network_offset (skb) + len); +} +static inline int pskb_network_may_pull (struct sk_buff *skb,unsigned int len) { -return pskb_may_pull (skb,skb_network_offset (skb) + len); +return pskb_network_may_pull_reason (skb, len) ==SKB_NOT_DROPPED_YET ; }/*
Thanks,
Olek
Re: [PATCH net-next v2 02/12] net: skb: add pskb_network_may_pull_reason() helper
Quoted 11 lines · Alexander Lobakin
From: Menglong Dong <[email protected]>
Date: Fri, 30 Aug 2024 09:59:51 +0800Quoted 3 lines
Introduce the function
pskb_network_may_pull_reason()and makepskb_network_may_pull()a simple inline call to it. The drop reasons of it just come frompskb_may_pull_reason.No object code changes I guess? Have you checked it via
scripts/bloat-o-meter?
Not yet. I'll have a try on it.
Quoted 30 lines
Quoted 17 lines
Signed-off-by Menglong Dong <[email protected]>--- include/linux/skbuff.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)include/linux/skbuff.h +3
-0@@ -3114,9 +3114,15 @@ static inline int skb_inner_network_offset(const struct sk_buff *skb)return skb_inner_network_header (skb) - skb->data; } +static inline enum skb_drop_reason +pskb_network_may_pull_reason (struct sk_buff *skb,unsigned int len) +{include/linux/skbuff.h static inline int skb_inner_network_offset(const struct sk_buff *skb) · line 3128
Quoted 10 lines
include/linux/skbuff.h +4
-1+return pskb_may_pull_reason (skb,skb_network_offset (skb) + len); +} +static inline int pskb_network_may_pull (struct sk_buff *skb,unsigned int len) { -return pskb_may_pull (skb,skb_network_offset (skb) + len); +return pskb_network_may_pull_reason (skb, len) ==SKB_NOT_DROPPED_YET ; }/* Thanks,
Olek
PATCH v2 3/12 net: tunnel: add pskb_inet_may_pull_reason() helper
In reply to Menglong DongIntroduce the function pskb_inet_may_pull_reason() and make pskb_inet_may_pull a simple inline call to it. The drop reasons of it just come from pskb_may_pull_reason().
--- include/net/ip_tunnels.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)
include/net/ip_tunnels.h +8 -2
@@ -439,7 +439,8 @@ int ip_tunnel_encap_del_ops(const struct ip_tunnel_encap_ops *op,int ip_tunnel_encap_setup (struct ip_tunnel *t,struct ip_tunnel_encap *ipencap); -static inline bool pskb_inet_may_pull (struct sk_buff *skb) +static inline enum skb_drop_reason +pskb_inet_may_pull_reason (struct sk_buff *skb) {int nhlen;
@@ -456,7 +457,12 @@ static inline bool pskb_inet_may_pull(struct sk_buff *skb) nhlen =0 ; } -return pskb_network_may_pull (skb, nhlen); +return pskb_network_may_pull_reason (skb, nhlen); +} + +static inline bool pskb_inet_may_pull (struct sk_buff *skb) +{ +return pskb_inet_may_pull_reason (skb) ==SKB_NOT_DROPPED_YET ; }/* Variant of pskb_inet_may_pull().
Signature · 1 line
2.39.2
PATCH v2 4/12 net: tunnel: add skb_vlan_inet_prepare_reason() helper
In reply to Menglong DongIntroduce the function skb_vlan_inet_prepare_reason() and make skb_vlan_inet_prepare an inline call to it. The drop reasons of it just come from pskb_may_pull_reason.
--- include/net/ip_tunnels.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
include/net/ip_tunnels.h +15 -6
@@ -465,13 +465,14 @@ static inline bool pskb_inet_may_pull(struct sk_buff *skb)return pskb_inet_may_pull_reason (skb) ==SKB_NOT_DROPPED_YET ; } -/* Variant of pskb_inet_may_pull(). +/* Variant of pskb_inet_may_pull_reason(). */ -static inline bool skb_vlan_inet_prepare (struct sk_buff *skb, -bool inner_proto_inherit) +static inline enum skb_drop_reason +skb_vlan_inet_prepare_reason (struct sk_buff *skb,bool inner_proto_inherit) {int nhlen =0 , maclen = inner_proto_inherit ?0 :ETH_HLEN ;__be16 type = skb->protocol; +enum skb_drop_reason reason;/* Essentially this is skb_protocol(skb, true) * And we get MAC len.
@@ -492,11 +493,19 @@ static inline bool skb_vlan_inet_prepare(struct sk_buff *skb,/* For ETH_P_IPV6/ETH_P_IP we make sure to pull * a base network header in skb->head. */ -if (!pskb_may_pull (skb, maclen + nhlen)) -return false; + reason =pskb_may_pull_reason (skb, maclen + nhlen); +if (reason) +return reason;skb_set_network_header (skb, maclen); -return true; +return SKB_NOT_DROPPED_YET ; +} + +static inline bool skb_vlan_inet_prepare (struct sk_buff *skb, +bool inner_proto_inherit) +{ +return skb_vlan_inet_prepare_reason (skb, inner_proto_inherit) == +SKB_NOT_DROPPED_YET ; }static inline int ip_encap_hlen (struct ip_tunnel_encap *e)
Signature · 1 line
2.39.2
Re: [PATCH net-next v2 04/12] net: tunnel: add skb_vlan_inet_prepare_reason() helper
From: Menglong Dong <[email protected]>
Date: Fri, 30 Aug 2024 09:59:53 +0800
Quoted 34 lines
Introduce the function
skb_vlan_inet_prepare_reason()and makeskb_vlan_inet_preparean inline call to it. The drop reasons of it just come frompskb_may_pull_reason.Signed-off-by Menglong Dong <[email protected]>--- include/net/ip_tunnels.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)include/net/ip_tunnels.h +4
-3@@ -465,13 +465,14 @@ static inline bool pskb_inet_may_pull(struct sk_buff *skb)return pskb_inet_may_pull_reason (skb) ==SKB_NOT_DROPPED_YET ; } -/* Variant of pskb_inet_may_pull(). +/* Variant of pskb_inet_may_pull_reason(). */ -static inline bool skb_vlan_inet_prepare (struct sk_buff *skb, -bool inner_proto_inherit) +static inline enum skb_drop_reason +skb_vlan_inet_prepare_reason (struct sk_buff *skb,bool inner_proto_inherit) {int nhlen =0 , maclen = inner_proto_inherit ?0 :ETH_HLEN ;__be16 type = skb->protocol; +enum skb_drop_reason reason;/* Essentially this is skb_protocol(skb, true) * And we get MAC len. @@ -492,11 +493,19 @@ static inline bool skb_vlan_inet_prepare(struct sk_buff *skb,/* For ETH_P_IPV6/ETH_P_IP we make sure to pull * a base network header in skb->head.
include/net/ip_tunnels.h static inline bool skb_vlan_inet_prepare(struct sk_buff *skb, · line 501
Quoted 10 lines
include/net/ip_tunnels.h +4
-3*/ -if (!pskb_may_pull (skb, maclen + nhlen)) -return false; + reason =pskb_may_pull_reason (skb, maclen + nhlen); +if (reason) +return reason;skb_set_network_header (skb, maclen); -return true; +return SKB_NOT_DROPPED_YET ;
An empty newline before the return as we usually do?
include/net/ip_tunnels.h static inline bool skb_vlan_inet_prepare(struct sk_buff *skb, · line 508
Quoted 7 lines
include/net/ip_tunnels.h +7
-0+} + +static inline bool skb_vlan_inet_prepare (struct sk_buff *skb, +bool inner_proto_inherit) +{ +return skb_vlan_inet_prepare_reason (skb, inner_proto_inherit) == +SKB_NOT_DROPPED_YET ;
This line must be aligned to skb_vlan_blah, IOW you need 7 spaces, not 1 tab here.
include/net/ip_tunnels.h static inline bool skb_vlan_inet_prepare(struct sk_buff *skb, · line 511
Quoted 3 lines
include/net/ip_tunnels.h +0
-0}static inline int ip_encap_hlen (struct ip_tunnel_encap *e)
Thanks,
Olek
Re: [PATCH net-next v2 04/12] net: tunnel: add skb_vlan_inet_prepare_reason() helper
Quoted 51 lines · Alexander Lobakin
From: Menglong Dong <[email protected]>
Date: Fri, 30 Aug 2024 09:59:53 +0800Quoted 34 lines
Introduce the function
skb_vlan_inet_prepare_reason()and makeskb_vlan_inet_preparean inline call to it. The drop reasons of it just come frompskb_may_pull_reason.Signed-off-by Menglong Dong <[email protected]>--- include/net/ip_tunnels.h | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)include/net/ip_tunnels.h +4
-3@@ -465,13 +465,14 @@ static inline bool pskb_inet_may_pull(struct sk_buff *skb)return pskb_inet_may_pull_reason (skb) ==SKB_NOT_DROPPED_YET ; } -/* Variant of pskb_inet_may_pull(). +/* Variant of pskb_inet_may_pull_reason(). */ -static inline bool skb_vlan_inet_prepare (struct sk_buff *skb, -bool inner_proto_inherit) +static inline enum skb_drop_reason +skb_vlan_inet_prepare_reason (struct sk_buff *skb,bool inner_proto_inherit) {int nhlen =0 , maclen = inner_proto_inherit ?0 :ETH_HLEN ;__be16 type = skb->protocol; +enum skb_drop_reason reason;/* Essentially this is skb_protocol(skb, true) * And we get MAC len. @@ -492,11 +493,19 @@ static inline bool skb_vlan_inet_prepare(struct sk_buff *skb,/* For ETH_P_IPV6/ETH_P_IP we make sure to pull * a base network header in skb->head. include/net/ip_tunnels.h static inline bool skb_vlan_inet_prepare(struct sk_buff *skb, · line 501
Quoted 10 lines
include/net/ip_tunnels.h +4
-3*/ -if (!pskb_may_pull (skb, maclen + nhlen)) -return false; + reason =pskb_may_pull_reason (skb, maclen + nhlen); +if (reason) +return reason;skb_set_network_header (skb, maclen); -return true; +return SKB_NOT_DROPPED_YET ;An empty newline before the return as we usually do?
Quoted 11 lines
include/net/ip_tunnels.h static inline bool skb_vlan_inet_prepare(struct sk_buff *skb, · line 508
Quoted 7 lines
include/net/ip_tunnels.h +7
-0+} + +static inline bool skb_vlan_inet_prepare (struct sk_buff *skb, +bool inner_proto_inherit) +{ +return skb_vlan_inet_prepare_reason (skb, inner_proto_inherit) == +SKB_NOT_DROPPED_YET ;This line must be aligned to
skb_vlan_blah, IOW you need 7 spaces, not 1 tab here.
Okay! I'll follow your advice of the format in this series.
Thanks!
Menglong Dong
Quoted 6 lines
include/net/ip_tunnels.h static inline bool skb_vlan_inet_prepare(struct sk_buff *skb, · line 511
Quoted 3 lines
include/net/ip_tunnels.h +0
-0}static inline int ip_encap_hlen (struct ip_tunnel_encap *e)Thanks,
Olek
PATCH v2 5/12 net: vxlan: make vxlan_remcsum() return drop reasons
In reply to Menglong DongMake vxlan_remcsum() support skb drop reasons by changing the return value type of it from bool to enum skb_drop_reason.
The only drop reason in vxlan_remcsum() comes from pskb_may_pull_reason(), so we just return it.
--- drivers/net/vxlan/vxlan_core.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/net/vxlan/vxlan_core.c +8 -5
@@ -1551,9 +1551,11 @@ static void vxlan_sock_release(struct vxlan_dev *vxlan)#endif } -static bool vxlan_remcsum (struct vxlanhdr *unparsed, -struct sk_buff *skb,u32 vxflags) +static enum skb_drop_reason vxlan_remcsum (struct vxlanhdr *unparsed, +struct sk_buff *skb, +u32 vxflags) { +enum skb_drop_reason reason;size_t start, offset;if (!(unparsed->vx_flags &VXLAN_HF_RCO ) || skb->remcsum_offload)
@@ -1562,15 +1564,16 @@ static bool vxlan_remcsum(struct vxlanhdr *unparsed, start =vxlan_rco_start (unparsed->vx_vni); offset = start +vxlan_rco_offset (unparsed->vx_vni); -if (!pskb_may_pull (skb, offset +sizeof (u16))) -return false; + reason =pskb_may_pull_reason (skb, offset +sizeof (u16)); +if (reason) +return reason;skb_remcsum_process (skb, (void *)(vxlan_hdr (skb) +1 ), start, offset, !!(vxflags &VXLAN_F_REMCSUM_NOPARTIAL )); out: unparsed->vx_flags &= ~VXLAN_HF_RCO ; unparsed->vx_vni &=VXLAN_VNI_MASK ; -return true; +return SKB_NOT_DROPPED_YET ; } static void vxlan_parse_gbp_hdr(struct vxlanhdr *unparsed,
Signature · 1 line
2.39.2
Re: [PATCH net-next v2 05/12] net: vxlan: make vxlan_remcsum() return drop reasons
From: Menglong Dong <[email protected]>
Date: Fri, 30 Aug 2024 09:59:54 +0800
Quoted 35 lines
Make
vxlan_remcsum()support skb drop reasons by changing the return value type of it from bool to enumskb_drop_reason.The only drop reason in
vxlan_remcsum()comes frompskb_may_pull_reason(), so we just return it.Signed-off-by Menglong Dong <[email protected]>--- drivers/net/vxlan/vxlan_core.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-)drivers/net/vxlan/vxlan_core.c +4
-4@@ -1551,9 +1551,11 @@ static void vxlan_sock_release(struct vxlan_dev *vxlan)#endif } -static bool vxlan_remcsum (struct vxlanhdr *unparsed, -struct sk_buff *skb,u32 vxflags) +static enum skb_drop_reason vxlan_remcsum (struct vxlanhdr *unparsed, +struct sk_buff *skb, +u32 vxflags) { +enum skb_drop_reason reason;size_t start, offset;if (!(unparsed->vx_flags &VXLAN_HF_RCO ) || skb->remcsum_offload)@@ -1562,15 +1564,16 @@ static bool vxlan_remcsum(struct vxlanhdr *unparsed, start =vxlan_rco_start (unparsed->vx_vni); offset = start +vxlan_rco_offset (unparsed->vx_vni); -if (!pskb_may_pull (skb, offset +sizeof (u16))) -return false;
drivers/net/vxlan/vxlan_core.c static bool vxlan_remcsum(struct vxlanhdr *unparsed, · line 1573
Quoted 10 lines
drivers/net/vxlan/vxlan_core.c +3
-1+ reason =pskb_may_pull_reason (skb, offset +sizeof (u16)); +if (reason) +return reason;skb_remcsum_process (skb, (void *)(vxlan_hdr (skb) +1 ), start, offset, !!(vxflags &VXLAN_F_REMCSUM_NOPARTIAL )); out: unparsed->vx_flags &= ~VXLAN_HF_RCO ; unparsed->vx_vni &=VXLAN_VNI_MASK ; -return true;
Also an empty newline before return.
drivers/net/vxlan/vxlan_core.c static bool vxlan_remcsum(struct vxlanhdr *unparsed, · line 1579
Quoted 4 lines
drivers/net/vxlan/vxlan_core.c +1
-0+return SKB_NOT_DROPPED_YET ; } static void vxlan_parse_gbp_hdr(struct vxlanhdr *unparsed,
Thanks,
Olek
PATCH v2 6/12 net: vxlan: make vxlan_set_mac() return drop reasons
In reply to Menglong DongChange the return type of vxlan_set_mac() from bool to enum skb_drop_reason. In this commit, two drop reasons are introduced:
VXLAN_DROP_INVALID_SMAC
VXLAN_DROP_ENTRY_EXISTS
To make it easier to document the reasons in drivers/net/vxlan/drop.h, we don't define the enum vxlan_drop_reason with the macro VXLAN_DROP_REASONS(), but hand by hand.
--- drivers/net/vxlan/drop.h | 9 +++++++++ drivers/net/vxlan/vxlan_core.c | 12 ++++++------ 2 files changed, 15 insertions(+), 6 deletions(-)
drivers/net/vxlan/drop.h +9 -0
@@ -9,11 +9,20 @@#include <net/dropreason.h> #define VXLAN_DROP_REASONS (R ) \ + R(VXLAN_DROP_INVALID_SMAC) \ + R(VXLAN_DROP_ENTRY_EXISTS) \/* deliberate comment for trailing \ */ enum vxlan_drop_reason { __VXLAN_DROP_REASON =SKB_DROP_REASON_SUBSYS_VXLAN <<SKB_DROP_REASON_SUBSYS_SHIFT , +/** @VXLAN_DROP_INVALID_SMAC: source mac is invalid */ +VXLAN_DROP_INVALID_SMAC , +/** +* @VXLAN_DROP_ENTRY_EXISTS: trying to migrate a static entry or +* one pointing to a nexthop +*/ +VXLAN_DROP_ENTRY_EXISTS , }; static inline void
drivers/net/vxlan/vxlan_core.c +6 -6
@@ -1607,9 +1607,9 @@ static void vxlan_parse_gbp_hdr(struct vxlanhdr *unparsed, unparsed->vx_flags &= ~VXLAN_GBP_USED_BITS ; } -static bool vxlan_set_mac (struct vxlan_dev *vxlan, -struct vxlan_sock *vs, -struct sk_buff *skb,__be32 vni) +static enum skb_drop_reason vxlan_set_mac (struct vxlan_dev *vxlan, +struct vxlan_sock *vs, +struct sk_buff *skb,__be32 vni) {union vxlan_addr saddr;u32 ifindex = skb->dev->ifindex;
@@ -1620,7 +1620,7 @@ static bool vxlan_set_mac(struct vxlan_dev *vxlan,/* Ignore packet loops (and multicast echo) */ if (ether_addr_equal (eth_hdr (skb)->h_source, vxlan->dev->dev_addr)) -return false; +return (u32 )VXLAN_DROP_INVALID_SMAC ;/* Get address from the outer IP header */ if (vxlan_get_sk_family (vs) ==AF_INET ) {
@@ -1635,9 +1635,9 @@ static bool vxlan_set_mac(struct vxlan_dev *vxlan,if ((vxlan->cfg.flags &VXLAN_F_LEARN ) &&vxlan_snoop (skb->dev, &saddr,eth_hdr (skb)->h_source, ifindex, vni)) -return false; +return (u32 )VXLAN_DROP_ENTRY_EXISTS ; -return true; +return (u32 )SKB_NOT_DROPPED_YET ; } static bool vxlan_ecn_decapsulate(struct vxlan_sock *vs, void *oiph,
Signature · 1 line
2.39.2
Re: [PATCH net-next v2 06/12] net: vxlan: make vxlan_set_mac() return drop reasons
From: Menglong Dong <[email protected]>
Date: Fri, 30 Aug 2024 09:59:55 +0800
Quoted 21 lines
Change the return type of
vxlan_set_mac()from bool to enumskb_drop_reason. In this commit, two drop reasons are introduced:
VXLAN_DROP_INVALID_SMAC
VXLAN_DROP_ENTRY_EXISTSTo make it easier to document the reasons in
drivers/net/vxlan/drop.h, we don't define the enumvxlan_drop_reasonwith the macroVXLAN_DROP_REASONS(), but hand by hand.Signed-off-by Menglong Dong <[email protected]>--- drivers/net/vxlan/drop.h | 9 +++++++++ drivers/net/vxlan/vxlan_core.c | 12 ++++++------ 2 files changed, 15 insertions(+), 6 deletions(-)drivers/net/vxlan/drop.h +0
-0
drivers/net/vxlan/drop.h line 13
Quoted 5 lines
drivers/net/vxlan/drop.h +2
-0@@ -9,11 +9,20 @@#include <net/dropreason.h> #define VXLAN_DROP_REASONS (R ) \ + R(VXLAN_DROP_INVALID_SMAC) \ + R(VXLAN_DROP_ENTRY_EXISTS) \
To Jakub:
In our recent conversation, you said you dislike templates much. What about this one? :>
drivers/net/vxlan/drop.h line 24
Quoted 11 lines
drivers/net/vxlan/drop.h +6
-0/* deliberate comment for trailing \ */ enum vxlan_drop_reason { __VXLAN_DROP_REASON =SKB_DROP_REASON_SUBSYS_VXLAN <<SKB_DROP_REASON_SUBSYS_SHIFT , +/** @VXLAN_DROP_INVALID_SMAC: source mac is invalid */ +VXLAN_DROP_INVALID_SMAC , +/** +* @VXLAN_DROP_ENTRY_EXISTS: trying to migrate a static entry or +* one pointing to a nexthop +*/
Maybe you'd do a proper kdoc for this enum at the top?
Quoted 31 lines
drivers/net/vxlan/drop.h +1
-0+ VXLAN_DROP_ENTRY_EXISTS, }; static inline voiddrivers/net/vxlan/vxlan_core.c +4
-4@@ -1607,9 +1607,9 @@ static void vxlan_parse_gbp_hdr(struct vxlanhdr *unparsed, unparsed->vx_flags &= ~VXLAN_GBP_USED_BITS ; } -static bool vxlan_set_mac (struct vxlan_dev *vxlan, -struct vxlan_sock *vs, -struct sk_buff *skb,__be32 vni) +static enum skb_drop_reason vxlan_set_mac (struct vxlan_dev *vxlan, +struct vxlan_sock *vs, +struct sk_buff *skb,__be32 vni) {union vxlan_addr saddr;u32 ifindex = skb->dev->ifindex;@@ -1620,7 +1620,7 @@ static bool vxlan_set_mac(struct vxlan_dev *vxlan,/* Ignore packet loops (and multicast echo) */ if (ether_addr_equal (eth_hdr (skb)->h_source, vxlan->dev->dev_addr)) -return false; +return (u32 )VXLAN_DROP_INVALID_SMAC ;/* Get address from the outer IP header */ if (vxlan_get_sk_family (vs) ==AF_INET ) {
drivers/net/vxlan/vxlan_core.c static bool vxlan_set_mac(struct vxlan_dev *vxlan, · line 1640
Quoted 8 lines
drivers/net/vxlan/vxlan_core.c +2
-2@@ -1635,9 +1635,9 @@ static bool vxlan_set_mac(struct vxlan_dev *vxlan,if ((vxlan->cfg.flags &VXLAN_F_LEARN ) &&vxlan_snoop (skb->dev, &saddr,eth_hdr (skb)->h_source, ifindex, vni)) -return false; +return (u32 )VXLAN_DROP_ENTRY_EXISTS ; -return true; +return (u32 )SKB_NOT_DROPPED_YET ;
Redundant cast.
drivers/net/vxlan/vxlan_core.c static bool vxlan_set_mac(struct vxlan_dev *vxlan, · line 1641
Quoted 1 line
drivers/net/vxlan/vxlan_core.c +0
-0}
Don't you need to adjust the call site accordingly? Previously, this function returned false in case of error and true otherwise, now it returns a non-zero in case of error and 0 (NOT_DROPPED_YET == 0) if everything went fine.
IOW the call site now needs to check whether the return value != NOT_DROPPED_YET instead of checking whether it returned false. You inverted the return code logic, but didn't touch the call site.
drivers/net/vxlan/vxlan_core.c static bool vxlan_set_mac(struct vxlan_dev *vxlan, · line 1643
Quoted 2 lines
drivers/net/vxlan/vxlan_core.c +0
-0static bool vxlan_ecn_decapsulate(struct vxlan_sock *vs, void *oiph,
Thanks,
Olek
Re: [PATCH net-next v2 06/12] net: vxlan: make vxlan_set_mac() return drop reasons
Quoted 48 lines · Alexander Lobakin
From: Menglong Dong <[email protected]>
Date: Fri, 30 Aug 2024 09:59:55 +0800Quoted 21 lines
Change the return type of
vxlan_set_mac()from bool to enumskb_drop_reason. In this commit, two drop reasons are introduced:
VXLAN_DROP_INVALID_SMAC
VXLAN_DROP_ENTRY_EXISTSTo make it easier to document the reasons in
drivers/net/vxlan/drop.h, we don't define the enumvxlan_drop_reasonwith the macroVXLAN_DROP_REASONS(), but hand by hand.Signed-off-by Menglong Dong <[email protected]>--- drivers/net/vxlan/drop.h | 9 +++++++++ drivers/net/vxlan/vxlan_core.c | 12 ++++++------ 2 files changed, 15 insertions(+), 6 deletions(-)drivers/net/vxlan/drop.h +0
-0drivers/net/vxlan/drop.h line 13
Quoted 5 lines
drivers/net/vxlan/drop.h +2
-0@@ -9,11 +9,20 @@#include <net/dropreason.h> #define VXLAN_DROP_REASONS (R ) \ + R(VXLAN_DROP_INVALID_SMAC) \ + R(VXLAN_DROP_ENTRY_EXISTS) \To Jakub:
In our recent conversation, you said you dislike templates much. What about this one? :>
drivers/net/vxlan/drop.h line 24
Quoted 11 lines
drivers/net/vxlan/drop.h +6
-0/* deliberate comment for trailing \ */ enum vxlan_drop_reason { __VXLAN_DROP_REASON =SKB_DROP_REASON_SUBSYS_VXLAN <<SKB_DROP_REASON_SUBSYS_SHIFT , +/** @VXLAN_DROP_INVALID_SMAC: source mac is invalid */ +VXLAN_DROP_INVALID_SMAC , +/** +* @VXLAN_DROP_ENTRY_EXISTS: trying to migrate a static entry or +* one pointing to a nexthop +*/
Quoted 2 lines
Maybe you'd do a proper kdoc for this enum at the top?
Do you mean the enum vxlan_drop_reason? Yeah, that makes sense, and I'll doc it.
Quoted 37 lines
Quoted 37 lines
drivers/net/vxlan/drop.h +1
-0+ VXLAN_DROP_ENTRY_EXISTS, }; static inline voiddrivers/net/vxlan/vxlan_core.c +5
-5@@ -1607,9 +1607,9 @@ static void vxlan_parse_gbp_hdr(struct vxlanhdr *unparsed, unparsed->vx_flags &= ~VXLAN_GBP_USED_BITS ; } -static bool vxlan_set_mac (struct vxlan_dev *vxlan, -struct vxlan_sock *vs, -struct sk_buff *skb,__be32 vni) +static enum skb_drop_reason vxlan_set_mac (struct vxlan_dev *vxlan, +struct vxlan_sock *vs, +struct sk_buff *skb,__be32 vni) {union vxlan_addr saddr;u32 ifindex = skb->dev->ifindex;@@ -1620,7 +1620,7 @@ static bool vxlan_set_mac(struct vxlan_dev *vxlan,/* Ignore packet loops (and multicast echo) */ if (ether_addr_equal (eth_hdr (skb)->h_source, vxlan->dev->dev_addr)) -return false; +return (u32 )VXLAN_DROP_INVALID_SMAC ;/* Get address from the outer IP header */ if (vxlan_get_sk_family (vs) ==AF_INET ) {@@ -1635,9 +1635,9 @@ static bool vxlan_set_mac(struct vxlan_dev *vxlan,if ((vxlan->cfg.flags &VXLAN_F_LEARN ) &&vxlan_snoop (skb->dev, &saddr,eth_hdr (skb)->h_source, ifindex, vni)) -return false; +return (u32 )VXLAN_DROP_ENTRY_EXISTS ;
Quoted 5 lines
drivers/net/vxlan/vxlan_core.c static bool vxlan_set_mac(struct vxlan_dev *vxlan, · line 1640
Quoted 2 lines
drivers/net/vxlan/vxlan_core.c +1
-1-return true; +return (u32 )SKB_NOT_DROPPED_YET ;Redundant cast.
Oops, I'll remove it.
Quoted 10 lines
drivers/net/vxlan/vxlan_core.c static bool vxlan_set_mac(struct vxlan_dev *vxlan, · line 1641
Quoted 1 line
drivers/net/vxlan/vxlan_core.c +0
-0}Don't you need to adjust the call site accordingly? Previously, this function returned false in case of error and true otherwise, now it returns a non-zero in case of error and 0 (
NOT_DROPPED_YET== 0) if everything went fine.
IOW the call site now needs to check whether the return value !=NOT_DROPPED_YETinstead of checking whether it returned false. You inverted the return code logic, but didn't touch the call site.
Yeah, you are right. I need to change the call of this function in this patch too, rather than the next patch. Thanks for reminding me of this point!
Quoted 5 lines
drivers/net/vxlan/vxlan_core.c static bool vxlan_set_mac(struct vxlan_dev *vxlan, · line 1643
Quoted 2 lines
drivers/net/vxlan/vxlan_core.c +0
-0static bool vxlan_ecn_decapsulate(struct vxlan_sock *vs, void *oiph,Thanks,
Olek
Simon Horman
reviewerRe: [PATCH net-next v2 06/12] net: vxlan: make vxlan_set_mac() return drop reasons
In reply to Menglong DongQuoted 26 lines · Menglong Dong
Change the return type of
vxlan_set_mac()from bool to enumskb_drop_reason. In this commit, two drop reasons are introduced:
VXLAN_DROP_INVALID_SMAC
VXLAN_DROP_ENTRY_EXISTSTo make it easier to document the reasons in
drivers/net/vxlan/drop.h, we don't define the enumvxlan_drop_reasonwith the macroVXLAN_DROP_REASONS(), but hand by hand.Signed-off-by Menglong Dong <[email protected]>--- drivers/net/vxlan/drop.h | 9 +++++++++ drivers/net/vxlan/vxlan_core.c | 12 ++++++------ 2 files changed, 15 insertions(+), 6 deletions(-)drivers/net/vxlan/drop.h +2
-0@@ -9,11 +9,20 @@#include <net/dropreason.h> #define VXLAN_DROP_REASONS (R ) \ + R(VXLAN_DROP_INVALID_SMAC) \ + R(VXLAN_DROP_ENTRY_EXISTS) \
drivers/net/vxlan/drop.h line 23
Quoted 10 lines
drivers/net/vxlan/drop.h +5
-0/* deliberate comment for trailing \ */ enum vxlan_drop_reason { __VXLAN_DROP_REASON =SKB_DROP_REASON_SUBSYS_VXLAN <<SKB_DROP_REASON_SUBSYS_SHIFT , +/** @VXLAN_DROP_INVALID_SMAC: source mac is invalid */ +VXLAN_DROP_INVALID_SMAC , +/** +* @VXLAN_DROP_ENTRY_EXISTS: trying to migrate a static entry or +* one pointing to a nexthop
Maybe it is clearer to write: one -> an entry
Quoted 5 lines
drivers/net/vxlan/drop.h +2
-0+*/ + VXLAN_DROP_ENTRY_EXISTS, }; static inline void
...
Re: [PATCH net-next v2 06/12] net: vxlan: make vxlan_set_mac() return drop reasons
Quoted 30 lines · Simon Horman
Quoted 28 lines · Menglong Dong
Change the return type of
vxlan_set_mac()from bool to enumskb_drop_reason. In this commit, two drop reasons are introduced:
VXLAN_DROP_INVALID_SMAC
VXLAN_DROP_ENTRY_EXISTSTo make it easier to document the reasons in
drivers/net/vxlan/drop.h, we don't define the enumvxlan_drop_reasonwith the macroVXLAN_DROP_REASONS(), but hand by hand.Signed-off-by Menglong Dong <[email protected]>--- drivers/net/vxlan/drop.h | 9 +++++++++ drivers/net/vxlan/vxlan_core.c | 12 ++++++------ 2 files changed, 15 insertions(+), 6 deletions(-)drivers/net/vxlan/drop.h +2
-0@@ -9,11 +9,20 @@#include <net/dropreason.h> #define VXLAN_DROP_REASONS (R ) \ + R(VXLAN_DROP_INVALID_SMAC) \ + R(VXLAN_DROP_ENTRY_EXISTS) \/* deliberate comment for trailing \ */
Quoted 11 lines
drivers/net/vxlan/drop.h line 23
Quoted 8 lines
drivers/net/vxlan/drop.h +5
-0enum vxlan_drop_reason { __VXLAN_DROP_REASON =SKB_DROP_REASON_SUBSYS_VXLAN <<SKB_DROP_REASON_SUBSYS_SHIFT , +/** @VXLAN_DROP_INVALID_SMAC: source mac is invalid */ +VXLAN_DROP_INVALID_SMAC , +/** +* @VXLAN_DROP_ENTRY_EXISTS: trying to migrate a static entry or +* one pointing to a nexthop Maybe it is clearer to write: one -> an entry
Okay!
Quoted 7 lines
Quoted 5 lines
drivers/net/vxlan/drop.h +2
-0+*/ + VXLAN_DROP_ENTRY_EXISTS, }; static inline void...
Jakub Kicinski
maintainerRe: [PATCH net-next v2 06/12] net: vxlan: make vxlan_set_mac() return drop reasons
In reply to Menglong DongQuoted 10 lines · On Fri, 30 Aug 2024 09:59:55 +0800 Menglong Dong wrote:
drivers/net/vxlan/vxlan_core.c +3
-3-static bool vxlan_set_mac (struct vxlan_dev *vxlan, -struct vxlan_sock *vs, -struct sk_buff *skb,__be32 vni) +static enum skb_drop_reason vxlan_set_mac (struct vxlan_dev *vxlan, +struct vxlan_sock *vs, +struct sk_buff *skb,__be32 vni) {union vxlan_addr saddr;u32 ifindex = skb->dev->ifindex;
drivers/net/vxlan/vxlan_core.c static bool vxlan_set_mac(struct vxlan_dev *vxlan, · line 1623
Quoted 5 lines
drivers/net/vxlan/vxlan_core.c +1
-1@@ -1620,7 +1620,7 @@ static bool vxlan_set_mac(struct vxlan_dev *vxlan,/* Ignore packet loops (and multicast echo) */ if (ether_addr_equal (eth_hdr (skb)->h_source, vxlan->dev->dev_addr)) -return false; +return (u32 )VXLAN_DROP_INVALID_SMAC ;
It's the MAC address of the local interface, not just invalid...
drivers/net/vxlan/vxlan_core.c static bool vxlan_set_mac(struct vxlan_dev *vxlan, · line 1638
Quoted 8 lines
drivers/net/vxlan/vxlan_core.c +1
-1/* Get address from the outer IP header */ if (vxlan_get_sk_family (vs) ==AF_INET ) {@@ -1635,9 +1635,9 @@ static bool vxlan_set_mac(struct vxlan_dev *vxlan,if ((vxlan->cfg.flags &VXLAN_F_LEARN ) &&vxlan_snoop (skb->dev, &saddr,eth_hdr (skb)->h_source, ifindex, vni)) -return false; +return (u32 )VXLAN_DROP_ENTRY_EXISTS ;
... because it's vxlan_snoop() that checks:
if (!is_valid_ether_addr(src_mac))
Signature · 1 line
pw-bot: cr
Re: [PATCH net-next v2 06/12] net: vxlan: make vxlan_set_mac() return drop reasons
Quoted 13 lines · Jakub Kicinski
Quoted 11 lines · On Fri, 30 Aug 2024 09:59:55 +0800 Menglong Dong wrote:
drivers/net/vxlan/vxlan_core.c +3
-3-static bool vxlan_set_mac (struct vxlan_dev *vxlan, -struct vxlan_sock *vs, -struct sk_buff *skb,__be32 vni) +static enum skb_drop_reason vxlan_set_mac (struct vxlan_dev *vxlan, +struct vxlan_sock *vs, +struct sk_buff *skb,__be32 vni) {union vxlan_addr saddr;u32 ifindex = skb->dev->ifindex;@@ -1620,7 +1620,7 @@ static bool vxlan_set_mac(struct vxlan_dev *vxlan,
Quoted 7 lines
drivers/net/vxlan/vxlan_core.c static bool vxlan_set_mac(struct vxlan_dev *vxlan, · line 1623
Quoted 4 lines
drivers/net/vxlan/vxlan_core.c +1
-1/* Ignore packet loops (and multicast echo) */ if (ether_addr_equal (eth_hdr (skb)->h_source, vxlan->dev->dev_addr)) -return false; +return (u32 )VXLAN_DROP_INVALID_SMAC ;It's the MAC address of the local interface, not just invalid...
Yeah, my mistake. It seems that we need to add a VXLAN_DROP_LOOP_SMAC here? I'm not sure if it is worth here, or can we reuse VXLAN_DROP_INVALID_SMAC here too?
Quoted 4 lines
Quoted 4 lines
drivers/net/vxlan/vxlan_core.c +0
-0/* Get address from the outer IP header */ if (vxlan_get_sk_family (vs) ==AF_INET ) {@@ -1635,9 +1635,9 @@ static bool vxlan_set_mac(struct vxlan_dev *vxlan,
Quoted 8 lines
drivers/net/vxlan/vxlan_core.c static bool vxlan_set_mac(struct vxlan_dev *vxlan, · line 1638
Quoted 4 lines
drivers/net/vxlan/vxlan_core.c +1
-1if ((vxlan->cfg.flags &VXLAN_F_LEARN ) &&vxlan_snoop (skb->dev, &saddr,eth_hdr (skb)->h_source, ifindex, vni)) -return false; +return (u32 )VXLAN_DROP_ENTRY_EXISTS ;... because it's
vxlan_snoop()that checks:if (!is_valid_ether_addr(src_mac))
It seems that we need to make vxlan_snoop() return skb drop reasons too, and we need to add a new patch, which makes this series too many patches. Any advice?
I'll see if I can combine some of them into one.
Thanks!
Menglong Dong
Quoted 2 lines
--
pw-bot: cr
Jakub Kicinski
maintainerRe: [PATCH net-next v2 06/12] net: vxlan: make vxlan_set_mac() return drop reasons
Quoted 10 lines · On Sun, 1 Sep 2024 20:47:27 +0800 Menglong Dong wrote:
Quoted 9 lines
drivers/net/vxlan/vxlan_core.c static bool vxlan_set_mac(struct vxlan_dev *vxlan, · line 1623
Quoted 6 lines
drivers/net/vxlan/vxlan_core.c +1
-1@@ -1620,7 +1620,7 @@ static bool vxlan_set_mac(struct vxlan_dev *vxlan,/* Ignore packet loops (and multicast echo) */ if (ether_addr_equal (eth_hdr (skb)->h_source, vxlan->dev->dev_addr)) -return false; +return (u32 )VXLAN_DROP_INVALID_SMAC ;It's the MAC address of the local interface, not just invalid...
Quoted 3 lines
Yeah, my mistake. It seems that we need to add a
VXLAN_DROP_LOOP_SMAChere? I'm not sure if it is worth here, or can we reuseVXLAN_DROP_INVALID_SMAChere too?
Could you take a look at the bridge code and see if it has similar checks? Learning the addresses and dropping frames which don't match static FDB entries seem like fairly normal L2 switching drop reasons. Perhaps we could add these as non-VXLAN specific?
The subsystem reason API was added for wireless, because wireless folks had their own encoding, and they have their own development tree (we don't merge their patches directly into net-next). I keep thinking that we should add the VXLAN reason to the "core" group rather than creating a subsystem..
Quoted 11 lines
Quoted 11 lines
drivers/net/vxlan/vxlan_core.c static bool vxlan_set_mac(struct vxlan_dev *vxlan, · line 1638
Quoted 8 lines
drivers/net/vxlan/vxlan_core.c +1
-1/* Get address from the outer IP header */ if (vxlan_get_sk_family (vs) ==AF_INET ) {@@ -1635,9 +1635,9 @@ static bool vxlan_set_mac(struct vxlan_dev *vxlan,if ((vxlan->cfg.flags &VXLAN_F_LEARN ) &&vxlan_snoop (skb->dev, &saddr,eth_hdr (skb)->h_source, ifindex, vni)) -return false; +return (u32 )VXLAN_DROP_ENTRY_EXISTS ;... because it's
vxlan_snoop()that checks:
Quoted 5 lines
Quoted 1 line
if (!is_valid_ether_addr(src_mac))It seems that we need to make
vxlan_snoop()return skb drop reasons too, and we need to add a new patch, which makes this series too many patches. Any advice?
You could save some indentation by inverting the condition:
if (!(vxlan->cfg.flags & VXLAN_F_LEARN))
return (u32)SKB_NOT_DROPPED_YET; return vxlan_snoop(skb->dev, &saddr, eth_hdr(skb)->h_source, ifindex, vni);
But yes, I don't see a better way than having vxlan_snoop() return a reason code :(
The patch limit count is 15, 12 is our preferred number but you can go higher if it helps the clarity of the series.
Re: [PATCH net-next v2 06/12] net: vxlan: make vxlan_set_mac() return drop reasons
Quoted 12 lines · Jakub Kicinski
Quoted 10 lines · On Sun, 1 Sep 2024 20:47:27 +0800 Menglong Dong wrote:
Quoted 9 lines
drivers/net/vxlan/vxlan_core.c static bool vxlan_set_mac(struct vxlan_dev *vxlan, · line 1623
Quoted 6 lines
drivers/net/vxlan/vxlan_core.c +1
-1@@ -1620,7 +1620,7 @@ static bool vxlan_set_mac(struct vxlan_dev *vxlan,/* Ignore packet loops (and multicast echo) */ if (ether_addr_equal (eth_hdr (skb)->h_source, vxlan->dev->dev_addr)) -return false; +return (u32 )VXLAN_DROP_INVALID_SMAC ;It's the MAC address of the local interface, not just invalid...
Quoted 9 lines
Quoted 3 lines
Yeah, my mistake. It seems that we need to add a
VXLAN_DROP_LOOP_SMAChere? I'm not sure if it is worth here, or can we reuseVXLAN_DROP_INVALID_SMAChere too?Could you take a look at the bridge code and see if it has similar checks? Learning the addresses and dropping frames which don't match static FDB entries seem like fairly normal L2 switching drop reasons. Perhaps we could add these as non-VXLAN specific?
Yeah, I'll have a look at that part.
Quoted 6 lines
The subsystem reason API was added for wireless, because wireless folks had their own encoding, and they have their own development tree (we don't merge their patches directly into net-next). I keep thinking that we should add the VXLAN reason to the "core" group rather than creating a subsystem..
I'm hesitant about this in the beginning too, as VXLAN is a standard tunnel protocol. And I'm still hesitant now, should I add them to the "core"? which will make things simpler.
Enn......I'll add them to the "core" in the next version, and let's see if it is better.
Quoted 24 lines
Quoted 11 lines
Quoted 11 lines
drivers/net/vxlan/vxlan_core.c static bool vxlan_set_mac(struct vxlan_dev *vxlan, · line 1638
Quoted 8 lines
drivers/net/vxlan/vxlan_core.c +1
-1/* Get address from the outer IP header */ if (vxlan_get_sk_family (vs) ==AF_INET ) {@@ -1635,9 +1635,9 @@ static bool vxlan_set_mac(struct vxlan_dev *vxlan,if ((vxlan->cfg.flags &VXLAN_F_LEARN ) &&vxlan_snoop (skb->dev, &saddr,eth_hdr (skb)->h_source, ifindex, vni)) -return false; +return (u32 )VXLAN_DROP_ENTRY_EXISTS ;... because it's
vxlan_snoop()that checks:Quoted 5 lines
Quoted 1 line
if (!is_valid_ether_addr(src_mac))It seems that we need to make
vxlan_snoop()return skb drop reasons too, and we need to add a new patch, which makes this series too many patches. Any advice?You could save some indentation by inverting the condition:
if (!(vxlan->cfg.flags & VXLAN_F_LEARN)) return (u32)SKB_NOT_DROPPED_YET; return vxlan_snoop(skb->dev, &saddr, eth_hdr(skb)->h_source, ifindex, vni);
Quoted 5 lines
But yes, I don't see a better way than having
vxlan_snoop()return a reason code :(The patch limit count is 15, 12 is our preferred number but you can go higher if it helps the clarity of the series.
Okay! I feel much better with your words :/
Thanks!
Menglong Dong
PATCH v2 7/12 net: vxlan: add skb drop reasons to vxlan_rcv()
In reply to Menglong DongIntroduce skb drop reasons to the function vxlan_rcv(). Following new vxlan drop reasons are added:
VXLAN_DROP_INVALID_HDR
VXLAN_DROP_VNI_NOT_FOUND
And Following core skb drop reason is added:
SKB_DROP_REASON_IP_TUNNEL_ECN
---
v2:
- rename the drop reasons, as Ido advised.
- document the drop reasons
--- drivers/net/vxlan/drop.h | 10 ++++++++++ drivers/net/vxlan/vxlan_core.c | 35 +++++++++++++++++++++++++--------- include/net/dropreason-core.h | 6 ++++++ 3 files changed, 42 insertions(+), 9 deletions(-)
drivers/net/vxlan/drop.h +10 -0
@@ -11,6 +11,8 @@#define VXLAN_DROP_REASONS (R ) \ R(VXLAN_DROP_INVALID_SMAC) \ R(VXLAN_DROP_ENTRY_EXISTS) \ + R(VXLAN_DROP_INVALID_HDR) \ + R(VXLAN_DROP_VNI_NOT_FOUND) \/* deliberate comment for trailing \ */ enum vxlan_drop_reason {
@@ -23,6 +25,14 @@ enum vxlan_drop_reason {* one pointing to a nexthop */ VXLAN_DROP_ENTRY_EXISTS , +/** +* @VXLAN_DROP_INVALID_HDR: the vxlan header is invalid, such as: +* 1) the reserved fields are not zero +* 2) the "I" flag is not set +*/ +VXLAN_DROP_INVALID_HDR , +/** @VXLAN_DROP_VNI_NOT_FOUND: no vxlan device found for the vni */ + VXLAN_DROP_VNI_NOT_FOUND, }; static inline void
drivers/net/vxlan/vxlan_core.c +26 -9
@@ -1674,13 +1674,15 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)struct vxlan_metadata _md;struct vxlan_metadata *md = &_md;__be16 protocol =htons (ETH_P_TEB ); +enum skb_drop_reason reason;bool raw_proto = false;void *oiph;__be32 vni =0 ;int nh;/* Need UDP and VXLAN header to be present */ -if (!pskb_may_pull (skb,VXLAN_HLEN )) + reason =pskb_may_pull_reason (skb,VXLAN_HLEN ); +if (reason) goto drop; unparsed = *vxlan_hdr (skb);
@@ -1689,6 +1691,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)netdev_dbg (skb->dev,"invalid vxlan flags=%#x vni=%#x\n" ,ntohl (vxlan_hdr (skb)->vx_flags),ntohl (vxlan_hdr (skb)->vx_vni)); + reason = (u32 )VXLAN_DROP_INVALID_HDR ;/* Return non vxlan pkt */ goto drop; }
@@ -1702,8 +1705,10 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) vni =vxlan_vni (vxlan_hdr (skb)->vx_vni); vxlan =vxlan_vs_find_vni (vs, skb->dev->ifindex, vni, &vninode); -if (!vxlan) +if (!vxlan) { + reason = (u32 )VXLAN_DROP_VNI_NOT_FOUND ; goto drop; + }/* For backwards compatibility, only allow reserved fields to be * used by VXLAN extensions if explicitly requested.
@@ -1716,12 +1721,16 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) }if (__iptunnel_pull_header (skb,VXLAN_HLEN , protocol, raw_proto, - !net_eq (vxlan->net,dev_net (vxlan->dev)))) + !net_eq (vxlan->net,dev_net (vxlan->dev)))) { + reason =SKB_DROP_REASON_NOMEM ; goto drop; + } -if (vs->flags &VXLAN_F_REMCSUM_RX ) -if (unlikely (!vxlan_remcsum (&unparsed, skb, vs->flags))) +if (vs->flags &VXLAN_F_REMCSUM_RX ) { + reason =vxlan_remcsum (&unparsed, skb, vs->flags); +if (unlikely (reason)) goto drop; + }if (vxlan_collect_metadata (vs)) {IP_TUNNEL_DECLARE_FLAGS (flags) = { };
@@ -1731,8 +1740,10 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) tun_dst =udp_tun_rx_dst (skb,vxlan_get_sk_family (vs), flags,key32_to_tunnel_id (vni),sizeof (*md)); -if (!tun_dst) +if (!tun_dst) { + reason =SKB_DROP_REASON_NOMEM ; goto drop; + } md =ip_tunnel_info_opts (&tun_dst->u.tun_info);
@@ -1756,11 +1767,13 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)* is more robust and provides a little more security in * adding extensions to VXLAN. */ + reason = (u32 )VXLAN_DROP_INVALID_HDR ; goto drop; }if (!raw_proto) { -if (!vxlan_set_mac (vxlan, vs, skb, vni)) + reason =vxlan_set_mac (vxlan, vs, skb, vni); +if (reason) goto drop; }else {skb_reset_mac_header (skb);
@@ -1776,7 +1789,8 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)skb_reset_network_header (skb); -if (!pskb_inet_may_pull (skb)) { + reason =pskb_inet_may_pull_reason (skb); +if (reason) {DEV_STATS_INC (vxlan->dev, rx_length_errors);DEV_STATS_INC (vxlan->dev, rx_errors); vxlan_vnifilter_count(vxlan, vni, vninode,
@@ -1788,6 +1802,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) oiph = skb->head + nh;if (!vxlan_ecn_decapsulate (vs, oiph, skb)) { + reason =SKB_DROP_REASON_IP_TUNNEL_ECN ;DEV_STATS_INC (vxlan->dev, rx_frame_errors);DEV_STATS_INC (vxlan->dev, rx_errors); vxlan_vnifilter_count(vxlan, vni, vninode,
@@ -1802,6 +1817,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)dev_core_stats_rx_dropped_inc (vxlan->dev);vxlan_vnifilter_count (vxlan, vni, vninode,VXLAN_VNI_STATS_RX_DROPS ,0 ); + reason =SKB_DROP_REASON_DEV_READY ; goto drop; }
@@ -1814,8 +1830,9 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)return 0 ; drop: + reason = reason ?:SKB_DROP_REASON_NOT_SPECIFIED ;/* Consume bad packet */ -kfree_skb (skb); +kfree_skb_reason (skb, reason);return 0 ; }
include/net/dropreason-core.h +6 -0
@@ -92,6 +92,7 @@ FN(PACKET_SOCK_ERROR) \ FN(TC_CHAIN_NOTFOUND) \ FN(TC_RECLASSIFY_LOOP) \ + FN(IP_TUNNEL_ECN) \ FNe(MAX)/**
@@ -418,6 +419,11 @@ enum skb_drop_reason {* iterations. */ SKB_DROP_REASON_TC_RECLASSIFY_LOOP , +/** +* @SKB_DROP_REASON_IP_TUNNEL_ECN: skb is dropped according to +* RFC 6040 4.2, see __INET_ECN_decapsulate() for detail. +*/ + SKB_DROP_REASON_IP_TUNNEL_ECN,/** * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which * shouldn't be used as a real 'reason' - only for tracing code gen
Signature · 1 line
2.39.2
Re: [PATCH net-next v2 07/12] net: vxlan: add skb drop reasons to vxlan_rcv()
From: Menglong Dong <[email protected]>
Date: Fri, 30 Aug 2024 09:59:56 +0800
Quoted 7 lines
Introduce skb drop reasons to the function
vxlan_rcv(). Following new vxlan drop reasons are added:
VXLAN_DROP_INVALID_HDR
VXLAN_DROP_VNI_NOT_FOUNDAnd Following core skb drop reason is added:
"the following", lowercase + "the".
Quoted 4 lines
SKB_DROP_REASON_IP_TUNNEL_ECNSigned-off-by Menglong Dong <[email protected]>
[...]
drivers/net/vxlan/drop.h enum vxlan_drop_reason { · line 29
Quoted 6 lines
drivers/net/vxlan/drop.h +2
-0@@ -23,6 +25,14 @@ enum vxlan_drop_reason {* one pointing to a nexthop */ VXLAN_DROP_ENTRY_EXISTS, +/** +* @VXLAN_DROP_INVALID_HDR: the vxlan header is invalid, such as:
Same as before, "VXLAN" in uppercase I'd say.
drivers/net/vxlan/drop.h enum vxlan_drop_reason { · line 34
Quoted 5 lines
drivers/net/vxlan/drop.h +5
-0+* 1) the reserved fields are not zero +* 2) the "I" flag is not set +*/ + VXLAN_DROP_INVALID_HDR, +/** @VXLAN_DROP_VNI_NOT_FOUND: no vxlan device found for the vni */
^
Quoted 2 lines
drivers/net/vxlan/drop.h +1
-0+ VXLAN_DROP_VNI_NOT_FOUND, };
[...]
drivers/net/vxlan/vxlan_core.c static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) · line 1777
Quoted 5 lines
drivers/net/vxlan/vxlan_core.c +2
-1if (!raw_proto) { -if (!vxlan_set_mac (vxlan, vs, skb, vni)) + reason =vxlan_set_mac (vxlan, vs, skb, vni); +if (reason) goto drop;
This piece must go in the previous patch, see my comment there.
[...]
drivers/net/vxlan/vxlan_core.c static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) · line 1833
Quoted 5 lines
drivers/net/vxlan/vxlan_core.c +1
-0@@ -1814,8 +1830,9 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)return 0 ; drop: + reason = reason ?:SKB_DROP_REASON_NOT_SPECIFIED ;
Is this possible that @reason will be 0 (NOT_DROPPED_YET) here? At the beginning of the function, it's not initialized, then each error path sets it to a specific value. In most paths, you check for it being != 0 as a sign of error, so I doubt it can be 0 here.
drivers/net/vxlan/vxlan_core.c static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) · line 1837
Quoted 5 lines
drivers/net/vxlan/vxlan_core.c +1
-1/* Consume bad packet */ -kfree_skb (skb); +kfree_skb_reason (skb, reason);return 0 ; }
Thanks,
Olek
Re: [PATCH net-next v2 07/12] net: vxlan: add skb drop reasons to vxlan_rcv()
Quoted 7 lines · Alexander Lobakin
From: Menglong Dong <[email protected]>
Date: Fri, 30 Aug 2024 09:59:56 +0800Quoted 3 lines
Introduce skb drop reasons to the function
vxlan_rcv(). Following new vxlan drop reasons are added:
Quoted 7 lines
Quoted 4 lines
VXLAN_DROP_INVALID_HDR
VXLAN_DROP_VNI_NOT_FOUNDAnd Following core skb drop reason is added:
"the following", lowercase + "the".
Okay!
Quoted 29 lines
Quoted 4 lines
SKB_DROP_REASON_IP_TUNNEL_ECNSigned-off-by Menglong Dong <[email protected]>[...]
drivers/net/vxlan/drop.h enum vxlan_drop_reason { · line 29
Quoted 6 lines
drivers/net/vxlan/drop.h +2
-0@@ -23,6 +25,14 @@ enum vxlan_drop_reason {* one pointing to a nexthop */ VXLAN_DROP_ENTRY_EXISTS, +/** +* @VXLAN_DROP_INVALID_HDR: the vxlan header is invalid, such as: Same as before, "VXLAN" in uppercase I'd say.
drivers/net/vxlan/drop.h enum vxlan_drop_reason { · line 34
Quoted 5 lines
drivers/net/vxlan/drop.h +5
-0+* 1) the reserved fields are not zero +* 2) the "I" flag is not set +*/ + VXLAN_DROP_INVALID_HDR, +/** @VXLAN_DROP_VNI_NOT_FOUND: no vxlan device found for the vni */ ^
Quoted 2 lines
drivers/net/vxlan/drop.h +1
-0+ VXLAN_DROP_VNI_NOT_FOUND, };[...]
Quoted 8 lines
drivers/net/vxlan/vxlan_core.c static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) · line 1777
Quoted 5 lines
if (!raw_proto) {drivers/net/vxlan/vxlan_core.c +2
-1-if (!vxlan_set_mac (vxlan, vs, skb, vni)) + reason =vxlan_set_mac (vxlan, vs, skb, vni); +if (reason) goto drop;This piece must go in the previous patch, see my comment there.
Yeah, I'll do it.
Quoted 5 lines
[...]
Quoted 3 lines
(quoted diff) +0
-0@@ -1814,8 +1830,9 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) return 0;
Quoted 8 lines
drivers/net/vxlan/vxlan_core.c static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) · line 1833
Quoted 2 lines
drivers/net/vxlan/vxlan_core.c +1
-0drop: + reason = reason ?:SKB_DROP_REASON_NOT_SPECIFIED ;Is this possible that @reason will be 0 (
NOT_DROPPED_YET) here? At the beginning of the function, it's not initialized, then each error path sets it to a specific value. In most paths, you check for it being != 0 as a sign of error, so I doubt it can be 0 here.
It can be 0 here, as we don't set a reason for every "goto drop" path. For example, in the line:
if (!vs)
goto drop;we don't set a reason, and the "reason" is 0 when we "goto drop", as I don't think that it is worth introducing a reason here.
Thanks!
Menglong Dong
Quoted 8 lines
drivers/net/vxlan/vxlan_core.c static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) · line 1837
Quoted 5 lines
drivers/net/vxlan/vxlan_core.c +1
-1/* Consume bad packet */ -kfree_skb (skb); +kfree_skb_reason (skb, reason);return 0 ; }Thanks,
Olek
Re: [PATCH net-next v2 07/12] net: vxlan: add skb drop reasons to vxlan_rcv()
From: Menglong Dong <[email protected]>
Date: Sun, 1 Sep 2024 21:02:17 +0800
Quoted 2 lines
On Fri, Aug 30, 2024 at 11:04 PM Alexander Lobakin <[email protected]> wrote:
[...]
Quoted 12 lines
Quoted 11 lines
drivers/net/vxlan/vxlan_core.c static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) · line 1833
Quoted 5 lines
drivers/net/vxlan/vxlan_core.c +1
-0@@ -1814,8 +1830,9 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)return 0 ; drop: + reason = reason ?:SKB_DROP_REASON_NOT_SPECIFIED ;Is this possible that @reason will be 0 (
NOT_DROPPED_YET) here? At the beginning of the function, it's not initialized, then each error path sets it to a specific value. In most paths, you check for it being != 0 as a sign of error, so I doubt it can be 0 here.
Quoted 8 lines
It can be 0 here, as we don't set a reason for every "goto drop" path. For example, in the line:
if (!vs) goto drop;we don't set a reason, and the "reason" is 0 when we "goto drop", as I don't think that it is worth introducing a reason here.
Aaah okay, I didn't notice that, thanks for the explanation!
Quoted 9 lines
Thanks!
Menglong DongQuoted 5 lines
Quoted 5 lines
drivers/net/vxlan/vxlan_core.c +1
-1/* Consume bad packet */ -kfree_skb (skb); +kfree_skb_reason (skb, reason);return 0 ; }
Thanks,
Olek
Simon Horman
reviewerRe: [PATCH net-next v2 07/12] net: vxlan: add skb drop reasons to vxlan_rcv()
In reply to Menglong DongQuoted 35 lines · Menglong Dong
Introduce skb drop reasons to the function
vxlan_rcv(). Following new vxlan drop reasons are added:
VXLAN_DROP_INVALID_HDR
VXLAN_DROP_VNI_NOT_FOUNDAnd Following core skb drop reason is added:
SKB_DROP_REASON_IP_TUNNEL_ECNSigned-off-by Menglong Dong <[email protected]>---
v2:
- rename the drop reasons, as Ido advised.
- document the drop reasons--- drivers/net/vxlan/drop.h | 10 ++++++++++ drivers/net/vxlan/vxlan_core.c | 35 +++++++++++++++++++++++++--------- include/net/dropreason-core.h | 6 ++++++ 3 files changed, 42 insertions(+), 9 deletions(-)drivers/net/vxlan/drop.h +2
-0@@ -11,6 +11,8 @@#define VXLAN_DROP_REASONS (R ) \ R(VXLAN_DROP_INVALID_SMAC) \ R(VXLAN_DROP_ENTRY_EXISTS) \ + R(VXLAN_DROP_INVALID_HDR) \ + R(VXLAN_DROP_VNI_NOT_FOUND) \/* deliberate comment for trailing \ */ enum vxlan_drop_reason {
drivers/net/vxlan/drop.h enum vxlan_drop_reason { · line 32
Quoted 8 lines
drivers/net/vxlan/drop.h +4
-0@@ -23,6 +25,14 @@ enum vxlan_drop_reason {* one pointing to a nexthop */ VXLAN_DROP_ENTRY_EXISTS, +/** +* @VXLAN_DROP_INVALID_HDR: the vxlan header is invalid, such as: +* 1) the reserved fields are not zero +* 2) the "I" flag is not set
Maybe:
* ...: VXLAN header is invalid. E.g.:
* 1) reserved fields are not zero
* 2) "I" flag is not set
drivers/net/vxlan/drop.h enum vxlan_drop_reason { · line 34
Quoted 3 lines
drivers/net/vxlan/drop.h +3
-0+*/ + VXLAN_DROP_INVALID_HDR, +/** @VXLAN_DROP_VNI_NOT_FOUND: no vxlan device found for the vni */
Maybe: no VXLAN device found for VNI
Quoted 2 lines
drivers/net/vxlan/drop.h +1
-0+ VXLAN_DROP_VNI_NOT_FOUND, };
...
Re: [PATCH net-next v2 07/12] net: vxlan: add skb drop reasons to vxlan_rcv()
Quoted 43 lines · Simon Horman
Quoted 40 lines · Menglong Dong
Introduce skb drop reasons to the function
vxlan_rcv(). Following new vxlan drop reasons are added:
VXLAN_DROP_INVALID_HDR
VXLAN_DROP_VNI_NOT_FOUNDAnd Following core skb drop reason is added:
SKB_DROP_REASON_IP_TUNNEL_ECNSigned-off-by Menglong Dong <[email protected]>---
v2:
- rename the drop reasons, as Ido advised.
- document the drop reasons--- drivers/net/vxlan/drop.h | 10 ++++++++++ drivers/net/vxlan/vxlan_core.c | 35 +++++++++++++++++++++++++--------- include/net/dropreason-core.h | 6 ++++++ 3 files changed, 42 insertions(+), 9 deletions(-)drivers/net/vxlan/drop.h +4
-0@@ -11,6 +11,8 @@#define VXLAN_DROP_REASONS (R ) \ R(VXLAN_DROP_INVALID_SMAC) \ R(VXLAN_DROP_ENTRY_EXISTS) \ + R(VXLAN_DROP_INVALID_HDR) \ + R(VXLAN_DROP_VNI_NOT_FOUND) \/* deliberate comment for trailing \ */ enum vxlan_drop_reason {@@ -23,6 +25,14 @@ enum vxlan_drop_reason {* one pointing to a nexthop */ VXLAN_DROP_ENTRY_EXISTS, +/** +* @VXLAN_DROP_INVALID_HDR: the vxlan header is invalid, such as:
Quoted 8 lines
drivers/net/vxlan/drop.h enum vxlan_drop_reason { · line 31
Quoted 2 lines
drivers/net/vxlan/drop.h +2
-0+* 1) the reserved fields are not zero +* 2) the "I" flag is not set Maybe:
* ...: VXLAN header is invalid. E.g.:
* 1) reserved fields are not zero
* 2) "I" flag is not set
Sounds nice!
Quoted 6 lines
drivers/net/vxlan/drop.h enum vxlan_drop_reason { · line 34
Quoted 3 lines
drivers/net/vxlan/drop.h +3
-0+*/ + VXLAN_DROP_INVALID_HDR, +/** @VXLAN_DROP_VNI_NOT_FOUND: no vxlan device found for the vni */ Maybe: no VXLAN device found for VNI
Okay!
Thanks!
Menglong Dong
Quoted 4 lines
Quoted 2 lines
drivers/net/vxlan/drop.h +1
-0+ VXLAN_DROP_VNI_NOT_FOUND, };...
PATCH v2 8/12 net: vxlan: use vxlan_kfree_skb() in vxlan_xmit()
In reply to Menglong DongReplace kfree_skb() with vxlan_kfree_skb() in vxlan_xmit(). Following new skb drop reasons are introduced for vxlan:
/* no remote found */VXLAN_DROP_NO_REMOTE
And following drop reason is introduced to dropreason-core:
/* txinfo is missed in "external" mode */SKB_DROP_REASON_TUNNEL_TXINFO
---
v2:
- move the drop reason "TXINFO" from vxlan to core
- rename VXLAN_DROP_REMOTE to VXLAN_DROP_NO_REMOTE
--- drivers/net/vxlan/drop.h | 3 +++ drivers/net/vxlan/vxlan_core.c | 6 +++--- include/net/dropreason-core.h | 3 +++ 3 files changed, 9 insertions(+), 3 deletions(-)
drivers/net/vxlan/drop.h +3 -0
@@ -13,6 +13,7 @@R (VXLAN_DROP_ENTRY_EXISTS) \R (VXLAN_DROP_INVALID_HDR ) \R (VXLAN_DROP_VNI_NOT_FOUND ) \ +R (VXLAN_DROP_NO_REMOTE ) \/* deliberate comment for trailing \ */ enum vxlan_drop_reason {
@@ -33,6 +34,8 @@ enum vxlan_drop_reason {VXLAN_DROP_INVALID_HDR ,/** @VXLAN_DROP_VNI_NOT_FOUND: no vxlan device found for the vni */ VXLAN_DROP_VNI_NOT_FOUND , +/** @VXLAN_DROP_NO_REMOTE: no remote found to transmit the packet */ + VXLAN_DROP_NO_REMOTE, }; static inline void
drivers/net/vxlan/vxlan_core.c +3 -3
@@ -2728,7 +2728,7 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev)if (info && info->mode &IP_TUNNEL_INFO_TX )vxlan_xmit_one (skb, dev, vni,NULL , false);else -kfree_skb (skb); +kfree_skb_reason (skb,SKB_DROP_REASON_TUNNEL_TXINFO );return NETDEV_TX_OK ; } }
@@ -2791,7 +2791,7 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev)dev_core_stats_tx_dropped_inc (dev);vxlan_vnifilter_count (vxlan, vni,NULL ,VXLAN_VNI_STATS_TX_DROPS ,0 ); -kfree_skb (skb); +vxlan_kfree_skb (skb,VXLAN_DROP_NO_REMOTE );return NETDEV_TX_OK ; } }
@@ -2814,7 +2814,7 @@ static netdev_tx_t vxlan_xmit(struct sk_buff *skb, struct net_device *dev)if (fdst)vxlan_xmit_one (skb, dev, vni, fdst, did_rsc);else -kfree_skb (skb); +vxlan_kfree_skb (skb,VXLAN_DROP_NO_REMOTE ); }return NETDEV_TX_OK ;
include/net/dropreason-core.h +3 -0
@@ -93,6 +93,7 @@ FN(TC_CHAIN_NOTFOUND) \ FN(TC_RECLASSIFY_LOOP) \ FN(IP_TUNNEL_ECN) \ + FN(TUNNEL_TXINFO) \ FNe(MAX)/**
@@ -424,6 +425,8 @@ enum skb_drop_reason {* RFC 6040 4.2, see __INET_ECN_decapsulate() for detail. */ SKB_DROP_REASON_IP_TUNNEL_ECN , +/** @SKB_DROP_REASON_TUNNEL_TXINFO: tx info for tunnel is missed */ + SKB_DROP_REASON_TUNNEL_TXINFO,/** * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which * shouldn't be used as a real 'reason' - only for tracing code gen
Signature · 1 line
2.39.2
Simon Horman
reviewerRe: [PATCH net-next v2 08/12] net: vxlan: use vxlan_kfree_skb() in vxlan_xmit()
Quoted 35 lines · Menglong Dong
Replace
kfree_skb()withvxlan_kfree_skb()invxlan_xmit(). Following new skb drop reasons are introduced for vxlan:/* no remote found */
VXLAN_DROP_NO_REMOTEAnd following drop reason is introduced to dropreason-core:
/* txinfo is missed in "external" mode */
SKB_DROP_REASON_TUNNEL_TXINFOSigned-off-by Menglong Dong <[email protected]>---
v2:
- move the drop reason "TXINFO" from vxlan to core
- renameVXLAN_DROP_REMOTEtoVXLAN_DROP_NO_REMOTE--- drivers/net/vxlan/drop.h | 3 +++ drivers/net/vxlan/vxlan_core.c | 6 +++--- include/net/dropreason-core.h | 3 +++ 3 files changed, 9 insertions(+), 3 deletions(-)drivers/net/vxlan/drop.h +1
-0@@ -13,6 +13,7 @@R (VXLAN_DROP_ENTRY_EXISTS) \R (VXLAN_DROP_INVALID_HDR ) \R (VXLAN_DROP_VNI_NOT_FOUND ) \ +R (VXLAN_DROP_NO_REMOTE ) \/* deliberate comment for trailing \ */ enum vxlan_drop_reason {
drivers/net/vxlan/drop.h enum vxlan_drop_reason { · line 37
Quoted 4 lines
drivers/net/vxlan/drop.h +1
-0@@ -33,6 +34,8 @@ enum vxlan_drop_reason {VXLAN_DROP_INVALID_HDR ,/** @VXLAN_DROP_VNI_NOT_FOUND: no vxlan device found for the vni */ VXLAN_DROP_VNI_NOT_FOUND, +/** @VXLAN_DROP_NO_REMOTE: no remote found to transmit the packet */
Maybe: no remote found for transmit
or: no remote found for xmit
Quoted 4 lines
drivers/net/vxlan/drop.h +1
-0+ VXLAN_DROP_NO_REMOTE, }; static inline void
...
Re: [PATCH net-next v2 08/12] net: vxlan: use vxlan_kfree_skb() in vxlan_xmit()
Quoted 35 lines · Simon Horman
Quoted 33 lines · Menglong Dong
Replace
kfree_skb()withvxlan_kfree_skb()invxlan_xmit(). Following new skb drop reasons are introduced for vxlan:/* no remote found */
VXLAN_DROP_NO_REMOTEAnd following drop reason is introduced to dropreason-core:
/* txinfo is missed in "external" mode */
SKB_DROP_REASON_TUNNEL_TXINFOSigned-off-by Menglong Dong <[email protected]>---
v2:
- move the drop reason "TXINFO" from vxlan to core
- renameVXLAN_DROP_REMOTEtoVXLAN_DROP_NO_REMOTE--- drivers/net/vxlan/drop.h | 3 +++ drivers/net/vxlan/vxlan_core.c | 6 +++--- include/net/dropreason-core.h | 3 +++ 3 files changed, 9 insertions(+), 3 deletions(-)drivers/net/vxlan/drop.h +1
-0@@ -13,6 +13,7 @@ R(VXLAN_DROP_ENTRY_EXISTS) \ R(VXLAN_DROP_INVALID_HDR) \ R(VXLAN_DROP_VNI_NOT_FOUND) \ + R(VXLAN_DROP_NO_REMOTE) \ /* deliberate comment for trailing \ */
Quoted 10 lines
drivers/net/vxlan/drop.h enum vxlan_drop_reason { · line 37
Quoted 6 lines
drivers/net/vxlan/drop.h +1
-0enum vxlan_drop_reason {@@ -33,6 +34,8 @@ enum vxlan_drop_reason {VXLAN_DROP_INVALID_HDR ,/** @VXLAN_DROP_VNI_NOT_FOUND: no vxlan device found for the vni */ VXLAN_DROP_VNI_NOT_FOUND, +/** @VXLAN_DROP_NO_REMOTE: no remote found to transmit the packet */ Maybe: no remote found for transmit
or: no remote found for xmit
Okay!
Quoted 6 lines
Quoted 4 lines
drivers/net/vxlan/drop.h +1
-0+ VXLAN_DROP_NO_REMOTE, }; static inline void...
PATCH v2 9/12 net: vxlan: add drop reasons support to vxlan_xmit_one()
In reply to Menglong DongReplace kfree_skb/dev_kfree_skb with kfree_skb_reason in vxlan_xmit_one. No drop reasons are introduced in this commit.
The only concern of mine is replacing dev_kfree_skb with kfree_skb_reason. The dev_kfree_skb is equal to consume_skb, and I'm not sure if we can change it to kfree_skb here. In my option, the skb is "dropped" here, isn't it?
--- drivers/net/vxlan/vxlan_core.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-)
drivers/net/vxlan/vxlan_core.c +14 -5
@@ -2372,13 +2372,16 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,bool use_cache;bool udp_sum = false;bool xnet = !net_eq (vxlan->net,dev_net (vxlan->dev)); +enum skb_drop_reason reason;bool no_eth_encap;__be32 vni =0 ; no_eth_encap = flags &VXLAN_F_GPE && skb->protocol !=htons (ETH_P_TEB ); -if (!skb_vlan_inet_prepare (skb, no_eth_encap)) + reason =skb_vlan_inet_prepare_reason (skb, no_eth_encap); +if (reason) goto drop; + reason =SKB_DROP_REASON_NOT_SPECIFIED ; old_iph =ip_hdr (skb); info =skb_tunnel_info (skb);
@@ -2482,6 +2485,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, tos, use_cache ? dst_cache : NULL);if (IS_ERR (rt)) { err =PTR_ERR (rt); + reason =SKB_DROP_REASON_IP_OUTNOROUTES ; goto tx_error; }
@@ -2533,8 +2537,10 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, ttl = ttl ? :ip4_dst_hoplimit (&rt->dst); err =vxlan_build_skb (skb, ndst,sizeof (struct iphdr ), vni, md, flags, udp_sum); -if (err <0 ) +if (err <0 ) { + reason =SKB_DROP_REASON_NOMEM ; goto tx_error; + } udp_tunnel_xmit_skb(rt, sock4->sock->sk, skb, saddr, pkey->u.ipv4.dst, tos, ttl, df,
@@ -2554,6 +2560,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,if (IS_ERR (ndst)) { err =PTR_ERR (ndst); ndst =NULL ; + reason =SKB_DROP_REASON_IP_OUTNOROUTES ; goto tx_error; }
@@ -2594,8 +2601,10 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,skb_scrub_packet (skb, xnet); err =vxlan_build_skb (skb, ndst,sizeof (struct ipv6hdr ), vni, md, flags, udp_sum); -if (err <0 ) +if (err <0 ) { + reason =SKB_DROP_REASON_NOMEM ; goto tx_error; + } udp_tunnel6_xmit_skb(ndst, sock6->sock->sk, skb, dev, &saddr, &pkey->u.ipv6.dst, tos, ttl,
@@ -2610,7 +2619,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, drop:dev_core_stats_tx_dropped_inc (dev);vxlan_vnifilter_count (vxlan, vni,NULL ,VXLAN_VNI_STATS_TX_DROPS ,0 ); -dev_kfree_skb (skb); +kfree_skb_reason (skb, reason);return ; tx_error:
@@ -2622,7 +2631,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,dst_release (ndst);DEV_STATS_INC (dev, tx_errors);vxlan_vnifilter_count (vxlan, vni,NULL ,VXLAN_VNI_STATS_TX_ERRORS ,0 ); -kfree_skb (skb); +kfree_skb_reason (skb, reason); } static void vxlan_xmit_nh(struct sk_buff *skb, struct net_device *dev,
Signature · 1 line
2.39.2
PATCH v2 10/12 net: vxlan: use kfree_skb_reason in vxlan_mdb_xmit
In reply to Menglong DongReplace kfree_skb() with kfree_skb_reason() in vxlan_mdb_xmit. No drop reaons are introduced in this commit.
--- drivers/net/vxlan/vxlan_mdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/vxlan/vxlan_mdb.c +1 -1
@@ -1712,7 +1712,7 @@ netdev_tx_t vxlan_mdb_xmit(struct vxlan_dev *vxlan,vxlan_xmit_one (skb, vxlan->dev, src_vni,rcu_dereference (fremote->rd), false); else -kfree_skb (skb ); +vxlan_kfree_skb (skb ,VXLAN_DROP_NO_REMOTE );return NETDEV_TX_OK ; }
Signature · 1 line
2.39.2
PATCH v2 11/12 net: vxlan: use kfree_skb_reason in vxlan_encap_bypass
In reply to Menglong DongReplace kfree_skb with kfree_skb_reason in vxlan_encap_bypass, and no new skb drop reason is added in this commit.
--- drivers/net/vxlan/vxlan_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/vxlan/vxlan_core.c +1 -1
@@ -2288,7 +2288,7 @@ static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan,rcu_read_lock (); dev = skb->dev;if (unlikely (!(dev->flags &IFF_UP ))) { -kfree_skb (skb); +kfree_skb_reason (skb,SKB_DROP_REASON_DEV_READY ); goto drop; }
Signature · 1 line
2.39.2
PATCH v2 12/12 net: vxlan: use vxlan_kfree_skb in encap_bypass_if_local
In reply to Menglong DongReplace kfree_skb with vxlan_kfree_skb in encap_bypass_if_local, and no new skb drop reason is added in this commit.
--- drivers/net/vxlan/vxlan_core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/vxlan/vxlan_core.c +1 -1
@@ -2339,7 +2339,7 @@ static int encap_bypass_if_local(struct sk_buff *skb, struct net_device *dev,DEV_STATS_INC (dev, tx_errors);vxlan_vnifilter_count (vxlan, vni,NULL ,VXLAN_VNI_STATS_TX_ERRORS ,0 ); -kfree_skb (skb); +vxlan_kfree_skb (skb,VXLAN_DROP_INVALID_HDR );return -ENOENT ; }
Signature · 1 line
2.39.2