Skip to content

Commit d1b2a6c

Browse files
pmachatadavem330
authored andcommitted
net: GRE: Add is_gretap_dev, is_ip6gretap_dev
Determining whether a device is a GRE device is easily done by inspecting struct net_device.type. However, for the tap variants, the type is just ARPHRD_ETHER. Therefore introduce two predicate functions that use netdev_ops to tell the tap devices. Signed-off-by: Petr Machata <petrm@mellanox.com> Reviewed-by: Ido Schimmel <idosch@mellanox.com> Signed-off-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8897207 commit d1b2a6c

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

‎include/net/gre.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ struct net_device *gretap_fb_dev_create(struct net *net, const char *name,
3737
int gre_parse_header(struct sk_buff *skb, struct tnl_ptk_info *tpi,
3838
bool *csum_err, __be16 proto, int nhs);
3939

40+
bool is_gretap_dev(const struct net_device *dev);
41+
bool is_ip6gretap_dev(const struct net_device *dev);
42+
4043
static inline int gre_calc_hlen(__be16 o_flags)
4144
{
4245
int addend = 4;

‎net/ipv4/ip_gre.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,6 +1323,12 @@ static void ipgre_tap_setup(struct net_device *dev)
13231323
ip_tunnel_setup(dev, gre_tap_net_id);
13241324
}
13251325

1326+
bool is_gretap_dev(const struct net_device *dev)
1327+
{
1328+
return dev->netdev_ops == &gre_tap_netdev_ops;
1329+
}
1330+
EXPORT_SYMBOL_GPL(is_gretap_dev);
1331+
13261332
static int ipgre_newlink(struct net *src_net, struct net_device *dev,
13271333
struct nlattr *tb[], struct nlattr *data[],
13281334
struct netlink_ext_ack *extack)

‎net/ipv6/ip6_gre.c‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1785,6 +1785,12 @@ static void ip6gre_tap_setup(struct net_device *dev)
17851785
netif_keep_dst(dev);
17861786
}
17871787

1788+
bool is_ip6gretap_dev(const struct net_device *dev)
1789+
{
1790+
return dev->netdev_ops == &ip6gre_tap_netdev_ops;
1791+
}
1792+
EXPORT_SYMBOL_GPL(is_ip6gretap_dev);
1793+
17881794
static bool ip6gre_netlink_encap_parms(struct nlattr *data[],
17891795
struct ip_tunnel_encap *ipencap)
17901796
{

0 commit comments

Comments
 (0)