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.

95 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
  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_gateway gateway ${INTERFACE}_4
  24. network_get_ipaddr src_ip ${INTERFACE}_4
  25. else
  26. network_get_gateway gateway $INTERFACE
  27. network_get_ipaddr src_ip ${INTERFACE}
  28. fi
  29. elif [ "$family" = "ipv6" ]; then
  30. ubus call network.interface.${INTERFACE}_6 status &>/dev/null
  31. if [ "$?" -eq "0" ]; then
  32. network_get_gateway6 gateway ${INTERFACE}_6
  33. network_get_ipaddr6 src_ip ${INTERFACE}_6
  34. else
  35. network_get_gateway6 gateway ${INTERFACE}
  36. network_get_ipaddr6 src_ip ${INTERFACE}
  37. fi
  38. fi
  39. [ -n "$gateway" ] || exit 9
  40. fi
  41. if [ "$initial_state" = "offline" ]; then
  42. json_load "$(ubus call mwan3 status '{"section":"interfaces"}')"
  43. json_select "interfaces"
  44. json_select "${INTERFACE}"
  45. json_get_var running running
  46. json_get_var status status
  47. else
  48. status=online
  49. running=1
  50. fi
  51. mwan3_lock
  52. $LOG notice "Execute "$ACTION" event on interface $INTERFACE (${DEVICE:-unknown})"
  53. case "$ACTION" in
  54. ifup)
  55. mwan3_set_general_rules
  56. mwan3_set_general_iptables
  57. mwan3_create_iface_iptables $INTERFACE $DEVICE
  58. mwan3_create_iface_rules $INTERFACE $DEVICE
  59. mwan3_create_iface_route $INTERFACE $DEVICE
  60. if [ ${running} -eq 1 -a "${status}" = "online" ]; then
  61. $LOG notice "Starting tracker on interface $INTERFACE (${DEVICE:-unknown})"
  62. mwan3_set_iface_hotplug_state $INTERFACE "online"
  63. mwan3_track $INTERFACE $DEVICE "online" "$src_ip"
  64. mwan3_set_policies_iptables
  65. mwan3_set_user_rules
  66. mwan3_flush_conntrack $INTERFACE $DEVICE "ifup"
  67. else
  68. $LOG notice "Starting tracker on interface $INTERFACE (${DEVICE:-unknown})"
  69. mwan3_set_iface_hotplug_state $INTERFACE "offline"
  70. mwan3_track $INTERFACE $DEVICE "unknown" "$src_ip"
  71. fi
  72. ;;
  73. ifdown)
  74. mwan3_set_iface_hotplug_state $INTERFACE "offline"
  75. mwan3_delete_iface_ipset_entries $INTERFACE
  76. mwan3_track_signal $INTERFACE $DEVICE
  77. mwan3_set_policies_iptables
  78. mwan3_set_user_rules
  79. mwan3_flush_conntrack $INTERFACE $DEVICE "ifdown"
  80. ;;
  81. esac
  82. mwan3_unlock
  83. exit 0