Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 3 commits into from Mar 19, 2024

Conversation

Lab-8916100448256
Copy link
Contributor

@Lab-8916100448256 Lab-8916100448256 commented Mar 8, 2024

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

  • Code finished and ready to be reviewed/tested
  • The fix/enhancement were manually tested (if applicable)

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)

@alexAubin alexAubin merged commit 8a580cf into YunoHost-Apps:testing Mar 19, 2024
@alexAubin alexAubin mentioned this pull request Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants