mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-05 08:48:07 +02:00
platform: fix bridge test with fake platform
Fixes: 5afb323ed8 ('platform/tests: add test for nm_platform_link_set_bridge_info()')
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1552
This commit is contained in:
parent
7ba9f94237
commit
a7405b0892
2 changed files with 85 additions and 28 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue