Skip to content

Commit ea89106

Browse files
committed
Revert "Merge pull request #3182 from wkennington/master.ipv6"
This reverts commit b23fd65, reversing changes made to 43654cb.
1 parent 2f697bf commit ea89106

File tree

7 files changed

+57
-118
lines changed

7 files changed

+57
-118
lines changed

nixos/doc/manual/configuration/ipv4-config.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,12 @@ interfaces. However, you can configure an interface manually as
1212
follows:
1313

1414
<programlisting>
15-
networking.interfaces.eth0.ip4 = [ { address = "192.168.1.2"; prefixLength = 24; } ];
15+
networking.interfaces.eth0 = { ipAddress = "192.168.1.2"; prefixLength = 24; };
1616
</programlisting>
1717

18+
(The network prefix can also be specified using the option
19+
<literal>subnetMask</literal>,
20+
e.g. <literal>"255.255.255.0"</literal>, but this is deprecated.)
1821
Typically you’ll also want to set a default gateway and set of name
1922
servers:
2023

nixos/lib/build-vms.nix

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,10 @@ rec {
4848
let
4949
interfacesNumbered = zipTwoLists config.virtualisation.vlans (range 1 255);
5050
interfaces = flip map interfacesNumbered ({ first, second }:
51-
nameValuePair "eth${toString second}" { ip4 =
52-
[ { address = "192.168.${toString first}.${toString m.second}";
53-
prefixLength = 24;
54-
} ];
55-
}
51+
nameValuePair "eth${toString second}"
52+
{ ipAddress = "192.168.${toString first}.${toString m.second}";
53+
subnetMask = "255.255.255.0";
54+
});
5655
in
5756
{ key = "ip-address";
5857
config =
@@ -61,7 +60,7 @@ rec {
6160
networking.interfaces = listToAttrs interfaces;
6261

6362
networking.primaryIPAddress =
64-
optionalString (interfaces != []) (head (head interfaces).value.ip4).address;
63+
optionalString (interfaces != []) (head interfaces).value.ipAddress;
6564

6665
# Put the IP addresses of all VMs in this machine's
6766
# /etc/hosts file. If a machine has multiple

nixos/modules/programs/virtualbox.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ let virtualbox = config.boot.kernelPackages.virtualbox; in
4444
'';
4545
};
4646

47-
networking.interfaces.vboxnet0.ip4 = [ { address = "192.168.56.1"; prefixLength = 24; } ];
47+
networking.interfaces.vboxnet0 = { ipAddress = "192.168.56.1"; prefixLength = 24; };
4848
}

nixos/modules/services/networking/dhcpcd.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ let
1111
# Don't start dhcpcd on explicitly configured interfaces or on
1212
# interfaces that are part of a bridge, bond or sit device.
1313
ignoredInterfaces =
14-
map (i: i.name) (filter (i: i.ip4 != [ ] || i.ipAddress != null) (attrValues config.networking.interfaces))
14+
map (i: i.name) (filter (i: i.ipAddress != null) (attrValues config.networking.interfaces))
1515
++ mapAttrsToList (i: _: i) config.networking.sits
1616
++ concatLists (attrValues (mapAttrs (n: v: v.interfaces) config.networking.bridges))
1717
++ concatLists (attrValues (mapAttrs (n: v: v.interfaces) config.networking.bonds))

nixos/modules/tasks/network-interfaces.nix

Lines changed: 42 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,6 @@ let
1010
hasSits = cfg.sits != { };
1111
hasBonds = cfg.bonds != { };
1212

13-
addrOpts = v:
14-
assert v == 4 || v == 6;
15-
{
16-
address = mkOption {
17-
type = types.str;
18-
description = ''
19-
IPv${toString v} address of the interface. Leave empty to configure the
20-
interface using DHCP.
21-
'';
22-
};
23-
24-
prefixLength = mkOption {
25-
type = types.addCheck types.int (n: n >= 0 && n <= (if v == 4 then 32 else 128));
26-
description = ''
27-
Subnet mask of the interface, specified as the number of
28-
bits in the prefix (<literal>${if v == 4 then "24" else "64"}</literal>).
29-
'';
30-
};
31-
};
32-
3313
interfaceOpts = { name, ... }: {
3414

3515
options = {
@@ -40,36 +20,10 @@ let
4020
description = "Name of the interface.";
4121
};
4222

43-
ip4 = mkOption {
44-
default = [ ];
45-
example = [
46-
{ address = "10.0.0.1"; prefixLength = 16; }
47-
{ address = "192.168.1.1"; prefixLength = 24; }
48-
];
49-
type = types.listOf types.optionSet;
50-
options = addrOpts 4;
51-
description = ''
52-
List of IPv4 addresses that will be statically assigned to the interface.
53-
'';
54-
};
55-
56-
ip6 = mkOption {
57-
default = [ ];
58-
example = [
59-
{ address = "fdfd:b3f0:482::1"; prefixLength = 48; }
60-
{ address = "2001:1470:fffd:2098::e006"; prefixLength = 64; }
61-
];
62-
type = types.listOf types.optionSet;
63-
options = addrOpts 6;
64-
description = ''
65-
List of IPv6 addresses that will be statically assigned to the interface.
66-
'';
67-
};
68-
6923
ipAddress = mkOption {
7024
default = null;
7125
example = "10.0.0.1";
72-
type = types.nullOr types.str;
26+
type = types.nullOr (types.str);
7327
description = ''
7428
IP address of the interface. Leave empty to configure the
7529
interface using DHCP.
@@ -87,16 +41,20 @@ let
8741
};
8842

8943
subnetMask = mkOption {
90-
default = null;
44+
default = "";
45+
example = "255.255.255.0";
46+
type = types.str;
9147
description = ''
92-
Defunct, supply the prefix length instead.
48+
Subnet mask of the interface, specified as a bitmask.
49+
This is deprecated; use <option>prefixLength</option>
50+
instead.
9351
'';
9452
};
9553

9654
ipv6Address = mkOption {
9755
default = null;
9856
example = "2001:1470:fffd:2098::e006";
99-
type = types.nullOr types.str;
57+
type = types.nullOr types.string;
10058
description = ''
10159
IPv6 address of the interface. Leave empty to configure the
10260
interface using NDP.
@@ -266,10 +224,10 @@ in
266224
networking.interfaces = mkOption {
267225
default = {};
268226
example =
269-
{ eth0.ip4 = [ {
270-
address = "131.211.84.78";
271-
prefixLength = 25;
272-
} ];
227+
{ eth0 = {
228+
ipAddress = "131.211.84.78";
229+
subnetMask = "255.255.255.128";
230+
};
273231
};
274232
description = ''
275233
The configuration for each network interface. If
@@ -480,12 +438,6 @@ in
480438

481439
config = {
482440

483-
assertions =
484-
flip map interfaces (i: {
485-
assertion = i.subnetMask == null;
486-
message = "The networking.interfaces.${i.name}.subnetMask option is defunct. Use prefixLength instead.";
487-
});
488-
489441
boot.kernelModules = [ ]
490442
++ optional cfg.enableIPv6 "ipv6"
491443
++ optional hasVirtuals "tun"
@@ -582,18 +534,12 @@ in
582534
# network device, so it only gets started after the interface
583535
# has appeared, and it's stopped when the interface
584536
# disappears.
585-
configureInterface = i:
586-
let
587-
ips = i.ip4 ++ optionals cfg.enableIPv6 i.ip6
588-
++ optional (i.ipAddress != null) {
589-
ipAddress = i.ipAddress;
590-
prefixLength = i.prefixLength;
591-
} ++ optional (cfg.enableIPv6 && i.ipv6Address != null) {
592-
ipAddress = i.ipv6Address;
593-
prefixLength = i.ipv6PrefixLength;
594-
};
537+
configureInterface = i: nameValuePair "${i.name}-cfg"
538+
(let mask =
539+
if i.prefixLength != null then toString i.prefixLength else
540+
if i.subnetMask != "" then i.subnetMask else "32";
541+
staticIPv6 = cfg.enableIPv6 && i.ipv6Address != null;
595542
in
596-
nameValuePair "${i.name}-cfg"
597543
{ description = "Configuration of ${i.name}";
598544
wantedBy = [ "network-interfaces.target" ];
599545
bindsTo = [ "sys-subsystem-net-devices-${i.name}.device" ];
@@ -616,32 +562,36 @@ in
616562
echo "setting MTU to ${toString i.mtu}..."
617563
ip link set "${i.name}" mtu "${toString i.mtu}"
618564
''
619-
620-
# Ip Setup
621-
+
565+
+ optionalString (i.ipAddress != null)
622566
''
623-
curIps=$(ip -o a show dev "${i.name}" | awk '{print $4}')
624-
# Only do an add if it's necessary. This is
567+
cur=$(ip -4 -o a show dev "${i.name}" | awk '{print $4}')
568+
# Only do a flush/add if it's necessary. This is
625569
# useful when the Nix store is accessed via this
626570
# interface (e.g. in a QEMU VM test).
571+
if [ "$cur" != "${i.ipAddress}/${mask}" ]; then
572+
echo "configuring interface..."
573+
ip -4 addr flush dev "${i.name}"
574+
ip -4 addr add "${i.ipAddress}/${mask}" dev "${i.name}"
575+
restart_network_setup=true
576+
else
577+
echo "skipping configuring interface"
578+
fi
627579
''
628-
+ flip concatMapStrings (ips) (ip:
629-
let
630-
address = "${ip.address}/${toString ip.prefixLength}";
631-
in
580+
+ optionalString (staticIPv6)
632581
''
633-
echo "checking ip ${address}..."
634-
if ! echo "$curIps" | grep "${address}" >/dev/null 2>&1; then
635-
if out=$(ip addr add "${address}" dev "${i.name}" 2>&1); then
636-
echo "added ip ${address}..."
637-
restart_network_setup=true
638-
elif ! echo "$out" | grep "File exists" >/dev/null 2>&1; then
639-
echo "failed to add ${address}"
640-
exit 1
641-
fi
582+
# Only do a flush/add if it's necessary. This is
583+
# useful when the Nix store is accessed via this
584+
# interface (e.g. in a QEMU VM test).
585+
if ! ip -6 -o a show dev "${i.name}" | grep "${i.ipv6Address}/${toString i.ipv6prefixLength}"; then
586+
echo "configuring interface..."
587+
ip -6 addr flush dev "${i.name}"
588+
ip -6 addr add "${i.ipv6Address}/${toString i.ipv6prefixLength}" dev "${i.name}"
589+
restart_network_setup=true
590+
else
591+
echo "skipping configuring interface"
642592
fi
643-
'')
644-
+ optionalString (ips != [ ])
593+
''
594+
+ optionalString (i.ipAddress != null || staticIPv6)
645595
''
646596
if [ restart_network_setup = true ]; then
647597
# Ensure that the default gateway remains set.
@@ -658,20 +608,7 @@ in
658608
''
659609
echo 1 > /proc/sys/net/ipv6/conf/${i.name}/proxy_ndp
660610
'';
661-
preStop =
662-
''
663-
echo "releasing configured ip's..."
664-
''
665-
+ flip concatMapStrings (ips) (ip:
666-
let
667-
address = "${ip.address}/${toString ip.prefixLength}";
668-
in
669-
''
670-
echo -n "Deleting ${address}..."
671-
ip addr del "${address}" dev "${i.name}" >/dev/null 2>&1 || echo -n " Failed"
672-
echo ""
673-
'');
674-
};
611+
});
675612

676613
createTunDevice = i: nameValuePair "${i.name}"
677614
{ description = "Virtual Network Interface ${i.name}";

nixos/tests/bittorrent.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ let
1616
miniupnpdConf = nodes: pkgs.writeText "miniupnpd.conf"
1717
''
1818
ext_ifname=eth1
19-
listening_ip=${(head nodes.router.config.networking.interfaces.eth2.ip4).address}/24
19+
listening_ip=${nodes.router.config.networking.interfaces.eth2.ipAddress}/24
2020
allow 1024-65535 192.168.2.0/24 1024-65535
2121
'';
2222

@@ -53,7 +53,7 @@ in
5353
{ environment.systemPackages = [ pkgs.transmission ];
5454
virtualisation.vlans = [ 2 ];
5555
networking.defaultGateway =
56-
(head nodes.router.config.networking.interfaces.eth2.ip4).address;
56+
nodes.router.config.networking.interfaces.eth2.ipAddress;
5757
networking.firewall.enable = false;
5858
};
5959

@@ -81,7 +81,7 @@ in
8181
# Create the torrent.
8282
$tracker->succeed("mkdir /tmp/data");
8383
$tracker->succeed("cp ${file} /tmp/data/test.tar.bz2");
84-
$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");
84+
$tracker->succeed("transmission-create /tmp/data/test.tar.bz2 -t http://${nodes.tracker.config.networking.interfaces.eth1.ipAddress}:6969/announce -o /tmp/test.torrent");
8585
$tracker->succeed("chmod 644 /tmp/test.torrent");
8686
8787
# Start the tracker. !!! use a less crappy tracker

nixos/tests/nat.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import ./make-test.nix {
1313
{ virtualisation.vlans = [ 1 ];
1414
networking.firewall.allowPing = true;
1515
networking.defaultGateway =
16-
(head nodes.router.config.networking.interfaces.eth2.ip4).address;
16+
nodes.router.config.networking.interfaces.eth2.ipAddress;
1717
};
1818

1919
router =

0 commit comments

Comments
 (0)