network: support for not setting DNS and/or default gateway (v2)

This patch introduces two new qvm-services:
 - disable-default-route
 - disable-dns-server
Both disabled by default. You can enable any of them to not set default
route and/or DNS servers in the VM. Those settings have no effect on
NetVM, where such settings are controlled by NetworkManager.

This is based on patch sent by Joonas Lehtonen
<joonas.lehtonen@openmailbox.org>
https://groups.google.com/d/msgid/qubes-devel/54C7FB59.2020603%40openmailbox.org

Conflicts:
	network/setup-ip
	vm-init.d/qubes-core
	vm-systemd/qubes-sysinit.sh
This commit is contained in:
Marek Marczykowski-Górecki 2015-01-29 01:10:34 +01:00
parent 9f51c82666
commit 19a4c6d0dd
3 changed files with 15 additions and 12 deletions

View File

@ -1,5 +1,11 @@
#!/bin/sh #!/bin/sh
# setup-ip is potentially invoked before qubes-sysinit.sh is done, therefore
# we perform our qubesdb reads here instead of relying on qvm-service
# 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`
ip=`/usr/bin/qubesdb-read /qubes-ip 2> /dev/null` ip=`/usr/bin/qubesdb-read /qubes-ip 2> /dev/null`
if [ x$ip != x ]; then if [ x$ip != x ]; then
netmask=`/usr/bin/qubesdb-read /qubes-netmask` netmask=`/usr/bin/qubesdb-read /qubes-netmask`
@ -8,13 +14,13 @@ if [ x$ip != x ]; then
/sbin/ifconfig $INTERFACE $ip netmask 255.255.255.255 /sbin/ifconfig $INTERFACE $ip netmask 255.255.255.255
/sbin/ifconfig $INTERFACE up /sbin/ifconfig $INTERFACE up
/sbin/route add -host $gateway dev $INTERFACE /sbin/route add -host $gateway dev $INTERFACE
if [ -f /var/run/qubes-service/set-default-route ]; then if [ "x$disablegw" != "x1" ]; then
/sbin/route add default gw $gateway /sbin/route add default gw $gateway
fi fi
/sbin/ethtool -K $INTERFACE sg off /sbin/ethtool -K $INTERFACE sg off
/sbin/ethtool -K $INTERFACE tx off /sbin/ethtool -K $INTERFACE tx off
echo > /etc/resolv.conf echo > /etc/resolv.conf
if [ -f /var/run/qubes-service/set-dns-server ]; then if [ "x$disabledns" != "x1" ]; then
echo "nameserver $gateway" > /etc/resolv.conf echo "nameserver $gateway" > /etc/resolv.conf
echo "nameserver $secondary_dns" >> /etc/resolv.conf echo "nameserver $secondary_dns" >> /etc/resolv.conf
fi fi
@ -39,10 +45,10 @@ method=ignore
method=manual method=manual
may-fail=false may-fail=false
__EOF__ __EOF__
if [ -f /var/run/qubes-service/set-dns-server ]; then if [ "x$disabledns" != "x1" ]; then
echo "dns=$gateway;$secondary_dns" >> $nm_config echo "dns=$gateway;$secondary_dns" >> $nm_config
fi fi
if [ -f /var/run/qubes-service/set-default-route ]; then if [ "x$disablegw" != "x1" ]; then
echo "address1=$ip/32,$gateway" >> $nm_config echo "address1=$ip/32,$gateway" >> $nm_config
else else
echo "address1=$ip/32" >> $nm_config echo "address1=$ip/32" >> $nm_config
@ -50,7 +56,7 @@ __EOF__
chmod 600 $nm_config chmod 600 $nm_config
fi fi
network=$(qubesdb-read /qubes-netvm-network 2>/dev/null) network=$(qubesdb-read /qubes-netvm-network 2>/dev/null)
if [ "x$network" != "x" ] && [ -f /var/run/qubes-service/set-dns-server ]; then if [ "x$network" != "x" ] && [ "x$disabledns" != "x1" ]; then
gateway=$(qubesdb-read /qubes-netvm-gateway) gateway=$(qubesdb-read /qubes-netvm-gateway)
netmask=$(qubesdb-read /qubes-netvm-netmask) netmask=$(qubesdb-read /qubes-netvm-netmask)
secondary_dns=$(qubesdb-read /qubes-netvm-secondary-dns) secondary_dns=$(qubesdb-read /qubes-netvm-secondary-dns)

View File

@ -33,8 +33,6 @@ start()
echo "ZONE=\"$timezone\"" >> /etc/sysconfig/clock echo "ZONE=\"$timezone\"" >> /etc/sysconfig/clock
fi fi
touch /var/run/qubes-service/set-default-route
touch /var/run/qubes-service/set-dns-server
yum_proxy_setup=$(/usr/bin/qubesdb-read /qubes-service/yum-proxy-setup 2> /dev/null || /usr/bin/qubesdb-read /qubes-service/updates-proxy-setup 2> /dev/null) yum_proxy_setup=$(/usr/bin/qubesdb-read /qubes-service/yum-proxy-setup 2> /dev/null || /usr/bin/qubesdb-read /qubes-service/updates-proxy-setup 2> /dev/null)
type=$(/usr/bin/qubesdb-read /qubes-vm-type) type=$(/usr/bin/qubesdb-read /qubes-vm-type)
if [ "$yum_proxy_setup" != "0" ] || [ -z "$yum_proxy_setup" -a "$type" == "TemplateVM" ]; then if [ "$yum_proxy_setup" != "0" ] || [ -z "$yum_proxy_setup" -a "$type" == "TemplateVM" ]; then

View File

@ -1,12 +1,11 @@
#!/bin/bash #!/bin/bash
# List of services enabled by default (in case of absence of qubesdb entry) # List of services enabled by default (in case of absence of qubesdb entry)
DEFAULT_ENABLED_ALL="set-default-route set-dns-server" DEFAULT_ENABLED_NETVM="network-manager qubes-network qubes-update-check qubes-updates-proxy"
DEFAULT_ENABLED_NETVM="$DEFAULT_ENABLED_ALL network-manager qubes-network qubes-update-check qubes-updates-proxy" DEFAULT_ENABLED_PROXYVM="meminfo-writer qubes-network qubes-firewall qubes-netwatcher qubes-update-check"
DEFAULT_ENABLED_PROXYVM="$DEFAULT_ENABLED_ALL meminfo-writer qubes-network qubes-firewall qubes-netwatcher qubes-update-check" DEFAULT_ENABLED_APPVM="meminfo-writer cups qubes-update-check"
DEFAULT_ENABLED_APPVM="$DEFAULT_ENABLED_ALL meminfo-writer cups qubes-update-check"
DEFAULT_ENABLED_TEMPLATEVM="$DEFAULT_ENABLED_APPVM updates-proxy-setup" DEFAULT_ENABLED_TEMPLATEVM="$DEFAULT_ENABLED_APPVM updates-proxy-setup"
DEFAULT_ENABLED="$DEFAULT_ENABLED_ALL meminfo-writer" DEFAULT_ENABLED="meminfo-writer"
QDB_READ=qubesdb-read QDB_READ=qubesdb-read
QDB_LS=qubesdb-multiread QDB_LS=qubesdb-multiread