core: use nmp_utils_sysctl_open_netdir() for platform master/slave options
This commit is contained in:
@@ -1708,34 +1708,44 @@ nm_platform_link_tun_add (NMPlatform *self,
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static char *
|
||||
link_option_path (NMPlatform *self, int master, const char *category, const char *option)
|
||||
static gboolean
|
||||
link_set_option (NMPlatform *self, int ifindex, const char *category, const char *option, const char *value)
|
||||
{
|
||||
const char *name = nm_platform_link_get_name (self, master);
|
||||
nm_auto_close int dirfd = -1;
|
||||
char ifname_verified[IFNAMSIZ];
|
||||
const char *path;
|
||||
|
||||
if (!name || !category || !option)
|
||||
if (!category || !option)
|
||||
return FALSE;
|
||||
|
||||
dirfd = nm_platform_sysctl_open_netdir (self, ifindex, ifname_verified);
|
||||
if (dirfd < 0)
|
||||
return FALSE;
|
||||
|
||||
path = nm_sprintf_bufa (strlen (category) + strlen (option) + 2,
|
||||
"%s/%s",
|
||||
category, option);
|
||||
return nm_platform_sysctl_set (self, NMP_SYSCTL_PATHID_NETDIR_unsafe (dirfd, ifname_verified, path), value);
|
||||
}
|
||||
|
||||
static char *
|
||||
link_get_option (NMPlatform *self, int ifindex, const char *category, const char *option)
|
||||
{
|
||||
nm_auto_close int dirfd = -1;
|
||||
char ifname_verified[IFNAMSIZ];
|
||||
const char *path;
|
||||
|
||||
if (!category || !option)
|
||||
return NULL;
|
||||
|
||||
return g_strdup_printf ("/sys/class/net/%s/%s/%s",
|
||||
NM_ASSERT_VALID_PATH_COMPONENT (name),
|
||||
NM_ASSERT_VALID_PATH_COMPONENT (category),
|
||||
NM_ASSERT_VALID_PATH_COMPONENT (option));
|
||||
}
|
||||
dirfd = nm_platform_sysctl_open_netdir (self, ifindex, ifname_verified);
|
||||
if (dirfd < 0)
|
||||
return NULL;
|
||||
|
||||
static gboolean
|
||||
link_set_option (NMPlatform *self, int master, const char *category, const char *option, const char *value)
|
||||
{
|
||||
gs_free char *path = link_option_path (self, master, category, option);
|
||||
|
||||
return path && nm_platform_sysctl_set (self, NMP_SYSCTL_PATHID_ABSOLUTE (path), value);
|
||||
}
|
||||
|
||||
static char *
|
||||
link_get_option (NMPlatform *self, int master, const char *category, const char *option)
|
||||
{
|
||||
gs_free char *path = link_option_path (self, master, category, option);
|
||||
|
||||
return path ? nm_platform_sysctl_get (self, NMP_SYSCTL_PATHID_ABSOLUTE (path)) : NULL;
|
||||
path = nm_sprintf_bufa (strlen (category) + strlen (option) + 2,
|
||||
"%s/%s",
|
||||
category, option);
|
||||
return nm_platform_sysctl_get (self, NMP_SYSCTL_PATHID_NETDIR_unsafe (dirfd, ifname_verified, path));
|
||||
}
|
||||
|
||||
static const char *
|
||||
|
@@ -398,26 +398,28 @@ test_software (NMLinkType link_type, const char *link_typename)
|
||||
accept_signal (link_changed);
|
||||
|
||||
/* Set master option */
|
||||
switch (link_type) {
|
||||
case NM_LINK_TYPE_BRIDGE:
|
||||
if (nmtstp_is_sysfs_writable ()) {
|
||||
g_assert (nm_platform_sysctl_master_set_option (NM_PLATFORM_GET, ifindex, "forward_delay", "628"));
|
||||
value = nm_platform_sysctl_master_get_option (NM_PLATFORM_GET, ifindex, "forward_delay");
|
||||
g_assert_cmpstr (value, ==, "628");
|
||||
g_free (value);
|
||||
if (nmtstp_is_root_test ()) {
|
||||
switch (link_type) {
|
||||
case NM_LINK_TYPE_BRIDGE:
|
||||
if (nmtstp_is_sysfs_writable ()) {
|
||||
g_assert (nm_platform_sysctl_master_set_option (NM_PLATFORM_GET, ifindex, "forward_delay", "628"));
|
||||
value = nm_platform_sysctl_master_get_option (NM_PLATFORM_GET, ifindex, "forward_delay");
|
||||
g_assert_cmpstr (value, ==, "628");
|
||||
g_free (value);
|
||||
}
|
||||
break;
|
||||
case NM_LINK_TYPE_BOND:
|
||||
if (nmtstp_is_sysfs_writable ()) {
|
||||
g_assert (nm_platform_sysctl_master_set_option (NM_PLATFORM_GET, ifindex, "mode", "active-backup"));
|
||||
value = nm_platform_sysctl_master_get_option (NM_PLATFORM_GET, ifindex, "mode");
|
||||
/* When reading back, the output looks slightly different. */
|
||||
g_assert (g_str_has_prefix (value, "active-backup"));
|
||||
g_free (value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case NM_LINK_TYPE_BOND:
|
||||
if (nmtstp_is_sysfs_writable ()) {
|
||||
g_assert (nm_platform_sysctl_master_set_option (NM_PLATFORM_GET, ifindex, "mode", "active-backup"));
|
||||
value = nm_platform_sysctl_master_get_option (NM_PLATFORM_GET, ifindex, "mode");
|
||||
/* When reading back, the output looks slightly different. */
|
||||
g_assert (g_str_has_prefix (value, "active-backup"));
|
||||
g_free (value);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
/* Enslave and release */
|
||||
|
Reference in New Issue
Block a user