summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBeniamino Galvani <bgalvani@redhat.com>2023-03-01 18:45:57 +0100
committerBeniamino Galvani <bgalvani@redhat.com>2023-03-01 23:51:22 +0100
commita7405b0892ad329aa3f3c7e84138d6f30caf3806 (patch)
tree9a34d167d9e52970fc5e4acab71d11ef2d3c355e
parent7ba9f94237cf0110a1e303847cc14a904633092d (diff)
downloadNetworkManager-a7405b0892ad329aa3f3c7e84138d6f30caf3806.tar.gz
platform: fix bridge test with fake platform
Fixes: 5afb323ed8d4 ('platform/tests: add test for nm_platform_link_set_bridge_info()') https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1552
-rw-r--r--src/core/platform/nm-fake-platform.c61
-rw-r--r--src/core/platform/tests/test-link.c52
2 files changed, 85 insertions, 28 deletions
diff --git a/src/core/platform/nm-fake-platform.c b/src/core/platform/nm-fake-platform.c
index c5ecd90ddf..0b9f62f638 100644
--- a/src/core/platform/nm-fake-platform.c
+++ b/src/core/platform/nm-fake-platform.c
@@ -278,6 +278,24 @@ link_add_pre(NMPlatform *platform,
return device;
}
+static void
+link_add_post(NMPlatform *self, NMFakePlatformLink *device)
+{
+ char path[128];
+
+ switch (device->obj->link.type) {
+ case NM_LINK_TYPE_BRIDGE:
+ nm_sprintf_buf(path, "/sys/class/net/%s/bridge/default_pvid", device->obj->link.name);
+ sysctl_set(self, NMP_SYSCTL_PATHID_ABSOLUTE(path), "1");
+
+ nm_sprintf_buf(path, "/sys/class/net/%s/bridge/vlan_filtering", device->obj->link.name);
+ sysctl_set(self, NMP_SYSCTL_PATHID_ABSOLUTE(path), "0");
+ break;
+ default:
+ break;
+ }
+}
+
static int
link_add(NMPlatform *platform,
NMLinkType type,
@@ -389,6 +407,7 @@ link_add(NMPlatform *platform,
*out_link = NMP_OBJECT_CAST_LINK(device->obj);
link_changed(platform, device, cache_op, NULL);
+ link_add_post(platform, device);
if (veth_peer)
link_changed(platform, device_veth, cache_op_veth, NULL);
@@ -441,6 +460,7 @@ link_add_one(NMPlatform *platform,
static gboolean
link_delete(NMPlatform *platform, int ifindex)
{
+ NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE(platform);
NMFakePlatformLink *device = link_get(platform, ifindex);
nm_auto_nmpobj const NMPObject *obj_old = NULL;
nm_auto_nmpobj const NMPObject *obj_old2 = NULL;
@@ -451,6 +471,17 @@ link_delete(NMPlatform *platform, int ifindex)
obj_old = g_steal_pointer(&device->obj);
+ if (obj_old->link.type == NM_LINK_TYPE_BRIDGE) {
+ char path[128];
+
+ g_hash_table_remove(
+ priv->options,
+ nm_sprintf_buf(path, "/sys/class/net/%s/bridge/default_pvid", obj_old->link.name));
+ g_hash_table_remove(
+ priv->options,
+ nm_sprintf_buf(path, "/sys/class/net/%s/bridge/vlan_filtering", obj_old->link.name));
+ }
+
cache_op = nmp_cache_remove(nm_platform_get_cache(platform), obj_old, FALSE, FALSE, &obj_old2);
g_assert(cache_op == NMP_CACHE_OPS_REMOVED);
g_assert(obj_old2);
@@ -725,6 +756,34 @@ link_vlan_change(NMPlatform *platform,
return FALSE;
}
+static gboolean
+link_set_bridge_info(NMPlatform *self,
+ int ifindex,
+ const NMPlatformLinkSetBridgeInfoData *bridge_info)
+{
+ NMFakePlatformLink *link;
+ char path[128];
+ char value[128];
+
+ link = link_get(self, ifindex);
+ if (!link)
+ return FALSE;
+
+ if (bridge_info->vlan_default_pvid_has) {
+ nm_sprintf_buf(path, "/sys/class/net/%s/bridge/default_pvid", link->obj->link.name);
+ nm_sprintf_buf(value, "%u", bridge_info->vlan_default_pvid_val);
+ sysctl_set(self, NMP_SYSCTL_PATHID_ABSOLUTE(path), value);
+ }
+
+ if (bridge_info->vlan_filtering_has) {
+ nm_sprintf_buf(path, "/sys/class/net/%s/bridge/vlan_filtering", link->obj->link.name);
+ nm_sprintf_buf(value, "%u", bridge_info->vlan_filtering_val);
+ sysctl_set(self, NMP_SYSCTL_PATHID_ABSOLUTE(path), value);
+ }
+
+ return TRUE;
+}
+
struct infiniband_add_data {
int parent;
int p_key;
@@ -1348,6 +1407,8 @@ nm_fake_platform_class_init(NMFakePlatformClass *klass)
platform_class->link_vlan_change = link_vlan_change;
+ platform_class->link_set_bridge_info = link_set_bridge_info;
+
platform_class->infiniband_partition_add = infiniband_partition_add;
platform_class->infiniband_partition_delete = infiniband_partition_delete;
diff --git a/src/core/platform/tests/test-link.c b/src/core/platform/tests/test-link.c
index 2a13deae6f..fd341b4c8b 100644
--- a/src/core/platform/tests/test-link.c
+++ b/src/core/platform/tests/test-link.c
@@ -36,6 +36,16 @@
#define _ADD_DUMMY(platform, name) \
g_assert(NMTST_NM_ERR_SUCCESS(nm_platform_link_dummy_add((platform), (name), NULL)))
+#define _sysctl_assert_eq(plat, path, value) \
+ G_STMT_START \
+ { \
+ gs_free char *_val = NULL; \
+ \
+ _val = nm_platform_sysctl_get(plat, NMP_SYSCTL_PATHID_ABSOLUTE(path)); \
+ g_assert_cmpstr(_val, ==, value); \
+ } \
+ G_STMT_END
+
static void
test_bogus(void)
{
@@ -673,19 +683,15 @@ test_bridge_addr(void)
b = nm_platform_link_set_bridge_info(NM_PLATFORM_GET, link.ifindex, &info_data);
g_assert(b);
- str = nm_platform_sysctl_master_get_option(NM_PLATFORM_GET, link.ifindex, "default_pvid");
- g_assert_cmpstr(str,
- ==,
- info_data.vlan_default_pvid_has
- ? nm_sprintf_buf(sbuf, "%u", info_data.vlan_default_pvid_val)
- : "1");
- nm_clear_g_free(&str);
+ _sysctl_assert_eq(NM_PLATFORM_GET,
+ "/sys/class/net/" DEVICE_NAME "/bridge/default_pvid",
+ info_data.vlan_default_pvid_has
+ ? nm_sprintf_buf(sbuf, "%u", info_data.vlan_default_pvid_val)
+ : "1");
- str = nm_platform_sysctl_master_get_option(NM_PLATFORM_GET, link.ifindex, "vlan_filtering");
- g_assert_cmpstr(str,
- ==,
- info_data.vlan_filtering_val && info_data.vlan_filtering_has ? "1" : "0");
- nm_clear_g_free(&str);
+ _sysctl_assert_eq(NM_PLATFORM_GET,
+ "/sys/class/net/" DEVICE_NAME "/bridge/vlan_filtering",
+ info_data.vlan_filtering_val && info_data.vlan_filtering_has ? "1" : "0");
info_data = (const NMPlatformLinkSetBridgeInfoData){
.vlan_default_pvid_val = 55,
@@ -696,13 +702,13 @@ test_bridge_addr(void)
b = nm_platform_link_set_bridge_info(NM_PLATFORM_GET, link.ifindex, &info_data);
g_assert(b);
- str = nm_platform_sysctl_master_get_option(NM_PLATFORM_GET, link.ifindex, "default_pvid");
- g_assert_cmpstr(str, ==, nm_sprintf_buf(sbuf, "%u", info_data.vlan_default_pvid_val));
- nm_clear_g_free(&str);
+ _sysctl_assert_eq(NM_PLATFORM_GET,
+ "/sys/class/net/" DEVICE_NAME "/bridge/default_pvid",
+ nm_sprintf_buf(sbuf, "%u", info_data.vlan_default_pvid_val));
- str = nm_platform_sysctl_master_get_option(NM_PLATFORM_GET, link.ifindex, "vlan_filtering");
- g_assert_cmpstr(str, ==, info_data.vlan_filtering_val ? "1" : "0");
- nm_clear_g_free(&str);
+ _sysctl_assert_eq(NM_PLATFORM_GET,
+ "/sys/class/net/" DEVICE_NAME "/bridge/vlan_filtering",
+ info_data.vlan_filtering_val ? "1" : "0");
nmtstp_link_delete(NULL, -1, link.ifindex, link.name, TRUE);
}
@@ -2932,16 +2938,6 @@ _check_sysctl_skip(void)
/*****************************************************************************/
-#define _sysctl_assert_eq(plat, path, value) \
- G_STMT_START \
- { \
- gs_free char *_val = NULL; \
- \
- _val = nm_platform_sysctl_get(plat, NMP_SYSCTL_PATHID_ABSOLUTE(path)); \
- g_assert_cmpstr(_val, ==, value); \
- } \
- G_STMT_END
-
static void
test_netns_general(gpointer fixture, gconstpointer test_data)
{