Moved netlink cleanup functions to separate files. This is another effort to allow linking with a lower version of libnl. This patch moved cleanup functions into their specific files.
Review: https://reviews.apache.org/r/49835 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/c1bd3a54 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/c1bd3a54 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/c1bd3a54 Branch: refs/heads/master Commit: c1bd3a54175204a5218e03224031ee933fe8974d Parents: b419633 Author: Jie Yu <yujie....@gmail.com> Authored: Fri Jul 8 15:31:32 2016 -0700 Committer: Jie Yu <yujie....@gmail.com> Committed: Mon Jul 11 11:27:37 2016 -0700 ---------------------------------------------------------------------- src/linux/routing/diagnosis/diagnosis.cpp | 9 +++++++-- src/linux/routing/diagnosis/diagnosis.hpp | 3 --- src/linux/routing/filter/internal.hpp | 7 +++++++ src/linux/routing/internal.hpp | 28 +++++++++++++++----------- src/linux/routing/link/internal.hpp | 7 +++++++ src/linux/routing/queueing/internal.hpp | 7 +++++++ 6 files changed, 44 insertions(+), 17 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/c1bd3a54/src/linux/routing/diagnosis/diagnosis.cpp ---------------------------------------------------------------------- diff --git a/src/linux/routing/diagnosis/diagnosis.cpp b/src/linux/routing/diagnosis/diagnosis.cpp index ce54697..aa2d020 100644 --- a/src/linux/routing/diagnosis/diagnosis.cpp +++ b/src/linux/routing/diagnosis/diagnosis.cpp @@ -29,8 +29,14 @@ using namespace std; namespace routing { -namespace diagnosis { +template <> +inline void cleanup(struct idiagnl_msg* msg) +{ + idiagnl_msg_put(msg); +} + +namespace diagnosis { namespace socket { static Option<net::IP> IP(nl_addr* _ip) @@ -82,6 +88,5 @@ Try<vector<Info>> infos(int family, int states) } } // namespace socket { - } // namespace diagnosis { } // namespace routing { http://git-wip-us.apache.org/repos/asf/mesos/blob/c1bd3a54/src/linux/routing/diagnosis/diagnosis.hpp ---------------------------------------------------------------------- diff --git a/src/linux/routing/diagnosis/diagnosis.hpp b/src/linux/routing/diagnosis/diagnosis.hpp index 447f342..7722fd2 100644 --- a/src/linux/routing/diagnosis/diagnosis.hpp +++ b/src/linux/routing/diagnosis/diagnosis.hpp @@ -29,9 +29,7 @@ namespace routing { namespace diagnosis { - namespace socket { - namespace state { // The different connection states of a socket. @@ -103,7 +101,6 @@ struct Info Try<std::vector<Info>> infos(int familiy, int states); } // namespace socket { - } // namespace diagnosis { } // namespace routing { http://git-wip-us.apache.org/repos/asf/mesos/blob/c1bd3a54/src/linux/routing/filter/internal.hpp ---------------------------------------------------------------------- diff --git a/src/linux/routing/filter/internal.hpp b/src/linux/routing/filter/internal.hpp index 6c174e1..dc4b8f9 100644 --- a/src/linux/routing/filter/internal.hpp +++ b/src/linux/routing/filter/internal.hpp @@ -59,6 +59,13 @@ #include "linux/routing/link/internal.hpp" namespace routing { + +template <> +inline void cleanup(struct rtnl_cls* cls) +{ + rtnl_cls_put(cls); +} + namespace filter { namespace internal { http://git-wip-us.apache.org/repos/asf/mesos/blob/c1bd3a54/src/linux/routing/internal.hpp ---------------------------------------------------------------------- diff --git a/src/linux/routing/internal.hpp b/src/linux/routing/internal.hpp index 9396346..132f62e 100644 --- a/src/linux/routing/internal.hpp +++ b/src/linux/routing/internal.hpp @@ -22,12 +22,6 @@ #include <netlink/netlink.h> #include <netlink/socket.h> -#include <netlink/idiag/msg.h> - -#include <netlink/route/classifier.h> -#include <netlink/route/link.h> -#include <netlink/route/qdisc.h> - #include <memory> #include <string> @@ -39,12 +33,22 @@ namespace routing { // Customized deallocation functions for netlink objects. -inline void cleanup(struct nl_cache* cache) { nl_cache_free(cache); } -inline void cleanup(struct nl_sock* sock) { nl_socket_free(sock); } -inline void cleanup(struct rtnl_cls* cls) { rtnl_cls_put(cls); } -inline void cleanup(struct rtnl_link* link) { rtnl_link_put(link); } -inline void cleanup(struct rtnl_qdisc* qdisc) { rtnl_qdisc_put(qdisc); } -inline void cleanup(struct idiagnl_msg* msg) { idiagnl_msg_put(msg); } +template <typename T> +void cleanup(T* t); + + +template <> +inline void cleanup(struct nl_cache* cache) +{ + nl_cache_free(cache); +} + + +template <> +inline void cleanup(struct nl_sock* sock) +{ + nl_socket_free(sock); +} // A helper class for managing netlink objects (e.g., rtnl_link, http://git-wip-us.apache.org/repos/asf/mesos/blob/c1bd3a54/src/linux/routing/link/internal.hpp ---------------------------------------------------------------------- diff --git a/src/linux/routing/link/internal.hpp b/src/linux/routing/link/internal.hpp index eb89b9a..551ffda 100644 --- a/src/linux/routing/link/internal.hpp +++ b/src/linux/routing/link/internal.hpp @@ -42,6 +42,13 @@ #include "linux/routing/internal.hpp" namespace routing { + +template <> +inline void cleanup(struct rtnl_link* link) +{ + rtnl_link_put(link); +} + namespace link { namespace internal { http://git-wip-us.apache.org/repos/asf/mesos/blob/c1bd3a54/src/linux/routing/queueing/internal.hpp ---------------------------------------------------------------------- diff --git a/src/linux/routing/queueing/internal.hpp b/src/linux/routing/queueing/internal.hpp index 151d1b1..9fe522e 100644 --- a/src/linux/routing/queueing/internal.hpp +++ b/src/linux/routing/queueing/internal.hpp @@ -45,6 +45,13 @@ #include "linux/routing/queueing/statistics.hpp" namespace routing { + +template <> +inline void cleanup(struct rtnl_qdisc* qdisc) +{ + rtnl_qdisc_put(qdisc); +} + namespace queueing { namespace internal {