Commit Graph

163 Commits

Author SHA1 Message Date
Etienne Champetier
8ae00f92b3 mwan3: handle missing interface gracefully
`ubus.call(sprintf('network.interface.%s', ifname), 'status', {})`
returns null if the interface `ifname` doesn't exists (yet).

For pppoe interfaces using `option ipv6 auto`, a virtual interface suffixed `_6`
is automatically created once the connection is established,
but until then it doesn't exists.

Fixes: 6423781254 ("mwan3: reimplement rpcd plugin using ucode")

Signed-off-by: Etienne Champetier <champetier.etienne@gmail.com>
2025-08-03 14:24:52 -04:00
Etienne Champetier
6423781254 mwan3: reimplement rpcd plugin using ucode
On my "test" router (5 wans, 2 tracking ips per wan), before any rework,
prometheus-node-exporter-lua mwan3 average scraping time was 1230ms
(scraping only the interfaces), after optimizing the shell version,
average time was down to 485ms, with ucode we are now at 41ms.

Signed-off-by: Etienne Champetier <champetier.etienne@gmail.com>
2025-08-01 13:03:01 +02:00
Etienne Champetier
bfdbacca56 mwan3: remove call to network_is_up
It calls jsonfilter but can be avoided as we know
network is up if uptime is present.

Signed-off-by: Etienne Champetier <champetier.etienne@gmail.com>
2025-08-01 13:03:01 +02:00
Etienne Champetier
a6a7f0b21b mwan3: return via variable
Using $(...) to call an internal function causes a fork().
Pass the name of the return variable as first parameter,
and write to it using 'export -n'.

Signed-off-by: Etienne Champetier <champetier.etienne@gmail.com>
2025-08-01 13:03:01 +02:00
Etienne Champetier
ecd2470ddb mwan3: replace $(cat ..) with readfile
Remove a fork+exec

Signed-off-by: Etienne Champetier <champetier.etienne@gmail.com>
2025-08-01 13:03:01 +02:00
Etienne Champetier
de98fdebef mwan3: remove pgrep usage
pgrep is pretty slow as it needs to read all /proc/*/cmdline
or /proc/*/status, and it's called twice per wan.
Add STARTED and PID files to speedup mwan3_get_mwan3track_status().

Signed-off-by: Etienne Champetier <champetier.etienne@gmail.com>
2025-08-01 13:03:01 +02:00
Etienne Champetier
50be11c618 mwan3: simplify how we kill subprocs
Just use 'job -p' to list the subprocesses currently running,
so we do not needed the global variables TRACK_PID and SLEEP_PID anymore

Signed-off-by: Etienne Champetier <champetier.etienne@gmail.com>
2025-08-01 13:03:01 +02:00
Philipp Schmitt
3f7c3ee7f7 mwan3: write mwan3 use error/debug messages to stderr instead of stdout
This redirects the debug output to stderr, allowing `mwan3 use` to be used in
scripts without polluting stdout.

Before:

mwan3 use wan curl -fsSL https://ifconfig.co/json | jq -er '.country_iso'
jq: parse error: Invalid numeric literal at line 1, column 8
curl: (23) Failure writing output to destination, passed 389 returned 0

After:

mwan3 use wan curl -fsSL https://ifconfig.co/json | jq -er '.country_iso'
Running 'curl -fsSL https://ifconfig.co/json' with DEVICE=eth2 SRCIP=192.168.0.1 FWMARK=0x3f00 FAMILY=ipv4
DE

Signed-off-by: Philipp Schmitt <philipp@schmitt.co>
2025-02-20 11:10:34 +01:00
Philipp Schmitt
0c9f4a8410 mwan3: propagate mwan3 use command exit code
This propagates the exit code of the command wrapped by `mwan3 use` and
allows for example to use `mwan3 use` in monitoring scripts.

Before change:
shell command:
  mwan3 use wan false >/dev/null && echo ok || echo fail
result:
  ok

After change:
shell command:
  mwan3 use wan false >/dev/null && echo ok || echo fail
result:
  fail

