2014-08-13 08:58:10 +02:00
|
|
|
#!/bin/sh
|
2011-04-23 02:31:54 +02:00
|
|
|
|
2016-10-22 17:43:16 +02:00
|
|
|
# Source Qubes library.
|
2017-09-30 03:17:14 +02:00
|
|
|
# shellcheck disable=SC1091
|
2016-10-22 17:43:16 +02:00
|
|
|
. /usr/lib/qubes/init/functions
|
2015-01-29 01:10:34 +01:00
|
|
|
|
2016-10-22 17:43:16 +02:00
|
|
|
have_qubesdb || exit 0
|
2015-04-22 08:04:10 +02:00
|
|
|
|
2017-09-30 03:17:14 +02:00
|
|
|
ip=$(/usr/bin/qubesdb-read /qubes-ip 2> /dev/null)
|
|
|
|
if [ "x$ip" != x ]; then
|
|
|
|
#netmask=$(/usr/bin/qubesdb-read /qubes-netmask)
|
|
|
|
gateway=$(/usr/bin/qubesdb-read /qubes-gateway)
|
|
|
|
primary_dns=$(/usr/bin/qubesdb-read /qubes-primary-dns 2>/dev/null || echo "$gateway")
|
|
|
|
secondary_dns=$(/usr/bin/qubesdb-read /qubes-secondary-dns)
|
|
|
|
/sbin/ethtool -K "$INTERFACE" sg off
|
|
|
|
/sbin/ethtool -K "$INTERFACE" tx off
|
2015-11-13 04:26:23 +01:00
|
|
|
# If NetworkManager is enabled, let it configure the network
|
2016-10-22 17:43:16 +02:00
|
|
|
if qsvc network-manager ; then
|
2015-01-27 00:27:08 +01:00
|
|
|
nm_config=/etc/NetworkManager/system-connections/qubes-uplink-$INTERFACE
|
2017-09-30 03:17:14 +02:00
|
|
|
cat > "$nm_config" <<__EOF__
|
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]
|
2017-09-30 03:17:14 +02:00
|
|
|
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__
|
2016-10-22 17:43:16 +02:00
|
|
|
if ! qsvc disable-dns-server ; then
|
2017-09-30 03:17:14 +02:00
|
|
|
echo "dns=$primary_dns;$secondary_dns" >> "$nm_config"
|
2015-01-27 00:27:08 +01:00
|
|
|
fi
|
2016-10-22 17:43:16 +02:00
|
|
|
if ! qsvc disable-default-route ; then
|
2017-09-30 03:17:14 +02:00
|
|
|
echo "addresses1=$ip;32;$gateway" >> "$nm_config"
|
2015-01-27 00:27:08 +01:00
|
|
|
else
|
2017-09-30 03:17:14 +02:00
|
|
|
echo "addresses1=$ip;32" >> "$nm_config"
|
2015-01-27 00:27:08 +01:00
|
|
|
fi
|
2017-09-30 03:17:14 +02:00
|
|
|
chmod 600 "$nm_config"
|
2016-08-02 02:08:36 +02:00
|
|
|
# reload connection
|
2017-09-30 03:17:14 +02:00
|
|
|
nmcli connection load "$nm_config" || :
|
2015-11-13 04:26:23 +01:00
|
|
|
else
|
|
|
|
# No NetworkManager enabled, configure the network manually
|
2017-09-30 03:17:14 +02:00
|
|
|
/sbin/ifconfig "$INTERFACE" "$ip" netmask 255.255.255.255
|
|
|
|
/sbin/ifconfig "$INTERFACE" up
|
|
|
|
/sbin/route add -host "$gateway" dev "$INTERFACE"
|
2016-12-31 21:50:29 +01:00
|
|
|
if ! qsvc disable-default-route ; then
|
2017-09-30 03:17:14 +02:00
|
|
|
/sbin/route add default gw "$gateway"
|
2015-11-13 04:26:23 +01:00
|
|
|
fi
|
2016-10-22 17:43:16 +02:00
|
|
|
if ! is_protected_file /etc/resolv.conf ; then
|
2016-05-19 21:12:16 +02:00
|
|
|
echo > /etc/resolv.conf
|
2016-12-31 21:50:29 +01:00
|
|
|
if ! qsvc disable-dns-server ; then
|
2016-03-07 13:37:45 +01:00
|
|
|
echo "nameserver $primary_dns" > /etc/resolv.conf
|
2015-11-13 04:26:23 +01:00
|
|
|
echo "nameserver $secondary_dns" >> /etc/resolv.conf
|
|
|
|
fi
|
|
|
|
fi
|
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)
|
2016-12-31 21:50:29 +01:00
|
|
|
if [ "x$network" != "x" ] && ! qsvc disable-dns-server ; then
|
2014-12-22 00:04:16 +01:00
|
|
|
gateway=$(qubesdb-read /qubes-netvm-gateway)
|
2017-09-30 03:17:14 +02:00
|
|
|
#netmask=$(qubesdb-read /qubes-netvm-netmask)
|
|
|
|
primary_dns=$(qubesdb-read /qubes-netvm-primary-dns 2>/dev/null || echo "$gateway")
|
2014-12-22 00:04:16 +01:00
|
|
|
secondary_dns=$(qubesdb-read /qubes-netvm-secondary-dns)
|
2016-03-07 13:37:45 +01:00
|
|
|
echo "NS1=$primary_dns" > /var/run/qubes/qubes-ns
|
2014-12-22 00:04:16 +01:00
|
|
|
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
|
2016-09-19 01:04:25 +02:00
|
|
|
if [ -x /rw/config/qubes-ip-change-hook ]; then
|
|
|
|
/rw/config/qubes-ip-change-hook
|
|
|
|
fi
|
2014-12-22 00:04:16 +01:00
|
|
|
# XXX: Backward compatibility
|
2016-09-19 01:04:25 +02:00
|
|
|
if [ -x /rw/config/qubes_ip_change_hook ]; then
|
|
|
|
/rw/config/qubes_ip_change_hook
|
|
|
|
fi
|
2014-12-22 00:04:16 +01:00
|
|
|
fi
|
2011-04-23 02:31:54 +02:00
|
|
|
fi
|