setup-ip 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. primary_dns=`/usr/bin/qubesdb-read /qubes-primary-dns 2>/dev/null || echo $gateway`
  14. secondary_dns=`/usr/bin/qubesdb-read /qubes-secondary-dns`
  15. /sbin/ethtool -K $INTERFACE sg off
  16. /sbin/ethtool -K $INTERFACE tx off
  17. # If NetworkManager is enabled, let it configure the network
  18. if [ -f /var/run/qubes-service/network-manager ]; then
  19. nm_config=/etc/NetworkManager/system-connections/qubes-uplink-$INTERFACE
  20. cat > $nm_config <<__EOF__
  21. [802-3-ethernet]
  22. duplex=full
  23. [ethernet]
  24. mac-address=`ip l show dev $INTERFACE |grep link|awk '{print $2}'`
  25. [connection]
  26. id=VM uplink $INTERFACE
  27. uuid=de85f79b-8c3d-405f-a652-cb4c10b4f9ef
  28. type=802-3-ethernet
  29. [ipv6]
  30. method=ignore
  31. [ipv4]
  32. method=manual
  33. may-fail=false
  34. __EOF__
  35. if [ "x$disabledns" != "x1" ]; then
  36. echo "dns=$primary_dns;$secondary_dns" >> $nm_config
  37. fi
  38. if [ "x$disablegw" != "x1" ]; then
  39. echo "addresses1=$ip;32;$gateway" >> $nm_config
  40. else
  41. echo "addresses1=$ip;32" >> $nm_config
  42. fi
  43. chmod 600 $nm_config
  44. # reload connection
  45. nmcli connection load $nm_config || :
  46. else
  47. # No NetworkManager enabled, configure the network manually
  48. /sbin/ifconfig $INTERFACE $ip netmask 255.255.255.255
  49. /sbin/ifconfig $INTERFACE up
  50. /sbin/route add -host $gateway dev $INTERFACE
  51. if [ "x$disablegw" != "x1" ]; then
  52. /sbin/route add default gw $gateway
  53. fi
  54. if ! grep -rq "^/etc/resolv[.]conf$" "${PROTECTED_FILE_LIST}" 2>/dev/null; then
  55. echo > /etc/resolv.conf
  56. if [ "x$disabledns" != "x1" ]; then
  57. echo "nameserver $primary_dns" > /etc/resolv.conf
  58. echo "nameserver $secondary_dns" >> /etc/resolv.conf
  59. fi
  60. fi
  61. fi
  62. network=$(qubesdb-read /qubes-netvm-network 2>/dev/null)
  63. if [ "x$network" != "x" ] && [ "x$disabledns" != "x1" ]; then
  64. gateway=$(qubesdb-read /qubes-netvm-gateway)
  65. netmask=$(qubesdb-read /qubes-netvm-netmask)
  66. primary_dns=$(qubesdb-read /qubes-netvm-primary-dns 2>/dev/null || echo $gateway)
  67. secondary_dns=$(qubesdb-read /qubes-netvm-secondary-dns)
  68. echo "NS1=$primary_dns" > /var/run/qubes/qubes-ns
  69. echo "NS2=$secondary_dns" >> /var/run/qubes/qubes-ns
  70. /usr/lib/qubes/qubes-setup-dnat-to-ns
  71. fi
  72. if [ "x$network" != "x" ]; then
  73. [ -x /rw/config/qubes-ip-change-hook ] && /rw/config/qubes-ip-change-hook
  74. # XXX: Backward compatibility
  75. [ -x /rw/config/qubes_ip_change_hook ] && /rw/config/qubes_ip_change_hook
  76. fi
  77. fi