little-dude / netlink

netlink libraries for rust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrect VXLAN port endianess

Tuetuopay opened this issue · comments

During serialization, the VXLAN port is serialized using the host endianess, which is incorrect as netlink uses network endianess, which is big endian. This breaks on little-endian architectures, such as x86.

Example on x86 (handle setup omitted):

handle.link().add().vxlan("vxlan10".into(), 10).port(4789).execute().await?;

will result in a vxlan interface with a dstport of 46354, which is 4789 with the two bytes swapped:

$ ip -d l show dev vxlan10
9: vxlan10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/ether 7e:e7:d4:c7:ec:2c brd ff:ff:ff:ff:ff:ff promiscuity 1 minmtu 68 maxmtu 65535
    vxlan id 10 local 172.16.0.1 srcport 0 0 dstport 46354 nolearning ttl auto ageing 300 udpcsum noudp6zerocsumtx noudp6zerocsumrx

Interesting this is, parsing is done correctly by using u16::from_be_bytes().

Doing .port(u16::from_be(4789)) makes the link come with the proper port.