Merge branch 'master' into mcast_ssdp

This commit is contained in:
Thomas Bernard 2014-10-22 11:47:46 +02:00
commit ac816e91f9
42 changed files with 342 additions and 273 deletions

View File

@ -1,4 +1,8 @@
$Id: Changelog.txt,v 1.34 2014/05/01 21:05:14 nanard Exp $
$Id: Changelog.txt,v 1.35 2014/09/06 08:32:58 nanard Exp $
2014/09/06:
freebsd-glue for Debian/kFreeBSD
use LDFLAGS when linking binary
2014/05/01:
listen on only 1 IPv4 if only 1 interface is specified

View File

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.18 2014/02/03 14:32:14 nanard Exp $
# $Id: Makefile,v 1.19 2014/06/10 10:00:18 nanard Exp $
# MiniUPnP project
# author: Thomas Bernard
# website: http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
@ -53,7 +53,11 @@ ifneq ($(OS), Darwin)
endif
minissdpd: $(MINISSDPDOBJS)
$(CC) $(CFLAGS) -o $@ $(MINISSDPDOBJS)
if [ "$(DEB_BUILD_ARCH_OS)" = "kfreebsd" ] ; then \
$(CC) $(CFLAGS) $(LDFLAGS) -lfreebsd-glue -o $@ $(MINISSDPDOBJS) ; \
else \
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(MINISSDPDOBJS) ; \
fi
testminissdpd: $(TESTMINISSDPDOBJS)

View File

