diff mbox series

[net,6/7] net: ip6_gre: Split up ip6gre_changelink()

Message ID 8cc069a772b633ee9c2ba4f7cb8564ac2e097dac.1526567568.git.petrm@mellanox.com
State Accepted, archived
Delegated to: David Miller
Headers show
Series net: ip6_gre: Fixes in headroom handling | expand

Commit Message

Petr Machata May 17, 2018, 2:36 p.m. UTC
Extract from ip6gre_changelink() a reusable function
ip6gre_changelink_common(). This will allow introduction of
ERSPAN-specific _changelink() function with not a lot of code
duplication.

Signed-off-by: Petr Machata <petrm@mellanox.com>
---
 net/ipv6/ip6_gre.c | 33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

Comments

William Tu May 17, 2018, 7:48 p.m. UTC | #1
On Thu, May 17, 2018 at 7:36 AM, Petr Machata <petrm@mellanox.com> wrote:
> Extract from ip6gre_changelink() a reusable function
> ip6gre_changelink_common(). This will allow introduction of
> ERSPAN-specific _changelink() function with not a lot of code
> duplication.
>
> Signed-off-by: Petr Machata <petrm@mellanox.com>
> ---

LGTM.
Acked-by: William Tu <u9012063@gmail.com>


>  net/ipv6/ip6_gre.c | 33 ++++++++++++++++++++++++---------
>  1 file changed, 24 insertions(+), 9 deletions(-)
>
> diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
> index 4dfa21d..c17e38b 100644
> --- a/net/ipv6/ip6_gre.c
> +++ b/net/ipv6/ip6_gre.c
> @@ -1921,37 +1921,52 @@ static int ip6gre_newlink(struct net *src_net, struct net_device *dev,
>         return err;
>  }
>
> -static int ip6gre_changelink(struct net_device *dev, struct nlattr *tb[],
> -                            struct nlattr *data[],
> -                            struct netlink_ext_ack *extack)
> +static struct ip6_tnl *
> +ip6gre_changelink_common(struct net_device *dev, struct nlattr *tb[],
> +                        struct nlattr *data[], struct __ip6_tnl_parm *p_p,
> +                        struct netlink_ext_ack *extack)
>  {
>         struct ip6_tnl *t, *nt = netdev_priv(dev);
>         struct net *net = nt->net;
>         struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
> -       struct __ip6_tnl_parm p;
>         struct ip_tunnel_encap ipencap;
>
>         if (dev == ign->fb_tunnel_dev)
> -               return -EINVAL;
> +               return ERR_PTR(-EINVAL);
>
>         if (ip6gre_netlink_encap_parms(data, &ipencap)) {
>                 int err = ip6_tnl_encap_setup(nt, &ipencap);
>
>                 if (err < 0)
> -                       return err;
> +                       return ERR_PTR(err);
>         }
>
> -       ip6gre_netlink_parms(data, &p);
> +       ip6gre_netlink_parms(data, p_p);
>
> -       t = ip6gre_tunnel_locate(net, &p, 0);
> +       t = ip6gre_tunnel_locate(net, p_p, 0);
>
>         if (t) {
>                 if (t->dev != dev)
> -                       return -EEXIST;
> +                       return ERR_PTR(-EEXIST);
>         } else {
>                 t = nt;
>         }
>
> +       return t;
> +}
> +
> +static int ip6gre_changelink(struct net_device *dev, struct nlattr *tb[],
> +                            struct nlattr *data[],
> +                            struct netlink_ext_ack *extack)
> +{
> +       struct ip6gre_net *ign = net_generic(dev_net(dev), ip6gre_net_id);
> +       struct __ip6_tnl_parm p;
> +       struct ip6_tnl *t;
> +
> +       t = ip6gre_changelink_common(dev, tb, data, &p, extack);
> +       if (IS_ERR(t))
> +               return PTR_ERR(t);
> +
>         ip6gre_tunnel_unlink(ign, t);
>         ip6gre_tnl_change(t, &p, !tb[IFLA_MTU]);
>         ip6gre_tunnel_link(ign, t);
> --
> 2.4.11
>
Petr Machata May 17, 2018, 8:46 p.m. UTC | #2
Fixes: 5a963eb61b7c ("ip6_gre: Add ERSPAN native tunnel support")
diff mbox series

Patch

diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index 4dfa21d..c17e38b 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -1921,37 +1921,52 @@  static int ip6gre_newlink(struct net *src_net, struct net_device *dev,
 	return err;
 }
 
-static int ip6gre_changelink(struct net_device *dev, struct nlattr *tb[],
-			     struct nlattr *data[],
-			     struct netlink_ext_ack *extack)
+static struct ip6_tnl *
+ip6gre_changelink_common(struct net_device *dev, struct nlattr *tb[],
+			 struct nlattr *data[], struct __ip6_tnl_parm *p_p,
+			 struct netlink_ext_ack *extack)
 {
 	struct ip6_tnl *t, *nt = netdev_priv(dev);
 	struct net *net = nt->net;
 	struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
-	struct __ip6_tnl_parm p;
 	struct ip_tunnel_encap ipencap;
 
 	if (dev == ign->fb_tunnel_dev)
-		return -EINVAL;
+		return ERR_PTR(-EINVAL);
 
 	if (ip6gre_netlink_encap_parms(data, &ipencap)) {
 		int err = ip6_tnl_encap_setup(nt, &ipencap);
 
 		if (err < 0)
-			return err;
+			return ERR_PTR(err);
 	}
 
-	ip6gre_netlink_parms(data, &p);
+	ip6gre_netlink_parms(data, p_p);
 
-	t = ip6gre_tunnel_locate(net, &p, 0);
+	t = ip6gre_tunnel_locate(net, p_p, 0);
 
 	if (t) {
 		if (t->dev != dev)
-			return -EEXIST;
+			return ERR_PTR(-EEXIST);
 	} else {
 		t = nt;
 	}
 
+	return t;
+}
+
+static int ip6gre_changelink(struct net_device *dev, struct nlattr *tb[],
+			     struct nlattr *data[],
+			     struct netlink_ext_ack *extack)
+{
+	struct ip6gre_net *ign = net_generic(dev_net(dev), ip6gre_net_id);
+	struct __ip6_tnl_parm p;
+	struct ip6_tnl *t;
+
+	t = ip6gre_changelink_common(dev, tb, data, &p, extack);
+	if (IS_ERR(t))
+		return PTR_ERR(t);
+
 	ip6gre_tunnel_unlink(ign, t);
 	ip6gre_tnl_change(t, &p, !tb[IFLA_MTU]);
 	ip6gre_tunnel_link(ign, t);