Skip to content

Commit

Permalink
datapath: ip6_gre: Fix ip6erspan hlen calculation
Browse files Browse the repository at this point in the history
commit 2d665034f239412927b1e71329f20f001c92da09
Author: Petr Machata <petrm@mellanox.com>
Date:   Thu May 17 16:36:51 2018 +0200

    net: ip6_gre: Fix ip6erspan hlen calculation

    Even though ip6erspan_tap_init() sets up hlen and tun_hlen according to
    what ERSPAN needs, it goes ahead to call ip6gre_tnl_link_config() which
    overwrites these settings with GRE-specific ones.

    Similarly for changelink callbacks, which are handled by
    ip6gre_changelink() calls ip6gre_tnl_change() calls
    ip6gre_tnl_link_config() as well.

    The difference ends up being 12 vs. 20 bytes, and this is generally not
    a problem, because a 12-byte request likely ends up allocating more and
    the extra 8 bytes are thus available. However correct it is not.

    So replace the newlink and changelink callbacks with an ERSPAN-specific
    ones, reusing the newly-introduced _common() functions.

    Fixes: 5a963eb61b7c ("ip6_gre: Add ERSPAN native tunnel support")
    Signed-off-by: Petr Machata <petrm@mellanox.com>
    Acked-by: William Tu <u9012063@gmail.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Cc: Greg Rose <gvrose8192@gmail.com>
Signed-off-by: William Tu <u9012063@gmail.com>
Signed-off-by: Ben Pfaff <blp@ovn.org>
Reviewed-by: Greg Rose <gvrose8192@gmail.com>
Tested-by: Greg Rose <gvrose8192@gmail.com>
  • Loading branch information
williamtu authored and blp committed May 29, 2018
1 parent 2f625b3 commit 2274109
Showing 1 changed file with 84 additions and 9 deletions.
93 changes: 84 additions & 9 deletions datapath/linux/compat/ip6_gre.c
Expand Up @@ -79,6 +79,7 @@ static int ip6gre_tunnel_init(struct net_device *dev);
static void ip6gre_tunnel_setup(struct net_device *dev);
static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
static void ip6gre_tnl_link_config(struct ip6_tnl *t, int set_mtu);
static void ip6erspan_tnl_link_config(struct ip6_tnl *t, int set_mtu);

#define gre_calc_hlen rpl_ip_gre_calc_hlen
static int rpl_ip_gre_calc_hlen(__be16 o_flags)
Expand Down Expand Up @@ -1979,6 +1980,19 @@ static const struct net_device_ops ip6gre_tap_netdev_ops = {
#endif
};

static int ip6erspan_calc_hlen(struct ip6_tnl *tunnel)
{
int t_hlen;

tunnel->tun_hlen = 8;
tunnel->hlen = tunnel->tun_hlen + tunnel->encap_hlen +
erspan_hdr_len(tunnel->parms.erspan_ver);

t_hlen = tunnel->hlen + sizeof(struct ipv6hdr);
tunnel->dev->hard_header_len = LL_MAX_HEADER + t_hlen;
return t_hlen;
}

static int ip6erspan_tap_init(struct net_device *dev)
{
struct ip6_tnl *tunnel;
Expand All @@ -2002,12 +2016,7 @@ static int ip6erspan_tap_init(struct net_device *dev)
return ret;
}

tunnel->tun_hlen = 8;
tunnel->hlen = tunnel->tun_hlen + tunnel->encap_hlen +
erspan_hdr_len(tunnel->parms.erspan_ver);
t_hlen = tunnel->hlen + sizeof(struct ipv6hdr);

dev->hard_header_len = LL_MAX_HEADER + t_hlen;
t_hlen = ip6erspan_calc_hlen(tunnel);
dev->mtu = ETH_DATA_LEN - t_hlen;
if (dev->type == ARPHRD_ETHER)
dev->mtu -= ETH_HLEN;
Expand All @@ -2016,7 +2025,7 @@ static int ip6erspan_tap_init(struct net_device *dev)

