From dd9bf47c686c3fd3df51e26e5a2085d4a8c23995 Mon Sep 17 00:00:00 2001 From: Thomas Bernard Date: Fri, 12 Feb 2016 14:51:59 +0100 Subject: [PATCH] iptcrdr.c: add iptc_init() check in init_redirect() --- miniupnpd/Changelog.txt | 5 ++++- miniupnpd/netfilter/iptcrdr.c | 19 +++++++++++++++++-- miniupnpd/netfilter/testiptcrdr.c | 13 ++++++++----- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/miniupnpd/Changelog.txt b/miniupnpd/Changelog.txt index 1945508..eb908e3 100644 --- a/miniupnpd/Changelog.txt +++ b/miniupnpd/Changelog.txt @@ -1,4 +1,7 @@ -$Id: Changelog.txt,v 1.418 2016/02/11 10:35:11 nanard Exp $ +$Id: Changelog.txt,v 1.421 2016/02/12 12:34:37 nanard Exp $ + +2016/02/12: + add iptc_init() check in iptcrdr.c/init_redirect() 2016/02/11: use Linux libuuid uuid_generate() / BSD uuid_create() API diff --git a/miniupnpd/netfilter/iptcrdr.c b/miniupnpd/netfilter/iptcrdr.c index 674771a..8464c6b 100644 --- a/miniupnpd/netfilter/iptcrdr.c +++ b/miniupnpd/netfilter/iptcrdr.c @@ -1,4 +1,4 @@ -/* $Id: iptcrdr.c,v 1.53 2015/02/08 09:10:00 nanard Exp $ */ +/* $Id: iptcrdr.c,v 1.57 2016/02/12 12:34:39 nanard Exp $ */ /* MiniUPnP project * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ * (c) 2006-2016 Thomas Bernard @@ -91,9 +91,24 @@ addpeerdscprule(int proto, unsigned char dscp, const char * iaddr, unsigned short iport, const char * rhost, unsigned short rport); -/* dummy init and shutdown functions */ +/* dummy init and shutdown functions + * Only test iptc_init() */ int init_redirect(void) { + IPTC_HANDLE h; + + h = iptc_init("nat"); + if(!h) { + syslog(LOG_ERR, "iptc_init() failed : %s", + iptc_strerror(errno)); + return -1; + } else { +#ifdef IPTABLES_143 + iptc_free(h); +#else + iptc_free(&h); +#endif + } return 0; } diff --git a/miniupnpd/netfilter/testiptcrdr.c b/miniupnpd/netfilter/testiptcrdr.c index b9582ba..3a6a749 100644 --- a/miniupnpd/netfilter/testiptcrdr.c +++ b/miniupnpd/netfilter/testiptcrdr.c @@ -1,7 +1,7 @@ -/* $Id: testiptcrdr.c,v 1.18 2012/04/24 22:41:53 nanard Exp $ */ +/* $Id: testiptcrdr.c,v 1.21 2016/02/12 12:35:50 nanard Exp $ */ /* MiniUPnP project * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ - * (c) 2006-2015 Thomas Bernard + * (c) 2006-2016 Thomas Bernard * This software is subject to the conditions detailed * in the LICENCE file provided within the distribution */ @@ -29,6 +29,8 @@ main(int argc, char ** argv) if(argc<4) return -1; openlog("testiptcrdr", LOG_PERROR|LOG_CONS, LOG_LOCAL0); + if(init_redirect() < 0) + return -1; eport = (unsigned short)atoi(argv[1]); iaddr = argv[2]; iport = (unsigned short)atoi(argv[3]); @@ -73,14 +75,15 @@ main(int argc, char ** argv) } else { - printf("redirected port %hu to %s:%hu proto %d packets=%" PRIu64 " bytes=%" PRIu64 "\n", - p1, addr, p2, proto2, packets, bytes); + printf("redirected port %hu to %s:%hu proto %d packets=%" PRIu64 " bytes=%" PRIu64 " ts=%u desc='%s'\n", + p1, addr, p2, proto2, packets, bytes, timestamp, desc); } } printf("trying to list nat rules :\n"); - list_redirect_rule(argv[1]); + list_redirect_rule(NULL); printf("deleting\n"); delete_redirect_and_filter_rules(eport, proto); + shutdown_redirect(); return 0; }