garywill / linux-router

Set Linux as router in one command. Support Internet sharing, redsocks, Wifi hotspot, IPv6. Can also be used for routing VM/containers 🛰️ (也欢迎关注B站 https://space.bilibili.com/2123686105 )
GNU Lesser General Public License v2.1
1.67k stars 148 forks source link

command failed: Invalid argument (-22) #44

Closed Cabbache closed 1 year ago

Cabbache commented 1 year ago

On ubuntu, When trying to serve a hotspot on the same interface that has internet, the script is failing. sudo ./lnxrouter --ap <wireless interface with internet> hotspot -p password.

linux-router 0.6.6 (https://github.com/garywill/linux-router)
Released under LGPL, with no warranty. Use on your own risk.

PID: 216391
Target interface is <interface with internet> (a6:1a:58:36:f3:c9)   PCI: 
Use random LAN IPv4 address 192.168.99.1
<interface with internet> already in channel 6 (2437 MHz)
Channel fallback to 6
Creating a virtual WiFi interface... 
kernel reports: Attribute failed policy validation
command failed: Invalid argument (-22)
Error occured

ERROR: Failed creating virtual WiFi interface. Maybe your WiFi adapter does not fully support virtual interfaces. Try again with '--no-virt'

If I add --no-virt it works but no internet is served on the hotspot. I had no trouble doing this with the original create_ap script.

The problem is coming from this line.

I even tried manually running the command iw dev ...etc but it returns the same error:

kernel reports: Attribute failed policy validation
command failed: Invalid argument (-22)

In case it is related to this, the name of the interface I have with internet is 15 characters long, and the variable VWIFI_IFACE has a length of 17 characters.

Cabbache commented 1 year ago

I've confirmed that it works when I make the name of the virtual interface shorter instead of 2 characters added to the original interface name.

garywill commented 1 year ago

Hi, thank you for reporting the issue and sending PR!

I think it is better to defaultly name the new interface name after the original interface name. People may create more than 1 virtual interface based on different wifi adapters simutaneously.

So adding an option to rename the new interface (e.g. --virt-name) would be better. Also, the script should warn user if the original interface has a long name.

garywill commented 1 year ago

I'm considering that

v_iface_name="$VIRT_PREFIX$i"

is not 100% preditable interface name

It is better to do it a preditable way

v_iface_name="$VIRT_NAME"

Let user decide the exact interface name

Cabbache commented 1 year ago

Currently the alloc_new_vface_name function seems to increment $i until $VIRT_PREFIX$i is not the name of an existing interface. If we change it to v_iface_name="$VIRT_NAME", then should the script exit with an error if the interface already exists?

garywill commented 1 year ago

Yes. User should receive an error if the interface name already exist.