IPv4 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. Suggested-by: Ido Schimmel Reviewed-by: Ido Schimmel Signed-off-by: Anton Danilov --- 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(-) diff --git a/include/net/dropreason-core.h b/include/net/dropreason-core.h index 83a17e36fed5..73053bd25c2a 100644 --- a/include/net/dropreason-core.h +++ b/include/net/dropreason-core.h @@ -132,6 +132,7 @@ FN(TUNNEL_OPT_MISMATCH) \ FN(TUNNEL_OLD_SEQ) \ FN(GRE_CSUM) \ + FN(TUNNEL_ENCAP) \ FNe(MAX) /** @@ -640,6 +641,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_MAX: the maximum of core drop reasons, which * shouldn't be used as a real 'reason' - only for tracing code gen diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h index 792690ae4f26..87046ba50d45 100644 --- a/include/net/ip_tunnels.h +++ b/include/net/ip_tunnels.h @@ -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 */ diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c index 7d8744ed1664..f3c5d8424925 100644 --- a/net/ipv4/ip_tunnel.c +++ b/net/ipv4/ip_tunnel.c @@ -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; use_cache = ip_tunnel_dst_cache_usable(skb, tun_info); @@ -780,7 +780,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; if (connected && md) { diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c index a7ec800216ad..9576d146c961 100644 --- a/net/ipv6/sit.c +++ b/net/ipv6/sit.c @@ -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; } -- 2.47.3