123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- #!/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`
- # Location of files which contains list of protected files
- PROTECTED_FILE_LIST='/etc/qubes/protected-files.d'
- 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
- # If NetworkManager is enabled, let it configure the network
- if [ -f /var/run/qubes-service/network-manager ]; then
- nm_config=/etc/NetworkManager/system-connections/qubes-uplink-$INTERFACE
- cat > $nm_config <<__EOF__
- [802-3-ethernet]
- duplex=full
- [ethernet]
- mac-address=`ip l show dev $INTERFACE |grep link|awk '{print $2}'`
- [connection]
- id=VM uplink $INTERFACE
- uuid=de85f79b-8c3d-405f-a652-cb4c10b4f9ef
- type=802-3-ethernet
- [ipv6]
- method=ignore
- [ipv4]
- method=manual
- may-fail=false
- __EOF__
- if [ "x$disabledns" != "x1" ]; then
- echo "dns=$primary_dns;$secondary_dns" >> $nm_config
- fi
- if [ "x$disablegw" != "x1" ]; then
- echo "addresses1=$ip;32;$gateway" >> $nm_config
- else
- echo "addresses1=$ip;32" >> $nm_config
- fi
- chmod 600 $nm_config
- # reload connection
- nmcli connection load $nm_config || :
- else
- # No NetworkManager enabled, configure the network manually
- /sbin/ifconfig $INTERFACE $ip netmask 255.255.255.255
- /sbin/ifconfig $INTERFACE up
- /sbin/route add -host $gateway dev $INTERFACE
- if [ "x$disablegw" != "x1" ]; then
- /sbin/route add default gw $gateway
- fi
- if ! grep -rq "^/etc/resolv[.]conf$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
- echo > /etc/resolv.conf
- if [ "x$disabledns" != "x1" ]; then
- echo "nameserver $primary_dns" > /etc/resolv.conf
- echo "nameserver $secondary_dns" >> /etc/resolv.conf
- fi
- fi
- fi
- network=$(qubesdb-read /qubes-netvm-network 2>/dev/null)
- if [ "x$network" != "x" ] && [ "x$disabledns" != "x1" ]; then
- gateway=$(qubesdb-read /qubes-netvm-gateway)
- netmask=$(qubesdb-read /qubes-netvm-netmask)
- primary_dns=$(qubesdb-read /qubes-netvm-primary-dns 2>/dev/null || echo $gateway)
- secondary_dns=$(qubesdb-read /qubes-netvm-secondary-dns)
- echo "NS1=$primary_dns" > /var/run/qubes/qubes-ns
- echo "NS2=$secondary_dns" >> /var/run/qubes/qubes-ns
- /usr/lib/qubes/qubes-setup-dnat-to-ns
- fi
- if [ "x$network" != "x" ]; then
- [ -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
- fi
|