summary refs log tree commit diff
path: root/modules/tasks/network-interfaces.nix
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2011-03-15 15:13:48 +0000
committerEelco Dolstra <eelco.dolstra@logicblox.com>2011-03-15 15:13:48 +0000
commit3cb7a54dbafb93cb7f8f0f0b315676b367172466 (patch)
tree36c977956e8264aa4edc6bab2a5413663ee9f38b /modules/tasks/network-interfaces.nix
parentf45866d0e7eba8fcfcdb4f3badbcc879f7511fa7 (diff)
downloadnixpkgs-3cb7a54dbafb93cb7f8f0f0b315676b367172466.tar
nixpkgs-3cb7a54dbafb93cb7f8f0f0b315676b367172466.tar.gz
nixpkgs-3cb7a54dbafb93cb7f8f0f0b315676b367172466.tar.bz2
nixpkgs-3cb7a54dbafb93cb7f8f0f0b315676b367172466.tar.lz
nixpkgs-3cb7a54dbafb93cb7f8f0f0b315676b367172466.tar.xz
nixpkgs-3cb7a54dbafb93cb7f8f0f0b315676b367172466.tar.zst
nixpkgs-3cb7a54dbafb93cb7f8f0f0b315676b367172466.zip
* Added an option `networking.bridges' to allow Ethernet bridges to be
  defined.

svn path=/nixos/trunk/; revision=26325
Diffstat (limited to 'modules/tasks/network-interfaces.nix')
-rw-r--r--modules/tasks/network-interfaces.nix44
1 files changed, 43 insertions, 1 deletions
diff --git a/modules/tasks/network-interfaces.nix b/modules/tasks/network-interfaces.nix
index f6343815a95..eb94315b063 100644
--- a/modules/tasks/network-interfaces.nix
+++ b/modules/tasks/network-interfaces.nix
@@ -133,6 +133,36 @@ in
       '';
     };
     
+    networking.bridges = mkOption {
+      default = { };
+      example =
+        { br0.interfaces = [ "eth0" "eth1" ];
+          br1.interfaces = [ "eth2" "wlan0" ];
+        };
+      description =
+        ''
+          This option allows you to define Ethernet bridge devices
+          that connect physical networks together.  The value of this
+          option is an attribute set.  Each attribute specifies a
+          bridge, with the attribute name specifying the name of the
+          bridge's network interface.
+        '';
+
+      type = types.attrsOf types.optionSet;
+
+      options = {
+
+        interfaces = mkOption {
+          example = [ "eth0" "eth1" ];
+          type = types.listOf types.string;
+          description =
+            "The physical network interfaces connected by the bridge.";
+        };
+
+      };
+      
+    };
+
   };
 
 
@@ -149,7 +179,7 @@ in
         pkgs.nettools
         pkgs.wirelesstools
         pkgs.rfkill
-      ];
+      ] ++ optional (cfg.bridges != {}) [ pkgs.bridge_utils ];
 
     security.setuidPrograms = [ "ping" "ping6" ];
     
@@ -204,6 +234,18 @@ in
             # Run any user-specified commands.
             ${pkgs.stdenv.shell} ${pkgs.writeText "local-net-cmds" cfg.localCommands} || true
 
+            # Create bridge devices.
+            ${concatStrings (attrValues (flip mapAttrs cfg.bridges (n: v: ''
+                echo "Creating bridge ${n}..."
+                ${pkgs.bridge_utils}/sbin/brctl addbr "${n}" || true
+                ${flip concatMapStrings v.interfaces (i: ''
+                  ${pkgs.bridge_utils}/sbin/brctl addif "${n}" "${i}" || true
+                  ip addr flush dev "${i}" || true
+                '')}
+                # !!! Should delete (brctl delif) any interfaces that
+                # no longer belong to the bridge.
+            '')))}
+            
             ${optionalString (cfg.interfaces != [] || cfg.localCommands != "") ''
               # Emit the ip-up event (e.g. to start ntpd).
               initctl emit -n ip-up