diff mbox series

[ovs-dev,5/8] net: ip6_gre: Split up ip6gre_newlink()

Message ID 1527598505-22648-5-git-send-email-u9012063@gmail.com
State Accepted
Headers show
Series [ovs-dev,1/8] net: ip6_gre: Request headroom in __gre6_xmit() | expand

Commit Message

William Tu May 29, 2018, 12:55 p.m. UTC
commit 7fa38a7c852ec99e3a7fc375eb2c21c50c2e46b8
Author: Petr Machata <petrm@mellanox.com>
Date:   Thu May 17 16:36:39 2018 +0200

    net: ip6_gre: Split up ip6gre_newlink()

    Extract from ip6gre_newlink() a reusable function
    ip6gre_newlink_common(). The ip6gre_tnl_link_config() call needs to be
    made customizable for ERSPAN, thus reorder it with calls to
    ip6_tnl_change_mtu() and dev_hold(), and extract the whole tail to the
    caller, ip6gre_newlink(). Thus enable an ERSPAN-specific _newlink()
    function without a lot of duplicity.

    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>
---
 datapath/linux/compat/ip6_gre.c | 34 +++++++++++++++++++++++++++++-----
 1 file changed, 29 insertions(+), 5 deletions(-)

Comments

Gregory Rose May 29, 2018, 8:37 p.m. UTC | #1
On 5/29/2018 5:55 AM, William Tu wrote:
> commit 7fa38a7c852ec99e3a7fc375eb2c21c50c2e46b8
> Author: Petr Machata <petrm@mellanox.com>
> Date:   Thu May 17 16:36:39 2018 +0200
>
>      net: ip6_gre: Split up ip6gre_newlink()
>
>      Extract from ip6gre_newlink() a reusable function
>      ip6gre_newlink_common(). The ip6gre_tnl_link_config() call needs to be
>      made customizable for ERSPAN, thus reorder it with calls to
>      ip6_tnl_change_mtu() and dev_hold(), and extract the whole tail to the
>      caller, ip6gre_newlink(). Thus enable an ERSPAN-specific _newlink()
>      function without a lot of duplicity.
>
>      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>
> ---
>   datapath/linux/compat/ip6_gre.c | 34 +++++++++++++++++++++++++++++-----
>   1 file changed, 29 insertions(+), 5 deletions(-)
>
> diff --git a/datapath/linux/compat/ip6_gre.c b/datapath/linux/compat/ip6_gre.c
> index d8c5a83d8531..4cd877bcf32e 100644
> --- a/datapath/linux/compat/ip6_gre.c
> +++ b/datapath/linux/compat/ip6_gre.c
> @@ -2089,11 +2089,11 @@ static bool ip6gre_netlink_encap_parms(struct nlattr *data[],
>   }
>   
>   #ifdef HAVE_IP6GRE_EXTACK
> -static int rpl_ip6gre_newlink(struct net *src_net, struct net_device *dev,
> +static int rpl_ip6gre_newlink_common(struct net *src_net, struct net_device *dev,
>   			      struct nlattr *tb[], struct nlattr *data[],
>   			      struct netlink_ext_ack *extack)
>   #else
> -static int rpl_ip6gre_newlink(struct net *src_net, struct net_device *dev,
> +static int rpl_ip6gre_newlink_common(struct net *src_net, struct net_device *dev,
>   			      struct nlattr *tb[], struct nlattr *data[])
>   #endif
>   {
> @@ -2132,17 +2132,41 @@ static int rpl_ip6gre_newlink(struct net *src_net, struct net_device *dev,
>   	if (err)
>   		goto out;
>   
> -	ip6gre_tnl_link_config(nt, !tb[IFLA_MTU]);
> -
>   	if (tb[IFLA_MTU])
>   		ip6_tnl_change_mtu(dev, nla_get_u32(tb[IFLA_MTU]));
>   
>   	dev_hold(dev);
> -	ip6gre_tunnel_link(ign, nt);
>   
>   out:
>   	return err;
>   }
> +#define ip6gre_newlink_common rpl_ip6gre_newlink_common
> +
> +#ifdef HAVE_IP6GRE_EXTACK
> +static int rpl_ip6gre_newlink(struct net *src_net, struct net_device *dev,
> +			  struct nlattr *tb[], struct nlattr *data[],
> +			  struct netlink_ext_ack *extack)
> +#else
> +static int rpl_ip6gre_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) {
> +		ip6gre_tnl_link_config(nt, !tb[IFLA_MTU]);
> +		ip6gre_tunnel_link(net_generic(net, ip6gre_net_id), nt);
> +	}
> +	return err;
> +}
> +
>   #define ip6gre_newlink rpl_ip6gre_newlink
>   
>   #ifdef HAVE_IP6GRE_EXTACK

Reviewed-by: Greg Rose <gvrose8192@gmail.com>
Tested-by: Greg Rose <gvrose8192@gmail.com>
diff mbox series

Patch

diff --git a/datapath/linux/compat/ip6_gre.c b/datapath/linux/compat/ip6_gre.c
index d8c5a83d8531..4cd877bcf32e 100644
--- a/datapath/linux/compat/ip6_gre.c
+++ b/datapath/linux/compat/ip6_gre.c
@@ -2089,11 +2089,11 @@  static bool ip6gre_netlink_encap_parms(struct nlattr *data[],
 }
 
 #ifdef HAVE_IP6GRE_EXTACK
-static int rpl_ip6gre_newlink(struct net *src_net, struct net_device *dev,
+static int rpl_ip6gre_newlink_common(struct net *src_net, struct net_device *dev,
 			      struct nlattr *tb[], struct nlattr *data[],
 			      struct netlink_ext_ack *extack)
 #else
-static int rpl_ip6gre_newlink(struct net *src_net, struct net_device *dev,
+static int rpl_ip6gre_newlink_common(struct net *src_net, struct net_device *dev,
 			      struct nlattr *tb[], struct nlattr *data[])
 #endif
 {
@@ -2132,17 +2132,41 @@  static int rpl_ip6gre_newlink(struct net *src_net, struct net_device *dev,
 	if (err)
 		goto out;
 
-	ip6gre_tnl_link_config(nt, !tb[IFLA_MTU]);
-
 	if (tb[IFLA_MTU])
 		ip6_tnl_change_mtu(dev, nla_get_u32(tb[IFLA_MTU]));
 
 	dev_hold(dev);
-	ip6gre_tunnel_link(ign, nt);
 
 out:
 	return err;
 }
+#define ip6gre_newlink_common rpl_ip6gre_newlink_common
+
+#ifdef HAVE_IP6GRE_EXTACK
+static int rpl_ip6gre_newlink(struct net *src_net, struct net_device *dev,
+			  struct nlattr *tb[], struct nlattr *data[],
+			  struct netlink_ext_ack *extack)
+#else
+static int rpl_ip6gre_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) {
+		ip6gre_tnl_link_config(nt, !tb[IFLA_MTU]);
+		ip6gre_tunnel_link(net_generic(net, ip6gre_net_id), nt);
+	}
+	return err;
+}
+
 #define ip6gre_newlink rpl_ip6gre_newlink
 
 #ifdef HAVE_IP6GRE_EXTACK