Signed-off-by: Philipp Schmitt <philipp@schmitt.co>
2025-02-20 07:59:20 +01:00
Brian J. Murrell
6f7562dee2 mwan3: Add support for nslookup track method
Signed-off-by: Brian J. Murrell <brian@interlinx.bc.ca>
2025-01-21 10:33:42 +01:00
Brian J. Murrell
c442892978 mwan3: Bug fixes with nping usage
The IP address family is a single dash option and one of 4 or 6, not tcp
or udp.

Signed-off-by: Brian J. Murrell <brian@interlinx.bc.ca>
2025-01-21 10:33:42 +01:00
William Solichin
40b84a3ce7 mwan3: add check_quality for httping
Example output of TRACK_OUTPUT (httping -c 1 -t 1 'http://www.google.co.uk'):

PING www.google.co.uk:80 (/):
connected to 142.250.200.35:80 (654 bytes), seq=0 time=136.58 ms
--- http://www.google.co.uk/ ping statistics ---
1 connects, 1 ok, 0.00% failed, time 1137 ms
round-trip min/avg/max = 136.6/136.6/136.6 ms

Signed-off-by: William Solichin <william.r.solichin@protonmail.com>
2024-10-07 08:18:07 +02:00
Eduardo Aldaz-Carroll
6b2e5c71e3 mwan3: fix grep order for nping track method
Signed-off-by: Eduardo Aldaz-Carroll <ealdaz@sees.ai>
2024-09-05 14:38:33 +02:00
William Solichin
ebf5531b42 mwan3: fix sed regex for tracking output ping check_quality
Signed-off-by: William Solichin <william.r.solichin@protonmail.com>
2024-09-02 09:22:39 +02:00
Lars Kruse
d3c2f7625c mwan3: "use" action: run process via exec and handle whitespace
Previously the "use" command had the following shortcomings:
* a subprocess was created instead of replacing the shell process
* whitespace in arguments was not handled correctly

Implementation detail:
In shell context the `"$@"` expression should be used (instead of `$*`).
This allows the safe handling of arguments containing whitespace.

Closes: #20001

Signed-off-by: Lars Kruse <devel@sumpfralle.de>
2024-06-23 11:20:26 -07:00
Sergey Ponomarev
4c4a7bd31d treewide: use config_get_bool instead of config_get enabled
The config_get_bool function parses not just the 1 but on/yes, true/false or enabled/disabled.

Signed-off-by: Sergey Ponomarev <stokito@gmail.com>
2024-05-26 03:00:50 +08:00
Jonas Lochmann
e119a57e97 mwan3: check removed route before removal
This makes mwan3rtmon check if mwan3_get_routes returns a route
before removing it. This helps with IPv6 routes with source address
selector removal where multiple original routes are transformed to
the same mwan3 route if one of the source routes is removed while
the others are kept.

Signed-off-by: Jonas Lochmann <git@inkompetenz.org>
2024-02-20 21:53:22 +01:00
Florian Eckert
002439594c mwan3: also show tracker state via ubus
The tracker state is not shown via ubus. Only if the tracker was in
active state, then the boolean running was set or not. By adding the
tracking state to the ubus information we could also evaluate the state
of the tracker. To remain compatible, the runnig flag of the tracker is
not removed, which in fact displays the same information, but only if
the tracker is in state 'active' or not.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2023-09-20 16:10:06 +02:00
Florian Eckert
4f59c248e0 mwan3: remove notracking in mwan3track ubus status
The function 'get_mwan3_status' is reading the internal state from the
tracker via the status file. Do not use the state 'notracking' status
anymore. If the mwan3track is not running always return 'unknown'
and not 'notracking'. There is already an other function that evaluates
the external state of the tracker.

We have now the following states of the tracker:
internal (mwan3track):
- offline
- online
- diconnecting
- connecting
- disabled
- unknown

external (via pgrep and config):
- paused
- active
- down
- not enabled

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2023-09-20 16:05:08 +02:00
Florian Eckert
a56e111c49 mwan3: fix mwan3_connected ubus output
During the renameing of mwan3_connected_v4 to mwan3_connected_ipv4 and
mwan3_connected_v6 to mwan3_connected_ipv6 the adjustment in the ubus
call was forgotten. This commit fixes this.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2023-09-12 16:03:18 +02:00
Florian Eckert
5f0461be8b mwan3: reset score to up+down on connected
Set the score value to the maximum value when the connected function is
called. The same happens with a disconnected event, the score value is
there set to zero.

