Netdev Archive mirror
 help / color / mirror / Atom feed
* [PATCH net v2 0/2] vxlan: IPv6 fill_metadata_dst support
@ 2015-12-03 10:41 Jiri Benc
  2015-12-03 10:41 ` [PATCH net v2 1/2] vxlan: move IPv6 outpute route calculation to a function Jiri Benc
  2015-12-03 10:41 ` [PATCH net v2 2/2] vxlan: support ndo_fill_metadata_dst also for IPv6 Jiri Benc
  0 siblings, 2 replies; 7+ messages in thread
From: Jiri Benc @ 2015-12-03 10:41 UTC (permalink / raw
  To: netdev; +Cc: Jesse Gross, Pravin B Shelar

This adds IPv6 support to ndo_fill_metadata_dst in vxlan. The IPv4 part
needs some restructuring to avoid duplicate code, this will be sent as
a separate patch targeting net-next.

Jiri Benc (2):
  vxlan: move IPv6 outpute route calculation to a function
  vxlan: support ndo_fill_metadata_dst also for IPv6

 drivers/net/vxlan.c | 70 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 58 insertions(+), 12 deletions(-)

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH net v2 1/2] vxlan: move IPv6 outpute route calculation to a function
  2015-12-03 10:41 [PATCH net v2 0/2] vxlan: IPv6 fill_metadata_dst support Jiri Benc
@ 2015-12-03 10:41 ` Jiri Benc
  2015-12-04 18:47   ` Pravin Shelar
  2015-12-03 10:41 ` [PATCH net v2 2/2] vxlan: support ndo_fill_metadata_dst also for IPv6 Jiri Benc
  1 sibling, 1 reply; 7+ messages in thread
From: Jiri Benc @ 2015-12-03 10:41 UTC (permalink / raw
  To: netdev; +Cc: Jesse Gross, Pravin B Shelar

Will be used also for ndo_fill_metadata_dst.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
---
v2: removed the unused 'tos' parameter that leaked from the IPv4 version
---
 drivers/net/vxlan.c | 44 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 34 insertions(+), 10 deletions(-)

diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index 6369a5734d4c..5a38558da157 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -1848,6 +1848,34 @@ static int vxlan_xmit_skb(struct rtable *rt, struct sock *sk, struct sk_buff *sk
 				   !(vxflags & VXLAN_F_UDP_CSUM));
 }
 
+#if IS_ENABLED(CONFIG_IPV6)
+static struct dst_entry *vxlan6_get_route(struct vxlan_dev *vxlan,
+					  struct sk_buff *skb, int oif,
+					  const struct in6_addr *daddr,
+					  struct in6_addr *saddr)
+{
+	struct dst_entry *ndst;
+	struct flowi6 fl6;
+	int err;
+
+	memset(&fl6, 0, sizeof(fl6));
+	fl6.flowi6_oif = oif;
+	fl6.daddr = *daddr;
+	fl6.saddr = vxlan->cfg.saddr.sin6.sin6_addr;
+	fl6.flowi6_mark = skb->mark;
+	fl6.flowi6_proto = IPPROTO_UDP;
+
+	err = ipv6_stub->ipv6_dst_lookup(vxlan->net,
+					 vxlan->vn6_sock->sock->sk,
+					 &ndst, &fl6);
+	if (err < 0)
+		return ERR_PTR(err);
+
+	*saddr = fl6.saddr;
+	return ndst;
+}
+#endif
+
 /* Bypass encapsulation if the destination is local */
 static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_vxlan,
 			       struct vxlan_dev *dst_vxlan)
@@ -2035,21 +2063,17 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 #if IS_ENABLED(CONFIG_IPV6)
 	} else {
 		struct dst_entry *ndst;
-		struct flowi6 fl6;
+		struct in6_addr saddr;
 		u32 rt6i_flags;
 
 		if (!vxlan->vn6_sock)
 			goto drop;
 		sk = vxlan->vn6_sock->sock->sk;
 
-		memset(&fl6, 0, sizeof(fl6));
-		fl6.flowi6_oif = rdst ? rdst->remote_ifindex : 0;
-		fl6.daddr = dst->sin6.sin6_addr;
-		fl6.saddr = vxlan->cfg.saddr.sin6.sin6_addr;
-		fl6.flowi6_mark = skb->mark;
-		fl6.flowi6_proto = IPPROTO_UDP;
-
-		if (ipv6_stub->ipv6_dst_lookup(vxlan->net, sk, &ndst, &fl6)) {
+		ndst = vxlan6_get_route(vxlan, skb,
+					rdst ? rdst->remote_ifindex : 0,
+					&dst->sin6.sin6_addr, &saddr);
+		if (IS_ERR(ndst)) {
 			netdev_dbg(dev, "no route to %pI6\n",
 				   &dst->sin6.sin6_addr);
 			dev->stats.tx_carrier_errors++;
@@ -2081,7 +2105,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
 		}
 
 		ttl = ttl ? : ip6_dst_hoplimit(ndst);
-		err = vxlan6_xmit_skb(ndst, sk, skb, dev, &fl6.saddr, &fl6.daddr,
+		err = vxlan6_xmit_skb(ndst, sk, skb, dev, &saddr, &dst->sin6.sin6_addr,
 				      0, ttl, src_port, dst_port, htonl(vni << 8), md,
 				      !net_eq(vxlan->net, dev_net(vxlan->dev)),
 				      flags);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH net v2 2/2] vxlan: support ndo_fill_metadata_dst also for IPv6
  2015-12-03 10:41 [PATCH net v2 0/2] vxlan: IPv6 fill_metadata_dst support Jiri Benc
  2015-12-03 10:41 ` [PATCH net v2 1/2] vxlan: move IPv6 outpute route calculation to a function Jiri Benc
