Page MenuHomeFreeBSD

ifnet: Add some sanity checks
ClosedPublic

Authored by zlei on Mar 16 2026, 8:23 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sat, Apr 18, 12:29 PM
Unknown Object (File)
Fri, Apr 17, 12:44 PM
Unknown Object (File)
Fri, Apr 17, 8:52 AM
Unknown Object (File)
Thu, Apr 16, 9:10 PM
Unknown Object (File)
Tue, Apr 14, 5:54 AM
Unknown Object (File)
Tue, Apr 14, 1:45 AM
Unknown Object (File)
Mon, Apr 13, 4:30 PM
Unknown Object (File)
Wed, Apr 8, 9:55 AM

Details

Summary

To be more robust since the checking is performed where the interface
is referenced.

While here, remove a redundant check from if_vmove_loan().

MFC after: 2 weeks

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

zlei requested review of this revision.Mar 16 2026, 8:23 AM

I'm not sure how these assertions will be beneficial if we have to add them to every function of the ifp [un]linking.
IMHO, KASSERT/MPASS are existing to verify programmatic assumptions.
And yes, these changes are definitely verifies programmatic assumptions.
However, I don't think that using them to verify every programmatic assumptions per function is appropriate.

sys/net/if.c
2132

while you're here, could you please fix its style too?

This revision is now accepted and ready to land.Mar 16 2026, 10:59 AM
zlei added inline comments.
sys/net/if.c
2132

while you're here, could you please fix its style too?

The flag IFF_DYING is a bit useless in practices. The writes to if_flags is not lock protected, hence a thread is not guareenteed to see it. Also it is a bit confusing to see a IFF_DYING interface on a "alive" list.

I believe the only valid consumer of IFF_DYING is the driver, to prevent potential race condition on ioctls. Anyway this flag do not belong to if_flags.

There're plans to remove IFF_DYING. See also https://reviews.freebsd.org/D49412.
I do not want to touch the style right now.

zlei marked an inline comment as done.Thu, Apr 2, 3:55 AM

I'm not sure how these assertions will be beneficial if we have to add them to every function of the ifp [un]linking.
IMHO, KASSERT/MPASS are existing to verify programmatic assumptions.

For example assertions in if_unlink_ifnet(), there're multiple places, if_detach() / if_vmove_loan() / if_vmove_reclaim() / vnet_if_return() want them. You do not want to repeat everywhere.

And yes, these changes are definitely verifies programmatic assumptions.
However, I don't think that using them to verify every programmatic assumptions per function is appropriate.

For assertions in ifunit() / ifunit_ref(), they guarantee the ifp is in good shape when being used, also they serve a document to developers. The net stack evolves, but the document lags.

This revision was automatically updated to reflect the committed changes.