commit eed637da392accdec6d5f615c5bca291766709a4
Author: Laine Stump <laine@laine.org>
Date:   Tue Apr 7 14:16:18 2015 -0400

    fix if.h problems when compiling with newer libnl3
    
    When netcf first include support for libnl3, the author of that patch
    (Serge Hallyn, commit 0310cd505) found that
    /usr/include/libnl3/netlink/route/link.h #included <linux/if.h>, which
    conflicts with <net/if.h> (but for our purposes at least defines all the
    same things). So he put the #include <net/if.h> in dutil_linux.c inside
    an #ifndef HAVE_LIBNL3.
    
    That worked fine until libnl3 finally removed the offending (and
    unnecessary) #include <linux/if.h> from its link.h. That fix to libnl3
    broke the netcf build.
    
    This patch fixes the build by using autotools magic to attempt
    compiling essentially this short program:
    
      #include <netlink/route/link.h>
      int main()
      {
          struct ifreq ifr;
          return ifr.ifr_ifru.ifru_ivalue = IFF_UP;
      }
    
    If this can compile successfully without any other includes, then
    link.h is already including linux/if.h and we should avoid including
    net/if.h, so we #define AVOID_NET_IF_H. If the compile fails, then we
    do need to include net/if.h, so we *don't* #define
    AVOID_NET_IF_H. Then we enclose dutil_linux.c's #include <net/if.h>
    within #ifndef AVOID_NET_IF_H and we're done.
    
    Although this check would probably be safe on a libnl1 system, we know
    from past experience that we should always include net/if.h in those
    cases anyway, so we don't even try - we only do the configure-time
    check if we're using libnl3.

diff --git a/configure.ac b/configure.ac
index a914b0f..bab4e92 100644
--- a/configure.ac
+++ b/configure.ac
@@ -162,9 +162,29 @@ then
 	fi
 
 	if (test "${have_libnl3}" = "yes" -a "${have_libnl_route3}" = "yes"); then
-		AC_DEFINE([HAVE_LIBNL3], [1], [Use libnl-3.0])
-		have_libnl="yes"
-	else
+            AC_DEFINE([HAVE_LIBNL3], [1], [Use libnl-3.0])
+            have_libnl="yes"
+            SAVE_CFLAGS="${CFLAGS}"
+            CFLAGS="${LIBNL_CFLAGS} ${CFLAGS}"
+            dnl Avoid #including net/if.h when using earlier versions
+            dnl of libnl3 that include linux/if.h from netlink/route/link.h,
+            dnl since the two if.h files conflict with each other.
+            AC_CACHE_CHECK(
+                [whether to avoid including <net/if.h> to prevent conflict with <linux/if.h> included by libnl3],
+                [netcf_cv_avoid_net_if_h],
+                [AC_COMPILE_IFELSE([AC_LANG_PROGRAM(
+                    [[
+                      #include <netlink/route/link.h>
+                    ]],
+                    [[struct ifreq ifr; return ifr.ifr_ifru.ifru_ivalue = IFF_UP;]])],
+                    [netcf_cv_avoid_net_if_h=yes], [netcf_cv_avoid_net_if_h=no])])
+                CFLAGS="${SAVE_CFLAGS}"
+                if test "x$netcf_cv_avoid_net_if_h" = "xyes"; then
+                   AC_DEFINE([AVOID_NET_IF_H], [1],
+                             [define to 1 if the libnl3 header netlink/route/link.h already
+                              includes linux/if.h (which will conflict with net/if.h)])
+                fi
+        else
 		PKG_CHECK_MODULES([LIBNL], [libnl-1],
 				  [have_libnl1=yes],
 				  [have_libnl1=no])
diff --git a/src/dutil_linux.c b/src/dutil_linux.c
index 299b36e..0850593 100644
--- a/src/dutil_linux.c
+++ b/src/dutil_linux.c
@@ -54,8 +54,8 @@
 #include "dutil.h"
 #include "dutil_linux.h"
 
-#ifndef HAVE_LIBNL3
-#include <net/if.h>
+#ifndef AVOID_NET_IF_H
+# include <net/if.h>
 #endif
 #include <netlink/socket.h>
 #include <netlink/cache.h>