Suggested-by: Anna Tikhomirova <vamp@vampik.ru>
Suggested-by: Maxim Mikityanskiy <maxtram95@gmail.com>
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2023-05-08 09:47:08 +02:00
Florian Eckert
1f6bd672fe mwan3: refactoring mwan3track action handling
Refactoring the score handling, so that only one action could take place
during run. The behaviour should be more comprehensible, since several
score actions are not processed at the same time.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2023-05-08 09:47:08 +02:00
Anna Tikhomirova
84b3de9eda mwan3: fix addition of routes to mwan3_connected ipset
Addition of routes to mwan3_connected ipset is broken. The ipset name was
changed from mwan3_connected_v4/6 to mwan3_connected_ipv4/6, but this
change was not reflected in mwan3rtmon.

Signed-off-by: Anna Tikhomirova <vamp@vampik.ru>
* Update commit message
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2023-05-04 12:00:27 +02:00
Florian Eckert
997c0842ca mwan3: only send disconnected event if interface was connected before
Up to now on every interface down event a mwan3 disconnected event was
send. This is wrong because if the interface was never connected, then a
disconnected event should not get generated. This commit fixes this bug.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2022-10-17 15:17:31 +02:00
Florian Eckert
a49d0953dc mwan3: move command definitions to common.sh
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2022-03-14 09:34:49 +01:00
Florian Eckert
619b721c2f mwan3: add troublshoot command from LuCI
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2021-07-08 09:07:52 +02:00
Florian Eckert
a9dac71e3d mwan3: cleanup help output
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2021-07-08 09:07:52 +02:00
Florian Eckert
f1da872cd4 mwan3: update ubus status for not tracked interfaces
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2021-05-03 10:52:26 +02:00
Florian Eckert
5348732b98 mwan3: add connecting and disconnecting event to mwan3track
If the interface goes into failure state (is disconnecting)
then with this change one hotplug.d event is generated.

The same is true for the recovery state (is connecting), when the interface
comes back from a failure state.

