summaryrefslogtreecommitdiff
path: root/src/nm-core-utils.c
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2017-10-23 13:55:54 +0200
committerThomas Haller <thaller@redhat.com>2017-10-24 16:05:40 +0200
commit32b3eb11814e522e18800d0d402d84d170a6f456 (patch)
tree33b069feee84ce60ece5fd807deb54797abd15bb /src/nm-core-utils.c
parent6e01238a407ac546bf20fd23998b28cde672aeba (diff)
downloadNetworkManager-32b3eb11814e522e18800d0d402d84d170a6f456.tar.gz
core: merge IPv4 and IPv6 implementation of nm_utils_ip4_property_path()
and nm_utils_ip6_property_path(). Also, rename to nm_utils_sysctl_ip_conf_path().
Diffstat (limited to 'src/nm-core-utils.c')
-rw-r--r--src/nm-core-utils.c62
1 files changed, 19 insertions, 43 deletions
diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c
index 2325283e6d..bf8d50e18e 100644
--- a/src/nm-core-utils.c
+++ b/src/nm-core-utils.c
@@ -2525,65 +2525,41 @@ nm_utils_monotonic_timestamp_as_boottime (gint64 timestamp, gint64 timestamp_ns_
#define IPV6_PROPERTY_DIR "/proc/sys/net/ipv6/conf/"
#define IPV4_PROPERTY_DIR "/proc/sys/net/ipv4/conf/"
G_STATIC_ASSERT (sizeof (IPV4_PROPERTY_DIR) == sizeof (IPV6_PROPERTY_DIR));
-G_STATIC_ASSERT (NM_STRLEN (IPV6_PROPERTY_DIR) + IFNAMSIZ + 60 == NM_UTILS_IP_PROPERTY_PATH_BUFSIZE);
+G_STATIC_ASSERT (NM_STRLEN (IPV6_PROPERTY_DIR) + IFNAMSIZ + 60 == NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE);
-static const char *
-_get_property_path (char *buf,
- const char *ifname,
- const char *property,
- gboolean ipv6)
+/**
+ * nm_utils_sysctl_ip_conf_path:
+ * @addr_family: either AF_INET or AF_INET6.
+ * @buf: the output buffer where to write the path. It
+ * must be at least NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE bytes
+ * long.
+ * @ifname: an interface name
+ * @property: a property name
+ *
+ * Returns: the path to IPv6 property @property on @ifname. Note that
+ * this returns the input argument @buf.
+ */
+const char *
+nm_utils_sysctl_ip_conf_path (int addr_family, char *buf, const char *ifname, const char *property)
{
int len;
nm_assert (buf);
+ nm_assert_addr_family (addr_family);
ifname = NM_ASSERT_VALID_PATH_COMPONENT (ifname);
property = NM_ASSERT_VALID_PATH_COMPONENT (property);
len = g_snprintf (buf,
- NM_UTILS_IP_PROPERTY_PATH_BUFSIZE,
+ NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE,
"%s%s/%s",
- ipv6 ? IPV6_PROPERTY_DIR : IPV4_PROPERTY_DIR,
+ addr_family == AF_INET6 ? IPV6_PROPERTY_DIR : IPV4_PROPERTY_DIR,
ifname,
property);
- g_assert (len < NM_UTILS_IP_PROPERTY_PATH_BUFSIZE - 1);
+ g_assert (len < NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE - 1);
return buf;
}
-/**
- * nm_utils_ip6_property_path:
- * @buf: the output buffer where to write the path. It
- * must be at least NM_UTILS_IP_PROPERTY_PATH_BUFSIZE bytes
- * long.
- * @ifname: an interface name
- * @property: a property name
- *
- * Returns: the path to IPv6 property @property on @ifname. Note that
- * this returns the input argument @buf.
- */
-const char *
-nm_utils_ip6_property_path (char *buf, const char *ifname, const char *property)
-{
- return _get_property_path (buf, ifname, property, TRUE);
-}
-
-/**
- * nm_utils_ip4_property_path:
- * @buf: the output buffer where to write the path. It
- * must be at least NM_UTILS_IP_PROPERTY_PATH_BUFSIZE bytes
- * long.
- * @ifname: an interface name
- * @property: a property name
- *
- * Returns: the path to IPv6 property @property on @ifname. Note that
- * this returns the input argument @buf.
- */
-const char *
-nm_utils_ip4_property_path (char *buf, const char *ifname, const char *property)
-{
- return _get_property_path (buf, ifname, property, FALSE);
-}
-
gboolean
nm_utils_is_valid_path_component (const char *name)
{