Page MenuHomeFreeBSD

libifconfig: Add netlink based helper to bring the interface up/down
ClosedPublic

Authored by saheed on Aug 22 2025, 6:18 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Oct 10, 10:35 PM
Unknown Object (File)
Fri, Oct 10, 4:32 PM
Unknown Object (File)
Fri, Oct 10, 4:32 PM
Unknown Object (File)
Fri, Oct 10, 4:32 PM
Unknown Object (File)
Fri, Oct 10, 10:51 AM
Unknown Object (File)
Wed, Oct 8, 5:15 AM
Unknown Object (File)
Thu, Oct 2, 7:25 PM
Unknown Object (File)
Fri, Sep 26, 6:33 PM
Subscribers

Details

Summary

Adds ifconfig_set_up() to set and unset the IFF_UP
on a network interface using RTM_NEWLINK.

Sponsored by: Google LLC (GSoC)

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Looks good to me!

When you re-open D51871, you should set that as this revision's parent revision.

otherwise I have tested this out with the _nl_ifp_modify_generic fix and it all works :)

lib/libifconfig/libifconfig_nl.c
41

sort of off-topic for this change but I realize D51871 wouldn't have worked if we assumed programs could just set ifi_change to 0 or 0xFFFFFFFF. Maybe should look into how linux handles this, maybe similar to promisc

This revision is now accepted and ready to land.Aug 23 2025, 10:27 AM

Also not something that must be done in this commit, but we should modify sbin/ifconfig to the new functions. That'll remove a little more code from ifconfig and it'll mean we test this code (as part of any test that runs ifconfig foo up).

lib/libifconfig/libifconfig.h
393

I think that should be ifconfig_up() or even better ifconfig_set_up() rather than ifconfig_if_up().
We already have ifconfig_set_name(), ifconfig_set_metric(), ifconfig_set_description(), ... where we also don't include the _if_ part.

Given that this is libifconfig it's pretty much implicitly obvious that we'll be acting on a network interface so I don't think including _if_ adds anything.

lib/libifconfig/libifconfig_nl.c
30

Perhaps not something to fix in this commit, but we ought to do this in ifconfig_open().
That way library users can call ifconfig_open() as root and then drop privileges for the rest of their work.

(It's not just here, the carp libifconfig code does this wrong too.)

Respond to review comments

lib/libifconfig/libifconfig.h
393

You're right, I'll make it ifconfig_set_up().

lib/libifconfig/libifconfig_nl.c
30

I'll refactor it into ifconfig_open() soon in a new revision :)

41

I feel like on Linux the flags are not touched if both ifi_change and ifi_flags are 0 (see do_setlink and rtnl_configure_link). I'll look deep into it soon :)

saheed retitled this revision from libifconfig: Add netlink based helpers to bring the interface up/down to libifconfig: Add netlink based helper to bring the interface up/down.
saheed edited the summary of this revision. (Show Details)

Change ifconfig_if_up/down() to ifconfig_set_up()

This revision now requires review to proceed.Aug 27 2025, 8:19 AM
lib/libifconfig/libifconfig_nl.c
41

Either way, if we do change how _nl_modify_ifp_generic ups/downs interfaces to work correctly with 0xFFFFFFFF or 0, this patch will still work :)

kp added inline comments.
lib/libifconfig/libifconfig.h
390

Missing the 'up' param.

This revision is now accepted and ready to land.Aug 28 2025, 8:24 AM
mckusick added a subscriber: mckusick.

Mentor approval.