Revert "Merge pull request #3182 from wkennington/master.ipv6"

This reverts commit b23fd65854, reversing
changes made to 43654cba2c.
This commit is contained in:
Rob Vermaas 2014-08-31 10:58:54 +02:00
parent 2f697bf693
commit ea8910652f
7 changed files with 59 additions and 120 deletions

View file

@ -12,9 +12,12 @@ interfaces. However, you can configure an interface manually as
follows: follows:
<programlisting> <programlisting>
networking.interfaces.eth0.ip4 = [ { address = "192.168.1.2"; prefixLength = 24; } ]; networking.interfaces.eth0 = { ipAddress = "192.168.1.2"; prefixLength = 24; };
</programlisting> </programlisting>
(The network prefix can also be specified using the option
<literal>subnetMask</literal>,
e.g. <literal>"255.255.255.0"</literal>, but this is deprecated.)
Typically youll also want to set a default gateway and set of name Typically youll also want to set a default gateway and set of name
servers: servers:

View file

@ -48,11 +48,10 @@ rec {
let let
interfacesNumbered = zipTwoLists config.virtualisation.vlans (range 1 255); interfacesNumbered = zipTwoLists config.virtualisation.vlans (range 1 255);
interfaces = flip map interfacesNumbered ({ first, second }: interfaces = flip map interfacesNumbered ({ first, second }:
nameValuePair "eth${toString second}" { ip4 = nameValuePair "eth${toString second}"
[ { address = "192.168.${toString first}.${toString m.second}"; { ipAddress = "192.168.${toString first}.${toString m.second}";
prefixLength = 24; subnetMask = "255.255.255.0";
} ]; });
}
in in
{ key = "ip-address"; { key = "ip-address";
config = config =
@ -61,7 +60,7 @@ rec {
networking.interfaces = listToAttrs interfaces; networking.interfaces = listToAttrs interfaces;
networking.primaryIPAddress = networking.primaryIPAddress =
optionalString (interfaces != []) (head (head interfaces).value.ip4).address; optionalString (interfaces != []) (head interfaces).value.ipAddress;
# Put the IP addresses of all VMs in this machine's # Put the IP addresses of all VMs in this machine's
# /etc/hosts file. If a machine has multiple # /etc/hosts file. If a machine has multiple

View file

@ -44,5 +44,5 @@ let virtualbox = config.boot.kernelPackages.virtualbox; in
''; '';
}; };
networking.interfaces.vboxnet0.ip4 = [ { address = "192.168.56.1"; prefixLength = 24; } ]; networking.interfaces.vboxnet0 = { ipAddress = "192.168.56.1"; prefixLength = 24; };
} }

View file

@ -11,7 +11,7 @@ let
# Don't start dhcpcd on explicitly configured interfaces or on # Don't start dhcpcd on explicitly configured interfaces or on
# interfaces that are part of a bridge, bond or sit device. # interfaces that are part of a bridge, bond or sit device.
ignoredInterfaces = ignoredInterfaces =
map (i: i.name) (filter (i: i.ip4 != [ ] || i.ipAddress != null) (attrValues config.networking.interfaces)) map (i: i.name) (filter (i: i.ipAddress != null) (attrValues config.networking.interfaces))
++ mapAttrsToList (i: _: i) config.networking.sits ++ mapAttrsToList (i: _: i) config.networking.sits
++ concatLists (attrValues (mapAttrs (n: v: v.interfaces) config.networking.bridges)) ++ concatLists (attrValues (mapAttrs (n: v: v.interfaces) config.networking.bridges))
++ concatLists (attrValues (mapAttrs (n: v: v.interfaces) config.networking.bonds)) ++ concatLists (attrValues (mapAttrs (n: v: v.interfaces) config.networking.bonds))

View file

@ -10,26 +10,6 @@ let
hasSits = cfg.sits != { }; hasSits = cfg.sits != { };
hasBonds = cfg.bonds != { }; hasBonds = cfg.bonds != { };
addrOpts = v:
assert v == 4 || v == 6;
{
address = mkOption {
type = types.str;
description = ''
IPv${toString v} address of the interface. Leave empty to configure the
interface using DHCP.
'';
};
prefixLength = mkOption {
type = types.addCheck types.int (n: n >= 0 && n <= (if v == 4 then 32 else 128));
description = ''
Subnet mask of the interface, specified as the number of
bits in the prefix (<literal>${if v == 4 then "24" else "64"}</literal>).
'';
};
};
interfaceOpts = { name, ... }: { interfaceOpts = { name, ... }: {
options = { options = {
@ -40,36 +20,10 @@ let
description = "Name of the interface."; description = "Name of the interface.";
}; };
ip4 = mkOption {
default = [ ];
example = [
{ address = "10.0.0.1"; prefixLength = 16; }
{ address = "192.168.1.1"; prefixLength = 24; }
];
type = types.listOf types.optionSet;
options = addrOpts 4;
description = ''
List of IPv4 addresses that will be statically assigned to the interface.
'';
};
ip6 = mkOption {
default = [ ];
example = [
{ address = "fdfd:b3f0:482::1"; prefixLength = 48; }
{ address = "2001:1470:fffd:2098::e006"; prefixLength = 64; }
];
type = types.listOf types.optionSet;
options = addrOpts 6;
description = ''
List of IPv6 addresses that will be statically assigned to the interface.
'';
};
ipAddress = mkOption { ipAddress = mkOption {
default = null; default = null;
example = "10.0.0.1"; example = "10.0.0.1";
type = types.nullOr types.str; type = types.nullOr (types.str);
description = '' description = ''
IP address of the interface. Leave empty to configure the IP address of the interface. Leave empty to configure the
interface using DHCP. interface using DHCP.
@ -87,16 +41,20 @@ let
}; };
subnetMask = mkOption { subnetMask = mkOption {
default = null; default = "";
example = "255.255.255.0";
type = types.str;
description = '' description = ''
Defunct, supply the prefix length instead. Subnet mask of the interface, specified as a bitmask.
This is deprecated; use <option>prefixLength</option>
instead.
''; '';
}; };
ipv6Address = mkOption { ipv6Address = mkOption {
default = null; default = null;
example = "2001:1470:fffd:2098::e006"; example = "2001:1470:fffd:2098::e006";
type = types.nullOr types.str; type = types.nullOr types.string;
description = '' description = ''
IPv6 address of the interface. Leave empty to configure the IPv6 address of the interface. Leave empty to configure the
interface using NDP. interface using NDP.
@ -266,10 +224,10 @@ in
networking.interfaces = mkOption { networking.interfaces = mkOption {
default = {}; default = {};
example = example =
{ eth0.ip4 = [ { { eth0 = {
address = "131.211.84.78"; ipAddress = "131.211.84.78";
prefixLength = 25; subnetMask = "255.255.255.128";
} ]; };
}; };
description = '' description = ''
The configuration for each network interface. If The configuration for each network interface. If
@ -480,12 +438,6 @@ in
config = { config = {
assertions =
flip map interfaces (i: {
assertion = i.subnetMask == null;
message = "The networking.interfaces.${i.name}.subnetMask option is defunct. Use prefixLength instead.";
});
boot.kernelModules = [ ] boot.kernelModules = [ ]
++ optional cfg.enableIPv6 "ipv6" ++ optional cfg.enableIPv6 "ipv6"
++ optional hasVirtuals "tun" ++ optional hasVirtuals "tun"
@ -582,18 +534,12 @@ in
# network device, so it only gets started after the interface # network device, so it only gets started after the interface
# has appeared, and it's stopped when the interface # has appeared, and it's stopped when the interface
# disappears. # disappears.
configureInterface = i: configureInterface = i: nameValuePair "${i.name}-cfg"
let (let mask =
ips = i.ip4 ++ optionals cfg.enableIPv6 i.ip6 if i.prefixLength != null then toString i.prefixLength else
++ optional (i.ipAddress != null) { if i.subnetMask != "" then i.subnetMask else "32";
ipAddress = i.ipAddress; staticIPv6 = cfg.enableIPv6 && i.ipv6Address != null;
prefixLength = i.prefixLength;
} ++ optional (cfg.enableIPv6 && i.ipv6Address != null) {
ipAddress = i.ipv6Address;
prefixLength = i.ipv6PrefixLength;
};
in in
nameValuePair "${i.name}-cfg"
{ description = "Configuration of ${i.name}"; { description = "Configuration of ${i.name}";
wantedBy = [ "network-interfaces.target" ]; wantedBy = [ "network-interfaces.target" ];
bindsTo = [ "sys-subsystem-net-devices-${i.name}.device" ]; bindsTo = [ "sys-subsystem-net-devices-${i.name}.device" ];
@ -616,32 +562,36 @@ in
echo "setting MTU to ${toString i.mtu}..." echo "setting MTU to ${toString i.mtu}..."
ip link set "${i.name}" mtu "${toString i.mtu}" ip link set "${i.name}" mtu "${toString i.mtu}"
'' ''
+ optionalString (i.ipAddress != null)
# Ip Setup
+
'' ''
curIps=$(ip -o a show dev "${i.name}" | awk '{print $4}') cur=$(ip -4 -o a show dev "${i.name}" | awk '{print $4}')
# Only do an add if it's necessary. This is # Only do a flush/add if it's necessary. This is
# useful when the Nix store is accessed via this # useful when the Nix store is accessed via this
# interface (e.g. in a QEMU VM test). # interface (e.g. in a QEMU VM test).
'' if [ "$cur" != "${i.ipAddress}/${mask}" ]; then
+ flip concatMapStrings (ips) (ip: echo "configuring interface..."
let ip -4 addr flush dev "${i.name}"
address = "${ip.address}/${toString ip.prefixLength}"; ip -4 addr add "${i.ipAddress}/${mask}" dev "${i.name}"
in restart_network_setup=true
'' else
echo "checking ip ${address}..." echo "skipping configuring interface"
if ! echo "$curIps" | grep "${address}" >/dev/null 2>&1; then
if out=$(ip addr add "${address}" dev "${i.name}" 2>&1); then
echo "added ip ${address}..."
restart_network_setup=true
elif ! echo "$out" | grep "File exists" >/dev/null 2>&1; then
echo "failed to add ${address}"
exit 1
fi
fi fi
'') ''
+ optionalString (ips != [ ]) + optionalString (staticIPv6)
''
# Only do a flush/add if it's necessary. This is
# useful when the Nix store is accessed via this
# interface (e.g. in a QEMU VM test).
if ! ip -6 -o a show dev "${i.name}" | grep "${i.ipv6Address}/${toString i.ipv6prefixLength}"; then
echo "configuring interface..."
ip -6 addr flush dev "${i.name}"
ip -6 addr add "${i.ipv6Address}/${toString i.ipv6prefixLength}" dev "${i.name}"
restart_network_setup=true
else
echo "skipping configuring interface"
fi
''
+ optionalString (i.ipAddress != null || staticIPv6)
'' ''
if [ restart_network_setup = true ]; then if [ restart_network_setup = true ]; then
# Ensure that the default gateway remains set. # Ensure that the default gateway remains set.
@ -658,20 +608,7 @@ in
'' ''
echo 1 > /proc/sys/net/ipv6/conf/${i.name}/proxy_ndp echo 1 > /proc/sys/net/ipv6/conf/${i.name}/proxy_ndp
''; '';
preStop = });
''
echo "releasing configured ip's..."
''
+ flip concatMapStrings (ips) (ip:
let
address = "${ip.address}/${toString ip.prefixLength}";
in
''
echo -n "Deleting ${address}..."
ip addr del "${address}" dev "${i.name}" >/dev/null 2>&1 || echo -n " Failed"
echo ""
'');
};
createTunDevice = i: nameValuePair "${i.name}" createTunDevice = i: nameValuePair "${i.name}"
{ description = "Virtual Network Interface ${i.name}"; { description = "Virtual Network Interface ${i.name}";

View file

@ -16,7 +16,7 @@ let
miniupnpdConf = nodes: pkgs.writeText "miniupnpd.conf" miniupnpdConf = nodes: pkgs.writeText "miniupnpd.conf"
'' ''
ext_ifname=eth1 ext_ifname=eth1
listening_ip=${(head nodes.router.config.networking.interfaces.eth2.ip4).address}/24 listening_ip=${nodes.router.config.networking.interfaces.eth2.ipAddress}/24
allow 1024-65535 192.168.2.0/24 1024-65535 allow 1024-65535 192.168.2.0/24 1024-65535
''; '';
@ -53,7 +53,7 @@ in
{ environment.systemPackages = [ pkgs.transmission ]; { environment.systemPackages = [ pkgs.transmission ];
virtualisation.vlans = [ 2 ]; virtualisation.vlans = [ 2 ];
networking.defaultGateway = networking.defaultGateway =
(head nodes.router.config.networking.interfaces.eth2.ip4).address; nodes.router.config.networking.interfaces.eth2.ipAddress;
networking.firewall.enable = false; networking.firewall.enable = false;
}; };
@ -81,7 +81,7 @@ in
# Create the torrent. # Create the torrent.
$tracker->succeed("mkdir /tmp/data"); $tracker->succeed("mkdir /tmp/data");
$tracker->succeed("cp ${file} /tmp/data/test.tar.bz2"); $tracker->succeed("cp ${file} /tmp/data/test.tar.bz2");
$tracker->succeed("transmission-create /tmp/data/test.tar.bz2 -t http://${(head nodes.tracker.config.networking.interfaces.eth1.ip4).address}:6969/announce -o /tmp/test.torrent"); $tracker->succeed("transmission-create /tmp/data/test.tar.bz2 -t http://${nodes.tracker.config.networking.interfaces.eth1.ipAddress}:6969/announce -o /tmp/test.torrent");
$tracker->succeed("chmod 644 /tmp/test.torrent"); $tracker->succeed("chmod 644 /tmp/test.torrent");
# Start the tracker. !!! use a less crappy tracker # Start the tracker. !!! use a less crappy tracker

View file

@ -13,7 +13,7 @@ import ./make-test.nix {
{ virtualisation.vlans = [ 1 ]; { virtualisation.vlans = [ 1 ];
networking.firewall.allowPing = true; networking.firewall.allowPing = true;
networking.defaultGateway = networking.defaultGateway =
(head nodes.router.config.networking.interfaces.eth2.ip4).address; nodes.router.config.networking.interfaces.eth2.ipAddress;
}; };
router = router =