15-mwan3 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. [ -x /usr/bin/ip ] || exit 4
  11. [ -x /usr/sbin/ipset ] || exit 5
  12. [ -x /usr/sbin/iptables ] || exit 6
  13. [ -x /usr/sbin/ip6tables ] || exit 7
  14. [ -x /usr/bin/logger ] || exit 8
  15. mwan3_lock
  16. mwan3_set_connected_iptables
  17. mwan3_unlock
  18. config_load mwan3
  19. config_get enabled $INTERFACE enabled 0
  20. [ "$enabled" == "1" ] || exit 0
  21. config_get family $INTERFACE family ipv4
  22. if [ "$family" == "ipv4" ]; then
  23. network_get_gateway gateway $INTERFACE
  24. elif [ "$family" == "ipv6" ]; then
  25. network_get_gateway6 gateway $INTERFACE
  26. fi
  27. if [ "$ACTION" == "ifup" ]; then
  28. [ -n "$gateway" ] || exit 9
  29. fi
  30. mwan3_lock
  31. $LOG notice "$ACTION interface $INTERFACE (${DEVICE:-unknown})"
  32. case "$ACTION" in
  33. ifup)
  34. mwan3_set_general_rules
  35. mwan3_set_general_iptables
  36. mwan3_create_iface_rules $INTERFACE $DEVICE
  37. mwan3_create_iface_iptables $INTERFACE $DEVICE
  38. mwan3_create_iface_route $INTERFACE $DEVICE
  39. mwan3_set_iface_hotplug_state $INTERFACE "online"
  40. mwan3_track $INTERFACE $DEVICE
  41. mwan3_set_policies_iptables
  42. mwan3_set_user_rules
  43. ;;
  44. ifdown)
  45. mwan3_set_iface_hotplug_state $INTERFACE "offline"
  46. mwan3_delete_iface_ipset_entries $INTERFACE
  47. mwan3_set_policies_iptables
  48. mwan3_set_user_rules
  49. ;;
  50. esac
  51. mwan3_unlock
  52. exit 0