pfroute: extract netmasks correctly on Darwin/NetBSD - #5074
Open
evverx wants to merge 1 commit into
Open
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:
|
evverx
commented
Aug 4, 2026
| (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), |
Contributor
Author
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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