Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: Add netif_is_gretap()/netif_is_ip6gretap()

Changed the is_gretap_dev and is_ip6gretap_dev logic from structure
comparison to string comparison of the rtnl_link_ops kind field.

This approach aligns with the current identification methods and function
names of vxlan and geneve network devices.

Convert mlxsw to use these helpers and use them in downstream mlx5 patch.

Signed-off-by: Oz Shlomo <ozsh@mellanox.com>
Reviewed-by: Eli Britstein <elibr@mellanox.com>
Reviewed-by: Ido Schimmel <idosch@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>

authored by

Oz Shlomo and committed by
Saeed Mahameed
0621e6fc 101f4de9

+13 -16
+2 -2
drivers/net/ethernet/mellanox/mlxsw/spectrum_span.c
··· 383 383 } 384 384 385 385 static const struct mlxsw_sp_span_entry_ops mlxsw_sp_span_entry_ops_gretap4 = { 386 - .can_handle = is_gretap_dev, 386 + .can_handle = netif_is_gretap, 387 387 .parms = mlxsw_sp_span_entry_gretap4_parms, 388 388 .configure = mlxsw_sp_span_entry_gretap4_configure, 389 389 .deconfigure = mlxsw_sp_span_entry_gretap4_deconfigure, ··· 484 484 485 485 static const 486 486 struct mlxsw_sp_span_entry_ops mlxsw_sp_span_entry_ops_gretap6 = { 487 - .can_handle = is_ip6gretap_dev, 487 + .can_handle = netif_is_ip6gretap, 488 488 .parms = mlxsw_sp_span_entry_gretap6_parms, 489 489 .configure = mlxsw_sp_span_entry_gretap6_configure, 490 490 .deconfigure = mlxsw_sp_span_entry_gretap6_deconfigure,
+11 -2
include/net/gre.h
··· 37 37 int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi, 38 38 bool *csum_err, __be16 proto, int nhs); 39 39 40 - bool is_gretap_dev(const struct net_device *dev); 41 - bool is_ip6gretap_dev(const struct net_device *dev); 40 + static inline bool netif_is_gretap(const struct net_device *dev) 41 + { 42 + return dev->rtnl_link_ops && 43 + !strcmp(dev->rtnl_link_ops->kind, "gretap"); 44 + } 45 + 46 + static inline bool netif_is_ip6gretap(const struct net_device *dev) 47 + { 48 + return dev->rtnl_link_ops && 49 + !strcmp(dev->rtnl_link_ops->kind, "ip6gretap"); 50 + } 42 51 43 52 static inline int gre_calc_hlen(__be16 o_flags) 44 53 {
-6
net/ipv4/ip_gre.c
··· 1341 1341 ip_tunnel_setup(dev, gre_tap_net_id); 1342 1342 } 1343 1343 1344 - bool is_gretap_dev(const struct net_device *dev) 1345 - { 1346 - return dev->netdev_ops == &gre_tap_netdev_ops; 1347 - } 1348 - EXPORT_SYMBOL_GPL(is_gretap_dev); 1349 - 1350 1344 static int ipgre_newlink(struct net *src_net, struct net_device *dev, 1351 1345 struct nlattr *tb[], struct nlattr *data[], 1352 1346 struct netlink_ext_ack *extack)
-6
net/ipv6/ip6_gre.c
··· 1885 1885 netif_keep_dst(dev); 1886 1886 } 1887 1887 1888 - bool is_ip6gretap_dev(const struct net_device *dev) 1889 - { 1890 - return dev->netdev_ops == &ip6gre_tap_netdev_ops; 1891 - } 1892 - EXPORT_SYMBOL_GPL(is_ip6gretap_dev); 1893 - 1894 1888 static bool ip6gre_netlink_encap_parms(struct nlattr *data[], 1895 1889 struct ip_tunnel_encap *ipencap) 1896 1890 {