/*-
* Copyright (c) 2010 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
%token STATE
%token IN OUT
%token ON PROTO
%token FROM TO USING
%token ID CID EXPIRE TIMEOUT
%token SRC DST
%token SEQ MAX_WIN WSCALE MSS
%token NOSCRUB SCRUB FLAGS TTL MODE
%token NUMBER STRING
%type <str> STRING
%type <num> NUMBER
%%
states
: /* NOTHING */
| state states { parse_init(); }
;
state
: STATE direction iface proto addrs id cid expire timeout src_peer dst_peer {
add_state();
}
;
direction
: IN {
global_state.direction = PF_IN;
src_peer = &global_state.dst;
dst_peer = &global_state.src;
}
| OUT {
global_state.direction = PF_OUT;
src_peer = &global_state.src;
dst_peer = &global_state.dst;
}
;
proto
: PROTO STRING {
struct protoent *p;
p = getprotobyname($2);
if (p == NULL)
yyfatal("Invalid protocol name");
global_state.proto = p->p_proto;
free($2);
}
| PROTO NUMBER {
// check that the number may be valid proto ?
global_state.proto = $2;
}
;
addrs
: FROM STRING TO STRING {
get_pfsync_host($2, &global_state.lan, &global_state.af);
get_pfsync_host($4, &global_state.ext, &global_state.af);
memcpy(&global_state.gwy, &global_state.lan, sizeof(struct pfsync_state_host));
free($2);
free($4);
}
| FROM STRING TO STRING USING STRING {
get_pfsync_host($2, &global_state.lan, &global_state.af);
get_pfsync_host($4, &global_state.ext, &global_state.af);
get_pfsync_host($6, &global_state.gwy, &global_state.af);
free($2);
free($4);
free($6);
}
;
id
: ID NUMBER {
if ( $2 > UINT64_MAX)
yyfatal("id is too big");
uint64_t value = (uint64_t)$2;
memcpy(global_state.id, &value, sizeof(global_state.id));
}
;
cid
: CID NUMBER {
if ( $2 > UINT32_MAX)
yyfatal("creator id is too big");
global_state.creatorid = (uint32_t)$2;
}
;
expire
: EXPIRE NUMBER {
if ( $2 > UINT32_MAX)
yyfatal("expire time is too big");
global_state.expire = (uint32_t) $2;
}
;
timeout
: TIMEOUT NUMBER {
if ($2 > UINT8_MAX)
yyfatal("timeout time is too big");
global_state.timeout = (uint8_t) $2;
}
;
peer_state
: STATE STRING {
current_peer.state = retrieve_peer_state($2, global_state.proto);
free($2);
}
| STATE NUMBER {
if ( $2 > UINT8_MAX)
yyfatal("peer state is too big");
current_peer.state = $2;
}
;
tcp_options
: SEQ seqs MAX_WIN NUMBER WSCALE NUMBER {
if ($4 > UINT16_MAX)
yyfatal("max_win is too big");
current_peer.max_win = $4;
if ($6 > UINT8_MAX)
yyfatal("wscale is too big");
current_peer.wscale = $6;
}
| SEQ seqs MAX_WIN NUMBER WSCALE NUMBER MSS NUMBER {
if ($4 > UINT16_MAX)
yyfatal("max_win is too big");
current_peer.max_win = $4;
if ($6 > UINT8_MAX)
yyfatal("wscale is too big");
current_peer.wscale = $6;
if ($8 > UINT16_MAX)
yyfatal("mss is too big");
current_peer.mss = $8;
}
;
seqs
: STRING {
if (!retrieve_seq($1, ¤t_peer))
yyfatal("invalid seq number");
free($1);
}
;
scrub
: NOSCRUB { current_peer.scrub.scrub_flag= 0;}
| SCRUB FLAGS NUMBER MODE NUMBER TTL NUMBER {
current_peer.scrub.scrub_flag= PFSYNC_SCRUB_FLAG_VALID;
if ($3 > UINT16_MAX)
yyfatal("scrub flags is too big");
current_peer.scrub.pfss_flags = $3;
if ($5 > UINT32_MAX)
yyfatal("scrub mode is too big");
current_peer.scrub.pfss_ts_mod = $5;
if ($7 > UINT8_MAX)
yyfatal("scrub ttl is too big");
current_peer.scrub.pfss_ttl = $7;
}
;