On 05/03/2012 12:10 PM, Serge Hallyn wrote:
configure.ac+Makefile.am:
support libnl-3 as well as libnl-1
src/util/virnetlink.c:
support libnl3 api. To minimize impact on code flow with #ifdefs as
requested by Stefan Berger, do some #defines at the top.
Unfortunately libnl3 moves netlink/msg.h to
/usr/include/libnl3/netlink/msg.h, so the LIBNL_CFLAGS need to be added
to a bunch of places where they weren't needed with libnl1.
Stefan,
in this version I may have gone too far :) if you prefer I just
stick to using 'struct nl_socket nlhandle' and leave the rest
with explicit #ifdefs, let me know. But this version leaves the
original code flow unencumbered by ifdefs and easier to read and
vet.
Signed-off-by: Serge Hallyn<serge.hallyn(a)canonical.com>
--- a/src/util/virnetlink.c
+++ b/src/util/virnetlink.c
@@ -60,6 +60,16 @@ struct virNetlinkEventHandle {
int deleted;
};
+#ifdef HAVE_LIBNL1
+#define nl_alloc nl_handle_alloc
+#define nl_free nl_handle_destroy
+typedef struct nl_handle nlhandle_t;
+#else
+#define nl_alloc nl_socket_alloc
+#define nl_free nl_socket_free
+typedef struct nl_sock nlhandle_t;
+#endif
+
I would not #define in the namespace of that library (nl_*). What about
the following:
#ifdef HAVE_LIBNL1
static struct nl_handle *
virNLHandleAlloc(void)
{
return nl_handle_alloc();
}
static void
virNWHandleDestroy(struct nl_handle *h)
{
nl_handle_destroy(h);
}
#else
static struct nl_sock *
virNLHandleAlloc(void)
{
return nl_socket_alloc();
}
static void
virNWHandleDestroy(struct nl_sock *h)
{
nl_socket_free(h);
}
#endif
Regards,
Stefan