pfroute: extract netmasks correctly on Darwin/NetBSD - #5074
Conversation
by skipping the 2-byte sin_port field and switching to the network byte order when RTA_NETMASKs are parsed. Apart from the unit tests it was tested on NetBSD (32 and 64 bit) and Darwin and also cross-checked with netstat and route. It's a follow-up to 528626a. AI-Assisted: no
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #5074 +/- ##
=======================================
Coverage 80.50% 80.51%
=======================================
Files 390 390
Lines 96785 96785
=======================================
+ Hits 77920 77923 +3
+ Misses 18865 18862 -3
🚀 New features to boost your workflow:
|
| (2130706432, 4278190080, '127.0.0.1', 'lo0', '127.0.0.1', 1), | ||
| (2130706433, 4294967295, '0.0.0.0', 'lo0', '127.0.0.1', 1), | ||
| (2887237632, 4294967295, '0.0.0.0', 'hvn0', '172.23.207.191', 1), | ||
| (2887237632, 4294963200, '0.0.0.0', 'hvn0', '172.23.207.191', 1), |
There was a problem hiding this comment.
This is a cool test in the sense that it helped me to notice the wrong byte order. The corresponding sockaddrs are
[<sockaddr sa_len=16 sa_family=AF_INET sin_port=0 sin_addr=172.23.192.0 sin_zero=b'' |>,
<sockaddr sa_len=18 sa_family=AF_LINK sdl_index=1 sdl_type=6 sdl_nlen=0 sdl_alen=0 sdl_slen=0 sdl_iface=b'' sdl_addr=b'' sdl_sel=b'' sdl_data=00000000000000000000 |>,
<sockaddr sa_len=7 sa_family=255 sa_data=fffffffff0 |>,
<sockaddr sa_len=18 sa_family=AF_LINK sdl_index=1 sdl_type=6 sdl_nlen=4 sdl_alen=6 sdl_slen=0 sdl_iface=b'hvn0' sdl_addr=00:15:5d:00:65:0a sdl_sel=b'' sdl_data= |>,
<sockaddr sa_len=16 sa_family=AF_INET sin_port=0 sin_addr=172.23.207.191 sin_zero=b'' |>]and looking at
>>> pfmsghdrs(b).msgs[3].addrs[2].sa_data[2:]
b'\xff\xff\xf0'it's kind of obvious that the netmask should be /20 (255.255.240.0) but it produced 240.255.255.0 instead. I had /4, /8,/24 and /32 locally and it worked regardless of the order but /20 is different.
There was a problem hiding this comment.
Yes ! I like those tests. All the test data is real data I got running a bunch of VMs, so they should be pretty accurate. We should make one for NetBSD 32bits with the data you provided in #5054 (comment)
|
Thanks for the PR ! LGTM |
by skipping the 2-byte sin_port field and switching to the network byte order when RTA_NETMASKs are parsed.
Apart from the unit tests it was tested on NetBSD (32 and 64 bit) and Darwin and also cross-checked with netstat and route.
It's a follow-up to 528626a.
AI-Assisted: no