xref: /illumos-gate/usr/src/cmd/ipf/tools/ippool_y.y (revision 7c478bd9)
1*7c478bd9Sstevel@tonic-gate %{
2*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
3*7c478bd9Sstevel@tonic-gate #include <sys/time.h>
4*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
5*7c478bd9Sstevel@tonic-gate #include <sys/socket.h>
6*7c478bd9Sstevel@tonic-gate #if defined(BSD) && (BSD >= 199306)
7*7c478bd9Sstevel@tonic-gate # include <sys/cdefs.h>
8*7c478bd9Sstevel@tonic-gate #endif
9*7c478bd9Sstevel@tonic-gate #include <sys/ioctl.h>
10*7c478bd9Sstevel@tonic-gate 
11*7c478bd9Sstevel@tonic-gate #include <net/if.h>
12*7c478bd9Sstevel@tonic-gate #if __FreeBSD_version >= 300000
13*7c478bd9Sstevel@tonic-gate # include <net/if_var.h>
14*7c478bd9Sstevel@tonic-gate #endif
15*7c478bd9Sstevel@tonic-gate #include <netinet/in.h>
16*7c478bd9Sstevel@tonic-gate 
17*7c478bd9Sstevel@tonic-gate #include <arpa/inet.h>
18*7c478bd9Sstevel@tonic-gate 
19*7c478bd9Sstevel@tonic-gate #include <stdio.h>
20*7c478bd9Sstevel@tonic-gate #include <fcntl.h>
21*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
22*7c478bd9Sstevel@tonic-gate #include <string.h>
23*7c478bd9Sstevel@tonic-gate #include <netdb.h>
24*7c478bd9Sstevel@tonic-gate #include <ctype.h>
25*7c478bd9Sstevel@tonic-gate #include <unistd.h>
26*7c478bd9Sstevel@tonic-gate 
27*7c478bd9Sstevel@tonic-gate #include "ipf.h"
28*7c478bd9Sstevel@tonic-gate #if SOLARIS2 >= 10
29*7c478bd9Sstevel@tonic-gate #include "ip_lookup.h"
30*7c478bd9Sstevel@tonic-gate #include "ip_pool.h"
31*7c478bd9Sstevel@tonic-gate #include "ip_htable.h"
32*7c478bd9Sstevel@tonic-gate #else
33*7c478bd9Sstevel@tonic-gate #include "netinet/ip_lookup.h"
34*7c478bd9Sstevel@tonic-gate #include "netinet/ip_pool.h"
35*7c478bd9Sstevel@tonic-gate #include "netinet/ip_htable.h"
36*7c478bd9Sstevel@tonic-gate #endif
37*7c478bd9Sstevel@tonic-gate #include "ippool_l.h"
38*7c478bd9Sstevel@tonic-gate #include "kmem.h"
39*7c478bd9Sstevel@tonic-gate 
40*7c478bd9Sstevel@tonic-gate #define	YYDEBUG	1
41*7c478bd9Sstevel@tonic-gate 
42*7c478bd9Sstevel@tonic-gate extern	int	yyparse __P((void));
43*7c478bd9Sstevel@tonic-gate extern	int	yydebug;
44*7c478bd9Sstevel@tonic-gate extern	FILE	*yyin;
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate static	iphtable_t	ipht;
47*7c478bd9Sstevel@tonic-gate static	iphtent_t	iphte;
48*7c478bd9Sstevel@tonic-gate static	ip_pool_t	iplo;
49*7c478bd9Sstevel@tonic-gate static	ioctlfunc_t	poolioctl = NULL;
50*7c478bd9Sstevel@tonic-gate static	char		poolname[FR_GROUPLEN];
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate %}
53*7c478bd9Sstevel@tonic-gate 
54*7c478bd9Sstevel@tonic-gate %union	{
55*7c478bd9Sstevel@tonic-gate 	char	*str;
56*7c478bd9Sstevel@tonic-gate 	u_32_t	num;
57*7c478bd9Sstevel@tonic-gate 	struct	in_addr	addr;
58*7c478bd9Sstevel@tonic-gate 	struct	alist_s	*alist;
59*7c478bd9Sstevel@tonic-gate 	struct	in_addr	adrmsk[2];
60*7c478bd9Sstevel@tonic-gate 	iphtent_t	*ipe;
61*7c478bd9Sstevel@tonic-gate 	ip_pool_node_t	*ipp;
62*7c478bd9Sstevel@tonic-gate 	union	i6addr	ip6;
63*7c478bd9Sstevel@tonic-gate }
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate %token  <num>   YY_NUMBER YY_HEX
66*7c478bd9Sstevel@tonic-gate %token  <str>   YY_STR
67*7c478bd9Sstevel@tonic-gate %token	  YY_COMMENT
68*7c478bd9Sstevel@tonic-gate %token	  YY_CMP_EQ YY_CMP_NE YY_CMP_LE YY_CMP_GE YY_CMP_LT YY_CMP_GT
69*7c478bd9Sstevel@tonic-gate %token	  YY_RANGE_OUT YY_RANGE_IN
70*7c478bd9Sstevel@tonic-gate %token  <ip6>   YY_IPV6
71*7c478bd9Sstevel@tonic-gate 
72*7c478bd9Sstevel@tonic-gate %token	IPT_IPF IPT_NAT IPT_COUNT IPT_AUTH IPT_IN IPT_OUT
73*7c478bd9Sstevel@tonic-gate %token	IPT_TABLE IPT_GROUPMAP IPT_HASH
74*7c478bd9Sstevel@tonic-gate %token	IPT_ROLE IPT_TYPE IPT_TREE
75*7c478bd9Sstevel@tonic-gate %token	IPT_GROUP IPT_SIZE IPT_SEED IPT_NUM IPT_NAME
76*7c478bd9Sstevel@tonic-gate %type	<num> role table inout
77*7c478bd9Sstevel@tonic-gate %type	<ipp> ipftree range addrlist
78*7c478bd9Sstevel@tonic-gate %type	<adrmsk> addrmask
79*7c478bd9Sstevel@tonic-gate %type	<ipe> ipfgroup ipfhash hashlist hashentry
80*7c478bd9Sstevel@tonic-gate %type	<ipe> groupentry setgrouplist grouplist
81*7c478bd9Sstevel@tonic-gate %type	<addr> ipaddr mask ipv4
82*7c478bd9Sstevel@tonic-gate %type	<str> number setgroup
83*7c478bd9Sstevel@tonic-gate 
84*7c478bd9Sstevel@tonic-gate %%
85*7c478bd9Sstevel@tonic-gate file:	line
86*7c478bd9Sstevel@tonic-gate 	| assign
87*7c478bd9Sstevel@tonic-gate 	| file line
88*7c478bd9Sstevel@tonic-gate 	| file assign
89*7c478bd9Sstevel@tonic-gate 	;
90*7c478bd9Sstevel@tonic-gate 
91*7c478bd9Sstevel@tonic-gate line:	table role ipftree eol		{ iplo.ipo_unit = $2;
92*7c478bd9Sstevel@tonic-gate 					  iplo.ipo_list = $3;
93*7c478bd9Sstevel@tonic-gate 					  load_pool(&iplo, poolioctl);
94*7c478bd9Sstevel@tonic-gate 					  resetlexer();
95*7c478bd9Sstevel@tonic-gate 					}
96*7c478bd9Sstevel@tonic-gate 	| table role ipfhash eol	{ ipht.iph_unit = $2;
97*7c478bd9Sstevel@tonic-gate 					  ipht.iph_type = IPHASH_LOOKUP;
98*7c478bd9Sstevel@tonic-gate 					  load_hash(&ipht, $3, poolioctl);
99*7c478bd9Sstevel@tonic-gate 					  resetlexer();
100*7c478bd9Sstevel@tonic-gate 					}
101*7c478bd9Sstevel@tonic-gate 	| groupmap role number ipfgroup eol
102*7c478bd9Sstevel@tonic-gate 					{ ipht.iph_unit = $2;
103*7c478bd9Sstevel@tonic-gate 					  strncpy(ipht.iph_name, $3,
104*7c478bd9Sstevel@tonic-gate 						  sizeof(ipht.iph_name));
105*7c478bd9Sstevel@tonic-gate 					  ipht.iph_type = IPHASH_GROUPMAP;
106*7c478bd9Sstevel@tonic-gate 					  load_hash(&ipht, $4, poolioctl);
107*7c478bd9Sstevel@tonic-gate 					  resetlexer();
108*7c478bd9Sstevel@tonic-gate 					}
109*7c478bd9Sstevel@tonic-gate 	| YY_COMMENT
110*7c478bd9Sstevel@tonic-gate 	;
111*7c478bd9Sstevel@tonic-gate 
112*7c478bd9Sstevel@tonic-gate eol:	';'
113*7c478bd9Sstevel@tonic-gate 	;
114*7c478bd9Sstevel@tonic-gate 
115*7c478bd9Sstevel@tonic-gate assign:	YY_STR assigning YY_STR ';'	{ set_variable($1, $3);
116*7c478bd9Sstevel@tonic-gate 					  resetlexer();
117*7c478bd9Sstevel@tonic-gate 					  free($1);
118*7c478bd9Sstevel@tonic-gate 					  free($3);
119*7c478bd9Sstevel@tonic-gate 					}
120*7c478bd9Sstevel@tonic-gate 	;
121*7c478bd9Sstevel@tonic-gate 
122*7c478bd9Sstevel@tonic-gate assigning:
123*7c478bd9Sstevel@tonic-gate 	'='				{ yyvarnext = 1; }
124*7c478bd9Sstevel@tonic-gate 	;
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate table:	IPT_TABLE		{ bzero((char *)&ipht, sizeof(ipht));
127*7c478bd9Sstevel@tonic-gate 				  bzero((char *)&iphte, sizeof(iphte));
128*7c478bd9Sstevel@tonic-gate 				  bzero((char *)&iplo, sizeof(iplo));
129*7c478bd9Sstevel@tonic-gate 				  *ipht.iph_name = '\0';
130*7c478bd9Sstevel@tonic-gate 				  iplo.ipo_flags = IPHASH_ANON;
131*7c478bd9Sstevel@tonic-gate 				  iplo.ipo_name[0] = '\0';
132*7c478bd9Sstevel@tonic-gate 				}
133*7c478bd9Sstevel@tonic-gate 	;
134*7c478bd9Sstevel@tonic-gate 
135*7c478bd9Sstevel@tonic-gate groupmap:
136*7c478bd9Sstevel@tonic-gate 	IPT_GROUPMAP inout	{ bzero((char *)&ipht, sizeof(ipht));
137*7c478bd9Sstevel@tonic-gate 				  bzero((char *)&iphte, sizeof(iphte));
138*7c478bd9Sstevel@tonic-gate 				  *ipht.iph_name = '\0';
139*7c478bd9Sstevel@tonic-gate 				  ipht.iph_unit = IPHASH_GROUPMAP;
140*7c478bd9Sstevel@tonic-gate 				  ipht.iph_flags = $2;
141*7c478bd9Sstevel@tonic-gate 				}
142*7c478bd9Sstevel@tonic-gate 	;
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate inout:	IPT_IN				{ $$ = FR_INQUE; }
145*7c478bd9Sstevel@tonic-gate 	| IPT_OUT			{ $$ = FR_OUTQUE; }
146*7c478bd9Sstevel@tonic-gate 	;
147*7c478bd9Sstevel@tonic-gate role:
148*7c478bd9Sstevel@tonic-gate 	IPT_ROLE '=' IPT_IPF		{ $$ = IPL_LOGIPF; }
149*7c478bd9Sstevel@tonic-gate 	| IPT_ROLE '=' IPT_NAT		{ $$ = IPL_LOGNAT; }
150*7c478bd9Sstevel@tonic-gate 	| IPT_ROLE '=' IPT_AUTH		{ $$ = IPL_LOGAUTH; }
151*7c478bd9Sstevel@tonic-gate 	| IPT_ROLE '=' IPT_COUNT	{ $$ = IPL_LOGCOUNT; }
152*7c478bd9Sstevel@tonic-gate 	;
153*7c478bd9Sstevel@tonic-gate 
154*7c478bd9Sstevel@tonic-gate ipftree:
155*7c478bd9Sstevel@tonic-gate 	IPT_TYPE '=' IPT_TREE number '{' addrlist '}'
156*7c478bd9Sstevel@tonic-gate 					{ strncpy(iplo.ipo_name, $4,
157*7c478bd9Sstevel@tonic-gate 						  sizeof(iplo.ipo_name));
158*7c478bd9Sstevel@tonic-gate 					  $$ = $6;
159*7c478bd9Sstevel@tonic-gate 					}
160*7c478bd9Sstevel@tonic-gate 	;
161*7c478bd9Sstevel@tonic-gate 
162*7c478bd9Sstevel@tonic-gate ipfhash:
163*7c478bd9Sstevel@tonic-gate 	IPT_TYPE '=' IPT_HASH number hashopts '{' hashlist '}'
164*7c478bd9Sstevel@tonic-gate 					{ strncpy(ipht.iph_name, $4,
165*7c478bd9Sstevel@tonic-gate 						  sizeof(ipht.iph_name));
166*7c478bd9Sstevel@tonic-gate 					  $$ = $7;
167*7c478bd9Sstevel@tonic-gate 					}
168*7c478bd9Sstevel@tonic-gate 	;
169*7c478bd9Sstevel@tonic-gate 
170*7c478bd9Sstevel@tonic-gate ipfgroup:
171*7c478bd9Sstevel@tonic-gate 	setgroup hashopts '{' grouplist '}'
172*7c478bd9Sstevel@tonic-gate 					{ iphtent_t *e;
173*7c478bd9Sstevel@tonic-gate 					  for (e = $4; e != NULL;
174*7c478bd9Sstevel@tonic-gate 					       e = e->ipe_next)
175*7c478bd9Sstevel@tonic-gate 						if (e->ipe_group[0] == '\0')
176*7c478bd9Sstevel@tonic-gate 							strncpy(e->ipe_group,
177*7c478bd9Sstevel@tonic-gate 								$1,
178*7c478bd9Sstevel@tonic-gate 								FR_GROUPLEN);
179*7c478bd9Sstevel@tonic-gate 					  $$ = $4;
180*7c478bd9Sstevel@tonic-gate 					}
181*7c478bd9Sstevel@tonic-gate 	| hashopts '{' setgrouplist '}'		{ $$ = $3; }
182*7c478bd9Sstevel@tonic-gate 	;
183*7c478bd9Sstevel@tonic-gate 
184*7c478bd9Sstevel@tonic-gate number:	IPT_NUM '=' YY_NUMBER			{ sprintf(poolname, "%u", $3);
185*7c478bd9Sstevel@tonic-gate 						  $$ = poolname;
186*7c478bd9Sstevel@tonic-gate 						}
187*7c478bd9Sstevel@tonic-gate 	| IPT_NAME '=' YY_STR			{ $$ = $3; }
188*7c478bd9Sstevel@tonic-gate 	|					{ $$ = ""; }
189*7c478bd9Sstevel@tonic-gate 	;
190*7c478bd9Sstevel@tonic-gate 
191*7c478bd9Sstevel@tonic-gate setgroup:
192*7c478bd9Sstevel@tonic-gate 	IPT_GROUP '=' YY_STR		{ char tmp[FR_GROUPLEN+1];
193*7c478bd9Sstevel@tonic-gate 					  strncpy(tmp, $3, FR_GROUPLEN);
194*7c478bd9Sstevel@tonic-gate 					  $$ = strdup(tmp);
195*7c478bd9Sstevel@tonic-gate 					}
196*7c478bd9Sstevel@tonic-gate 	| IPT_GROUP '=' YY_NUMBER	{ char tmp[FR_GROUPLEN+1];
197*7c478bd9Sstevel@tonic-gate 					  sprintf(tmp, "%u", $3);
198*7c478bd9Sstevel@tonic-gate 					  $$ = strdup(tmp);
199*7c478bd9Sstevel@tonic-gate 					}
200*7c478bd9Sstevel@tonic-gate 	;
201*7c478bd9Sstevel@tonic-gate 
202*7c478bd9Sstevel@tonic-gate hashopts:
203*7c478bd9Sstevel@tonic-gate 	| size
204*7c478bd9Sstevel@tonic-gate 	| seed
205*7c478bd9Sstevel@tonic-gate 	| size seed
206*7c478bd9Sstevel@tonic-gate 	;
207*7c478bd9Sstevel@tonic-gate 
208*7c478bd9Sstevel@tonic-gate addrlist:
209*7c478bd9Sstevel@tonic-gate 	range ',' addrlist		{ $1->ipn_next = $3; $$ = $1; }
210*7c478bd9Sstevel@tonic-gate 	| range				{ $$ = $1; }
211*7c478bd9Sstevel@tonic-gate 	;
212*7c478bd9Sstevel@tonic-gate 
213*7c478bd9Sstevel@tonic-gate grouplist:
214*7c478bd9Sstevel@tonic-gate 	groupentry ';' grouplist	{ $$ = $1; $1->ipe_next = $3; }
215*7c478bd9Sstevel@tonic-gate 	| addrmask ';' grouplist	{ $$ = calloc(1, sizeof(iphtent_t));
216*7c478bd9Sstevel@tonic-gate 					  bcopy((char *)&($1[0]),
217*7c478bd9Sstevel@tonic-gate 						(char *)&($$->ipe_addr),
218*7c478bd9Sstevel@tonic-gate 						sizeof($$->ipe_addr));
219*7c478bd9Sstevel@tonic-gate 					  bcopy((char *)&($1[1]),
220*7c478bd9Sstevel@tonic-gate 						(char *)&($$->ipe_mask),
221*7c478bd9Sstevel@tonic-gate 						sizeof($$->ipe_mask));
222*7c478bd9Sstevel@tonic-gate 					  $$->ipe_next = $3;
223*7c478bd9Sstevel@tonic-gate 					}
224*7c478bd9Sstevel@tonic-gate 	| groupentry ';'		{ $$ = $1; }
225*7c478bd9Sstevel@tonic-gate 	| addrmask ';'			{ $$ = calloc(1, sizeof(iphtent_t));
226*7c478bd9Sstevel@tonic-gate 					  bcopy((char *)&($1[0]),
227*7c478bd9Sstevel@tonic-gate 						(char *)&($$->ipe_addr),
228*7c478bd9Sstevel@tonic-gate 						sizeof($$->ipe_addr));
229*7c478bd9Sstevel@tonic-gate 					  bcopy((char *)&($1[1]),
230*7c478bd9Sstevel@tonic-gate 						(char *)&($$->ipe_mask),
231*7c478bd9Sstevel@tonic-gate 						sizeof($$->ipe_mask));
232*7c478bd9Sstevel@tonic-gate 					}
233*7c478bd9Sstevel@tonic-gate 	;
234*7c478bd9Sstevel@tonic-gate 
235*7c478bd9Sstevel@tonic-gate setgrouplist:
236*7c478bd9Sstevel@tonic-gate 	groupentry ';'			{ $$ = $1; }
237*7c478bd9Sstevel@tonic-gate 	| groupentry ';' setgrouplist	{ $1->ipe_next = $3; $$ = $1; }
238*7c478bd9Sstevel@tonic-gate 	;
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate groupentry:
241*7c478bd9Sstevel@tonic-gate 	addrmask ',' setgroup		{ $$ = calloc(1, sizeof(iphtent_t));
242*7c478bd9Sstevel@tonic-gate 					  bcopy((char *)&($1[0]),
243*7c478bd9Sstevel@tonic-gate 						(char *)&($$->ipe_addr),
244*7c478bd9Sstevel@tonic-gate 						sizeof($$->ipe_addr));
245*7c478bd9Sstevel@tonic-gate 					  bcopy((char *)&($1[1]),
246*7c478bd9Sstevel@tonic-gate 						(char *)&($$->ipe_mask),
247*7c478bd9Sstevel@tonic-gate 						sizeof($$->ipe_mask));
248*7c478bd9Sstevel@tonic-gate 					  strncpy($$->ipe_group, $3,
249*7c478bd9Sstevel@tonic-gate 						  FR_GROUPLEN);
250*7c478bd9Sstevel@tonic-gate 					  free($3);
251*7c478bd9Sstevel@tonic-gate 					}
252*7c478bd9Sstevel@tonic-gate 	;
253*7c478bd9Sstevel@tonic-gate 
254*7c478bd9Sstevel@tonic-gate range:	addrmask	{ $$ = calloc(1, sizeof(*$$));
255*7c478bd9Sstevel@tonic-gate 			  $$->ipn_info = 0;
256*7c478bd9Sstevel@tonic-gate 			  $$->ipn_addr.adf_addr.in4.s_addr = $1[0].s_addr;
257*7c478bd9Sstevel@tonic-gate 			  $$->ipn_mask.adf_addr.in4.s_addr = $1[1].s_addr;
258*7c478bd9Sstevel@tonic-gate 			}
259*7c478bd9Sstevel@tonic-gate 	| '!' addrmask	{ $$ = calloc(1, sizeof(*$$));
260*7c478bd9Sstevel@tonic-gate 			  $$->ipn_info = 1;
261*7c478bd9Sstevel@tonic-gate 			  $$->ipn_addr.adf_addr.in4.s_addr = $2[0].s_addr;
262*7c478bd9Sstevel@tonic-gate 			  $$->ipn_mask.adf_addr.in4.s_addr = $2[1].s_addr;
263*7c478bd9Sstevel@tonic-gate 			}
264*7c478bd9Sstevel@tonic-gate 
265*7c478bd9Sstevel@tonic-gate hashlist:
266*7c478bd9Sstevel@tonic-gate 	hashentry ';'			{ $$ = $1; }
267*7c478bd9Sstevel@tonic-gate 	| hashentry ';' hashlist	{ $1->ipe_next = $3; $$ = $1; }
268*7c478bd9Sstevel@tonic-gate 	;
269*7c478bd9Sstevel@tonic-gate 
270*7c478bd9Sstevel@tonic-gate hashentry:
271*7c478bd9Sstevel@tonic-gate 	addrmask 			{ $$ = calloc(1, sizeof(iphtent_t));
272*7c478bd9Sstevel@tonic-gate 					  bcopy((char *)&($1[0]),
273*7c478bd9Sstevel@tonic-gate 						(char *)&($$->ipe_addr),
274*7c478bd9Sstevel@tonic-gate 						sizeof($$->ipe_addr));
275*7c478bd9Sstevel@tonic-gate 					  bcopy((char *)&($1[1]),
276*7c478bd9Sstevel@tonic-gate 						(char *)&($$->ipe_mask),
277*7c478bd9Sstevel@tonic-gate 						sizeof($$->ipe_mask));
278*7c478bd9Sstevel@tonic-gate 					}
279*7c478bd9Sstevel@tonic-gate 	;
280*7c478bd9Sstevel@tonic-gate 
281*7c478bd9Sstevel@tonic-gate addrmask:
282*7c478bd9Sstevel@tonic-gate 	ipaddr '/' mask		{ $$[0] = $1; $$[1].s_addr = $3.s_addr; }
283*7c478bd9Sstevel@tonic-gate 	| ipaddr		{ $$[0] = $1; $$[1].s_addr = 0xffffffff; }
284*7c478bd9Sstevel@tonic-gate 	;
285*7c478bd9Sstevel@tonic-gate 
286*7c478bd9Sstevel@tonic-gate ipaddr:	ipv4			{ $$ = $1; }
287*7c478bd9Sstevel@tonic-gate 	| YY_NUMBER		{ $$.s_addr = htonl($1); }
288*7c478bd9Sstevel@tonic-gate 	;
289*7c478bd9Sstevel@tonic-gate 
290*7c478bd9Sstevel@tonic-gate mask:	YY_NUMBER		{ ntomask(4, $1, (u_32_t *)&$$.s_addr); }
291*7c478bd9Sstevel@tonic-gate 	| ipv4			{ $$ = $1; }
292*7c478bd9Sstevel@tonic-gate 	;
293*7c478bd9Sstevel@tonic-gate 
294*7c478bd9Sstevel@tonic-gate size:	IPT_SIZE '=' YY_NUMBER	{ ipht.iph_size = $3; }
295*7c478bd9Sstevel@tonic-gate 	;
296*7c478bd9Sstevel@tonic-gate 
297*7c478bd9Sstevel@tonic-gate seed:	IPT_SEED '=' YY_NUMBER	{ ipht.iph_seed = $3; }
298*7c478bd9Sstevel@tonic-gate 	;
299*7c478bd9Sstevel@tonic-gate 
300*7c478bd9Sstevel@tonic-gate ipv4:	YY_NUMBER '.' YY_NUMBER '.' YY_NUMBER '.' YY_NUMBER
301*7c478bd9Sstevel@tonic-gate 		{ if ($1 > 255 || $3 > 255 || $5 > 255 || $7 > 255) {
302*7c478bd9Sstevel@tonic-gate 			yyerror("Invalid octet string for IP address");
303*7c478bd9Sstevel@tonic-gate 			return 0;
304*7c478bd9Sstevel@tonic-gate 		  }
305*7c478bd9Sstevel@tonic-gate 		  $$.s_addr = ($1 << 24) | ($3 << 16) | ($5 << 8) | $7;
306*7c478bd9Sstevel@tonic-gate 		  $$.s_addr = htonl($$.s_addr);
307*7c478bd9Sstevel@tonic-gate 		}
308*7c478bd9Sstevel@tonic-gate 	;
309*7c478bd9Sstevel@tonic-gate %%
310*7c478bd9Sstevel@tonic-gate static	wordtab_t	yywords[] = {
311*7c478bd9Sstevel@tonic-gate 	{ "auth",	IPT_AUTH },
312*7c478bd9Sstevel@tonic-gate 	{ "count",	IPT_COUNT },
313*7c478bd9Sstevel@tonic-gate 	{ "group",	IPT_GROUP },
314*7c478bd9Sstevel@tonic-gate 	{ "group-map",	IPT_GROUPMAP },
315*7c478bd9Sstevel@tonic-gate 	{ "hash",	IPT_HASH },
316*7c478bd9Sstevel@tonic-gate 	{ "in",		IPT_IN },
317*7c478bd9Sstevel@tonic-gate 	{ "ipf",	IPT_IPF },
318*7c478bd9Sstevel@tonic-gate 	{ "name",	IPT_NAME },
319*7c478bd9Sstevel@tonic-gate 	{ "nat",	IPT_NAT },
320*7c478bd9Sstevel@tonic-gate 	{ "number",	IPT_NUM },
321*7c478bd9Sstevel@tonic-gate 	{ "out",	IPT_OUT },
322*7c478bd9Sstevel@tonic-gate 	{ "role",	IPT_ROLE },
323*7c478bd9Sstevel@tonic-gate 	{ "seed",	IPT_SEED },
324*7c478bd9Sstevel@tonic-gate 	{ "size",	IPT_SIZE },
325*7c478bd9Sstevel@tonic-gate 	{ "table",	IPT_TABLE },
326*7c478bd9Sstevel@tonic-gate 	{ "tree",	IPT_TREE },
327*7c478bd9Sstevel@tonic-gate 	{ "type",	IPT_TYPE },
328*7c478bd9Sstevel@tonic-gate 	{ NULL,		0 }
329*7c478bd9Sstevel@tonic-gate };
330*7c478bd9Sstevel@tonic-gate 
331*7c478bd9Sstevel@tonic-gate 
332*7c478bd9Sstevel@tonic-gate int ippool_parsefile(fd, filename, iocfunc)
333*7c478bd9Sstevel@tonic-gate int fd;
334*7c478bd9Sstevel@tonic-gate char *filename;
335*7c478bd9Sstevel@tonic-gate ioctlfunc_t iocfunc;
336*7c478bd9Sstevel@tonic-gate {
337*7c478bd9Sstevel@tonic-gate 	FILE *fp = NULL;
338*7c478bd9Sstevel@tonic-gate 	char *s;
339*7c478bd9Sstevel@tonic-gate 
340*7c478bd9Sstevel@tonic-gate 	yylineNum = 1;
341*7c478bd9Sstevel@tonic-gate 	(void) yysettab(yywords);
342*7c478bd9Sstevel@tonic-gate 
343*7c478bd9Sstevel@tonic-gate 	s = getenv("YYDEBUG");
344*7c478bd9Sstevel@tonic-gate 	if (s)
345*7c478bd9Sstevel@tonic-gate 		yydebug = atoi(s);
346*7c478bd9Sstevel@tonic-gate 	else
347*7c478bd9Sstevel@tonic-gate 		yydebug = 0;
348*7c478bd9Sstevel@tonic-gate 
349*7c478bd9Sstevel@tonic-gate 	if (strcmp(filename, "-")) {
350*7c478bd9Sstevel@tonic-gate 		fp = fopen(filename, "r");
351*7c478bd9Sstevel@tonic-gate 		if (!fp) {
352*7c478bd9Sstevel@tonic-gate 			fprintf(stderr, "fopen(%s) failed: %s\n", filename,
353*7c478bd9Sstevel@tonic-gate 				STRERROR(errno));
354*7c478bd9Sstevel@tonic-gate 			return -1;
355*7c478bd9Sstevel@tonic-gate 		}
356*7c478bd9Sstevel@tonic-gate 	} else
357*7c478bd9Sstevel@tonic-gate 		fp = stdin;
358*7c478bd9Sstevel@tonic-gate 
359*7c478bd9Sstevel@tonic-gate 	while (ippool_parsesome(fd, fp, iocfunc) == 1)
360*7c478bd9Sstevel@tonic-gate 		;
361*7c478bd9Sstevel@tonic-gate 	if (fp != NULL)
362*7c478bd9Sstevel@tonic-gate 		fclose(fp);
363*7c478bd9Sstevel@tonic-gate 	return 0;
364*7c478bd9Sstevel@tonic-gate }
365*7c478bd9Sstevel@tonic-gate 
366*7c478bd9Sstevel@tonic-gate 
367*7c478bd9Sstevel@tonic-gate int ippool_parsesome(fd, fp, iocfunc)
368*7c478bd9Sstevel@tonic-gate int fd;
369*7c478bd9Sstevel@tonic-gate FILE *fp;
370*7c478bd9Sstevel@tonic-gate ioctlfunc_t iocfunc;
371*7c478bd9Sstevel@tonic-gate {
372*7c478bd9Sstevel@tonic-gate 	char *s;
373*7c478bd9Sstevel@tonic-gate 	int i;
374*7c478bd9Sstevel@tonic-gate 
375*7c478bd9Sstevel@tonic-gate 	poolioctl = iocfunc;
376*7c478bd9Sstevel@tonic-gate 
377*7c478bd9Sstevel@tonic-gate 	if (feof(fp))
378*7c478bd9Sstevel@tonic-gate 		return 0;
379*7c478bd9Sstevel@tonic-gate 	i = fgetc(fp);
380*7c478bd9Sstevel@tonic-gate 	if (i == EOF)
381*7c478bd9Sstevel@tonic-gate 		return 0;
382*7c478bd9Sstevel@tonic-gate 	if (ungetc(i, fp) == EOF)
383*7c478bd9Sstevel@tonic-gate 		return 0;
384*7c478bd9Sstevel@tonic-gate 	if (feof(fp))
385*7c478bd9Sstevel@tonic-gate 		return 0;
386*7c478bd9Sstevel@tonic-gate 	s = getenv("YYDEBUG");
387*7c478bd9Sstevel@tonic-gate 	if (s)
388*7c478bd9Sstevel@tonic-gate 		yydebug = atoi(s);
389*7c478bd9Sstevel@tonic-gate 	else
390*7c478bd9Sstevel@tonic-gate 		yydebug = 0;
391*7c478bd9Sstevel@tonic-gate 
392*7c478bd9Sstevel@tonic-gate 	yyin = fp;
393*7c478bd9Sstevel@tonic-gate 	yyparse();
394*7c478bd9Sstevel@tonic-gate 	return 1;
395*7c478bd9Sstevel@tonic-gate }
396