From 940909890e030269c9fc9005da02a3240c152cc9 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Sun, 26 Apr 2015 16:15:41 +0200 Subject: [PATCH] remove dependency on libnfnetlink fixes #110 still allow to use libnfnetlink by defining USE_LIBNFNETLINK if you really want/need to --- miniupnpd/Makefile.linux | 4 ++-- miniupnpd/linux/getroute.c | 27 ++++++++++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/miniupnpd/Makefile.linux b/miniupnpd/Makefile.linux index 92fc49d..979add6 100644 --- a/miniupnpd/Makefile.linux +++ b/miniupnpd/Makefile.linux @@ -1,6 +1,6 @@ # $Id: Makefile.linux,v 1.86 2014/04/09 07:22:28 nanard Exp $ # MiniUPnP project -# (c) 2006-2014 Thomas Bernard +# (c) 2006-2015 Thomas Bernard # http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ # Author : Thomas Bernard # for use with GNU Make @@ -138,7 +138,7 @@ endif # ($(TEST), 1) endif # ifdef IPTABLESPATH endif # ifdef PCFILE_FOUND -LDLIBS += -lnfnetlink +#LDLIBS += -lnfnetlink TEST := $(shell $(PKG_CONFIG) --atleast-version=1.0.2 libnetfilter_conntrack && $(PKG_CONFIG) --atleast-version=1.0.3 libmnl && echo 1) ifeq ($(TEST),1) diff --git a/miniupnpd/linux/getroute.c b/miniupnpd/linux/getroute.c index 40bcbb6..f9afea7 100644 --- a/miniupnpd/linux/getroute.c +++ b/miniupnpd/linux/getroute.c @@ -1,7 +1,7 @@ /* $Id: getroute.c,v 1.4 2013/02/06 10:50:04 nanard Exp $ */ /* MiniUPnP project * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * (c) 2006-2013 Thomas Bernard + * (c) 2006-2015 Thomas Bernard * This software is subject to the conditions detailed * in the LICENCE file provided within the distribution */ @@ -16,7 +16,12 @@ /*#include */ #include #include +#ifdef USE_LIBNFNETLINK +/* define USE_LIBNFNETLINK in order to use libnfnetlink + * instead of custom code + * see https://github.com/miniupnp/miniupnp/issues/110 */ #include +#endif /* USE_LIBNFNETLINK */ #include "../getroute.h" #include "../upnputils.h" @@ -46,6 +51,9 @@ get_src_for_route_to(const struct sockaddr * dst, }; const struct sockaddr_in * dst4; const struct sockaddr_in6 * dst6; +#ifndef USE_LIBNFNETLINK + struct rtattr * rta; +#endif /* USE_LIBNFNETLINK */ memset(&req, 0, sizeof(req)); req.n.nlmsg_len = NLMSG_LENGTH(sizeof(struct rtmsg)); @@ -66,15 +74,32 @@ get_src_for_route_to(const struct sockaddr * dst, syslog(LOG_DEBUG, "get_src_for_route_to (%s)", dst_str); } /* add address */ +#ifndef USE_LIBNFNETLINK + rta = (struct rtattr *)(((char*)&req) + NLMSG_ALIGN(req.n.nlmsg_len)); + rta->rta_type = RTA_DST; +#endif /* USE_LIBNFNETLINK */ if(dst->sa_family == AF_INET) { dst4 = (const struct sockaddr_in *)dst; +#ifdef USE_LIBNFNETLINK nfnl_addattr_l(&req.n, sizeof(req), RTA_DST, &dst4->sin_addr, 4); +#else + rta->rta_len = RTA_SPACE(sizeof(dst4->sin_addr)); + memcpy(RTA_DATA(rta), &dst4->sin_addr, sizeof(dst4->sin_addr)); +#endif /* USE_LIBNFNETLINK */ req.r.rtm_dst_len = 32; } else { dst6 = (const struct sockaddr_in6 *)dst; +#ifdef USE_LIBNFNETLINK nfnl_addattr_l(&req.n, sizeof(req), RTA_DST, &dst6->sin6_addr, 16); +#else + rta->rta_len = RTA_SPACE(sizeof(dst6->sin6_addr)); + memcpy(RTA_DATA(rta), &dst6->sin6_addr, sizeof(dst6->sin6_addr)); +#endif /* USE_LIBNFNETLINK */ req.r.rtm_dst_len = 128; } +#ifndef USE_LIBNFNETLINK + req.n.nlmsg_len += rta->rta_len; +#endif /* USE_LIBNFNETLINK */ fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE); if (fd < 0) {