|
version 1.1.1.2, 2012/05/29 12:55:57
|
version 1.1.1.3, 2013/07/22 00:32:35
|
|
Line 1
|
Line 1
|
| /* $Id$ */ |
/* $Id$ */ |
| /* MiniUPnP project |
/* MiniUPnP project |
| * http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ |
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/ |
| * (c) 2006-2010 Thomas Bernard | * (c) 2006-2012 Thomas Bernard |
| * This software is subject to the conditions detailed |
* This software is subject to the conditions detailed |
| * in the LICENCE file provided within the distribution */ |
* in the LICENCE file provided within the distribution */ |
| |
|
|
Line 55
|
Line 55
|
| #include <stdio.h> |
#include <stdio.h> |
| #include <stdlib.h> |
#include <stdlib.h> |
| |
|
| |
#include "../macros.h" |
| #include "../config.h" |
#include "../config.h" |
| #include "obsdrdr.h" |
#include "obsdrdr.h" |
| #include "../upnpglobalvars.h" |
#include "../upnpglobalvars.h" |
|
Line 101 remove_timestamp_entry(unsigned short eport, int proto
|
Line 102 remove_timestamp_entry(unsigned short eport, int proto
|
| } |
} |
| } |
} |
| |
|
| /* anchor name */ |
|
| static const char anchor_name[] = "miniupnpd"; |
|
| |
|
| /* /dev/pf when opened */ |
/* /dev/pf when opened */ |
| static int dev = -1; | int dev = -1; |
| |
|
| /* shutdown_redirect() : |
/* shutdown_redirect() : |
| * close the /dev/pf device */ |
* close the /dev/pf device */ |
|
Line 214 add_redirect_rule2(const char * ifname,
|
Line 212 add_redirect_rule2(const char * ifname,
|
| if(1) |
if(1) |
| { |
{ |
| pcr.rule.direction = PF_IN; |
pcr.rule.direction = PF_IN; |
| //pcr.rule.src.addr.type = PF_ADDR_NONE; | /*pcr.rule.src.addr.type = PF_ADDR_NONE;*/ |
| pcr.rule.src.addr.type = PF_ADDR_ADDRMASK; |
pcr.rule.src.addr.type = PF_ADDR_ADDRMASK; |
| pcr.rule.dst.addr.type = PF_ADDR_ADDRMASK; |
pcr.rule.dst.addr.type = PF_ADDR_ADDRMASK; |
| pcr.rule.nat.addr.type = PF_ADDR_NONE; |
pcr.rule.nat.addr.type = PF_ADDR_NONE; |
| pcr.rule.rdr.addr.type = PF_ADDR_ADDRMASK; |
pcr.rule.rdr.addr.type = PF_ADDR_ADDRMASK; |
| #endif |
#endif |
| | |
| pcr.rule.dst.port_op = PF_OP_EQ; |
pcr.rule.dst.port_op = PF_OP_EQ; |
| pcr.rule.dst.port[0] = htons(eport); |
pcr.rule.dst.port[0] = htons(eport); |
| pcr.rule.dst.port[1] = htons(eport); |
pcr.rule.dst.port[1] = htons(eport); |
|
Line 248 add_redirect_rule2(const char * ifname,
|
Line 246 add_redirect_rule2(const char * ifname,
|
| #ifdef PFRULE_HAS_RTABLEID |
#ifdef PFRULE_HAS_RTABLEID |
| pcr.rule.rtableid = -1; /* first appeared in OpenBSD 4.0 */ |
pcr.rule.rtableid = -1; /* first appeared in OpenBSD 4.0 */ |
| #endif |
#endif |
| |
#ifdef PFRULE_HAS_ONRDOMAIN |
| |
pcr.rule.onrdomain = -1; /* first appeared in OpenBSD 5.0 */ |
| |
#endif |
| pcr.rule.quick = 1; |
pcr.rule.quick = 1; |
| pcr.rule.keep_state = PF_STATE_NORMAL; |
pcr.rule.keep_state = PF_STATE_NORMAL; |
| if(tag) |
if(tag) |
|
Line 327 add_filter_rule2(const char * ifname,
|
Line 328 add_filter_rule2(const char * ifname,
|
| int proto, const char * desc) |
int proto, const char * desc) |
| { |
{ |
| #ifndef PF_ENABLE_FILTER_RULES |
#ifndef PF_ENABLE_FILTER_RULES |
| |
UNUSED(ifname); |
| |
UNUSED(rhost); UNUSED(iaddr); |
| |
UNUSED(eport); UNUSED(iport); |
| |
UNUSED(proto); UNUSED(desc); |
| return 0; |
return 0; |
| #else |
#else |
| int r; |
int r; |
|
Line 358 add_filter_rule2(const char * ifname,
|
Line 363 add_filter_rule2(const char * ifname,
|
| if(1) |
if(1) |
| { |
{ |
| #endif |
#endif |
| | |
| pcr.rule.dst.port_op = PF_OP_EQ; |
pcr.rule.dst.port_op = PF_OP_EQ; |
| pcr.rule.dst.port[0] = htons(eport); |
pcr.rule.dst.port[0] = htons(eport); |
| pcr.rule.direction = PF_IN; |
pcr.rule.direction = PF_IN; |
|
Line 376 add_filter_rule2(const char * ifname,
|
Line 381 add_filter_rule2(const char * ifname,
|
| pcr.rule.flags = TH_SYN; |
pcr.rule.flags = TH_SYN; |
| pcr.rule.flagset = (TH_SYN|TH_ACK); |
pcr.rule.flagset = (TH_SYN|TH_ACK); |
| #ifdef PFRULE_HAS_RTABLEID |
#ifdef PFRULE_HAS_RTABLEID |
| pcr.rule.rtableid = -1; /* first appeared in OpenBSD 4.0 */ | pcr.rule.rtableid = -1; /* first appeared in OpenBSD 4.0 */ |
| #endif |
#endif |
| |
#ifdef PFRULE_HAS_ONRDOMAIN |
| |
pcr.rule.onrdomain = -1; /* first appeared in OpenBSD 5.0 */ |
| |
#endif |
| pcr.rule.keep_state = 1; |
pcr.rule.keep_state = 1; |
| strlcpy(pcr.rule.label, desc, PF_RULE_LABEL_SIZE); |
strlcpy(pcr.rule.label, desc, PF_RULE_LABEL_SIZE); |
| if(queue) |
if(queue) |
|
Line 399 add_filter_rule2(const char * ifname,
|
Line 407 add_filter_rule2(const char * ifname,
|
| TAILQ_INIT(&pcr.rule.rpool.list); |
TAILQ_INIT(&pcr.rule.rpool.list); |
| inet_pton(AF_INET, iaddr, &a->addr.v.a.addr.v4.s_addr); |
inet_pton(AF_INET, iaddr, &a->addr.v.a.addr.v4.s_addr); |
| TAILQ_INSERT_TAIL(&pcr.rule.rpool.list, a, entries); |
TAILQ_INSERT_TAIL(&pcr.rule.rpool.list, a, entries); |
| | |
| /* we have any - any port = # keep state label */ |
/* we have any - any port = # keep state label */ |
| /* we want any - iaddr port = # keep state label */ |
/* we want any - iaddr port = # keep state label */ |
| /* memcpy(&pcr.rule.dst, a, sizeof(struct pf_pooladdr)); */ |
/* memcpy(&pcr.rule.dst, a, sizeof(struct pf_pooladdr)); */ |
|
Line 457 get_redirect_rule(const char * ifname, unsigned short
|
Line 465 get_redirect_rule(const char * ifname, unsigned short
|
| #ifndef PF_NEWSTYLE |
#ifndef PF_NEWSTYLE |
| struct pfioc_pooladdr pp; |
struct pfioc_pooladdr pp; |
| #endif |
#endif |
| |
UNUSED(ifname); |
| |
|
| if(dev<0) { |
if(dev<0) { |
| syslog(LOG_ERR, "pf device is not open"); |
syslog(LOG_ERR, "pf device is not open"); |
| return -1; |
return -1; |
|
Line 556 delete_redirect_rule(const char * ifname, unsigned sho
|
Line 566 delete_redirect_rule(const char * ifname, unsigned sho
|
| { |
{ |
| int i, n; |
int i, n; |
| struct pfioc_rule pr; |
struct pfioc_rule pr; |
| |
UNUSED(ifname); |
| |
|
| if(dev<0) { |
if(dev<0) { |
| syslog(LOG_ERR, "pf device is not open"); |
syslog(LOG_ERR, "pf device is not open"); |
| return -1; |
return -1; |
|
Line 608 int
|
Line 620 int
|
| delete_filter_rule(const char * ifname, unsigned short eport, int proto) |
delete_filter_rule(const char * ifname, unsigned short eport, int proto) |
| { |
{ |
| #ifndef PF_ENABLE_FILTER_RULES |
#ifndef PF_ENABLE_FILTER_RULES |
| |
UNUSED(ifname); UNUSED(eport); UNUSED(proto); |
| return 0; |
return 0; |
| #else |
#else |
| int i, n; |
int i, n; |
|
Line 865 list_rules(void)
|
Line 878 list_rules(void)
|
| perror("DIOCGETRULE"); |
perror("DIOCGETRULE"); |
| printf(" %s %s %d:%d -> %d:%d proto %d keep_state=%d action=%d\n", |
printf(" %s %s %d:%d -> %d:%d proto %d keep_state=%d action=%d\n", |
| pr.rule.ifname, |
pr.rule.ifname, |
| inet_ntop(AF_INET, &pr.rule.src.addr.v.a.addr.v4.s_addr, buf, 32); | inet_ntop(AF_INET, &pr.rule.src.addr.v.a.addr.v4.s_addr, buf, 32), |
| (int)ntohs(pr.rule.dst.port[0]), |
(int)ntohs(pr.rule.dst.port[0]), |
| (int)ntohs(pr.rule.dst.port[1]), |
(int)ntohs(pr.rule.dst.port[1]), |
| #ifndef PF_NEWSTYLE |
#ifndef PF_NEWSTYLE |