View previous topic :: View next topic |
Author |
Message |
mgorny
Joined: 03 Oct 2019 Posts: 6
|
Posted: Sun Aug 22, 2021 7:40 am Post subject: testgetifaddr.sh doesn't handle missing default route |
|
|
Hi,
We're running the miniupnpd test suite in an isolated environment without external network access. However, it seems that testgetifaddr.sh relies on the default route to get interface name.
The output is:
Code: | /bin/sh testgetifaddr.sh
Usage: ./testgetifaddr interface_name
testgetifaddr test FAILED : 127.0.0.1
10.0.0.1 !=
make: *** [check.mk:12: validategetifaddr] Error 1
|
Firstly, there's a mistake in error handling when getting EXTIF:
Code: | EXTIF="`LC_ALL=C $IP -4 route | grep 'default' | sed -e 's/.*dev[[:space:]]*//' -e 's/[[:space:]].*//'`" || exit 1 |
This exit will only happen if the last command on the pipeline (i.e. sed) fails which doesn't happen. On my system, grep returns unsucessfully (because it can't find default) but sed clobbers that exit code. If the intention is to exit when you can't get the default route, you probably need to split this into more variables and check exit status from grep.
However, I think we can resolve the problem without causing any regressions by grabbing the interface name from 'ip addr show' output, i.e. doing something like (added the middle line):
Code: | EXTIF="`LC_ALL=C $IP -4 route | grep 'default' | sed -e 's/.*dev[[:space:]]*//' -e 's/[[:space:]].*//'`" || exit 1
EXTIF="`LC_ALL=C $IP -4 addr show $EXTIF | awk '/[0-9]+:/ { print $2 }' | cut -d ":" -f 1`"
EXTIP="`LC_ALL=C $IP -4 addr show $EXTIF | awk '/inet/ { print $2 }' | cut -d "/" -f 1`"
|
This will still prefer using the interface with the default route but will accept any interface returned by 'ip -4 addr show'. |
|
Back to top |
|
 |
mgorny
Joined: 03 Oct 2019 Posts: 6
|
Posted: Sun Aug 22, 2021 7:47 am Post subject: |
|
|
Hmm, it seems that you also need to terminate the awk after getting first IP address, as otherwise the test will fail if the interface has multiple addresses.
I'm going to submit a PR. |
|
Back to top |
|
 |
mgorny
Joined: 03 Oct 2019 Posts: 6
|
|
Back to top |
|
 |
miniupnp Site Admin
Joined: 14 Apr 2007 Posts: 1594
|
|
Back to top |
|
 |
mgorny
Joined: 03 Oct 2019 Posts: 6
|
Posted: Mon Aug 23, 2021 6:25 am Post subject: |
|
|
Thanks for maintaining miniupnp* ;-). |
|
Back to top |
|
 |
|