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.

70 lines
1.7 KiB

  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. mwan3_lock
  34. $LOG notice "$ACTION interface $INTERFACE (${DEVICE:-unknown})"
  35. case "$ACTION" in
  36. ifup)
  37. mwan3_set_general_rules
  38. mwan3_set_general_iptables
  39. mwan3_create_iface_rules $INTERFACE $DEVICE
  40. mwan3_create_iface_iptables $INTERFACE $DEVICE
  41. mwan3_create_iface_route $INTERFACE $DEVICE
  42. mwan3_track $INTERFACE $DEVICE
  43. mwan3_set_policies_iptables
  44. mwan3_set_user_rules
  45. mwan3_flush_conntrack $INTERFACE $DEVICE "ifup"
  46. ;;
  47. ifdown)
  48. mwan3_delete_iface_rules $INTERFACE
  49. mwan3_delete_iface_iptables $INTERFACE
  50. mwan3_delete_iface_route $INTERFACE
  51. mwan3_delete_iface_ipset_entries $INTERFACE
  52. mwan3_track_signal $INTERFACE $DEVICE
  53. mwan3_set_policies_iptables
  54. mwan3_set_user_rules
  55. mwan3_flush_conntrack $INTERFACE $DEVICE "ifdown"
  56. ;;
  57. esac
  58. mwan3_unlock
  59. exit 0