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.

60 lines
1.3 KiB

  1. #!/bin/sh
  2. . /lib/functions.sh
  3. . /lib/functions/network.sh
  4. . /lib/mwan3/mwan3.sh
  5. config_load mwan3
  6. config_get enabled $INTERFACE enabled 0
  7. [ "$enabled" == "1" ] || exit 0
  8. [ "$ACTION" == "ifup" -o "$ACTION" == "ifdown" ] || exit 1
  9. [ -n "$INTERFACE" ] || exit 2
  10. if [ "$ACTION" == "ifup" ]; then
  11. [ -n "$DEVICE" ] || exit 3
  12. fi
  13. [ -x /usr/bin/ip ] || exit 4
  14. [ -x /usr/sbin/ipset ] || exit 5
  15. [ -x /usr/sbin/iptables ] || exit 6
  16. [ -x /usr/sbin/ip6tables ] || exit 7
  17. [ -x /usr/bin/logger ] || exit 8
  18. config_get family $INTERFACE family ipv4
  19. if [ "$family" == "ipv4" ]; then
  20. network_get_gateway gateway $INTERFACE
  21. elif [ "$family" == "ipv6" ]; then
  22. network_get_gateway6 gateway $INTERFACE
  23. fi
  24. [ -n "$gateway" ] || exit 9
  25. $LOG notice "$ACTION interface $INTERFACE (${DEVICE:-unknown})"
  26. mwan3_set_connected_iptables
  27. case "$ACTION" in
  28. ifup)
  29. mwan3_set_general_rules
  30. mwan3_set_general_iptables
  31. mwan3_create_iface_rules $INTERFACE $DEVICE
  32. mwan3_create_iface_iptables $INTERFACE $DEVICE
  33. mwan3_create_iface_route $INTERFACE $DEVICE
  34. mwan3_track $INTERFACE $DEVICE
  35. mwan3_set_policies_iptables
  36. mwan3_set_user_rules
  37. ;;
  38. ifdown)
  39. mwan3_delete_iface_rules $INTERFACE
  40. mwan3_delete_iface_iptables $INTERFACE
  41. mwan3_delete_iface_route $INTERFACE
  42. mwan3_delete_iface_ipset_entries $INTERFACE
  43. mwan3_set_policies_iptables
  44. mwan3_set_user_rules
  45. ;;
  46. esac
  47. exit 0