vxlan: generalize and refine drop reasons
Subsystems (3)
cover vxlan: generalize and refine drop reasons
This series makes two vxlan drop reasons generic, so that other tunnels can report the same conditions with them, and makes the reasons vxlan reports for two other failures more precise.
Patch 1 renames VXLAN_INVALID_HDR and VXLAN_VNI_NOT_FOUND to TUNNEL_INVALID_HDR and TUNNEL_NOT_FOUND. Their values stay the same; the names vxlan drops are reported with change.
Patch 2 makes __iptunnel_pull_header() and iptunnel_pull_header() return a drop reason. Until now they returned -ENOMEM for any failure, so a packet too short to pull looked like an allocation failure. The three callers in ip_gre and ip6_gre that tested the result with "< 0" test for a non-zero value instead. Patch 3 has vxlan report the reason these functions now return: PKT_TOO_SMALL instead of NOMEM for an inner frame shorter than an Ethernet header.
Patch 4 has vxlan report a route that goes out of the vxlan device itself as RECURSION_LIMIT instead of IP_OUTNOROUTES, and adds this case to the description of RECURSION_LIMIT.
These were patches 1-3 and 14 of v5 of "tunnels: add core and gre drop reasons", split out as Ido suggested. The conversion of ip_tunnel, ip6_tunnel and GRE, the rest of that series, will follow once these are in.
Changes since v5 of "tunnels: add core and gre drop reasons":
- split out of that series (Ido)
- the messages of patches 1, 2 and 4 no longer refer to the rest of it
- the message of patch 2 says that vxlan keeps reporting NOMEM until patch 3
- patch 4 adds the tunnel case to the description of RECURSION_LIMIT, which v5 did in its patch 9
- v5: https://lore.kernel.org/netdev/[email protected]/
Anton Danilov (4):
vxlan: rename the drop reasons for use by other tunnels
ip_tunnel: make __iptunnel_pull_header() return a drop reason
vxlan: report the drop reason of __iptunnel_pull_header()
vxlan: report a circular route as SKB_DROP_REASON_RECURSION_LIMIT
drivers/net/vxlan/vxlan_core.c | 26 ++++++++++++++++---------- include/net/dropreason-core.h | 25 ++++++++++++++++--------- include/net/ip_tunnels.h | 10 ++++++---- net/ipv4/ip_gre.c | 4 ++-- net/ipv4/ip_tunnel_core.c | 22 +++++++++++++++------- net/ipv6/ip6_gre.c | 2 +- 6 files changed, 56 insertions(+), 33 deletions(-)
Signature · 1 line
2.47.3
PATCH 1/4 vxlan: rename the drop reasons for use by other tunnels
VXLAN_INVALID_HDR and VXLAN_VNI_NOT_FOUND describe conditions that are not specific to vxlan: a malformed tunnel header, and a packet for which no tunnel device is found. The GRE receive paths drop packets for the same two conditions, and can report them with the same reasons once they are converted to drop reasons.
Rename them to TUNNEL_INVALID_HDR and TUNNEL_NOT_FOUND and reword their descriptions, the way VXLAN_NO_REMOTE became NO_TX_TARGET in commit 46e0ccfb88f0 ("net: vxlan: rename SKB_DROP_REASON_VXLAN_NO_REMOTE"). The numeric values stay the same; the names that the skb:kfree_skb tracepoint and drop_monitor report change.
--- drivers/net/vxlan/vxlan_core.c | 8 ++++---- include/net/dropreason-core.h | 19 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-)
drivers/net/vxlan/vxlan_core.c +4 -4
@@ -1700,7 +1700,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)if (!(vh->vx_flags &VXLAN_HF_VNI )) {netdev_dbg (skb->dev,"invalid vxlan flags=%#x vni=%#x\n" ,ntohl (vh->vx_flags),ntohl (vh->vx_vni)); - reason =SKB_DROP_REASON_VXLAN_INVALID_HDR ; + reason =SKB_DROP_REASON_TUNNEL_INVALID_HDR ;/* Return non vxlan pkt */ goto drop; }
@@ -1713,7 +1713,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) vxlan =vxlan_vs_find_vni (vs, skb->dev->ifindex, vni, &vninode);if (!vxlan) { - reason =SKB_DROP_REASON_VXLAN_VNI_NOT_FOUND ; + reason =SKB_DROP_REASON_TUNNEL_NOT_FOUND ; goto drop; }
@@ -1729,7 +1729,7 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb)* previous stack code, and also is more robust and provides a * little more security in adding extensions to VXLAN. */ - reason =SKB_DROP_REASON_VXLAN_INVALID_HDR ; + reason =SKB_DROP_REASON_TUNNEL_INVALID_HDR ;DEV_STATS_INC (vxlan->dev, rx_frame_errors);DEV_STATS_INC (vxlan->dev, rx_errors); vxlan_vnifilter_count(vxlan, cfg, vni, vninode,
@@ -2389,7 +2389,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, cfg, vni,NULL ,VXLAN_VNI_STATS_TX_ERRORS ,0 ); -kfree_skb_reason (skb,SKB_DROP_REASON_VXLAN_VNI_NOT_FOUND ); +kfree_skb_reason (skb,SKB_DROP_REASON_TUNNEL_NOT_FOUND );return -ENOENT ; }
include/net/dropreason-core.h +11 -8
@@ -111,8 +111,8 @@ FN(PACKET_SOCK_ERROR) \ FN(TC_CHAIN_NOTFOUND) \ FN(TC_RECLASSIFY_LOOP) \ - FN(VXLAN_INVALID_HDR) \ - FN(VXLAN_VNI_NOT_FOUND) \ + FN(TUNNEL_INVALID_HDR) \ + FN(TUNNEL_NOT_FOUND) \ FN(MAC_INVALID_SOURCE) \ FN(VXLAN_ENTRY_EXISTS) \ FN(NO_TX_TARGET) \
@@ -539,13 +539,16 @@ enum skb_drop_reason {*/ SKB_DROP_REASON_TC_RECLASSIFY_LOOP ,/** -* @SKB_DROP_REASON_VXLAN_INVALID_HDR: VXLAN header is invalid. E.g.: -* 1) reserved fields are not zero -* 2) "I" flag is not set +* @SKB_DROP_REASON_TUNNEL_INVALID_HDR: tunnel header is invalid. E.g.: +* 1) VXLAN reserved fields are not zero +* 2) VXLAN "I" flag is not set */ -SKB_DROP_REASON_VXLAN_INVALID_HDR , -/** @SKB_DROP_REASON_VXLAN_VNI_NOT_FOUND: no VXLAN device found for VNI */ -SKB_DROP_REASON_VXLAN_VNI_NOT_FOUND , +SKB_DROP_REASON_TUNNEL_INVALID_HDR , +/** +* @SKB_DROP_REASON_TUNNEL_NOT_FOUND: no tunnel device found for the +* packet, e.g. no VXLAN device for its VNI +*/ +SKB_DROP_REASON_TUNNEL_NOT_FOUND ,/** @SKB_DROP_REASON_MAC_INVALID_SOURCE: source mac is invalid */ SKB_DROP_REASON_MAC_INVALID_SOURCE,/**
Signature · 1 line
2.47.3
PATCH 2/4 ip_tunnel: make __iptunnel_pull_header() return a drop reason
In reply to Anton Danilov__iptunnel_pull_header() returns -ENOMEM whenever it fails. It can fail in two pskb_may_pull() calls, one for the tunnel header and one for the inner Ethernet header of ETH_P_TEB, and in the skb_unclone() done for GSO packets. pskb_may_pull() fails when the packet is shorter than the requested length as well as when pulling from the frags cannot allocate, so a truncated packet and an allocation failure look the same to the callers. The ones that report a drop reason can only pick SKB_DROP_REASON_NOMEM, as vxlan_rcv() does, and so would the GRE receive paths once they report drop reasons. In ip6_gre, gre_rcv() pulls the header before the tunnel lookup, so a packet from any sender whose ETH_P_TEB inner Ethernet header or WCCPv2 extra word is cut short would be reported as an out of memory condition.
Make __iptunnel_pull_header() and iptunnel_pull_header() return the reason pskb_may_pull_reason() already computes, SKB_DROP_REASON_NOMEM when skb_unclone() fails, and SKB_NOT_DROPPED_YET on success. A failure is still non-zero, so the callers that only test the result keep working. Three callers, in ip_gre and ip6_gre, test it with "< 0" instead; the enum has no negative values, so that test would always be false, and the compiler does not warn about it. Make them test for a non-zero value. vxlan_rcv() keeps reporting NOMEM for any failure until the next patch has it report the returned reason.
--- include/net/ip_tunnels.h | 10 ++++++---- net/ipv4/ip_gre.c | 4 ++-- net/ipv4/ip_tunnel_core.c | 22 +++++++++++++++------- net/ipv6/ip6_gre.c | 2 +- 4 files changed, 24 insertions(+), 14 deletions(-)
include/net/ip_tunnels.h +6 -4
@@ -614,11 +614,13 @@ static inline u8 ip_tunnel_ecn_encap(u8 tos, const struct iphdr *iph,return INET_ECN_encapsulate (tos, inner); } -int __iptunnel_pull_header (struct sk_buff *skb,int hdr_len, -__be16 inner_proto,bool raw_proto,bool xnet); +enum skb_drop_reason +__iptunnel_pull_header (struct sk_buff *skb,int hdr_len, +__be16 inner_proto,bool raw_proto,bool xnet); -static inline int iptunnel_pull_header (struct sk_buff *skb,int hdr_len, -__be16 inner_proto,bool xnet) +static inline enum skb_drop_reason +iptunnel_pull_header (struct sk_buff *skb,int hdr_len, +__be16 inner_proto,bool xnet) {return __iptunnel_pull_header (skb, hdr_len, inner_proto, false, xnet); }
net/ipv4/ip_gre.c +2 -2
@@ -312,7 +312,7 @@ static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,if (__iptunnel_pull_header (skb, len,htons (ETH_P_TEB ), - false, false) <0 ) + false, false)) goto drop;if (tunnel->collect_md) {
@@ -378,7 +378,7 @@ static int __ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,const struct iphdr *tnl_params;if (__iptunnel_pull_header (skb, hdr_len, tpi->proto, - raw_proto, false) <0 ) + raw_proto, false)) goto drop;/* Special case for ipgre_header_parse(), which expects the
net/ipv4/ip_tunnel_core.c +15 -7
@@ -106,19 +106,24 @@ void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb, }EXPORT_SYMBOL_GPL (iptunnel_xmit); -int __iptunnel_pull_header (struct sk_buff *skb,int hdr_len, -__be16 inner_proto,bool raw_proto,bool xnet) +enum skb_drop_reason +__iptunnel_pull_header (struct sk_buff *skb,int hdr_len, +__be16 inner_proto,bool raw_proto,bool xnet) { -if (unlikely (!pskb_may_pull (skb, hdr_len))) -return -ENOMEM ; +enum skb_drop_reason reason; + + reason =pskb_may_pull_reason (skb, hdr_len); +if (unlikely (reason)) +return reason;skb_pull_rcsum (skb, hdr_len);if (!raw_proto && inner_proto ==htons (ETH_P_TEB )) {struct ethhdr *eh; -if (unlikely (!pskb_may_pull (skb,ETH_HLEN ))) -return -ENOMEM ; + reason =pskb_may_pull_reason (skb,ETH_HLEN ); +if (unlikely (reason)) +return reason; eh = (struct ethhdr *)skb->data;if (likely (eth_proto_is_802_3 (eh->h_proto)))
@@ -135,7 +140,10 @@ int __iptunnel_pull_header(struct sk_buff *skb, int hdr_len,skb_set_queue_mapping (skb,0 );skb_scrub_packet (skb, xnet); -return iptunnel_pull_offloads (skb); +if (unlikely (iptunnel_pull_offloads (skb))) +return SKB_DROP_REASON_NOMEM ; + +return SKB_NOT_DROPPED_YET ; }EXPORT_SYMBOL_GPL (__iptunnel_pull_header);
net/ipv6/ip6_gre.c +1 -1
@@ -512,7 +512,7 @@ static int ip6erspan_rcv(struct sk_buff *skb,if (__iptunnel_pull_header (skb, len,htons (ETH_P_TEB ), - false, false) <0 ) + false, false))return PACKET_REJECT ;if (tunnel->parms.collect_md) {
Signature · 1 line
2.47.3
PATCH 3/4 vxlan: report the drop reason of __iptunnel_pull_header()
In reply to Anton Danilovvxlan_rcv() reports SKB_DROP_REASON_NOMEM whenever __iptunnel_pull_header() fails, as the helper used to return -ENOMEM for any failure. The VXLAN header is already in the linear area at this point, but the inner Ethernet header of a packet without GPE may not be, so a packet whose inner frame is shorter than an Ethernet header is reported as an out of memory condition.
Report the reason __iptunnel_pull_header() now returns instead:PKT_TOO_SMALL for such a packet, NOMEM when an allocation fails.
--- drivers/net/vxlan/vxlan_core.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/net/vxlan/vxlan_core.c +4 -4
@@ -1743,11 +1743,11 @@ static int vxlan_rcv(struct sock *sk, struct sk_buff *skb) raw_proto = true; } -if (__iptunnel_pull_header (skb,VXLAN_HLEN , protocol, raw_proto, - !net_eq (vxlan->net,dev_net (vxlan->dev)))) { - reason =SKB_DROP_REASON_NOMEM ; + reason =__iptunnel_pull_header (skb,VXLAN_HLEN , protocol, raw_proto, + !net_eq (vxlan->net, +dev_net (vxlan->dev))); +if (reason) goto drop; - }if (cfg->flags &VXLAN_F_REMCSUM_RX ) { reason =vxlan_remcsum (skb, cfg->flags);
Signature · 1 line
2.47.3
PATCH 4/4 vxlan: report a circular route as SKB_DROP_REASON_RECURSION_LIMIT
In reply to Anton Danilovudp_tunnel_dst_lookup() and udp_tunnel6_dst_lookup() return -ELOOP when the route to the remote end goes out of the vxlan device itself, and vxlan_xmit_one() counts that in collisions, apart from the -ENETUNREACH of a failed lookup. The drop reason does not tell them
apart: both are reported as SKB_DROP_REASON_IP_OUTNOROUTES, which describes a failed route lookup.
Such a route would send the encapsulated packet back into the device it leaves, which is the dead loop on a virtual device that SKB_DROP_REASON_RECURSION_LIMIT describes. Report the -ELOOP case with that reason, and add the tunnel case to the description of the reason as an example. ip_tunnel and ip6_tunnel make the same check, rt->dst.dev == dev in ip_tunnel_xmit() and ip_md_tunnel_xmit() and tdev == dev in ip6_tnl_xmit(), and can report it with the same reason.
--- drivers/net/vxlan/vxlan_core.c | 10 ++++++++-- include/net/dropreason-core.h | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-)
drivers/net/vxlan/vxlan_core.c +8 -2
@@ -2547,7 +2547,10 @@ 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 ; +if (err == -ELOOP ) + reason =SKB_DROP_REASON_RECURSION_LIMIT ; +else + reason =SKB_DROP_REASON_IP_OUTNOROUTES ; goto tx_error; }
@@ -2633,7 +2636,10 @@ 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 ; +if (err == -ELOOP ) + reason =SKB_DROP_REASON_RECURSION_LIMIT ; +else + reason =SKB_DROP_REASON_IP_OUTNOROUTES ; goto tx_error; }
include/net/dropreason-core.h +5 -1
@@ -613,7 +613,11 @@ enum skb_drop_reason {SKB_DROP_REASON_PSP_INPUT ,/** @SKB_DROP_REASON_PSP_OUTPUT: PSP output checks failed */ SKB_DROP_REASON_PSP_OUTPUT , -/** @SKB_DROP_REASON_RECURSION_LIMIT: Dead loop on virtual device. */ +/** +* @SKB_DROP_REASON_RECURSION_LIMIT: Dead loop on virtual device, e.g. a +* tunnel whose route to its remote end goes out of the tunnel device +* itself. +*/ SKB_DROP_REASON_RECURSION_LIMIT,/** * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which
Signature · 1 line
2.47.3
Quoted 3 lines · Anton Danilov
This series makes two vxlan drop reasons generic, so that other tunnels can report the same conditions with them, and makes the reasons vxlan reports for two other failures more precise.
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 9 lines · On Mon, 5 Oct 2026 23:14:13 +0300 you wrote:
This series makes two vxlan drop reasons generic, so that other tunnels can report the same conditions with them, and makes the reasons vxlan reports for two other failures more precise.
Patch 1 renames
VXLAN_INVALID_HDRandVXLAN_VNI_NOT_FOUNDtoTUNNEL_INVALID_HDRandTUNNEL_NOT_FOUND. Their values stay the same; the names vxlan drops are reported with change.[...]
Here is the summary with links:
- [net-next,1/4] vxlan: rename the drop reasons for use by other tunnels
https://git.kernel.org/netdev/net-next/c/7629d6db839f - [net-next,2/4] ip_tunnel: make __iptunnel_pull_header() return a drop reason https://git.kernel.org/netdev/net-next/c/6c0509aa8900 - [net-next,3/4] vxlan: report the drop reason of __iptunnel_pull_header() https://git.kernel.org/netdev/net-next/c/0518c33e1d7e - [net-next,4/4] vxlan: report a circular route as SKB_DROP_REASON_RECURSION_LIMIT https://git.kernel.org/netdev/net-next/c/d476bb7c0efd
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html