[General Questions and Answers] i_dont_use_xda:
I am in need of an Ethernet connection which is fully compatible with userspace on the latest version of Android. Plugging in an Ethernet cable through an adapter works fine, it's just apps that require a connection from userspace do not work (such as Telegram, Magisk, etc).

I am able to compile a custom kernel and have compiled a kernel as part of a LineageOS ROM that I had built from the official instructions for my Pixel 3a XL (bonito). I had set the following in the kernel configuration:

CONFIG_MAC80211_HWSIM=m
CONFIG_VIRT_WIFI=m

so that I could build the virt_wifi module.

I ended up making several more modifications to the kernel as the virt_wifi module source code was different to one listed in Android-x86 (which I know definitely works). I was having issues with the virt_wifi module that came with my kernel as it was never connecting, only giving me 'Failed to connect to network' alerts and failing to connect 100% of the time (as opposed to 90% of the time that I get from Android-x86's kernel module). I took the following files from the Android-x86 kernel and placed them into the msm-4.9 kernel for my Pixel 3a XL device:

include/net/virt_wifi.h
kernel/drivers/net/wireless/virt_wifi.c

After recompiling with these files replacing the existing ones, I had more success but things were still unreliable (I dive deeper into the issue later in this post).

I found instructions listed at the bottom of https://groups.google.com/g/android-x86/c/cjzhscvylSw which helped me setup a virtual wireless connection. I have altered them for my particular case.

rmmod wlan # remove internal wifi module to remove existing wlan0 interface
modprobe -d /vendor/lib/modules lib80211 # modprobe lib80211 - seemingly required for virt_wifi
modprobe -d /vendor/lib/modules virt_wifi # modprobe virt_wifi itself
ifconfig eth0 down # bring ethernet interface down temporarily
ip link set eth0 name wifi_eth # change ethernet interface name
ifconfig wifi_eth up # bring ethernet interface back up (under new name)
ip link add link wifi_eth name wlan0 type virt_wifi # add virtual link from wifi_eth interface to wlan0 as type 'virt_wifi'

After this, if I immediately turn on my Wi-Fi and check the Wi-Fi settings, it just says that it is searching for a network.

ifconfig wlan0 up

Before I transferred the virt_wifi related files from Android-x86's kernel source code to the msm-4.9 kernel source code, I was completely unable to get a connection at all (I tried over 25 times to get a connection with no success).

After transferring the files and rebuilding the LineageOS ROM for my Pixel 3a XL, I was able to get a connection after repeating the previous command multiple times and returning back to the Wi-Fi settings screen quickly. I have ended up being able to get a connection five times and I had used the previous command over 50 times in total. Magisk functioned without issues (which requires Wi-Fi to use any downloading functionality - it cannot use Ethernet directly for this) and the Wi-Fi status screen showed everything as connected fully, as it would a standard Wi-Fi connection.

The problem is, it is incredibly tedious to be trying to connect constantly and have to repeat this time consuming process if I disconnect the Ethernet cable. I want to be able to simply tap on VirtWifi and connect to it without issues, at the moment when I tap on it I get 'Failed to connect to network' alerts.

By the way, before anyone asks, it is very unlikely to be related to my Ethernet adapter. I used a dummy Ethernet interface to connect so that I could test to see if it has the same problem of not being able to connect most of the time and it still has the issue where it only connects once in every ten or so times (however it isn't able to connect to the internet so it drops the connection after 30 or so seconds anyway, it just attempts a connection but the real Ethernet interface would do the same thing if it had no internet).

If anyone could help me fix this issue, I will give them $100. Thanks.