Skip to content

Commit

Permalink
linux: Disable bond0 creation by bonding driver
Browse files Browse the repository at this point in the history
Linux defaults to creating a `bond0` interface when modprobing the
`bonding` driver, because the `max_bonds` option defaults to `1`¹.

This `bond0` interface is created with the default bond mode
`balance-rr`, which is most often undesirable.
Networkd in turn is unable to change this mode, since it does not
implement netdev recreation on parameter mismatch².

If we instead default `max_bonds=0` the driver will be loaded, but no
default interface will be created, leaving networkd in a better position
to set up the network configuration.

[1] https://www.kernel.org/doc/Documentation/networking/bonding.txt
[2] systemd/systemd#9627
  • Loading branch information
mweinelt committed Feb 21, 2022
1 parent 8eb1922 commit 8640ecc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkgs/os-specific/linux/kernel/bonding-dont-create-bond0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Prevent the bonding driver to create a bond0 interface by default when
loaded, as that conflicts with declarative configuration management and
instead feels much like a side-effect.


diff --git a/include/uapi/linux/if_bonding.h b/include/uapi/linux/if_bonding.h
index d174914a837d..bf8e2af101a3 100644
--- a/include/uapi/linux/if_bonding.h
+++ b/include/uapi/linux/if_bonding.h
@@ -82,7 +82,7 @@
#define BOND_STATE_ACTIVE 0 /* link is active */
#define BOND_STATE_BACKUP 1 /* link is backup */

-#define BOND_DEFAULT_MAX_BONDS 1 /* Default maximum number of devices to support */
+#define BOND_DEFAULT_MAX_BONDS 0 /* Default maximum number of devices to support */

#define BOND_DEFAULT_TX_QUEUES 16 /* Default number of tx queues per device */

5 changes: 5 additions & 0 deletions pkgs/os-specific/linux/kernel/patches.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
};
};

bonding_dont_create_bond0 =
{ name = "bonding-dont-create-bond0";
patch = ./bonding-dont-create-bond0.patch;
};

bridge_stp_helper =
{ name = "bridge-stp-helper";
patch = ./bridge-stp-helper.patch;
Expand Down
7 changes: 7 additions & 0 deletions pkgs/top-level/linux-kernels.nix
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ in {

linux_5_4 = callPackage ../os-specific/linux/kernel/linux-5.4.nix {
kernelPatches = [
kernelPatches.bonding_dont_create_bond0
kernelPatches.bridge_stp_helper
kernelPatches.request_key_helper
kernelPatches.rtl8761b_support
Expand All @@ -139,20 +140,23 @@ in {

linux_rt_5_4 = callPackage ../os-specific/linux/kernel/linux-rt-5.4.nix {
kernelPatches = [
kernelPatches.bonding_dont_create_bond0
kernelPatches.bridge_stp_helper
kernelPatches.request_key_helper
];
};

linux_5_10 = callPackage ../os-specific/linux/kernel/linux-5.10.nix {
kernelPatches = [
kernelPatches.bonding_dont_create_bond0
kernelPatches.bridge_stp_helper
kernelPatches.request_key_helper
];
};

linux_rt_5_10 = callPackage ../os-specific/linux/kernel/linux-rt-5.10.nix {
kernelPatches = [
kernelPatches.bonding_dont_create_bond0
kernelPatches.bridge_stp_helper
kernelPatches.request_key_helper
kernelPatches.export-rt-sched-migrate
Expand All @@ -161,13 +165,15 @@ in {

linux_5_15 = callPackage ../os-specific/linux/kernel/linux-5.15.nix {
kernelPatches = [
kernelPatches.bonding_dont_create_bond0
kernelPatches.bridge_stp_helper
kernelPatches.request_key_helper
];
};

linux_5_16 = callPackage ../os-specific/linux/kernel/linux-5.16.nix {
kernelPatches = [
kernelPatches.bonding_dont_create_bond0
kernelPatches.bridge_stp_helper
kernelPatches.request_key_helper
];
Expand All @@ -176,6 +182,7 @@ in {
linux_testing = let
testing = callPackage ../os-specific/linux/kernel/linux-testing.nix {
kernelPatches = [
kernelPatches.bonding_dont_create_bond0
kernelPatches.bridge_stp_helper
kernelPatches.request_key_helper
];
Expand Down

0 comments on commit 8640ecc

Please sign in to comment.