Repository: mesos Updated Branches: refs/heads/master a31d81f11 -> f751e3b6b
Fixed compiler errors in routing library when an old glibc is used. Review: https://reviews.apache.org/r/21822 Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/fe1e63e1 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/fe1e63e1 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/fe1e63e1 Branch: refs/heads/master Commit: fe1e63e137746c7b54ff369335b8e2dd5685e97b Parents: a31d81f Author: Jie Yu <yujie....@gmail.com> Authored: Thu May 22 11:41:40 2014 -0700 Committer: Jie Yu <yujie....@gmail.com> Committed: Fri May 23 14:46:02 2014 -0700 ---------------------------------------------------------------------- src/linux/routing/filter/arp.cpp | 9 +++++++-- src/linux/routing/filter/icmp.cpp | 9 +++++++-- src/linux/routing/filter/ip.cpp | 9 +++++++-- src/linux/routing/internal.hpp | 16 ++++++++-------- src/linux/routing/route.cpp | 3 +-- src/tests/routing_tests.cpp | 5 +++-- 6 files changed, 33 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/fe1e63e1/src/linux/routing/filter/arp.cpp ---------------------------------------------------------------------- diff --git a/src/linux/routing/filter/arp.cpp b/src/linux/routing/filter/arp.cpp index 3f37a83..c18aebb 100644 --- a/src/linux/routing/filter/arp.cpp +++ b/src/linux/routing/filter/arp.cpp @@ -16,8 +16,6 @@ * limitations under the License. */ -#include <linux/if_ether.h> - #include <netlink/errno.h> #include <netlink/route/tc.h> @@ -62,6 +60,13 @@ struct Classifier namespace internal { +// This is a work around. Including <linux/if_ether.h> causes +// duplicated definitions on some platforms with old glibc. +#ifndef ETH_P_ARP +#define ETH_P_ARP 0x0806 +#endif + + // Encodes the ARP classifier into the libnl filter 'cls'. Each type // of classifier needs to implement this function. template <> http://git-wip-us.apache.org/repos/asf/mesos/blob/fe1e63e1/src/linux/routing/filter/icmp.cpp ---------------------------------------------------------------------- diff --git a/src/linux/routing/filter/icmp.cpp b/src/linux/routing/filter/icmp.cpp index 31a7332..8e6f013 100644 --- a/src/linux/routing/filter/icmp.cpp +++ b/src/linux/routing/filter/icmp.cpp @@ -20,8 +20,6 @@ #include <arpa/inet.h> -#include <linux/if_ether.h> - #include <netlink/errno.h> #include <netlink/route/tc.h> @@ -53,6 +51,13 @@ namespace filter { namespace internal { +// This is a work around. Including <linux/if_ether.h> causes +// duplicated definitions on some platforms with old glibc. +#ifndef ETH_P_IP +#define ETH_P_IP 0x0800 +#endif + + // Encodes the ICMP classifier into the libnl filter 'cls'. Each type // of classifier needs to implement this function. template <> http://git-wip-us.apache.org/repos/asf/mesos/blob/fe1e63e1/src/linux/routing/filter/ip.cpp ---------------------------------------------------------------------- diff --git a/src/linux/routing/filter/ip.cpp b/src/linux/routing/filter/ip.cpp index 24f3d52..86dbf35 100644 --- a/src/linux/routing/filter/ip.cpp +++ b/src/linux/routing/filter/ip.cpp @@ -16,8 +16,6 @@ * limitations under the License. */ -#include <linux/if_ether.h> - #include <netlink/errno.h> #include <netlink/route/tc.h> @@ -49,6 +47,13 @@ namespace filter { namespace internal { +// This is a work around. Including <linux/if_ether.h> causes +// duplicated definitions on some platforms with old glibc. +#ifndef ETH_P_IP +#define ETH_P_IP 0x0800 +#endif + + // Encodes the IP classifier into the libnl filter 'cls'. Each type of // classifier needs to implement this function. template <> http://git-wip-us.apache.org/repos/asf/mesos/blob/fe1e63e1/src/linux/routing/internal.hpp ---------------------------------------------------------------------- diff --git a/src/linux/routing/internal.hpp b/src/linux/routing/internal.hpp index 8971840..dca0dc5 100644 --- a/src/linux/routing/internal.hpp +++ b/src/linux/routing/internal.hpp @@ -38,6 +38,14 @@ 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); } + + // A helper class for managing netlink objects (e.g., rtnl_link, // nl_sock, etc.). It manages the life cycle of a netlink object. It // is copyable and assignable, and multiple copies share the same @@ -72,14 +80,6 @@ private: }; -// 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); } - - // Returns a netlink socket for communicating with the kernel. This // socket is needed for most of the operations. inline Try<Netlink<struct nl_sock> > socket() http://git-wip-us.apache.org/repos/asf/mesos/blob/fe1e63e1/src/linux/routing/route.cpp ---------------------------------------------------------------------- diff --git a/src/linux/routing/route.cpp b/src/linux/routing/route.cpp index 6e3ec0f..234027e 100644 --- a/src/linux/routing/route.cpp +++ b/src/linux/routing/route.cpp @@ -18,13 +18,12 @@ #include <stdint.h> -#include <linux/rtnetlink.h> - #include <netinet/in.h> #include <netlink/addr.h> #include <netlink/cache.h> #include <netlink/errno.h> +#include <netlink/netlink.h> #include <netlink/object.h> #include <netlink/socket.h> http://git-wip-us.apache.org/repos/asf/mesos/blob/fe1e63e1/src/tests/routing_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/routing_tests.cpp b/src/tests/routing_tests.cpp index e435a7c..0e8f61a 100644 --- a/src/tests/routing_tests.cpp +++ b/src/tests/routing_tests.cpp @@ -231,6 +231,9 @@ TEST_F(RoutingVethTest, ROOT_LinkRemove) } +// Network namespace is not available until Linux 2.6.24. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) + // Entry point of the child process (used in clone()). static int child(void*) { @@ -246,8 +249,6 @@ static int child(void*) } -// Network namespace is not available until Linux 2.6.24. -#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24) TEST_F(RoutingVethTest, ROOT_LinkCreatePid) { // Stack used in the child process.