core: use nmp_utils_sysctl_open_netdir() to read tun/tap sysctl
This commit is contained in:
@@ -80,7 +80,7 @@ reload_tun_properties (NMDeviceTun *self)
|
|||||||
|
|
||||||
ifindex = nm_device_get_ifindex (NM_DEVICE (self));
|
ifindex = nm_device_get_ifindex (NM_DEVICE (self));
|
||||||
if (ifindex > 0) {
|
if (ifindex > 0) {
|
||||||
if (!nm_platform_link_tun_get_properties (NM_PLATFORM_GET, ifindex, &props)) {
|
if (!nm_platform_link_tun_get_properties (NM_PLATFORM_GET, ifindex, NULL, &props)) {
|
||||||
_LOGD (LOGD_DEVICE, "tun-properties: cannot loading tun properties from platform for ifindex %d", ifindex);
|
_LOGD (LOGD_DEVICE, "tun-properties: cannot loading tun properties from platform for ifindex %d", ifindex);
|
||||||
ifindex = 0;
|
ifindex = 0;
|
||||||
} else if (g_strcmp0 (priv->mode, props.mode) != 0) {
|
} else if (g_strcmp0 (priv->mode, props.mode) != 0) {
|
||||||
@@ -181,7 +181,7 @@ update_connection (NMDevice *device, NMConnection *connection)
|
|||||||
nm_connection_add_setting (connection, (NMSetting *) s_tun);
|
nm_connection_add_setting (connection, (NMSetting *) s_tun);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!nm_platform_link_tun_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (device), &props)) {
|
if (!nm_platform_link_tun_get_properties (NM_PLATFORM_GET, nm_device_get_ifindex (device), NULL, &props)) {
|
||||||
_LOGW (LOGD_PLATFORM, "failed to get TUN interface info while updating connection.");
|
_LOGW (LOGD_PLATFORM, "failed to get TUN interface info while updating connection.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@@ -656,7 +656,7 @@ _linktype_get_type (NMPlatform *platform,
|
|||||||
NMPlatformTunProperties props;
|
NMPlatformTunProperties props;
|
||||||
|
|
||||||
if ( platform
|
if ( platform
|
||||||
&& nm_platform_link_tun_get_properties_ifname (platform, ifname, &props)) {
|
&& nm_platform_link_tun_get_properties (platform, ifindex, ifname ?: "", &props)) {
|
||||||
if (!g_strcmp0 (props.mode, "tap"))
|
if (!g_strcmp0 (props.mode, "tap"))
|
||||||
return NM_LINK_TYPE_TAP;
|
return NM_LINK_TYPE_TAP;
|
||||||
if (!g_strcmp0 (props.mode, "tun"))
|
if (!g_strcmp0 (props.mode, "tun"))
|
||||||
|
@@ -2259,74 +2259,59 @@ nm_platform_link_veth_get_properties (NMPlatform *self, int ifindex, int *out_pe
|
|||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
nm_platform_link_tun_get_properties_ifname (NMPlatform *self, const char *ifname, NMPlatformTunProperties *props)
|
nm_platform_link_tun_get_properties (NMPlatform *self, int ifindex, const char *ifname_guess, NMPlatformTunProperties *props)
|
||||||
{
|
{
|
||||||
char path[256];
|
nm_auto_close int dirfd = -1;
|
||||||
char *val;
|
const char *ifname;
|
||||||
|
char ifname_verified[IFNAMSIZ];
|
||||||
|
gint64 flags;
|
||||||
gboolean success = TRUE;
|
gboolean success = TRUE;
|
||||||
|
|
||||||
_CHECK_SELF (self, klass, FALSE);
|
_CHECK_SELF (self, klass, FALSE);
|
||||||
|
|
||||||
|
g_return_val_if_fail (ifindex > 0, FALSE);
|
||||||
g_return_val_if_fail (props, FALSE);
|
g_return_val_if_fail (props, FALSE);
|
||||||
|
|
||||||
|
/* ifname_guess is an optional argument to find a guess for the ifname corresponding to
|
||||||
|
* ifindex. */
|
||||||
|
if (!ifname_guess) {
|
||||||
|
/* if NULL, obtain the guess from the platform cache. */
|
||||||
|
ifname = nm_platform_link_get_name (self, ifindex);
|
||||||
|
} else if (!ifname_guess[0]) {
|
||||||
|
/* if empty, don't use a guess. That means to use if_indextoname(). */
|
||||||
|
ifname = NULL;
|
||||||
|
} else
|
||||||
|
ifname = ifname_guess;
|
||||||
|
|
||||||
memset (props, 0, sizeof (*props));
|
memset (props, 0, sizeof (*props));
|
||||||
props->owner = -1;
|
props->owner = -1;
|
||||||
props->group = -1;
|
props->group = -1;
|
||||||
|
|
||||||
if (!ifname || !nm_utils_iface_valid_name (ifname))
|
dirfd = nm_platform_sysctl_open_netdir (self, ifindex, ifname_verified);
|
||||||
|
if (dirfd < 0)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
nm_sprintf_buf (path, "/sys/class/net/%s/owner", ifname);
|
ifname = ifname_verified;
|
||||||
val = nm_platform_sysctl_get (self, NMP_SYSCTL_PATHID_ABSOLUTE (path));
|
|
||||||
if (val) {
|
props->owner = nm_platform_sysctl_get_int_checked (self, NMP_SYSCTL_PATHID_NETDIR (dirfd, ifname, "owner"), 10, -1, G_MAXINT64, -1);
|
||||||
props->owner = _nm_utils_ascii_str_to_int64 (val, 10, -1, G_MAXINT64, -1);
|
|
||||||
if (errno)
|
if (errno)
|
||||||
success = FALSE;
|
success = FALSE;
|
||||||
g_free (val);
|
|
||||||
} else
|
|
||||||
success = FALSE;
|
|
||||||
|
|
||||||
nm_sprintf_buf (path, "/sys/class/net/%s/group", ifname);
|
props->group = nm_platform_sysctl_get_int_checked (self, NMP_SYSCTL_PATHID_NETDIR (dirfd, ifname, "group"), 10, -1, G_MAXINT64, -1);
|
||||||
val = nm_platform_sysctl_get (self, NMP_SYSCTL_PATHID_ABSOLUTE (path));
|
|
||||||
if (val) {
|
|
||||||
props->group = _nm_utils_ascii_str_to_int64 (val, 10, -1, G_MAXINT64, -1);
|
|
||||||
if (errno)
|
if (errno)
|
||||||
success = FALSE;
|
success = FALSE;
|
||||||
g_free (val);
|
|
||||||
} else
|
|
||||||
success = FALSE;
|
|
||||||
|
|
||||||
nm_sprintf_buf (path, "/sys/class/net/%s/tun_flags", ifname);
|
flags = nm_platform_sysctl_get_int_checked (self, NMP_SYSCTL_PATHID_NETDIR (dirfd, ifname, "tun_flags"), 16, 0, G_MAXINT64, -1);
|
||||||
val = nm_platform_sysctl_get (self, NMP_SYSCTL_PATHID_ABSOLUTE (path));
|
if (flags >= 0) {
|
||||||
if (val) {
|
|
||||||
gint64 flags;
|
|
||||||
|
|
||||||
flags = _nm_utils_ascii_str_to_int64 (val, 16, 0, G_MAXINT64, 0);
|
|
||||||
if (!errno) {
|
|
||||||
props->mode = ((flags & (IFF_TUN | IFF_TAP)) == IFF_TUN) ? "tun" : "tap";
|
props->mode = ((flags & (IFF_TUN | IFF_TAP)) == IFF_TUN) ? "tun" : "tap";
|
||||||
props->no_pi = !!(flags & IFF_NO_PI);
|
props->no_pi = !!(flags & IFF_NO_PI);
|
||||||
props->vnet_hdr = !!(flags & IFF_VNET_HDR);
|
props->vnet_hdr = !!(flags & IFF_VNET_HDR);
|
||||||
props->multi_queue = !!(flags & NM_IFF_MULTI_QUEUE);
|
props->multi_queue = !!(flags & NM_IFF_MULTI_QUEUE);
|
||||||
} else
|
} else
|
||||||
success = FALSE;
|
success = FALSE;
|
||||||
g_free (val);
|
|
||||||
} else
|
|
||||||
success = FALSE;
|
|
||||||
|
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
|
||||||
nm_platform_link_tun_get_properties (NMPlatform *self, int ifindex, NMPlatformTunProperties *props)
|
|
||||||
{
|
|
||||||
_CHECK_SELF (self, klass, FALSE);
|
|
||||||
|
|
||||||
g_return_val_if_fail (ifindex > 0, FALSE);
|
|
||||||
g_return_val_if_fail (props != NULL, FALSE);
|
|
||||||
|
|
||||||
return nm_platform_link_tun_get_properties_ifname (self, nm_platform_link_get_name (self, ifindex), props);
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
nm_platform_wifi_get_capabilities (NMPlatform *self, int ifindex, NMDeviceWifiCapabilities *caps)
|
nm_platform_wifi_get_capabilities (NMPlatform *self, int ifindex, NMDeviceWifiCapabilities *caps)
|
||||||
{
|
{
|
||||||
|
@@ -865,9 +865,7 @@ NMPlatformError nm_platform_link_infiniband_delete (NMPlatform *self,
|
|||||||
gboolean nm_platform_link_infiniband_get_properties (NMPlatform *self, int ifindex, int *parent, int *p_key, const char **mode);
|
gboolean nm_platform_link_infiniband_get_properties (NMPlatform *self, int ifindex, int *parent, int *p_key, const char **mode);
|
||||||
|
|
||||||
gboolean nm_platform_link_veth_get_properties (NMPlatform *self, int ifindex, int *out_peer_ifindex);
|
gboolean nm_platform_link_veth_get_properties (NMPlatform *self, int ifindex, int *out_peer_ifindex);
|
||||||
gboolean nm_platform_link_tun_get_properties (NMPlatform *self, int ifindex, NMPlatformTunProperties *properties);
|
gboolean nm_platform_link_tun_get_properties (NMPlatform *self, int ifindex, const char *ifname_guess, NMPlatformTunProperties *properties);
|
||||||
|
|
||||||
gboolean nm_platform_link_tun_get_properties_ifname (NMPlatform *platform, const char *ifname, NMPlatformTunProperties *props);
|
|
||||||
|
|
||||||
gboolean nm_platform_wifi_get_capabilities (NMPlatform *self, int ifindex, NMDeviceWifiCapabilities *caps);
|
gboolean nm_platform_wifi_get_capabilities (NMPlatform *self, int ifindex, NMDeviceWifiCapabilities *caps);
|
||||||
gboolean nm_platform_wifi_get_bssid (NMPlatform *self, int ifindex, guint8 *bssid);
|
gboolean nm_platform_wifi_get_bssid (NMPlatform *self, int ifindex, guint8 *bssid);
|
||||||
|
Reference in New Issue
Block a user