2015-02-05 03:14:41 +01:00
|
|
|
#!/bin/sh
|
2011-03-11 19:39:52 +01:00
|
|
|
set -e
|
|
|
|
|
2013-03-13 02:26:40 +01:00
|
|
|
PIDFILE=/var/run/qubes/qubes-netwatcher.pid
|
2011-03-11 19:39:52 +01:00
|
|
|
CURR_NETCFG=""
|
|
|
|
|
|
|
|
# PIDfile handling
|
2015-02-05 03:14:41 +01:00
|
|
|
[ -e "$PIDFILE" ] && kill -s 0 $(cat "$PIDFILE") 2>/dev/null && exit 0
|
2011-03-11 19:39:52 +01:00
|
|
|
echo $$ >$PIDFILE
|
|
|
|
|
2015-02-05 03:14:41 +01:00
|
|
|
trap 'exit 0' TERM
|
2011-03-11 19:39:52 +01:00
|
|
|
|
|
|
|
while true; do
|
2014-09-26 19:56:12 +02:00
|
|
|
NET_DOMID=$(xenstore-read qubes-netvm-domid || :)
|
2015-02-05 03:14:41 +01:00
|
|
|
if [ -n "$NET_DOMID" ] && [ $NET_DOMID -gt 0 ]; then
|
2014-09-26 19:56:12 +02:00
|
|
|
UNTRUSTED_NETCFG=$(xenstore-read /local/domain/$NET_DOMID/qubes-netvm-external-ip || :)
|
2011-05-09 16:23:52 +02:00
|
|
|
# UNTRUSTED_NETCFG is not parsed in any way
|
2011-05-09 16:26:48 +02:00
|
|
|
# thus, no sanitization ready
|
|
|
|
# but be careful when passing it to other shell scripts
|
2015-02-05 03:14:41 +01:00
|
|
|
if [ "$UNTRUSTED_NETCFG" != "$CURR_NETCFG" ]; then
|
2012-03-09 00:21:39 +01:00
|
|
|
/sbin/service qubes-firewall stop
|
|
|
|
/sbin/service qubes-firewall start
|
2011-05-09 16:23:52 +02:00
|
|
|
CURR_NETCFG="$UNTRUSTED_NETCFG"
|
2014-09-26 19:56:12 +02:00
|
|
|
xenstore-write qubes-netvm-external-ip "$CURR_NETCFG"
|
2011-03-11 19:39:52 +01:00
|
|
|
fi
|
|
|
|
|
2014-09-26 19:56:12 +02:00
|
|
|
xenstore-watch -n 3 /local/domain/$NET_DOMID/qubes-netvm-external-ip qubes-netvm-domid
|
2011-03-11 19:39:52 +01:00
|
|
|
else
|
2014-09-26 19:56:12 +02:00
|
|
|
xenstore-watch -n 2 qubes-netvm-domid
|
2011-03-11 19:39:52 +01:00
|
|
|
fi
|
|
|
|
done
|