dev->priv_flags |= IFF_LIVE_ADDR_CHANGE;
tunnel = netdev_priv(dev);
ip6gre_tnl_link_config(tunnel, 1);
ip6erspan_tnl_link_config(tunnel, 1);

return 0;
}
Expand Down Expand Up @@ -2387,6 +2396,72 @@ static void ip6erspan_tap_setup(struct net_device *dev)
netif_keep_dst(dev);
}

#ifdef HAVE_IP6GRE_EXTACK
static int rpl_ip6erspan_newlink(struct net *src_net, struct net_device *dev,
struct nlattr *tb[], struct nlattr *data[],
struct netlink_ext_ack *extack)
#else
static int rpl_ip6erspan_newlink(struct net *src_net, struct net_device *dev,
struct nlattr *tb[], struct nlattr *data[])
#endif
{
#ifdef HAVE_IP6GRE_EXTACK
int err = ip6gre_newlink_common(src_net, dev, tb, data, extack);
#else
int err = ip6gre_newlink_common(src_net, dev, tb, data);
#endif
struct ip6_tnl *nt = netdev_priv(dev);
struct net *net = dev_net(dev);

if (!err) {
ip6erspan_tnl_link_config(nt, !tb[IFLA_MTU]);
ip6gre_tunnel_link(net_generic(net, ip6gre_net_id), nt);
}
return err;
}
#define ip6erspan_newlink rpl_ip6erspan_newlink

static void ip6erspan_tnl_link_config(struct ip6_tnl *t, int set_mtu)
{
ip6gre_tnl_link_config_common(t);
ip6gre_tnl_link_config_route(t, set_mtu, ip6erspan_calc_hlen(t));
}

static int ip6erspan_tnl_change(struct ip6_tnl *t,
const struct __ip6_tnl_parm *p, int set_mtu)
{
ip6gre_tnl_copy_tnl_parm(t, p);
ip6erspan_tnl_link_config(t, set_mtu);
return 0;
}

#ifdef HAVE_IP6GRE_EXTACK
static int rpl_ip6erspan_changelink(struct net_device *dev, struct nlattr *tb[],
struct nlattr *data[],
struct netlink_ext_ack *extack)
#else
static int rpl_ip6erspan_changelink(struct net_device *dev, struct nlattr *tb[],
struct nlattr *data[])
#endif
{
struct ip6gre_net *ign = net_generic(dev_net(dev), ip6gre_net_id);
struct __ip6_tnl_parm p;
struct ip6_tnl *t;
#ifdef HAVE_IP6GRE_EXTACK
t = ip6gre_changelink_common(dev, tb, data, &p, extack);
#else
t = ip6gre_changelink_common(dev, tb, data, &p);
#endif
if (IS_ERR(t))
return PTR_ERR(t);

ip6gre_tunnel_unlink(ign, t);
ip6erspan_tnl_change(t, &p, !tb[IFLA_MTU]);
ip6gre_tunnel_link(ign, t);
return 0;
}
#define ip6erspan_changelink rpl_ip6erspan_changelink

static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
.kind = "ip6gre",
.maxtype = RPL_IFLA_GRE_MAX,
Expand Down Expand Up @@ -2428,8 +2503,8 @@ static struct rtnl_link_ops ip6erspan_tap_ops __read_mostly = {
.priv_size = sizeof(struct ip6_tnl),
.setup = ip6erspan_tap_setup,
.validate = ip6erspan_tap_validate,
.newlink = ip6gre_newlink,
.changelink = ip6gre_changelink,
.newlink = ip6erspan_newlink,
.changelink = ip6erspan_changelink,
.dellink = ip6gre_dellink,
.get_size = ip6gre_get_size,
.fill_info = ip6gre_fill_info,
Expand Down

0 comments on commit 2274109

Please sign in to comment.