miniupnpd/pf: add clear_filter_rules() for testing
also add a --clear / -c argument to testobsdrdr programm
This commit is contained in:
parent
5512d022ac
commit
65b776f1ed
|
@ -180,6 +180,45 @@ clear_redirect_rules(void)
|
|||
error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
clear_filter_rules(void)
|
||||
{
|
||||
#ifndef PF_ENABLE_FILTER_RULES
|
||||
return 0;
|
||||
#else
|
||||
struct pfioc_trans io;
|
||||
struct pfioc_trans_e ioe;
|
||||
if(dev<0) {
|
||||
syslog(LOG_ERR, "pf device is not open");
|
||||
return -1;
|
||||
}
|
||||
memset(&ioe, 0, sizeof(ioe));
|
||||
io.size = 1;
|
||||
io.esize = sizeof(ioe);
|
||||
io.array = &ioe;
|
||||
#ifndef PF_NEWSTYLE
|
||||
ioe.rs_num = PF_RULESET_FILTER;
|
||||
#else
|
||||
/* ? */
|
||||
ioe.type = PF_TRANS_RULESET;
|
||||
#endif
|
||||
strlcpy(ioe.anchor, anchor_name, MAXPATHLEN);
|
||||
if(ioctl(dev, DIOCXBEGIN, &io) < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ioctl(dev, DIOCXBEGIN, ...): %m");
|
||||
goto error;
|
||||
}
|
||||
if(ioctl(dev, DIOCXCOMMIT, &io) < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "ioctl(dev, DIOCXCOMMIT, ...): %m");
|
||||
goto error;
|
||||
}
|
||||
return 0;
|
||||
error:
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
/* add_redirect_rule2() :
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $Id: obsdrdr.h,v 1.22 2014/02/28 20:18:41 nanard Exp $ */
|
||||
/* $Id: obsdrdr.h,v 1.23 2014/03/06 12:24:33 nanard Exp $ */
|
||||
/* MiniUPnP project
|
||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||
* (c) 2006-2014 Thomas Bernard
|
||||
|
@ -58,8 +58,12 @@ int
|
|||
delete_redirect_and_filter_rules(const char * ifname, unsigned short eport,
|
||||
int proto);
|
||||
|
||||
#ifdef TEST
|
||||
int
|
||||
clear_redirect_rules(void);
|
||||
int
|
||||
clear_filter_rules(void);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
/* $Id: testobsdrdr.c,v 1.24 2012/04/18 19:42:03 nanard Exp $ */
|
||||
/* $Id: testobsdrdr.c,v 1.28 2014/03/06 13:02:47 nanard Exp $ */
|
||||
/* MiniUPnP project
|
||||
* http://miniupnp.free.fr/ or http://miniupnp.tuxfamily.org/
|
||||
* (c) 2006-2012 Thomas Bernard
|
||||
* (c) 2006-2014 Thomas Bernard
|
||||
* This software is subject to the conditions detailed
|
||||
* in the LICENCE file provided within the distribution */
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
@ -17,6 +18,7 @@
|
|||
int runtime_flags = 0;
|
||||
const char * tag = 0;
|
||||
const char * anchor_name = "miniupnpd";
|
||||
const char * queue = NULL;
|
||||
|
||||
void
|
||||
list_rules(void);
|
||||
|
@ -67,7 +69,7 @@ test_index(void)
|
|||
}
|
||||
|
||||
int
|
||||
main(int arc, char * * argv)
|
||||
main(int argc, char * * argv)
|
||||
{
|
||||
char buf[32];
|
||||
char desc[64];
|
||||
|
@ -77,6 +79,12 @@ main(int arc, char * * argv)
|
|||
unsigned int timestamp;
|
||||
u_int64_t packets = 0;
|
||||
u_int64_t bytes = 0;
|
||||
int clear = 0;
|
||||
|
||||
if(argc > 1) {
|
||||
if(0 == strcmp(argv[1], "--clear") || 0 == strcmp(argv[1], "-c"))
|
||||
clear = 1;
|
||||
}
|
||||
|
||||
openlog("testobsdrdr", LOG_PERROR, LOG_USER);
|
||||
if(init_redirect() < 0)
|
||||
|
@ -121,12 +129,13 @@ main(int arc, char * * argv)
|
|||
else
|
||||
printf("delete_redirect_rule() succeded\n");
|
||||
|
||||
#if 0
|
||||
test_index();
|
||||
|
||||
clear_redirect_rules();
|
||||
list_rules();
|
||||
#endif
|
||||
if(clear) {
|
||||
clear_redirect_rules();
|
||||
clear_filter_rules();
|
||||
}
|
||||
/*list_rules();*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue