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.

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