Author: eelco
Date: Fri Mar 11 14:50:11 2011
New Revision: 26279
URL: https://svn.nixos.org/websvn/nix/?rev=26279&sc=1

Log:
* Use "ip" instead of "ifconfig" for setting up network interfaces,
  since the latter is rather deprecated and has been unmaintained
  since 2001.  Note that "ip" doesn't know about classful addressing,
  so you can no longer get away with not specifying the subnet mask
  for explicitly configured interfaces.  So if you had

    networking.interfaces =
      [ { name = "eth0"; ipAddress = "192.168.1.1"; } ];

  this should be changed to

    networking.interfaces =
      [ { name = "eth0";
          ipAddress = "192.168.1.1";
          subnetMask = "255.255.255.0";
        }
     ];

  otherwise you end up with a subnet mask of 255.255.255.255.

Modified:
   nixos/trunk/lib/build-vms.nix
   nixos/trunk/modules/tasks/network-interfaces.nix

Modified: nixos/trunk/lib/build-vms.nix
==============================================================================
--- nixos/trunk/lib/build-vms.nix       Fri Mar 11 13:59:01 2011        (r26278)
+++ nixos/trunk/lib/build-vms.nix       Fri Mar 11 14:50:11 2011        (r26279)
@@ -51,6 +51,7 @@
                 lib.flip map interfacesNumbered ({ first, second }:
                   { name = "eth${toString second}";
                     ipAddress = "192.168.${toString first}.${toString 
m.second}";
+                    subnetMask = "255.255.255.0";
                   }
                 );
             in

Modified: nixos/trunk/modules/tasks/network-interfaces.nix
==============================================================================
--- nixos/trunk/modules/tasks/network-interfaces.nix    Fri Mar 11 13:59:01 
2011        (r26278)
+++ nixos/trunk/modules/tasks/network-interfaces.nix    Fri Mar 11 14:50:11 
2011        (r26279)
@@ -4,12 +4,8 @@
 
 let
 
-  inherit (pkgs) nettools;
-
   cfg = config.networking;
 
-  ifconfig = "${nettools}/sbin/ifconfig";
-
 in 
 
 {
@@ -166,33 +162,28 @@
 
         preStart =
           ''
-            ${pkgs.lib.concatMapStrings (i:
-              if i.macAddress != "" then
-                ''
-                  echo "Configuring interface ${i.name}..."
-                  ${ifconfig} "${i.name}" down || true
-                  ${ifconfig} "${i.name}" hw ether "${i.macAddress}" || true
+            ${flip concatMapStrings cfg.interfaces (i:
+              optionalString (i.macAddress != "")
                 ''
-              else "") cfg.interfaces
+                  echo "Setting MAC address of ${i.name} to ${i.macAddress}..."
+                  ip link set "${i.name}" address "${i.macAddress}" || true
+                '')
             }
 
             for i in $(cd /sys/class/net && ls -d *); do
                 echo "Bringing up network device $i..."
-                ${ifconfig} $i up || true
+                ip link set "$i" up || true
             done
 
             # Configure the manually specified interfaces.
-            ${pkgs.lib.concatMapStrings (i:
-              if i.ipAddress != "" then
+            ${flip concatMapStrings cfg.interfaces (i:
+              optionalString (i.ipAddress != "")
                 ''
                   echo "Configuring interface ${i.name}..."
-                  extraFlags=
-                  if test -n "${i.subnetMask}"; then
-                      extraFlags="$extraFlags netmask ${i.subnetMask}"
-                  fi
-                  ${ifconfig} "${i.name}" "${i.ipAddress}" $extraFlags || true
-                ''
-              else "") cfg.interfaces}
+                  ip addr add "${i.ipAddress}""${optionalString (i.subnetMask 
!= "") ("/" + i.subnetMask)}" \
+                    dev "${i.name}" || true
+                '')
+            }
 
             # Set the nameservers.
             if test -n "${toString cfg.nameservers}"; then
@@ -206,9 +197,9 @@
             fi
 
             # Set the default gateway.
-            if test -n "${cfg.defaultGateway}"; then
-                ${nettools}/sbin/route add default gw "${cfg.defaultGateway}" 
|| true
-            fi
+            ${optionalString (cfg.defaultGateway != "") ''
+                ip route add default via "${cfg.defaultGateway}" || true
+            ''}
 
             # Run any user-specified commands.
             ${pkgs.stdenv.shell} ${pkgs.writeText "local-net-cmds" 
cfg.localCommands} || true
@@ -218,14 +209,6 @@
               initctl emit -n ip-up
             ''}
           '';
-
-        postStop =
-          ''
-            #for i in $(cd /sys/class/net && ls -d *); do
-            #    echo "Taking down network device $i..."
-            #    ${ifconfig} $i down || true
-            #done
-          '';
       };
 
     # Set the host name in the activation script.  Don't clear it if
_______________________________________________
nix-commits mailing list
[email protected]
http://mail.cs.uu.nl/mailman/listinfo/nix-commits

Reply via email to