From ec1bea522f87fc1408f649ac21ba33094d80c5ad Mon Sep 17 00:00:00 2001 From: Bart De Schuymer Date: Tue, 25 Jan 2005 21:15:59 +0000 Subject: add -c option --- userspace/ebtables2/ebtables.8 | 17 +++++++++------- userspace/ebtables2/ebtables.c | 44 +++++++++++++++++++++++++++++------------- 2 files changed, 41 insertions(+), 20 deletions(-) (limited to 'userspace') diff --git a/userspace/ebtables2/ebtables.8 b/userspace/ebtables2/ebtables.8 index 1dc8cd5..7d8671f 100644 --- a/userspace/ebtables2/ebtables.8 +++ b/userspace/ebtables2/ebtables.8 @@ -34,7 +34,7 @@ ebtables (v.2.0.7), ebtablesd, ebtablesu \- Ethernet bridge frame table administ .br .BR "ebtables " [ -t " table ] " -Z " [chain]" .br -.BR "ebtables " [ -t " table ] " -L " [" -Z "] [chain] [ [ [" --Ln "] [" --Lc "] ] | [" --Lx "] ] [" --Lmac2 ] +.BR "ebtables " [ -t " table ] " -L " [" -Z "] [chain] [ [" --Ln "] | [" --Lx "] ] [" --Lc "] [" --Lmac2 ] .br .BR "ebtables " [ -t " table ] " -N " chain [" "-P ACCEPT " | " DROP " | " RETURN" ] .br @@ -299,7 +299,8 @@ command. .br .B "--Ln" .br -Places the rule number in front of every rule. +Places the rule number in front of every rule. This option is incompatible with the +.BR --Lx " option." .br .B "--Lc" .br @@ -307,7 +308,9 @@ Shows the counters at the end of each rule displayed by the .B "-L" command. Both a frame counter (pcnt) and a byte counter (bcnt) are displayed. The frame counter shows how many frames have matched the specific rule, the byte -counter shows the sum of the frame sizes of these matching frames. +counter shows the sum of the frame sizes of these matching frames. Using this option +.BR "" "in combination with the " --Lx " option causes the counters to be written out" +.BR "" "in the '" -c " ' option format." .br .B "--Lx" .br @@ -319,11 +322,11 @@ You can use this set of commands in an ebtables boot or reload script. For example the output could be used at system startup. The .B "--Lx" -option is incompatible with both the +option is incompatible with the .B "--Ln" -and -.B "--Lc" -listing options. +listing option. Using the +.BR --Lx " option together with the " --Lc " option will cause the counters to be written out" +.BR "" "in the '" -c " ' option format." .br .B "--Lmac2" .br diff --git a/userspace/ebtables2/ebtables.c b/userspace/ebtables2/ebtables.c index f3ea7c6..8723e66 100644 --- a/userspace/ebtables2/ebtables.c +++ b/userspace/ebtables2/ebtables.c @@ -57,6 +57,7 @@ static struct option ebt_original_options[] = { "version" , no_argument , 0, 'V' }, { "help" , no_argument , 0, 'h' }, { "jump" , required_argument, 0, 'j' }, + { "set-counter" , required_argument, 0, 'c' }, { "proto" , required_argument, 0, 'p' }, { "protocol" , required_argument, 0, 'p' }, { "db" , required_argument, 0, 'b' }, @@ -298,10 +299,12 @@ static void list_em(struct ebt_u_entries *entries) if (!t) ebt_print_bug("Target '%s' not found", hlp->t->u.name); t->print(hlp, hlp->t); - if (replace->flags & LIST_C) - printf(", pcnt = %llu -- bcnt = %llu", - hlp->cnt.pcnt, - hlp->cnt.bcnt); + if (replace->flags & LIST_C) { + if (replace->flags & LIST_X) + printf("-c %llu %llu", hlp->cnt.pcnt, hlp->cnt.bcnt); + else + printf(", pcnt = %llu -- bcnt = %llu", hlp->cnt.pcnt, hlp->cnt.bcnt); + } printf("\n"); hlp = hlp->next; } @@ -467,10 +470,12 @@ void ebt_early_init_once() ({ebt_check_option(flags,mask); \ if (ebt_errormsg[0] != '\0') \ return -1;}) -#define ebt_check_inverse2(option) \ -({int __ret = ebt_check_inverse(option); \ -if (ebt_errormsg[0] != '\0') \ - return -1; \ +#define ebt_check_inverse2(option) \ +({int __ret = ebt_check_inverse(option); \ +if (ebt_errormsg[0] != '\0') \ + return -1; \ +if (!optarg) \ + __ebt_print_error("Option without (mandatory) argument"); \ __ret;}) #define OPT_COMMANDS (replace->flags & OPT_COMMAND || replace->flags & OPT_ZERO) @@ -486,6 +491,7 @@ __ret;}) #define OPT_LOGICALIN 0x200 #define OPT_LOGICALOUT 0x400 #define OPT_KERNELDATA 0x800 /* This value is also defined in ebtablesd.c */ +#define OPT_COUNT 0x1000 int do_command(int argc, char *argv[], int exec_style, struct ebt_u_replace *replace_) { @@ -539,7 +545,7 @@ int do_command(int argc, char *argv[], int exec_style, /* Getopt saves the day */ while ((c = getopt_long(argc, argv, - "-A:D:I:N:E:X::L::Z::F::P:Vhi:o:j:p:s:d:t:M:", ebt_options, NULL)) != -1) { + "-A:D:I:N:E:X::L::Z::F::P:Vhi:o:j:c:p:s:d:t:M:", ebt_options, NULL)) != -1) { switch (c) { case 'A': /* Add a rule */ @@ -730,6 +736,7 @@ print_zero: case 'p': /* Net family protocol */ case 's': /* Source mac */ case 'd': /* Destination mac */ + case 'c': /* Set counters */ if (!OPT_COMMANDS) ebt_print_error2("No command specified"); if (replace->command != 'A' && replace->command != 'D' && replace->command != 'I') @@ -836,6 +843,21 @@ print_zero: ebt_print_error2("Problem with specified destination mac"); new_entry->bitmask |= EBT_DESTMAC; break; + } else if (c == 'c') { + ebt_check_option2(&(replace->flags), OPT_COUNT); + if (ebt_check_inverse2(optarg)) + ebt_print_error2("Unexpected '!' after -c"); + if (optind >= argc) + ebt_print_error2("Option -c needs 2 arguments"); + + new_entry->cnt.pcnt = strtoull(optarg, &buffer, 10); + if (*buffer != '\0') + ebt_print_error2("Packet counter '%s' invalid", optarg) + new_entry->cnt.bcnt = strtoull(argv[optind], &buffer, 10); + if (*buffer != '\0') + ebt_print_error2("Packet counter '%s' invalid", argv[optind]) + optind++; + break; } ebt_check_option2(&(replace->flags), OPT_PROTOCOL); if (ebt_check_inverse2(optarg)) @@ -870,8 +892,6 @@ print_zero: ebt_check_option2(&(replace->flags), LIST_C); if (replace->command != 'L') ebt_print_error("Use --Lc with -L"); - if (replace->flags & LIST_X) - ebt_print_error2("--Lx is not compatible with --Lc"); replace->flags |= LIST_C; break; case 5 : /* Ln */ @@ -894,8 +914,6 @@ print_zero: ebt_check_option2(&(replace->flags), LIST_X); if (replace->command != 'L') ebt_print_error2("Use --Lx with -L"); - if (replace->flags & LIST_C) - ebt_print_error2("--Lx is not compatible with --Lc"); if (replace->flags & LIST_N) ebt_print_error2("--Lx is not compatible with --Ln"); replace->flags |= LIST_X; -- cgit v1.2.3