Skip to content

macos port: use native interfaces to find default network interface #6925

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

trws
Copy link
Member

@trws trws commented Jul 21, 2025

I decided to try out the MacOS build at the end of last week, and noticed one bit of low-hanging fruit. The getprimary_iface4 function was failing, and I guessed that could cause a whole lot of downstream failures.

The commit message has much more detail, but I ended up completely reworking the approach with roughly the same result.

@trws trws requested a review from garlick July 21, 2025 19:32
@trws trws force-pushed the getprimary-macos branch 2 times, most recently from 9a18911 to 524ca5e Compare July 21, 2025 19:40
@trws trws mentioned this pull request Jul 21, 2025
Copy link
Contributor

@grondo grondo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a nice improvement to me!

@trws
Copy link
Member Author

trws commented Jul 22, 2025

It turns out this is not reliable in some cases, where no interface with a blank netmask exists but a default still does, working on a fix.

problem: MacOS/BSD lack a linux-compatible proc (usually) so we can't
read routes from proc

solution: On linux we'll continue to use /proc/net/route, while on macos
it turns out you can have a default interface *that does not have a
netmask of zero*.  To get it reliably, I've added a version of
`getprimary_interface4` that uses the CoreFoundation and
SystemConfiguration frameworks to request the global IPv4 default
interface name from macos directly.  This is more macos specific than
using a PF_ROUTE socket, but much _much_ simpler.  If we want this to
work on other BSDs (aside from FreeBSD with linux compat turned on)
we'll want to do that but NETLINK/PF_ROUTE are really arcane and rather
high overhead for something this simple.

Anyway, this is using the classic C interface to CoreFoundation rather
than any of the add-ons so there's no need to compile code as
Objective-C or anything.

As to why I switched to this from the getifaddrs approach, that seemed
to work fine on linux with a small tweak, but not on macos, and if it
doesn't work reliably cross-platform it seems better to keep what we had
battle tested and add the more specific mac version like this.
@trws trws force-pushed the getprimary-macos branch from 524ca5e to a496d82 Compare July 23, 2025 18:43
@trws trws changed the title macos port: use getifaddrs to find default if macos port: use native interfaces to find default if Jul 23, 2025
@trws trws requested a review from grondo July 23, 2025 18:44
Copy link

codecov bot commented Jul 23, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 83.91%. Comparing base (1824d14) to head (a496d82).
Report is 28 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6925      +/-   ##
==========================================
- Coverage   83.91%   83.91%   -0.01%     
==========================================
  Files         540      540              
  Lines       90526    90526              
==========================================
- Hits        75967    75963       -4     
- Misses      14559    14563       +4     
Files with missing lines Coverage Δ
src/common/libutil/ipaddr.c 79.27% <100.00%> (ø)

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@trws trws changed the title macos port: use native interfaces to find default if macos port: use native interfaces to find default network interface Jul 23, 2025
@trws
Copy link
Member Author

trws commented Jul 24, 2025

There's a failure happening on both PRs related to this from the fileref test. I haven't been able to reproduce it on a local mac, and it doesn't seem to have cropped up before. @garlick have you seen this? It looks like a symlink test failure, but there's no related output from GHA to see what actually failed other than that.

@grondo
Copy link
Contributor

grondo commented Jul 24, 2025

Does the tmate action work on the macos builder? I've used that in the past to debug issues that annoyingly only happen in CI. I just usually temporarily add the action on failure. (I Ikeep wondering if there's a way to permanently add that action and only trigger it via a "debug" rebuild)

@trws
Copy link
Member Author

trws commented Jul 24, 2025

That is an excellent thought. I don't know, but I will find out.

@garlick
Copy link
Member

garlick commented Jul 25, 2025

Apologies, I made a comment on this stuff in the other PR that is based on top of it. Just that I'm traveling today and wanted to have a closer look at this before it goes in. Great work @trws.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants