YunoHost-Apps / hotspot_ynh

Wifi Hotspot app for YunoHost
GNU Affero General Public License v3.0
39 stars 19 forks source link

Fix issue of gateway interface detection in the case of VPN usage #122

Closed Lab-8916100448256 closed 4 months ago

Lab-8916100448256 commented 5 months ago

Problem

The gateway interface is detected with the following code : new_gateway_interface=$(ip route get 1.2.3.4 | awk '{ print $5; }') This code works as expected in some cases because ip route get 1.2.3.4 returns a line where the interface name is in the 5th field, like in this first example :

root@clic:~
# -> ip route get 1.2.3.4 
1.2.3.4 via 192.168.1.254 dev end0 src 192.168.1.35 uid 0 

But in some other cases, for example when a wireguard VPN is used to make the server reachable from the internet, the network interface name is in the 3rd field, like in this second example :

root@lab12:~# ip route get 1.2.3.4
1.2.3.4 dev vpn_iloth table 51820 src 5.6.7.8 uid 0 

(note that in the above example the actual public IP address of the VPN was replaced by 5.6.7.8 to anonymize it)

Solution

replace the gateway interface detection code with the following : new_gateway_interface=$(ip route get 1.2.3.4 | awk '$2 ~ /^dev$/ { print $3; } $4 ~ /^dev$/ { print $5; }') I have tested that this is working in both cases described above. But I'm no awk expert. There might be a better way to do this that would find the interface name in any other position in the result of ip route get 1.2.3.4

PR Status

Automatic tests

Automatic tests can be triggered on https://ci-apps-dev.yunohost.org/ after creating the PR, by commenting "!testme", "!gogogadgetoci" or "By the power of systemd, I invoke The Great App CI to test this Pull Request!". (N.B. : for this to work you need to be a member of the Yunohost-Apps organization)