@ -261,6 +261,7 @@ processMSEARCH(int s, const char * st, int st_len,
ntohs(((const struct sockaddr_in *)addr)->sin_port),
st_len, st);
#endif
/* TODO : ignore packet if not coming from a LAN */
if(st_len==8 && (0==memcmp(st, "ssdp:all", 8))) {
/* send a response for all services */
for(serv = servicelisthead.lh_first;

View File

@ -8,6 +8,7 @@ build/
Makefile.bak
miniupnpcstrings.h
pythonmodule
pythonmodule3
upnpc-shared
upnpc-static
minihttptestserver

View File

@ -36,7 +36,7 @@ else (NOT WIN32)
endif (NOT WIN32)
if (CMAKE_SYSTEM_NAME STREQUAL "Darwin")
add_definitions (-DMACOSX -D_DARWIN_C_SOURCE)
add_definitions (-D_DARWIN_C_SOURCE)
endif ()
# Set compiler specific build flags
@ -86,7 +86,7 @@ endif (NOT WIN32 AND NOT CMAKE_SYSTEM_NAME STREQUAL "AmigaOS")
if (WIN32)
set_source_files_properties (${MINIUPNPC_SOURCES} PROPERTIES
COMPILE_DEFINITIONS STATICLIB
COMPILE_DEFINITIONS MINIUPNP_STATICLIB
COMPILE_DEFINITIONS MINIUPNP_EXPORTS
)
endif (WIN32)

View File

@ -1,6 +1,18 @@
$Id: Changelog.txt,v 1.194 2014/05/15 08:41:44 nanard Exp $
$Id: Changelog.txt,v 1.198 2014/09/11 14:13:31 nanard Exp $
miniUPnP client Changelog.
2014/09/11:
use remoteHost arg of DeletePortMapping
2014/09/06:
Fix python3 build
2014/07/01:
Fix parsing of IGD2 root descriptions
2014/06/10:
rename LIBSPEC to MINIUPNP_LIBSPEC
2014/05/15:
Add support for IGD2 AddAnyPortMapping and DeletePortMappingRange

View File

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.105 2013/05/14 20:37:36 nanard Exp $
# $Id: Makefile,v 1.110 2014/09/06 08:24:12 nanard Exp $
# MiniUPnP Project
# http://miniupnp.free.fr/
# http://miniupnp.tuxfamily.org/
@ -85,7 +85,7 @@ LIBRARY = libminiupnpc.a
ifeq ($(OS), Darwin)
SHAREDLIBRARY = libminiupnpc.dylib
SONAME = $(basename $(SHAREDLIBRARY)).$(APIVERSION).dylib
CFLAGS := -DMACOSX -D_DARWIN_C_SOURCE $(CFLAGS)
CFLAGS := -D_DARWIN_C_SOURCE $(CFLAGS)
else
ifeq ($(JARSUFFIX), win32)
SHAREDLIBRARY = miniupnpc.dll
@ -174,9 +174,11 @@ validateupnpreplyparse: testupnpreplyparse testupnpreplyparse.sh
clean:
$(RM) $(LIBRARY) $(SHAREDLIBRARY) $(EXECUTABLES) $(OBJS) miniupnpcstrings.h
$(RM) $(EXECUTABLES_ADDTESTS)
# clean python stuff
$(RM) pythonmodule pythonmodule3
$(RM) validateminixml validateminiwget validateupnpreplyparse
$(RM) minihttptestserver minihttptestserver.o
$(RM) -r build/ dist/
#python setup.py clean
# clean jnaerator stuff

View File

@ -50,11 +50,11 @@ dll/upnpc.o: upnpc.o
echo $@ generated with $<
.c.o:
$(CC) $(CFLAGS) -DSTATICLIB -c -o $@ $<
$(CC) $(CFLAGS) -DMINIUPNP_STATICLIB -c -o $@ $<
$(CC) $(CFLAGS) -DMINIUPNP_EXPORTS -c -o dll/$@ $<
upnpc.o:
$(CC) $(CFLAGS) -DSTATICLIB -c -o $@ $<
$(CC) $(CFLAGS) -DMINIUPNP_STATICLIB -c -o $@ $<
$(CC) $(CFLAGS) -c -o dll/$@ $<
# --enable-stdcall-fixup

View File

@ -1,4 +1,4 @@
/* $Id: connecthostport.c,v 1.12 2014/02/05 17:26:46 nanard Exp $ */
/* $Id: connecthostport.c,v 1.13 2014/03/31 12:36:36 nanard Exp $ */
/* Project : miniupnp
* Author : Thomas Bernard
* Copyright (c) 2010-2014 Thomas Bernard
@ -35,6 +35,7 @@
#ifndef USE_GETHOSTBYNAME
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/select.h>
#endif /* #ifndef USE_GETHOSTBYNAME */
#endif /* #else _WIN32 */

View File

@ -1,19 +1,19 @@
#ifndef DECLSPEC_H_INCLUDED
#define DECLSPEC_H_INCLUDED
#if defined(_WIN32) && !defined(STATICLIB)
#if defined(_WIN32) && !defined(MINIUPNP_STATICLIB)
/* for windows dll */
#ifdef MINIUPNP_EXPORTS
#define LIBSPEC __declspec(dllexport)
#define MINIUPNP_LIBSPEC __declspec(dllexport)
#else
#define LIBSPEC __declspec(dllimport)
#define MINIUPNP_LIBSPEC __declspec(dllimport)
#endif
#else
#if defined(__GNUC__) && __GNUC__ >= 4
/* fix dynlib for OS X 10.9.2 and Apple LLVM version 5.0 */
#define LIBSPEC __attribute__ ((visibility ("default")))
#define MINIUPNP_LIBSPEC __attribute__ ((visibility ("default")))
#else
#define LIBSPEC
#define MINIUPNP_LIBSPEC
#endif
#endif

View File

@ -1,8 +1,8 @@
/* $Id: igd_desc_parse.c,v 1.14 2011/04/11 09:19:24 nanard Exp $ */
/* $Id: igd_desc_parse.c,v 1.15 2014/07/01 13:01:17 nanard Exp $ */
/* Project : miniupnp
* http://miniupnp.free.fr/
* Author : Thomas Bernard
* Copyright (c) 2005-2010 Thomas Bernard
* Copyright (c) 2005-2014 Thomas Bernard
* This software is subject to the conditions detailed in the
* LICENCE file provided in this distribution. */
@ -26,6 +26,8 @@ void IGDstartelt(void * d, const char * name, int l)
}
}
#define COMPARE(str, cstr) (0==memcmp(str, cstr, sizeof(cstr) - 1))
/* End element handler :
* update nesting level counter and update parser state if
* service element is parsed */
@ -36,23 +38,16 @@ void IGDendelt(void * d, const char * name, int l)
/*printf("endelt %2d %.*s\n", datas->level, l, name);*/
if( (l==7) && !memcmp(name, "service", l) )
{
/*
if( datas->state < 1
&& !strcmp(datas->servicetype,
// "urn:schemas-upnp-org:service:WANIPConnection:1") )
"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1"))
datas->state ++;
*/
if(0==strcmp(datas->tmp.servicetype,
"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:1")) {
if(COMPARE(datas->tmp.servicetype,
"urn:schemas-upnp-org:service:WANCommonInterfaceConfig:")) {
memcpy(&datas->CIF, &datas->tmp, sizeof(struct IGDdatas_service));
} else if(0==strcmp(datas->tmp.servicetype,
"urn:schemas-upnp-org:service:WANIPv6FirewallControl:1")) {
} else if(COMPARE(datas->tmp.servicetype,
"urn:schemas-upnp-org:service:WANIPv6FirewallControl:")) {
memcpy(&datas->IPv6FC, &datas->tmp, sizeof(struct IGDdatas_service));
} else if(0==strcmp(datas->tmp.servicetype,
"urn:schemas-upnp-org:service:WANIPConnection:1")
|| 0==strcmp(datas->tmp.servicetype,
"urn:schemas-upnp-org:service:WANPPPConnection:1") ) {
} else if(COMPARE(datas->tmp.servicetype,
"urn:schemas-upnp-org:service:WANIPConnection:")
|| COMPARE(datas->tmp.servicetype,
"urn:schemas-upnp-org:service:WANPPPConnection:") ) {
if(datas->first.servicetype[0] == '\0') {
memcpy(&datas->first, &datas->tmp, sizeof(struct IGDdatas_service));
} else {

View File

@ -6,7 +6,7 @@
* This software is subjet to the conditions detailed in the
* provided LICENSE file. */
#define __EXTENSIONS__ 1
#if !defined(MACOSX) && !defined(__sun)
#if !defined(__APPLE__) && !defined(__sun)
#if !defined(_XOPEN_SOURCE) && !defined(__OpenBSD__) && !defined(__NetBSD__)
#ifndef __cplusplus
#define _XOPEN_SOURCE 600
@ -17,7 +17,7 @@
#endif
#endif
#if !defined(__DragonFly__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(MACOSX) && !defined(_WIN32) && !defined(__CYGWIN__) && !defined(__sun)
#if !defined(__DragonFly__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__APPLE__) && !defined(_WIN32) && !defined(__CYGWIN__) && !defined(__sun) && !defined(__GNU__) && !defined(__FreeBSD_kernel__)
#define HAS_IP_MREQN
#endif
@ -70,6 +70,9 @@
/* Amiga OS specific stuff */
#define TIMEVAL struct timeval
#endif
#ifdef __GNU__
#define MAXHOSTNAMELEN 64
#endif
#if defined(HAS_IP_MREQN) && defined(NEED_STRUCT_IP_MREQN)
@ -106,7 +109,7 @@ struct ip_mreqn
#define SERVICEPREFIX2 'u'
/* root description parsing */
LIBSPEC void parserootdesc(const char * buffer, int bufsize, struct IGDdatas * data)
MINIUPNP_LIBSPEC void parserootdesc(const char * buffer, int bufsize, struct IGDdatas * data)
{
struct xmlparser parser;
/* xmlparser object */
@ -335,7 +338,7 @@ parseMSEARCHReply(const char * reply, int size,
* no devices was found.
* It is up to the caller to free the chained list
* delay is in millisecond (poll) */
LIBSPEC struct UPNPDev *
MINIUPNP_LIBSPEC struct UPNPDev *
upnpDiscover(int delay, const char * multicastif,
const char * minissdpdsock, int sameport,
int ipv6,
@ -718,7 +721,7 @@ upnpDiscover(int delay, const char * multicastif,
/* freeUPNPDevlist() should be used to
* free the chained list returned by upnpDiscover() */
LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist)
MINIUPNP_LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist)
{
struct UPNPDev * next;
while(devlist)
@ -754,7 +757,7 @@ url_cpy_or_cat(char * dst, const char * src, int n)
/* Prepare the Urls for usage...
*/
LIBSPEC void
MINIUPNP_LIBSPEC void
GetUPNPUrls(struct UPNPUrls * urls, struct IGDdatas * data,
const char * descURL, unsigned int scope_id)
{
@ -844,7 +847,7 @@ GetUPNPUrls(struct UPNPUrls * urls, struct IGDdatas * data,
#endif
}
LIBSPEC void
MINIUPNP_LIBSPEC void
FreeUPNPUrls(struct UPNPUrls * urls)
{
if(!urls)
@ -891,7 +894,7 @@ UPNPIGD_IsConnected(struct UPNPUrls * urls, struct IGDdatas * data)
* passed as parameters are set. Donc forget to call FreeUPNPUrls(urls) to
* free allocated memory.
*/
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetValidIGD(struct UPNPDev * devlist,
struct UPNPUrls * urls,
struct IGDdatas * data,

View File

@ -24,7 +24,9 @@ EXPORTS
UPNP_GetExternalIPAddress
UPNP_GetLinkLayerMaxBitRates
UPNP_AddPortMapping
UPNP_AddAnyPortMapping
UPNP_DeletePortMapping
UPNP_DeletePortMappingRange
UPNP_GetPortMappingNumberOfEntries
UPNP_GetSpecificPortMappingEntry
UPNP_GetGenericPortMappingEntry

View File

@ -54,19 +54,19 @@ struct UPNPDev {
* multicast interface for sending SSDP discover packets.
* If sameport is not null, SSDP packets will be sent from the source port
* 1900 (same as destination port) otherwise system assign a source port. */
LIBSPEC struct UPNPDev *
MINIUPNP_LIBSPEC struct UPNPDev *
upnpDiscover(int delay, const char * multicastif,
const char * minissdpdsock, int sameport,
int ipv6,
int * error);
/* freeUPNPDevlist()
* free list returned by upnpDiscover() */
LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist);
MINIUPNP_LIBSPEC void freeUPNPDevlist(struct UPNPDev * devlist);
/* parserootdesc() :
* parse root XML description of a UPnP device and fill the IGDdatas
* structure. */
LIBSPEC void parserootdesc(const char *, int, struct IGDdatas *);
MINIUPNP_LIBSPEC void parserootdesc(const char *, int, struct IGDdatas *);
/* structure used to get fast access to urls
* controlURL: controlURL of the WANIPConnection
@ -94,7 +94,7 @@ struct UPNPUrls {
* passed as parameters are set. Donc forget to call FreeUPNPUrls(urls) to
* free allocated memory.
*/
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetValidIGD(struct UPNPDev * devlist,
struct UPNPUrls * urls,
struct IGDdatas * data,
@ -105,21 +105,21 @@ UPNP_GetValidIGD(struct UPNPDev * devlist,
* return value :
* 0 - Not ok
* 1 - OK */
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetIGDFromUrl(const char * rootdescurl,
struct UPNPUrls * urls,
struct IGDdatas * data,
char * lanaddr, int lanaddrlen);
LIBSPEC void
MINIUPNP_LIBSPEC void
GetUPNPUrls(struct UPNPUrls *, struct IGDdatas *,
const char *, unsigned int);
LIBSPEC void
MINIUPNP_LIBSPEC void
FreeUPNPUrls(struct UPNPUrls *);
/* return 0 or 1 */
LIBSPEC int UPNPIGD_IsConnected(struct UPNPUrls *, struct IGDdatas *);
MINIUPNP_LIBSPEC int UPNPIGD_IsConnected(struct UPNPUrls *, struct IGDdatas *);
#ifdef __cplusplus

View File

@ -1,4 +1,4 @@
/* $Id: miniupnpcmodule.c,v 1.22 2014/01/31 13:18:25 nanard Exp $*/
/* $Id: miniupnpcmodule.c,v 1.24 2014/06/10 09:48:11 nanard Exp $*/
/* Project : miniupnp
* Author : Thomas BERNARD
* website : http://miniupnp.tuxfamily.org/
@ -6,7 +6,7 @@
* This software is subjet to the conditions detailed in the
* provided LICENCE file. */
#include <Python.h>
#define STATICLIB
#define MINIUPNP_STATICLIB
#include "structmember.h"
#include "miniupnpc.h"
#include "upnpcommands.h"
@ -599,7 +599,11 @@ initminiupnpc(void)
UPnPType.tp_new = PyType_GenericNew;
#endif
if (PyType_Ready(&UPnPType) < 0)
#if PY_MAJOR_VERSION >= 3
return 0;
#else
return;
#endif
#if PY_MAJOR_VERSION >= 3
m = PyModule_Create(&moduledef);
@ -610,7 +614,7 @@ initminiupnpc(void)
Py_INCREF(&UPnPType);
PyModule_AddObject(m, "UPnP", (PyObject *)&UPnPType);
#if PY_MAJOR_VERSION >= 3
return m;
#endif

View File

@ -15,7 +15,6 @@
#include <ws2tcpip.h>
#include <io.h>
#define MAXHOSTNAMELEN 64
#define MIN(x,y) (((x)<(y))?(x):(y))
#define snprintf _snprintf
#define socklen_t int
#ifndef strncasecmp
@ -40,9 +39,14 @@
#include <netdb.h>
#define closesocket close
#endif /* #else _WIN32 */
#if defined(__sun) || defined(sun)
#ifdef __GNU__
#define MAXHOSTNAMELEN 64
#endif /* __GNU__ */
#ifndef MIN
#define MIN(x,y) (((x)<(y))?(x):(y))
#endif
#endif /* MIN */
#include "miniupnpcstrings.h"
#include "miniwget.h"

View File

@ -14,11 +14,11 @@
extern "C" {
#endif
LIBSPEC void * getHTTPResponse(int s, int * size);
MINIUPNP_LIBSPEC void * getHTTPResponse(int s, int * size);
LIBSPEC void * miniwget(const char *, int *, unsigned int);
MINIUPNP_LIBSPEC void * miniwget(const char *, int *, unsigned int);
LIBSPEC void * miniwget_getaddr(const char *, int *, char *, int, unsigned int);
MINIUPNP_LIBSPEC void * miniwget_getaddr(const char *, int *, char *, int, unsigned int);
int parseURL(const char *, char *, unsigned short *, char * *, unsigned int *);

View File

@ -41,7 +41,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS;WIN32;STATICLIB;DEBUG"
PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS;MINIUPNP_STATICLIB;DEBUG"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
@ -104,7 +104,7 @@
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS;WIN32;STATICLIB"
PreprocessorDefinitions="_CRT_SECURE_NO_WARNINGS;MINIUPNP_STATICLIB"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"

View File

@ -41,7 +41,7 @@
<Tool
Name="VCCLCompilerTool"
Optimization="0"
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;STATICLIB;DEBUG;_CRT_SECURE_NO_WARNINGS"
PreprocessorDefinitions="_DEBUG;_CONSOLE;MINIUPNP_STATICLIB;DEBUG;_CRT_SECURE_NO_WARNINGS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
@ -115,7 +115,7 @@
Name="VCCLCompilerTool"
Optimization="2"
EnableIntrinsicFunctions="true"
PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;STATICLIB"
PreprocessorDefinitions="NDEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;MINIUPNP_STATICLIB"
RuntimeLibrary="2"
EnableFunctionLevelLinking="true"
UsePrecompiledHeader="0"

View File

@ -57,11 +57,11 @@ struct PortMappingParserData {
portMappingElt curelt;
};
LIBSPEC void
MINIUPNP_LIBSPEC void
ParsePortListing(const char * buffer, int bufsize,
struct PortMappingParserData * pdata);
LIBSPEC void
MINIUPNP_LIBSPEC void
FreePortListing(struct PortMappingParserData * pdata);
#ifdef __cplusplus

View File

@ -1,4 +1,4 @@
/* $Id: upnpc.c,v 1.102 2014/02/05 17:27:14 nanard Exp $ */
/* $Id: upnpc.c,v 1.104 2014/09/11 14:13:30 nanard Exp $ */
/* Project : miniupnp
* Author : Thomas Bernard
* Copyright (c) 2005-2014 Thomas Bernard
@ -295,8 +295,9 @@ static void SetRedirectAndTest(struct UPNPUrls * urls,
static void
RemoveRedirect(struct UPNPUrls * urls,
struct IGDdatas * data,
const char * eport,
const char * proto)
const char * eport,
const char * proto,
const char * remoteHost)
{
int r;
if(!proto || !eport)
@ -310,7 +311,7 @@ RemoveRedirect(struct UPNPUrls * urls,
fprintf(stderr, "protocol invalid\n");
return;
}
r = UPNP_DeletePortMapping(urls->controlURL, data->first.servicetype, eport, proto, 0);
r = UPNP_DeletePortMapping(urls->controlURL, data->first.servicetype, eport, proto, remoteHost);
printf("UPNP_DeletePortMapping() returned : %d\n", r);
}
@ -584,7 +585,7 @@ int main(int argc, char ** argv)
|| (command == 'D' && commandargc<1))
{
fprintf(stderr, "Usage :\t%s [options] -a ip port external_port protocol [duration]\n\t\tAdd port redirection\n", argv[0]);
fprintf(stderr, " \t%s [options] -d external_port protocol [port2 protocol2] [...]\n\t\tDelete port redirection\n", argv[0]);
fprintf(stderr, " \t%s [options] -d external_port protocol <remote host>\n\t\tDelete port redirection\n", argv[0]);
fprintf(stderr, " \t%s [options] -s\n\t\tGet Connection status\n", argv[0]);
fprintf(stderr, " \t%s [options] -l\n\t\tList redirections\n", argv[0]);
fprintf(stderr, " \t%s [options] -L\n\t\tList redirections (using GetListOfPortMappings (for IGD:2 only)\n", argv[0]);
@ -677,10 +678,8 @@ int main(int argc, char ** argv)
description, 0);
break;
case 'd':
for(i=0; i<commandargc; i+=2)
{
RemoveRedirect(&urls, &data, commandargv[i], commandargv[i+1]);
}
RemoveRedirect(&urls, &data, commandargv[0], commandargv[1],
commandargc > 2 ? commandargv[2] : NULL);
break;
case 'n': /* aNy */
SetRedirectAndTest(&urls, &data,

View File

@ -20,7 +20,7 @@ my_atoui(const char * s)
/*
* */
LIBSPEC UNSIGNED_INTEGER
MINIUPNP_LIBSPEC UNSIGNED_INTEGER
UPNP_GetTotalBytesSent(const char * controlURL,
const char * servicetype)
{
@ -44,7 +44,7 @@ UPNP_GetTotalBytesSent(const char * controlURL,
/*
* */
LIBSPEC UNSIGNED_INTEGER
MINIUPNP_LIBSPEC UNSIGNED_INTEGER
UPNP_GetTotalBytesReceived(const char * controlURL,
const char * servicetype)
{
@ -68,7 +68,7 @@ UPNP_GetTotalBytesReceived(const char * controlURL,
/*
* */
LIBSPEC UNSIGNED_INTEGER
MINIUPNP_LIBSPEC UNSIGNED_INTEGER
UPNP_GetTotalPacketsSent(const char * controlURL,
const char * servicetype)
{
@ -92,7 +92,7 @@ UPNP_GetTotalPacketsSent(const char * controlURL,
/*
* */
LIBSPEC UNSIGNED_INTEGER
MINIUPNP_LIBSPEC UNSIGNED_INTEGER
UPNP_GetTotalPacketsReceived(const char * controlURL,
const char * servicetype)
{
@ -116,7 +116,7 @@ UPNP_GetTotalPacketsReceived(const char * controlURL,
/* UPNP_GetStatusInfo() call the corresponding UPNP method
* returns the current status and uptime */
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetStatusInfo(const char * controlURL,
const char * servicetype,
char * status,
@ -181,7 +181,7 @@ UPNP_GetStatusInfo(const char * controlURL,
/* UPNP_GetConnectionTypeInfo() call the corresponding UPNP method
* returns the connection type */
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetConnectionTypeInfo(const char * controlURL,
const char * servicetype,
char * connectionType)
@ -224,7 +224,7 @@ UPNP_GetConnectionTypeInfo(const char * controlURL,
* One of the values can be null
* Note : GetLinkLayerMaxBitRates belongs to WANPPPConnection:1 only
* We can use the GetCommonLinkProperties from WANCommonInterfaceConfig:1 */
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetLinkLayerMaxBitRates(const char * controlURL,
const char * servicetype,
unsigned int * bitrateDown,
@ -293,7 +293,7 @@ UPNP_GetLinkLayerMaxBitRates(const char * controlURL,
* 402 Invalid Args - See UPnP Device Architecture section on Control.
* 501 Action Failed - See UPnP Device Architecture section on Control.
*/
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetExternalIPAddress(const char * controlURL,
const char * servicetype,
char * extIpAdd)
@ -333,7 +333,7 @@ UPNP_GetExternalIPAddress(const char * controlURL,
return ret;
}
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_AddPortMapping(const char * controlURL, const char * servicetype,
const char * extPort,
const char * inPort,
@ -394,7 +394,7 @@ UPNP_AddPortMapping(const char * controlURL, const char * servicetype,
return ret;
}
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_AddAnyPortMapping(const char * controlURL, const char * servicetype,
const char * extPort,
const char * inPort,
@ -461,7 +461,7 @@ UPNP_AddAnyPortMapping(const char * controlURL, const char * servicetype,
return ret;
}
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_DeletePortMapping(const char * controlURL, const char * servicetype,
const char * extPort, const char * proto,
const char * remoteHost)
@ -505,7 +505,7 @@ UPNP_DeletePortMapping(const char * controlURL, const char * servicetype,
return ret;
}
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_DeletePortMappingRange(const char * controlURL, const char * servicetype,
const char * extPortStart, const char * extPortEnd,
const char * proto,
@ -551,7 +551,7 @@ UPNP_DeletePortMappingRange(const char * controlURL, const char * servicetype,
return ret;
}
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetGenericPortMappingEntry(const char * controlURL,
const char * servicetype,
const char * index,
@ -646,7 +646,7 @@ UPNP_GetGenericPortMappingEntry(const char * controlURL,
return r;
}
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetPortMappingNumberOfEntries(const char * controlURL,
const char * servicetype,
unsigned int * numEntries)
@ -687,7 +687,7 @@ UPNP_GetPortMappingNumberOfEntries(const char * controlURL,
/* UPNP_GetSpecificPortMappingEntry retrieves an existing port mapping
* the result is returned in the intClient and intPort strings
* please provide 16 and 6 bytes of data */
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetSpecificPortMappingEntry(const char * controlURL,
const char * servicetype,
const char * extPort,
@ -779,7 +779,7 @@ UPNP_GetSpecificPortMappingEntry(const char * controlURL,
* 733 InconsistantParameters - NewStartPort and NewEndPort values are not
* consistent.
*/
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetListOfPortMappings(const char * controlURL,
const char * servicetype,
const char * startPort,
@ -861,7 +861,7 @@ UPNP_GetListOfPortMappings(const char * controlURL,
}
/* IGD:2, functions for service WANIPv6FirewallControl:1 */
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetFirewallStatus(const char * controlURL,
const char * servicetype,
int * firewallEnabled,
@ -905,7 +905,7 @@ UPNP_GetFirewallStatus(const char * controlURL,
return ret;
}
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetOutboundPinholeTimeout(const char * controlURL, const char * servicetype,
const char * remoteHost,
const char * remotePort,
@ -960,7 +960,7 @@ UPNP_GetOutboundPinholeTimeout(const char * controlURL, const char * servicetype
return ret;
}
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_AddPinhole(const char * controlURL, const char * servicetype,
const char * remoteHost,
const char * remotePort,
@ -1039,7 +1039,7 @@ UPNP_AddPinhole(const char * controlURL, const char * servicetype,
return ret;
}
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_UpdatePinhole(const char * controlURL, const char * servicetype,
const char * uniqueID,
const char * leaseTime)
@ -1081,7 +1081,7 @@ UPNP_UpdatePinhole(const char * controlURL, const char * servicetype,
return ret;
}
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_DeletePinhole(const char * controlURL, const char * servicetype, const char * uniqueID)
{
/*struct NameValueParserData pdata;*/
@ -1120,7 +1120,7 @@ UPNP_DeletePinhole(const char * controlURL, const char * servicetype, const char
return ret;
}
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_CheckPinholeWorking(const char * controlURL, const char * servicetype,
const char * uniqueID, int * isWorking)
{
@ -1165,7 +1165,7 @@ UPNP_CheckPinholeWorking(const char * controlURL, const char * servicetype,
return ret;
}
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetPinholePackets(const char * controlURL, const char * servicetype,
const char * uniqueID, int * packets)
{

View File

@ -23,19 +23,19 @@
extern "C" {
#endif
LIBSPEC UNSIGNED_INTEGER
MINIUPNP_LIBSPEC UNSIGNED_INTEGER
UPNP_GetTotalBytesSent(const char * controlURL,
const char * servicetype);
LIBSPEC UNSIGNED_INTEGER
MINIUPNP_LIBSPEC UNSIGNED_INTEGER
UPNP_GetTotalBytesReceived(const char * controlURL,
const char * servicetype);
LIBSPEC UNSIGNED_INTEGER
MINIUPNP_LIBSPEC UNSIGNED_INTEGER
UPNP_GetTotalPacketsSent(const char * controlURL,
const char * servicetype);
LIBSPEC UNSIGNED_INTEGER
MINIUPNP_LIBSPEC UNSIGNED_INTEGER
UPNP_GetTotalPacketsReceived(const char * controlURL,
const char * servicetype);
@ -44,7 +44,7 @@ UPNP_GetTotalPacketsReceived(const char * controlURL,
* Return values :
* UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR
* or a UPnP Error code */
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetStatusInfo(const char * controlURL,
const char * servicetype,
char * status,
@ -56,7 +56,7 @@ UPNP_GetStatusInfo(const char * controlURL,
* Return Values :
* UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR
* or a UPnP Error code */
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetConnectionTypeInfo(const char * controlURL,
const char * servicetype,
char * connectionType);
@ -72,7 +72,7 @@ UPNP_GetConnectionTypeInfo(const char * controlURL,
* possible UPnP Errors :
* 402 Invalid Args - See UPnP Device Architecture section on Control.
* 501 Action Failed - See UPnP Device Architecture section on Control. */
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetExternalIPAddress(const char * controlURL,
const char * servicetype,
char * extIpAdd);
@ -83,7 +83,7 @@ UPNP_GetExternalIPAddress(const char * controlURL,
* return values :
* UPNPCOMMAND_SUCCESS, UPNPCOMMAND_INVALID_ARGS, UPNPCOMMAND_UNKNOWN_ERROR
* or a UPnP Error Code. */
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetLinkLayerMaxBitRates(const char* controlURL,
const char* servicetype,
unsigned int * bitrateDown,
@ -122,7 +122,7 @@ UPNP_GetLinkLayerMaxBitRates(const char* controlURL,
* due to conflict with other mechanisms.
* 732 WildCardNotPermittedInIntPort - The internal port cannot be wild-carded
*/
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_AddPortMapping(const char * controlURL, const char * servicetype,
const char * extPort,
const char * inPort,
@ -155,7 +155,7 @@ UPNP_AddPortMapping(const char * controlURL, const char * servicetype,
* due to conflict with other mechanisms.
* 732 WildCardNotPermittedInIntPort - The internal port cannot be wild-carded
*/
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_AddAnyPortMapping(const char * controlURL, const char * servicetype,
const char * extPort,
const char * inPort,
@ -178,7 +178,7 @@ UPNP_AddAnyPortMapping(const char * controlURL, const char * servicetype,
* 606 Action not authorized - The action requested REQUIRES authorization
* and the sender was not authorized.
* 714 NoSuchEntryInArray - The specified value does not exist in the array */
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_DeletePortMapping(const char * controlURL, const char * servicetype,
const char * extPort, const char * proto,
const char * remoteHost);
@ -196,7 +196,7 @@ UPNP_DeletePortMapping(const char * controlURL, const char * servicetype,
* 730 PortMappingNotFound - This error message is returned if no port
* mapping is found in the specified range.
* 733 InconsistentParameters - NewStartPort and NewEndPort values are not consistent. */
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_DeletePortMappingRange(const char * controlURL, const char * servicetype,
const char * extPortStart, const char * extPortEnd,
const char * proto,
@ -204,7 +204,7 @@ UPNP_DeletePortMappingRange(const char * controlURL, const char * servicetype,
/* UPNP_GetPortMappingNumberOfEntries()
* not supported by all routers */
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetPortMappingNumberOfEntries(const char* controlURL,
const char* servicetype,
unsigned int * num);
@ -232,7 +232,7 @@ UPNP_GetPortMappingNumberOfEntries(const char* controlURL,
* and the sender was not authorized.
* 714 NoSuchEntryInArray - The specified value does not exist in the array.
*/
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetSpecificPortMappingEntry(const char * controlURL,
const char * servicetype,
const char * extPort,
@ -266,7 +266,7 @@ UPNP_GetSpecificPortMappingEntry(const char * controlURL,
* and the sender was not authorized.
* 713 SpecifiedArrayIndexInvalid - The specified array index is out of bounds
*/
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetGenericPortMappingEntry(const char * controlURL,
const char * servicetype,
const char * index,
@ -288,7 +288,7 @@ UPNP_GetGenericPortMappingEntry(const char * controlURL,
* 733 InconsistantParameters - NewStartPort and NewEndPort values are not
* consistent.
*/
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetListOfPortMappings(const char * controlURL,
const char * servicetype,
const char * startPort,
@ -298,13 +298,13 @@ UPNP_GetListOfPortMappings(const char * controlURL,
struct PortMappingParserData * data);
/* IGD:2, functions for service WANIPv6FirewallControl:1 */
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetFirewallStatus(const char * controlURL,
const char * servicetype,
int * firewallEnabled,
int * inboundPinholeAllowed);
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetOutboundPinholeTimeout(const char * controlURL, const char * servicetype,
const char * remoteHost,
const char * remotePort,
@ -313,7 +313,7 @@ UPNP_GetOutboundPinholeTimeout(const char * controlURL, const char * servicetype
const char * proto,
int * opTimeout);
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_AddPinhole(const char * controlURL, const char * servicetype,
const char * remoteHost,
const char * remotePort,
@ -323,19 +323,19 @@ UPNP_AddPinhole(const char * controlURL, const char * servicetype,
const char * leaseTime,
char * uniqueID);
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_UpdatePinhole(const char * controlURL, const char * servicetype,
const char * uniqueID,
const char * leaseTime);
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_DeletePinhole(const char * controlURL, const char * servicetype, const char * uniqueID);
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_CheckPinholeWorking(const char * controlURL, const char * servicetype,
const char * uniqueID, int * isWorking);
LIBSPEC int
MINIUPNP_LIBSPEC int
UPNP_GetPinholePackets(const char * controlURL, const char * servicetype,
const char * uniqueID, int * packets);

View File

@ -17,7 +17,7 @@ extern "C" {
/* strupnperror()
* Return a string description of the UPnP error code
* or NULL for undefinded errors */
LIBSPEC const char * strupnperror(int err);
MINIUPNP_LIBSPEC const char * strupnperror(int err);
#ifdef __cplusplus
}

View File

@ -1,4 +1,22 @@
$Id: Changelog.txt,v 1.374 2014/05/22 07:56:32 nanard Exp $
$Id: Changelog.txt,v 1.379 2014/10/22 08:52:17 nanard Exp $
2014/10/22:
Discard NAT-PMP packets coming from the WAN
2014/10/21:
small modifications to compile with exotic C libraries
2014/10/14:
add comments in miniupnpd.conf regarding security
2014/09/25:
DeletePortMapping now checks for client IP in Securemode
2014/06/xx:
Various fixes :
e->ipv6.flags |= IP6T_F_PROTO; (netfilter)
fix natpmp.c byte order conversion
add small delay before SSDP response to prevent flooding
2014/05/22:
Add ipv6_bind_address (option "ipv6_listening_ip")

View File

@ -45,25 +45,37 @@ FWNAME = pf
.endif
# better way to find if we are using ipf or pf
.if exists(/etc/rc.subr) && exists(/etc/rc.conf)
.if $(OSNAME) == "FreeBSD"
.if exists(/etc/rc.subr) && exists(/etc/rc.conf)
FWNAME != . /etc/rc.subr; . /etc/rc.conf; \
if checkyesno ipfilter_enable; then \
echo "ipf"; elif checkyesno pf_enable; then \
echo "pf"; else echo "ipfw"; fi
echo "pf"; elif checkyesno firewall_enable; then \
echo "ipfw"; else echo "pf"; fi
.else
FWNAME = pf
.endif
.endif
.if $(OSNAME) == "NetBSD"
.if exists(/etc/rc.subr) && exists(/etc/rc.conf)
FWNAME != . /etc/rc.subr; . /etc/rc.conf; \
if checkyesno ipfilter; then \
if checkyesno pf; then \
echo "pf"; elif checkyesno ipfilter; then \
echo "ipf"; else echo "pf"; fi
.else
FWNAME = pf
.endif
.endif
.if $(OSNAME) == "DragonFly"
.if exists(/etc/rc.subr) && exists(/etc/rc.conf)
FWNAME != . /etc/rc.subr; . /etc/rc.conf; \
if checkyesno ipfilter; then \
echo "ipf"; elif checkyesno pf_enable; then \
echo "pf"; else echo "ipfw"; fi
if checkyesno pf; then \
echo "pf"; elif checkyesno ipfilter; then \
echo "ipf"; else echo "pf"; fi
.else
FWNAME = pf
.endif
.endif

View File

@ -184,7 +184,7 @@ install: miniupnpd miniupnpd.8 miniupnpd.conf genuuid \
$(INSTALL) linux/miniupnpd.init.d.script $(DESTDIR)$(PREFIX)/etc/init.d/miniupnpd
$(INSTALL) -d $(DESTDIR)$(MANINSTALLDIR)
$(INSTALL) --mode=0644 miniupnpd.8 $(DESTDIR)$(MANINSTALLDIR)
gzip $(DESTDIR)$(MANINSTALLDIR)/miniupnpd.8
gzip -f $(DESTDIR)$(MANINSTALLDIR)/miniupnpd.8
# genuuid is using the uuidgen CLI tool which is part of libuuid
# from the e2fsprogs

View File

@ -20,8 +20,6 @@ MV = mv
INSTALL = install
STRIP = strip
CFLAGS += -DMACOSX
# OSNAME and FWNAME are used for building OS or FW dependent code.
OSNAME = $(shell uname)
ARCH = $(shell uname -p)

View File

@ -1,61 +1,32 @@
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* author: Ryan Wagoner and Thomas Bernard
* author: Gleb Smirnoff <glebius@FreeBSD.org>
* (c) 2006 Ryan Wagoner
* (c) 2014 Gleb Smirnoff
* This software is subject to the conditions detailed
* in the LICENCE file provided within the distribution */
#include <syslog.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#if defined(__FreeBSD__) || defined(__DragonFly__)
#ifdef __DragonFly__
#define _KERNEL_STRUCTURES
#endif
#include <net/if_var.h>
#endif
#if defined(__DragonFly__)
#include <net/pf/pfvar.h>
#else
#include <net/pfvar.h>
#endif
#include <kvm.h>
#include <fcntl.h>
#include <nlist.h>
#include <sys/queue.h>
#include <stdio.h>
#include <errno.h>
#include <ifaddrs.h>
#include <string.h>
#include <limits.h>
#include <syslog.h>
#ifdef ENABLE_GETIFSTATS_CACHING
#include <time.h>
#endif
#include "../getifstats.h"
#include "../config.h"
static struct nlist list[] = {
{"_ifnet", 0, 0, 0, 0},
{NULL,0, 0, 0, 0}
};
int
getifstats(const char * ifname, struct ifdata * data)
getifstats(const char *ifname, struct ifdata *data)
{
#if defined(__FreeBSD__) || defined(__DragonFly__)
struct ifnethead ifh;
#elif defined(__OpenBSD__) || defined(__NetBSD__)
struct ifnet_head ifh;
#else
#error "Dont know if I should use struct ifnethead or struct ifnet_head"
#endif
struct ifnet ifc;
struct ifnet *ifp;
kvm_t *kd;
ssize_t n;
char errstr[_POSIX2_LINE_MAX];
static struct ifaddrs *ifap, *ifa;
#ifdef ENABLE_GETIFSTATS_CACHING
static time_t cache_timestamp = 0;
static struct ifdata cache_data;
static time_t cache_timestamp;
time_t current_time;
#endif
if(!data)
@ -67,70 +38,40 @@ getifstats(const char * ifname, struct ifdata * data)
data->ibytes = 0;
if(!ifname || ifname[0]=='\0')
return -1;
#ifdef ENABLE_GETIFSTATS_CACHING
current_time = time(NULL);
if(current_time == ((time_t)-1)) {
syslog(LOG_ERR, "getifstats() : time() error : %m");
} else {
if(current_time < cache_timestamp + GETIFSTATS_CACHING_DURATION) {
memcpy(data, &cache_data, sizeof(struct ifdata));
return 0;
}
}
if (ifap != NULL &&
current_time < cache_timestamp + GETIFSTATS_CACHING_DURATION)
goto copy;
#endif
/*kd = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL);*/
kd = kvm_openfiles(NULL, NULL, NULL, O_RDONLY, errstr);
if(!kd)
{
syslog (LOG_ERR, "getifstats() : kvm_open(): %s", errstr);
return -1;
if (ifap != NULL) {
freeifaddrs(ifap);
ifap = NULL;
}
if(kvm_nlist(kd, list) < 0)
{
syslog(LOG_ERR, "getifstats() : kvm_nlist(): FAILED");
goto error;
}
if(!list[0].n_value)
{
syslog(LOG_ERR, "getifstats() : n_value(): FAILED");
goto error;
}
n = kvm_read(kd, list[0].n_value, &ifh, sizeof(ifh));
if(n<0)
{
syslog(LOG_ERR, "getifstats() : kvm_read(head): %s", kvm_geterr(kd));
goto error;
}
for(ifp = TAILQ_FIRST(&ifh); ifp; ifp = TAILQ_NEXT(&ifc, if_list))
{
n = kvm_read(kd, (u_long)ifp, &ifc, sizeof(ifc));
if(n<0)
{
syslog(LOG_ERR, "getifstats() : kvm_read(element): %s", kvm_geterr(kd));
goto error;
}
if(strcmp(ifname, ifc.if_xname) == 0)
{
/* found the right interface */
data->opackets = ifc.if_data.ifi_opackets;
data->ipackets = ifc.if_data.ifi_ipackets;
data->obytes = ifc.if_data.ifi_obytes;
data->ibytes = ifc.if_data.ifi_ibytes;
data->baudrate = ifc.if_data.ifi_baudrate;
kvm_close(kd);
if (getifaddrs(&ifap) != 0) {
syslog (LOG_ERR, "getifstats() : getifaddrs(): %s",
strerror(errno));
return (-1);
}
for (ifa = ifap; ifa; ifa = ifa->ifa_next)
if (ifa->ifa_addr->sa_family == AF_LINK &&
strcmp(ifa->ifa_name, ifname) == 0) {
#ifdef ENABLE_GETIFSTATS_CACHING
if(current_time!=((time_t)-1)) {
cache_timestamp = current_time;
memcpy(&cache_data, data, sizeof(struct ifdata));
}
cache_timestamp = current_time;
copy:
#endif
return 0; /* ok */
#define IFA_STAT(s) (((struct if_data *)ifa->ifa_data)->ifi_ ## s)
data->opackets = IFA_STAT(opackets);
data->ipackets = IFA_STAT(ipackets);
data->obytes = IFA_STAT(obytes);
data->ibytes = IFA_STAT(ibytes);
data->baudrate = IFA_STAT(baudrate);
return (0);
}
}
error:
kvm_close(kd);
return -1; /* not found or error */
}
return (-1);
}

View File

@ -1,4 +1,4 @@
/* $Id: minissdp.c,v 1.66 2014/04/20 16:34:26 nanard Exp $ */
/* $Id: minissdp.c,v 1.69 2014/09/06 08:17:01 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2014 Thomas Bernard
@ -26,6 +26,7 @@
#include "getroute.h"
#include "asyncsendto.h"
#include "codelength.h"
#include "macros.h"
/* SSDP ip/port */
#define SSDP_PORT (1900)
@ -607,6 +608,9 @@ SendSSDPNotifies(int s, const char * host, unsigned short http_port,
const char * dest_str;
int i=0;
char ver_str[4];
#ifndef ENABLE_IPV6
UNUSED(ipv6);
#endif
memset(&sockname, 0, sizeof(sockname));
#ifdef ENABLE_IPV6
@ -779,7 +783,7 @@ ProcessSSDPData(int s, const char *bufr, int n,
#if defined(UPNP_STRICT) || defined(DELAY_MSEARCH_RESPONSE)
int mx_value = -1;
#endif
unsigned int delay = 0;
unsigned int delay = 50; /* Non-zero default delay to prevent flooding */
/* UPnP Device Architecture v1.1. 1.3.3 Search response :
* Devices responding to a multicast M-SEARCH SHOULD wait a random period
* of time between 0 seconds and the number of seconds specified in the
@ -1144,11 +1148,11 @@ SendSSDPGoodbye(int * sockets, int n_sockets)
struct sockaddr_in6 sockname6;
struct sockaddr * sockname;
socklen_t socknamelen;
int ipv6 = 0;
#endif
int i, j;
char ver_str[4];
int ret = 0;
int ipv6 = 0;
const char * dest_str;
memset(&sockname4, 0, sizeof(struct sockaddr_in));

View File

@ -39,7 +39,7 @@
#include <sys/param.h>
#if defined(sun)
#include <kstat.h>
#else
#elif !defined(__linux__)
/* for BSD's sysctl */
#include <sys/sysctl.h>
#endif
@ -2133,6 +2133,20 @@ main(int argc, char * * argv)
msg_buff, sizeof(msg_buff));
if (len < 1)
continue;
/* Check if the packet is coming from a LAN to enforce RFC6886 :
* The NAT gateway MUST NOT accept mapping requests destined to the NAT
* gateway's external IP address or received on its external network
* interface. Only packets received on the internal interface(s) with a
* destination address matching the internal address(es) of the NAT
* gateway should be allowed. */
lan_addr = get_lan_for_peer((struct sockaddr *)&senderaddr);
if(lan_addr == NULL) {
char sender_str[64];
sockaddr_to_string((struct sockaddr *)&senderaddr, sender_str, sizeof(sender_str));
syslog(LOG_WARNING, "NAT-PMP/PCP packet sender %s not from a LAN, ignoring",
sender_str);
continue;
}
#ifdef ENABLE_PCP
if (msg_buff[0]==0) { /* version equals to 0 -> means NAT-PMP */
ProcessIncomingNATPMPPacket(snatpmp[i], msg_buff, len,

View File

@ -1,5 +1,5 @@
# WAN network interface
ext_ifname=eth1
#ext_ifname=eth1
#ext_ifname=xl1
# if the WAN interface has several IP addresses, you
# can specify the one to use below
@ -15,10 +15,14 @@ ext_ifname=eth1
# address associated with the subnet follows. for example :
# listening_ip=192.168.0.1/24 88.22.44.13
#listening_ip=192.168.0.1/24
listening_ip=192.168.10.109/24
#listening_ip=10.5.0.0/16
#listening_ip=eth0
# CAUTION: mixing up WAN and LAN interfaces may introduce security risks!
# be sure to assign the correct interfaces to LAN and WAN and consider
# implementing UPnP permission rules at the bottom of this configuration file
# port for HTTP (descriptions and SOAP) traffic. set 0 for autoselect.
http_port=0
#http_port=0
# port for HTTPS. set to 0 for autoselect (default)
#https_port=0
@ -28,15 +32,16 @@ http_port=0
#minissdpdsocket=/var/run/minissdpd.sock
# enable NAT-PMP support (default is no)
enable_natpmp=yes
#enable_natpmp=yes
# enable UPNP support (default is yes)
enable_upnp=yes
#enable_upnp=no
# PCP :
# configure minimal and maximal lifetime of the port mapping in seconds
# 120s and 86400s (24h) are suggested values from PCP-base
min_lifetime=120
max_lifetime=86400
#min_lifetime=120
#max_lifetime=86400
# chain names for netfilter (not used for pf or ipf).
# default is MINIUPNPD for both
@ -68,8 +73,9 @@ max_lifetime=86400
#model_url=http://miniupnp.free.fr/
# bitrates reported by daemon in bits per second
bitrate_up=1000000
bitrate_down=10000000
# by default miniupnpd tries to get WAN interface speed
#bitrate_up=1000000
#bitrate_down=10000000
# "secure" mode : when enabled, UPnP client are allowed to add mappings only
# to their IP.
@ -116,12 +122,12 @@ clean_ruleset_interval=600
#quickrules=no
# uuid : generate your own with "make genuuid"
uuid=3d3cec3a-8cf0-11e0-98ee-001a6bd2d07b
uuid=00000000-0000-0000-0000-000000000000
# serial and model number the daemon will report to clients
# in its XML description
serial=12345678
model_number=1
#serial=12345678
#model_number=1
# UPnP permission rules
# (allow|deny) (external port range) ip/mask (internal port range)
@ -130,6 +136,11 @@ model_number=1
# ip/mask format must be nn.nn.nn.nn/nn
# it is advised to only allow redirection of port above 1024
# and to finish the rule set with "deny 0-65535 0.0.0.0/0 0-65535"
# The following default ruleset allows specific LAN side IP addresses
# to request only ephemeral ports. it is recommended that users
# modify the IP ranges to match their own internal networks, and
# also consider implementing network-specific restrictions
# CAUTION: failure to enforce any rules may permit insecure requests to be made!
allow 1024-65535 192.168.0.0/24 1024-65535
allow 1024-65535 192.168.1.0/24 1024-65535
allow 1024-65535 192.168.0.0/23 22

View File

@ -54,7 +54,7 @@ INLINE void writenu32(uint8_t * p, uint32_t n)
#define WRITENU32(p, n) writenu32(p, n)
INLINE void writenu16(uint8_t * p, uint16_t n)
{
p[0] = (n < 0xff00) >> 8;
p[0] = (n & 0xff00) >> 8;
p[1] = n & 0xff;
}
#define WRITENU16(p, n) writenu16(p, n)

View File

@ -206,6 +206,8 @@ int add_pinhole(const char * ifname,
e = calloc(1, sizeof(struct ip6t_entry));
e->ipv6.proto = proto;
if (proto)
e->ipv6.flags |= IP6T_F_PROTO;
if(ifname)
strncpy(e->ipv6.iniface, ifname, IFNAMSIZ);

View File

@ -8,6 +8,7 @@
#define IPTPINHOLE_H_INCLUDED
#ifdef ENABLE_UPNPPINHOLE
#include <sys/types.h>
int add_pinhole(const char * ifname,
const char * rem_host, unsigned short rem_port,

View File

@ -135,10 +135,10 @@ typedef enum pcp_options {
} pcp_options_t;
#ifdef WIN32
#ifdef _WIN32
#pragma warning (push)
#pragma warning (disable:4200)
#endif /* WIN32 */
#endif /* _WIN32 */
#pragma pack(push, 1)
@ -285,6 +285,6 @@ typedef struct pcp_filter_option {
#pragma pack(pop)
#ifdef WIN32
#ifdef _WIN32
#pragma warning (pop)
#endif /* WIN32 */
#endif /* _WIN32 */

View File

@ -1020,6 +1020,7 @@ static int CreatePCPMap_FW(pcp_info_t *pcp_msg_info)
&uid);
if (r < 0)
return PCP_ERR_NO_RESOURCES;
pcp_msg_info->ext_port = pcp_msg_info->int_port;
return PCP_SUCCESS;
#else
return PCP_ERR_NO_RESOURCES;

View File

@ -49,7 +49,7 @@
#ifdef __DragonFly__
#include <net/pf/pfvar.h>
#else
#ifdef MACOSX
#ifdef __APPLE__
#define PRIVATE 1
#endif
#include <net/pfvar.h>
@ -269,7 +269,7 @@ add_redirect_rule2(const char * ifname,
pcr.rule.rdr.addr.type = PF_ADDR_ADDRMASK;
#endif
#ifdef MACOSX
#ifdef __APPLE__
pcr.rule.dst.xport.range.op = PF_OP_EQ;
pcr.rule.dst.xport.range.port[0] = htons(eport);
pcr.rule.dst.xport.range.port[1] = htons(eport);
@ -528,7 +528,7 @@ get_redirect_rule(const char * ifname, unsigned short eport, int proto,
syslog(LOG_ERR, "ioctl(dev, DIOCGETRULE): %m");
goto error;
}
#ifdef MACOSX
#ifdef __APPLE__
if( (eport == ntohs(pr.rule.dst.xport.range.port[0]))
&& (eport == ntohs(pr.rule.dst.xport.range.port[1]))
#else
@ -636,7 +636,7 @@ priv_delete_redirect_rule(const char * ifname, unsigned short eport,
syslog(LOG_ERR, "ioctl(dev, DIOCGETRULE): %m");
goto error;
}
#ifdef MACOSX
#ifdef __APPLE__
if( (eport == ntohs(pr.rule.dst.xport.range.port[0]))
&& (eport == ntohs(pr.rule.dst.xport.range.port[1]))
#else
@ -830,7 +830,7 @@ get_redirect_rule_by_index(int index,
goto error;
}
*proto = pr.rule.proto;
#ifdef MACOSX
#ifdef __APPLE__
*eport = ntohs(pr.rule.dst.xport.range.port[0]);
#else
*eport = ntohs(pr.rule.dst.port[0]);
@ -946,7 +946,7 @@ get_portmappings_in_range(unsigned short startport, unsigned short endport,
syslog(LOG_ERR, "ioctl(dev, DIOCGETRULE): %m");
continue;
}
#ifdef MACOSX
#ifdef __APPLE__
eport = ntohs(pr.rule.dst.xport.range.port[0]);
if( (eport == ntohs(pr.rule.dst.xport.range.port[1]))
#else

View File

@ -15,7 +15,7 @@
#ifdef __DragonFly__
#include <net/pf/pfvar.h>
#else
#ifdef MACOSX
#ifdef __APPLE__
#define PRIVATE 1
#endif
#include <net/pfvar.h>

View File

@ -368,9 +368,9 @@ static const struct argument GetExternalIPAddressArgs[] =
static const struct argument DeletePortMappingArgs[] =
{
{1, 11},
{1, 12},
{1, 14},
{1, 11}, /* RemoteHost */
{1, 12}, /* ExternalPort */
{1, 14}, /* PortMappingProtocol */
{0, 0}
};

View File

@ -1,4 +1,4 @@
/* $Id: upnpsoap.c,v 1.123 2014/04/09 12:39:54 nanard Exp $ */
/* $Id: upnpsoap.c,v 1.128 2014/09/25 09:02:25 nanard Exp $ */
/* MiniUPnP project
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
* (c) 2006-2014 Thomas Bernard
@ -707,13 +707,37 @@ DeletePortMapping(struct upnphttp * h, const char * action)
eport = (unsigned short)atoi(ext_port);
/* TODO : if in secure mode, check the IP
syslog(LOG_INFO, "%s: external port: %hu, protocol: %s",
action, eport, protocol);
/* if in secure mode, check the IP
* Removing a redirection is not a security threat,
* just an annoyance for the user using it. So this is not
* a priority. */
syslog(LOG_INFO, "%s: external port: %hu, protocol: %s",
action, eport, protocol);
if(GETFLAG(SECUREMODEMASK))
{
char int_ip[32];
struct in_addr int_ip_addr;
unsigned short iport;
unsigned int leaseduration = 0;
r = upnp_get_redirection_infos(eport, protocol, &iport,
int_ip, sizeof(int_ip),
NULL, 0, NULL, 0,
&leaseduration);
if(r >= 0)
{
if(inet_pton(AF_INET, int_ip, &int_ip_addr) > 0)
{
if(h->clientaddr.s_addr != int_ip_addr.s_addr)
{
SoapError(h, 606, "Action not authorized");
/*SoapError(h, 714, "NoSuchEntryInArray");*/
ClearNameValueList(&data);
return;
}
}
}
}
r = upnp_delete_redirection(eport, protocol);

View File

@ -19,6 +19,7 @@
#ifdef AF_LINK
#include <net/if_dl.h>
#endif
#include <errno.h>
#include "upnputils.h"
#include "upnpglobalvars.h"
@ -35,17 +36,23 @@ sockaddr_to_string(const struct sockaddr * addr, char * str, size_t size)
switch(addr->sa_family)
{
#ifdef AF_INET6
case AF_INET6:
inet_ntop(addr->sa_family,
&((struct sockaddr_in6 *)addr)->sin6_addr,
buffer, sizeof(buffer));
if(inet_ntop(addr->sa_family,
&((struct sockaddr_in6 *)addr)->sin6_addr,
buffer, sizeof(buffer)) == NULL) {
snprintf(buffer, sizeof(buffer), "inet_ntop: %s", strerror(errno));
}
port = ntohs(((struct sockaddr_in6 *)addr)->sin6_port);
n = snprintf(str, size, "[%s]:%hu", buffer, port);
break;
#endif /* AF_INET6 */
case AF_INET:
inet_ntop(addr->sa_family,
&((struct sockaddr_in *)addr)->sin_addr,
buffer, sizeof(buffer));
if(inet_ntop(addr->sa_family,
&((struct sockaddr_in *)addr)->sin_addr,
buffer, sizeof(buffer)) == NULL) {
snprintf(buffer, sizeof(buffer), "inet_ntop: %s", strerror(errno));
}
port = ntohs(((struct sockaddr_in *)addr)->sin_port);
n = snprintf(str, size, "%s:%hu", buffer, port);
break;
@ -63,7 +70,7 @@ sockaddr_to_string(const struct sockaddr * addr, char * str, size_t size)
link_ntoa(sdl));
}
break;
#endif
#endif /* AF_LINK */
default:
n = snprintf(str, size, "unknown address family %d", addr->sa_family);
#if 0
@ -93,7 +100,9 @@ struct lan_addr_s *
get_lan_for_peer(const struct sockaddr * peer)
{
struct lan_addr_s * lan_addr = NULL;
#ifdef DEBUG
char dbg_str[64];
#endif /* DEBUG */
#ifdef ENABLE_IPV6
if(peer->sa_family == AF_INET6)
@ -141,7 +150,7 @@ get_lan_for_peer(const struct sockaddr * peer)
}
else if(peer->sa_family == AF_INET)
{
#endif
#endif /* ENABLE_IPV6 */
for(lan_addr = lan_addrs.lh_first;
lan_addr != NULL;
lan_addr = lan_addr->list.le_next)
@ -152,8 +161,9 @@ get_lan_for_peer(const struct sockaddr * peer)
}
#ifdef ENABLE_IPV6
}
#endif
#endif /* ENABLE_IPV6 */
#ifdef DEBUG
sockaddr_to_string(peer, dbg_str, sizeof(dbg_str));
if(lan_addr) {
syslog(LOG_DEBUG, "%s: %s found in LAN %s %s",
@ -163,6 +173,7 @@ get_lan_for_peer(const struct sockaddr * peer)
syslog(LOG_DEBUG, "%s: %s not found !", "get_lan_for_peer()",
dbg_str);
}
#endif /* DEBUG */
return lan_addr;
}