@ 2015-12-03 10:41 ` Jiri Benc
  2015-12-04 18:49   ` Pravin Shelar
  1 sibling, 1 reply; 7+ messages in thread
From: Jiri Benc @ 2015-12-03 10:41 UTC (permalink / raw
  To: netdev; +Cc: Jesse Gross, Pravin B Shelar

Fill the metadata correctly even when tunneling over IPv6. Also, check that
the provided metadata is of an address family that is supported by the
tunnel.

Signed-off-by: Jiri Benc <jbenc@redhat.com>
---
v2: fixed unused variable warning when building without IPv6
---
 drivers/net/vxlan.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index 5a38558da157..d3594de3ad07 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -2413,15 +2413,37 @@ static int vxlan_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb)
 {
 	struct vxlan_dev *vxlan = netdev_priv(dev);
 	struct ip_tunnel_info *info = skb_tunnel_info(skb);
+#if IS_ENABLED(CONFIG_IPV6)
+	struct dst_entry *ndst;
+#endif
 	__be16 sport, dport;
 
 	sport = udp_flow_src_port(dev_net(dev), skb, vxlan->cfg.port_min,
 				  vxlan->cfg.port_max, true);
 	dport = info->key.tp_dst ? : vxlan->cfg.dst_port;
 
-	if (ip_tunnel_info_af(info) == AF_INET)
+	if (ip_tunnel_info_af(info) == AF_INET) {
+		if (!vxlan->vn4_sock)
+			return -EINVAL;
 		return egress_ipv4_tun_info(dev, skb, info, sport, dport);
-	return -EINVAL;
+	} else {
+		if (!IS_ENABLED(CONFIG_IPV6))
+			return -EPFNOSUPPORT;
+
+#if IS_ENABLED(CONFIG_IPV6)
+		if (!vxlan->vn6_sock)
+			return -EINVAL;
+		ndst = vxlan6_get_route(vxlan, skb, 0,
+					&info->key.u.ipv6.dst,
+					&info->key.u.ipv6.src);
+		if (IS_ERR(ndst))
+			return PTR_ERR(ndst);
+		dst_release(ndst);
+#endif
+		info->key.tp_src = sport;
+		info->key.tp_dst = dport;
+	}
+	return 0;
 }
 
 static const struct net_device_ops vxlan_netdev_ops = {
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH net v2 1/2] vxlan: move IPv6 outpute route calculation to a function
  2015-12-03 10:41 ` [PATCH net v2 1/2] vxlan: move IPv6 outpute route calculation to a function Jiri Benc
@ 2015-12-04 18:47   ` Pravin Shelar
  0 siblings, 0 replies; 7+ messages in thread
