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,6 +398,7 @@ test_software (NMLinkType link_type, const char *link_typename)
|
|||||||
accept_signal (link_changed);
|
accept_signal (link_changed);
|
||||||
|
|
||||||
/* Set master option */
|
/* Set master option */
|
||||||
|
if (nmtstp_is_root_test ()) {
|
||||||
switch (link_type) {
|
switch (link_type) {
|
||||||
case NM_LINK_TYPE_BRIDGE:
|
case NM_LINK_TYPE_BRIDGE:
|
||||||
if (nmtstp_is_sysfs_writable ()) {
|
if (nmtstp_is_sysfs_writable ()) {
|
||||||
@@ -419,6 +420,7 @@ test_software (NMLinkType link_type, const char *link_typename)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Enslave and release */
|
/* Enslave and release */
|
||||||
switch (link_type) {
|
switch (link_type) {
|
||||||
|
Reference in New Issue
Block a user