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.

45 lines
971 B

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