Skip to content

Commit

Permalink
Fix namespace collision with musl if_ether.h
Browse files Browse the repository at this point in the history
Using musl libc headers there is a namespace collision between
netinet/if_ether.h and linux/if_ether.h. This commit incorporates
a workaround.

Signed-off-by: Quentin Armitage <quentin@armitage.org.uk>
  • Loading branch information
pqarmitage committed Apr 23, 2018
1 parent d8d0661 commit afc4508
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
30 changes: 30 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -9165,6 +9165,36 @@ fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
CPPFLAGS="$SAV_CPPFLAGS"

# Including <linux/if_ether.h> and <netinet/if_ether.h> can cause a namespace collision (musl libc).
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for linux/if_ether.h and netinet/if_ether.h namespace collision" >&5
$as_echo_n "checking for linux/if_ether.h and netinet/if_ether.h namespace collision... " >&6; }
SAV_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $kernelinc"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <linux/if_ether.h>
#include <netinet/if_ether.h>
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :

{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }

else

{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }

$as_echo "#define _HAVE_NETINET_LINUX_IF_ETHER_H_COLLISION_ 1 " >>confdefs.h

BUILD_OPTIONS="$BUILD_OPTIONS NETINET_LINUX_IF_ETHER_H_COLLISION"

fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
CPPFLAGS="$SAV_CPPFLAGS"

# Linux 4.5 to 4.5.4 has <libiptc/libiptc.h> indirectly including <net/if.h>
# and <linux/if.h> which causes a namespace collision.
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for libiptc/libiptc.h linux/if.h and net/if.h namespace collision" >&5
Expand Down
19 changes: 19 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,25 @@ AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
])
CPPFLAGS="$SAV_CPPFLAGS"
dnl ----[Check if have linux/if_ether.h and netinet/if_ether.h namespace collision]----
# Including <linux/if_ether.h> and <netinet/if_ether.h> can cause a namespace collision (musl libc).
AC_MSG_CHECKING([for linux/if_ether.h and netinet/if_ether.h namespace collision])
SAV_CPPFLAGS="$CPPFLAGS"
CPPFLAGS="$CPPFLAGS $kernelinc"
AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
#include <linux/if_ether.h>
#include <netinet/if_ether.h>
]])],
[
AC_MSG_RESULT([no])
],
[
AC_MSG_RESULT([yes])
AC_DEFINE([_HAVE_NETINET_LINUX_IF_ETHER_H_COLLISION_], [ 1 ], [Define to 1 if have linux/if_ether.h followed by netinet/if_ether.h namespace collision])
add_build_opt([NETINET_LINUX_IF_ETHER_H_COLLISION])
])
CPPFLAGS="$SAV_CPPFLAGS"
# Linux 4.5 to 4.5.4 has <libiptc/libiptc.h> indirectly including <net/if.h>
# and <linux/if.h> which causes a namespace collision.
AC_MSG_CHECKING([for libiptc/libiptc.h linux/if.h and net/if.h namespace collision])
Expand Down
4 changes: 4 additions & 0 deletions keepalived/include/vrrp_arp.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

/* system includes */
#include <netinet/in.h>
#ifdef _HAVE_NET_LINUX_IF_H_COLLISION_
#define _NETINET_IF_ETHER_H
#include <linux/if_ether.h>
#endif
#include <net/ethernet.h>
#include <net/if_arp.h>
#include <linux/if_infiniband.h>
Expand Down
4 changes: 4 additions & 0 deletions keepalived/include/vrrp_vmac.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#include <arpa/inet.h>
#include <string.h>
#include <syslog.h>
#ifdef _HAVE_NET_LINUX_IF_H_COLLISION_
#define _NETINET_IF_ETHER_H
#include <linux/if_ether.h>
#endif
#include <net/ethernet.h>

/* local includes */
Expand Down
4 changes: 4 additions & 0 deletions lib/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,10 @@
/* Define to 1 if using libnl-3 */
#undef _HAVE_LIBNL3_

/* Define to 1 if have linux/if_ether.h followed by netinet/if_ether.h
namespace collision */
#undef _HAVE_NETINET_LINUX_IF_ETHER_H_COLLISION_

/* Define to 1 if have linux/if.h followed by net/if.h namespace collision */
#undef _HAVE_NET_LINUX_IF_H_COLLISION_

Expand Down

0 comments on commit afc4508

Please sign in to comment.