From 7ec587bcdc8bcf916c1eef876cb71b5eaae45f93 Mon Sep 17 00:00:00 2001 From: Andre Puschmann Date: Mon, 29 Apr 2019 17:35:09 +0200 Subject: [PATCH] backport support for ipv6 for older glibc --- CMakeLists.txt | 6 ++++++ srsue/src/upper/gw.cc | 36 ++++++++++++++++++++++++++++++++++-- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 32b68080a..73c3613cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -81,6 +81,7 @@ option(ENABLE_MSAN "Enable clang memory sanitizer" OFF) option(ENABLE_TIDY "Enable clang tidy" OFF) option(USE_LTE_RATES "Use standard LTE sampling rates" OFF) +option(USE_GLIBC_IPV6 "Use glibc's own ipv6.h" ON) set(GCC_ARCH native CACHE STRING "GCC compile for specific architecture.") @@ -301,6 +302,11 @@ if(CMAKE_C_COMPILER_ID MATCHES "GNU" OR CMAKE_C_COMPILER_ID MATCHES "Clang") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFORCE_STANDARD_RATE") endif (USE_LTE_RATES) + if (USE_GLIBC_IPV6) + message(STATUS "Using default glibc header for IPv6 support.") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_GLIBC_IPV6") + endif (USE_GLIBC_IPV6) + find_package(SSE) if (HAVE_AVX2) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=${GCC_ARCH} -mfpmath=sse -mavx2 -DLV_HAVE_AVX2 -DLV_HAVE_AVX -DLV_HAVE_SSE") diff --git a/srsue/src/upper/gw.cc b/srsue/src/upper/gw.cc index cf4f3e571..21753828b 100644 --- a/srsue/src/upper/gw.cc +++ b/srsue/src/upper/gw.cc @@ -24,15 +24,47 @@ #include #include #include -#include #include -#include #include #include #include #include #include +#ifdef USE_GLIBC_IPV6 +#include +#else +// Some versions of glibc yield to a compile error with gcc +// complaining about a redefinition of struct in6_pktinfo. See [1]. +// Since we only need two structs from that header we define them here and +// just don't include the entire file. See [1] for more information. +// +// [1] https://patchwork.ozlabs.org/patch/425881/ +struct ipv6hdr { +#if defined(__LITTLE_ENDIAN_BITFIELD) + __u8 priority : 4, version : 4; +#elif defined(__BIG_ENDIAN_BITFIELD) + __u8 version : 4, priority : 4; +#else +#error "Please fix " +#endif + __u8 flow_lbl[3]; + + __be16 payload_len; + __u8 nexthdr; + __u8 hop_limit; + + struct in6_addr saddr; + struct in6_addr daddr; +}; + +struct in6_ifreq { + struct in6_addr ifr6_addr; + __u32 ifr6_prefixlen; + int ifr6_ifindex; +}; +#endif + namespace srsue { gw::gw()