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.

62 lines
1.4 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. local family gateway
  19. config_get family $INTERFACE family ipv4
  20. if [ "$family" == "ipv4" ]; then
  21. network_get_gateway gateway $INTERFACE
  22. elif [ "$family" == "ipv6" ]; then
  23. network_get_gateway6 gateway $INTERFACE
  24. fi
  25. [ -n "$gateway" ] || exit 9
  26. $LOG notice "$ACTION interface $INTERFACE (${DEVICE:-unknown})"
  27. mwan3_set_connected_iptables
  28. case "$ACTION" in
  29. ifup)
  30. mwan3_set_general_rules
  31. mwan3_set_general_iptables
  32. mwan3_create_iface_rules $INTERFACE $DEVICE
  33. mwan3_create_iface_iptables $INTERFACE $DEVICE
  34. mwan3_create_iface_route $INTERFACE $DEVICE
  35. mwan3_track $INTERFACE $DEVICE
  36. mwan3_set_policies_iptables
  37. mwan3_set_user_rules
  38. ;;
  39. ifdown)
  40. mwan3_delete_iface_rules $INTERFACE
  41. mwan3_delete_iface_iptables $INTERFACE
  42. mwan3_delete_iface_route $INTERFACE
  43. mwan3_delete_iface_ipset_entries $INTERFACE
  44. mwan3_set_policies_iptables
  45. mwan3_set_user_rules
  46. ;;
  47. esac
  48. exit 0