From: Pravin Shelar @ 2015-12-04 18:47 UTC (permalink / raw
  To: Jiri Benc; +Cc: netdev, Jesse Gross

On Thu, Dec 3, 2015 at 2:41 AM, Jiri Benc <jbenc@redhat.com> wrote:
> Will be used also for ndo_fill_metadata_dst.
>
> Signed-off-by: Jiri Benc <jbenc@redhat.com>

Looks good.

Acked-by: Pravin B Shelar <pshelar@nicira.com>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net v2 2/2] vxlan: support ndo_fill_metadata_dst also for IPv6
  2015-12-03 10:41 ` [PATCH net v2 2/2] vxlan: support ndo_fill_metadata_dst also for IPv6 Jiri Benc
@ 2015-12-04 18:49   ` Pravin Shelar
  2015-12-04 19:28     ` David Miller
  0 siblings, 1 reply; 7+ messages in thread
From: Pravin Shelar @ 2015-12-04 18:49 UTC (permalink / raw
  To: Jiri Benc; +Cc: netdev, Jesse Gross

On Thu, Dec 3, 2015 at 2:41 AM, Jiri Benc <jbenc@redhat.com> wrote:
> Fill the metadata correctly even when tunneling over IPv6. Also, check that
> the provided metadata is of an address family that is supported by the
> tunnel.
>
> Signed-off-by: Jiri Benc <jbenc@redhat.com>
> ---
> v2: fixed unused variable warning when building without IPv6
> ---
>  drivers/net/vxlan.c | 26 ++++++++++++++++++++++++--
>  1 file changed, 24 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
> index 5a38558da157..d3594de3ad07 100644
> --- a/drivers/net/vxlan.c
> +++ b/drivers/net/vxlan.c
> @@ -2413,15 +2413,37 @@ static int vxlan_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb)
>  {
>         struct vxlan_dev *vxlan = netdev_priv(dev);
>         struct ip_tunnel_info *info = skb_tunnel_info(skb);
> +#if IS_ENABLED(CONFIG_IPV6)
> +       struct dst_entry *ndst;
> +#endif
>         __be16 sport, dport;
>
>         sport = udp_flow_src_port(dev_net(dev), skb, vxlan->cfg.port_min,
>                                   vxlan->cfg.port_max, true);
>         dport = info->key.tp_dst ? : vxlan->cfg.dst_port;
>
> -       if (ip_tunnel_info_af(info) == AF_INET)
> +       if (ip_tunnel_info_af(info) == AF_INET) {
> +               if (!vxlan->vn4_sock)
> +                       return -EINVAL;
>                 return egress_ipv4_tun_info(dev, skb, info, sport, dport);
> -       return -EINVAL;
> +       } else {
> +               if (!IS_ENABLED(CONFIG_IPV6))
> +                       return -EPFNOSUPPORT;
> +
> +#if IS_ENABLED(CONFIG_IPV6)
> +               if (!vxlan->vn6_sock)
> +                       return -EINVAL;
> +               ndst = vxlan6_get_route(vxlan, skb, 0,
> +                                       &info->key.u.ipv6.dst,
> +                                       &info->key.u.ipv6.src);
> +               if (IS_ERR(ndst))
> +                       return PTR_ERR(ndst);
> +               dst_release(ndst);
> +#endif

Rather than checking IS_ENABLED(CONFIG_IPV6) three separate times, all
code can is restructured in one #if #else block by moving the ndst
definition to IPv6 local block.

> +               info->key.tp_src = sport;
> +               info->key.tp_dst = dport;
> +       }
> +       return 0;
>  }
>
>  static const struct net_device_ops vxlan_netdev_ops = {
> --
> 1.8.3.1
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net v2 2/2] vxlan: support ndo_fill_metadata_dst also for IPv6
  2015-12-04 18:49   ` Pravin Shelar
