[PATCH net-next 3/3] vxlan: support ndo_fill_metadata_dst also for IPv6

2015-12-02 Thread Jiri Benc
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 
---
 drivers/net/vxlan.c | 50 +-
 1 file changed, 29 insertions(+), 21 deletions(-)

diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
index 2945cf7f9c73..d2edc35cfdaf 100644
--- a/drivers/net/vxlan.c
+++ b/drivers/net/vxlan.c
@@ -2401,37 +2401,45 @@ static int vxlan_change_mtu(struct net_device *dev, int 
new_mtu)
return 0;
 }
 
-static int egress_ipv4_tun_info(struct net_device *dev, struct sk_buff *skb,
-   struct ip_tunnel_info *info,
-   __be16 sport, __be16 dport)
-{
-   struct vxlan_dev *vxlan = netdev_priv(dev);
-   struct rtable *rt;
-
-   rt = vxlan_get_route(vxlan, skb, 0, info->key.tos,
-info->key.u.ipv4.dst, &info->key.u.ipv4.src);
-   if (IS_ERR(rt))
-   return PTR_ERR(rt);
-   ip_rt_put(rt);
-
-   info->key.tp_src = sport;
-   info->key.tp_dst = dport;
-   return 0;
-}
-
 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);
+   struct dst_entry *ndst;
+   struct rtable *rt;
__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)
-   return egress_ipv4_tun_info(dev, skb, info, sport, dport);
-   return -EINVAL;
+   if (ip_tunnel_info_af(info) == AF_INET) {
+   if (!vxlan->vn4_sock)
+   return -EINVAL;
+   rt = vxlan_get_route(vxlan, skb, 0, info->key.tos,
+info->key.u.ipv4.dst,
+&info->key.u.ipv4.src);
+   if (IS_ERR(rt))
+   return PTR_ERR(rt);
+   ip_rt_put(rt);
+   } 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.tos,
+   &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

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH net-next 3/3] vxlan: support ndo_fill_metadata_dst also for IPv6

2015-12-02 Thread kbuild test robot
Hi Jiri,

[auto build test WARNING on net-next/master]

url:
https://github.com/0day-ci/linux/commits/Jiri-Benc/vxlan-IPv6-fill_metadata_dst-support/20151203-021449
config: x86_64-randconfig-i0-201548 (attached as .config)
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All warnings (new ones prefixed by >>):

   drivers/net/vxlan.c: In function 'vxlan_fill_metadata_dst':
>> drivers/net/vxlan.c:2408:20: warning: unused variable 'ndst' 
>> [-Wunused-variable]
 struct dst_entry *ndst;
   ^

vim +/ndst +2408 drivers/net/vxlan.c

  2392  if (dst->remote_ip.sa.sa_family == AF_INET6)
  2393  max_mtu = lowerdev->mtu - VXLAN6_HEADROOM;
  2394  else
  2395  max_mtu = lowerdev->mtu - VXLAN_HEADROOM;
  2396  
  2397  if (new_mtu < 68 || new_mtu > max_mtu)
  2398  return -EINVAL;
  2399  
  2400  dev->mtu = new_mtu;
  2401  return 0;
  2402  }
  2403  
  2404  static int vxlan_fill_metadata_dst(struct net_device *dev, struct 
sk_buff *skb)
  2405  {
  2406  struct vxlan_dev *vxlan = netdev_priv(dev);
  2407  struct ip_tunnel_info *info = skb_tunnel_info(skb);
> 2408  struct dst_entry *ndst;
  2409  struct rtable *rt;
  2410  __be16 sport, dport;
  2411  
  2412  sport = udp_flow_src_port(dev_net(dev), skb, 
vxlan->cfg.port_min,
  2413vxlan->cfg.port_max, true);
  2414  dport = info->key.tp_dst ? : vxlan->cfg.dst_port;
  2415  
  2416  if (ip_tunnel_info_af(info) == AF_INET) {

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: Binary data