Skip to content

Commit 7d836a7

Browse files
shemmingerdavem330
authored andcommitted
vxlan: compute source port in network byte order
Rather than computing source port and returning it in host order then swapping later, go ahead and compute it in network order to start with. Cleaner and less error prone. Signed-off-by: Stephen Hemminger <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5d174dd commit 7d836a7

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

drivers/net/vxlan.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ static void vxlan_set_owner(struct net_device *dev, struct sk_buff *skb)
896896
* better and maybe available from hardware
897897
* secondary choice is to use jhash on the Ethernet header
898898
*/
899-
static u16 vxlan_src_port(const struct vxlan_dev *vxlan, struct sk_buff *skb)
899+
static __be16 vxlan_src_port(const struct vxlan_dev *vxlan, struct sk_buff *skb)
900900
{
901901
unsigned int range = (vxlan->port_max - vxlan->port_min) + 1;
902902
u32 hash;
@@ -906,7 +906,7 @@ static u16 vxlan_src_port(const struct vxlan_dev *vxlan, struct sk_buff *skb)
906906
hash = jhash(skb->data, 2 * ETH_ALEN,
907907
(__force u32) skb->protocol);
908908

909-
return (((u64) hash * range) >> 32) + vxlan->port_min;
909+
return htons((((u64) hash * range) >> 32) + vxlan->port_min);
910910
}
911911

912912
static int handle_offloads(struct sk_buff *skb)
@@ -965,8 +965,7 @@ static netdev_tx_t vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
965965
struct udphdr *uh;
966966
struct flowi4 fl4;
967967
__be32 dst;
968-
__u16 src_port;
969-
__be16 dst_port;
968+
__be16 src_port, dst_port;
970969
u32 vni;
971970
__be16 df = 0;
972971
__u8 tos, ttl;
@@ -1053,7 +1052,7 @@ static netdev_tx_t vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
10531052
uh = udp_hdr(skb);
10541053

10551054
uh->dest = dst_port;
1056-
uh->source = htons(src_port);
1055+
uh->source = src_port;
10571056

10581057
uh->len = htons(skb->len);
10591058
uh->check = 0;

0 commit comments

Comments
 (0)