qubes_netwatcher 953 B

12345678910111213141516171819202122232425262728293031
  1. #!/bin/bash
  2. set -e
  3. PIDFILE=/var/run/qubes/qubes_netwatcher.pid
  4. CURR_NETCFG=""
  5. # PIDfile handling
  6. [[ -e $PIDFILE ]] && kill -s 0 $(<$PIDFILE) 2>/dev/null && exit 0
  7. echo $$ >$PIDFILE
  8. trap 'exit 0' SIGTERM
  9. while true; do
  10. NET_DOMID=$(/usr/bin/xenstore-read qubes_netvm_domid)
  11. if [[ -n "$NET_DOMID" ]] && [[ $NET_DOMID -gt 0 ]]; then
  12. UNTRUSTED_NETCFG=$(/usr/bin/xenstore-read /local/domain/$NET_DOMID/qubes_netvm_external_ip || :)
  13. # UNTRUSTED_NETCFG is not parsed in any way
  14. # thus, no sanitization ready
  15. # but be careful when passing it to other shell scripts
  16. if [[ "$UNTRUSTED_NETCFG" != "$CURR_NETCFG" ]]; then
  17. /sbin/service qubes_firewall stop
  18. /sbin/service qubes_firewall start
  19. CURR_NETCFG="$UNTRUSTED_NETCFG"
  20. /usr/bin/xenstore-write qubes_netvm_external_ip "$CURR_NETCFG"
  21. fi
  22. /usr/bin/xenstore-watch-qubes /local/domain/$NET_DOMID/qubes_netvm_external_ip
  23. else
  24. /usr/bin/xenstore-watch-qubes qubes_netvm_domid
  25. fi
  26. done