vxlan: bug fixes
Subsystems (2)
v2 cover vxlan: bug fixes
Revision to earlier patch set for vxlan, includes a couple more issues.
PATCH v2 1/8 vxlan: minor output refactoring
Move code to find destination to a small function.
---
v2 - breakup compound if()
drivers/net/vxlan.c +20 -11
@@ -621,6 +621,22 @@ static inline u8 vxlan_ecn_encap(u8 tos,return INET_ECN_encapsulate (tos, inner); } +static __be32 vxlan_find_dst (struct vxlan_dev *vxlan,struct sk_buff *skb) +{ +const struct ethhdr *eth = (struct ethhdr *) skb->data; +const struct vxlan_fdb *f; + +if (is_multicast_ether_addr (eth->h_dest)) +return vxlan->gaddr; + + f =vxlan_find_mac (vxlan, eth->h_dest); +if (f) +return f->remote_ip; +else +return vxlan->gaddr; + +} +/* Transmit local packets over Vxlan * * Outer IP header inherits ECN and DF from inner header.
@@ -632,13 +648,11 @@ static netdev_tx_t vxlan_xmit(struct sk_ {struct vxlan_dev *vxlan =netdev_priv (dev);struct rtable *rt; -const struct ethhdr *eth;const struct iphdr *old_iph;struct iphdr *iph;struct vxlanhdr *vxh;struct udphdr *uh;struct flowi4 fl4; -struct vxlan_fdb *f;unsigned int pkt_len = skb->len;u32 hash;__be32 dst;
@@ -646,21 +660,16 @@ static netdev_tx_t vxlan_xmit(struct sk___u8 tos, ttl;int err; + dst =vxlan_find_dst (vxlan, skb); +if (!dst) + goto drop; +/* Need space for new headers (invalidates iph ptr) */ if (skb_cow_head (skb,VXLAN_HEADROOM )) goto drop; - eth = (void *)skb->data; old_iph =ip_hdr (skb); -if (!is_multicast_ether_addr (eth->h_dest) && - (f =vxlan_find_mac (vxlan, eth->h_dest))) - dst = f->remote_ip; -else if (vxlan->gaddr) { - dst = vxlan->gaddr; - }else - goto drop; - ttl = vxlan->ttl;if (!ttl &&IN_MULTICAST (ntohl (dst))) ttl =1 ;
PATCH v2 2/8 vxlan: fix byte order in hash function
In reply to Stephen HemmingerShift was wrong direction causing packets to hash based on other parts of the ethernet header, not the address.
drivers/net/vxlan.c +2 -2
@@ -228,9 +228,9 @@ static u32 eth_hash(const unsigned char/* only want 6 bytes */ #ifdef __BIG_ENDIAN - value <<=16 ; -#else value >>=16 ; +#else + value <<=16 ;#endif return hash_64 (value,FDB_HASH_BITS ); }
PATCH v2 3/8 vxlan: use ip_route_output
In reply to Stephen HemmingerSelect source address for VXLAN packet based on route destination and don't lie to route code. VXLAN is not GRE.
---
v2 - zero flow structure
drivers/net/vxlan.c +8 -4
@@ -680,9 +680,13 @@ static netdev_tx_t vxlan_xmit(struct sk_ hash =skb_get_rxhash (skb); - rt =ip_route_output_gre (dev_net (dev), &fl4, dst, - vxlan->saddr, vxlan->vni, -RT_TOS (tos), vxlan->link); +memset (&fl4,0 ,sizeof (fl4)); + fl4.flowi4_oif = vxlan->link; + fl4.flowi4_tos =RT_TOS (tos); + fl4.daddr = dst; + fl4.saddr = vxlan->saddr; + + rt =ip_route_output_key (dev_net (dev), &fl4);if (IS_ERR (rt)) {netdev_dbg (dev,"no route to %pI4\n" , &dst); dev->stats.tx_carrier_errors++;
@@ -724,7 +728,7 @@ static netdev_tx_t vxlan_xmit(struct sk_ iph->frag_off = df; iph->protocol =IPPROTO_UDP ; iph->tos =vxlan_ecn_encap (tos, old_iph, skb); - iph->daddr = fl4.daddr; + iph->daddr = dst; iph->saddr = fl4.saddr; iph->ttl = ttl ? :ip4_dst_hoplimit (&rt->dst);
PATCH v2 4/8 vxlan: associate with tunnel socket on transmit
In reply to Stephen HemmingerWhen tunnelling a skb, associate it with the tunnel socket. This allows parameters set on tunnel socket (like multicast loop flag), to be picked up by ip_output.
drivers/net/vxlan.c +19 -0
@@ -637,6 +637,23 @@ static __be32 vxlan_find_dst(struct vxla } +static void vxlan_sock_free (struct sk_buff *skb) +{ +sock_put (skb->sk); +} + +/* On transmit, associate with the tunnel socket */ +static void vxlan_set_owner (struct net_device *dev,struct sk_buff *skb) +{ +struct vxlan_net *vn =net_generic (dev_net (dev), vxlan_net_id); +struct sock *sk = vn->sock->sk; + +skb_orphan (skb); +sock_hold (sk); + skb->sk = sk; + skb->destructor = vxlan_sock_free; +} +/* Transmit local packets over Vxlan * * Outer IP header inherits ECN and DF from inner header.
@@ -732,6 +749,8 @@ static netdev_tx_t vxlan_xmit(struct sk_ iph->saddr = fl4.saddr; iph->ttl = ttl ? :ip4_dst_hoplimit (&rt->dst); +vxlan_set_owner (dev, skb); +/* See __IPTUNNEL_XMIT */ skb->ip_summed =CHECKSUM_NONE ;ip_select_ident (iph, &rt->dst,NULL );
PATCH v2 5/8 vxlan: allow configuring port range
In reply to Stephen HemmingerVXLAN bases source UDP port based on flow to help the receiver to be able to load balance based on outer header flow.
This patch restricts the port range to the normal UDP local ports, and allows overriding via configuration.
It also uses jhash of Ethernet header when looking at flows with out know L3 header.
---
v2 - min/max are non-inclusive so allow min == max
drivers/net/vxlan.c | 62 ++++++++++++++++++++++++++++++++++++++++++++---- include/linux/if_link.h | 6 ++++ 2 files changed, 63 insertions(+), 5 deletions(-)
drivers/net/vxlan.c +57 -5
@@ -106,6 +106,8 @@ struct vxlan_dev {__be32 gaddr;/* multicast group */ __be32 saddr;/* source address */ unsigned int link;/* link to multicast over */ +__u16 port_min;/* source port range */ +__u16 port_max;__u8 tos;/* TOS override */ __u8 ttl;bool learn;
@@ -654,12 +656,29 @@ static void vxlan_set_owner(struct net_d skb->destructor = vxlan_sock_free; } +/* Compute source port for outgoing packet +* first choice to use L4 flow hash since it will spread +* better and maybe available from hardware +* secondary choice is to use jhash on the Ethernet header +*/ +static u16 vxlan_src_port (const struct vxlan_dev *vxlan,struct sk_buff *skb) +{ +unsigned int range = (vxlan->port_max - vxlan->port_min) +1 ; +u32 hash; + + hash =skb_get_rxhash (skb); +if (!hash) + hash =jhash (skb->data,2 *ETH_ALEN , + (__force u32 ) skb->protocol); + +return (((u64 ) hash * range) >>32 ) + vxlan->port_min; +} +/* Transmit local packets over Vxlan * * Outer IP header inherits ECN and DF from inner header. * Outer UDP destination is the VXLAN assigned port. -* source port is based on hash of flow if available -* otherwise use a random value +* source port is based on hash of flow */ static netdev_tx_t vxlan_xmit (struct sk_buff *skb,struct net_device *dev) {
@@ -671,8 +690,8 @@ static netdev_tx_t vxlan_xmit(struct sk_struct udphdr *uh;struct flowi4 fl4;unsigned int pkt_len = skb->len; -u32 hash;__be32 dst; +__u16 src_port;__be16 df =0 ;__u8 tos, ttl;int err;
@@ -695,7 +714,7 @@ static netdev_tx_t vxlan_xmit(struct sk_if (tos ==1 ) tos =vxlan_get_dsfield (old_iph, skb); - hash =skb_get_rxhash (skb); + src_port =vxlan_src_port (vxlan, skb);memset (&fl4,0 ,sizeof (fl4)); fl4.flowi4_oif = vxlan->link;
@@ -732,7 +751,7 @@ static netdev_tx_t vxlan_xmit(struct sk_ uh =udp_hdr (skb); uh->dest =htons (vxlan_port); - uh->source = hash ? :random32 (); + uh->source =htons (src_port); uh->len =htons (skb->len); uh->check =0 ;
@@ -960,6 +979,7 @@ static void vxlan_setup(struct net_devic {struct vxlan_dev *vxlan =netdev_priv (dev);unsigned h; +int low, high;eth_hw_addr_random (dev);ether_setup (dev);
@@ -979,6 +999,10 @@ static void vxlan_setup(struct net_devic vxlan->age_timer.function = vxlan_cleanup; vxlan->age_timer.data = (unsigned long ) vxlan; +inet_get_local_port_range (&low, &high); + vxlan->port_min = low; + vxlan->port_max = high; + vxlan->dev = dev;for (h =0 ; h <FDB_HASH_SIZE ; ++h)
@@ -995,6 +1019,7 @@ static const struct nla_policy vxlan_pol [IFLA_VXLAN_LEARNING] = { .type = NLA_U8 }, [IFLA_VXLAN_AGEING] = { .type = NLA_U32 }, [IFLA_VXLAN_LIMIT] = { .type = NLA_U32 }, + [IFLA_VXLAN_PORT_RANGE] = { .len = sizeof(struct ifla_vxlan_port_range) }, };static int vxlan_validate (struct nlattr *tb[],struct nlattr *data[])
@@ -1027,6 +1052,18 @@ static int vxlan_validate(struct nlattrreturn -EADDRNOTAVAIL ; } } + +if (data[IFLA_VXLAN_PORT_RANGE ]) { +const struct ifla_vxlan_port_range *p + =nla_data (data[IFLA_VXLAN_PORT_RANGE ]); + +if (ntohs (p->high) <ntohs (p->low)) { +pr_debug ("port range %u .. %u not valid\n" , +ntohs (p->low),ntohs (p->high)); +return -EINVAL ; + } + } +return 0 ; }
@@ -1077,6 +1114,13 @@ static int vxlan_newlink(struct net *netif (data[IFLA_VXLAN_LIMIT ]) vxlan->addrmax =nla_get_u32 (data[IFLA_VXLAN_LIMIT ]); +if (data[IFLA_VXLAN_PORT_RANGE ]) { +const struct ifla_vxlan_port_range *p + =nla_data (data[IFLA_VXLAN_PORT_RANGE ]); + vxlan->port_min =ntohs (p->low); + vxlan->port_max =ntohs (p->high); + } + err =register_netdevice (dev);if (!err)hlist_add_head_rcu (&vxlan->hlist,vni_head (net, vxlan->vni));
@@ -1105,12 +1149,17 @@ static size_t vxlan_get_size(const strucnla_total_size (sizeof (__u8)) +/* IFLA_VXLAN_LEARNING */ nla_total_size (sizeof (__u32)) +/* IFLA_VXLAN_AGEING */ nla_total_size (sizeof (__u32)) +/* IFLA_VXLAN_LIMIT */ +nla_total_size (sizeof (struct ifla_vxlan_port_range )) +0 ; }static int vxlan_fill_info (struct sk_buff *skb,const struct net_device *dev) {const struct vxlan_dev *vxlan =netdev_priv (dev); +struct ifla_vxlan_port_range ports = { + .low =htons (vxlan->port_min), + .high =htons (vxlan->port_max), + };if (nla_put_u32 (skb,IFLA_VXLAN_ID , vxlan->vni)) goto nla_put_failure;
@@ -1131,6 +1180,9 @@ static int vxlan_fill_info(struct sk_buf nla_put_u32(skb, IFLA_VXLAN_LIMIT, vxlan->addrmax)) goto nla_put_failure; +if (nla_put (skb,IFLA_VXLAN_PORT_RANGE ,sizeof (ports), &ports)) + goto nla_put_failure; +return 0 ; nla_put_failure:
include/linux/if_link.h +6 -0
@@ -284,10 +284,16 @@ enum {IFLA_VXLAN_LEARNING ,IFLA_VXLAN_AGEING ,IFLA_VXLAN_LIMIT , +IFLA_VXLAN_PORT_RANGE , __IFLA_VXLAN_MAX };#define IFLA_VXLAN_MAX (__IFLA_VXLAN_MAX - 1) +struct ifla_vxlan_port_range { +__be16 low; +__be16 high; +}; +/* SR-IOV virtual function management section */ enum {
PATCH 1/1 iproute2: allow configuring vxlan port range
New options to ip link to allow setting vxlan port range. Also, don't print everything that is defaulted when showing device.
--- include/linux/if_link.h | 6 ++++++ ip/iplink_vxlan.c | 51 ++++++++++++++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 16 deletions(-)
include/linux/if_link.h +6 -0
@@ -282,10 +282,16 @@ enum {IFLA_VXLAN_LEARNING ,IFLA_VXLAN_AGEING ,IFLA_VXLAN_LIMIT , +IFLA_VXLAN_PORT_RANGE , __IFLA_VXLAN_MAX };#define IFLA_VXLAN_MAX (__IFLA_VXLAN_MAX - 1) +struct ifla_vxlan_port_range { +__be16 low; +__be16 high; +}; +/* SR-IOV virtual function management section */ enum {
ip/iplink_vxlan.c +35 -16
108 lines not on this page · raw message
Signature · 1 line
1.7.10.4
PATCH v2 6/8 vxlan: add additional headroom
In reply to Stephen HemmingerTell upper layer protocols to allocate skb with additional headroom. This avoids allocation and copy in local packet sends.
drivers/net/vxlan.c +1 -0
@@ -983,6 +983,7 @@ static void vxlan_setup(struct net_deviceth_hw_addr_random (dev);ether_setup (dev); + dev->hard_header_len =ETH_HLEN +VXLAN_HEADROOM ; dev->netdev_ops = &vxlan_netdev_ops; dev->destructor = vxlan_free;
PATCH v2 7/8 vxlan: fix receive checksum handling
In reply to Stephen HemmingerVxlan was trying to use postpull_rcsum to allow receive checksum offload to work on drivers using CHECKSUM_COMPLETE method. But this doesn't work correctly. Just force full receive checksum on received packet.
drivers/net/vxlan.c +1 -2
@@ -537,7 +537,6 @@ static int vxlan_udp_encap_recv(struct s }__skb_pull (skb,sizeof (struct vxlanhdr )); -skb_postpull_rcsum (skb,eth_hdr (skb),sizeof (struct vxlanhdr ));/* Is this VNI defined? */ vni =ntohl (vxh->vx_vni) >>8 ;
@@ -556,7 +555,6 @@ static int vxlan_udp_encap_recv(struct s/* Re-examine inner Ethernet packet */ oip =ip_hdr (skb); skb->protocol =eth_type_trans (skb, vxlan->dev); -skb_postpull_rcsum (skb,eth_hdr (skb),ETH_HLEN );/* Ignore packet loops (and multicast echo) */ if (compare_ether_addr(eth_hdr(skb)->h_source,
@@ -568,6 +566,7 @@ static int vxlan_udp_encap_recv(struct s__skb_tunnel_rx (skb, vxlan->dev);skb_reset_network_header (skb); + skb->ip_summed =CHECKSUM_NONE ; err =IP_ECN_decapsulate (oip, skb);if (unlikely (err)) {
PATCH v2 8/8 vxlan: fix oops when give unknown ifindex
In reply to Stephen HemmingerIf vxlan is created and the ifindex is passed; there are two cases which are incorrectly handled by the existing code. The ifindex could be zero (i.e. no device) or there could be no device with that ifindex.
drivers/net/vxlan.c +10 -6
@@ -1090,14 +1090,18 @@ static int vxlan_newlink(struct net *netif (data[IFLA_VXLAN_LOCAL ]) vxlan->saddr =nla_get_be32 (data[IFLA_VXLAN_LOCAL ]); -if (data[IFLA_VXLAN_LINK ]) { - vxlan->link =nla_get_u32 (data[IFLA_VXLAN_LINK ]); +if (data[IFLA_VXLAN_LINK ] && + (vxlan->link =nla_get_u32 (data[IFLA_VXLAN_LINK ]))) { +struct net_device *lowerdev + =__dev_get_by_index (net, vxlan->link); -if (!tb[IFLA_MTU ]) { -struct net_device *lowerdev; - lowerdev =__dev_get_by_index (net, vxlan->link); - dev->mtu = lowerdev->mtu -VXLAN_HEADROOM ; +if (!lowerdev) { +pr_info ("ifindex %d does not exist\n" , vxlan->link); +return -ENODEV ; } + +if (!tb[IFLA_MTU ]) + dev->mtu = lowerdev->mtu -VXLAN_HEADROOM ; }if (data[IFLA_VXLAN_TOS ])
From: Stephen Hemminger <[email protected]>
Date: Tue, 09 Oct 2012 23:35:45 -0700
Quoted 2 lines
Revision to earlier patch set for vxlan, includes a couple more issues.
Applied, but that checksum issue is extremely unfortunate.
Why does postpull rcsum work for GRE but not VXLAN?
Quoted 9 lines · On Wed, 10 Oct 2012 22:42:20 -0400 (EDT) David Miller <[email protected]>…
From: Stephen Hemminger <[email protected]>
Date: Tue, 09 Oct 2012 23:35:45 -0700Quoted 2 lines
Revision to earlier patch set for vxlan, includes a couple more issues.
Applied, but that checksum issue is extremely unfortunate.
Why does postpull rcsum work for GRE but not VXLAN?
Not sure, plan to investigate getting rx checksum offload working and possibly tx checksum (using checksum start). Part of the problem with Tx checksum is too many drivers are looking directly at skb_network_header() and skb_transport_header() when they should be using skb_checksum_start().