From c7fa728e7fd6792d46087783aea22d9378f5a9d1 Mon Sep 17 00:00:00 2001
From: Stephen Gallagher <sgallagh@redhat.com>
Date: Mon, 17 Jan 2011 09:12:45 -0500
Subject: [PATCH] Remove support for pre-1.1 netlink

Netlink 1.0 and older is buggy and unreliable, occasionally
causing tight-loops. We're no longer going to try to support it.

https://fedorahosted.org/sssd/ticket/755
---
 configure.ac                  |    2 +-
 src/conf_macros.m4            |    7 ++---
 src/external/libnl.m4         |   49 ++++++++++++++++++++---------------------
 src/monitor/monitor_netlink.c |   32 --------------------------
 4 files changed, 28 insertions(+), 62 deletions(-)

diff --git a/configure.ac b/configure.ac
index 6192c533f3d2a1bf99e4302ad6326c46a3100a19..f0fa07257d8e957957a620d6b9b60aaf655bdd68 100644
--- a/configure.ac
+++ b/configure.ac
@@ -161,7 +161,7 @@ if test x$HAVE_SEMANAGE != x -a x$HAVE_SELINUX != x; then
     AM_CHECK_SEMANAGE
 fi
 
-if test x$HAVE_LIBNL != x; then
+if test x$BUILD_LIBNL != x; then
     AM_CHECK_LIBNL
 fi
 
