tunnels: add core and gre drop reasons
Subsystems (3)
v8 cover tunnels: add core and gre drop reasons
Several tunnel receive and transmit paths free packets from unrelated checks at a common drop site. For example, a missing GRE sequence number and an old sequence number both increment rx_fifo_errors. Reporting a reason through skb:kfree_skb and drop_monitor lets an operator distinguish a tunnel configuration mismatch from a reordered packet or a peer that restarted its sequence numbering.
Patches 1-5 cover the shared IPv4 and IPv6 tunnel receive paths and the GRE and ip6tnl receive handlers. Patches 6-8 cover IPv4 tunnel and GRE transmit, including FOU and GUE encapsulation failures. The IPv6 transmit path will follow separately.
The series adds four reasons: TUNNEL_OPT_MISMATCH, TUNNEL_OLD_SEQ, GRE_CSUM and TUNNEL_ENCAP. It reuses existing reasons for tunnel lookup, header validation, PMTU and allocation failures. The device error counters keep their existing meanings.
I used Claude Code and Codex to help develop, test and review the series and edit the patch descriptions. Testing included virtme-ng and a local run of the Sashiko review prompts. I take responsibility for the changes.
Changes since v7:
- Rebase onto net-next eb6d6c80d354.
- Group the four new drop reasons with the existing tunnel reasons, immediately after TUNNEL_NOT_FOUND, as requested by Jakub.
- v7: https://lore.kernel.org/netdev/[email protected]/
Changes since v6:
- Rebase onto net-next a0aa9ceca03f as requested by Jakub.
- In patches 4 and 5, report TUNNEL_INVALID_HDR for the ERSPAN checks added by 7ccc5e05043b ("erspan: drop packets with an unknown ERSPAN version"), including the type I check on IPv6.
- Carry Ido's Reviewed-by on patches 1-3 and 6-8. Leave it off 4 and 5 for review of the new drop reasons. Shorten the patch descriptions.
- v6: https://lore.kernel.org/netdev/[email protected]/
Changes since v5:
- Split out the vxlan patches (now in net-next) and defer IPv6 TX.
- Set a reason on each path to a drop label. Keep NOT_SPECIFIED for looped-back multicast and ip6_tnl_rcv_ctl() failures.
- Add patch 6 to distinguish allocation failures in ip_tunnel_encap(). Its IPv6 counterpart will follow with ip6_tnl_xmit().
- Mention reordering in the TUNNEL_OLD_SEQ description. The vxlan series already updated the RECURSION_LIMIT description.
- Describe AI assistance in the cover letter after 1e035297ffda ("docs: remove Assisted-by references").
- v5: https://lore.kernel.org/netdev/[email protected]/
- vxlan part of v5: https://lore.kernel.org/netdev/[email protected]/
- v4: https://lore.kernel.org/netdev/[email protected]/
- v3: https://lore.kernel.org/netdev/[email protected]/
- v2: https://lore.kernel.org/netdev/[email protected]/
- v1: https://lore.kernel.org/netdev/[email protected]/
Anton Danilov (8):
ip_tunnel: add drop reasons to the generic RX path
ip6_tunnel: add drop reasons to the receive path
gre: make gre_parse_header() report a drop reason
ip_gre: add drop reasons to the RX path
ip6_gre: add drop reasons to the RX path
ip_tunnel: make ip_tunnel_encap() return a drop reason
ip_tunnel: add drop reasons to the transmit path
ip_gre: add drop reasons to the transmit path
include/net/dropreason-core.h | 31 +++++- include/net/gre.h | 5 +- include/net/ip_tunnels.h | 20 ++-- net/ipv4/gre_demux.c | 64 +++++++---- net/ipv4/ip_gre.c | 199 ++++++++++++++++++++++------------ net/ipv4/ip_tunnel.c | 61 ++++++++--- net/ipv6/ip6_gre.c | 66 ++++++----- net/ipv6/ip6_tunnel.c | 45 ++++++-- net/ipv6/sit.c | 2 +- 9 files changed, 331 insertions(+), 162 deletions(-)
base-commit: eb6d6c80d35449c27471b1874f13066c09a8964d
Signature · 1 line
2.47.3
PATCH v8 1/8 ip_tunnel: add drop reasons to the generic RX path
ip_tunnel_rcv() frees every rejected packet at the same call site. Report the failing check through skb:kfree_skb and drop_monitor while keeping the existing device error counters.
Use TUNNEL_OPT_MISMATCH when the checksum option differs from the tunnel configuration in either direction, or a required sequence number is missing. GRE checksum validation happens earlier. Use TUNNEL_OLD_SEQ for a sequence number below the expected value. A reordered packet or a peer that restarts its sequence numbering can trigger this check.
Propagate the reason from pskb_inet_may_pull_reason() and report ECN decapsulation failures as IP_TUNNEL_ECN.
--- include/net/dropreason-core.h | 17 +++++++++++++++++ net/ipv4/ip_tunnel.c | 19 +++++++++++++++---- 2 files changed, 32 insertions(+), 4 deletions(-)
include/net/dropreason-core.h +17 -0
@@ -113,6 +113,8 @@ FN(TC_RECLASSIFY_LOOP) \ FN(TUNNEL_INVALID_HDR) \ FN(TUNNEL_NOT_FOUND) \ + FN(TUNNEL_OPT_MISMATCH) \ + FN(TUNNEL_OLD_SEQ) \ FN(MAC_INVALID_SOURCE) \ FN(VXLAN_ENTRY_EXISTS) \ FN(NO_TX_TARGET) \
@@ -550,6 +552,21 @@ enum skb_drop_reason {* packet, e.g. no VXLAN device for its VNI */ SKB_DROP_REASON_TUNNEL_NOT_FOUND , +/** +* @SKB_DROP_REASON_TUNNEL_OPT_MISMATCH: the tunnel options carried by +* the packet do not match the tunnel configuration, e.g. a GRE tunnel +* configured with 'icsum' or 'iseq' received a packet with no checksum +* or no sequence number, or a GRE tunnel without 'icsum' received a +* packet with a checksum. +*/ +SKB_DROP_REASON_TUNNEL_OPT_MISMATCH , +/** +* @SKB_DROP_REASON_TUNNEL_OLD_SEQ: the sequence number carried by the +* packet is older than the one expected by the tunnel, e.g. the packet +* was reordered in the network or by the receive processing, or the +* remote endpoint restarted and reset its sequence numbering. +*/ +SKB_DROP_REASON_TUNNEL_OLD_SEQ ,/** @SKB_DROP_REASON_MAC_INVALID_SOURCE: source mac is invalid */ SKB_DROP_REASON_MAC_INVALID_SOURCE,/**
net/ipv4/ip_tunnel.c +15 -4
@@ -384,6 +384,7 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb, const struct tnl_ptk_info *tpi, struct metadata_dst *tun_dst, bool log_ecn_error) { + enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;const struct iphdr *iph =ip_hdr (skb);int nh, err;
@@ -398,14 +399,22 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb, test_bit(IP_TUNNEL_CSUM_BIT, tpi->flags)) {DEV_STATS_INC (tunnel->dev, rx_crc_errors);DEV_STATS_INC (tunnel->dev, rx_errors); + reason =SKB_DROP_REASON_TUNNEL_OPT_MISMATCH ; goto drop; }if (test_bit (IP_TUNNEL_SEQ_BIT , tunnel->parms.i_flags)) { -if (!test_bit (IP_TUNNEL_SEQ_BIT , tpi->flags) || - (tunnel->i_seqno && (s32)(ntohl (tpi->seq) - tunnel->i_seqno) <0 )) { +if (!test_bit (IP_TUNNEL_SEQ_BIT , tpi->flags)) {DEV_STATS_INC (tunnel->dev, rx_fifo_errors);DEV_STATS_INC (tunnel->dev, rx_errors); + reason =SKB_DROP_REASON_TUNNEL_OPT_MISMATCH ; + goto drop; + } +if (tunnel->i_seqno && + (s32)(ntohl (tpi->seq) - tunnel->i_seqno) <0 ) { +DEV_STATS_INC (tunnel->dev, rx_fifo_errors); +DEV_STATS_INC (tunnel->dev, rx_errors); + reason =SKB_DROP_REASON_TUNNEL_OLD_SEQ ; goto drop; } tunnel->i_seqno =ntohl (tpi->seq) +1 ;
@@ -419,7 +428,8 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,skb_set_network_header (skb, (tunnel->dev->type ==ARPHRD_ETHER ) ?ETH_HLEN :0 ); -if (!pskb_inet_may_pull (skb)) { + reason =pskb_inet_may_pull_reason (skb); +if (reason) {DEV_STATS_INC (tunnel->dev, rx_length_errors);DEV_STATS_INC (tunnel->dev, rx_errors); goto drop;
@@ -434,6 +444,7 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb,if (err >1 ) {DEV_STATS_INC (tunnel->dev, rx_frame_errors);DEV_STATS_INC (tunnel->dev, rx_errors); + reason =SKB_DROP_REASON_IP_TUNNEL_ECN ; goto drop; } }
@@ -457,7 +468,7 @@ int ip_tunnel_rcv(struct ip_tunnel *tunnel, struct sk_buff *skb, drop:if (tun_dst)dst_release ((struct dst_entry *)tun_dst); -kfree_skb (skb); +kfree_skb_reason (skb, reason);return 0 ; }EXPORT_SYMBOL_GPL (ip_tunnel_rcv);
Signature · 1 line
2.47.3
PATCH v8 2/8 ip6_tunnel: add drop reasons to the receive path
In reply to Anton DanilovReport the same option, sequence and ECN failures in __ip6_tnl_rcv() as in ip_tunnel_rcv(). Preserve the reason from skb_vlan_inet_prepare() and use pskb_may_pull_reason() for the Ethernet header check.
Also report drops in ipxip6_rcv() before it hands the packet to the common receive path. Distinguish a payload protocol mismatch, an XFRM policy failure, a header pull failure and a metadata allocation failure. Keep NOT_SPECIFIED for ip6_tnl_rcv_ctl(), which returns a single value for several different failures.
--- net/ipv6/ip6_tunnel.c | 45 +++++++++++++++++++++++++++++++------------ 1 file changed, 33 insertions(+), 12 deletions(-)
net/ipv6/ip6_tunnel.c +33 -12
@@ -813,6 +813,7 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb, struct sk_buff *skb), bool log_ecn_err) { +enum skb_drop_reason reason =SKB_DROP_REASON_NOT_SPECIFIED ;const struct ipv6hdr *ipv6h;int nh, err;
@@ -820,15 +821,22 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb, test_bit(IP_TUNNEL_CSUM_BIT, tpi->flags)) {DEV_STATS_INC (tunnel->dev, rx_crc_errors);DEV_STATS_INC (tunnel->dev, rx_errors); + reason =SKB_DROP_REASON_TUNNEL_OPT_MISMATCH ; goto drop; }if (test_bit (IP_TUNNEL_SEQ_BIT , tunnel->parms.i_flags)) { -if (!test_bit (IP_TUNNEL_SEQ_BIT , tpi->flags) || - (tunnel->i_seqno && - (s32)(ntohl (tpi->seq) - tunnel->i_seqno) <0 )) { +if (!test_bit (IP_TUNNEL_SEQ_BIT , tpi->flags)) {DEV_STATS_INC (tunnel->dev, rx_fifo_errors);DEV_STATS_INC (tunnel->dev, rx_errors); + reason =SKB_DROP_REASON_TUNNEL_OPT_MISMATCH ; + goto drop; + } +if (tunnel->i_seqno && + (s32)(ntohl (tpi->seq) - tunnel->i_seqno) <0 ) { +DEV_STATS_INC (tunnel->dev, rx_fifo_errors); +DEV_STATS_INC (tunnel->dev, rx_errors); + reason =SKB_DROP_REASON_TUNNEL_OLD_SEQ ; goto drop; } tunnel->i_seqno =ntohl (tpi->seq) +1 ;
@@ -838,7 +846,8 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,/* Warning: All skb pointers will be invalidated! */ if (tunnel->dev->type ==ARPHRD_ETHER ) { -if (!pskb_may_pull (skb,ETH_HLEN )) { + reason =pskb_may_pull_reason (skb,ETH_HLEN ); +if (reason) {DEV_STATS_INC (tunnel->dev, rx_length_errors);DEV_STATS_INC (tunnel->dev, rx_errors); goto drop;
@@ -859,7 +868,8 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,skb_reset_network_header (skb); -if (skb_vlan_inet_prepare (skb, true)) { + reason =skb_vlan_inet_prepare (skb, true); +if (reason) {DEV_STATS_INC (tunnel->dev, rx_length_errors);DEV_STATS_INC (tunnel->dev, rx_errors); goto drop;
@@ -881,6 +891,7 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb,if (err >1 ) {DEV_STATS_INC (tunnel->dev, rx_frame_errors);DEV_STATS_INC (tunnel->dev, rx_errors); + reason =SKB_DROP_REASON_IP_TUNNEL_ECN ; goto drop; } }
@@ -898,7 +909,7 @@ static int __ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb, drop:if (tun_dst)dst_release ((struct dst_entry *)tun_dst); -kfree_skb (skb); +kfree_skb_reason (skb, reason);return 0 ; }
@@ -941,6 +952,7 @@ static int ipxip6_rcv(struct sk_buff *skb, u8 ipproto,const struct ipv6hdr *ipv6h, struct sk_buff *skb)) { + enum skb_drop_reason reason = SKB_DROP_REASON_NOT_SPECIFIED;struct ip6_tnl *t;const struct ipv6hdr *ipv6h =ipv6_hdr (skb);struct metadata_dst *tun_dst =NULL ;
@@ -952,21 +964,30 @@ static int ipxip6_rcv(struct sk_buff *skb, u8 ipproto,if (t) {u8 tproto =READ_ONCE (t->parms.proto); -if (tproto != ipproto && tproto !=0 ) +if (tproto != ipproto && tproto !=0 ) { + reason =SKB_DROP_REASON_UNHANDLED_PROTO ; goto drop; -if (!xfrm6_policy_check (NULL ,XFRM_POLICY_IN , skb)) + } +if (!xfrm6_policy_check (NULL ,XFRM_POLICY_IN , skb)) { + reason =SKB_DROP_REASON_XFRM_POLICY ; goto drop; + } ipv6h =ipv6_hdr (skb); -if (!ip6_tnl_rcv_ctl (t, &ipv6h->daddr, &ipv6h->saddr)) +if (!ip6_tnl_rcv_ctl (t, &ipv6h->daddr, &ipv6h->saddr)) { + reason =SKB_DROP_REASON_NOT_SPECIFIED ; goto drop; -if (iptunnel_pull_header (skb,0 , tpi->proto, false)) + } + reason =iptunnel_pull_header (skb,0 , tpi->proto, false); +if (reason) goto drop;if (t->parms.collect_md) {IP_TUNNEL_DECLARE_FLAGS (flags) = { }; tun_dst =ipv6_tun_rx_dst (skb, flags,0 ,0 ); -if (!tun_dst) +if (!tun_dst) { + reason =SKB_DROP_REASON_NOMEM ; goto drop; + } } ret =__ip6_tnl_rcv (t, skb, tpi, tun_dst, dscp_ecn_decapsulate, log_ecn_error);
@@ -978,7 +999,7 @@ static int ipxip6_rcv(struct sk_buff *skb, u8 ipproto, drop:rcu_read_unlock (); -kfree_skb (skb); +kfree_skb_reason (skb, reason);return 0 ; }
Signature · 1 line
2.47.3
PATCH v8 3/8 gre: make gre_parse_header() report a drop reason
In reply to Anton Danilovgre_parse_header() returns -EINVAL for every failure. Neither receive caller uses its csum_err output. Return a drop reason and let callers read the parsed header length from tpi->hdr_len.
Use GRE_CSUM for a bad checksum and TUNNEL_INVALID_HDR for unsupported version or routing bits. Propagate header pull failures. The WCCP byte read with skb_header_pointer() has no detailed error, so use PKT_TOO_SMALL there. In the demux, distinguish an invalid version from a valid version with no registered handler (UNHANDLED_PROTO).
ICMP error handlers may see only part of the original packet. Preserve their checksum handling by passing ignore_csum_err explicitly. After a successful parse, reset the receive drop reason to NOT_SPECIFIED until the tunnel handlers themselves return reasons.
--- include/net/dropreason-core.h | 4 +++ include/net/gre.h | 5 +-- net/ipv4/gre_demux.c | 64 ++++++++++++++++++++++++----------- net/ipv4/ip_gre.c | 23 +++++++------ net/ipv6/ip6_gre.c | 19 ++++++----- 5 files changed, 74 insertions(+), 41 deletions(-)
include/net/dropreason-core.h +4 -0
@@ -115,6 +115,7 @@ FN(TUNNEL_NOT_FOUND) \ FN(TUNNEL_OPT_MISMATCH) \ FN(TUNNEL_OLD_SEQ) \ + FN(GRE_CSUM) \ FN(MAC_INVALID_SOURCE) \ FN(VXLAN_ENTRY_EXISTS) \ FN(NO_TX_TARGET) \
@@ -545,6 +546,7 @@ enum skb_drop_reason {* @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 +* 3) GRE version is not supported or the routing bit is set */ SKB_DROP_REASON_TUNNEL_INVALID_HDR,/**
@@ -567,6 +569,8 @@ enum skb_drop_reason {* remote endpoint restarted and reset its sequence numbering. */ SKB_DROP_REASON_TUNNEL_OLD_SEQ , +/** @SKB_DROP_REASON_GRE_CSUM: GRE checksum error */ +SKB_DROP_REASON_GRE_CSUM ,/** @SKB_DROP_REASON_MAC_INVALID_SOURCE: source mac is invalid */ SKB_DROP_REASON_MAC_INVALID_SOURCE,/**
include/net/gre.h +3 -2
@@ -32,8 +32,9 @@ struct gre_protocol {int gre_add_protocol (const struct gre_protocol *proto,u8 version);int gre_del_protocol (const struct gre_protocol *proto,u8 version); -int gre_parse_header (struct sk_buff *skb,struct tnl_ptk_info *tpi, -bool *csum_err,__be16 proto,int nhs); +enum skb_drop_reason +gre_parse_header (struct sk_buff *skb,struct tnl_ptk_info *tpi, +bool ignore_csum_err,__be16 proto,int nhs);static inline bool netif_is_gretap (const struct net_device *dev) {
net/ipv4/gre_demux.c +44 -20
128 lines not on this page · raw message
net/ipv4/ip_gre.c +13 -10
@@ -237,8 +237,8 @@ static void gre_err(struct sk_buff *skb, u32 info)const int code =icmp_hdr (skb)->code;struct tnl_ptk_info tpi; -if (gre_parse_header (skb, &tpi,NULL ,htons (ETH_P_IP ), - iph->ihl *4 ) <0 ) +if (gre_parse_header (skb, &tpi, true,htons (ETH_P_IP ), + iph->ihl *4 ))return ;if (type ==ICMP_DEST_UNREACH && code ==ICMP_FRAG_NEEDED ) {
@@ -441,37 +441,40 @@ static int ipgre_rcv(struct sk_buff *skb, const struct tnl_ptk_info *tpi,static int gre_rcv (struct sk_buff *skb) { +enum skb_drop_reason reason =SKB_DROP_REASON_NOT_SPECIFIED ;struct tnl_ptk_info tpi; -bool csum_err = false; -int hdr_len;#ifdef CONFIG_NET_IPGRE_BROADCAST if (ipv4_is_multicast (ip_hdr (skb)->daddr)) {/* Looped back packet, drop it! */ -if (rt_is_output_route (skb_rtable (skb))) +if (rt_is_output_route (skb_rtable (skb))) { + reason =SKB_DROP_REASON_NOT_SPECIFIED ; goto drop; + } }#endif - hdr_len =gre_parse_header (skb, &tpi, &csum_err,htons (ETH_P_IP ),0 ); -if (hdr_len <0 ) + reason =gre_parse_header (skb, &tpi, false,htons (ETH_P_IP ),0 ); +if (reason) goto drop; + reason =SKB_DROP_REASON_NOT_SPECIFIED ; +if (unlikely (tpi.proto ==htons (ETH_P_ERSPAN ) || tpi.proto ==htons (ETH_P_ERSPAN2 ))) { -if (erspan_rcv (skb, &tpi, hdr_len) ==PACKET_RCVD ) +if (erspan_rcv (skb, &tpi, tpi.hdr_len) ==PACKET_RCVD )return 0 ; goto out; } -if (ipgre_rcv (skb, &tpi, hdr_len) ==PACKET_RCVD ) +if (ipgre_rcv (skb, &tpi, tpi.hdr_len) ==PACKET_RCVD )return 0 ; out:icmp_send (skb,ICMP_DEST_UNREACH ,ICMP_PORT_UNREACH ,0 ); drop:dev_core_stats_rx_dropped_inc (skb->dev); -kfree_skb (skb); +kfree_skb_reason (skb, reason);return 0 ; }
net/ipv6/ip6_gre.c +10 -9
@@ -389,8 +389,8 @@ static int ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt,struct tnl_ptk_info tpi;struct ip6_tnl *t; -if (gre_parse_header (skb, &tpi,NULL ,htons (ETH_P_IPV6 ), - offset) <0 ) +if (gre_parse_header (skb, &tpi, true,htons (ETH_P_IPV6 ), + offset))return -EINVAL ; ipv6h = (const struct ipv6hdr *)skb->data;
@@ -575,20 +575,21 @@ static int ip6erspan_rcv(struct sk_buff *skb,static int gre_rcv (struct sk_buff *skb) { +enum skb_drop_reason reason;struct tnl_ptk_info tpi; -bool csum_err = false; -int hdr_len; - hdr_len =gre_parse_header (skb, &tpi, &csum_err,htons (ETH_P_IPV6 ),0 ); -if (hdr_len <0 ) + reason =gre_parse_header (skb, &tpi, false,htons (ETH_P_IPV6 ),0 ); +if (reason) goto drop; -if (iptunnel_pull_header (skb, hdr_len, tpi.proto, false)) + reason =SKB_DROP_REASON_NOT_SPECIFIED ; + +if (iptunnel_pull_header (skb, tpi.hdr_len, tpi.proto, false)) goto drop;if (unlikely (tpi.proto ==htons (ETH_P_ERSPAN ) || tpi.proto ==htons (ETH_P_ERSPAN2 ))) { -if (ip6erspan_rcv (skb, &tpi, hdr_len) ==PACKET_RCVD ) +if (ip6erspan_rcv (skb, &tpi, tpi.hdr_len) ==PACKET_RCVD )return 0 ; goto out; }
@@ -600,7 +601,7 @@ static int gre_rcv(struct sk_buff *skb)icmpv6_send (skb,ICMPV6_DEST_UNREACH ,ICMPV6_PORT_UNREACH ,0 ); drop:dev_core_stats_rx_dropped_inc (skb->dev); -kfree_skb (skb); +kfree_skb_reason (skb, reason);return 0 ; }
Signature · 1 line
2.47.3
PATCH v8 4/8 ip_gre: add drop reasons to the RX path
In reply to Anton DanilovAn IPv4 GRE packet that matches no tunnel is reported at the same drop site as a truncated header. Report TUNNEL_NOT_FOUND for a lookup miss and preserve the ETH_P_TEB fallback lookup only for that result.
Have the receive handlers return a drop reason when the caller must free the skb, and zero when they have consumed it. Propagate header pull failures, use NOMEM for metadata allocation failures, and report an unsupported ERSPAN version as TUNNEL_INVALID_HDR.
---
v7: Report TUNNEL_INVALID_HDR for the new ERSPAN version check. Omit Ido's Reviewed-by pending review of this change.
include/net/dropreason-core.h | 3 +- net/ipv4/ip_gre.c | 83 +++++++++++++++++++---------------- 2 files changed, 48 insertions(+), 38 deletions(-)
include/net/dropreason-core.h +2 -1
@@ -551,7 +551,8 @@ enum skb_drop_reason {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 +* packet, e.g. no VXLAN device for its VNI or no GRE tunnel for its +* endpoints and key */ SKB_DROP_REASON_TUNNEL_NOT_FOUND,/**
net/ipv4/ip_gre.c +46 -37
168 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH v8 5/8 ip6_gre: add drop reasons to the RX path
In reply to Anton DanilovHave the IPv6 GRE and ERSPAN receive handlers return the reason for rejecting an skb. Report TUNNEL_NOT_FOUND for a lookup miss and NOMEM for a metadata allocation failure. Use TUNNEL_INVALID_HDR for an unsupported ERSPAN version or ERSPAN type I over IPv6.
Preserve the reason from header pulls. IPv6 GRE pulls the inner header before tunnel lookup, so a truncated ETH_P_TEB header is reported even if no tunnel would match.
Remove the now unused PACKET_* return codes. In particular, a leftover PACKET_REJECT would compile as a drop reason with the value of SKB_CONSUMED.
---
v7: Report TUNNEL_INVALID_HDR for the new ERSPAN version and type I checks. Omit Ido's Reviewed-by pending review of this change.
include/net/ip_tunnels.h | 4 --- net/ipv6/ip6_gre.c | 55 ++++++++++++++++++++++------------------ 2 files changed, 30 insertions(+), 29 deletions(-)
include/net/ip_tunnels.h +0 -4
@@ -207,10 +207,6 @@ struct tnl_ptk_info {int hdr_len; }; -#define PACKET_RCVD 0 -#define PACKET_REJECT 1 -#define PACKET_NEXT 2 -#define IP_TNL_HASH_BITS 7#define IP_TNL_HASH_SIZE (1 << IP_TNL_HASH_BITS)
net/ipv6/ip6_gre.c +30 -25
123 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH v8 6/8 ip_tunnel: make ip_tunnel_encap() return a drop reason
In reply to Anton DanilovIPv4 tunnel transmitters need the reason why encapsulation failed. Make ip_tunnel_encap() return NOMEM when the FOU or GUE build_header() callback returns -ENOMEM, and TUNNEL_ENCAP for other failures. Success, including when encapsulation is disabled, still returns zero.
Update both callers in ip_tunnel.c and the one in sit.c to test for a nonzero result. Their old negative-error test would miss a drop reason.
--- include/net/dropreason-core.h | 7 +++++++ include/net/ip_tunnels.h | 16 ++++++++++------ net/ipv4/ip_tunnel.c | 4 ++-- net/ipv6/sit.c | 2 +- 4 files changed, 20 insertions(+), 9 deletions(-)
include/net/dropreason-core.h +7 -0
@@ -116,6 +116,7 @@ FN(TUNNEL_OPT_MISMATCH) \ FN(TUNNEL_OLD_SEQ) \ FN(GRE_CSUM) \ + FN(TUNNEL_ENCAP) \ FN(MAC_INVALID_SOURCE) \ FN(VXLAN_ENTRY_EXISTS) \ FN(NO_TX_TARGET) \
@@ -572,6 +573,12 @@ enum skb_drop_reason {SKB_DROP_REASON_TUNNEL_OLD_SEQ ,/** @SKB_DROP_REASON_GRE_CSUM: GRE checksum error */ SKB_DROP_REASON_GRE_CSUM , +/** +* @SKB_DROP_REASON_TUNNEL_ENCAP: failed to build the encapsulation +* header of a tunnel, e.g. an unknown or unregistered encapsulation +* type. +*/ +SKB_DROP_REASON_TUNNEL_ENCAP ,/** @SKB_DROP_REASON_MAC_INVALID_SOURCE: source mac is invalid */ SKB_DROP_REASON_MAC_INVALID_SOURCE,/**
include/net/ip_tunnels.h +10 -6
@@ -541,18 +541,18 @@ static inline int ip_encap_hlen(struct ip_tunnel_encap *e)return hlen; } -static inline int ip_tunnel_encap (struct sk_buff *skb, -struct ip_tunnel_encap *e, -u8 *protocol,struct flowi4 *fl4) +static inline enum skb_drop_reason +ip_tunnel_encap (struct sk_buff *skb,struct ip_tunnel_encap *e, +u8 *protocol,struct flowi4 *fl4) {const struct ip_tunnel_encap_ops *ops;int ret = -EINVAL ;if (e->type ==TUNNEL_ENCAP_NONE ) -return 0 ; +return SKB_NOT_DROPPED_YET ;if (e->type >=MAX_IPTUN_ENCAP_OPS ) -return -EINVAL ; +return SKB_DROP_REASON_TUNNEL_ENCAP ;rcu_read_lock (); ops =rcu_dereference (iptun_encaps[e->type]);
@@ -560,7 +560,11 @@ static inline int ip_tunnel_encap(struct sk_buff *skb, ret = ops->build_header (skb, e, protocol, fl4);rcu_read_unlock (); -return ret; +if (!ret) +return SKB_NOT_DROPPED_YET ; +if (ret == -ENOMEM ) +return SKB_DROP_REASON_NOMEM ; +return SKB_DROP_REASON_TUNNEL_ENCAP ; }/* Extract dsfield from inner protocol */
net/ipv4/ip_tunnel.c +2 -2
@@ -619,7 +619,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,if (!tunnel_hlen) tunnel_hlen =ip_encap_hlen (&tun_info->encap); -if (ip_tunnel_encap (skb, &tun_info->encap, &proto, &fl4) <0 ) +if (ip_tunnel_encap (skb, &tun_info->encap, &proto, &fl4)) goto tx_error; inner_iph = (const struct iphdr *)skb_inner_network_header (skb);
@@ -783,7 +783,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, tunnel->net,READ_ONCE (tunnel->parms.link), tunnel->fwmark, skb_get_hash(skb), 0); -if (ip_tunnel_encap (skb, &tunnel->encap, &protocol, &fl4) <0 ) +if (ip_tunnel_encap (skb, &tunnel->encap, &protocol, &fl4)) goto tx_error; inner_iph = (const struct iphdr *)skb_inner_network_header (skb);
net/ipv6/sit.c +1 -1
@@ -1096,7 +1096,7 @@ static netdev_tx_t ipip6_tunnel_xmit(struct sk_buff *skb, ttl = iph6->hop_limit; tos =INET_ECN_encapsulate (tos,ipv6_get_dsfield (iph6)); -if (ip_tunnel_encap (skb, &tunnel->encap, &protocol, &fl4) <0 ) { +if (ip_tunnel_encap (skb, &tunnel->encap, &protocol, &fl4)) {ip_rt_put (rt); goto tx_error; }
Signature · 1 line
2.47.3
PATCH v8 7/8 ip_tunnel: add drop reasons to the transmit path
In reply to Anton Danilovip_tunnel_xmit() and ip_md_tunnel_xmit() free packets from unrelated failures at a common drop site in each function. In particular, a PMTU drop after sending an ICMP error and a failed encapsulation both increment tx_errors. Report PKT_TOO_BIG for the former and propagate the reason from ip_tunnel_encap() for the latter.
Use IP_OUTNOROUTES for a failed route lookup, RECURSION_LIMIT for a route back to the tunnel device and NOMEM for headroom allocation. Distinguish an NBMA neighbour lookup failure from a missing transmit target, and report TUNNEL_TXINFO for invalid external-mode metadata.
--- net/ipv4/ip_tunnel.c | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-)
net/ipv4/ip_tunnel.c +30 -12
@@ -586,6 +586,7 @@ static int tnl_update_pmtu(struct net_device *dev, struct sk_buff *skb,void ip_md_tunnel_xmit (struct sk_buff *skb,struct net_device *dev,u8 proto,int tunnel_hlen) { +enum skb_drop_reason reason =SKB_DROP_REASON_NOT_SPECIFIED ;struct ip_tunnel *tunnel =netdev_priv (dev);u32 headroom =sizeof (struct iphdr );struct ip_tunnel_info *tun_info;
@@ -599,8 +600,10 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, tun_info =skb_tunnel_info (skb);if (unlikely (!tun_info || !(tun_info->mode &IP_TUNNEL_INFO_TX ) || -ip_tunnel_info_af (tun_info) !=AF_INET )) +ip_tunnel_info_af (tun_info) !=AF_INET )) { + reason =SKB_DROP_REASON_TUNNEL_TXINFO ; goto tx_error; + } key = &tun_info->key;memset (&(IPCB (skb)->opt),0 ,sizeof (IPCB (skb)->opt)); inner_iph = (const struct iphdr *)skb_inner_network_header (skb);
@@ -619,7 +622,8 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,if (!tunnel_hlen) tunnel_hlen =ip_encap_hlen (&tun_info->encap); -if (ip_tunnel_encap (skb, &tun_info->encap, &proto, &fl4)) + reason =ip_tunnel_encap (skb, &tun_info->encap, &proto, &fl4); +if (reason) goto tx_error; inner_iph = (const struct iphdr *)skb_inner_network_header (skb);
@@ -630,6 +634,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, rt =ip_route_output_key (tunnel->net, &fl4);if (IS_ERR (rt)) {DEV_STATS_INC (dev, tx_carrier_errors); + reason =SKB_DROP_REASON_IP_OUTNOROUTES ; goto tx_error; }if (use_cache)
@@ -639,6 +644,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,if (rt->dst.dev == dev) {ip_rt_put (rt);DEV_STATS_INC (dev, collisions); + reason =SKB_DROP_REASON_RECURSION_LIMIT ; goto tx_error; }
@@ -647,6 +653,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,if (tnl_update_pmtu (dev, skb, rt, df, inner_iph, tunnel_hlen, key->u.ipv4.dst, true)) {ip_rt_put (rt); + reason =SKB_DROP_REASON_PKT_TOO_BIG ; goto tx_error; }
@@ -664,6 +671,7 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, headroom +=LL_RESERVED_SPACE (rt->dst.dev) + rt->dst.header_len;if (skb_cow_head (skb, headroom)) {ip_rt_put (rt); + reason =SKB_DROP_REASON_NOMEM ; goto tx_dropped; }
@@ -678,13 +686,14 @@ void ip_md_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, tx_dropped:DEV_STATS_INC (dev, tx_dropped); kfree: -kfree_skb (skb); +kfree_skb_reason (skb, reason); }EXPORT_SYMBOL_GPL (ip_md_tunnel_xmit);void ip_tunnel_xmit (struct sk_buff *skb,struct net_device *dev,const struct iphdr *tnl_params,u8 protocol) { +enum skb_drop_reason reason =SKB_DROP_REASON_NOT_SPECIFIED ;struct ip_tunnel *tunnel =netdev_priv (dev);struct ip_tunnel_info *tun_info =NULL ;const struct iphdr *inner_iph;
@@ -712,6 +721,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,if (!skb_dst (skb)) {DEV_STATS_INC (dev, tx_fifo_errors); + reason =SKB_DROP_REASON_NO_TX_TARGET ; goto tx_error; }
@@ -725,9 +735,8 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, }else if (payload_protocol ==htons (ETH_P_IP )) { rt =skb_rtable (skb); dst =rt_nexthop (rt, inner_iph->daddr); - }#if IS_ENABLED (CONFIG_IPV6 ) - else if (payload_protocol == htons(ETH_P_IPV6)) { + } else if (payload_protocol == htons(ETH_P_IPV6)) {const struct in6_addr *addr6;struct neighbour *neigh;bool do_tx_error_icmp;
@@ -735,8 +744,10 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, neigh =dst_neigh_lookup (skb_dst (skb), &ipv6_hdr (skb)->daddr); -if (!neigh) +if (!neigh) { + reason =SKB_DROP_REASON_NEIGH_CREATEFAIL ; goto tx_error; + } addr6 = (const struct in6_addr *)&neigh->primary_key; addr_type =ipv6_addr_type (addr6);
@@ -753,12 +764,15 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, dst = addr6->s6_addr32[3]; }neigh_release (neigh); -if (do_tx_error_icmp) +if (do_tx_error_icmp) { + reason =SKB_DROP_REASON_NO_TX_TARGET ; goto tx_error_icmp; - } + }#endif - else + }else { + reason =SKB_DROP_REASON_NO_TX_TARGET ; goto tx_error; + }if (!md) connected = false;
@@ -783,7 +797,8 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, tunnel->net,READ_ONCE (tunnel->parms.link), tunnel->fwmark, skb_get_hash(skb), 0); -if (ip_tunnel_encap (skb, &tunnel->encap, &protocol, &fl4)) + reason =ip_tunnel_encap (skb, &tunnel->encap, &protocol, &fl4); +if (reason) goto tx_error; inner_iph = (const struct iphdr *)skb_inner_network_header (skb);
@@ -802,6 +817,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,if (IS_ERR (rt)) {DEV_STATS_INC (dev, tx_carrier_errors); + reason =SKB_DROP_REASON_IP_OUTNOROUTES ; goto tx_error; }if (use_cache)
@@ -815,6 +831,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,if (rt->dst.dev == dev) {ip_rt_put (rt);DEV_STATS_INC (dev, collisions); + reason =SKB_DROP_REASON_RECURSION_LIMIT ; goto tx_error; }
@@ -823,6 +840,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,if (tnl_update_pmtu (dev, skb, rt, df, inner_iph,0 ,0 , false)) {ip_rt_put (rt); + reason =SKB_DROP_REASON_PKT_TOO_BIG ; goto tx_error; }
@@ -856,7 +874,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,if (skb_cow_head (skb, max_headroom)) {ip_rt_put (rt);DEV_STATS_INC (dev, tx_dropped); -kfree_skb (skb); +kfree_skb_reason (skb,SKB_DROP_REASON_NOMEM );return ; }
@@ -872,7 +890,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,#endif tx_error:DEV_STATS_INC (dev, tx_errors); -kfree_skb (skb); +kfree_skb_reason (skb, reason); }EXPORT_SYMBOL_GPL (ip_tunnel_xmit);
Signature · 1 line
2.47.3
PATCH v8 8/8 ip_gre: add drop reasons to the transmit path
In reply to Anton DanilovThe ip_gre transmit handlers count drops in tx_dropped, but the common free site in each handler hides which check failed. Preserve the reasons from the header length checks and report NOMEM for headroom, offload preparation and trim failures.
Report TUNNEL_TXINFO for missing or incomplete tunnel metadata, UNHANDLED_PROTO for an unsupported transmit ERSPAN version and SKB_CSUM when the checksum starts before the data to be sent.
--- net/ipv4/ip_gre.c | 101 +++++++++++++++++++++++++++++++++------------- 1 file changed, 74 insertions(+), 27 deletions(-)
net/ipv4/ip_gre.c +74 -27
@@ -510,6 +510,7 @@ static int gre_handle_offloads(struct sk_buff *skb, bool csum)static void gre_fb_xmit (struct sk_buff *skb,struct net_device *dev,__be16 proto) { +enum skb_drop_reason reason =SKB_DROP_REASON_NOT_SPECIFIED ;struct ip_tunnel *tunnel =netdev_priv (dev);IP_TUNNEL_DECLARE_FLAGS (flags) = { };struct ip_tunnel_info *tun_info;
@@ -518,19 +519,25 @@ static void gre_fb_xmit(struct sk_buff *skb, struct net_device *dev, tun_info =skb_tunnel_info (skb);if (unlikely (!tun_info || !(tun_info->mode &IP_TUNNEL_INFO_TX ) || -ip_tunnel_info_af (tun_info) !=AF_INET )) +ip_tunnel_info_af (tun_info) !=AF_INET )) { + reason =SKB_DROP_REASON_TUNNEL_TXINFO ; goto err_free_skb; + } key = &tun_info->key; tunnel_hlen =gre_calc_hlen (key->tun_flags); -if (skb_cow_head (skb, dev->needed_headroom)) +if (skb_cow_head (skb, dev->needed_headroom)) { + reason =SKB_DROP_REASON_NOMEM ; goto err_free_skb; + }/* Push Tunnel header. */ if (gre_handle_offloads (skb,test_bit (IP_TUNNEL_CSUM_BIT , - tunnel->parms.o_flags))) + tunnel->parms.o_flags))) { + reason =SKB_DROP_REASON_NOMEM ; goto err_free_skb; + }__set_bit (IP_TUNNEL_CSUM_BIT , flags);__set_bit (IP_TUNNEL_KEY_BIT , flags);
@@ -547,12 +554,13 @@ static void gre_fb_xmit(struct sk_buff *skb, struct net_device *dev,return ; err_free_skb: -kfree_skb (skb); +kfree_skb_reason (skb, reason);DEV_STATS_INC (dev, tx_dropped); }static void erspan_fb_xmit (struct sk_buff *skb,struct net_device *dev) { +enum skb_drop_reason reason =SKB_DROP_REASON_NOT_SPECIFIED ;struct ip_tunnel *tunnel =netdev_priv (dev);IP_TUNNEL_DECLARE_FLAGS (flags) = { };struct ip_tunnel_info *tun_info;
@@ -566,29 +574,41 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev) tun_info =skb_tunnel_info (skb);if (unlikely (!tun_info || !(tun_info->mode &IP_TUNNEL_INFO_TX ) || -ip_tunnel_info_af (tun_info) !=AF_INET )) +ip_tunnel_info_af (tun_info) !=AF_INET )) { + reason =SKB_DROP_REASON_TUNNEL_TXINFO ; goto err_free_skb; + } key = &tun_info->key; -if (!test_bit (IP_TUNNEL_ERSPAN_OPT_BIT , tun_info->key.tun_flags)) +if (!test_bit (IP_TUNNEL_ERSPAN_OPT_BIT , tun_info->key.tun_flags)) { + reason =SKB_DROP_REASON_TUNNEL_TXINFO ; goto err_free_skb; -if (tun_info->options_len <sizeof (*md)) + } +if (tun_info->options_len <sizeof (*md)) { + reason =SKB_DROP_REASON_TUNNEL_TXINFO ; goto err_free_skb; + } md =ip_tunnel_info_opts (tun_info);/* ERSPAN has fixed 8 byte GRE header */ version = md->version; tunnel_hlen =8 +erspan_hdr_len (version); -if (skb_cow_head (skb, dev->needed_headroom)) +if (skb_cow_head (skb, dev->needed_headroom)) { + reason =SKB_DROP_REASON_NOMEM ; goto err_free_skb; + } -if (gre_handle_offloads (skb, false)) +if (gre_handle_offloads (skb, false)) { + reason =SKB_DROP_REASON_NOMEM ; goto err_free_skb; + }if (skb->len > dev->mtu + dev->hard_header_len) { -if (pskb_trim (skb, dev->mtu + dev->hard_header_len)) +if (pskb_trim (skb, dev->mtu + dev->hard_header_len)) { + reason =SKB_DROP_REASON_NOMEM ; goto err_free_skb; + } truncate = true; }
@@ -620,6 +640,7 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev) truncate, true); proto =htons (ETH_P_ERSPAN2 ); }else { + reason =SKB_DROP_REASON_UNHANDLED_PROTO ; goto err_free_skb; }
@@ -632,7 +653,7 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev)return ; err_free_skb: -kfree_skb (skb); +kfree_skb_reason (skb, reason);DEV_STATS_INC (dev, tx_dropped); }
@@ -666,8 +687,10 @@ static netdev_tx_t ipgre_xmit(struct sk_buff *skb,struct ip_tunnel *tunnel =netdev_priv (dev);IP_TUNNEL_DECLARE_FLAGS (flags);const struct iphdr *tnl_params; +enum skb_drop_reason reason; -if (!pskb_inet_may_pull (skb)) + reason =pskb_inet_may_pull_reason (skb); +if (reason) goto free_skb;if (tunnel->collect_md) {
@@ -678,10 +701,13 @@ static netdev_tx_t ipgre_xmit(struct sk_buff *skb,if (dev->header_ops) {int pull_len = tunnel->hlen +sizeof (struct iphdr ); -if (skb_cow_head (skb,0 )) +if (skb_cow_head (skb,0 )) { + reason =SKB_DROP_REASON_NOMEM ; goto free_skb; + } -if (!pskb_may_pull (skb, pull_len)) + reason =pskb_may_pull_reason (skb, pull_len); +if (reason) goto free_skb; tnl_params = (const struct iphdr *)skb->data;
@@ -691,25 +717,31 @@ static netdev_tx_t ipgre_xmit(struct sk_buff *skb,skb_reset_mac_header (skb);if (skb->ip_summed ==CHECKSUM_PARTIAL && -skb_checksum_start (skb) < skb->data) +skb_checksum_start (skb) < skb->data) { + reason =SKB_DROP_REASON_SKB_CSUM ; goto free_skb; + } }else { -if (skb_cow_head (skb, dev->needed_headroom)) +if (skb_cow_head (skb, dev->needed_headroom)) { + reason =SKB_DROP_REASON_NOMEM ; goto free_skb; + } tnl_params = &tunnel->parms.iph; }ip_tunnel_flags_copy (flags, tunnel->parms.o_flags); -if (gre_handle_offloads (skb,test_bit (IP_TUNNEL_CSUM_BIT , flags))) +if (gre_handle_offloads (skb,test_bit (IP_TUNNEL_CSUM_BIT , flags))) { + reason =SKB_DROP_REASON_NOMEM ; goto free_skb; + }__gre_xmit (skb, dev, tnl_params, skb->protocol, flags);return NETDEV_TX_OK ; free_skb: -kfree_skb (skb); +kfree_skb_reason (skb, reason);DEV_STATS_INC (dev, tx_dropped);return NETDEV_TX_OK ; }
@@ -719,10 +751,12 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb, {struct ip_tunnel *tunnel =netdev_priv (dev);IP_TUNNEL_DECLARE_FLAGS (flags); +enum skb_drop_reason reason;bool truncate = false;__be16 proto; -if (!pskb_inet_may_pull (skb)) + reason =pskb_inet_may_pull_reason (skb); +if (reason) goto free_skb;if (tunnel->collect_md) {
@@ -730,15 +764,21 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,return NETDEV_TX_OK ; } -if (gre_handle_offloads (skb, false)) +if (gre_handle_offloads (skb, false)) { + reason =SKB_DROP_REASON_NOMEM ; goto free_skb; + } -if (skb_cow_head (skb, dev->needed_headroom)) +if (skb_cow_head (skb, dev->needed_headroom)) { + reason =SKB_DROP_REASON_NOMEM ; goto free_skb; + }if (skb->len > dev->mtu + dev->hard_header_len) { -if (pskb_trim (skb, dev->mtu + dev->hard_header_len)) +if (pskb_trim (skb, dev->mtu + dev->hard_header_len)) { + reason =SKB_DROP_REASON_NOMEM ; goto free_skb; + } truncate = true; }
@@ -759,6 +799,7 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb, truncate, true); proto =htons (ETH_P_ERSPAN2 ); }else { + reason =SKB_DROP_REASON_UNHANDLED_PROTO ; goto free_skb; }
@@ -767,7 +808,7 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,return NETDEV_TX_OK ; free_skb: -kfree_skb (skb); +kfree_skb_reason (skb, reason);DEV_STATS_INC (dev, tx_dropped);return NETDEV_TX_OK ; }
@@ -777,8 +818,10 @@ static netdev_tx_t gre_tap_xmit(struct sk_buff *skb, {struct ip_tunnel *tunnel =netdev_priv (dev);IP_TUNNEL_DECLARE_FLAGS (flags); +enum skb_drop_reason reason; -if (!pskb_inet_may_pull (skb)) + reason =pskb_inet_may_pull_reason (skb); +if (reason) goto free_skb;if (tunnel->collect_md) {
@@ -788,17 +831,21 @@ static netdev_tx_t gre_tap_xmit(struct sk_buff *skb,ip_tunnel_flags_copy (flags, tunnel->parms.o_flags); -if (gre_handle_offloads (skb,test_bit (IP_TUNNEL_CSUM_BIT , flags))) +if (gre_handle_offloads (skb,test_bit (IP_TUNNEL_CSUM_BIT , flags))) { + reason =SKB_DROP_REASON_NOMEM ; goto free_skb; + } -if (skb_cow_head (skb, dev->needed_headroom)) +if (skb_cow_head (skb, dev->needed_headroom)) { + reason =SKB_DROP_REASON_NOMEM ; goto free_skb; + }__gre_xmit (skb, dev, &tunnel->parms.iph,htons (ETH_P_TEB ), flags);return NETDEV_TX_OK ; free_skb: -kfree_skb (skb); +kfree_skb_reason (skb, reason);DEV_STATS_INC (dev, tx_dropped);return NETDEV_TX_OK ; }
Signature · 1 line
2.47.3