diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c index 89af928841..89d7f9eac4 100644 --- a/src/platform/nm-linux-platform.c +++ b/src/platform/nm-linux-platform.c @@ -829,6 +829,18 @@ build_rtnl_link (int ifindex, const char *name, NMLinkType type) static gboolean link_add (NMPlatform *platform, const char *name, NMLinkType type) { + if (type == NM_LINK_TYPE_BOND) { + /* When the kernel loads the bond module, either via explicit modprobe + * or automatically in response to creating a bond master, it will also + * create a 'bond0' interface. Since the bond we're about to create may + * or may not be named 'bond0' prevent potential confusion about a bond + * that the user didn't want by telling the bonding module not to create + * bond0 automatically. + */ + if (!g_file_test ("/sys/class/net/bonding_masters", G_FILE_TEST_EXISTS)) + system ("modprobe bonding max_bonds=0"); + } + return add_object (platform, build_rtnl_link (0, name, type)); } diff --git a/src/platform/tests/test-link.c b/src/platform/tests/test-link.c index 049dc97d98..c5a8ef6729 100644 --- a/src/platform/tests/test-link.c +++ b/src/platform/tests/test-link.c @@ -107,7 +107,18 @@ virtual_add (NMLinkType link_type, const char *name, SignalData *link_added, Sig case NM_LINK_TYPE_BRIDGE: return nm_platform_bridge_add (name); case NM_LINK_TYPE_BOND: - return nm_platform_bond_add (name); + { + gboolean bond0_exists = nm_platform_link_exists ("bond0"); + gboolean result = nm_platform_bond_add (name); + NMPlatformError error = nm_platform_get_error (); + + /* Check that bond0 is *not* automatically created. */ + if (!bond0_exists) + g_assert (!nm_platform_link_exists ("bond0")); + + nm_platform_set_error (error); + return result; + } case NM_LINK_TYPE_TEAM: return nm_platform_team_add (name); default: