setup-ip 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. [802-3-ethernet]
  33. duplex=full
  34. [ethernet]
  35. mac-address=`ip l show dev $INTERFACE |grep link|awk '{print $2}'`
  36. [connection]
  37. id=VM uplink $INTERFACE
  38. uuid=de85f79b-8c3d-405f-a652-cb4c10b4f9ef
  39. type=802-3-ethernet
  40. [ipv6]
  41. method=ignore
  42. [ipv4]
  43. method=manual
  44. may-fail=false
  45. __EOF__
  46. if [ "x$disabledns" != "x1" ]; then
  47. echo "dns=$gateway;$secondary_dns" >> $nm_config
  48. fi
  49. if [ "x$disablegw" != "x1" ]; then
  50. echo "address1=$ip/32,$gateway" >> $nm_config
  51. else
  52. echo "address1=$ip/32" >> $nm_config
  53. fi
  54. chmod 600 $nm_config
  55. fi
  56. network=$(qubesdb-read /qubes-netvm-network 2>/dev/null)
  57. if [ "x$network" != "x" ] && [ "x$disabledns" != "x1" ]; then
  58. gateway=$(qubesdb-read /qubes-netvm-gateway)
  59. netmask=$(qubesdb-read /qubes-netvm-netmask)
  60. secondary_dns=$(qubesdb-read /qubes-netvm-secondary-dns)
  61. echo "NS1=$gateway" > /var/run/qubes/qubes-ns
  62. echo "NS2=$secondary_dns" >> /var/run/qubes/qubes-ns
  63. /usr/lib/qubes/qubes-setup-dnat-to-ns
  64. fi
  65. if [ "x$network" != "x" ]; then
  66. [ -x /rw/config/qubes-ip-change-hook ] && /rw/config/qubes-ip-change-hook
  67. # XXX: Backward compatibility
  68. [ -x /rw/config/qubes_ip_change_hook ] && /rw/config/qubes_ip_change_hook
  69. fi
  70. fi