@ 2015-12-04 19:28     ` David Miller
  2015-12-07 10:19       ` Jiri Benc
  0 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2015-12-04 19:28 UTC (permalink / raw
  To: pshelar; +Cc: jbenc, netdev, jesse

From: Pravin Shelar <pshelar@nicira.com>
Date: Fri, 4 Dec 2015 10:49:37 -0800

> On Thu, Dec 3, 2015 at 2:41 AM, Jiri Benc <jbenc@redhat.com> wrote:
>> Fill the metadata correctly even when tunneling over IPv6. Also, check that
>> the provided metadata is of an address family that is supported by the
>> tunnel.
>>
>> Signed-off-by: Jiri Benc <jbenc@redhat.com>
>> ---
>> v2: fixed unused variable warning when building without IPv6
>> ---
>>  drivers/net/vxlan.c | 26 ++++++++++++++++++++++++--
>>  1 file changed, 24 insertions(+), 2 deletions(-)
>>
>> diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
>> index 5a38558da157..d3594de3ad07 100644
>> --- a/drivers/net/vxlan.c
>> +++ b/drivers/net/vxlan.c
>> @@ -2413,15 +2413,37 @@ static int vxlan_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb)
>>  {
>>         struct vxlan_dev *vxlan = netdev_priv(dev);
>>         struct ip_tunnel_info *info = skb_tunnel_info(skb);
>> +#if IS_ENABLED(CONFIG_IPV6)
>> +       struct dst_entry *ndst;
>> +#endif
>>         __be16 sport, dport;
>>
>>         sport = udp_flow_src_port(dev_net(dev), skb, vxlan->cfg.port_min,
>>                                   vxlan->cfg.port_max, true);
>>         dport = info->key.tp_dst ? : vxlan->cfg.dst_port;
>>
>> -       if (ip_tunnel_info_af(info) == AF_INET)
>> +       if (ip_tunnel_info_af(info) == AF_INET) {
>> +               if (!vxlan->vn4_sock)
>> +                       return -EINVAL;
>>                 return egress_ipv4_tun_info(dev, skb, info, sport, dport);
>> -       return -EINVAL;
>> +       } else {
>> +               if (!IS_ENABLED(CONFIG_IPV6))
>> +                       return -EPFNOSUPPORT;
>> +
>> +#if IS_ENABLED(CONFIG_IPV6)
>> +               if (!vxlan->vn6_sock)
>> +                       return -EINVAL;
>> +               ndst = vxlan6_get_route(vxlan, skb, 0,
>> +                                       &info->key.u.ipv6.dst,
>> +                                       &info->key.u.ipv6.src);
>> +               if (IS_ERR(ndst))
>> +                       return PTR_ERR(ndst);
>> +               dst_release(ndst);
>> +#endif
> 
> Rather than checking IS_ENABLED(CONFIG_IPV6) three separate times, all
> code can is restructured in one #if #else block by moving the ndst
> definition to IPv6 local block.

Agreed, you should be putting variable definitions into the deepest most
containing scope anyways.  So if you declare 'ndst' inside of the else
branch you'll be doing that plus decreasing the amount of CPP tests in
this file.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH net v2 2/2] vxlan: support ndo_fill_metadata_dst also for IPv6
  2015-12-04 19:28     ` David Miller
@ 2015-12-07 10:19       ` Jiri Benc
  0 siblings, 0 replies; 7+ messages in thread
From: Jiri Benc @ 2015-12-07 10:19 UTC (permalink / raw
  To: David Miller; +Cc: pshelar, netdev, jesse

On Fri, 04 Dec 2015 14:28:38 -0500 (EST), David Miller wrote:
> From: Pravin Shelar <pshelar@nicira.com>
> > Rather than checking IS_ENABLED(CONFIG_IPV6) three separate times, all
> > code can is restructured in one #if #else block by moving the ndst
> > definition to IPv6 local block.
> 
> Agreed, you should be putting variable definitions into the deepest most
> containing scope anyways.  So if you declare 'ndst' inside of the else
> branch you'll be doing that plus decreasing the amount of CPP tests in
> this file.

No problem. I actually had it that way but decided that I didn't like
the #if #else maze. I'll change it and send v3.

 Jiri

-- 
Jiri Benc

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-12-07 10:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-12-03 10:41 [PATCH net v2 0/2] vxlan: IPv6 fill_metadata_dst support Jiri Benc
2015-12-03 10:41 ` [PATCH net v2 1/2] vxlan: move IPv6 outpute route calculation to a function Jiri Benc
2015-12-04 18:47   ` Pravin Shelar
2015-12-03 10:41 ` [PATCH net v2 2/2] vxlan: support ndo_fill_metadata_dst also for IPv6 Jiri Benc
2015-12-04 18:49   ` Pravin Shelar
2015-12-04 19:28     ` David Miller
2015-12-07 10:19       ` Jiri Benc

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).