setup-ip 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/sh
  2. # setup-ip is potentially invoked before qubes-sysinit.sh is done, therefore
  3. # we perform our qubesdb reads here instead of relying on qvm-service
  4. # files under /var/run/qubes-service/
  5. disablegw=`qubesdb-read /qubes-service/disable-default-route 2> /dev/null`
  6. disabledns=`qubesdb-read /qubes-service/disable-dns-server 2> /dev/null`
  7. # Location of files which contains list of protected files
  8. PROTECTED_FILE_LIST='/etc/qubes/protected-files.d'
  9. ip=`/usr/bin/qubesdb-read /qubes-ip 2> /dev/null`
  10. if [ x$ip != x ]; then
  11. netmask=`/usr/bin/qubesdb-read /qubes-netmask`
  12. gateway=`/usr/bin/qubesdb-read /qubes-gateway`
  13. secondary_dns=`/usr/bin/qubesdb-read /qubes-secondary-dns`
  14. /sbin/ifconfig $INTERFACE $ip netmask 255.255.255.255
  15. /sbin/ifconfig $INTERFACE up
  16. /sbin/route add -host $gateway dev $INTERFACE
  17. if [ "x$disablegw" != "x1" ]; then
  18. /sbin/route add default gw $gateway
  19. fi
  20. /sbin/ethtool -K $INTERFACE sg off
  21. /sbin/ethtool -K $INTERFACE tx off
  22. if ! grep -rq "^/etc/resolv[.]conf$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
  23. echo > /etc/resolv.conf
  24. if [ "x$disabledns" != "x1" ]; then
  25. echo "nameserver $gateway" > /etc/resolv.conf
  26. echo "nameserver $secondary_dns" >> /etc/resolv.conf
  27. fi
  28. fi
  29. if [ -f /var/run/qubes-service/network-manager ]; then
  30. nm_config=/etc/NetworkManager/system-connections/qubes-uplink-$INTERFACE
  31. cat > $nm_config <<__EOF__
  32. ## This file is automatically generated by Qubes OS
  33. ## Changes in this file will be overriden by /usr/lib/qubes/setup-ip script.
  34. [802-3-ethernet]
  35. duplex=full
  36. [ethernet]
  37. mac-address=`ip l show dev $INTERFACE |grep link|awk '{print $2}'`
  38. [connection]
  39. id=VM uplink $INTERFACE
  40. uuid=de85f79b-8c3d-405f-a652-cb4c10b4f9ef
  41. type=802-3-ethernet
  42. [ipv6]
  43. method=ignore
  44. [ipv4]
  45. method=manual
  46. may-fail=false
  47. __EOF__
  48. if [ "x$disabledns" != "x1" ]; then
  49. echo "dns=$gateway;$secondary_dns" >> $nm_config
  50. fi
  51. if [ "x$disablegw" != "x1" ]; then
  52. echo "addresses1=$ip;32;$gateway" >> $nm_config
  53. else
  54. echo "addresses1=$ip;32" >> $nm_config
  55. fi
  56. chmod 600 $nm_config
  57. fi
  58. network=$(qubesdb-read /qubes-netvm-network 2>/dev/null)
  59. if [ "x$network" != "x" ] && [ "x$disabledns" != "x1" ]; then
  60. gateway=$(qubesdb-read /qubes-netvm-gateway)
  61. netmask=$(qubesdb-read /qubes-netvm-netmask)
  62. secondary_dns=$(qubesdb-read /qubes-netvm-secondary-dns)
  63. echo "NS1=$gateway" > /var/run/qubes/qubes-ns
  64. echo "NS2=$secondary_dns" >> /var/run/qubes/qubes-ns
  65. /usr/lib/qubes/qubes-setup-dnat-to-ns
  66. fi
  67. if [ "x$network" != "x" ]; then
  68. [ -x /rw/config/qubes-ip-change-hook ] && /rw/config/qubes-ip-change-hook
  69. # XXX: Backward compatibility
  70. [ -x /rw/config/qubes_ip_change_hook ] && /rw/config/qubes_ip_change_hook
  71. fi
  72. fi