aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2002-06-17 16:28:39 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2002-06-17 16:28:39 +0000
commit6a8b9a06b39e5f88df504de37ad187d45ec10dc9 (patch)
treea49c2827fc3f64f78b058f3aed34ca4fbb7ac4f8 /src
parent541898a55ad62f1ac96620303cae5a08ca61c70d (diff)
downloadipacct-6a8b9a06b39e5f88df504de37ad187d45ec10dc9.tar.gz
ipacct-6a8b9a06b39e5f88df504de37ad187d45ec10dc9.tar.bz2
A slight change in the syntax. The reported direction is determined by
`as input/as output' clause at the end of stream_decl.
Diffstat (limited to 'src')
-rw-r--r--src/config.y495
1 files changed, 262 insertions, 233 deletions
diff --git a/src/config.y b/src/config.y
index 4575d23..c8af6c4 100644
--- a/src/config.y
+++ b/src/config.y
@@ -68,7 +68,7 @@ static void register_address(char *name, IPADDR addr, UINT4 netmask);
%token <string> STRING
%token <ipaddr> IPADDRESS
%token STAT HOST NET NETMASK
-%token STREAM IS FROM TO ALL EXCEPT ITSELF IN OUT
+%token STREAM IS FROM TO ALL EXCEPT ITSELF IN OUT AS
%token DEFINE
%token SLICE OPTION
%token CHANNEL K_FILE K_SYSLOG UDP
@@ -87,224 +87,251 @@ static void register_address(char *name, IPADDR addr, UINT4 netmask);
%type <string> strnam
%type <network> address
-%type <list> addr_list
+%type <list> addr_list to_addr_list from_addr_list all_addr_list
%type <number> flow_dir
%type <flow> flow_decl
-%type <stream> stream_decl
+%type <stream> stream_decl stream_def
%type <list> stream_decl_list
%%
-
-input : list
- ;
-
-list : stmt
- | list stmt
- ;
-
-stmt : stat_stmt
- | dump_stmt
- | host_stmt
- | stream_stmt
- | defn_stmt
- | error /* Actually it is `error EOL' (see yyerrsync) */
- {
- yyerrsync();
- yyerrok;
- yyclearin;
- }
- ;
-
-stat_stmt: STAT stat_cmd
- ;
-
-stat_cmd : SLICE timeval
- {
- slice_interval = $2;
- }
- | OPTION STRING
- {
- switch (xlat_keyword(options, $2)) {
- case OPT_EXACT:
- fixed_clocks++;
- break;
- default:
- parse_err("%s:%d: unknown option");
- }
- }
- | CHANNEL channel
- ;
-
-timeval : NUMBER
- | NUMBER ':' NUMBER
- {
- $$ = $1*60+$3;
- }
- | NUMBER ':' NUMBER ':' NUMBER
- {
- $$ = ($1*60+$3)*60+$5;
- }
- ;
-
-channel : K_FILE STRING channel_opts
- {
- if (add_file_channel($2, $3))
- error("too many channels");
- }
- | K_SYSLOG facility '.' priority channel_opts
- {
- if (add_syslog_channel($5, $2, $4))
- error("too many channels");
- }
- | UDP host port channel_opts
- {
- if (add_udp_channel($2, $3, $4))
- error("too many channels");
- }
- ;
-
-facility : NUMBER
- | FACILITY
- ;
-
-priority : NUMBER
- | PRIORITY
- ;
+
+input : list
+ ;
+
+list : stmt
+ | list stmt
+ ;
+
+stmt : stat_stmt
+ | dump_stmt
+ | host_stmt
+ | stream_stmt
+ | defn_stmt
+ | error /* Actually it is `error EOL' (see yyerrsync) */
+ {
+ yyerrsync();
+ yyerrok;
+ yyclearin;
+ }
+ ;
+
+stat_stmt : STAT stat_cmd
+ ;
+
+stat_cmd : SLICE timeval
+ {
+ slice_interval = $2;
+ }
+ | OPTION STRING
+ {
+ switch (xlat_keyword(options, $2)) {
+ case OPT_EXACT:
+ fixed_clocks++;
+ break;
+ default:
+ parse_err("%s:%d: unknown option");
+ }
+ }
+ | CHANNEL channel
+ ;
+
+timeval : NUMBER
+ | NUMBER ':' NUMBER
+ {
+ $$ = $1*60+$3;
+ }
+ | NUMBER ':' NUMBER ':' NUMBER
+ {
+ $$ = ($1*60+$3)*60+$5;
+ }
+ ;
+
+channel : K_FILE STRING channel_opts
+ {
+ if (add_file_channel($2, $3))
+ error("too many channels");
+ }
+ | K_SYSLOG facility '.' priority channel_opts
+ {
+ if (add_syslog_channel($5, $2, $4))
+ error("too many channels");
+ }
+ | UDP host port channel_opts
+ {
+ if (add_udp_channel($2, $3, $4))
+ error("too many channels");
+ }
+ ;
+
+facility : NUMBER
+ | FACILITY
+ ;
+
+priority : NUMBER
+ | PRIORITY
+ ;
channel_opts: /* empty */
- {
- $$ = 0;
- }
- | ABSOLUTE
- {
- $$ = 1;
- }
- ;
-
-host : IPADDRESS
- | STRING
- {
- struct hostent *hp;
- if ((hp = gethostbyname($1)) == (struct hostent *)NULL) {
- parse_err("host not found: %s", $1);
- YYERROR;
- }
- $$ = *(IPADDR*)hp->h_addr;
- }
- ;
-
-port : NUMBER
- {
- $$ = ntohs($1);
- }
- | STRING
- {
- struct servent *s;
-
- s = getservbyname($1, "udp");
- if (s)
- $$ = s->s_port;
- else {
- parse_err("no such service: %s", $1);
- YYERROR;
- }
- }
- ;
-
-dump_stmt: DUMPFILE STRING
- {
- strcpy(dump_name, $2);
- }
- ;
+ {
+ $$ = 0;
+ }
+ | ABSOLUTE
+ {
+ $$ = 1;
+ }
+ ;
+
+host : IPADDRESS
+ | STRING
+ {
+ struct hostent *hp;
+ if ((hp = gethostbyname($1)) == NULL) {
+ parse_err("host not found: %s", $1);
+ YYERROR;
+ }
+ $$ = *(IPADDR*)hp->h_addr;
+ }
+ ;
+
+port : NUMBER
+ {
+ $$ = ntohs($1);
+ }
+ | STRING
+ {
+ struct servent *s;
+
+ s = getservbyname($1, "udp");
+ if (s)
+ $$ = s->s_port;
+ else {
+ parse_err("no such service: %s", $1);
+ YYERROR;
+ }
+ }
+ ;
+
+dump_stmt : DUMPFILE STRING
+ {
+ strcpy(dump_name, $2);
+ }
+ ;
/* Backward compatibility */
-host_stmt: HOST IPADDRESS
- {
- char addrbuf[ASCII_IP_LENGTH];
- ipaddr2str(addrbuf, $2);
- register_address(addrbuf, $2, ALLONES);
- }
- | NET network
- {
- char addrbuf[ASCII_IP_LENGTH];
- ipaddr2str(addrbuf, $2.addr);
- register_address(addrbuf, $2.addr, $2.netmask);
- }
- ;
-
-network : IPADDRESS '/' NUMBER
- {
- $$.addr = $1;
- get_mask_by_length($3, &$$.netmask);
- }
- | IPADDRESS NETMASK IPADDRESS
- {
- $$.addr = $1;
- $$.netmask = $3;
- }
- ;
-
-stream_stmt: STREAM strnam is address
- {
- /* FIXME: take care of ALL and ITSELF */
- register_address($2, $4.addr, $4.netmask);
- }
- | STREAM strnam is stream_decl_list
- {
- register_stream_list($2, $4);
- }
- ;
-
-strnam : STRING
- ;
-
-is : /* empty */
- | IS
- ;
+host_stmt : HOST IPADDRESS
+ {
+ char addrbuf[ASCII_IP_LENGTH];
+ ipaddr2str(addrbuf, $2);
+ register_address(addrbuf, $2, ALLONES);
+ }
+ | NET network
+ {
+ char addrbuf[ASCII_IP_LENGTH];
+ ipaddr2str(addrbuf, $2.addr);
+ register_address(addrbuf, $2.addr, $2.netmask);
+ }
+ ;
+
+network : IPADDRESS '/' NUMBER
+ {
+ $$.addr = $1;
+ get_mask_by_length($3, &$$.netmask);
+ }
+ | IPADDRESS NETMASK IPADDRESS
+ {
+ $$.addr = $1;
+ $$.netmask = $3;
+ }
+ ;
+
+stream_stmt : STREAM strnam is address
+ {
+ /* FIXME: take care of ALL and ITSELF */
+ register_address($2, $4.addr, $4.netmask);
+ }
+ | STREAM strnam is stream_decl_list
+ {
+ register_stream_list($2, $4);
+ }
+ ;
+
+strnam : STRING
+ ;
+
+is : /* empty */
+ | IS
+ ;
stream_decl_list: stream_decl
- {
- $$ = NULL;
- list_alloc(&$$, &$1, sizeof($1));
- }
- | stream_decl_list stream_decl
- {
- list_alloc(&$1, &$2, sizeof($2));
- $$ = $1;
- }
- ;
-
-stream_decl: flow_dir flow_decl
+ {
+ $$ = NULL;
+ list_alloc(&$$, &$1, sizeof($1));
+ }
+ | stream_decl_list stream_decl
+ {
+ list_alloc(&$1, &$2, sizeof($2));
+ $$ = $1;
+ }
+ ;
+
+as : /* empty */
+ | AS
+ ;
+
+stream_decl : stream_def as flow_dir
+ {
+ $$ = $1;
+ $$.dir = $3;
+ }
+ ;
+
+stream_def : flow_decl
+ {
+ $$.direct = $1;
+ $$.except.src = NULL;
+ $$.except.dst = NULL;
+ }
+ | flow_decl EXCEPT flow_decl
+ {
+ $$.direct = $1;
+ $$.except = $3;
+ }
+ ;
+
+all_addr_list: /* empty */
{
- $$.dir = $1;
- $$.direct = $2;
- $$.except.src = NULL;
- $$.except.dst = NULL;
+ network_t all = {0, 0};
+ $$ = NULL;
+ list_alloc(&$$, &all, sizeof(all));
}
- | flow_dir flow_decl EXCEPT flow_decl
+ ;
+
+to_addr_list: all_addr_list
+ | TO addr_list
{
- $$.dir = $1;
- $$.direct = $2;
- $$.except = $4;
+ $$ = $2;
}
;
-flow_decl : FROM addr_list TO addr_list
+from_addr_list: all_addr_list
+ | FROM addr_list
+ {
+ $$ = $2;
+ }
+ ;
+
+flow_decl : FROM addr_list to_addr_list
{
$$.src = $2;
- $$.dst = $4;
+ $$.dst = $3;
}
- | TO addr_list FROM addr_list
+ | TO addr_list from_addr_list
{
- $$.src = $4;
+ $$.src = $3;
$$.dst = $2;
}
;
-flow_dir : /* empty */
- {
- $$ = DIR_SRC;
- }
- | IN
+flow_dir : IN
{
$$ = DIR_SRC;
}
@@ -314,42 +341,36 @@ flow_dir : /* empty */
}
;
-addr_list: address
- {
- $$ = NULL;
- list_alloc(&$$, &$1, sizeof($1));
- }
- | addr_list address
- {
- list_alloc(&$1, &$2, sizeof($2));
- $$ = $1;
- }
- ;
-
-address : IPADDRESS
- {
- $$.addr = $1;
- $$.netmask = ALLONES;
- }
- | network
- | ALL
- {
- $$.addr = 0;
- $$.netmask = 0;
- }
- | ITSELF
- {
- /*FIXME*/
- $$.addr = 0;
- $$.netmask = 0;
- }
- ;
-
-defn_stmt: DEFINE strnam addr_list
- {
- /* install_netlist($2, $3);*/
- }
- ;
+addr_list : address
+ {
+ $$ = NULL;
+ list_alloc(&$$, &$1, sizeof($1));
+ }
+ | addr_list address
+ {
+ list_alloc(&$1, &$2, sizeof($2));
+ $$ = $1;
+ }
+ ;
+
+address : IPADDRESS
+ {
+ $$.addr = $1;
+ $$.netmask = ALLONES;
+ }
+ | network
+ | ALL
+ {
+ $$.addr = 0;
+ $$.netmask = 0;
+ }
+ ;
+
+defn_stmt : DEFINE strnam addr_list
+ {
+ /* install_netlist($2, $3);*/
+ }
+ ;
%%
@@ -464,8 +485,9 @@ struct keyword keywords[] = {
"but", EXCEPT,
"itself", ITSELF,
"define", DEFINE,
- "in", IN,
- "out", OUT,
+ "as", AS,
+ "input", IN,
+ "output", OUT,
NULL, 0
};
@@ -620,6 +642,11 @@ read_profile(name)
fclose(file);
}
+void
+debug_profile()
+{
+ yydebug = 1;
+}
void
register_address(name, addr, netmask)
@@ -643,12 +670,14 @@ register_address(name, addr, netmask)
stream.except.src = NULL;
stream.except.dst = NULL;
list_alloc(&stream.direct.src, &network, sizeof(network));
+ list_alloc(&stream.direct.dst, &all, sizeof(all));
list_alloc(&streamlist, &stream, sizeof(stream));
stream.dir = DIR_DST;
stream.direct.src = NULL;
stream.direct.dst = NULL;
list_alloc(&stream.direct.dst, &network, sizeof(network));
+ list_alloc(&stream.direct.src, &all, sizeof(all));
list_alloc(&streamlist, &stream, sizeof(stream));
register_stream_list(name, streamlist);
}

Return to:

Send suggestions and report system problems to the System administrator.