platform: move reading sysctl-options for master/slave to NMPlatform
These functions are only helpers for accessing sysctl and independent from NMLinuxPlatform. Move their implementation to the base class.
This commit is contained in:
@@ -641,38 +641,6 @@ link_release (NMPlatform *platform, int master_idx, int slave_idx)
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
master_set_option (NMPlatform *platform, int master, const char *option, const char *value)
|
||||
{
|
||||
gs_free char *path = g_strdup_printf ("master:%d:%s", master, option);
|
||||
|
||||
return sysctl_set (platform, path, value);
|
||||
}
|
||||
|
||||
static char *
|
||||
master_get_option (NMPlatform *platform, int master, const char *option)
|
||||
{
|
||||
gs_free char *path = g_strdup_printf ("master:%d:%s", master, option);
|
||||
|
||||
return sysctl_get (platform, path);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
slave_set_option (NMPlatform *platform, int slave, const char *option, const char *value)
|
||||
{
|
||||
gs_free char *path = g_strdup_printf ("slave:%d:%s", slave, option);
|
||||
|
||||
return sysctl_set (platform, path, value);
|
||||
}
|
||||
|
||||
static char *
|
||||
slave_get_option (NMPlatform *platform, int slave, const char *option)
|
||||
{
|
||||
gs_free char *path = g_strdup_printf ("slave:%d:%s", slave, option);
|
||||
|
||||
return sysctl_get (platform, path);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
vlan_add (NMPlatform *platform, const char *name, int parent, int vlan_id, guint32 vlan_flags, const NMPlatformLink **out_link)
|
||||
{
|
||||
@@ -1478,10 +1446,6 @@ nm_fake_platform_class_init (NMFakePlatformClass *klass)
|
||||
|
||||
platform_class->link_enslave = link_enslave;
|
||||
platform_class->link_release = link_release;
|
||||
platform_class->master_set_option = master_set_option;
|
||||
platform_class->master_get_option = master_get_option;
|
||||
platform_class->slave_set_option = slave_set_option;
|
||||
platform_class->slave_get_option = slave_get_option;
|
||||
|
||||
platform_class->vlan_add = vlan_add;
|
||||
platform_class->link_vlan_change = link_vlan_change;
|
||||
|
@@ -4801,89 +4801,6 @@ link_release (NMPlatform *platform, int master, int slave)
|
||||
return link_enslave (platform, 0, slave);
|
||||
}
|
||||
|
||||
static char *
|
||||
link_option_path (NMPlatform *platform, int master, const char *category, const char *option)
|
||||
{
|
||||
const char *name = nm_platform_link_get_name (platform, master);
|
||||
|
||||
if (!name || !category || !option)
|
||||
return NULL;
|
||||
|
||||
return g_strdup_printf ("/sys/class/net/%s/%s/%s",
|
||||
ASSERT_VALID_PATH_COMPONENT (name),
|
||||
ASSERT_VALID_PATH_COMPONENT (category),
|
||||
ASSERT_VALID_PATH_COMPONENT (option));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
link_set_option (NMPlatform *platform, int master, const char *category, const char *option, const char *value)
|
||||
{
|
||||
gs_free char *path = link_option_path (platform, master, category, option);
|
||||
|
||||
return path && nm_platform_sysctl_set (platform, path, value);
|
||||
}
|
||||
|
||||
static char *
|
||||
link_get_option (NMPlatform *platform, int master, const char *category, const char *option)
|
||||
{
|
||||
gs_free char *path = link_option_path (platform, master, category, option);
|
||||
|
||||
return path ? nm_platform_sysctl_get (platform, path) : NULL;
|
||||
}
|
||||
|
||||
static const char *
|
||||
master_category (NMPlatform *platform, int master)
|
||||
{
|
||||
switch (nm_platform_link_get_type (platform, master)) {
|
||||
case NM_LINK_TYPE_BRIDGE:
|
||||
return "bridge";
|
||||
case NM_LINK_TYPE_BOND:
|
||||
return "bonding";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static const char *
|
||||
slave_category (NMPlatform *platform, int slave)
|
||||
{
|
||||
int master = nm_platform_link_get_master (platform, slave);
|
||||
|
||||
if (master <= 0)
|
||||
return NULL;
|
||||
|
||||
switch (nm_platform_link_get_type (platform, master)) {
|
||||
case NM_LINK_TYPE_BRIDGE:
|
||||
return "brport";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
master_set_option (NMPlatform *platform, int master, const char *option, const char *value)
|
||||
{
|
||||
return link_set_option (platform, master, master_category (platform, master), option, value);
|
||||
}
|
||||
|
||||
static char *
|
||||
master_get_option (NMPlatform *platform, int master, const char *option)
|
||||
{
|
||||
return link_get_option (platform, master, master_category (platform, master), option);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
slave_set_option (NMPlatform *platform, int slave, const char *option, const char *value)
|
||||
{
|
||||
return link_set_option (platform, slave, slave_category (platform, slave), option, value);
|
||||
}
|
||||
|
||||
static char *
|
||||
slave_get_option (NMPlatform *platform, int slave, const char *option)
|
||||
{
|
||||
return link_get_option (platform, slave, slave_category (platform, slave), option);
|
||||
}
|
||||
|
||||
/******************************************************************/
|
||||
|
||||
static gboolean
|
||||
@@ -5967,10 +5884,6 @@ nm_linux_platform_class_init (NMLinuxPlatformClass *klass)
|
||||
|
||||
platform_class->link_enslave = link_enslave;
|
||||
platform_class->link_release = link_release;
|
||||
platform_class->master_set_option = master_set_option;
|
||||
platform_class->master_get_option = master_get_option;
|
||||
platform_class->slave_set_option = slave_set_option;
|
||||
platform_class->slave_get_option = slave_get_option;
|
||||
|
||||
platform_class->vlan_add = vlan_add;
|
||||
platform_class->link_vlan_change = link_vlan_change;
|
||||
|
@@ -1636,6 +1636,67 @@ nm_platform_link_tun_add (NMPlatform *self,
|
||||
return NM_PLATFORM_ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static char *
|
||||
link_option_path (NMPlatform *self, int master, const char *category, const char *option)
|
||||
{
|
||||
const char *name = nm_platform_link_get_name (self, master);
|
||||
|
||||
if (!name || !category || !option)
|
||||
return NULL;
|
||||
|
||||
return g_strdup_printf ("/sys/class/net/%s/%s/%s",
|
||||
ASSERT_VALID_PATH_COMPONENT (name),
|
||||
ASSERT_VALID_PATH_COMPONENT (category),
|
||||
ASSERT_VALID_PATH_COMPONENT (option));
|
||||
}
|
||||
|
||||
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, 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, path) : NULL;
|
||||
}
|
||||
|
||||
static const char *
|
||||
master_category (NMPlatform *self, int master)
|
||||
{
|
||||
switch (nm_platform_link_get_type (self, master)) {
|
||||
case NM_LINK_TYPE_BRIDGE:
|
||||
return "bridge";
|
||||
case NM_LINK_TYPE_BOND:
|
||||
return "bonding";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
static const char *
|
||||
slave_category (NMPlatform *self, int slave)
|
||||
{
|
||||
int master = nm_platform_link_get_master (self, slave);
|
||||
|
||||
if (master <= 0)
|
||||
return NULL;
|
||||
|
||||
switch (nm_platform_link_get_type (self, master)) {
|
||||
case NM_LINK_TYPE_BRIDGE:
|
||||
return "brport";
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
gboolean
|
||||
nm_platform_sysctl_master_set_option (NMPlatform *self, int ifindex, const char *option, const char *value)
|
||||
{
|
||||
@@ -1644,9 +1705,8 @@ nm_platform_sysctl_master_set_option (NMPlatform *self, int ifindex, const char
|
||||
g_return_val_if_fail (ifindex > 0, FALSE);
|
||||
g_return_val_if_fail (option, FALSE);
|
||||
g_return_val_if_fail (value, FALSE);
|
||||
g_return_val_if_fail (klass->master_set_option, FALSE);
|
||||
|
||||
return klass->master_set_option (self, ifindex, option, value);
|
||||
return link_set_option (self, ifindex, master_category (self, ifindex), option, value);
|
||||
}
|
||||
|
||||
char *
|
||||
@@ -1656,9 +1716,8 @@ nm_platform_sysctl_master_get_option (NMPlatform *self, int ifindex, const char
|
||||
|
||||
g_return_val_if_fail (ifindex > 0, FALSE);
|
||||
g_return_val_if_fail (option, FALSE);
|
||||
g_return_val_if_fail (klass->master_set_option, FALSE);
|
||||
|
||||
return klass->master_get_option (self, ifindex, option);
|
||||
return link_get_option (self, ifindex, master_category (self, ifindex), option);
|
||||
}
|
||||
|
||||
gboolean
|
||||
@@ -1669,9 +1728,8 @@ nm_platform_sysctl_slave_set_option (NMPlatform *self, int ifindex, const char *
|
||||
g_return_val_if_fail (ifindex > 0, FALSE);
|
||||
g_return_val_if_fail (option, FALSE);
|
||||
g_return_val_if_fail (value, FALSE);
|
||||
g_return_val_if_fail (klass->slave_set_option, FALSE);
|
||||
|
||||
return klass->slave_set_option (self, ifindex, option, value);
|
||||
return link_set_option (self, ifindex, slave_category (self, ifindex), option, value);
|
||||
}
|
||||
|
||||
char *
|
||||
@@ -1681,11 +1739,12 @@ nm_platform_sysctl_slave_get_option (NMPlatform *self, int ifindex, const char *
|
||||
|
||||
g_return_val_if_fail (ifindex > 0, FALSE);
|
||||
g_return_val_if_fail (option, FALSE);
|
||||
g_return_val_if_fail (klass->slave_set_option, FALSE);
|
||||
|
||||
return klass->slave_get_option (self, ifindex, option);
|
||||
return link_get_option (self, ifindex, slave_category (self, ifindex), option);
|
||||
}
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
gboolean
|
||||
nm_platform_link_vlan_change (NMPlatform *self,
|
||||
int ifindex,
|
||||
|
@@ -545,10 +545,6 @@ typedef struct {
|
||||
|
||||
gboolean (*link_enslave) (NMPlatform *, int master, int slave);
|
||||
gboolean (*link_release) (NMPlatform *, int master, int slave);
|
||||
gboolean (*master_set_option) (NMPlatform *, int ifindex, const char *option, const char *value);
|
||||
char * (*master_get_option) (NMPlatform *, int ifindex, const char *option);
|
||||
gboolean (*slave_set_option) (NMPlatform *, int ifindex, const char *option, const char *value);
|
||||
char * (*slave_get_option) (NMPlatform *, int ifindex, const char *option);
|
||||
|
||||
gboolean (*vlan_add) (NMPlatform *, const char *name, int parent, int vlanid, guint32 vlanflags, const NMPlatformLink **out_link);
|
||||
gboolean (*link_vlan_change) (NMPlatform *self,
|
||||
|
Reference in New Issue
Block a user