124 lines
4.2 KiB
Diff
124 lines
4.2 KiB
Diff
From abb7391f38893af7d6108f97ac8597468f113a41 Mon Sep 17 00:00:00 2001
|
|
From: Thomas Haller <thaller@redhat.com>
|
|
Date: Wed, 15 Apr 2020 12:42:05 +0200
|
|
Subject: [PATCH] lib: add "include/netlink-private/nl-auto.h" header
|
|
|
|
Conflict:NA
|
|
Reference:https://github.com/thom311/libnl/commit/abb7391f38893af7d6108f97ac8597468f113a41
|
|
|
|
---
|
|
Makefile.am | 1 +
|
|
include/netlink-private/nl-auto.h | 60 +++++++++++++++++++++++++++++++
|
|
include/netlink-private/utils.h | 14 ++------
|
|
3 files changed, 63 insertions(+), 12 deletions(-)
|
|
create mode 100644 include/netlink-private/nl-auto.h
|
|
|
|
diff --git a/Makefile.am b/Makefile.am
|
|
index b2e87379..085da53f 100644
|
|
--- a/Makefile.am
|
|
+++ b/Makefile.am
|
|
@@ -261,6 +261,7 @@ noinst_HEADERS = \
|
|
include/netlink-private/cache-api.h \
|
|
include/netlink-private/genl.h \
|
|
include/netlink-private/netlink.h \
|
|
+ include/netlink-private/nl-auto.h \
|
|
include/netlink-private/object-api.h \
|
|
include/netlink-private/route/link/api.h \
|
|
include/netlink-private/route/link/sriov.h \
|
|
diff --git a/include/netlink-private/nl-auto.h b/include/netlink-private/nl-auto.h
|
|
new file mode 100644
|
|
index 00000000..7b923f26
|
|
--- /dev/null
|
|
+++ b/include/netlink-private/nl-auto.h
|
|
@@ -0,0 +1,60 @@
|
|
+// SPDX-License-Identifier: LGPL-2.1+
|
|
+
|
|
+#ifndef NETLINK_NL_AUTO_H_
|
|
+#define NETLINK_NL_AUTO_H_
|
|
+
|
|
+#define _nl_auto(fcn) __attribute__ ((__cleanup__(fcn)))
|
|
+
|
|
+#define _NL_AUTO_DEFINE_FCN_VOID0(CastType, name, func) \
|
|
+static inline void name(void *v) \
|
|
+{ \
|
|
+ if (*((CastType *) v)) \
|
|
+ func(*((CastType *) v)); \
|
|
+}
|
|
+
|
|
+#define _NL_AUTO_DEFINE_FCN_TYPED0(CastType, name, func) \
|
|
+static inline void name(CastType *v) \
|
|
+{ \
|
|
+ if (*v) \
|
|
+ func(*v); \
|
|
+}
|
|
+
|
|
+#define _nl_auto_free _nl_auto(_nl_auto_free_fcn)
|
|
+_NL_AUTO_DEFINE_FCN_VOID0(void *, _nl_auto_free_fcn, free)
|
|
+
|
|
+struct nl_addr;
|
|
+void nl_addr_put(struct nl_addr *);
|
|
+#define _nl_auto_nl_addr _nl_auto(_nl_auto_nl_addr_fcn)
|
|
+_NL_AUTO_DEFINE_FCN_TYPED0(struct nl_addr *, _nl_auto_nl_addr_fcn, nl_addr_put)
|
|
+
|
|
+struct nl_msg;
|
|
+void nlmsg_free(struct nl_msg *);
|
|
+#define _nl_auto_nl_msg _nl_auto(_nl_auto_nl_msg_fcn)
|
|
+_NL_AUTO_DEFINE_FCN_TYPED0(struct nl_msg *, _nl_auto_nl_msg_fcn, nlmsg_free)
|
|
+
|
|
+struct rtnl_link;
|
|
+void rtnl_link_put(struct rtnl_link *);
|
|
+#define _nl_auto_rtnl_link _nl_auto(_nl_auto_rtnl_link_fcn)
|
|
+_NL_AUTO_DEFINE_FCN_TYPED0(struct rtnl_link *, _nl_auto_rtnl_link_fcn, rtnl_link_put)
|
|
+
|
|
+struct rtnl_route;
|
|
+void rtnl_route_put(struct rtnl_route *);
|
|
+#define _nl_auto_rtnl_route _nl_auto(_nl_auto_rtnl_route_fcn)
|
|
+_NL_AUTO_DEFINE_FCN_TYPED0(struct rtnl_route *, _nl_auto_rtnl_route_fcn, rtnl_route_put)
|
|
+
|
|
+struct rtnl_nexthop;
|
|
+void rtnl_route_nh_free(struct rtnl_nexthop *);
|
|
+#define _nl_auto_rtnl_nexthop _nl_auto(_nl_auto_rtnl_nexthop_fcn)
|
|
+_NL_AUTO_DEFINE_FCN_TYPED0(struct rtnl_nexthop *, _nl_auto_rtnl_nexthop_fcn, rtnl_route_nh_free)
|
|
+
|
|
+struct nl_cache;
|
|
+void nl_cache_put(struct nl_cache *);
|
|
+#define _nl_auto_nl_cache _nl_auto(_nl_auto_nl_cache_fcn)
|
|
+_NL_AUTO_DEFINE_FCN_TYPED0(struct nl_cache *, _nl_auto_nl_cache_fcn, nl_cache_put)
|
|
+
|
|
+struct rtnl_link_af_ops;
|
|
+void rtnl_link_af_ops_put(struct rtnl_link_af_ops *);
|
|
+#define _nl_auto_rtnl_link_af_ops _nl_auto(_nl_auto_rtnl_link_af_ops_fcn)
|
|
+_NL_AUTO_DEFINE_FCN_TYPED0(struct rtnl_link_af_ops *, _nl_auto_rtnl_link_af_ops_fcn, rtnl_link_af_ops_put)
|
|
+
|
|
+#endif /* NETLINK_NL_AUTO_H_ */
|
|
diff --git a/include/netlink-private/utils.h b/include/netlink-private/utils.h
|
|
index 9c5a3d82..46e77451 100644
|
|
--- a/include/netlink-private/utils.h
|
|
+++ b/include/netlink-private/utils.h
|
|
@@ -85,18 +85,6 @@
|
|
|
|
/*****************************************************************************/
|
|
|
|
-#define _NL_AUTO_DEFINE_FCN_VOID0(CastType, name, func) \
|
|
-static inline void name (void *v) \
|
|
-{ \
|
|
- if (*((CastType *) v)) \
|
|
- func (*((CastType *) v)); \
|
|
-}
|
|
-
|
|
-#define _nl_auto_free _nl_auto(_nl_auto_free_fcn)
|
|
-_NL_AUTO_DEFINE_FCN_VOID0 (void *, _nl_auto_free_fcn, free)
|
|
-
|
|
-/*****************************************************************************/
|
|
-
|
|
extern const char *nl_strerror_l(int err);
|
|
|
|
/*****************************************************************************/
|
|
@@ -222,4 +210,6 @@ _nl_strncpy(char *dst, const char *src, size_t len)
|
|
return dst;
|
|
}
|
|
|
|
+#include "nl-auto.h"
|
|
+
|
|
#endif
|