utils: more flexible reading of /proc/sys/net
- changes nm_utils_get_proc_sys_net_value() to allow all values, not just 0,1 - adds nm_utils_get_proc_sys_net_value_with_bounds() for limiting valid values
This commit is contained in:
@@ -848,7 +848,7 @@ nm_utils_do_sysctl (const char *path, const char *value)
|
|||||||
gboolean
|
gboolean
|
||||||
nm_utils_get_proc_sys_net_value (const char *path,
|
nm_utils_get_proc_sys_net_value (const char *path,
|
||||||
const char *iface,
|
const char *iface,
|
||||||
guint32 *out_value)
|
gint32 *out_value)
|
||||||
{
|
{
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
char *contents = NULL;
|
char *contents = NULL;
|
||||||
@@ -864,8 +864,8 @@ nm_utils_get_proc_sys_net_value (const char *path,
|
|||||||
} else {
|
} else {
|
||||||
errno = 0;
|
errno = 0;
|
||||||
tmp = strtol (contents, NULL, 10);
|
tmp = strtol (contents, NULL, 10);
|
||||||
if ((errno == 0) && (tmp == 0 || tmp == 1)) {
|
if (errno == 0) {
|
||||||
*out_value = (guint32) tmp;
|
*out_value = (gint32) tmp;
|
||||||
success = TRUE;
|
success = TRUE;
|
||||||
}
|
}
|
||||||
g_free (contents);
|
g_free (contents);
|
||||||
@@ -874,6 +874,28 @@ nm_utils_get_proc_sys_net_value (const char *path,
|
|||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gboolean
|
||||||
|
nm_utils_get_proc_sys_net_value_with_bounds (const char *path,
|
||||||
|
const char *iface,
|
||||||
|
gint32 *out_value,
|
||||||
|
gint32 valid_min,
|
||||||
|
gint32 valid_max)
|
||||||
|
{
|
||||||
|
gboolean result;
|
||||||
|
gint32 val;
|
||||||
|
|
||||||
|
result = nm_utils_get_proc_sys_net_value (path, iface, &val);
|
||||||
|
|
||||||
|
if (result) {
|
||||||
|
if (val >= valid_min && val <= valid_max)
|
||||||
|
*out_value = val;
|
||||||
|
else
|
||||||
|
result = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
get_new_connection_name (const GSList *existing,
|
get_new_connection_name (const GSList *existing,
|
||||||
const char *format,
|
const char *format,
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*
|
*
|
||||||
* Copyright (C) 2004 - 2010 Red Hat, Inc.
|
* Copyright (C) 2004 - 2011 Red Hat, Inc.
|
||||||
* Copyright (C) 2005 - 2008 Novell, Inc.
|
* Copyright (C) 2005 - 2008 Novell, Inc.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -83,7 +83,13 @@ gboolean nm_utils_do_sysctl (const char *path, const char *value);
|
|||||||
|
|
||||||
gboolean nm_utils_get_proc_sys_net_value (const char *path,
|
gboolean nm_utils_get_proc_sys_net_value (const char *path,
|
||||||
const char *iface,
|
const char *iface,
|
||||||
guint32 *out_value);
|
gint32 *out_value);
|
||||||
|
|
||||||
|
gboolean nm_utils_get_proc_sys_net_value_with_bounds (const char *path,
|
||||||
|
const char *iface,
|
||||||
|
gint32 *out_value,
|
||||||
|
gint32 valid_min,
|
||||||
|
gint32 valid_max);
|
||||||
|
|
||||||
void nm_utils_complete_generic (NMConnection *connection,
|
void nm_utils_complete_generic (NMConnection *connection,
|
||||||
const char *ctype,
|
const char *ctype,
|
||||||
|
@@ -91,7 +91,7 @@ typedef struct {
|
|||||||
|
|
||||||
char *disable_ip6_path;
|
char *disable_ip6_path;
|
||||||
gboolean disable_ip6_save_valid;
|
gboolean disable_ip6_save_valid;
|
||||||
guint32 disable_ip6_save;
|
gint32 disable_ip6_save;
|
||||||
|
|
||||||
guint finish_addrconf_id;
|
guint finish_addrconf_id;
|
||||||
guint config_changed_id;
|
guint config_changed_id;
|
||||||
@@ -185,9 +185,10 @@ nm_ip6_device_new (NMIP6Manager *manager, int ifindex)
|
|||||||
device->disable_ip6_path = g_strdup_printf ("/proc/sys/net/ipv6/conf/%s/disable_ipv6",
|
device->disable_ip6_path = g_strdup_printf ("/proc/sys/net/ipv6/conf/%s/disable_ipv6",
|
||||||
device->iface);
|
device->iface);
|
||||||
g_assert (device->disable_ip6_path);
|
g_assert (device->disable_ip6_path);
|
||||||
device->disable_ip6_save_valid = nm_utils_get_proc_sys_net_value (device->disable_ip6_path,
|
device->disable_ip6_save_valid = nm_utils_get_proc_sys_net_value_with_bounds (device->disable_ip6_path,
|
||||||
device->iface,
|
device->iface,
|
||||||
&device->disable_ip6_save);
|
&device->disable_ip6_save,
|
||||||
|
0, 1);
|
||||||
|
|
||||||
return device;
|
return device;
|
||||||
|
|
||||||
|
@@ -204,7 +204,7 @@ typedef struct {
|
|||||||
NMIP6Config * ac_ip6_config;
|
NMIP6Config * ac_ip6_config;
|
||||||
|
|
||||||
char * ip6_accept_ra_path;
|
char * ip6_accept_ra_path;
|
||||||
guint32 ip6_accept_ra_save;
|
gint32 ip6_accept_ra_save;
|
||||||
|
|
||||||
NMDHCPClient * dhcp6_client;
|
NMDHCPClient * dhcp6_client;
|
||||||
guint32 dhcp6_mode;
|
guint32 dhcp6_mode;
|
||||||
@@ -281,9 +281,10 @@ update_accept_ra_save (NMDevice *self)
|
|||||||
|
|
||||||
/* Grab the original value of "accept_ra" so we can restore it when NM exits */
|
/* Grab the original value of "accept_ra" so we can restore it when NM exits */
|
||||||
priv->ip6_accept_ra_path = new_path;
|
priv->ip6_accept_ra_path = new_path;
|
||||||
if (!nm_utils_get_proc_sys_net_value (priv->ip6_accept_ra_path,
|
if (!nm_utils_get_proc_sys_net_value_with_bounds (priv->ip6_accept_ra_path,
|
||||||
ip_iface,
|
ip_iface,
|
||||||
&priv->ip6_accept_ra_save)) {
|
&priv->ip6_accept_ra_save,
|
||||||
|
0, 1)) {
|
||||||
g_free (priv->ip6_accept_ra_path);
|
g_free (priv->ip6_accept_ra_path);
|
||||||
priv->ip6_accept_ra_path = NULL;
|
priv->ip6_accept_ra_path = NULL;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user