From a313da882a81e2701e8e1d3c90212c0a71591558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20=C5=A0imerda?= Date: Fri, 26 Apr 2013 21:20:57 +0200 Subject: [PATCH] platform: suppress kernel's automatic creation of bond0 (rh #953466) Which it does whenever the 'bonding' module gets loaded no matter what name the user wants to give the new bond interface. Ported nm-system fix from commit 7cc95d8, using system() to avoid dependency on NM libs. Automatic test included. You have to run 'rmmod bonding' before testing to ensure that the module is not already inserted. Second run without rmmod always succeeds. --- src/platform/nm-linux-platform.c | 12 ++++++++++++ src/platform/tests/test-link.c | 13 ++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) 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: