Skip to content

Commit 73cf331

Browse files
shemmingerdavem330
authored andcommitted
vxlan: fix byte order issues with NDA_PORT
The NDA_PORT attribute was added, but the author wasn't careful about width (port is 16 bits), or byte order. The attribute was being dumped as 16 bits, but only 32 bit value would be accepted when setting up a device. Also, the remote port is in network byte order and was being compared with default port in host byte order. Signed-off-by: Stephen Hemminger <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 23c578b commit 73cf331

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

drivers/net/vxlan.c

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ static int vxlan_fdb_info(struct sk_buff *skb, struct vxlan_dev *vxlan,
192192
if (send_ip && nla_put_be32(skb, NDA_DST, rdst->remote_ip))
193193
goto nla_put_failure;
194194

195-
if (rdst->remote_port && rdst->remote_port != vxlan_port &&
195+
if (rdst->remote_port && rdst->remote_port != htons(vxlan_port) &&
196196
nla_put_be16(skb, NDA_PORT, rdst->remote_port))
197197
goto nla_put_failure;
198198
if (rdst->remote_vni != vxlan->default_dst.remote_vni &&
@@ -222,7 +222,7 @@ static inline size_t vxlan_nlmsg_size(void)
222222
return NLMSG_ALIGN(sizeof(struct ndmsg))
223223
+ nla_total_size(ETH_ALEN) /* NDA_LLADDR */
224224
+ nla_total_size(sizeof(__be32)) /* NDA_DST */
225-
+ nla_total_size(sizeof(__be32)) /* NDA_PORT */
225+
+ nla_total_size(sizeof(__be16)) /* NDA_PORT */
226226
+ nla_total_size(sizeof(__be32)) /* NDA_VNI */
227227
+ nla_total_size(sizeof(__u32)) /* NDA_IFINDEX */
228228
+ nla_total_size(sizeof(struct nda_cacheinfo));
@@ -317,7 +317,7 @@ static struct vxlan_fdb *vxlan_find_mac(struct vxlan_dev *vxlan,
317317

318318
/* Add/update destinations for multicast */
319319
static int vxlan_fdb_append(struct vxlan_fdb *f,
320-
__be32 ip, __u32 port, __u32 vni, __u32 ifindex)
320+
__be32 ip, __be16 port, __u32 vni, __u32 ifindex)
321321
{
322322
struct vxlan_rdst *rd_prev, *rd;
323323

@@ -346,7 +346,7 @@ static int vxlan_fdb_append(struct vxlan_fdb *f,
346346
static int vxlan_fdb_create(struct vxlan_dev *vxlan,
347347
const u8 *mac, __be32 ip,
348348
__u16 state, __u16 flags,
349-
__u32 port, __u32 vni, __u32 ifindex,
349+
__be16 port, __u32 vni, __u32 ifindex,
350350
__u8 ndm_flags)
351351
{
352352
struct vxlan_fdb *f;
@@ -444,7 +444,8 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
444444
struct vxlan_dev *vxlan = netdev_priv(dev);
445445
struct net *net = dev_net(vxlan->dev);
446446
__be32 ip;
447-
u32 port, vni, ifindex;
447+
__be16 port;
448+
u32 vni, ifindex;
448449
int err;
449450

450451
if (!(ndm->ndm_state & (NUD_PERMANENT|NUD_REACHABLE))) {
@@ -462,11 +463,11 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
462463
ip = nla_get_be32(tb[NDA_DST]);
463464

464465
if (tb[NDA_PORT]) {
465-
if (nla_len(tb[NDA_PORT]) != sizeof(u32))
466+
if (nla_len(tb[NDA_PORT]) != sizeof(__be16))
466467
return -EINVAL;
467-
port = nla_get_u32(tb[NDA_PORT]);
468+
port = nla_get_be16(tb[NDA_PORT]);
468469
} else
469-
port = vxlan_port;
470+
port = htons(vxlan_port);
470471

471472
if (tb[NDA_VNI]) {
472473
if (nla_len(tb[NDA_VNI]) != sizeof(u32))
@@ -489,8 +490,8 @@ static int vxlan_fdb_add(struct ndmsg *ndm, struct nlattr *tb[],
489490
ifindex = 0;
490491

491492
spin_lock_bh(&vxlan->hash_lock);
492-
err = vxlan_fdb_create(vxlan, addr, ip, ndm->ndm_state, flags, port,
493-
vni, ifindex, ndm->ndm_flags);
493+
err = vxlan_fdb_create(vxlan, addr, ip, ndm->ndm_state, flags,
494+
port, vni, ifindex, ndm->ndm_flags);
494495
spin_unlock_bh(&vxlan->hash_lock);
495496

496497
return err;
@@ -964,12 +965,13 @@ static netdev_tx_t vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
964965
struct udphdr *uh;
965966
struct flowi4 fl4;
966967
__be32 dst;
967-
__u16 src_port, dst_port;
968+
__u16 src_port;
969+
__be16 dst_port;
968970
u32 vni;
969971
__be16 df = 0;
970972
__u8 tos, ttl;
971973

972-
dst_port = rdst->remote_port ? rdst->remote_port : vxlan_port;
974+
dst_port = rdst->remote_port ? rdst->remote_port : htons(vxlan_port);
973975
vni = rdst->remote_vni;
974976
dst = rdst->remote_ip;
975977

@@ -1050,7 +1052,7 @@ static netdev_tx_t vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev,
10501052
skb_reset_transport_header(skb);
10511053
uh = udp_hdr(skb);
10521054

1053-
uh->dest = htons(dst_port);
1055+
uh->dest = dst_port;
10541056
uh->source = htons(src_port);
10551057

10561058
uh->len = htons(skb->len);

0 commit comments

Comments
 (0)