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.

73 lines
1.8 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. if [ "$ACTION" == "ifup" ]; then
  19. config_get family $INTERFACE family ipv4
  20. if [ "$family" = "ipv4" ]; then
  21. ubus call network.interface.${INTERFACE}_4 status &>/dev/null
  22. if [ "$?" -eq "0" ]; then
  23. network_get_gateway gateway ${INTERFACE}_4
  24. else
  25. network_get_gateway gateway $INTERFACE
  26. fi
  27. elif [ "$family" = "ipv6" ]; then
  28. ubus call network.interface.${INTERFACE}_6 status &>/dev/null
  29. if [ "$?" -eq "0" ]; then
  30. network_get_gateway6 gateway ${INTERFACE}_6
  31. else
  32. network_get_gateway6 gateway ${INTERFACE}
  33. fi
  34. fi
  35. [ -n "$gateway" ] || exit 9
  36. fi
  37. $LOG notice "$ACTION interface $INTERFACE (${DEVICE:-unknown})"
  38. mwan3_set_connected_iptables
  39. case "$ACTION" in
  40. ifup)
  41. mwan3_set_general_rules
  42. mwan3_set_general_iptables
  43. mwan3_create_iface_rules $INTERFACE $DEVICE
  44. mwan3_create_iface_iptables $INTERFACE $DEVICE
  45. mwan3_create_iface_route $INTERFACE $DEVICE
  46. mwan3_track $INTERFACE $DEVICE
  47. mwan3_set_policies_iptables
  48. mwan3_set_user_rules
  49. mwan3_flush_conntrack $INTERFACE $DEVICE "ifup"
  50. ;;
  51. ifdown)
  52. mwan3_delete_iface_rules $INTERFACE
  53. mwan3_delete_iface_iptables $INTERFACE
  54. mwan3_delete_iface_route $INTERFACE
  55. mwan3_delete_iface_ipset_entries $INTERFACE
  56. mwan3_set_policies_iptables
  57. mwan3_set_user_rules
  58. mwan3_flush_conntrack $INTERFACE $DEVICE "ifdown"
  59. ;;
  60. esac
  61. exit 0