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.

48 lines
1.0 KiB

  1. #!/bin/sh
  2. . /lib/functions.sh
  3. . /lib/mwan3/mwan3.sh
  4. . /lib/functions/network.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. config_load mwan3
  11. config_get_bool enabled globals 'enabled' '0'
  12. [ ${enabled} -gt 0 ] || exit 0
  13. config_get local_source globals local_source 'none'
  14. [ "${local_source}" = "none" ] && {
  15. exit 0
  16. }
  17. [ "${local_source}" = "$INTERFACE" ] || {
  18. exit 0
  19. }
  20. mwan3_lock
  21. src_ip=$(uci_get_state mwan3 globals src_ip)
  22. [ "${src_ip}" != "" ] && {
  23. ip route del default via "${src_ip}" dev lo 1>/dev/null 2>&1
  24. ip addr del "${src_ip}/32" dev lo 1>/dev/null 2>&1
  25. }
  26. sleep 1
  27. [ "$ACTION" = "ifup" ] && {
  28. network_get_ipaddr src_ip "${local_source}"
  29. if [ "${src_ip}" = "" ]; then
  30. $LOG warn "Unable to set source ip for own initiated traffic (${local_source})"
  31. else
  32. ip addr add "${src_ip}/32" dev lo
  33. ip route add default via "${src_ip}" dev lo
  34. uci_toggle_state mwan3 globals src_ip "${src_ip}"
  35. fi
  36. }
  37. mwan3_unlock
  38. exit 0