From 512681ea05f185d80a6511407ccefacda94cfe21 Mon Sep 17 00:00:00 2001 From: Swati Singh Date: Wed, 24 Aug 2022 09:37:33 -0700 Subject: [PATCH 300/500] net:gre: Adding support to detect fb netdev adding support to detect whether the given netdevice is fallback device for gretap and ipv6 tunnel. Change-Id: Idf275af604ea56061e48f45c89154ef1d20c902a Signed-off-by: Swati Singh --- include/net/gre.h | 1 + include/net/ip_tunnels.h | 3 +++ net/ipv4/ip_gre.c | 20 ++++++++++++++++++++ net/ipv6/ip6_tunnel.c | 20 ++++++++++++++++++++ 4 files changed, 44 insertions(+) --- a/include/net/gre.h +++ b/include/net/gre.h @@ -31,6 +31,7 @@ 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); +bool gre_tunnel_is_fallback_dev(struct net_device *dev); struct net_device *gretap_fb_dev_create(struct net *net, const char *name, u8 name_assign_type); --- a/include/net/ip_tunnels.h +++ b/include/net/ip_tunnels.h @@ -592,4 +592,7 @@ static inline void ip_tunnel_info_opts_s #endif /* CONFIG_INET */ +void ipip6_update_offload_stats(struct net_device *dev, void *ptr); +void ip6_update_offload_stats(struct net_device *dev, void *ptr); +bool ip6_tunnel_is_fallback_dev(struct net_device *dev); #endif /* __NET_IP_TUNNELS_H */ --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -459,6 +459,26 @@ drop: return 0; } +bool gre_tunnel_is_fallback_dev(struct net_device *dev) +{ + struct net *net; + struct ip_tunnel_net *itn; + struct net_device *fb_tunnel_dev; + + net = dev_net(dev); + if (!net) + return false; + + itn = net_generic(net, gre_tap_net_id); + if (!itn) + return false; + + fb_tunnel_dev = itn->fb_tunnel_dev; + + return (fb_tunnel_dev == dev); +} +EXPORT_SYMBOL(gre_tunnel_is_fallback_dev); + static void __gre_xmit(struct sk_buff *skb, struct net_device *dev, const struct iphdr *tnl_params, __be16 proto) --- a/net/ipv6/ip6_tunnel.c +++ b/net/ipv6/ip6_tunnel.c @@ -2469,6 +2469,26 @@ struct net *ip6_tnl_get_link_net(const s } EXPORT_SYMBOL(ip6_tnl_get_link_net); +bool ip6_tunnel_is_fallback_dev(struct net_device *dev) +{ + struct net *net; + struct ip6_tnl_net *ip6n; + struct net_device *fb_tnl_dev; + + net = dev_net(dev); + if (!net) + return false; + + ip6n = net_generic(net, ip6_tnl_net_id); + if (!ip6n) + return false; + + fb_tnl_dev = ip6n->fb_tnl_dev; + + return (fb_tnl_dev == dev); +} +EXPORT_SYMBOL(ip6_tunnel_is_fallback_dev); + static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = { [IFLA_IPTUN_LINK] = { .type = NLA_U32 }, [IFLA_IPTUN_LOCAL] = { .len = sizeof(struct in6_addr) },