vxlan: IPv6 fill_metadata_dst support
Subsystems (2)
cover vxlan: IPv6 fill_metadata_dst support
This adds IPv6 support to ndo_fill_metadata_dst in vxlan together with restructuring to avoid duplicate code.
Jiri Benc (3):
vxlan: consolidate output route calculation
vxlan: move IPv6 outpute route calculation to a function
vxlan: support ndo_fill_metadata_dst also for IPv6
drivers/net/vxlan.c | 140 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 91 insertions(+), 49 deletions(-)
Signature · 1 line
1.8.3.1
PATCH 1/3 vxlan: consolidate output route calculation
The code for output route lookup is duplicated for ndo_start_xmit and ndo_fill_metadata_dst. Move it to a common function.
--- drivers/net/vxlan.c | 49 +++++++++++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 20 deletions(-)
drivers/net/vxlan.c +29 -20
@@ -1848,6 +1848,27 @@ static int vxlan_xmit_skb(struct rtable *rt, struct sock *sk, struct sk_buff *sk !(vxflags & VXLAN_F_UDP_CSUM)); } +static struct rtable *vxlan_get_route (struct vxlan_dev *vxlan, +struct sk_buff *skb,int oif,u8 tos, +__be32 daddr,__be32 *saddr) +{ +struct rtable *rt =NULL ; +struct flowi4 fl4; + +memset (&fl4,0 ,sizeof (fl4)); + fl4.flowi4_oif = oif; + fl4.flowi4_tos =RT_TOS (tos); + fl4.flowi4_mark = skb->mark; + fl4.flowi4_proto =IPPROTO_UDP ; + fl4.daddr = daddr; + fl4.saddr = vxlan->cfg.saddr.sin.sin_addr.s_addr; + + rt =ip_route_output_key (vxlan->net, &fl4); +if (!IS_ERR (rt)) + *saddr = fl4.saddr; +return rt; +} +/* 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)
@@ -1901,7 +1922,6 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,struct sock *sk;struct rtable *rt =NULL ;const struct iphdr *old_iph; -struct flowi4 fl4;union vxlan_addr *dst;union vxlan_addr remote_ip;struct vxlan_metadata _md;
@@ -1973,6 +1993,8 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, }if (dst->sa.sa_family ==AF_INET ) { +__be32 saddr; +if (!vxlan->vn4_sock) goto drop; sk = vxlan->vn4_sock->sock->sk;
@@ -1980,15 +2002,9 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,if (info && (info->key.tun_flags &TUNNEL_DONT_FRAGMENT )) df =htons (IP_DF ); -memset (&fl4,0 ,sizeof (fl4)); - fl4.flowi4_oif = rdst ? rdst->remote_ifindex :0 ; - fl4.flowi4_tos =RT_TOS (tos); - fl4.flowi4_mark = skb->mark; - fl4.flowi4_proto =IPPROTO_UDP ; - fl4.daddr = dst->sin.sin_addr.s_addr; - fl4.saddr = vxlan->cfg.saddr.sin.sin_addr.s_addr; - - rt =ip_route_output_key (vxlan->net, &fl4); + rt =vxlan_get_route (vxlan, skb, + rdst ? rdst->remote_ifindex :0 , tos, + dst->sin.sin_addr.s_addr, &saddr);if (IS_ERR (rt)) {netdev_dbg (dev,"no route to %pI4\n" , &dst->sin.sin_addr.s_addr);
@@ -2020,7 +2036,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, tos =ip_tunnel_ecn_encap (tos, old_iph, skb); ttl = ttl ? :ip4_dst_hoplimit (&rt->dst); - err = vxlan_xmit_skb(rt, sk, skb, fl4.saddr, + err = vxlan_xmit_skb(rt, sk, skb, saddr, dst->sin.sin_addr.s_addr, tos, ttl, df, src_port, dst_port, htonl(vni << 8), md, !net_eq(vxlan->net, dev_net(vxlan->dev)),
@@ -2366,20 +2382,13 @@ static int egress_ipv4_tun_info(struct net_device *dev, struct sk_buff *skb, {struct vxlan_dev *vxlan =netdev_priv (dev);struct rtable *rt; -struct flowi4 fl4; -memset (&fl4,0 ,sizeof (fl4)); - fl4.flowi4_tos =RT_TOS (info->key.tos); - fl4.flowi4_mark = skb->mark; - fl4.flowi4_proto =IPPROTO_UDP ; - fl4.daddr = info->key.u.ipv4.dst; - - rt =ip_route_output_key (vxlan->net, &fl4); + 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.u.ipv4.src = fl4.saddr; info->key.tp_src = sport; info->key.tp_dst = dport;return 0 ;
Signature · 1 line
1.8.3.1
PATCH 2/3 vxlan: move IPv6 outpute route calculation to a function
In reply to Jiri BencWill be used also for ndo_fill_metadata_dst.
--- drivers/net/vxlan.c | 45 +++++++++++++++++++++++++++++++++++---------- 1 file changed, 35 insertions(+), 10 deletions(-)
drivers/net/vxlan.c +35 -10
@@ -1869,6 +1869,35 @@ static struct rtable *vxlan_get_route(struct vxlan_dev *vxlan,return rt; } + +#if IS_ENABLED (CONFIG_IPV6 ) +static struct dst_entry *vxlan6_get_route (struct vxlan_dev *vxlan, +struct sk_buff *skb,int oif,u8 tos, +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)
@@ -2051,21 +2080,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 , tos, + &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++;
@@ -2097,7 +2122,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);
Signature · 1 line
1.8.3.1
PATCH 3/3 vxlan: support ndo_fill_metadata_dst also for IPv6
In reply to Jiri BencFill 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.
--- drivers/net/vxlan.c | 50 +++++++++++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 21 deletions(-)
drivers/net/vxlan.c +29 -21
@@ -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 = {
Signature · 1 line
1.8.3.1
kbuild test robot
build botRe: [PATCH net-next 3/3] vxlan: support ndo_fill_metadata_dst also for IPv6
reproduce:
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,
2413 vxlan->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 infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation
Quoted 3 lines · Jiri Benc
This adds IPv6 support to
ndo_fill_metadata_dstin vxlan together with restructuring to avoid duplicate code.
We need the ndo_fill_metadata_dst IPv6 support in net branch, since OVS IPv6 tunnel support is there already. Is there reason you targeted this patch series for net-next?
Quoted 3 lines · Pravin Shelar
We need the
ndo_fill_metadata_dstIPv6 support in net branch, since OVS IPv6 tunnel support is there already. Is there reason you targeted this patch series for net-next?
I guess you're right.
I need to resubmit anyway (seems I overlooked a warning when building without IPv6), I'll submit patches 2 and 3 for net and patch 1 for net-next (since it's a cleanup).
Jiri
Signature · 1 line
Jiri Benc