2727#include "logging.h"
2828#include "process.h"
2929
30- int fh_ipt6_flush ( int auto_create )
30+ int fh_ipt6_setup ( void )
3131{
32+ char xmark_str [64 ], nfqnum_str [32 ], iface_str [32 ];
33+ size_t i , ipt_cmds_cnt , ipt_opt_cmds_cnt ;
3234 int res ;
33- size_t i , cnt ;
34- char * ipt_flush_cmd [] = {"ip6tables" , "-w" , "-t" , "mangle" ,
35- "-F" , "FAKEHTTP" , NULL };
36- char * ipt_create_cmds [][32 ] = {
35+ char * ipt_cmds [][32 ] = {
3736 {"ip6tables" , "-w" , "-t" , "mangle" , "-N" , "FAKEHTTP" , NULL },
3837
3938 {"ip6tables" , "-w" , "-t" , "mangle" , "-I" , "INPUT" , "-j" , "FAKEHTTP" ,
4039 NULL },
4140
4241 {"ip6tables" , "-w" , "-t" , "mangle" , "-I" , "FORWARD" , "-j" , "FAKEHTTP" ,
43- NULL }};
44-
45- res = fh_execute_command (ipt_flush_cmd , 1 , NULL );
46- if (res < 0 ) {
47- if (!auto_create ) {
48- E (T (fh_execute_command ));
49- return -1 ;
50- }
51-
52- cnt = sizeof (ipt_create_cmds ) / sizeof (* ipt_create_cmds );
53- for (i = 0 ; i < cnt ; i ++ ) {
54- res = fh_execute_command (ipt_create_cmds [i ], 0 , NULL );
55- if (res < 0 ) {
56- E (T (fh_execute_command ));
57- return -1 ;
58- }
59- }
60- }
61-
62- return 0 ;
63- }
64-
42+ NULL },
6543
66- int fh_ipt6_add (void )
67- {
68- char xmark_str [64 ], nfqnum_str [32 ], iface_str [32 ];
69- size_t i , ipt_cmds_cnt , ipt_opt_cmds_cnt ;
70- int res ;
71- char * ipt_cmds [][32 ] = {
7244 /*
7345 exclude marked packets
7446 */
@@ -149,6 +121,8 @@ int fh_ipt6_add(void)
149121 return -1 ;
150122 }
151123
124+ fh_ipt6_cleanup ();
125+
152126 for (i = 0 ; i < ipt_cmds_cnt ; i ++ ) {
153127 res = fh_execute_command (ipt_cmds [i ], 0 , NULL );
154128 if (res < 0 ) {
@@ -163,3 +137,33 @@ int fh_ipt6_add(void)
163137
164138 return 0 ;
165139}
140+
141+
142+ void fh_ipt6_cleanup (void )
143+ {
144+ size_t i , cnt ;
145+ char * ipt_cmds [][32 ] = {
146+ {"ip6tables" , "-w" , "-t" , "mangle" , "-F" , "FAKEHTTP" , NULL },
147+
148+ {"ip6tables" , "-w" , "-t" , "mangle" , "-D" , "PREROUTING" , "-j" ,
149+ "FAKEHTTP" , NULL },
150+
151+ {"ip6tables" , "-w" , "-t" , "mangle" , "-D" , "INPUT" , "-j" , "FAKEHTTP" ,
152+ NULL },
153+
154+ {"ip6tables" , "-w" , "-t" , "mangle" , "-D" , "FORWARD" , "-j" , "FAKEHTTP" ,
155+ NULL },
156+
157+ {"ip6tables" , "-w" , "-t" , "mangle" , "-D" , "OUTPUT" , "-j" , "FAKEHTTP" ,
158+ NULL },
159+
160+ {"ip6tables" , "-w" , "-t" , "mangle" , "-D" , "POSTROUTING" , "-j" ,
161+ "FAKEHTTP" , NULL },
162+
163+ {"ip6tables" , "-w" , "-t" , "mangle" , "-X" , "FAKEHTTP" , NULL }};
164+
165+ cnt = sizeof (ipt_cmds ) / sizeof (* ipt_cmds );
166+ for (i = 0 ; i < cnt ; i ++ ) {
167+ fh_execute_command (ipt_cmds [i ], 1 , NULL );
168+ }
169+ }
0 commit comments