diff --git a/src/conf_macros.m4 b/src/conf_macros.m4
index 5898bc7f12079bb41636cd20442ccf2ea260d5b5..d759c48e9a48ca5c8d683e4e78372f7bbbfc1251 100644
--- a/src/conf_macros.m4
+++ b/src/conf_macros.m4
@@ -240,15 +240,14 @@ AC_DEFUN([WITH_SEMANAGE],
 AC_DEFUN([WITH_LIBNL],
   [ AC_ARG_WITH([libnl],
                 [AC_HELP_STRING([--with-libnl],
-                                [Whether to build with libnetlink support [yes]]
+                                [Whether to build with libnetlink support [AUTO]]
                                )
                 ],
                 [],
                 with_libnl=yes
                )
     if test x"$with_libnl" = xyes; then
-        HAVE_LIBNL=1
-        AC_SUBST(HAVE_LIBNL)
-        AC_DEFINE_UNQUOTED(HAVE_LIBNL, 1, [Build with libnetlink support])
+        BUILD_LIBNL=1
+        AC_SUBST(BUILD_LIBNL)
     fi
   ])
diff --git a/src/external/libnl.m4 b/src/external/libnl.m4
index ed8f95b63b8e542a11636e91074feb6975d72701..36619ff87490fa94651255224b9fb57e3194ecbc 100644
--- a/src/external/libnl.m4
+++ b/src/external/libnl.m4
@@ -1,35 +1,34 @@
 dnl A macro to check the availability and version of libnetlink
+
 AC_DEFUN([AM_CHECK_LIBNL],
 [
-    PKG_CHECK_MODULES(libnl, libnl-1)
+    PKG_CHECK_MODULES(libnl, libnl-1 >= 1.1,[
+        HAVE_LIBNL=1
+        AC_SUBST(HAVE_LIBNL)
+        AC_DEFINE_UNQUOTED(HAVE_LIBNL, 1, [Build with libnetlink support])
 
-    AC_CHECK_HEADERS(netlink.h)
-    AC_CHECK_LIB(nl, nl_connect, [ LIBNL_LIBS="-lnl" ], [AC_MSG_ERROR([libnl is required])])
+	    AC_CHECK_HEADERS(netlink.h)
+	    AC_CHECK_LIB(nl, nl_connect, [ LIBNL_LIBS="-lnl" ], [AC_MSG_ERROR([libnl is required])])
 
-    AC_CHECK_LIB([nl],
-                 [nl_handle_get_fd],
-                 [AC_DEFINE([HAVE_LIBNL_OLDER_THAN_1_1], 1, [Does libnl have pre-1.1 API?])
-                 ],
-    )
+	    dnl Check if this particular version of libnl supports particular functions
+	    AC_CHECK_LIB([nl],
+	                 [nl_socket_add_membership],
+	                 [AC_DEFINE([HAVE_NL_SOCKET_ADD_MEMBERSHIP], 1, [Does libnl have nl_socket_add_membership?])
+	                 ],
+	    )
 
-    dnl Check if this particular version of libnl supports particular functions
-    AC_CHECK_LIB([nl],
-                 [nl_socket_add_membership],
-                 [AC_DEFINE([HAVE_NL_SOCKET_ADD_MEMBERSHIP], 1, [Does libnl have nl_socket_add_membership?])
-                 ],
-    )
+	    AC_CHECK_LIB([nl],
+	                 [nl_socket_modify_cb],
+	                 [AC_DEFINE([HAVE_NL_SOCKET_MODIFY_CB], 1, [Does libnl have nl_socket_modify_cb?])
+	                 ],
+	    )
 
-    AC_CHECK_LIB([nl],
-                 [nl_socket_modify_cb],
-                 [AC_DEFINE([HAVE_NL_SOCKET_MODIFY_CB], 1, [Does libnl have nl_socket_modify_cb?])
-                 ],
-    )
-
-    AC_CHECK_LIB([nl],
-                 [nl_set_passcred],
-                 [AC_DEFINE([HAVE_NL_SET_PASSCRED], 1, [Does libnl have nl_set_passcred?])
-                 ],
-    )
+	    AC_CHECK_LIB([nl],
+	                 [nl_set_passcred],
+	                 [AC_DEFINE([HAVE_NL_SET_PASSCRED], 1, [Does libnl have nl_set_passcred?])
+	                 ],
+	    )
+    ],[AC_MSG_WARN([Netlink support unavailable or too old])])
 
     AC_SUBST(LIBNL_CFLAGS)
     AC_SUBST(LIBNL_LIBS)
diff --git a/src/monitor/monitor_netlink.c b/src/monitor/monitor_netlink.c
index 29a182b9db389808e3832be954f1807917ff20b7..33be7c85017c70242236dddf0e33fbbaf8b624c9 100644
--- a/src/monitor/monitor_netlink.c
+++ b/src/monitor/monitor_netlink.c
@@ -49,20 +49,11 @@
 #define SOL_NETLINK 270
 #endif
 
-#ifdef HAVE_LIBNL_OLDER_THAN_1_1
-#define nlw_get_fd nl_handle_get_fd
-#define nlw_recvmsgs_default nl_recvmsgs_def
-#define nlw_get_pid nl_handle_get_pid
-#define nlw_object_match nl_object_match
-#define NLW_OK NL_PROCEED
-#define OBJ_CAST(ptr)           ((struct nl_object *) (ptr))
-#else
 #define nlw_get_fd nl_socket_get_fd
 #define nlw_recvmsgs_default nl_recvmsgs_default
 #define nlw_get_pid nl_socket_get_local_port
 #define nlw_object_match nl_object_match_filter
 #define NLW_OK NL_OK
-#endif
 
 struct netlink_ctx {
 #ifdef HAVE_LIBNL
@@ -182,19 +173,6 @@ static int nlw_group_subscribe(struct nl_handle *nlh)
  * Callbacks for validating and receiving messages
  *******************************************************************/
 
-#ifdef HAVE_LIBNL_OLDER_THAN_1_1
-static int event_msg_recv(struct sockaddr_nl *nla, struct nlmsghdr *hdr,
-                          void *arg)
-{
-    struct netlink_ctx *ctx = (struct netlink_ctx *) arg;
-
-    if (!nlw_accept_message(ctx->nlh, nla, hdr)) {
-        return NL_SKIP;
-    }
-
-    return NLW_OK;
-}
-#else
 static int event_msg_recv(struct nl_msg *msg, void *arg)
 {
     struct netlink_ctx *ctx = (struct netlink_ctx *) arg;
@@ -218,24 +196,14 @@ static int event_msg_recv(struct nl_msg *msg, void *arg)
 
     return NLW_OK;
 }
-#endif
 
 static void link_msg_handler(struct nl_object *obj, void *arg);
 
-#ifdef HAVE_LIBNL_OLDER_THAN_1_1
-static int event_msg_ready(struct sockaddr_nl *nla, struct nlmsghdr *hdr,
-                           void *arg)
-{
-    nl_msg_parse(hdr, &link_msg_handler, arg);
-    return NLW_OK;
-}
-#else
 static int event_msg_ready(struct nl_msg *msg, void *arg)
 {
     nl_msg_parse(msg, &link_msg_handler, arg);
     return NLW_OK;
 }
-#endif
 
 static int nlw_set_callbacks(struct nl_handle *nlh, void *data)
 {
-- 
1.7.3.4

