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.

140 lines
3.2 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. . /usr/share/libubox/jshn.sh
  5. . /lib/mwan3/common.sh
  6. MWAN3TRACK_STATUS_DIR="/var/run/mwan3track"
  7. IPS="ipset"
  8. IPT4="iptables -t mangle -w"
  9. IPT6="ip6tables -t mangle -w"
  10. report_connected_v4() {
  11. local address
  12. if [ -n "$($IPT4 -S mwan3_connected 2> /dev/null)" ]; then
  13. for address in $($IPS list mwan3_connected_v4 | tail -n +8); do
  14. json_add_string "" "${address}"
  15. done
  16. fi
  17. }
  18. report_connected_v6() {
  19. local address
  20. if [ -n "$($IPT6 -S mwan3_connected 2> /dev/null)" ]; then
  21. for address in $($IPS list mwan3_connected_v6 | tail -n +8); do
  22. json_add_string "" "${address}"
  23. done
  24. fi
  25. }
  26. get_mwan3_status() {
  27. local iface="${1}"
  28. local iface_select="${2}"
  29. local running="0"
  30. local age=0
  31. local pid device time_p time_n
  32. network_get_device device $1
  33. if [ "${iface}" = "${iface_select}" ] || [ "${iface_select}" = "" ]; then
  34. pid="$(pgrep -f "mwan3track $iface $device")"
  35. if [ "${pid}" != "" ]; then
  36. running="1"
  37. fi
  38. time_p="$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TIME")"
  39. [ -z "${time_p}" ] || {
  40. time_n="$(get_uptime)"
  41. let age=time_n-time_p
  42. }
  43. json_add_object "${iface}"
  44. json_add_int age "$age"
  45. json_add_int "score" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/SCORE")"
  46. json_add_int "lost" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LOST")"
  47. json_add_int "turn" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/TURN")"
  48. json_add_string "status" "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/STATUS")"
  49. json_add_boolean "running" "${running}"
  50. json_add_array "track_ip"
  51. for file in $MWAN3TRACK_STATUS_DIR/${iface}/*; do
  52. track="${file#*/TRACK_}"
  53. if [ "${track}" != "${file}" ]; then
  54. json_add_object
  55. json_add_string ip "${track}"
  56. json_add_string status "$(cat "${file}")"
  57. json_add_int latency "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LATENCY_${track}")"
  58. json_add_int packetloss "$(cat "$MWAN3TRACK_STATUS_DIR/${iface}/LOSS_${track}")"
  59. json_close_object
  60. fi
  61. done
  62. json_close_array
  63. json_close_object
  64. fi
  65. }
  66. main () {
  67. case "$1" in
  68. list)
  69. json_init
  70. json_add_object "status"
  71. json_add_string "section" "x"
  72. json_add_string "interface" "x"
  73. json_close_object
  74. json_dump
  75. ;;
  76. call)
  77. case "$2" in
  78. status)
  79. local section iface
  80. read input;
  81. json_load "$input"
  82. json_get_var section section
  83. json_get_var iface interface
  84. config_load mwan3
  85. json_init
  86. case "$section" in
  87. interfaces)
  88. json_add_object interfaces
  89. config_foreach get_mwan3_status interface "${iface}"
  90. json_close_object
  91. ;;
  92. connected)
  93. json_add_object connected
  94. json_add_array ipv4
  95. report_connected_v4
  96. json_close_array
  97. json_add_array ipv6
  98. report_connected_v6
  99. json_close_array
  100. json_close_object
  101. ;;
  102. *)
  103. # interfaces
  104. json_add_object interfaces
  105. config_foreach get_mwan3_status interface
  106. json_close_object
  107. # connected
  108. json_add_object connected
  109. json_add_array ipv4
  110. report_connected_v4
  111. json_close_array
  112. json_add_array ipv6
  113. report_connected_v6
  114. json_close_array
  115. json_close_object
  116. ;;
  117. esac
  118. json_dump
  119. ;;
  120. esac
  121. ;;
  122. esac
  123. }
  124. main "$@"