You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.4 KiB

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
  1. #!/bin/sh
  2. . /lib/functions.sh
  3. . /lib/functions/network.sh
  4. . /lib/mwan3/mwan3.sh
  5. . /usr/share/libubox/jshn.sh
  6. [ "$ACTION" == "ifup" -o "$ACTION" == "ifdown" ] || exit 1
  7. [ -n "$INTERFACE" ] || exit 2
  8. if [ "$ACTION" == "ifup" ]; then
  9. [ -n "$DEVICE" ] || exit 3
  10. fi
  11. mwan3_lock
  12. mwan3_set_connected_iptables
  13. mwan3_unlock
  14. config_load mwan3
  15. config_get enabled $INTERFACE enabled 0
  16. config_get initial_state $INTERFACE initial_state "online"
  17. [ "$enabled" == "1" ] || exit 0
  18. if [ "$ACTION" == "ifup" ]; then
  19. config_get family $INTERFACE family ipv4
  20. if [ "$family" = "ipv4" ]; then
  21. ubus call network.interface.${INTERFACE}_4 status &>/dev/null
  22. if [ "$?" -eq "0" ]; then
  23. network_get_ipaddr src_ip ${INTERFACE}_4
  24. else
  25. network_get_ipaddr src_ip ${INTERFACE}
  26. fi
  27. [ -n "$src_ip" ] || src_ip="0.0.0.0"
  28. elif [ "$family" = "ipv6" ]; then
  29. ubus call network.interface.${INTERFACE}_6 status &>/dev/null
  30. if [ "$?" -eq "0" ]; then
  31. network_get_ipaddr6 src_ip ${INTERFACE}_6
  32. else
  33. network_get_ipaddr6 src_ip ${INTERFACE}
  34. fi
  35. [ -n "$src_ip" ] || src_ip="::"
  36. fi
  37. fi
  38. if [ "$initial_state" = "offline" ]; then
  39. json_load "$(ubus call mwan3 status '{"section":"interfaces"}')"
  40. json_select "interfaces"
  41. json_select "${INTERFACE}"
  42. json_get_var running running
  43. json_get_var status status
  44. else
  45. status=online
  46. running=1
  47. fi
  48. mwan3_lock
  49. $LOG notice "Execute "$ACTION" event on interface $INTERFACE (${DEVICE:-unknown})"
  50. case "$ACTION" in
  51. ifup)
  52. mwan3_set_general_rules
  53. mwan3_set_general_iptables
  54. mwan3_create_iface_iptables $INTERFACE $DEVICE
  55. mwan3_create_iface_rules $INTERFACE $DEVICE
  56. mwan3_create_iface_route $INTERFACE $DEVICE
  57. if [ ${running} -eq 1 -a "${status}" = "online" ]; then
  58. $LOG notice "Starting tracker on interface $INTERFACE (${DEVICE:-unknown})"
  59. mwan3_set_iface_hotplug_state $INTERFACE "online"
  60. mwan3_track $INTERFACE $DEVICE "online" "$src_ip"
  61. mwan3_set_policies_iptables
  62. mwan3_set_user_rules
  63. mwan3_flush_conntrack $INTERFACE $DEVICE "ifup"
  64. else
  65. $LOG notice "Starting tracker on interface $INTERFACE (${DEVICE:-unknown})"
  66. mwan3_set_iface_hotplug_state $INTERFACE "offline"
  67. mwan3_track $INTERFACE $DEVICE "unknown" "$src_ip"
  68. fi
  69. ;;
  70. ifdown)
  71. mwan3_set_iface_hotplug_state $INTERFACE "offline"
  72. mwan3_delete_iface_ipset_entries $INTERFACE
  73. mwan3_track_signal $INTERFACE $DEVICE
  74. mwan3_set_policies_iptables
  75. mwan3_set_user_rules
  76. mwan3_flush_conntrack $INTERFACE $DEVICE "ifdown"
  77. ;;
  78. esac
  79. mwan3_unlock
  80. exit 0