mwan3: fix interface-bound traffic when interface is offline
This commit fixed what 6d99b602 was supposed to fix without affecting
interface-bound traffic.
Before 6d99b602 interface-bound traffic was working normally as long
as at least one interface was online. However when the last interface
went offline, it was impossible to ping and such state was
unrecoverable.
Commit 6d99b602 fixed unrecoverable offline state problem (it was
possible to ping -I iface) but messed inteface-bound traffic. Traffic
with interface source address was not working if the interface was in
"offline" state, even if another interface was online.
The problem was caused by an inconsistent "offline" interface state:
iptables-related rules were kept while routing table and policy were
deleted.
The idea behind this commit is to:
1. Keep all the rules for each interface (iptables, routing table,
policy) regardless of its state. This ensures consistency,
2. Make interface state hotplug events affect only iptables'
mwan3_policy_* rules. Interface-related iptables, routing table
and policy is removed only when mwan3 is manually stopped.
To make such changes possible, it's necessary to change the way
mwan3_policy_* rule generator keeps track of interface state hotplug
events.
Until now, it checked for the existence of custom interface-related
routing table (table id 1, 2, 3, ...). Clearly we can no longer rely
on that so each interface state is stored explicitly in file.
Signed-off-by: Marcin Jurkowski <marcin1j@gmail.com>
7 years ago mwan3: fix interface-bound traffic when interface is offline
This commit fixed what 6d99b602 was supposed to fix without affecting
interface-bound traffic.
Before 6d99b602 interface-bound traffic was working normally as long
as at least one interface was online. However when the last interface
went offline, it was impossible to ping and such state was
unrecoverable.
Commit 6d99b602 fixed unrecoverable offline state problem (it was
possible to ping -I iface) but messed inteface-bound traffic. Traffic
with interface source address was not working if the interface was in
"offline" state, even if another interface was online.
The problem was caused by an inconsistent "offline" interface state:
iptables-related rules were kept while routing table and policy were
deleted.
The idea behind this commit is to:
1. Keep all the rules for each interface (iptables, routing table,
policy) regardless of its state. This ensures consistency,
2. Make interface state hotplug events affect only iptables'
mwan3_policy_* rules. Interface-related iptables, routing table
and policy is removed only when mwan3 is manually stopped.
To make such changes possible, it's necessary to change the way
mwan3_policy_* rule generator keeps track of interface state hotplug
events.
Until now, it checked for the existence of custom interface-related
routing table (table id 1, 2, 3, ...). Clearly we can no longer rely
on that so each interface state is stored explicitly in file.
Signed-off-by: Marcin Jurkowski <marcin1j@gmail.com>
7 years ago mwan3: fix interface-bound traffic when interface is offline
This commit fixed what 6d99b602 was supposed to fix without affecting
interface-bound traffic.
Before 6d99b602 interface-bound traffic was working normally as long
as at least one interface was online. However when the last interface
went offline, it was impossible to ping and such state was
unrecoverable.
Commit 6d99b602 fixed unrecoverable offline state problem (it was
possible to ping -I iface) but messed inteface-bound traffic. Traffic
with interface source address was not working if the interface was in
"offline" state, even if another interface was online.
The problem was caused by an inconsistent "offline" interface state:
iptables-related rules were kept while routing table and policy were
deleted.
The idea behind this commit is to:
1. Keep all the rules for each interface (iptables, routing table,
policy) regardless of its state. This ensures consistency,
2. Make interface state hotplug events affect only iptables'
mwan3_policy_* rules. Interface-related iptables, routing table
and policy is removed only when mwan3 is manually stopped.
To make such changes possible, it's necessary to change the way
mwan3_policy_* rule generator keeps track of interface state hotplug
events.
Until now, it checked for the existence of custom interface-related
routing table (table id 1, 2, 3, ...). Clearly we can no longer rely
on that so each interface state is stored explicitly in file.
Signed-off-by: Marcin Jurkowski <marcin1j@gmail.com>
7 years ago mwan3: fix interface-bound traffic when interface is offline
This commit fixed what 6d99b602 was supposed to fix without affecting
interface-bound traffic.
Before 6d99b602 interface-bound traffic was working normally as long
as at least one interface was online. However when the last interface
went offline, it was impossible to ping and such state was
unrecoverable.
Commit 6d99b602 fixed unrecoverable offline state problem (it was
possible to ping -I iface) but messed inteface-bound traffic. Traffic
with interface source address was not working if the interface was in
"offline" state, even if another interface was online.
The problem was caused by an inconsistent "offline" interface state:
iptables-related rules were kept while routing table and policy were
deleted.
The idea behind this commit is to:
1. Keep all the rules for each interface (iptables, routing table,
policy) regardless of its state. This ensures consistency,
2. Make interface state hotplug events affect only iptables'
mwan3_policy_* rules. Interface-related iptables, routing table
and policy is removed only when mwan3 is manually stopped.
To make such changes possible, it's necessary to change the way
mwan3_policy_* rule generator keeps track of interface state hotplug
events.
Until now, it checked for the existence of custom interface-related
routing table (table id 1, 2, 3, ...). Clearly we can no longer rely
on that so each interface state is stored explicitly in file.
Signed-off-by: Marcin Jurkowski <marcin1j@gmail.com>
7 years ago |
|
- #!/bin/sh
-
- . /lib/functions.sh
- . /lib/functions/network.sh
- . /lib/mwan3/mwan3.sh
- . /usr/share/libubox/jshn.sh
-
- [ "$ACTION" == "ifup" -o "$ACTION" == "ifdown" ] || exit 1
- [ -n "$INTERFACE" ] || exit 2
-
- if [ "$ACTION" == "ifup" ]; then
- [ -n "$DEVICE" ] || exit 3
- fi
-
- config_load mwan3
- config_get_bool enabled globals 'enabled' '0'
- [ ${enabled} -gt 0 ] || exit 0
-
- mwan3_lock
- mwan3_init
- mwan3_set_connected_iptables
- mwan3_set_custom_ipset
- mwan3_unlock
-
- config_get enabled $INTERFACE enabled 0
- config_get initial_state $INTERFACE initial_state "online"
- [ "$enabled" == "1" ] || exit 0
-
- if [ "$ACTION" == "ifup" ]; then
- config_get family $INTERFACE family ipv4
- if [ "$family" = "ipv4" ]; then
- ubus call network.interface.${INTERFACE}_4 status &>/dev/null
- if [ "$?" -eq "0" ]; then
- network_get_ipaddr src_ip ${INTERFACE}_4
- else
- network_get_ipaddr src_ip ${INTERFACE}
- fi
- [ -n "$src_ip" ] || src_ip="0.0.0.0"
- elif [ "$family" = "ipv6" ]; then
- ubus call network.interface.${INTERFACE}_6 status &>/dev/null
- if [ "$?" -eq "0" ]; then
- network_get_ipaddr6 src_ip ${INTERFACE}_6
- else
- network_get_ipaddr6 src_ip ${INTERFACE}
- fi
- [ -n "$src_ip" ] || src_ip="::"
- fi
- fi
-
- if [ "$initial_state" = "offline" ]; then
- json_load "$(ubus call mwan3 status '{"section":"interfaces"}')"
- json_select "interfaces"
- json_select "${INTERFACE}"
- json_get_var running running
- json_get_var status status
- else
- status=online
- running=1
- fi
-
- mwan3_lock
- $LOG notice "Execute "$ACTION" event on interface $INTERFACE (${DEVICE:-unknown})"
-
- case "$ACTION" in
- ifup)
- mwan3_set_general_rules
- mwan3_set_general_iptables
- mwan3_create_iface_iptables $INTERFACE $DEVICE
- mwan3_create_iface_rules $INTERFACE $DEVICE
- mwan3_create_iface_route $INTERFACE $DEVICE
- if [ ${running} -eq 1 -a "${status}" = "online" ]; then
- $LOG notice "Starting tracker on interface $INTERFACE (${DEVICE:-unknown})"
- mwan3_set_iface_hotplug_state $INTERFACE "online"
- mwan3_track $INTERFACE $DEVICE "online" "$src_ip"
- else
- $LOG notice "Starting tracker on interface $INTERFACE (${DEVICE:-unknown})"
- mwan3_set_iface_hotplug_state $INTERFACE "offline"
- mwan3_track $INTERFACE $DEVICE "offline" "$src_ip"
- fi
- mwan3_set_policies_iptables
- mwan3_set_user_rules
- mwan3_flush_conntrack $INTERFACE $DEVICE "ifup"
- ;;
- ifdown)
- mwan3_set_iface_hotplug_state $INTERFACE "offline"
- mwan3_delete_iface_ipset_entries $INTERFACE
- mwan3_track_signal $INTERFACE $DEVICE
- mwan3_set_policies_iptables
- mwan3_set_user_rules
- mwan3_flush_conntrack $INTERFACE $DEVICE "ifdown"
- ;;
- esac
-
- mwan3_unlock
-
- exit 0
|