Fix the htons byteorder of vxlan packets after
vxlan_pick_source_port picks a source port during encapsulation.
Details
Check the source port of outgoing packets before and after
applying the patch:
ifconfig vxlan create inet6 2001:db8:a::/48 vni 1 vxlanremote 2001:db8::a vxlanlocal 2001:db8::b vxlanportrange 1234 1234 up
Diff Detail
- Repository
- rG FreeBSD src repository
- Lint
Lint Not Applicable - Unit
Tests Not Applicable
Event Timeline
Looks good to me.
Well, I do not like the inconsistency, that vxlan_encap_header() requires network byte order of srcport and dstport, but vxlan_pick_source_port() generates the host byte order. Given the dstport is from sin[6]_port which is already in network byte order, then it makes no senses to convert it back and forth.
| sys/net/if_vxlan.c | ||
|---|---|---|
| 2433 | Hi! Would you at least please consider documenting what the return value here? That way it's clearer to people who are working on this that there are endian expectations? Thanks! | |
| sys/net/if_vxlan.c | ||
|---|---|---|
| 2433 | Generally we prefer host order, so I think no comments on vxlan_pick_source_port() is good. I'd rather prefer to add comments on vxlan_encap_header(), since it has parameter ipoff which is in host byte order but the parameters srcport and dstport require network byte order. | |
| sys/net/if_vxlan.c | ||
|---|---|---|
| 2433 | How about moving the htons() into vxlan_encap_header() so all input variables are consistent without extra comments? | |
| sys/net/if_vxlan.c | ||
|---|---|---|
| 2433 | I can pass fvxlsa directly into vxlan_encap_header() and call vxlan_pick_source_port() inside it too, since ports aren't required in vxlan_encap[4|6]. However, this makes the existing code more complex that it is. | |
IMHO, changing the current version of this patch or adding extra comments to this complex driver doesn't add value.
I'm in the middle of adding another NVO-based interface driver and I think these two could merge duplicate functions into another header for any future changes that NVO3 (IETF) brings.