tunnels: add core and gre drop reasons
Subsystems (3)
v4 cover tunnels: add core and gre drop reasons
Only vxlan reports drop reasons among the tunnel drivers today. The ones converted here free what they drop with kfree_skb(), which drop_monitor and the skb:kfree_skb tracepoint do report, but as NOT_SPECIFIED, with the call site as the only hint at which check failed. That hint does not go far: all the failures of ip_tunnel_rcv() end at one call site, and so do nearly all of those of each transmit function. The call site is not a stable interface either: its offset moves with the compiler, inlining and the configuration, so a filter on it has to follow every rebuild. The reason stays the same across kernels, whether NET_DM_ATTR_REASON reports it or a BPF program matches it by name. The device counters group the failures coarsely too: rx_errors and tx_errors each lump together unrelated conditions.
This series covers the generic paths shared by ipip, sit, gre and their IPv6 counterparts, plus the GRE specific code, in both directions. A later series will do the same for geneve, bareudp, fou and the remaining IP in IP drivers.
Patches 1-2 convert the generic receive paths, ip_tunnel_rcv() and __ip6_tnl_rcv(). Two reasons are added:
TNL_OPT_MISMATCH the options a packet carries do not match the
tunnel configuration
TNL_OLD_SEQ the sequence number is older than the one the
tunnel expects, like TCP_OLD_SEQUENCE for TCP
The second one has a failure mode worth naming: when a peer reboots, its outgoing sequence number restarts at zero, and the receiver drops everything until the peer's numbers get past the last one the receiver accepted. By the counters alone that looks like a misconfiguration: a packet without the sequence number option bumps the same rx_fifo_errors.
Patches 3-6 convert the GRE specific receive path. gre_parse_header() returns -EINVAL for every failure, and the only detail its callers could get was a csum_err flag that none of them read: both ip_gre and ip6_gre declared it, passed it in and ignored it. gre_parse_header() now returns a drop reason instead, and its callers take the header length from tpi->hdr_len. The receive helpers below gre_rcv() return the drop reason instead of a PACKET_* code, and the PACKET_* codes go away. Three reasons are added: GRE_INVALID_HDR and GRE_TUNNEL_NOT_FOUND, mirroring vxlan's VXLAN_INVALID_HDR and VXLAN_VNI_NOT_FOUND, and GRE_CSUM, like TCP_CSUM and UDP_CSUM.
Patch 4 adds __iptunnel_pull_header_reason(), because __iptunnel_pull_header() reports a packet too short to pull as -ENOMEM, the same as an allocation failure, and ip6_gre calls it for every GRE packet, before the tunnel lookup.
Patches 7-10 convert the transmit side of ip_tunnel, ip_gre, ip6_tunnel and ip6_gre. One reason is added, TNL_ENCAP, for a failure to build the encapsulation header. Patch 9 is a small preparation:prepare_ip6gre_xmit_other() cannot fail, so it is made void rather than given a drop reason for a branch that never runs. ip6_tnl_xmit() leaves freeing the packet to its callers, so it and the helpers between it and the ndo_start_xmit handlers return the drop reason instead of an error.
The transmit side has its own case worth naming: tnl_update_pmtu() returns -E2BIG after it has already sent the ICMP error back, which is path MTU discovery working exactly as intended, yet among the device counters the drop only bumps tx_errors, like a failed encapsulation and a few other failures do. If the ICMP error never reaches the sender, the resulting MTU black hole cannot be told from those by the device counters; the reason tells them apart.
Drop reasons on transmit are not new: vxlan already reports several from its xmit path, and ip_tunnel_core.c reports RECURSION_LIMIT. They are most useful for forwarded packets, which is what a tunnel gateway mostly
transmits: the sender is another host, which gets an ICMP error for only some of these failures, so the drop has to be explained on the gateway.
Changes since v3:
- the functions that took a drop reason output parameter now return the reason, SKB_NOT_DROPPED_YET on success: gre_parse_header(), the GRE receive helpers, ip6_tnl_xmit() and the helpers between it and the ndo_start_xmit handlers (Jakub)
- the callers of gre_parse_header() take the header length from tpi->hdr_len; the ICMP error handlers pass a new icmp_err argument instead of a NULL reason pointer
- the IPv6 transmit paths send the ICMP error on PKT_TOO_BIG, and ipgre_rcv() retries ETH_P_TEB on GRE_TUNNEL_NOT_FOUND: the same conditions as -EMSGSIZE and PACKET_NEXT before
- the motivation no longer says these drops are invisible; the problem is the NOT_SPECIFIED reason and the call site all the failures of a function share (Eric)
- new patch 4, __iptunnel_pull_header_reason(): a packet too short to pull is reported as PKT_TOO_SMALL instead of NOMEM
- PACKET_RCVD, PACKET_REJECT and PACKET_NEXT are removed
- the ip_tunnel transmit patch no longer says the counters cannot tell an MTU black hole from a failed route lookup
- the TNL_OPT_MISMATCH kernel-doc also covers an unexpected checksum; other commit message fixes
- 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 (10):
ip_tunnel: add drop reasons to the generic RX path
ip6_tunnel: add drop reasons to the generic RX path
gre: make gre_parse_header() report a drop reason
ip_tunnel: add __iptunnel_pull_header_reason()
ip_gre: add drop reasons to the RX path
ip6_gre: add drop reasons to the RX path
ip_tunnel: add drop reasons to the transmit path
ip_gre: add drop reasons to the transmit path
ip6_gre: make prepare_ip6gre_xmit_other() void
ip6_tunnel: add drop reasons to the transmit path
include/net/dropreason-core.h | 39 +++++++ include/net/gre.h | 5 +- include/net/ip6_tunnel.h | 5 +- include/net/ip_tunnels.h | 17 ++- net/ipv4/gre_demux.c | 42 ++++--- net/ipv4/ip_gre.c | 187 +++++++++++++++++++----------- net/ipv4/ip_tunnel.c | 60 ++++++++-- net/ipv4/ip_tunnel_core.c | 24 ++-- net/ipv6/ip6_gre.c | 211 ++++++++++++++++++++-------------- net/ipv6/ip6_tunnel.c | 123 ++++++++++++-------- 10 files changed, 467 insertions(+), 246 deletions(-)
Signature · 1 line
2.47.3
PATCH v4 1/10 ip_tunnel: add drop reasons to the generic RX path
ip_tunnel_rcv() collapses four distinct failures into the single kfree_skb() under its drop label:
- the tunnel options carried by the packet do not match the tunnel configuration (checksum or sequence number),
- the sequence number is older than the expected one,
- the inner network header cannot be pulled,
- the ECN decapsulation check fails (RFC 6040).
drop_monitor and the skb:kfree_skb tracepoint do see these packets, but all four as SKB_DROP_REASON_NOT_SPECIFIED from the same call site, so neither the reason nor the location tells the failures apart. Only the device error counters (rx_crc_errors, rx_fifo_errors, rx_length_errors, rx_frame_errors) hint at the cause, and they are not tied to the dropped packet.
Add two drop reasons for the tunnel specific cases and reuse the existing ones for the rest:
- SKB_DROP_REASON_TNL_OPT_MISMATCH is used when the packet lacks the checksum or the sequence number option the tunnel is configured for, or carries a checksum the tunnel is not configured for, as the checksum check compares both ways. This is a configuration mismatch between the two endpoints rather than a corrupted checksum: the checksum itself is validated earlier, in gre_parse_header().
- SKB_DROP_REASON_TNL_OLD_SEQ is used when the sequence number is older than the expected one. Unlike the previous one, this is a property of the received traffic: a remote endpoint that restarts and resets its sequence numbering has all of its packets dropped until its sequence numbers catch up with i_seqno.
- pskb_inet_may_pull_reason() already computes a drop reason, SKB_DROP_REASON_PKT_TOO_SMALL or SKB_DROP_REASON_NOMEM, which has so far been discarded.
- SKB_DROP_REASON_IP_TUNNEL_ECN already exists and documents exactly this check, but until now it was only used by vxlan.
The sequence number check is split in two so that the two cases can be told apart. The error counters are left unchanged.
ip_tunnel_rcv() is the RX path of ip_gre, ipip and sit, the latter for IPv4 and MPLS payloads only: ipip6_rcv() handles IPv6 in IPv4 on its own. The checksum and the sequence number options only exist for GRE, so the two new reasons are meant for ip_gre. ipip and sit carry neither option and only hit SKB_DROP_REASON_TNL_OPT_MISMATCH if their i_flags are given those bits, for instance through IFLA_IPTUN_FLAGS; such a device then drops every packet that reaches ip_tunnel_rcv(), with or without this patch. The ECN reason applies to all three, while the length ones can only be hit through ip_gre: tunnel4_rcv() has already pulled the inner IPv4 header for ipip and sit, and pskb_inet_may_pull_reason() has nothing to pull for an MPLS payload.
--- 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
@@ -129,6 +129,8 @@ FN(PSP_INPUT) \ FN(PSP_OUTPUT) \ FN(RECURSION_LIMIT) \ + FN(TNL_OPT_MISMATCH) \ + FN(TNL_OLD_SEQ) \ FNe(MAX)/**
@@ -612,6 +614,21 @@ enum skb_drop_reason {SKB_DROP_REASON_PSP_OUTPUT ,/** @SKB_DROP_REASON_RECURSION_LIMIT: Dead loop on virtual device. */ SKB_DROP_REASON_RECURSION_LIMIT , +/** +* @SKB_DROP_REASON_TNL_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_TNL_OPT_MISMATCH , +/** +* @SKB_DROP_REASON_TNL_OLD_SEQ: the sequence number carried +* by the packet is older than the one expected by the tunnel, e.g. +* after the remote endpoint restarted and reset its sequence +* numbering. +*/ +SKB_DROP_REASON_TNL_OLD_SEQ ,/** * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which * shouldn't be used as a real 'reason' - only for tracing code gen
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_TNL_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_TNL_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_TNL_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 v4 2/10 ip6_tunnel: add drop reasons to the generic RX path
In reply to Anton Danilov__ip6_tnl_rcv() mirrors its IPv4 counterpart: all of its failures share a single plain kfree_skb(). Reuse the drop reasons that ip_tunnel_rcv() now reports and the ones the length helpers already return.
Note that skb_vlan_inet_prepare() returns an enum skb_drop_reason that has so far been discarded, and that the ETH_HLEN check gets one by calling pskb_may_pull_reason() instead of pskb_may_pull().
__ip6_tnl_rcv() is reached two ways: ip6_gre (ip6gre, ip6gretap, ip6erspan) goes through the exported ip6_tnl_rcv(), while the ip6_tunnel encapsulations (ip4ip6, ip6ip6, mplsip6) reach it from ipxip6_rcv(). Only ip6_gre sets the checksum and sequence number bits:tpi_v4, tpi_v6 and tpi_mpls carry nothing but .proto, and unlike ipip and sit, ip6_tunnel stores IFLA_IPTUN_FLAGS in parms.flags, not in parms.i_flags. So the option mismatch and the old sequence reasons are reachable through ip6_gre alone.
--- net/ipv6/ip6_tunnel.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-)
net/ipv6/ip6_tunnel.c +17 -6
@@ -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_TNL_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_TNL_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_TNL_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 ; }
Signature · 1 line
2.47.3
PATCH v4 3/10 gre: make gre_parse_header() report a drop reason
In reply to Anton Danilovgre_parse_header() returns -EINVAL for every failure and its receive callers turn that into a plain kfree_skb(). The only detail they could get so far was the csum_err flag, which none of them actually reads:
both ip_gre and ip6_gre declare it, pass it in and then ignore it.
Make gre_parse_header() return the drop reason instead, with SKB_NOT_DROPPED_YET for a valid header, and let the two receive paths report it. The header length it used to return is already stored in tpi->hdr_len, so the callers take it from there. Two reasons are added:
- SKB_DROP_REASON_GRE_INVALID_HDR, for a header carrying an unsupported version or the routing bit,
- SKB_DROP_REASON_GRE_CSUM, for a checksum error, like the existing TCP_CSUM, UDP_CSUM, ICMP_CSUM and IP_CSUM.
The header pull failures reuse SKB_DROP_REASON_HDR_TRUNC, which documents exactly this case, and gre_rcv() in the demux reuses pskb_may_pull_reason() and SKB_DROP_REASON_UNHANDLED_PROTO.
csum_err had a second use: the ICMP error handlers pass NULL for it, so that a checksum failure does not reject the header and the rest of it is still parsed, as they only get a part of the original packet. That came with commit b0350d51f001 ("ip_gre: fix parsing gre header in ipgre_err") and becomes an explicit icmp_err argument. The checksum is still computed either way.
Tunnel lookup failures still report SKB_DROP_REASON_NOT_SPECIFIED here, which gre_rcv() sets again once the header is parsed; they are addressed in the following patches.
--- include/net/dropreason-core.h | 9 ++++++++ include/net/gre.h | 5 +++-- net/ipv4/gre_demux.c | 42 ++++++++++++++++++++++------------- net/ipv4/ip_gre.c | 18 +++++++-------- net/ipv6/ip6_gre.c | 18 +++++++-------- 5 files changed, 56 insertions(+), 36 deletions(-)
include/net/dropreason-core.h +9 -0
@@ -131,6 +131,8 @@ FN(RECURSION_LIMIT) \ FN(TNL_OPT_MISMATCH) \ FN(TNL_OLD_SEQ) \ + FN(GRE_INVALID_HDR) \ + FN(GRE_CSUM) \ FNe(MAX)/**
@@ -629,6 +631,13 @@ enum skb_drop_reason {* numbering. */ SKB_DROP_REASON_TNL_OLD_SEQ , +/** +* @SKB_DROP_REASON_GRE_INVALID_HDR: the GRE header is invalid, e.g. +* an unsupported version or the routing bit is set. +*/ +SKB_DROP_REASON_GRE_INVALID_HDR , +/** @SKB_DROP_REASON_GRE_CSUM: GRE checksum error */ + SKB_DROP_REASON_GRE_CSUM,/** * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which * shouldn't be used as a real 'reason' - only for tracing code gen
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 icmp_err,__be16 proto,int nhs);static inline bool netif_is_gretap (const struct net_device *dev) {
net/ipv4/gre_demux.c +26 -16
109 lines not on this page · raw message
net/ipv4/ip_gre.c +9 -9
@@ -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 ) {
@@ -439,9 +439,8 @@ 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)) {
@@ -451,25 +450,26 @@ static int gre_rcv(struct sk_buff *skb) }#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 +9 -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;
@@ -566,20 +566,20 @@ static int ip6erspan_rcv(struct sk_buff *skb,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; - 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; + reason =SKB_DROP_REASON_NOT_SPECIFIED ; -if (iptunnel_pull_header (skb, hdr_len, tpi.proto, false)) +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; }
@@ -591,7 +591,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
Ido Schimmel
maintainerRe: [PATCH net-next v4 03/10] gre: make gre_parse_header() report a drop reason
Quoted 21 lines · Anton Danilov
net/ipv4/gre_demux.c +8
-3@@ -56,28 +56,35 @@ int gre_del_protocol(const struct gre_protocol *proto, u8 version) }EXPORT_SYMBOL_GPL (gre_del_protocol); -/* Fills in tpi and returns header length to be pulled. +/* Fills in tpi, including the header length to be pulled in tpi->hdr_len, +* and returns SKB_NOT_DROPPED_YET, or the reason to drop the packet if the +* header is rejected. * Note that caller must use pskb_may_pull() before pulling GRE header. +* +* @icmp_err is set by the ICMP error handlers, which only get a part of +* the original packet: a checksum failure does not reject the header then, +* the checksum is still computed and the rest of the header is parsed. */ -int gre_parse_header (struct sk_buff *skb,struct tnl_ptk_info *tpi, -bool *csum_err,__be16 proto,int nhs) +enum skb_drop_reason
net/ipv4/gre_demux.c int gre_del_protocol(const struct gre_protocol *proto, u8 version) · line 77
Quoted 10 lines
net/ipv4/gre_demux.c +3
-1+gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi, + bool icmp_err, __be16 proto, int nhs) { const struct gre_base_hdr *greh;__be32 *options;int hdr_len;if (unlikely (!pskb_may_pull (skb, nhs +sizeof (struct gre_base_hdr )))) -return -EINVAL ; +return SKB_DROP_REASON_HDR_TRUNC ;
Please use pskb_may_pull_reason() as is done throughout the kernel. AFAICT, there's only one user of HDR_TRUNC (in tun) and it should also be converted to pskb_may_pull_reason() so that we could remove HDR_TRUNC. Can you send a patch?
Quoted 5 lines
net/ipv4/gre_demux.c +1
-1greh = (struct gre_base_hdr *)(skb->data + nhs);if (unlikely (greh->flags & (GRE_VERSION |GRE_ROUTING ))) -return -EINVAL ; +return SKB_DROP_REASON_GRE_INVALID_HDR ;
[...]
Quoted 6 lines
static int
gre_rcv(struct sk_buff *skb)
{net/ipv4/gre_demux.c +1
-0+enum skb_drop_reason reason =SKB_DROP_REASON_NOT_SPECIFIED ;const struct gre_protocol *proto;u8 ver;int ret;
net/ipv4/gre_demux.c int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi, · line 165
Quoted 10 lines
net/ipv4/gre_demux.c +4
-2-if (!pskb_may_pull (skb,12 )) + reason =pskb_may_pull_reason (skb,12 ); +if (reason) goto drop; ver = skb->data[1 ]&0x7f ; -if (ver >=GREPROTO_MAX ) +if (ver >=GREPROTO_MAX ) { + reason =SKB_DROP_REASON_UNHANDLED_PROTO ;
This should be TUNNEL_INVALID_HDR to be consistent with the hunk above.
net/ipv4/gre_demux.c static int gre_rcv(struct sk_buff *skb) · line 180
Quoted 11 lines
net/ipv4/gre_demux.c +2
-1goto drop; + }rcu_read_lock (); proto =rcu_dereference (gre_proto[ver]);@@ -167,11 +177,11 @@ static int gre_rcv(struct sk_buff *skb) drop_nohandler:rcu_read_unlock ();dev_core_stats_rx_nohandler_inc (skb->dev); -kfree_skb (skb); +kfree_skb_reason (skb,SKB_DROP_REASON_UNHANDLED_PROTO );
This looks correct.
Quoted 7 lines
net/ipv4/gre_demux.c +1
-1return NET_RX_DROP ; drop:dev_core_stats_rx_dropped_inc (skb->dev); -kfree_skb (skb); +kfree_skb_reason (skb, reason);return NET_RX_DROP ; }
Re: [PATCH net-next v4 03/10] gre: make gre_parse_header() report a drop reason
Quoted 9 lines · Ido Schimmel
net/ipv4/gre_demux.c int gre_del_protocol(const struct gre_protocol *proto, u8 version) · line 77
Quoted 3 lines · Anton Danilov
net/ipv4/gre_demux.c +1
-1if (unlikely (!pskb_may_pull (skb, nhs +sizeof (struct gre_base_hdr )))) -return -EINVAL ; +return SKB_DROP_REASON_HDR_TRUNC ;Please use
pskb_may_pull_reason()as is done throughout the kernel. AFAICT, there's only one user ofHDR_TRUNC(in tun) and it should also be converted topskb_may_pull_reason()so that we could removeHDR_TRUNC. Can you send a patch?
Sure, I will send it separately. It does not depend on this series, as v5 will no longer use HDR_TRUNC.
...
Quoted 5 lines
net/ipv4/gre_demux.c int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi, · line 165
Quoted 3 lines
net/ipv4/gre_demux.c +2
-1-if (ver >=GREPROTO_MAX ) +if (ver >=GREPROTO_MAX ) { + reason =SKB_DROP_REASON_UNHANDLED_PROTO ;This should be
TUNNEL_INVALID_HDRto be consistent with the hunk above.
Agreed, will change in v5.
PATCH v4 4/10 ip_tunnel: add __iptunnel_pull_header_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 converted by the following patches. In ip6_gre, gre_rcv() calls the helper 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.
Add __iptunnel_pull_header_reason(), which returns the reason pskb_may_pull_reason() already computes, SKB_DROP_REASON_NOMEM when skb_unclone() fails, and SKB_NOT_DROPPED_YET on success. Turn __iptunnel_pull_header() into a static inline wrapper that keeps returning -ENOMEM on any failure, so its existing callers are left unchanged; the export moves to the new function.
--- include/net/ip_tunnels.h | 13 +++++++++++-- net/ipv4/ip_tunnel_core.c | 24 ++++++++++++++++-------- 2 files changed, 27 insertions(+), 10 deletions(-)
include/net/ip_tunnels.h +11 -2
@@ -614,8 +614,17 @@ 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_reason (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 raw_proto, +bool xnet) +{ +return __iptunnel_pull_header_reason (skb, hdr_len, inner_proto, + raw_proto, xnet) ? -ENOMEM :0 ; +}static inline int iptunnel_pull_header (struct sk_buff *skb,int hdr_len,__be16 inner_proto,bool xnet)
net/ipv4/ip_tunnel_core.c +16 -8
@@ -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_reason (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,9 +140,12 @@ 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); +EXPORT_SYMBOL_GPL (__iptunnel_pull_header_reason);struct metadata_dst *iptunnel_metadata_reply (struct metadata_dst *md,gfp_t flags)
Signature · 1 line
2.47.3
Ido Schimmel
maintainerRe: [PATCH net-next v4 04/10] ip_tunnel: add __iptunnel_pull_header_reason()
Quoted 11 lines · Anton Danilov
include/net/ip_tunnels.h +1
-2@@ -614,8 +614,17 @@ 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
include/net/ip_tunnels.h static inline u8 ip_tunnel_ecn_encap(u8 tos, const struct iphdr *iph, · line 627
Quoted 10 lines
include/net/ip_tunnels.h +10
-0+__iptunnel_pull_header_reason(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 raw_proto, +bool xnet) +{ +return __iptunnel_pull_header_reason (skb, hdr_len, inner_proto, + raw_proto, xnet) ? -ENOMEM :0 ; +}
Either append patches to this series or as a follow-up, after this series the only caller of __iptunnel_pull_header() other than iptunnel_pull_header() is the VXLAN driver and it should be converted to report the actual drop reason instead of NOMEM:
drivers/net/vxlan/vxlan_core.c +4 -4
@@ -1720,11 +1720,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_reason (skb,VXLAN_HLEN , protocol, + raw_proto, + !net_eq (vxlan->net,dev_net (vxlan->dev))); +if (reason) goto drop; - }if (vxlan->cfg.flags &VXLAN_F_REMCSUM_RX ) { reason =vxlan_remcsum (skb, vxlan->cfg.flags);
Then remove __iptunnel_pull_header():
include/net/ip_tunnels.h +4 -11
@@ -614,18 +614,11 @@ enum skb_drop_reason __iptunnel_pull_header_reason(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 raw_proto, -bool xnet) +static inline bool iptunnel_pull_header (struct sk_buff *skb,int hdr_len, +__be16 inner_proto,bool xnet) { -return __iptunnel_pull_header_reason (skb, hdr_len, inner_proto, - raw_proto, xnet) ? -ENOMEM :0 ; -} - -static inline int 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); +return __iptunnel_pull_header_reason (skb, hdr_len, inner_proto, false, + xnet) !=SKB_NOT_DROPPED_YET ; } void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,
Re: [PATCH net-next v4 04/10] ip_tunnel: add __iptunnel_pull_header_reason()
Quoted 4 lines · Ido Schimmel
Either append patches to this series or as a follow-up, after this series the only caller of
__iptunnel_pull_header()other thaniptunnel_pull_header()is the VXLAN driver and it should be converted to report the actual drop reason instead of NOMEM:
...
Quoted 1 line
Then remove
__iptunnel_pull_header():
...
include/net/ip_tunnels.h enum skb_drop_reason · line 618
Quoted 2 lines
include/net/ip_tunnels.h +2
-0+static inline bool iptunnel_pull_header (struct sk_buff *skb,int hdr_len, +__be16 inner_proto,bool xnet)
...
Thanks, I will add both changes to v5.
One question before I send it: is there a reason to prefer bool here? All the callers only test the result for failure, so bool works for them, but coding-style.rst (section 16) says that a function whose name is an action should return an error-code integer. I can keep the int return, as it is in net-next now, or go with bool as in your diff, whichever you prefer.
Ido Schimmel
maintainerRe: [PATCH net-next v4 04/10] ip_tunnel: add __iptunnel_pull_header_reason()
Quoted 17 lines · Anton Danilov
Quoted 4 lines · Ido Schimmel
Either append patches to this series or as a follow-up, after this series the only caller of
__iptunnel_pull_header()other thaniptunnel_pull_header()is the VXLAN driver and it should be converted to report the actual drop reason instead of NOMEM:...
Quoted 1 line
Then remove
__iptunnel_pull_header():...
Quoted 2 lines
include/net/ip_tunnels.h +2
-0+static inline bool iptunnel_pull_header (struct sk_buff *skb,int hdr_len, +__be16 inner_proto,bool xnet)...
Quoted 8 lines
Thanks, I will add both changes to v5.
One question before I send it: is there a reason to prefer bool here? All the callers only test the result for failure, so bool works for them, but
coding-style.rst(section 16) says that a function whose name is an action should return an error-code integer. I can keep the int return, as it is in net-next now, or go with bool as in your diff, whichever you prefer.
Looking at it again, why do we even need__iptunnel_pull_header_reason()?
All the callers of __iptunnel_pull_header() and iptunnel_pull_header() treat the return value as a boolean. Can't you just change their return type to 'enum skb_drop_reason'?
PATCH v4 5/10 ip_gre: add drop reasons to the RX path
In reply to Anton DanilovA packet that reaches gre_rcv() and does not belong to any tunnel is dropped, after an ICMP port unreachable is sent back, as SKB_DROP_REASON_NOT_SPECIFIED from the same kfree_skb_reason() call as a truncated ERSPAN header or a failed metadata allocation. This is the GRE counterpart of a UDP packet hitting no socket, yet neither the reason nor the call site tells it apart. The fallback devices such as gre0 only take such a packet while they are up, and they are created down.
Add SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND for it, in the spirit of the existing SKB_DROP_REASON_VXLAN_VNI_NOT_FOUND.
erspan_rcv(), __ipgre_rcv() and ipgre_rcv() now return SKB_NOT_DROPPED_YET where they returned PACKET_RCVD, including the paths that free the packet themselves, and a drop reason where they returned PACKET_REJECT or PACKET_NEXT. __ipgre_rcv() only returned PACKET_NEXT when no tunnel matched, so the retry ipgre_rcv() does for ETH_P_TEB is now taken on SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND.
The length checks reuse SKB_DROP_REASON_HDR_TRUNC. The headers are pulled with __iptunnel_pull_header_reason(), added by the previous patch, which reports a packet too short to pull as SKB_DROP_REASON_PKT_TOO_SMALL and an allocation failure as SKB_DROP_REASON_NOMEM. The metadata allocation failures reuse SKB_DROP_REASON_NOMEM as well.
SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND is documented without naming an address family. The IPv6 side is converted by the next patch, which ends its lookup failures with the same reason.
--- include/net/dropreason-core.h | 6 +++ net/ipv4/ip_gre.c | 74 ++++++++++++++++++++--------------- 2 files changed, 48 insertions(+), 32 deletions(-)
include/net/dropreason-core.h +6 -0
@@ -133,6 +133,7 @@ FN(TNL_OLD_SEQ) \ FN(GRE_INVALID_HDR) \ FN(GRE_CSUM) \ + FN(GRE_TUNNEL_NOT_FOUND) \ FNe(MAX)/**
@@ -638,6 +639,11 @@ enum skb_drop_reason {SKB_DROP_REASON_GRE_INVALID_HDR ,/** @SKB_DROP_REASON_GRE_CSUM: GRE checksum error */ SKB_DROP_REASON_GRE_CSUM , +/** +* @SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND: no GRE tunnel found for the +* endpoints and the key the packet carries. +*/ + SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND,/** * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which * shouldn't be used as a real 'reason' - only for tracing code gen
net/ipv4/ip_gre.c +42 -32
164 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH v4 6/10 ip6_gre: add drop reasons to the RX path
In reply to Anton DanilovMirror the previous patch on the IPv6 side. So far gre_rcv() reported the drops below as SKB_DROP_REASON_NOT_SPECIFIED, all from the same kfree_skb_reason() call. Now it reports:
- SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND when no tunnel matches,
- SKB_DROP_REASON_HDR_TRUNC when a header is too short,
- what __iptunnel_pull_header_reason() returns when the pull fails,
- SKB_DROP_REASON_NOMEM when the metadata dst cannot be allocated.
Unlike ip_gre, gre_rcv() calls the helper before the tunnel lookup, so a packet whose ETH_P_TEB inner Ethernet header or WCCPv2 extra word is cut short is reported as SKB_DROP_REASON_PKT_TOO_SMALL whether a tunnel matches or not.
Like their IPv4 counterparts, ip6gre_rcv() and ip6erspan_rcv() now return SKB_NOT_DROPPED_YET where they returned PACKET_RCVD and a drop reason where they returned PACKET_REJECT. That leaves PACKET_RCVD, PACKET_REJECT and PACKET_NEXT without users, so remove them. PACKET_REJECT has the value of SKB_CONSUMED, and a stray one in a function that now returns a drop reason would build silently and be traced as a consumed packet.
--- include/net/ip_tunnels.h | 4 ---- net/ipv6/ip6_gre.c | 46 +++++++++++++++++++++++----------------- 2 files changed, 26 insertions(+), 24 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 +26 -20
112 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH v4 7/10 ip_tunnel: add drop reasons to the transmit path
In reply to Anton Danilovip_tunnel_xmit() and ip_md_tunnel_xmit() encapsulate the packets sent through the tunnel, and every failure these two functions detect ends in a plain kfree_skb(). The device counters separate them a little, but they are too coarse to act on: tx_errors counts an encapsulation failure, a routing failure, a routing loop and a packet that is simply too big alike.
The packet that is too big deserves attention. tnl_update_pmtu() returns -E2BIG for a non-GSO packet larger than the MTU if it is IPv4 with the DF bit set, or IPv6 and the MTU is at least IPV6_MIN_MTU, after it has already sent the ICMP error back to the sender. That is path MTU discovery working as intended, yet among the device counters the drop only bumps tx_errors, like a failed encapsulation and a few other failures do. If the ICMP error never reaches the sender, the resulting MTU black hole cannot be told from those by the device counters. A failed route lookup and a routing loop do have counters of their own, tx_carrier_errors and collisions, but in both functions all of these packets end up in the same kfree_skb() call.
No new reason is needed for most of it:
- SKB_DROP_REASON_PKT_TOO_BIG for the case above,
- SKB_DROP_REASON_IP_OUTNOROUTES when the route lookup fails,
- SKB_DROP_REASON_RECURSION_LIMIT when the route points back at the tunnel device itself, which is the "dead loop on virtual device" that reason describes,
- SKB_DROP_REASON_NOMEM when the headroom cannot be expanded,
- SKB_DROP_REASON_NEIGH_CREATEFAIL when the NBMA neighbour lookup fails, SKB_DROP_REASON_NO_TX_TARGET when no destination can be derived at all, and, on the same NBMA path, SKB_DROP_REASON_UNHANDLED_PROTO for a payload that is neither IPv4 nor IPv6,
- SKB_DROP_REASON_TUNNEL_TXINFO, which already documents a packet reaching an external mode device without metadata, for the collect_md path.
Only the encapsulation failure has no fitting reason, so add SKB_DROP_REASON_TNL_ENCAP for it.
Drop reasons on transmit are not new: vxlan already reports several of them from its xmit path, and ip_tunnel_core.c reports SKB_DROP_REASON_RECURSION_LIMIT. They are most useful for forwarded packets, which is what a tunnel gateway mostly transmits: the sender is another host, which gets an ICMP error for only some of these failures, so the drop has to be explained on the gateway.
--- include/net/dropreason-core.h | 7 ++++++ net/ipv4/ip_tunnel.c | 41 ++++++++++++++++++++++++++++------- 2 files changed, 40 insertions(+), 8 deletions(-)
include/net/dropreason-core.h +7 -0
@@ -134,6 +134,7 @@ FN(GRE_INVALID_HDR) \ FN(GRE_CSUM) \ FN(GRE_TUNNEL_NOT_FOUND) \ + FN(TNL_ENCAP) \ FNe(MAX)/**
@@ -644,6 +645,12 @@ enum skb_drop_reason {* endpoints and the key the packet carries. */ SKB_DROP_REASON_GRE_TUNNEL_NOT_FOUND , +/** +* @SKB_DROP_REASON_TNL_ENCAP: failed to build the +* encapsulation header of a tunnel, e.g. an unknown or +* unregistered encapsulation type. +*/ + SKB_DROP_REASON_TNL_ENCAP,/** * @SKB_DROP_REASON_MAX: the maximum of core drop reasons, which * shouldn't be used as a real 'reason' - only for tracing code gen
net/ipv4/ip_tunnel.c +33 -8
157 lines not on this page · raw message
Signature · 1 line
2.47.3
Ido Schimmel
maintainerRe: [PATCH net-next v4 07/10] ip_tunnel: add drop reasons to the transmit path
Quoted 30 lines · Anton Danilov
(quoted diff) +9
-1@@ -711,9 +721,15 @@ 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; } + /* Only the branches below can derive a destination. If + * none of them matches, the payload protocol is not one + * this tunnel can carry. + */ + reason = SKB_DROP_REASON_UNHANDLED_PROTO; tun_info = skb_tunnel_info(skb); if (tun_info && (tun_info->mode & IP_TUNNEL_INFO_TX) && ip_tunnel_info_af(tun_info) == AF_INET &&@@ -734,8 +750,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);@@ -752,8 +770,10 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, dst = addr6->s6_addr32[3];
Review void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, · line 779
Quoted 10 lines
(quoted diff) +3
-1} 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
Makes more sense:
net/ipv4/ip_tunnel.c +3 -6
@@ -725,11 +725,6 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, goto tx_error; } -/* Only the branches below can derive a destination. If -* none of them matches, the payload protocol is not one -* this tunnel can carry. -*/ - reason =SKB_DROP_REASON_UNHANDLED_PROTO ; tun_info =skb_tunnel_info (skb); if (tun_info && (tun_info->mode & IP_TUNNEL_INFO_TX) && ip_tunnel_info_af(tun_info) == AF_INET &&
@@ -776,8 +771,10 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev, } }#endif - else + else { + reason =SKB_DROP_REASON_UNHANDLED_PROTO ; goto tx_error; + }if (!md) connected = false;
PATCH v4 8/10 ip_gre: add drop reasons to the transmit path
In reply to Anton DanilovEach transmit function of ip_gre ends all of its failures in one kfree_skb() and a tx_dropped increment, so a drop can be traced to the function and to nothing more precise than "the tunnel did not send it".
No new reason is needed. The length helpers already compute one, so pskb_inet_may_pull_reason() and pskb_may_pull_reason() are used instead of their boolean wrappers, and the rest reuses:
- SKB_DROP_REASON_NOMEM for the headroom expansions, the offload handling and the trims,
- SKB_DROP_REASON_TUNNEL_TXINFO for the collect_md paths, when the metadata is missing or incomplete,
- SKB_DROP_REASON_UNHANDLED_PROTO for an ERSPAN version that is not implemented,
- SKB_DROP_REASON_SKB_CSUM when the checksum starts before the data the tunnel is about to send.
--- net/ipv4/ip_gre.c | 101 +++++++++++++++++++++++++++++++++------------- 1 file changed, 74 insertions(+), 27 deletions(-)
net/ipv4/ip_gre.c +74 -27
@@ -506,6 +506,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;
@@ -514,19 +515,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);
@@ -543,12 +550,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;
@@ -562,29 +570,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; }
@@ -616,6 +636,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; }
@@ -628,7 +649,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); }
@@ -659,11 +680,13 @@ static int gre_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb)static netdev_tx_t ipgre_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);const struct iphdr *tnl_params; -if (!pskb_inet_may_pull (skb)) + reason =pskb_inet_may_pull_reason (skb); +if (reason) goto free_skb;if (tunnel->collect_md) {
@@ -674,10 +697,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;
@@ -687,25 +713,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 ; }
@@ -713,12 +745,14 @@ static netdev_tx_t ipgre_xmit(struct sk_buff *skb,static netdev_tx_t erspan_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);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) {
@@ -726,15 +760,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; }
@@ -755,6 +795,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; }
@@ -763,7 +804,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 ; }
@@ -771,10 +812,12 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,static netdev_tx_t gre_tap_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); -if (!pskb_inet_may_pull (skb)) + reason =pskb_inet_may_pull_reason (skb); +if (reason) goto free_skb;if (tunnel->collect_md) {
@@ -784,17 +827,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
PATCH v4 9/10 ip6_gre: make prepare_ip6gre_xmit_other() void
In reply to Anton Danilovprepare_ip6gre_xmit_other() copies the flow template of the tunnel and picks up its encapsulation limit, DS field and mark. Unlike its IPv6 sibling, which fails when the packet's tunnel encapsulation limit option is 0 and so forbids encapsulating it again, it has nothing to fail on:
its only return statement is "return 0", and it has been that way since commit 41337f52b967 ("ip6_gre: set DSCP for non-IP") added the function. Its caller still checks the result and bails out on a branch that never runs.
Make it void and drop the check, the way prepare_ip6gre_xmit_ipv4() is already called. The next patch gives every failing branch of the transmit path a drop reason, and this one would otherwise get a reason it can never report.
--- net/ipv6/ip6_gre.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-)
net/ipv6/ip6_gre.c +7 -9
@@ -680,10 +680,10 @@ static int prepare_ip6gre_xmit_ipv6(struct sk_buff *skb,return 0 ; } -static int prepare_ip6gre_xmit_other (struct sk_buff *skb, -struct net_device *dev, -struct flowi6 *fl6,__u8 *dsfield, -int *encap_limit) +static void prepare_ip6gre_xmit_other (struct sk_buff *skb, +struct net_device *dev, +struct flowi6 *fl6,__u8 *dsfield, +int *encap_limit) {struct ip6_tnl *t =netdev_priv (dev);
@@ -703,8 +703,6 @@ static int prepare_ip6gre_xmit_other(struct sk_buff *skb, fl6->flowi6_mark = t->parms.fwmark; fl6->flowi6_uid =sock_net_uid (dev_net (dev),NULL ); - -return 0 ; }static struct ip_tunnel_info *skb_tunnel_info_txcheck (struct sk_buff *skb)
@@ -865,9 +863,9 @@ static int ip6gre_xmit_other(struct sk_buff *skb, struct net_device *dev)__u32 mtu;int err; -if (!t->parms.collect_md && -prepare_ip6gre_xmit_other (skb, dev, &fl6, &dsfield, &encap_limit)) -return -1 ; +if (!t->parms.collect_md) +prepare_ip6gre_xmit_other (skb, dev, &fl6, + &dsfield, &encap_limit); err =gre_handle_offloads (skb,test_bit (IP_TUNNEL_CSUM_BIT , t->parms.o_flags));
Signature · 1 line
2.47.3
PATCH v4 10/10 ip6_tunnel: add drop reasons to the transmit path
In reply to Anton DanilovDo for the IPv6 tunnels what the previous patches did for the IPv4 ones. The situation is the same, with one difference: ip6_tnl_xmit() does not free the packet itself, it returns an error and the callers do, so the reason has to travel with it.
Make ip6_tnl_xmit() return the drop reason, SKB_NOT_DROPPED_YET on success, instead of 0, -1 or an errno, and do the same for ipxip6_tnl_xmit(), __gre6_xmit() and the ip6gre_xmit_*() helpers, so that the ndo_start_xmit handlers, where the packet is actually freed, can report it. The callers only told success from failure and looked for -EMSGSIZE to send an ICMP error back. ip6_tnl_xmit() returns -EMSGSIZE only for a packet that exceeds the path MTU, which is exactly when it reports SKB_DROP_REASON_PKT_TOO_BIG, so the ICMP error is now sent when that reason is returned. A failed xfrm lookup never returns -EMSGSIZE, so its errno only ever meant failure and goes away. __gre6_xmit() was declared as returning netdev_tx_t while it returned an errno, and now returns the reason as well.
ip6_gre is converted in the same patch because it calls ip6_tnl_xmit() and depends on its return value.
As in ip_gre, the ndo_start_xmit handlers take the length reason from pskb_inet_may_pull_reason() instead of pskb_inet_may_pull(). The other reasons are the ones already used on the IPv4 side:
- SKB_DROP_REASON_PKT_TOO_BIG for a packet that exceeds the path MTU,
- SKB_DROP_REASON_IP_OUTNOROUTES for the route and xfrm lookups, including the source address selection that a collect_md tunnel does when the flow has no source address,
- SKB_DROP_REASON_NO_TX_TARGET when an NBMA tunnel gets an skb with no destination to derive its endpoint from,
- SKB_DROP_REASON_NEIGH_CREATEFAIL when the NBMA neighbour lookup fails,
- SKB_DROP_REASON_RECURSION_LIMIT for a route pointing back at the tunnel, and for the trivial tunnelling loop ip6_tnl_addr_conflict() guards against, a packet whose source is the exit point of the tunnel,
- SKB_DROP_REASON_NOMEM for the allocations,
- SKB_DROP_REASON_TUNNEL_TXINFO for the collect_md metadata checks,
- SKB_DROP_REASON_TNL_ENCAP when the encapsulation header cannot be built, and for a collect_md tunnel that has an encapsulation configured, which ip6_tnl_xmit() does not support,
- SKB_DROP_REASON_UNHANDLED_PROTO for a payload the tunnel does not carry, either by its mode or because it is neither IPv4, IPv6 nor MPLS, and for an ERSPAN version that is not implemented.
Two more fit here: SKB_DROP_REASON_DEV_READY when ip6_tnl_xmit_ctl() refuses the transmit, and SKB_DROP_REASON_IPV6_BAD_EXTHDR when the packet's tunnel encapsulation limit option is 0, which forbids encapsulating it again.
A collect_md tunnel has no fixed exit point and its raddr is normally ::, so ip6_tnl_addr_conflict() and the same check in ip6gre_xmit_ipv6() also drop the packets it sends from ::, such as the DAD probes of an ip6gretap device. They were dropped before as well; SKB_DROP_REASON_RECURSION_LIMIT names the check that drops them.
--- include/net/ip6_tunnel.h | 5 +- net/ipv6/ip6_gre.c | 137 ++++++++++++++++++++++++--------------- net/ipv6/ip6_tunnel.c | 100 ++++++++++++++++------------ 3 files changed, 146 insertions(+), 96 deletions(-)
include/net/ip6_tunnel.h +3 -2
@@ -143,8 +143,9 @@ int ip6_tnl_rcv(struct ip6_tnl *tunnel, struct sk_buff *skb, bool log_ecn_error);int ip6_tnl_xmit_ctl (struct ip6_tnl *t,const struct in6_addr *laddr,const struct in6_addr *raddr); -int ip6_tnl_xmit (struct sk_buff *skb,struct net_device *dev,__u8 dsfield, -struct flowi6 *fl6,int encap_limit,__u32 *pmtu,__u8 proto); +enum skb_drop_reason +ip6_tnl_xmit (struct sk_buff *skb,struct net_device *dev,__u8 dsfield, +struct flowi6 *fl6,int encap_limit,__u32 *pmtu,__u8 proto);__u16 ip6_tnl_parse_tlv_enc_lim (struct sk_buff *skb,__u8 *raw);__u32 ip6_tnl_get_cap (struct ip6_tnl *t,const struct in6_addr *laddr,const struct in6_addr *raddr);
net/ipv6/ip6_gre.c +83 -54
322 lines not on this page · raw message
net/ipv6/ip6_tunnel.c +60 -40
273 lines not on this page · raw message
Signature · 1 line
2.47.3
Ido Schimmel
maintainerQuoted 13 lines · Anton Danilov
Only vxlan reports drop reasons among the tunnel drivers today. The ones converted here free what they drop with
kfree_skb(), whichdrop_monitorand the skb:kfree_skb tracepoint do report, but asNOT_SPECIFIED, with the call site as the only hint at which check failed. That hint does not go far: all the failures ofip_tunnel_rcv()end at one call site, and so do nearly all of those of each transmit function. The call site is not a stable interface either: its offset moves with the compiler, inlining and the configuration, so a filter on it has to follow every rebuild. The reason stays the same across kernels, whetherNET_DM_ATTR_REASONreports it or a BPF program matches it by name. The device counters group the failures coarsely too:rx_errorsandtx_errorseach lump together unrelated conditions.
Quoted 4 lines
This series covers the generic paths shared by ipip, sit, gre and their IPv6 counterparts, plus the GRE specific code, in both directions. A later series will do the same for geneve, bareudp, fou and the remaining IP in IP drivers.
Please only annotate drivers that you are familiar with, using and can test. Otherwise it's a burden on the reviewer and potentially useless code churn that will make it harder to backport future fixes.
Quoted 15 lines
Patches 1-2 convert the generic receive paths,
ip_tunnel_rcv()and__ip6_tnl_rcv(). Two reasons are added:
TNL_OPT_MISMATCHthe options a packet carries do not match the
tunnel configuration
TNL_OLD_SEQthe sequence number is older than the one the
tunnel expects, likeTCP_OLD_SEQUENCEfor TCPThe second one has a failure mode worth naming: when a peer reboots, its outgoing sequence number restarts at zero, and the receiver drops everything until the peer's numbers get past the last one the receiver accepted. By the counters alone that looks like a misconfiguration: a packet without the sequence number option bumps the same
rx_fifo_errors.
Quoted 10 lines
Patches 3-6 convert the GRE specific receive path.
gre_parse_header()returns-EINVALfor every failure, and the only detail its callers could get was acsum_errflag that none of them read: bothip_greandip6_gredeclared it, passed it in and ignored it.gre_parse_header()now returns a drop reason instead, and its callers take the header length fromtpi->hdr_len. The receive helpers belowgre_rcv()return the drop reason instead of a PACKET_* code, and the PACKET_* codes go away. Three reasons are added:GRE_INVALID_HDRandGRE_TUNNEL_NOT_FOUND, mirroring vxlan'sVXLAN_INVALID_HDRandVXLAN_VNI_NOT_FOUND, andGRE_CSUM, likeTCP_CSUMandUDP_CSUM.
GRE_CSUM looks fine as I'm not aware of other tunnels that have a dedicated checksum, but GRE_INVALID_HDR and GRE_TUNNEL_NOT_FOUND should be renamed to something more generic (e.g., TUNNEL_INVALID_HDR and TUNNEL_NOT_FOUND) so that they could be reused across drivers and replace the existing VXLAN ones. Note that you don't need the drop reason to encode the tunnel name in order to know which tunnel driver dropped the packet.
Quoted 5 lines
Patch 4 adds
__iptunnel_pull_header_reason(), because__iptunnel_pull_header()reports a packet too short to pull as-ENOMEM, the same as an allocation failure, andip6_grecalls it for every GRE packet, before the tunnel lookup.
The series is inconsistent about this and returns different reasons (HDR_TRUNC / PKT_TOO_SMALL) for the same condition. I suggest that you convert pskb_may_pull() to pskb_may_pull_reason() and return its reason instead of HDR_TRUNC.
Quoted 9 lines · Ido Schimmel
Quoted 4 lines · Anton Danilov
This series covers the generic paths shared by ipip, sit, gre and their IPv6 counterparts, plus the GRE specific code, in both directions. A later series will do the same for geneve, bareudp, fou and the remaining IP in IP drivers.
Please only annotate drivers that you are familiar with, using and can test. Otherwise it's a burden on the reviewer and potentially useless code churn that will make it harder to backport future fixes.
Understood. I will drop that sentence from the cover letter.
Quoted 7 lines
GRE_CSUMlooks fine as I'm not aware of other tunnels that have a dedicated checksum, butGRE_INVALID_HDRandGRE_TUNNEL_NOT_FOUNDshould be renamed to something more generic (e.g.,TUNNEL_INVALID_HDRandTUNNEL_NOT_FOUND) so that they could be reused across drivers and replace the existing VXLAN ones. Note that you don't need the drop reason to encode the tunnel name in order to know which tunnel driver dropped the packet.
OK. In v5 a new patch will rename VXLAN_INVALID_HDR and VXLAN_VNI_NOT_FOUND to TUNNEL_INVALID_HDR and TUNNEL_NOT_FOUND, the way VXLAN_NO_REMOTE became NO_TX_TARGET, and the GRE patches will use the new names. To keep the naming consistent, I will also rename the TNL_* reasons this series adds to TUNNEL_*.
Quoted 9 lines
Quoted 4 lines
Patch 4 adds
__iptunnel_pull_header_reason(), because__iptunnel_pull_header()reports a packet too short to pull as-ENOMEM, the same as an allocation failure, andip6_grecalls it for every GRE packet, before the tunnel lookup.The series is inconsistent about this and returns different reasons (
HDR_TRUNC/PKT_TOO_SMALL) for the same condition. I suggest that you convertpskb_may_pull()topskb_may_pull_reason()and return its reason instead ofHDR_TRUNC.
Will do. The WCCP check in gre_parse_header() uses skb_header_pointer(), which only fails on a short packet, so it will return PKT_TOO_SMALL.
Thanks for the review!