In both cases, a hotplug.d event for the iface is triggered. Once
with the $ACTION=disconnecting and once for the $ACTION=connecting.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2021-03-16 09:24:36 +01:00
Florian Eckert
7cfb282432 mwan3: disable DNS lookups for ping checks
By default, ping does a reverse DNS of the IP that you are pinging.
When you have a network issue (such as when a link has just gone down
and you haven't yet marked it down), this lookup can cause failures on
tests for links that are still good.

This option only works for iputils ping.
For busybox the option is not evaluated, but it is accepted without
throwing an error.

Fixes: #14968
Fixes: #14924

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
Suggested-by: David Lang <david@lang.hm>
2021-03-01 12:23:43 +01:00
Aaron Goodman
267b65ad9f mwan3: fix regression in ipv6 routing tables
Signed-off-by: Aaron Goodman <aaronjg@stanford.edu>
2021-01-02 21:37:37 -05:00
Florian Eckert
2f58865a01 mwan3: fix string check for active_tbls
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2020-12-22 08:38:30 +01:00
Aaron Goodman
c6fce89bf7 mwan3: add more error logging to routing functions
Signed-off-by: Aaron Goodman <aaronjg@stanford.edu>
2020-12-16 09:32:44 +01:00
Aaron Goodman
21ac1b2c3e mwan3: fix race condition in route loading
Signed-off-by: Aaron Goodman <aaronjg@stanford.edu>
2020-12-16 09:32:13 +01:00
Aaron Goodman
5691ff247f mwan3: fix linkdown routes not being added
Signed-off-by: Aaron Goodman <aaronjg@stanford.edu>
2020-12-16 09:32:02 +01:00
Aaron Goodman
1bfb1a66cd mwan3: support latest iputils ping
iputils upstream changed build params with version s20200821
Latest OpenWRT iputils ping now appears to report the openwrt
version tag, rather than iputils date tag

This commit sends a test ping to localhost to evaluate the
capabilities of iputils ping.

Signed-off-by: Aaron Goodman <aaronjg@stanford.edu>
2020-11-16 11:23:10 -05:00
Aaron Goodman
a5f3e6bb6b mwan3: don't call rpcd on 'mwan3 interfaces'
Allow `mwan3 interfaces` to get uptime via an internal function and
thus remove the dependency on rpcd for `mwan3 interface` calls.

Signed-off-by: Aaron Goodman <aaronjg@stanford.edu>
2020-11-16 11:19:55 -05:00
Aaron Goodman
321a52862a mwan3: cleanup indenting in rpcd interface status
Signed-off-by: Aaron Goodman <aaronjg@stanford.edu>
2020-11-10 09:03:33 -05:00
Aaron Goodman
e405b261d6 mwan3: don't include output from TRACK_OUTUPUT in status call
Signed-off-by: Aaron Goodman <aaronjg@stanford.edu>
2020-11-10 08:51:47 -05:00
Aaron Goodman
c336e5d682 mwan3: remove unused device lookup in status check
Signed-off-by: Aaron Goodman <aaronjg@stanford.edu>
2020-11-10 08:50:39 -05:00
Aaron Goodman
a870bd70a9 mwan3: restore +x flag to mwan3 executables
Signed-off-by: Aaron Goodman <aaronjg@stanford.edu>
2020-11-10 08:45:46 -05:00
Florian Eckert
1f1d21ed28 mwan3: make it clearer who initiated the start
It was somewhat opaque how the variable a is questioned. To show this
better the variable is now a string and not a boolean. So you can see
directly what should happen. With a boolean you always have to think
about what it means when 0 or 1 is used.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2020-11-06 10:41:28 +01:00
Aaron Goodman
59d12598b5 mwan3: use procd for locking everywhere
Replace locks on /var/run/mwan3.lock with locks via procd.

This fixes a deadlock issue where mwan3 stop would have a procd
lock, but a hotplug script would have the /var/run/mwan3.lock

Locking can be removed from mwan3rtmon since:
1) procd will have sent the KILL signal to the process during
shutdown, so it will not add routes to already removed interfaces on
mwan3 shutdown and
2) mwan3rtmon checks if an interface is active based on the
mwan3_iface_in_<IFACE> entry in iptables, and the hotplug script
always adds this before creating the route table and removes it
before deleting the route table

Fixes github issue #13704
(https://github.com/openwrt/packages/issues/13704)
2020-11-06 10:40:57 +01:00
Florian Eckert
6834f8e3a6 mwan3: use common makefile install wrappers
With this change you can see at a glance which files will be installed on
the system.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2020-11-06 10:35:55 +01:00
Florian Eckert
94a25dbd92 mwan3: fix wait conditions in mwan3track
Will only run when no events are pending.

Signed-off-by: Aaron Goodman <aaronjg@stanford.edu>
[ Update description and split into own commit ]
Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2020-11-06 10:35:49 +01:00
Florian Eckert
81e6a8fd3b mwan3: move mwan3_init call in mwwan3track into main
Initialize TRACK_OUTPUT has been set after INTERFACE variable initialization.
Move definition into main fixes this issue.

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
2020-11-06 10:35:45 +01:00
Aaron Goodman
13d22445e4 mwan3: fix rpcd with for routers with no IPv6 support
Signed-off-by: Aaron Goodman <aaronjg@stanford.edu>
2020-10-29 23:06:25 -04:00
Aaron Goodman
f1bfda4c37 mwan3: do not wait to process ifup/ifdown events
Signed-off-by: Aaron Goodman <aaronjg@stanford.edu>
2020-10-27 23:18:18 -04:00
Aaron Goodman
8d4e202fa4 mwan3: fix mwan3 route handling
- support trailing route space from iproute2
- add routes even when iface is down
- fix source_routing argument check
- add quotes in logging to better detect issues with trailing spaces

Signed-off-by: Aaron Goodman <aaronjg@stanford.edu>
2020-10-27 21:40:06 -04:00
Aaron Goodman
e5dc144968 mwan3: fix mwan3 'use'
Signed-off-by: Aaron Goodman <aaronjg@stanford.edu>
2020-10-22 09:41:48 -04:00