15-mwan3 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #!/bin/sh
  2. . /lib/functions.sh
  3. . /lib/functions/network.sh
  4. . /lib/mwan3/mwan3.sh
  5. [ "$ACTION" == "ifup" -o "$ACTION" == "ifdown" ] || exit 1
  6. [ -n "$INTERFACE" ] || exit 2
  7. if [ "$ACTION" == "ifup" ]; then
  8. [ -n "$DEVICE" ] || exit 3
  9. fi
  10. mwan3_set_connected_iptables
  11. config_load mwan3
  12. config_get enabled $INTERFACE enabled 0
  13. [ "$enabled" == "1" ] || exit 0
  14. if [ "$ACTION" == "ifup" ]; then
  15. config_get family $INTERFACE family ipv4
  16. if [ "$family" = "ipv4" ]; then
  17. ubus call network.interface.${INTERFACE}_4 status &>/dev/null
  18. if [ "$?" -eq "0" ]; then
  19. network_get_gateway gateway ${INTERFACE}_4
  20. else
  21. network_get_gateway gateway $INTERFACE
  22. fi
  23. elif [ "$family" = "ipv6" ]; then
  24. ubus call network.interface.${INTERFACE}_6 status &>/dev/null
  25. if [ "$?" -eq "0" ]; then
  26. network_get_gateway6 gateway ${INTERFACE}_6
  27. else
  28. network_get_gateway6 gateway ${INTERFACE}
  29. fi
  30. fi
  31. [ -n "$gateway" ] || exit 9
  32. fi
  33. $LOG notice "$ACTION interface $INTERFACE (${DEVICE:-unknown})"
  34. case "$ACTION" in
  35. ifup)
  36. mwan3_set_general_rules
  37. mwan3_set_general_iptables
  38. mwan3_create_iface_rules $INTERFACE $DEVICE
  39. mwan3_create_iface_iptables $INTERFACE $DEVICE
  40. mwan3_create_iface_route $INTERFACE $DEVICE
  41. mwan3_track $INTERFACE $DEVICE
  42. mwan3_set_policies_iptables
  43. mwan3_set_user_rules
  44. mwan3_flush_conntrack $INTERFACE $DEVICE "ifup"
  45. ;;
  46. ifdown)
  47. mwan3_delete_iface_rules $INTERFACE
  48. mwan3_delete_iface_iptables $INTERFACE
  49. mwan3_delete_iface_route $INTERFACE
  50. mwan3_delete_iface_ipset_entries $INTERFACE
  51. mwan3_track_signal $INTERFACE $DEVICE
  52. mwan3_set_policies_iptables
  53. mwan3_set_user_rules
  54. mwan3_flush_conntrack $INTERFACE $DEVICE "ifdown"
  55. ;;
  56. esac
  57. exit 0