Page MenuHomeFreeBSD

vtnet, ptnet: include opt_*.h files early
ClosedPublic

Authored by tuexen on Aug 20 2025, 10:52 AM.
Tags
None
Referenced Files
Unknown Object (File)
Sun, Nov 2, 9:17 AM
Unknown Object (File)
Thu, Oct 23, 8:26 AM
Unknown Object (File)
Tue, Oct 21, 6:55 PM
Unknown Object (File)
Oct 10 2025, 4:59 PM
Unknown Object (File)
Oct 10 2025, 4:59 PM
Unknown Object (File)
Oct 10 2025, 4:59 PM
Unknown Object (File)
Oct 10 2025, 11:36 AM
Unknown Object (File)
Oct 10 2025, 4:51 AM

Details

Summary

Include opt_inet.h and opt_inet6.h early in the files including virtio_net.h, since they use INET and/or INET6. In addition to that, also include them in virtio_net.h, since this files contains inline function definitions using INET and INET6.
While there, remove redundant inclusion of sys/types.h, since it is included already by sys/param.h.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped

Event Timeline

Why not adding these includes in virtio_net.h?

Why not adding these includes in virtio_net.h?

if_ptnet.c and if_vtnet.c should include these files, since they use INET and/or INET6. They should not rely on other include files like virto_net.h including opt_inet.h and opt_inet6.h for them. If files include opt_*.h, these includes should be very early. So I guess the changes to if_ptnet.c and if_vtnet.c are appropriate.
A valid question is if virto_net.h should also include opt_inet.h and opt_inet6.h. I don't know. I will bring that up in tomorrow's transport call.

A valid question is if virto_net.h should also include opt_inet.h and opt_inet6.h. I don't know. I will bring that up in tomorrow's transport call.

Normally, we avoid that. But also normally we avoid inlines. We avoid including opt_*.h in .h files because those tend to become user-visible in time. And there's been some absuse of that to drive ABI differences (mostly away from FreeBSD) and so there's a big desire to disallow that. Plus, .h files tend to become user visible, and the opt files aren't around for user-land builds.

But in this case, it's purely internal, *AND* virtio_net.h uses the defies. I think it would be fine to include them there.. I'd do it there as well, as a backup, because it uses it. I'd still move the includes because these files also test those defines and the general rule is to put opt_*.h includes before everything else and you don't want these files to assume that virtio_net.h to snag it for them.

tl;dr: this is a weird case, and I'd do both the move and add it to the .h.

sys/dev/netmap/if_ptnet.c
29–31

A nickle says this include can now be removed. The opt includes should be before it anyway.

Follow Warner's advice to include opt_inet.h and opt_inet6.h also in virtio_net.h.

As Warner suggested: don't include sys/param.h and sys/types.h, since sys/param.h already includes sys/types.h as mentioned in style.9.

tuexen marked an inline comment as done.
This revision is now accepted and ready to land.Aug 21 2025, 1:57 PM
glebius requested changes to this revision.Aug 21 2025, 3:28 PM

Let's please fix only the C files, and don't touch virtio_net.h.

This revision now requires changes to proceed.Aug 21 2025, 3:28 PM

As discussed on today's FreeBSD transport meeting, don't include opt_inet.h and opt_inet6.h in virtio_net.h.
Gleb had the idea to extend the opt_*.h machinery in a way that every file needing these includes can check for them. virtio_net.h will be the first consumer of this. But that will be a separate commit.

This revision is now accepted and ready to land.Aug 21 2025, 6:37 PM

Thanks!

Thanks for the quick approval.

This revision was automatically updated to reflect the committed changes.