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 *
|
static gboolean
|
||||||
link_option_path (NMPlatform *self, int master, const char *category, const char *option)
|
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 NULL;
|
||||||
|
|
||||||
return g_strdup_printf ("/sys/class/net/%s/%s/%s",
|
dirfd = nm_platform_sysctl_open_netdir (self, ifindex, ifname_verified);
|
||||||
NM_ASSERT_VALID_PATH_COMPONENT (name),
|
if (dirfd < 0)
|
||||||
NM_ASSERT_VALID_PATH_COMPONENT (category),
|
return NULL;
|
||||||
NM_ASSERT_VALID_PATH_COMPONENT (option));
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
path = nm_sprintf_bufa (strlen (category) + strlen (option) + 2,
|
||||||
link_set_option (NMPlatform *self, int master, const char *category, const char *option, const char *value)
|
"%s/%s",
|
||||||
{
|
category, option);
|
||||||
gs_free char *path = link_option_path (self, master, category, option);
|
return nm_platform_sysctl_get (self, NMP_SYSCTL_PATHID_NETDIR_unsafe (dirfd, ifname_verified, path));
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static const char *
|
||||||
|
@@ -398,26 +398,28 @@ test_software (NMLinkType link_type, const char *link_typename)
|
|||||||
accept_signal (link_changed);
|
accept_signal (link_changed);
|
||||||
|
|
||||||
/* Set master option */
|
/* Set master option */
|
||||||
switch (link_type) {
|
if (nmtstp_is_root_test ()) {
|
||||||
case NM_LINK_TYPE_BRIDGE:
|
switch (link_type) {
|
||||||
if (nmtstp_is_sysfs_writable ()) {
|
case NM_LINK_TYPE_BRIDGE:
|
||||||
g_assert (nm_platform_sysctl_master_set_option (NM_PLATFORM_GET, ifindex, "forward_delay", "628"));
|
if (nmtstp_is_sysfs_writable ()) {
|
||||||
value = nm_platform_sysctl_master_get_option (NM_PLATFORM_GET, ifindex, "forward_delay");
|
g_assert (nm_platform_sysctl_master_set_option (NM_PLATFORM_GET, ifindex, "forward_delay", "628"));
|
||||||
g_assert_cmpstr (value, ==, "628");
|
value = nm_platform_sysctl_master_get_option (NM_PLATFORM_GET, ifindex, "forward_delay");
|
||||||
g_free (value);
|
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 */
|
/* Enslave and release */
|
||||||
|
Reference in New Issue
Block a user