summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-01-14 15:07:46 +0100
committerThomas Haller <thaller@redhat.com>2018-01-15 20:29:26 +0100
commitd7025818123631e893948f389ab2ec428359b238 (patch)
tree2340790f6e447eb3086488439265a30dabace965
parent9562d886336ff07f07ce4a9445da08e677d18b5c (diff)
platform: move netlink functions to nm-netlink.h
-rw-r--r--src/platform/nm-linux-platform.c34
-rw-r--r--src/platform/nm-netlink.h44
-rw-r--r--src/platform/wifi/wifi-utils-nl80211.c21
3 files changed, 46 insertions, 53 deletions
diff --git a/src/platform/nm-linux-platform.c b/src/platform/nm-linux-platform.c
index e90c93a039..0128362864 100644
--- a/src/platform/nm-linux-platform.c
+++ b/src/platform/nm-linux-platform.c
@@ -37,14 +37,13 @@
#include <linux/if_tun.h>
#include <linux/if_tunnel.h>
#include <linux/ip6_tunnel.h>
-#include <netlink/netlink.h>
-#include <netlink/msg.h>
#include <libudev.h>
#include "nm-utils.h"
#include "nm-core-internal.h"
#include "nm-setting-vlan.h"
+#include "nm-netlink.h"
#include "nm-core-utils.h"
#include "nmp-object.h"
#include "nmp-netns.h"
@@ -952,13 +951,6 @@ _nl_addattr_l (struct nlmsghdr *n,
return TRUE;
}
-static void
-_nm_auto_nl_msg_cleanup (void *ptr)
-{
- nlmsg_free (*((struct nl_msg **) ptr));
-}
-#define nm_auto_nlmsg nm_auto(_nm_auto_nl_msg_cleanup)
-
static const char *
_nl_nlmsghdr_to_str (const struct nlmsghdr *hdr, char *buf, gsize len)
{
@@ -1059,30 +1051,6 @@ flags_done:
return b;
}
-static int
-_nl_nla_parse (struct nlattr *tb[], int maxtype, struct nlattr *head, int len,
- const struct nla_policy *policy)
-{
- return nla_parse (tb, maxtype, head, len, (struct nla_policy *) policy);
-}
-#define nla_parse(...) _nl_nla_parse(__VA_ARGS__)
-
-static int
-_nl_nlmsg_parse (struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[],
- int maxtype, const struct nla_policy *policy)
-{
- return nlmsg_parse (nlh, hdrlen, tb, maxtype, (struct nla_policy *) policy);
-}
-#define nlmsg_parse(...) _nl_nlmsg_parse(__VA_ARGS__)
-
-static int
-_nl_nla_parse_nested (struct nlattr *tb[], int maxtype, struct nlattr *nla,
- const struct nla_policy *policy)
-{
- return nla_parse_nested (tb, maxtype, nla, (struct nla_policy *) policy);
-}
-#define nla_parse_nested(...) _nl_nla_parse_nested(__VA_ARGS__)
-
/******************************************************************
* NMPObject/netlink functions
******************************************************************/
diff --git a/src/platform/nm-netlink.h b/src/platform/nm-netlink.h
index e001c5fdaa..f94e6de7ea 100644
--- a/src/platform/nm-netlink.h
+++ b/src/platform/nm-netlink.h
@@ -21,4 +21,48 @@
#ifndef __NM_NETLINK_H__
#define __NM_NETLINK_H__
+#include <netlink/msg.h>
+#include <netlink/attr.h>
+
+/*****************************************************************************
+ * libnl3 compat code
+ *****************************************************************************/
+
+static inline int
+_nl_nla_parse (struct nlattr *tb[], int maxtype, struct nlattr *head, int len,
+ const struct nla_policy *policy)
+{
+ return nla_parse (tb, maxtype, head, len, (struct nla_policy *) policy);
+}
+#define nla_parse(...) _nl_nla_parse(__VA_ARGS__)
+
+static inline int
+_nl_nlmsg_parse (struct nlmsghdr *nlh, int hdrlen, struct nlattr *tb[],
+ int maxtype, const struct nla_policy *policy)
+{
+ return nlmsg_parse (nlh, hdrlen, tb, maxtype, (struct nla_policy *) policy);
+}
+#define nlmsg_parse(...) _nl_nlmsg_parse(__VA_ARGS__)
+
+static inline int
+_nl_nla_parse_nested (struct nlattr *tb[], int maxtype, struct nlattr *nla,
+ const struct nla_policy *policy)
+{
+ return nla_parse_nested (tb, maxtype, nla, (struct nla_policy *) policy);
+}
+#define nla_parse_nested(...) _nl_nla_parse_nested(__VA_ARGS__)
+
+/*****************************************************************************
+ * helpers
+ *****************************************************************************/
+
+static inline void
+_nm_auto_nl_msg_cleanup (struct nl_msg **ptr)
+{
+ nlmsg_free (*ptr);
+}
+#define nm_auto_nlmsg nm_auto(_nm_auto_nl_msg_cleanup)
+
+/*****************************************************************************/
+
#endif /* __NM_NETLINK_H__ */
diff --git a/src/platform/wifi/wifi-utils-nl80211.c b/src/platform/wifi/wifi-utils-nl80211.c
index 35bd415114..6125461175 100644
--- a/src/platform/wifi/wifi-utils-nl80211.c
+++ b/src/platform/wifi/wifi-utils-nl80211.c
@@ -29,10 +29,9 @@
#include <sys/ioctl.h>
#include <net/ethernet.h>
#include <unistd.h>
-#include <netlink/netlink.h>
-#include <netlink/msg.h>
#include <linux/nl80211.h>
+#include "platform/nm-netlink.h"
#include "wifi-utils-private.h"
#include "platform/nm-platform.h"
#include "platform/nm-platform-utils.h"
@@ -47,24 +46,6 @@
_NM_UTILS_MACRO_REST(__VA_ARGS__)); \
} G_STMT_END
-/*****************************************************************************/
-
-static int
-_nl_nla_parse (struct nlattr *tb[], int maxtype, struct nlattr *head, int len,
- const struct nla_policy *policy)
-{
- return nla_parse (tb, maxtype, head, len, (struct nla_policy *) policy);
-}
-#define nla_parse(...) _nl_nla_parse(__VA_ARGS__)
-
-static int
-_nl_nla_parse_nested (struct nlattr *tb[], int maxtype, struct nlattr *nla,
- const struct nla_policy *policy)
-{
- return nla_parse_nested (tb, maxtype, nla, (struct nla_policy *) policy);
-}
-#define nla_parse_nested(...) _nl_nla_parse_nested(__VA_ARGS__)
-
/*****************************************************************************
* Copied from libnl3/genl:
*****************************************************************************/