iptables: expose option to zero packet and byte counters for a specific rule using iptables/ip6tables
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 1/1 iptables: expose option to zero packet and byte counters for a specific rule using iptables/ip6tables
iptc_zero_counter/ip6tc_zero_counter are functions available in libiptc to zero counters for a rule in a given chain. However, this is not exposed in iptables/ip6tables. The patch below exposes the underlying function to the user to zero out packet and byte counters for a specific rule.
build-vm-jenner:/jenner/pkgs/iptables# git diff -u 039683e8958bb161d3eaece4853898ee575bc0f5 iptables.c ip6tables.c
ip6tables.c +23 -6
@@ -79,9 +79,10 @@#define CMD_SET_POLICY 0x0400U#define CMD_RENAME_CHAIN 0x0800U#define CMD_LIST_RULES 0x1000U -#define NUMBER_OF_CMD 14 +#define CMD_ZERO_NUM 0x2000U +#define NUMBER_OF_CMD 15static const char cmdflags[] = {'I' ,'D' ,'D' ,'R' ,'A' ,'L' ,'F' ,'Z' , -'N' ,'X' ,'P' ,'E' ,'S' }; +'Z' ,'N' ,'X' ,'P' ,'E' ,'S' };#define OPTION_OFFSET 256
@@ -165,6 +166,7 @@ static char commands_v_options[NUMBER_OF_CMD][NUMBER_OF_OPT] = /*LIST*/ {' ','x','x','x','x',' ',' ','x','x',' ','x'}, /*FLUSH*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, /*ZERO*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, +/*ZERO_NUM*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, /*NEW_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, /*DEL_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, /*SET_POLICY*/{'x','x','x','x','x',' ','x','x','x','x',' '},
@@ -308,7 +310,8 @@ exit_printhelp(struct ip6tables_rule_match *matches)" --list-rules -S [chain [rulenum]]\n" " Print the rules in a chain or all chains\n" " --flush -F [chain] Delete all rules in chain or all chains\n" -" --zero -Z [chain] Zero counters in chain or all chains\n" +" --zero -Z [chain[rulenum]]\n" +" Zero counters in chain or all chains\n" " --new -N chain Create a new user-defined chain\n" " --delete-chain\n" " -X [chain] Delete a user-defined chain\n"
@@ -1494,7 +1497,7 @@ int do_command6(int argc, char *argv[], char **table, ip6tc_handle_t *handle)break ;case 'L' : -add_command (&command,CMD_LIST ,CMD_ZERO , +add_command (&command,CMD_LIST ,CMD_ZERO |CMD_ZERO_NUM , invert);if (optarg) chain = optarg; else if (optind < argc && argv[optind][0] != '-'
@@ -1506,8 +1509,8 @@ int do_command6(int argc, char *argv[], char **table, ip6tc_handle_t *handle)break ;case 'S' : -add_command (&command,CMD_LIST_RULES ,CMD_ZERO , - invert); +add_command (&command,CMD_LIST_RULES , +CMD_ZERO |CMD_ZERO_NUM , invert);if (optarg) chain = optarg;else if (optind < argc && argv[optind][0 ] !='-' && argv[optind][0 ] !='!' )
@@ -1533,6 +1536,11 @@ int do_command6(int argc, char *argv[], char **table, ip6tc_handle_t *handle)else if (optind < argc && argv[optind][0 ] !='-' && argv[optind][0 ] !='!' ) chain = argv[optind++]; +if (optind < argc && argv[optind][0 ] !='-' + && argv[optind][0 ] !='!' ) { + rulenum =parse_rulenumber (argv[optind++]); + command =CMD_ZERO_NUM ; + }break ;case 'N' :
@@ -2035,8 +2043,12 @@ int do_command6(int argc, char *argv[], char **table, ip6tc_handle_t *handle)case CMD_ZERO : ret =zero_entries (chain, options&OPT_VERBOSE , handle);break ; +case CMD_ZERO_NUM : + ret =ip6tc_zero_counter (chain, rulenum, handle); +break ;case CMD_LIST :case CMD_LIST |CMD_ZERO : +case CMD_LIST |CMD_ZERO_NUM : ret = list_entries(chain, rulenum, options&OPT_VERBOSE,
@@ -2047,9 +2059,12 @@ int do_command6(int argc, char *argv[], char **table, ip6tc_handle_t *handle)if (ret && (command &CMD_ZERO )) ret =zero_entries (chain, options&OPT_VERBOSE , handle); +if (ret && (command &CMD_ZERO_NUM )) + ret =ip6tc_zero_counter (chain, rulenum, handle);break ;case CMD_LIST_RULES :case CMD_LIST_RULES |CMD_ZERO : +case CMD_LIST_RULES |CMD_ZERO_NUM : ret = list_rules(chain, rulenum, options&OPT_VERBOSE,
@@ -2057,6 +2072,8 @@ int do_command6(int argc, char *argv[], char **table, ip6tc_handle_t *handle)if (ret && (command &CMD_ZERO )) ret =zero_entries (chain, options&OPT_VERBOSE , handle); +if (ret && (command &CMD_ZERO_NUM )) + ret =ip6tc_zero_counter (chain, rulenum, handle);break ;case CMD_NEW_CHAIN : ret =ip6tc_create_chain (chain, handle);
iptables.c +23 -6
@@ -76,9 +76,10 @@#define CMD_SET_POLICY 0x0400U#define CMD_RENAME_CHAIN 0x0800U#define CMD_LIST_RULES 0x1000U -#define NUMBER_OF_CMD 14 +#define CMD_ZERO_NUM 0x2000U +#define NUMBER_OF_CMD 15static const char cmdflags[] = {'I' ,'D' ,'D' ,'R' ,'A' ,'L' ,'F' ,'Z' , -'N' ,'X' ,'P' ,'E' ,'S' }; +'Z' ,'N' ,'X' ,'P' ,'E' ,'S' };#define OPTION_OFFSET 256
@@ -165,6 +166,7 @@ static char commands_v_options[NUMBER_OF_CMD][NUMBER_OF_OPT] = /*LIST*/ {' ','x','x','x','x',' ',' ','x','x','x',' ','x'}, /*FLUSH*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, /*ZERO*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, +/*ZERO_NUM*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, /*NEW_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, /*DEL_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, /*SET_POLICY*/{'x','x','x','x','x',' ','x','x','x','x','x',' '},
@@ -311,7 +313,8 @@ exit_printhelp(struct iptables_rule_match *matches)" --list-rules -S [chain [rulenum]]\n" " Print the rules in a chain or all chains\n" " --flush -F [chain] Delete all rules in chain or all chains\n" -" --zero -Z [chain] Zero counters in chain or all chains\n" +" --zero -Z [chain [rulenum]]\n" +" Zero counters in chain or all chains\n" " --new -N chain Create a new user-defined chain\n" " --delete-chain\n" " -X [chain] Delete a user-defined chain\n"
@@ -1521,7 +1524,7 @@ int do_command(int argc, char *argv[], char **table, iptc_handle_t *handle)break ;case 'L' : -add_command (&command,CMD_LIST ,CMD_ZERO , +add_command (&command,CMD_LIST ,CMD_ZERO |CMD_ZERO_NUM , invert);if (optarg) chain = optarg; else if (optind < argc && argv[optind][0] != '-'
@@ -1533,8 +1536,8 @@ int do_command(int argc, char *argv[], char **table, iptc_handle_t *handle)break ;case 'S' : -add_command (&command,CMD_LIST_RULES ,CMD_ZERO , - invert); +add_command (&command,CMD_LIST_RULES , +CMD_ZERO |CMD_ZERO_NUM , invert);if (optarg) chain = optarg;else if (optind < argc && argv[optind][0 ] !='-' && argv[optind][0 ] !='!' )
@@ -1560,6 +1563,11 @@ int do_command(int argc, char *argv[], char **table, iptc_handle_t *handle)else if (optind < argc && argv[optind][0 ] !='-' && argv[optind][0 ] !='!' ) chain = argv[optind++]; +if (optind < argc && argv[optind][0 ] !='-' + && argv[optind][0 ] !='!' ) { + rulenum =parse_rulenumber (argv[optind++]); + command =CMD_ZERO_NUM ; + }break ;case 'N' :
@@ -2087,8 +2095,12 @@ int do_command(int argc, char *argv[], char **table, iptc_handle_t *handle)case CMD_ZERO : ret =zero_entries (chain, options&OPT_VERBOSE , handle);break ; +case CMD_ZERO_NUM : + ret =iptc_zero_counter (chain, rulenum, handle); +break ;case CMD_LIST :case CMD_LIST |CMD_ZERO : +case CMD_LIST |CMD_ZERO_NUM : ret = list_entries(chain, rulenum, options&OPT_VERBOSE,
@@ -2099,9 +2111,12 @@ int do_command(int argc, char *argv[], char **table, iptc_handle_t *handle)if (ret && (command &CMD_ZERO )) ret =zero_entries (chain, options&OPT_VERBOSE , handle); +if (ret && (command &CMD_ZERO_NUM )) + ret =iptc_zero_counter (chain, rulenum, handle);break ;case CMD_LIST_RULES :case CMD_LIST_RULES |CMD_ZERO : +case CMD_LIST_RULES |CMD_ZERO_NUM : ret = list_rules(chain, rulenum, options&OPT_VERBOSE,
@@ -2109,6 +2124,8 @@ int do_command(int argc, char *argv[], char **table, iptc_handle_t *handle)if (ret && (command &CMD_ZERO )) ret =zero_entries (chain, options&OPT_VERBOSE , handle); +if (ret && (command &CMD_ZERO_NUM )) + ret =iptc_zero_counter (chain, rulenum, handle);break ;case CMD_NEW_CHAIN : ret =iptc_create_chain (chain, handle);
build-vm-jenner:/jenner/pkgs/iptables#
Mohit Mehta
Vyatta Inc.
Quoted 1 line · Mohit Mehta
iptc_zero_counter/ip6tc_zero_counter are functions available in libiptc to zero counters for a rule in a given chain. However, this is not exposed in iptables/ip6tables. The patch below exposes the underlying function to the user to zero out packet and byte counters for a specific rule.
Exposing this seems useful, the patch doesn't apply to the current git version though:
8 out of 9 hunks FAILED -- saving rejects to file ip6tables.c.rej 8 out of 9 hunks FAILED -- saving rejects to file iptables.c.rej
Please rediff your patch against the current tree.
Quoted 1 line
Please rediff your patch against the current tree.
diff for iptables.c -
iptables.c 2009-02-18 11:38:30.000000000 -0800 renamed from iptables.c.orig 2009-02-18 11:26:31.000000000 -0800 +23 -6
@@ -76,9 +76,10 @@ #define CMD_SET_POLICY 0x0400U #define CMD_RENAME_CHAIN 0x0800U #define CMD_LIST_RULES 0x1000U -#define NUMBER_OF_CMD 14 +#define CMD_ZERO_NUM 0x2000U +#define NUMBER_OF_CMD 15 static const char cmdflags[] = { 'I', 'D', 'D', 'R', 'A', 'L', 'F', 'Z', - 'N', 'X', 'P', 'E', 'S' }; + 'Z', 'N', 'X', 'P', 'E', 'S' }; #define OPTION_OFFSET 256
@@ -165,6 +166,7 @@ static char commands_v_options[NUMBER_OF /*LIST*/ {' ','x','x','x','x',' ',' ','x','x','x',' ','x'}, /*FLUSH*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, /*ZERO*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, +/*ZERO_NUM*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, /*NEW_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, /*DEL_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, /*SET_POLICY*/{'x','x','x','x','x',' ','x','x','x','x','x',' '},
@@ -311,7 +313,8 @@ exit_printhelp(struct iptables_rule_matc " --list-rules -S [chain [rulenum]]\n" " Print the rules in a chain or all chains\n" " --flush -F [chain] Delete all rules in chain or all chains\n" -" --zero -Z [chain] Zero counters in chain or all chains\n" +" --zero -Z [chain[rulenum]]\n" +" Zero counters in chain or all chains\n" " --new -N chain Create a new user-defined chain\n" " --delete-chain\n" " -X [chain] Delete a user-defined chain\n"
@@ -1521,7 +1524,7 @@ int do_command(int argc, char *argv[], c break; case 'L': - add_command(&command, CMD_LIST, CMD_ZERO, + add_command(&command, CMD_LIST, CMD_ZERO|CMD_ZERO_NUM, invert); if (optarg) chain = optarg; else if (optind < argc && argv[optind][0] != '-'
@@ -1533,8 +1536,8 @@ int do_command(int argc, char *argv[], c break; case 'S': - add_command(&command, CMD_LIST_RULES, CMD_ZERO, - invert); + add_command(&command, CMD_LIST_RULES, + CMD_ZERO|CMD_ZERO_NUM, invert); if (optarg) chain = optarg; else if (optind < argc && argv[optind][0] != '-' && argv[optind][0] != '!')
@@ -1560,6 +1563,11 @@ int do_command(int argc, char *argv[], c else if (optind < argc && argv[optind][0] != '-' && argv[optind][0] != '!') chain = argv[optind++]; + if (optind < argc && argv[optind][0] != '-' + && argv[optind][0] != '!') { + rulenum = parse_rulenumber(argv[optind++]); + command = CMD_ZERO_NUM; + } break; case 'N':
@@ -2094,8 +2102,12 @@ int do_command(int argc, char *argv[], c case CMD_ZERO: ret = zero_entries(chain, options&OPT_VERBOSE, handle); break; + case CMD_ZERO_NUM: + ret = iptc_zero_counter(chain, rulenum, handle); + break; case CMD_LIST: case CMD_LIST|CMD_ZERO: + case CMD_LIST|CMD_ZERO_NUM: ret = list_entries(chain, rulenum, options&OPT_VERBOSE,
@@ -2106,9 +2118,12 @@ int do_command(int argc, char *argv[], c if (ret && (command & CMD_ZERO)) ret = zero_entries(chain, options&OPT_VERBOSE, handle); + if (ret && (command & CMD_ZERO_NUM)) + ret = iptc_zero_counter(chain, rulenum, handle); break; case CMD_LIST_RULES: case CMD_LIST_RULES|CMD_ZERO: + case CMD_LIST_RULES|CMD_ZERO_NUM: ret = list_rules(chain, rulenum, options&OPT_VERBOSE,
@@ -2116,6 +2131,8 @@ int do_command(int argc, char *argv[], c if (ret && (command & CMD_ZERO)) ret = zero_entries(chain, options&OPT_VERBOSE, handle); + if (ret && (command & CMD_ZERO_NUM)) + ret = iptc_zero_counter(chain, rulenum, handle); break; case CMD_NEW_CHAIN: ret = iptc_create_chain(chain, handle);
diff for ip6tables.c -
ip6tables.c 2009-02-18 11:50:51.000000000 -0800 renamed from ip6tables.c.orig 2009-02-18 11:44:04.000000000 -0800 +23 -6
@@ -79,9 +79,10 @@ #define CMD_SET_POLICY 0x0400U #define CMD_RENAME_CHAIN 0x0800U #define CMD_LIST_RULES 0x1000U -#define NUMBER_OF_CMD 14 +#define CMD_ZERO_NUM 0x2000U +#define NUMBER_OF_CMD 15 static const char cmdflags[] = { 'I', 'D', 'D', 'R', 'A', 'L', 'F', 'Z', - 'N', 'X', 'P', 'E', 'S' }; + 'Z', 'N', 'X', 'P', 'E', 'S' }; #define OPTION_OFFSET 256
@@ -166,6 +167,7 @@ static char commands_v_options[NUMBER_OF /*LIST*/ {' ','x','x','x','x',' ',' ','x','x',' ','x'}, /*FLUSH*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, /*ZERO*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, +/*ZERO_NUM*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, /*NEW_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, /*DEL_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, /*SET_POLICY*/{'x','x','x','x','x',' ','x','x','x','x',' '},
@@ -309,7 +311,8 @@ exit_printhelp(struct ip6tables_rule_mat " --list-rules -S [chain [rulenum]]\n" " Print the rules in a chain or all chains\n" " --flush -F [chain] Delete all rules in chain or all chains\n" -" --zero -Z [chain] Zero counters in chain or all chains\n" +" --zero -Z [chain[rulenum]]\n" +" Zero counters in chain or all chains\n" " --new -N chain Create a new user-defined chain\n" " --delete-chain\n" " -X [chain] Delete a user-defined chain\n"
@@ -1508,7 +1511,7 @@ int do_command6(int argc, char *argv[], break; case 'L': - add_command(&command, CMD_LIST, CMD_ZERO, + add_command(&command, CMD_LIST, CMD_ZERO|CMD_ZERO_NUM, invert); if (optarg) chain = optarg; else if (optind < argc && argv[optind][0] != '-'
@@ -1520,8 +1523,8 @@ int do_command6(int argc, char *argv[], break; case 'S': - add_command(&command, CMD_LIST_RULES, CMD_ZERO, - invert); + add_command(&command, CMD_LIST_RULES, + CMD_ZERO|CMD_ZERO_NUM, invert); if (optarg) chain = optarg; else if (optind < argc && argv[optind][0] != '-' && argv[optind][0] != '!')
@@ -1547,6 +1550,11 @@ int do_command6(int argc, char *argv[], else if (optind < argc && argv[optind][0] != '-' && argv[optind][0] != '!') chain = argv[optind++]; + if (optind < argc && argv[optind][0] != '-' + && argv[optind][0] != '!') { + rulenum = parse_rulenumber(argv[optind++]); + command = CMD_ZERO_NUM; + } break; case 'N':
@@ -2062,8 +2070,12 @@ int do_command6(int argc, char *argv[], case CMD_ZERO: ret = zero_entries(chain, options&OPT_VERBOSE, handle); break; + case CMD_ZERO_NUM: + ret = ip6tc_zero_counter(chain, rulenum, handle); + break; case CMD_LIST: case CMD_LIST|CMD_ZERO: + case CMD_LIST|CMD_ZERO_NUM: ret = list_entries(chain, rulenum, options&OPT_VERBOSE,
@@ -2074,9 +2086,12 @@ int do_command6(int argc, char *argv[], if (ret && (command & CMD_ZERO)) ret = zero_entries(chain, options&OPT_VERBOSE, handle); + if (ret && (command & CMD_ZERO_NUM)) + ret = ip6tc_zero_counter(chain, rulenum, handle); break; case CMD_LIST_RULES: case CMD_LIST_RULES|CMD_ZERO: + case CMD_LIST_RULES|CMD_ZERO_NUM: ret = list_rules(chain, rulenum, options&OPT_VERBOSE,
@@ -2084,6 +2099,8 @@ int do_command6(int argc, char *argv[], if (ret && (command & CMD_ZERO)) ret = zero_entries(chain, options&OPT_VERBOSE, handle); + if (ret && (command & CMD_ZERO_NUM)) + ret = ip6tc_zero_counter(chain, rulenum, handle); break; case CMD_NEW_CHAIN: ret = ip6tc_create_chain(chain, handle);
----- Original Message -----
From: "Patrick McHardy" <[email protected]>
To: "Mohit Mehta" <[email protected]>
Cc: [email protected]
Sent: Wednesday, February 18, 2009 10:40:35 AM (GMT-0800) Auto-Detected
Subject: Re: [PATCH] iptables: expose option to zero packet and byte counters for a specific rule using iptables/ip6tables
Quoted 1 line · Mohit Mehta
iptc_zero_counter/ip6tc_zero_counter are functions available in libiptc to zero counters for a rule in a given chain. However, this is not exposed in iptables/ip6tables. The patch below exposes the underlying function to the user to zero out packet and byte counters for a specific rule.
Exposing this seems useful, the patch doesn't apply to the current git version though:
8 out of 9 hunks FAILED -- saving rejects to file ip6tables.c.rej 8 out of 9 hunks FAILED -- saving rejects to file iptables.c.rej
Please rediff your patch against the current tree.
Quoted 3 lines · Mohit Mehta
Quoted 1 line
Please rediff your patch against the current tree.
diff for
iptables.c-
If you have trouble generating patches quickly, I can suggest the use of the following tools:
- quilt
(quilt new mywork.diff; quilt edit iptables.c; quilt ref;
grab patch from patches/ directory)
- git
(git clone; edit files; git add; git commit; git-export-patch)
- or git with stgit
(stg new mywork.diff; edit; stg ref; stg export...)
Quoted 32 lines
iptables.c 2009-02-18 11:38:30.000000000 -0800 renamed from iptables.c.orig 2009-02-18 11:26:31.000000000 -0800 +2
-0@@ -2116,6 +2131,8 @@ int do_command(int argc, char *argv[], c if (ret && (command & CMD_ZERO)) ret = zero_entries(chain, options&OPT_VERBOSE, handle); + if (ret && (command & CMD_ZERO_NUM)) + ret = iptc_zero_counter(chain, rulenum, handle); break; case CMD_NEW_CHAIN: ret = iptc_create_chain(chain, handle);diff for
ip6tables.c-ip6tables.c 2009-02-18 11:50:51.000000000 -0800 renamed from ip6tables.c.orig 2009-02-18 11:44:04.000000000 -0800 +3
-2@@ -79,9 +79,10 @@ #define CMD_SET_POLICY 0x0400U #define CMD_RENAME_CHAIN 0x0800U #define CMD_LIST_RULES 0x1000U -#define NUMBER_OF_CMD 14 +#define CMD_ZERO_NUM 0x2000U +#define NUMBER_OF_CMD 15 static const char cmdflags[] = { 'I', 'D', 'D', 'R', 'A', 'L', 'F', 'Z', - 'N', 'X', 'P', 'E', 'S' }; + 'Z', 'N', 'X', 'P', 'E', 'S' }; #define OPTION_OFFSET 256
Quoted 11 lines
If you have trouble generating patches quickly, I can suggest the use of the following tools:
- quilt
(quilt new mywork.diff; quilt editiptables.c; quilt ref;
grab patch from patches/ directory)- git
(git clone; edit files; git add; git commit; git-export-patch)
- or git with stgit
(stg new mywork.diff; edit; stg ref; stg export...)
Thanks for these suggestions.
It should be noted that I did these changes to the latest source that I grabbed from debian sid. May be I should have just git cloned it from iptables repository. let me knw if these aren't any good and I'll patch em against the most current version of iptables.
----- Original Message -----
From: "Jan Engelhardt" <[email protected]>
To: "Mohit Mehta" <[email protected]>
Cc: "Patrick McHardy" <[email protected]>, [email protected]
Sent: Wednesday, February 18, 2009 12:22:05 PM (GMT-0800) Auto-Detected
Subject: Re: [PATCH] iptables: expose option to zero packet and byte counters for a specific rule using iptables/ip6tables
Quoted 3 lines · Mohit Mehta
Quoted 1 line
Please rediff your patch against the current tree.
diff for
iptables.c-
If you have trouble generating patches quickly, I can suggest the use of the following tools:
- quilt
(quilt new mywork.diff; quilt edit iptables.c; quilt ref;
grab patch from patches/ directory)
- git
(git clone; edit files; git add; git commit; git-export-patch)
- or git with stgit
(stg new mywork.diff; edit; stg ref; stg export...)
Quoted 32 lines
iptables.c 2009-02-18 11:38:30.000000000 -0800 renamed from iptables.c.orig 2009-02-18 11:26:31.000000000 -0800 +2
-0@@ -2116,6 +2131,8 @@ int do_command(int argc, char *argv[], c if (ret && (command & CMD_ZERO)) ret = zero_entries(chain, options&OPT_VERBOSE, handle); + if (ret && (command & CMD_ZERO_NUM)) + ret = iptc_zero_counter(chain, rulenum, handle); break; case CMD_NEW_CHAIN: ret = iptc_create_chain(chain, handle);diff for
ip6tables.c-ip6tables.c 2009-02-18 11:50:51.000000000 -0800 renamed from ip6tables.c.orig 2009-02-18 11:44:04.000000000 -0800 +3
-2@@ -79,9 +79,10 @@ #define CMD_SET_POLICY 0x0400U #define CMD_RENAME_CHAIN 0x0800U #define CMD_LIST_RULES 0x1000U -#define NUMBER_OF_CMD 14 +#define CMD_ZERO_NUM 0x2000U +#define NUMBER_OF_CMD 15 static const char cmdflags[] = { 'I', 'D', 'D', 'R', 'A', 'L', 'F', 'Z', - 'N', 'X', 'P', 'E', 'S' }; + 'Z', 'N', 'X', 'P', 'E', 'S' }; #define OPTION_OFFSET 256
iptables.c 2009-02-18 11:38:30.000000000 -0800
Quoted 6 lines · Mohit Mehta
Quoted 1 line
Please rediff your patch against the current tree.
diff for
iptables.c-iptables.c 2009-02-18 11:38:30.000000000 -0800 renamed from iptables.c.orig 2009-02-18 11:26:31.000000000 -0800 +0
-0
That patch is whitespace-mangled and also doesn't apply.
Hopefully, this works -
ip6tables.c +23 -6
@@ -80,9 +80,10 @@#define CMD_SET_POLICY 0x0400U#define CMD_RENAME_CHAIN 0x0800U#define CMD_LIST_RULES 0x1000U -#define NUMBER_OF_CMD 14 +#define CMD_ZERO_NUM 0x2000U +#define NUMBER_OF_CMD 15static const char cmdflags[] = {'I' ,'D' ,'D' ,'R' ,'A' ,'L' ,'F' ,'Z' , -'N' ,'X' ,'P' ,'E' ,'S' }; +'Z' ,'N' ,'X' ,'P' ,'E' ,'S' };#define OPT_NONE 0x00000U#define OPT_NUMERIC 0x00001U
@@ -172,6 +173,7 @@ static char commands_v_options[NUMBER_OF_CMD][NUMBER_OF_OPT] = /*LIST*/ {' ','x','x','x','x',' ',' ','x','x',' ','x'}, /*FLUSH*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, /*ZERO*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, +/*ZERO_NUM*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, /*NEW_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, /*DEL_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, /*SET_POLICY*/{'x','x','x','x','x',' ','x','x','x','x',' '},
@@ -268,7 +270,8 @@ exit_printhelp(struct xtables_rule_match *matches)" --list-rules -S [chain [rulenum]]\n" " Print the rules in a chain or all chains\n" " --flush -F [chain] Delete all rules in chain or all chains\n" -" --zero -Z [chain] Zero counters in chain or all chains\n" +" --zero -Z [chain[rulenum]]\n" +" Zero counters in chain or all chains\n" " --new -N chain Create a new user-defined chain\n" " --delete-chain\n" " -X [chain] Delete a user-defined chain\n"
@@ -1377,7 +1380,7 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handbreak ;case 'L' : -add_command (&command,CMD_LIST ,CMD_ZERO , +add_command (&command,CMD_LIST ,CMD_ZERO |CMD_ZERO_NUM , invert);if (optarg) chain = optarg; else if (optind < argc && argv[optind][0] != '-'
@@ -1389,8 +1392,8 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handbreak ;case 'S' : -add_command (&command,CMD_LIST_RULES ,CMD_ZERO , - invert); +add_command (&command,CMD_LIST_RULES , +CMD_ZERO |CMD_ZERO_NUM , invert);if (optarg) chain = optarg;else if (optind < argc && argv[optind][0 ] !='-' && argv[optind][0 ] !='!' )
@@ -1416,6 +1419,11 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handelse if (optind < argc && argv[optind][0 ] !='-' && argv[optind][0 ] !='!' ) chain = argv[optind++]; +if (optind < argc && argv[optind][0 ] !='-' + && argv[optind][0 ] !='!' ) { + rulenum =parse_rulenumber (argv[optind++]); + command =CMD_ZERO_NUM ; + }break ;case 'N' :
@@ -1950,8 +1958,12 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handcase CMD_ZERO : ret =zero_entries (chain, options&OPT_VERBOSE , *handle);break ; +case CMD_ZERO_NUM : + ret =ip6tc_zero_counter (chain, rulenum, handle); +break ;case CMD_LIST :case CMD_LIST |CMD_ZERO : +case CMD_LIST |CMD_ZERO_NUM : ret = list_entries(chain, rulenum, options&OPT_VERBOSE,
@@ -1962,9 +1974,12 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handif (ret && (command &CMD_ZERO )) ret =zero_entries (chain, options&OPT_VERBOSE , *handle); +if (ret && (command &CMD_ZERO_NUM )) + ret =ip6tc_zero_counter (chain, rulenum, handle);break ;case CMD_LIST_RULES :case CMD_LIST_RULES |CMD_ZERO : +case CMD_LIST_RULES |CMD_ZERO_NUM : ret = list_rules(chain, rulenum, options&OPT_VERBOSE,
@@ -1972,6 +1987,8 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handif (ret && (command &CMD_ZERO )) ret =zero_entries (chain, options&OPT_VERBOSE , *handle); +if (ret && (command &CMD_ZERO_NUM )) + ret =ip6tc_zero_counter (chain, rulenum, handle);break ;case CMD_NEW_CHAIN : ret =ip6tc_create_chain (chain, *handle);
iptables.c +23 -6
@@ -77,9 +77,10 @@#define CMD_SET_POLICY 0x0400U#define CMD_RENAME_CHAIN 0x0800U#define CMD_LIST_RULES 0x1000U -#define NUMBER_OF_CMD 14 +#define CMD_ZERO_NUM 0x2000U +#define NUMBER_OF_CMD 15static const char cmdflags[] = {'I' ,'D' ,'D' ,'R' ,'A' ,'L' ,'F' ,'Z' , -'N' ,'X' ,'P' ,'E' ,'S' }; +'Z' ,'N' ,'X' ,'P' ,'E' ,'S' };#define OPT_NONE 0x00000U#define OPT_NUMERIC 0x00001U
@@ -173,6 +174,7 @@ static char commands_v_options[NUMBER_OF_CMD][NUMBER_OF_OPT] = /*LIST*/ {' ','x','x','x','x',' ',' ','x','x','x',' ','x'}, /*FLUSH*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, /*ZERO*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, +/*ZERO_NUM*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, /*NEW_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, /*DEL_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, /*SET_POLICY*/{'x','x','x','x','x',' ','x','x','x','x','x',' '},
@@ -282,7 +284,8 @@ exit_printhelp(struct xtables_rule_match *matches)" --list-rules -S [chain [rulenum]]\n" " Print the rules in a chain or all chains\n" " --flush -F [chain] Delete all rules in chain or all chains\n" -" --zero -Z [chain] Zero counters in chain or all chains\n" +" --zero -Z [chain[rulenum]]\n" +" Zero counters in chain or all chains\n" " --new -N chain Create a new user-defined chain\n" " --delete-chain\n" " -X [chain] Delete a user-defined chain\n"
@@ -1400,7 +1403,7 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handlebreak ;case 'L' : -add_command (&command,CMD_LIST ,CMD_ZERO , +add_command (&command,CMD_LIST ,CMD_ZERO |CMD_ZERO_NUM , invert);if (optarg) chain = optarg; else if (optind < argc && argv[optind][0] != '-'
@@ -1412,8 +1415,8 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handlebreak ;case 'S' : -add_command (&command,CMD_LIST_RULES ,CMD_ZERO , - invert); +add_command (&command,CMD_LIST_RULES , +CMD_ZERO |CMD_ZERO_NUM , invert);if (optarg) chain = optarg;else if (optind < argc && argv[optind][0 ] !='-' && argv[optind][0 ] !='!' )
@@ -1439,6 +1442,11 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handleelse if (optind < argc && argv[optind][0 ] !='-' && argv[optind][0 ] !='!' ) chain = argv[optind++]; +if (optind < argc && argv[optind][0 ] !='-' + && argv[optind][0 ] !='!' ) { + rulenum =parse_rulenumber (argv[optind++]); + command =CMD_ZERO_NUM ; + }break ;case 'N' :
@@ -1992,8 +2000,12 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handlecase CMD_ZERO : ret =zero_entries (chain, options&OPT_VERBOSE , *handle);break ; +case CMD_ZERO_NUM : + ret =iptc_zero_counter (chain, rulenum, handle); +break ;case CMD_LIST :case CMD_LIST |CMD_ZERO : +case CMD_LIST |CMD_ZERO_NUM : ret = list_entries(chain, rulenum, options&OPT_VERBOSE,
@@ -2004,9 +2016,12 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handleif (ret && (command &CMD_ZERO )) ret =zero_entries (chain, options&OPT_VERBOSE , *handle); +if (ret && (command &CMD_ZERO_NUM )) + ret =iptc_zero_counter (chain, rulenum, handle);break ;case CMD_LIST_RULES :case CMD_LIST_RULES |CMD_ZERO : +case CMD_LIST_RULES |CMD_ZERO_NUM : ret = list_rules(chain, rulenum, options&OPT_VERBOSE,
@@ -2014,6 +2029,8 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handleif (ret && (command &CMD_ZERO )) ret =zero_entries (chain, options&OPT_VERBOSE , *handle); +if (ret && (command &CMD_ZERO_NUM )) + ret =iptc_zero_counter (chain, rulenum, handle);break ;case CMD_NEW_CHAIN : ret =iptc_create_chain (chain, *handle);
----- Original Message -----
From: "Patrick McHardy" <[email protected]>
To: "Mohit Mehta" <[email protected]>
Cc: [email protected]
Sent: Thursday, February 19, 2009 2:21:31 AM (GMT-0800) Auto-Detected
Subject: Re: [PATCH] iptables: expose option to zero packet and byte counters for a specific rule using iptables/ip6tables
iptables.c 2009-02-18 11:38:30.000000000 -0800
Quoted 6 lines · Mohit Mehta
Quoted 1 line
Please rediff your patch against the current tree.
diff for
iptables.c-iptables.c 2009-02-18 11:38:30.000000000 -0800 renamed from iptables.c.orig 2009-02-18 11:26:31.000000000 -0800 +0
-0
That patch is whitespace-mangled and also doesn't apply.
Quoted 1 line · Mohit Mehta
Hopefully, this works -
It does not. Try sending to yourself first and applying it yourself. And I'd suggest not to use a web based client:
X-Mailer: Zimbra 5.0.11_GA_2696.RHEL4 (ZimbraWebClient - FF3.0 (Win)/5.0.11_GA_2696.RHEL4)
I was able to cleanly apply the attached modified patches to the latest iptables code. Also, below is the code in text if attachment doesn't reach.
build-vm:/# cat iptables.c.patch
Quoted 1 line
From
4dbfcfeb9fc65df7fac1f16230871c02a85b4ea1Mon Sep 17 00:00:00 2001
From: root <root@build-vm.(none)>
Date: Tue, 7 Jul 2009 14:03:50 -0700
Subject: [PATCH] expose option to zero packet and byte counters for a specific rule using iptables
--- iptables.c | 29 +++++++++++++++++++++++------ 1 files changed, 23 insertions(+), 6 deletions(-)
iptables.c +23 -6
@@ -78,9 +78,10 @@#define CMD_SET_POLICY 0x0400U#define CMD_RENAME_CHAIN 0x0800U#define CMD_LIST_RULES 0x1000U -#define NUMBER_OF_CMD 14 +#define CMD_ZERO_NUM 0x2000U +#define NUMBER_OF_CMD 15static const char cmdflags[] = {'I' ,'D' ,'D' ,'R' ,'A' ,'L' ,'F' ,'Z' , -'N' ,'X' ,'P' ,'E' ,'S' }; +'Z' ,'N' ,'X' ,'P' ,'E' ,'S' };#define OPT_NONE 0x00000U#define OPT_NUMERIC 0x00001U
@@ -172,6 +173,7 @@ static char commands_v_options[NUMBER_OF_CMD][NUMBER_OF_OPT] = /*LIST*/ {' ','x','x','x','x',' ',' ','x','x','x',' ','x'}, /*FLUSH*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, /*ZERO*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, +/*ZERO_NUM*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, /*NEW_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, /*DEL_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, /*SET_POLICY*/{'x','x','x','x','x',' ','x','x','x','x','x',' '},
@@ -280,7 +282,8 @@ exit_printhelp(struct xtables_rule_match *matches)" --list-rules -S [chain [rulenum]]\n" " Print the rules in a chain or all chains\n" " --flush -F [chain] Delete all rules in chain or all chains\n" -" --zero -Z [chain] Zero counters in chain or all chains\n" +" --zero -Z [chain [rulenum]]\n" +" Zero counters in chain or all chains\n" " --new -N chain Create a new user-defined chain\n" " --delete-chain\n" " -X [chain] Delete a user-defined chain\n"
@@ -1399,7 +1402,7 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handlebreak ;case 'L' : -add_command (&command,CMD_LIST ,CMD_ZERO , +add_command (&command,CMD_LIST ,CMD_ZERO |CMD_ZERO_NUM , invert);if (optarg) chain = optarg; else if (optind < argc && argv[optind][0] != '-'
@@ -1411,8 +1414,8 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handlebreak ;case 'S' : -add_command (&command,CMD_LIST_RULES ,CMD_ZERO , - invert); +add_command (&command,CMD_LIST_RULES , +CMD_ZERO |CMD_ZERO_NUM , invert);if (optarg) chain = optarg;else if (optind < argc && argv[optind][0 ] !='-' && argv[optind][0 ] !='!' )
@@ -1438,6 +1441,11 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handleelse if (optind < argc && argv[optind][0 ] !='-' && argv[optind][0 ] !='!' ) chain = argv[optind++]; +if (optind < argc && argv[optind][0 ] !='-' + && argv[optind][0 ] !='!' ) { + rulenum =parse_rulenumber (argv[optind++]); + command =CMD_ZERO_NUM ; + }break ;case 'N' :
@@ -1994,8 +2002,12 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handlecase CMD_ZERO : ret =zero_entries (chain, options&OPT_VERBOSE , *handle);break ; +case CMD_ZERO_NUM : + ret =iptc_zero_counter (chain, rulenum, *handle); +break ;case CMD_LIST :case CMD_LIST |CMD_ZERO : +case CMD_LIST |CMD_ZERO_NUM : ret = list_entries(chain, rulenum, options&OPT_VERBOSE,
@@ -2006,9 +2018,12 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handleif (ret && (command &CMD_ZERO )) ret =zero_entries (chain, options&OPT_VERBOSE , *handle); +if (ret && (command &CMD_ZERO_NUM )) + ret =iptc_zero_counter (chain, rulenum, *handle);break ;case CMD_LIST_RULES :case CMD_LIST_RULES |CMD_ZERO : +case CMD_LIST_RULES |CMD_ZERO_NUM : ret = list_rules(chain, rulenum, options&OPT_VERBOSE,
@@ -2016,6 +2031,8 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handleif (ret && (command &CMD_ZERO )) ret =zero_entries (chain, options&OPT_VERBOSE , *handle); +if (ret && (command &CMD_ZERO_NUM )) + ret =iptc_zero_counter (chain, rulenum, *handle);break ;case CMD_NEW_CHAIN : ret =iptc_create_chain (chain, *handle);
--
1.5.6.5
build-vm:/# cat ip6tables.c.patch
Quoted 1 line
From
8f98a64ad2a2b312a3b9c94a0f79145bf04c6391Mon Sep 17 00:00:00 2001
From: root <root@build-vm.(none)>
Date: Tue, 7 Jul 2009 14:17:40 -0700
Subject: [PATCH] expose option to zero packet and byte counters for a specific rule using ip6tables
--- ip6tables.c | 29 +++++++++++++++++++++++------ 1 files changed, 23 insertions(+), 6 deletions(-)
ip6tables.c +23 -6
@@ -81,9 +81,10 @@#define CMD_SET_POLICY 0x0400U#define CMD_RENAME_CHAIN 0x0800U#define CMD_LIST_RULES 0x1000U -#define NUMBER_OF_CMD 14 +#define CMD_ZERO_NUM 0x2000U +#define NUMBER_OF_CMD 15static const char cmdflags[] = {'I' ,'D' ,'D' ,'R' ,'A' ,'L' ,'F' ,'Z' , -'N' ,'X' ,'P' ,'E' ,'S' }; +'Z' ,'N' ,'X' ,'P' ,'E' ,'S' };#define OPT_NONE 0x00000U#define OPT_NUMERIC 0x00001U
@@ -172,6 +173,7 @@ static char commands_v_options[NUMBER_OF_CMD][NUMBER_OF_OPT] = /*LIST*/ {' ','x','x','x','x',' ',' ','x','x',' ','x'}, /*FLUSH*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, /*ZERO*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, +/*ZERO_NUM*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, /*NEW_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, /*DEL_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, /*SET_POLICY*/{'x','x','x','x','x',' ','x','x','x','x',' '},
@@ -267,7 +269,8 @@ exit_printhelp(struct xtables_rule_match *matches)" --list-rules -S [chain [rulenum]]\n" " Print the rules in a chain or all chains\n" " --flush -F [chain] Delete all rules in chain or all chains\n" -" --zero -Z [chain] Zero counters in chain or all chains\n" +" --zero -Z [chain [rulenum]]\n" +" Zero counters in chain or all chains\n" " --new -N chain Create a new user-defined chain\n" " --delete-chain\n" " -X [chain] Delete a user-defined chain\n"
@@ -1376,7 +1379,7 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handbreak ;case 'L' : -add_command (&command,CMD_LIST ,CMD_ZERO , +add_command (&command,CMD_LIST ,CMD_ZERO |CMD_ZERO_NUM , invert);if (optarg) chain = optarg; else if (optind < argc && argv[optind][0] != '-'
@@ -1388,8 +1391,8 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handbreak ;case 'S' : -add_command (&command,CMD_LIST_RULES ,CMD_ZERO , - invert); +add_command (&command,CMD_LIST_RULES , +CMD_ZERO |CMD_ZERO_NUM , invert);if (optarg) chain = optarg;else if (optind < argc && argv[optind][0 ] !='-' && argv[optind][0 ] !='!' )
@@ -1415,6 +1418,11 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handelse if (optind < argc && argv[optind][0 ] !='-' && argv[optind][0 ] !='!' ) chain = argv[optind++]; +if (optind < argc && argv[optind][0 ] !='-' + && argv[optind][0 ] !='!' ) { + rulenum =parse_rulenumber (argv[optind++]); + command =CMD_ZERO_NUM ; + }break ;case 'N' :
@@ -1953,8 +1961,12 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handcase CMD_ZERO : ret =zero_entries (chain, options&OPT_VERBOSE , *handle);break ; +case CMD_ZERO_NUM : + ret =ip6tc_zero_counter (chain, rulenum, *handle); +break ;case CMD_LIST :case CMD_LIST |CMD_ZERO : +case CMD_LIST |CMD_ZERO_NUM : ret = list_entries(chain, rulenum, options&OPT_VERBOSE,
@@ -1965,9 +1977,12 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handif (ret && (command &CMD_ZERO )) ret =zero_entries (chain, options&OPT_VERBOSE , *handle); +if (ret && (command &CMD_ZERO_NUM )) + ret =ip6tc_zero_counter (chain, rulenum, *handle);break ;case CMD_LIST_RULES :case CMD_LIST_RULES |CMD_ZERO : +case CMD_LIST_RULES |CMD_ZERO_NUM : ret = list_rules(chain, rulenum, options&OPT_VERBOSE,
@@ -1975,6 +1990,8 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handif (ret && (command &CMD_ZERO )) ret =zero_entries (chain, options&OPT_VERBOSE , *handle); +if (ret && (command &CMD_ZERO_NUM )) + ret =ip6tc_zero_counter (chain, rulenum, *handle);break ;case CMD_NEW_CHAIN : ret =ip6tc_create_chain (chain, *handle);
--
1.5.6.5
Quoted 10 lines · ----- Patrick McHardy
Quoted 1 line · Mohit Mehta
Hopefully, this works -
It does not. Try sending to yourself first and applying it yourself. And I'd suggest not to use a web based client:
X-Mailer: Zimbra 5.0.11_GA_2696.RHEL4 (ZimbraWebClient - FF3.0 (Win)/5.0.11_GA_2696.RHEL4)
From
8f98a64ad2a2b312a3b9c94a0f79145bf04c6391Mon Sep 17 00:00:00 2001
From: root <root@build-vm.(none)>
Date: Tue, 7 Jul 2009 14:17:40 -0700
Subject: [PATCH] expose option to zero packet and byte counters for a specific rule using ip6tables
--- ip6tables.c | 29 +++++++++++++++++++++++------ 1 files changed, 23 insertions(+), 6 deletions(-)
ip6tables.c +23 -6
@@ -81,9 +81,10 @@#define CMD_SET_POLICY 0x0400U#define CMD_RENAME_CHAIN 0x0800U#define CMD_LIST_RULES 0x1000U -#define NUMBER_OF_CMD 14 +#define CMD_ZERO_NUM 0x2000U +#define NUMBER_OF_CMD 15static const char cmdflags[] = {'I' ,'D' ,'D' ,'R' ,'A' ,'L' ,'F' ,'Z' , -'N' ,'X' ,'P' ,'E' ,'S' }; +'Z' ,'N' ,'X' ,'P' ,'E' ,'S' };#define OPT_NONE 0x00000U#define OPT_NUMERIC 0x00001U
@@ -172,6 +173,7 @@ static char commands_v_options[NUMBER_OF_CMD][NUMBER_OF_OPT] = /*LIST*/ {' ','x','x','x','x',' ',' ','x','x',' ','x'}, /*FLUSH*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, /*ZERO*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, +/*ZERO_NUM*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, /*NEW_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, /*DEL_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x'}, /*SET_POLICY*/{'x','x','x','x','x',' ','x','x','x','x',' '},
@@ -267,7 +269,8 @@ exit_printhelp(struct xtables_rule_match *matches)" --list-rules -S [chain [rulenum]]\n" " Print the rules in a chain or all chains\n" " --flush -F [chain] Delete all rules in chain or all chains\n" -" --zero -Z [chain] Zero counters in chain or all chains\n" +" --zero -Z [chain [rulenum]]\n" +" Zero counters in chain or all chains\n" " --new -N chain Create a new user-defined chain\n" " --delete-chain\n" " -X [chain] Delete a user-defined chain\n"
@@ -1376,7 +1379,7 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handbreak ;case 'L' : -add_command (&command,CMD_LIST ,CMD_ZERO , +add_command (&command,CMD_LIST ,CMD_ZERO |CMD_ZERO_NUM , invert);if (optarg) chain = optarg; else if (optind < argc && argv[optind][0] != '-'
@@ -1388,8 +1391,8 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handbreak ;case 'S' : -add_command (&command,CMD_LIST_RULES ,CMD_ZERO , - invert); +add_command (&command,CMD_LIST_RULES , +CMD_ZERO |CMD_ZERO_NUM , invert);if (optarg) chain = optarg;else if (optind < argc && argv[optind][0 ] !='-' && argv[optind][0 ] !='!' )
@@ -1415,6 +1418,11 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handelse if (optind < argc && argv[optind][0 ] !='-' && argv[optind][0 ] !='!' ) chain = argv[optind++]; +if (optind < argc && argv[optind][0 ] !='-' + && argv[optind][0 ] !='!' ) { + rulenum =parse_rulenumber (argv[optind++]); + command =CMD_ZERO_NUM ; + }break ;case 'N' :
@@ -1953,8 +1961,12 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handcase CMD_ZERO : ret =zero_entries (chain, options&OPT_VERBOSE , *handle);break ; +case CMD_ZERO_NUM : + ret =ip6tc_zero_counter (chain, rulenum, *handle); +break ;case CMD_LIST :case CMD_LIST |CMD_ZERO : +case CMD_LIST |CMD_ZERO_NUM : ret = list_entries(chain, rulenum, options&OPT_VERBOSE,
@@ -1965,9 +1977,12 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handif (ret && (command &CMD_ZERO )) ret =zero_entries (chain, options&OPT_VERBOSE , *handle); +if (ret && (command &CMD_ZERO_NUM )) + ret =ip6tc_zero_counter (chain, rulenum, *handle);break ;case CMD_LIST_RULES :case CMD_LIST_RULES |CMD_ZERO : +case CMD_LIST_RULES |CMD_ZERO_NUM : ret = list_rules(chain, rulenum, options&OPT_VERBOSE,
@@ -1975,6 +1990,8 @@ int do_command6(int argc, char *argv[], char **table, struct ip6tc_handle **handif (ret && (command &CMD_ZERO )) ret =zero_entries (chain, options&OPT_VERBOSE , *handle); +if (ret && (command &CMD_ZERO_NUM )) + ret =ip6tc_zero_counter (chain, rulenum, *handle);break ;case CMD_NEW_CHAIN : ret =ip6tc_create_chain (chain, *handle);
Signature · 1 line
1.5.6.5
Quoted 1 line
From
4dbfcfeb9fc65df7fac1f16230871c02a85b4ea1Mon Sep 17 00:00:00 2001
From: root <root@build-vm.(none)>
Date: Tue, 7 Jul 2009 14:03:50 -0700
Subject: [PATCH] expose option to zero packet and byte counters for a specific rule using iptables
--- iptables.c | 29 +++++++++++++++++++++++------ 1 files changed, 23 insertions(+), 6 deletions(-)
iptables.c +23 -6
@@ -78,9 +78,10 @@#define CMD_SET_POLICY 0x0400U#define CMD_RENAME_CHAIN 0x0800U#define CMD_LIST_RULES 0x1000U -#define NUMBER_OF_CMD 14 +#define CMD_ZERO_NUM 0x2000U +#define NUMBER_OF_CMD 15static const char cmdflags[] = {'I' ,'D' ,'D' ,'R' ,'A' ,'L' ,'F' ,'Z' , -'N' ,'X' ,'P' ,'E' ,'S' }; +'Z' ,'N' ,'X' ,'P' ,'E' ,'S' };#define OPT_NONE 0x00000U#define OPT_NUMERIC 0x00001U
@@ -172,6 +173,7 @@ static char commands_v_options[NUMBER_OF_CMD][NUMBER_OF_OPT] = /*LIST*/ {' ','x','x','x','x',' ',' ','x','x','x',' ','x'}, /*FLUSH*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, /*ZERO*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, +/*ZERO_NUM*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, /*NEW_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, /*DEL_CHAIN*/ {'x','x','x','x','x',' ','x','x','x','x','x','x'}, /*SET_POLICY*/{'x','x','x','x','x',' ','x','x','x','x','x',' '},
@@ -280,7 +282,8 @@ exit_printhelp(struct xtables_rule_match *matches)" --list-rules -S [chain [rulenum]]\n" " Print the rules in a chain or all chains\n" " --flush -F [chain] Delete all rules in chain or all chains\n" -" --zero -Z [chain] Zero counters in chain or all chains\n" +" --zero -Z [chain [rulenum]]\n" +" Zero counters in chain or all chains\n" " --new -N chain Create a new user-defined chain\n" " --delete-chain\n" " -X [chain] Delete a user-defined chain\n"
@@ -1399,7 +1402,7 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handlebreak ;case 'L' : -add_command (&command,CMD_LIST ,CMD_ZERO , +add_command (&command,CMD_LIST ,CMD_ZERO |CMD_ZERO_NUM , invert);if (optarg) chain = optarg; else if (optind < argc && argv[optind][0] != '-'
@@ -1411,8 +1414,8 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handlebreak ;case 'S' : -add_command (&command,CMD_LIST_RULES ,CMD_ZERO , - invert); +add_command (&command,CMD_LIST_RULES , +CMD_ZERO |CMD_ZERO_NUM , invert);if (optarg) chain = optarg;else if (optind < argc && argv[optind][0 ] !='-' && argv[optind][0 ] !='!' )
@@ -1438,6 +1441,11 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handleelse if (optind < argc && argv[optind][0 ] !='-' && argv[optind][0 ] !='!' ) chain = argv[optind++]; +if (optind < argc && argv[optind][0 ] !='-' + && argv[optind][0 ] !='!' ) { + rulenum =parse_rulenumber (argv[optind++]); + command =CMD_ZERO_NUM ; + }break ;case 'N' :
@@ -1994,8 +2002,12 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handlecase CMD_ZERO : ret =zero_entries (chain, options&OPT_VERBOSE , *handle);break ; +case CMD_ZERO_NUM : + ret =iptc_zero_counter (chain, rulenum, *handle); +break ;case CMD_LIST :case CMD_LIST |CMD_ZERO : +case CMD_LIST |CMD_ZERO_NUM : ret = list_entries(chain, rulenum, options&OPT_VERBOSE,
@@ -2006,9 +2018,12 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handleif (ret && (command &CMD_ZERO )) ret =zero_entries (chain, options&OPT_VERBOSE , *handle); +if (ret && (command &CMD_ZERO_NUM )) + ret =iptc_zero_counter (chain, rulenum, *handle);break ;case CMD_LIST_RULES :case CMD_LIST_RULES |CMD_ZERO : +case CMD_LIST_RULES |CMD_ZERO_NUM : ret = list_rules(chain, rulenum, options&OPT_VERBOSE,
@@ -2016,6 +2031,8 @@ int do_command(int argc, char *argv[], char **table, struct iptc_handle **handleif (ret && (command &CMD_ZERO )) ret =zero_entries (chain, options&OPT_VERBOSE , *handle); +if (ret && (command &CMD_ZERO_NUM )) + ret =iptc_zero_counter (chain, rulenum, *handle);break ;case CMD_NEW_CHAIN : ret =iptc_create_chain (chain, *handle);
Signature · 1 line
1.5.6.5
Quoted 9 lines · Mohit Mehta
I was able to cleanly apply the attached modified patches to the latest iptables code. Also, below is the code in text if attachment doesn't reach.
build-vm:/# cat iptables.c.patchQuoted 1 line
From
4dbfcfeb9fc65df7fac1f16230871c02a85b4ea1Mon Sep 17 00:00:00 2001From: root <root@build-vm.(none)>
Date: Tue, 7 Jul 2009 14:03:50 -0700
Subject: [PATCH] expose option to zero packet and byte counters for a specific rule using iptables
I wonder what the real-world use of this is, apart from rule debugging (for which -j TRACE seems better anyhow).
I queued these patches (since I guess they won't apply elsewhere again ;-) with reservation provision, fixed the trailing whitespace, and added the missing manpage updates. Pull requests follows soon. (It's in git://dev.medozas.de/iptables master already)
Hi Mohit,
Quoted 10 lines · Jan Engelhardt
Quoted 6 lines
I was able to cleanly apply the attached modified patches to the latest iptables code. Also, below is the code in text if attachment doesn't reach.
Subject: [PATCH] expose option to zero packet and byte counters for a specific rule using iptables
I wonder what the real-world use of this is, apart from rule debugging (for which -j TRACE seems better anyhow).
That was meant to be a question. Could you please let me know why exactly -Z # was needed? I guess there was some large value seen in it given you were sending it from Vyatta, so I would like to know. If it was just an experiment and TRACE and/or quota2 (Xta) was sufficient in regards to you accomplishing whatever the intention was to, please also let me know so that I can possibly discard the branch with your -Z# submission.
Hi Jan,
Sorry for the delay in reponse. I thought you were making a statement :-) Also, thanks for cleaning up the whitespaces and man page stuff for the patch.
So, as you already mentioned in your previous post -
Quoted 2 lines
wonder what the real-world use of this is, apart from rule debugging (for which -j TRACE seems better anyhow).
The motivation for exposing the existing library function for -Z # was to facilitate an easy way for the users to debug a specific rule. I think this is most useful when there's a couple hundred rules and the user wants to quickly check if a specific rule is getting hit by looking at its counters.
Honestly, I had not looked at the TRACE target before this and that as you point out is also useful in rule debugging. But I guess that resetting the counters of a rule would would come in handy when the user already has a target defined for a rule and wants to quickly test if the rule is getting hit for an expected traffic pattern as defined in the rule. Hopefully, other people will find this useful as well.
Mohit
Quoted 22 lines · ----- Jan Engelhardt
Hi Mohit,
Quoted 10 lines · Jan Engelhardt
Quoted 6 lines
I was able to cleanly apply the attached modified patches to the latest iptables code. Also, below is the code in text if attachment doesn't reach.
Subject: [PATCH] expose option to zero packet and byte counters for a specific rule using iptables
I wonder what the real-world use of this is, apart from rule debugging (for which -j TRACE seems better anyhow).
That was meant to be a question. Could you please let me know why exactly -Z # was needed? I guess there was some large value seen in it given you were sending it from Vyatta, so I would like to know. If it was just an experiment and TRACE and/or quota2 (Xta) was sufficient in regards to you accomplishing whatever the intention was to, please also let me know so that I can possibly discard the branch with your -Z# submission.