2014-08-13 08:58:10 +02:00
|
|
|
#!/bin/sh
|
2011-04-23 02:31:54 +02:00
|
|
|
|
2015-01-29 01:10:34 +01:00
|
|
|
# setup-ip is potentially invoked before qubes-sysinit.sh is done, therefore
|
2015-10-15 04:34:55 +02:00
|
|
|
# we perform our qubesdb reads here instead of relying on qvm-service
|
2015-01-29 01:10:34 +01:00
|
|
|
# files under /var/run/qubes-service/
|
|
|
|
disablegw=`qubesdb-read /qubes-service/disable-default-route 2> /dev/null`
|
|
|
|
disabledns=`qubesdb-read /qubes-service/disable-dns-server 2> /dev/null`
|
|
|
|
|
2015-04-22 08:04:10 +02:00
|
|
|
# Location of files which contains list of protected files
|
2015-04-25 01:16:54 +02:00
|
|
|
PROTECTED_FILE_LIST='/etc/qubes/protected-files.d'
|
2015-04-22 08:04:10 +02:00
|
|
|
|
2013-06-07 05:20:55 +02:00
|
|
|
ip=`/usr/bin/qubesdb-read /qubes-ip 2> /dev/null`
|
2011-04-23 02:31:54 +02:00
|
|
|
if [ x$ip != x ]; then
|
2013-06-07 05:20:55 +02:00
|
|
|
netmask=`/usr/bin/qubesdb-read /qubes-netmask`
|
|
|
|
gateway=`/usr/bin/qubesdb-read /qubes-gateway`
|
|
|
|
secondary_dns=`/usr/bin/qubesdb-read /qubes-secondary-dns`
|
2011-04-23 02:32:54 +02:00
|
|
|
/sbin/ifconfig $INTERFACE $ip netmask 255.255.255.255
|
|
|
|
/sbin/ifconfig $INTERFACE up
|
2014-08-13 08:58:10 +02:00
|
|
|
/sbin/route add -host $gateway dev $INTERFACE
|
2015-01-29 01:10:34 +01:00
|
|
|
if [ "x$disablegw" != "x1" ]; then
|
2015-01-27 00:27:08 +01:00
|
|
|
/sbin/route add default gw $gateway
|
|
|
|
fi
|
2011-08-02 19:27:45 +02:00
|
|
|
/sbin/ethtool -K $INTERFACE sg off
|
2013-01-08 03:03:44 +01:00
|
|
|
/sbin/ethtool -K $INTERFACE tx off
|
2015-04-25 01:16:54 +02:00
|
|
|
if ! grep -rq "^/etc/resolv[.]conf$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
|
2015-04-22 08:04:10 +02:00
|
|
|
echo > /etc/resolv.conf
|
|
|
|
if [ "x$disabledns" != "x1" ]; then
|
|
|
|
echo "nameserver $gateway" > /etc/resolv.conf
|
|
|
|
echo "nameserver $secondary_dns" >> /etc/resolv.conf
|
|
|
|
fi
|
2015-01-27 00:27:08 +01:00
|
|
|
fi
|
2014-05-22 01:36:15 +02:00
|
|
|
if [ -f /var/run/qubes-service/network-manager ]; then
|
2015-01-27 00:27:08 +01:00
|
|
|
nm_config=/etc/NetworkManager/system-connections/qubes-uplink-$INTERFACE
|
|
|
|
cat > $nm_config <<__EOF__
|
2015-10-06 15:15:26 +02:00
|
|
|
## This file is automatically generated by Qubes OS
|
|
|
|
## Changes in this file will be overriden by /usr/lib/qubes/setup-ip script.
|
|
|
|
|
2014-11-09 05:31:22 +01:00
|
|
|
[802-3-ethernet]
|
|
|
|
duplex=full
|
2015-01-27 00:27:08 +01:00
|
|
|
|
2014-12-22 00:03:37 +01:00
|
|
|
[ethernet]
|
|
|
|
mac-address=`ip l show dev $INTERFACE |grep link|awk '{print $2}'`
|
2014-11-09 05:31:22 +01:00
|
|
|
|
|
|
|
[connection]
|
|
|
|
id=VM uplink $INTERFACE
|
|
|
|
uuid=de85f79b-8c3d-405f-a652-cb4c10b4f9ef
|
|
|
|
type=802-3-ethernet
|
|
|
|
|
|
|
|
[ipv6]
|
|
|
|
method=ignore
|
|
|
|
|
|
|
|
[ipv4]
|
|
|
|
method=manual
|
|
|
|
may-fail=false
|
2014-05-22 01:36:15 +02:00
|
|
|
__EOF__
|
2015-01-29 01:10:34 +01:00
|
|
|
if [ "x$disabledns" != "x1" ]; then
|
2015-01-27 00:27:08 +01:00
|
|
|
echo "dns=$gateway;$secondary_dns" >> $nm_config
|
|
|
|
fi
|
2015-01-29 01:10:34 +01:00
|
|
|
if [ "x$disablegw" != "x1" ]; then
|
2015-10-06 15:29:30 +02:00
|
|
|
echo "addresses1=$ip;32;$gateway" >> $nm_config
|
2015-01-27 00:27:08 +01:00
|
|
|
else
|
2015-10-06 15:29:30 +02:00
|
|
|
echo "addresses1=$ip;32" >> $nm_config
|
2015-01-27 00:27:08 +01:00
|
|
|
fi
|
|
|
|
chmod 600 $nm_config
|
2014-05-22 01:36:15 +02:00
|
|
|
fi
|
2014-12-22 00:04:16 +01:00
|
|
|
network=$(qubesdb-read /qubes-netvm-network 2>/dev/null)
|
2015-01-29 01:10:34 +01:00
|
|
|
if [ "x$network" != "x" ] && [ "x$disabledns" != "x1" ]; then
|
2014-12-22 00:04:16 +01:00
|
|
|
gateway=$(qubesdb-read /qubes-netvm-gateway)
|
|
|
|
netmask=$(qubesdb-read /qubes-netvm-netmask)
|
|
|
|
secondary_dns=$(qubesdb-read /qubes-netvm-secondary-dns)
|
|
|
|
echo "NS1=$gateway" > /var/run/qubes/qubes-ns
|
|
|
|
echo "NS2=$secondary_dns" >> /var/run/qubes/qubes-ns
|
|
|
|
/usr/lib/qubes/qubes-setup-dnat-to-ns
|
2015-01-27 00:27:08 +01:00
|
|
|
fi
|
|
|
|
if [ "x$network" != "x" ]; then
|
2014-12-22 00:04:16 +01:00
|
|
|
[ -x /rw/config/qubes-ip-change-hook ] && /rw/config/qubes-ip-change-hook
|
|
|
|
# XXX: Backward compatibility
|
|
|
|
[ -x /rw/config/qubes_ip_change_hook ] && /rw/config/qubes_ip_change_hook
|
|
|
|
fi
|
2011-04-23 02:31:54 +02:00
|
|
|
fi
|