6in4.hotplug 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/bin/sh
  2. if [ "$ACTION" = ifup ]; then
  3. . /etc/functions.sh
  4. include /lib/network
  5. scan_interfaces
  6. update_tunnel() {
  7. local cfg="$1"
  8. local proto
  9. config_get proto "$cfg" proto
  10. [ "$proto" = 6in4 ] || return 0
  11. local wandev
  12. config_get wandev "$cfg" wan_device "$(find_6in4_wanif)"
  13. [ "$wandev" = "$DEVICE" ] || return 0
  14. local oldip
  15. local wanip=$(find_6in4_wanip "$wandev")
  16. config_get oldip "$cfg" ipaddr
  17. [ -n "$wanip" ] && [ "$oldip" != "$wanip" ] && {
  18. local tunnelid
  19. config_get tunnelid "$cfg" tunnelid
  20. local username
  21. config_get username "$cfg" username
  22. local password
  23. config_get password "$cfg" password
  24. [ -n "$tunnelid" ] && [ -n "$username" ] && [ -n "$password" ] && {
  25. [ "${#password}" == 32 -a -z "${password//[a-f0-9]/}" ] || {
  26. password="$(echo -n "$password" | md5sum)"; password="${password%% *}"
  27. }
  28. uci_set_state network "$cfg" ipaddr "$wanip"
  29. ( wget -qO/dev/null "http://ipv4.tunnelbroker.net/ipv4_end.php?ipv4b=AUTO&user_id=$username&pass=$password&tunnel_id=$tunnelid" && ifup "$cfg" )&
  30. }
  31. }
  32. }
  33. config_foreach update_tunnel interface
  34. fi