networking.bonds: add support for arbitrary driverOptions
Until now the four attributes available very selectively provided a small subset, while copying upstream documentation. We make driver options an arbitrary key-value set and point to kernel documentation, which is always up-to-date. This way every option can be set. The four already existing options are deprecated with a warning.
This commit is contained in:
parent
03024b39b7
commit
9debdaf512
@ -37,11 +37,24 @@ let
|
|||||||
ip link del "${i}" 2>/dev/null || true
|
ip link del "${i}" 2>/dev/null || true
|
||||||
'';
|
'';
|
||||||
|
|
||||||
in
|
# warn that these attributes are deprecated (2017-2-2)
|
||||||
|
# Should be removed in the release after next
|
||||||
|
bondDeprecation = rec {
|
||||||
|
deprecated = [ "lacp_rate" "miimon" "mode" "xmit_hash_policy" ];
|
||||||
|
filterDeprecated = bond: (filterAttrs (attrName: attr:
|
||||||
|
elem attrName deprecated && attr != null) bond);
|
||||||
|
};
|
||||||
|
|
||||||
{
|
bondWarnings =
|
||||||
|
let oneBondWarnings = bondName: bond:
|
||||||
|
mapAttrsToList (bondText bondName) (bondDeprecation.filterDeprecated bond);
|
||||||
|
bondText = bondName: optName: _:
|
||||||
|
"${bondName}.${optName} is deprecated, use ${bondName}.driverOptions";
|
||||||
|
in {
|
||||||
|
warnings = flatten (mapAttrsToList oneBondWarnings cfg.bonds);
|
||||||
|
};
|
||||||
|
|
||||||
config = mkIf (!cfg.useNetworkd) {
|
normalConfig = {
|
||||||
|
|
||||||
systemd.services =
|
systemd.services =
|
||||||
let
|
let
|
||||||
@ -296,10 +309,11 @@ in
|
|||||||
|
|
||||||
echo "Creating new bond ${n}..."
|
echo "Creating new bond ${n}..."
|
||||||
ip link add name "${n}" type bond \
|
ip link add name "${n}" type bond \
|
||||||
${optionalString (v.mode != null) "mode ${toString v.mode}"} \
|
${let opts = (mapAttrs (const toString)
|
||||||
${optionalString (v.miimon != null) "miimon ${toString v.miimon}"} \
|
(bondDeprecation.filterDeprecated v))
|
||||||
${optionalString (v.xmit_hash_policy != null) "xmit_hash_policy ${toString v.xmit_hash_policy}"} \
|
// v.driverOptions;
|
||||||
${optionalString (v.lacp_rate != null) "lacp_rate ${toString v.lacp_rate}"}
|
in concatStringsSep "\n"
|
||||||
|
(mapAttrsToList (set: val: " ${set} ${val} \\") opts)}
|
||||||
|
|
||||||
# !!! There must be a better way to wait for the interface
|
# !!! There must be a better way to wait for the interface
|
||||||
while [ ! -d "/sys/class/net/${n}" ]; do sleep 0.1; done;
|
while [ ! -d "/sys/class/net/${n}" ]; do sleep 0.1; done;
|
||||||
@ -410,6 +424,14 @@ in
|
|||||||
KERNEL=="tun", TAG+="systemd"
|
KERNEL=="tun", TAG+="systemd"
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
in
|
||||||
|
|
||||||
|
{
|
||||||
|
config = mkMerge [
|
||||||
|
bondWarnings
|
||||||
|
(mkIf (!cfg.useNetworkd) normalConfig)
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
@ -587,11 +587,28 @@ in
|
|||||||
description = "The interfaces to bond together";
|
description = "The interfaces to bond together";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
driverOptions = mkOption {
|
||||||
|
type = types.attrsOf types.str;
|
||||||
|
default = {};
|
||||||
|
example = literalExample {
|
||||||
|
interfaces = [ "eth0" "wlan0" ];
|
||||||
|
miimon = 100;
|
||||||
|
mode = "active-backup";
|
||||||
|
};
|
||||||
|
description = ''
|
||||||
|
Options for the bonding driver.
|
||||||
|
Documentation can be found in
|
||||||
|
<link xlink:href="https://www.kernel.org/doc/Documentation/networking/bonding.txt" />
|
||||||
|
'';
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
lacp_rate = mkOption {
|
lacp_rate = mkOption {
|
||||||
default = null;
|
default = null;
|
||||||
example = "fast";
|
example = "fast";
|
||||||
type = types.nullOr types.str;
|
type = types.nullOr types.str;
|
||||||
description = ''
|
description = ''
|
||||||
|
DEPRECATED, use `driverOptions`.
|
||||||
Option specifying the rate in which we'll ask our link partner
|
Option specifying the rate in which we'll ask our link partner
|
||||||
to transmit LACPDU packets in 802.3ad mode.
|
to transmit LACPDU packets in 802.3ad mode.
|
||||||
'';
|
'';
|
||||||
@ -602,6 +619,7 @@ in
|
|||||||
example = 100;
|
example = 100;
|
||||||
type = types.nullOr types.int;
|
type = types.nullOr types.int;
|
||||||
description = ''
|
description = ''
|
||||||
|
DEPRECATED, use `driverOptions`.
|
||||||
Miimon is the number of millisecond in between each round of polling
|
Miimon is the number of millisecond in between each round of polling
|
||||||
by the device driver for failed links. By default polling is not
|
by the device driver for failed links. By default polling is not
|
||||||
enabled and the driver is trusted to properly detect and handle
|
enabled and the driver is trusted to properly detect and handle
|
||||||
@ -614,6 +632,7 @@ in
|
|||||||
example = "active-backup";
|
example = "active-backup";
|
||||||
type = types.nullOr types.str;
|
type = types.nullOr types.str;
|
||||||
description = ''
|
description = ''
|
||||||
|
DEPRECATED, use `driverOptions`.
|
||||||
The mode which the bond will be running. The default mode for
|
The mode which the bond will be running. The default mode for
|
||||||
the bonding driver is balance-rr, optimizing for throughput.
|
the bonding driver is balance-rr, optimizing for throughput.
|
||||||
More information about valid modes can be found at
|
More information about valid modes can be found at
|
||||||
@ -626,6 +645,7 @@ in
|
|||||||
example = "layer2+3";
|
example = "layer2+3";
|
||||||
type = types.nullOr types.str;
|
type = types.nullOr types.str;
|
||||||
description = ''
|
description = ''
|
||||||
|
DEPRECATED, use `driverOptions`.
|
||||||
Selects the transmit hash policy to use for slave selection in
|
Selects the transmit hash policy to use for slave selection in
|
||||||
balance-xor, 802.3ad, and tlb modes.
|
balance-xor, 802.3ad, and tlb modes.
|
||||||
'';
|
'';
|
||||||
|
@ -236,8 +236,8 @@ let
|
|||||||
firewall.allowPing = true;
|
firewall.allowPing = true;
|
||||||
useDHCP = false;
|
useDHCP = false;
|
||||||
bonds.bond = {
|
bonds.bond = {
|
||||||
mode = "balance-rr";
|
|
||||||
interfaces = [ "eth1" "eth2" ];
|
interfaces = [ "eth1" "eth2" ];
|
||||||
|
driverOptions.mode = "balance-rr";
|
||||||
};
|
};
|
||||||
interfaces.eth1.ip4 = mkOverride 0 [ ];
|
interfaces.eth1.ip4 = mkOverride 0 [ ];
|
||||||
interfaces.eth2.ip4 = mkOverride 0 [ ];
|
interfaces.eth2.ip4 = mkOverride 0 [ ];
|
||||||
|
Loading…
Reference in New Issue
Block a user