Bug 282780 - emulators/virtualbox-ose-kmod: build error since 1500027 (struct ifnet is now hidden)
Summary: emulators/virtualbox-ose-kmod: build error since 1500027 (struct ifnet is now...
Status: New
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Some People
Assignee: Virtualbox Team (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-11-15 11:03 UTC by Olivier Cochard
Modified: 2024-11-28 09:24 UTC (History)
6 users (show)

See Also:
bugzilla: maintainer-feedback? (vbox)


Attachments
ifnet.patch (13.97 KB, patch)
2024-11-27 15:28 UTC, Vladimir Kondratyev
no flags Details | Diff
ifnet.patch (13.96 KB, patch)
2024-11-27 15:51 UTC, Vladimir Kondratyev
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Cochard freebsd_committer freebsd_triage 2024-11-15 11:03:42 UTC
Hi,

looks like a long due change switch to default on current:
https://lists.freebsd.org/archives/freebsd-net/2024-November/005983.html

--- VBoxNetFlt-freebsd.o ---
VBoxNetFlt-freebsd.c:343:24: error: incomplete definition of type 'struct ifnet'
  343 |     VBOXCURVNET_SET(ifp->if_vnet);
      |                     ~~~^
Comment 1 Vladimir Druzenko freebsd_committer freebsd_triage 2024-11-16 00:52:11 UTC
Can you suggest a patch?
Comment 2 Ken DEGUCHI 2024-11-18 08:58:31 UTC
(In reply to Vladimir Druzenko from comment #1)

As far as I have tried,

#include <net/if_private.h>

to the following two files, it seems to build and use them without any problem.

${WRKSRC}/src/VBox/HostDrivers/VBoxNetAdp/freebsd/VBoxNetAdp-freebsd.c
${WRKSRC}/src/VBox/HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c
Comment 3 Olivier Cochard freebsd_committer freebsd_triage 2024-11-18 17:00:42 UTC
(In reply to Ken DEGUCHI from comment #2)

The current plan is to remove inclusion of if_private.h
Comment 4 Vladimir Druzenko freebsd_committer freebsd_triage 2024-11-18 22:06:10 UTC
(In reply to Olivier Cochard from comment #3)
Okay, you told how not to do it. Can you tell how to do? :-D
Comment 5 Olivier Cochard freebsd_committer freebsd_triage 2024-11-18 22:22:26 UTC
(In reply to Vladimir Druzenko from comment #4)

Yes because it is a lot more easy to tell how to not doing it :-)

Following this announcement:
https://lists.freebsd.org/archives/freebsd-net/2024-November/005983.html

There is an helper script in instruction, but you need some coding skills which I don’t have.

cd /usr/ports/emulators/virtualbox-ose-kmod/
make patch
cd work/VirtualBox-6.1.50
/usr/src/tools/ifnet/convert_ifapi.sh ./src/VBox/HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c

Conversion for ./src/VBox/HostDrivers/VBoxNetFlt/freebsd/VBoxNetFlt-freebsd.c started, please wait:  \
       7 lines could not be converted to IFAPI
Look for /* XXX - IFAPI */ in the converted file

And this is where my skillset end :-)

I would start looking for all existing NIC drivers that were migrated by listing all commit with the name "IfAPI":
https://cgit.freebsd.org/src/log/?qt=grep&q=IfAPI
Comment 6 Justin Hibbits freebsd_committer freebsd_triage 2024-11-19 15:07:31 UTC
The "easy" thing to do after running the script on the file is to check:

* Any place you see foo->if_xxx = <N>, look for a if_setxxx in net/if_var.h.  If something doesn't exist, there may be an equivalent, or a new API may be needed.
* Any place you see N = foo->if_xxx, look for if_getxxx in net/if_var.h.

Now, there will probably be cases where the script messed up the conversion, and you went from something like:

   xxx_ifp->if_mtu = 42;

to:

   xxx_if_setmtu(ifp, 42);

This needs cleaned up to:

   if_setmtu(xxx_ifp, 42);


These above are the most common issues with the conversion script.  If you still have issues after applying changes I listed here, please let me know, either filing a PR, or email (freebsd-net list, CC me).  Since all in-tree drivers have been converted to IfAPI, the vast majority of use cases have been dealt with, and any new cases found are likely very special-case, so would be handled as needed.
Comment 7 Vladimir Kondratyev freebsd_committer freebsd_triage 2024-11-27 15:28:40 UTC
Created attachment 255491 [details]
ifnet.patch

Mechanical conversion to new ifnet KPI
Comment 8 Vladimir Kondratyev freebsd_committer freebsd_triage 2024-11-27 15:32:26 UTC
There may be more 'struct ifnet *' -> if_t conversion required but I am too lazy to do it
Comment 9 Justin Hibbits freebsd_committer freebsd_triage 2024-11-27 15:39:37 UTC
(In reply to Vladimir Kondratyev from comment #7)

Thanks for doing the work, one comment, though:

* You changed `struct ifnet *` to `if_t *`, but `if_t` is `struct ifnet *`, so `if_t *` is a pointer to a pointer now.  You just want `if_t foo` instead.
Comment 10 Vladimir Kondratyev freebsd_committer freebsd_triage 2024-11-27 15:51:48 UTC
Created attachment 255492 [details]
ifnet.patch

if_t * -> if_t
Comment 11 Justin Hibbits freebsd_committer freebsd_triage 2024-11-27 16:00:48 UTC
(In reply to Vladimir Kondratyev from comment #10)

Looks good.  Might want to make that patch conditional on the FreeBSD version in the port, though.  If it's just supporting FreeBSD 14 and later, though, I think you can skip it, since almost everything has been in place since FreeBSD 14 was still -CURRENT.
Comment 12 Vladimir Kondratyev freebsd_committer freebsd_triage 2024-11-28 09:24:13 UTC
It seems that 13-STABLE implements most or may be all of interfaces required by the patch. Someone running FreeBSD 13 should check that.