xref: /illumos-gate/usr/src/cmd/ipf/tools/ippool_y.y (revision 2a8bcb4e)
17c478bd9Sstevel@tonic-gate %{
27663b816Sml /*
37663b816Sml  * Copyright (C) 2003 by Darren Reed.
47663b816Sml  *
57663b816Sml  * See the IPFILTER.LICENCE file for details on licencing.
67663b816Sml  *
7ab25eeb5Syz  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
87663b816Sml  * Use is subject to license terms.
97663b816Sml  */
107663b816Sml 
117c478bd9Sstevel@tonic-gate #include <sys/types.h>
127c478bd9Sstevel@tonic-gate #include <sys/time.h>
137c478bd9Sstevel@tonic-gate #include <sys/param.h>
147c478bd9Sstevel@tonic-gate #include <sys/socket.h>
157c478bd9Sstevel@tonic-gate #if defined(BSD) && (BSD >= 199306)
167c478bd9Sstevel@tonic-gate # include <sys/cdefs.h>
177c478bd9Sstevel@tonic-gate #endif
187c478bd9Sstevel@tonic-gate #include <sys/ioctl.h>
197c478bd9Sstevel@tonic-gate 
207c478bd9Sstevel@tonic-gate #include <net/if.h>
217c478bd9Sstevel@tonic-gate #if __FreeBSD_version >= 300000
227c478bd9Sstevel@tonic-gate # include <net/if_var.h>
237c478bd9Sstevel@tonic-gate #endif
247c478bd9Sstevel@tonic-gate #include <netinet/in.h>
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include <arpa/inet.h>
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <stdio.h>
297c478bd9Sstevel@tonic-gate #include <fcntl.h>
307c478bd9Sstevel@tonic-gate #include <stdlib.h>
317c478bd9Sstevel@tonic-gate #include <string.h>
327c478bd9Sstevel@tonic-gate #include <netdb.h>
337c478bd9Sstevel@tonic-gate #include <ctype.h>
347c478bd9Sstevel@tonic-gate #include <unistd.h>
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include "ipf.h"
377c478bd9Sstevel@tonic-gate #include "netinet/ip_lookup.h"
387c478bd9Sstevel@tonic-gate #include "netinet/ip_pool.h"
397c478bd9Sstevel@tonic-gate #include "netinet/ip_htable.h"
407c478bd9Sstevel@tonic-gate #include "ippool_l.h"
417c478bd9Sstevel@tonic-gate #include "kmem.h"
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #define	YYDEBUG	1
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate extern	int	yyparse __P((void));
467c478bd9Sstevel@tonic-gate extern	int	yydebug;
477c478bd9Sstevel@tonic-gate extern	FILE	*yyin;
487c478bd9Sstevel@tonic-gate 
497c478bd9Sstevel@tonic-gate static	iphtable_t	ipht;
507c478bd9Sstevel@tonic-gate static	iphtent_t	iphte;
517c478bd9Sstevel@tonic-gate static	ip_pool_t	iplo;
527c478bd9Sstevel@tonic-gate static	ioctlfunc_t	poolioctl = NULL;
537c478bd9Sstevel@tonic-gate static	char		poolname[FR_GROUPLEN];
547663b816Sml static	int		set_ipv6_addr = 0;
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate %}
577c478bd9Sstevel@tonic-gate 
587c478bd9Sstevel@tonic-gate %union	{
597c478bd9Sstevel@tonic-gate 	char	*str;
607c478bd9Sstevel@tonic-gate 	u_32_t	num;
617c478bd9Sstevel@tonic-gate 	struct	in_addr	addr;
627c478bd9Sstevel@tonic-gate 	struct	alist_s	*alist;
637663b816Sml 	union   i6addr	adrmsk[2];
647c478bd9Sstevel@tonic-gate 	iphtent_t	*ipe;
657c478bd9Sstevel@tonic-gate 	ip_pool_node_t	*ipp;
667c478bd9Sstevel@tonic-gate 	union	i6addr	ip6;
677c478bd9Sstevel@tonic-gate }
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate %token  <num>   YY_NUMBER YY_HEX
707c478bd9Sstevel@tonic-gate %token  <str>   YY_STR
71*2a8bcb4eSToomas Soome %token	  YY_COMMENT
727c478bd9Sstevel@tonic-gate %token	  YY_CMP_EQ YY_CMP_NE YY_CMP_LE YY_CMP_GE YY_CMP_LT YY_CMP_GT
737c478bd9Sstevel@tonic-gate %token	  YY_RANGE_OUT YY_RANGE_IN
747c478bd9Sstevel@tonic-gate %token  <ip6>   YY_IPV6
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate %token	IPT_IPF IPT_NAT IPT_COUNT IPT_AUTH IPT_IN IPT_OUT
777c478bd9Sstevel@tonic-gate %token	IPT_TABLE IPT_GROUPMAP IPT_HASH
787c478bd9Sstevel@tonic-gate %token	IPT_ROLE IPT_TYPE IPT_TREE
797c478bd9Sstevel@tonic-gate %token	IPT_GROUP IPT_SIZE IPT_SEED IPT_NUM IPT_NAME
807c478bd9Sstevel@tonic-gate %type	<num> role table inout
817c478bd9Sstevel@tonic-gate %type	<ipp> ipftree range addrlist
827c478bd9Sstevel@tonic-gate %type	<adrmsk> addrmask
837c478bd9Sstevel@tonic-gate %type	<ipe> ipfgroup ipfhash hashlist hashentry
847c478bd9Sstevel@tonic-gate %type	<ipe> groupentry setgrouplist grouplist
857663b816Sml %type	<ip6> ipaddr mask ipv4
867c478bd9Sstevel@tonic-gate %type	<str> number setgroup
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate %%
897c478bd9Sstevel@tonic-gate file:	line
907c478bd9Sstevel@tonic-gate 	| assign
917c478bd9Sstevel@tonic-gate 	| file line
927c478bd9Sstevel@tonic-gate 	| file assign
937c478bd9Sstevel@tonic-gate 	;
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate line:	table role ipftree eol		{ iplo.ipo_unit = $2;
967c478bd9Sstevel@tonic-gate 					  iplo.ipo_list = $3;
977c478bd9Sstevel@tonic-gate 					  load_pool(&iplo, poolioctl);
987c478bd9Sstevel@tonic-gate 					  resetlexer();
997c478bd9Sstevel@tonic-gate 					}
1007c478bd9Sstevel@tonic-gate 	| table role ipfhash eol	{ ipht.iph_unit = $2;
1017c478bd9Sstevel@tonic-gate 					  ipht.iph_type = IPHASH_LOOKUP;
1027c478bd9Sstevel@tonic-gate 					  load_hash(&ipht, $3, poolioctl);
1037c478bd9Sstevel@tonic-gate 					  resetlexer();
1047c478bd9Sstevel@tonic-gate 					}
1057c478bd9Sstevel@tonic-gate 	| groupmap role number ipfgroup eol
1067c478bd9Sstevel@tonic-gate 					{ ipht.iph_unit = $2;
1077c478bd9Sstevel@tonic-gate 					  strncpy(ipht.iph_name, $3,
1087c478bd9Sstevel@tonic-gate 						  sizeof(ipht.iph_name));
1097c478bd9Sstevel@tonic-gate 					  ipht.iph_type = IPHASH_GROUPMAP;
1107c478bd9Sstevel@tonic-gate 					  load_hash(&ipht, $4, poolioctl);
1117c478bd9Sstevel@tonic-gate 					  resetlexer();
1127c478bd9Sstevel@tonic-gate 					}
1137c478bd9Sstevel@tonic-gate 	| YY_COMMENT
1147c478bd9Sstevel@tonic-gate 	;
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate eol:	';'
1177c478bd9Sstevel@tonic-gate 	;
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate assign:	YY_STR assigning YY_STR ';'	{ set_variable($1, $3);
1207c478bd9Sstevel@tonic-gate 					  resetlexer();
1217c478bd9Sstevel@tonic-gate 					  free($1);
1227c478bd9Sstevel@tonic-gate 					  free($3);
1237c478bd9Sstevel@tonic-gate 					}
1247c478bd9Sstevel@tonic-gate 	;
1257c478bd9Sstevel@tonic-gate 
1267c478bd9Sstevel@tonic-gate assigning:
1277c478bd9Sstevel@tonic-gate 	'='				{ yyvarnext = 1; }
1287c478bd9Sstevel@tonic-gate 	;
1297c478bd9Sstevel@tonic-gate 
1307c478bd9Sstevel@tonic-gate table:	IPT_TABLE		{ bzero((char *)&ipht, sizeof(ipht));
1317c478bd9Sstevel@tonic-gate 				  bzero((char *)&iphte, sizeof(iphte));
1327c478bd9Sstevel@tonic-gate 				  bzero((char *)&iplo, sizeof(iplo));
1337c478bd9Sstevel@tonic-gate 				  *ipht.iph_name = '\0';
1347c478bd9Sstevel@tonic-gate 				  iplo.ipo_flags = IPHASH_ANON;
1357c478bd9Sstevel@tonic-gate 				  iplo.ipo_name[0] = '\0';
1367c478bd9Sstevel@tonic-gate 				}
1377c478bd9Sstevel@tonic-gate 	;
1387c478bd9Sstevel@tonic-gate 
1397c478bd9Sstevel@tonic-gate groupmap:
1407c478bd9Sstevel@tonic-gate 	IPT_GROUPMAP inout	{ bzero((char *)&ipht, sizeof(ipht));
1417c478bd9Sstevel@tonic-gate 				  bzero((char *)&iphte, sizeof(iphte));
1427c478bd9Sstevel@tonic-gate 				  *ipht.iph_name = '\0';
1437c478bd9Sstevel@tonic-gate 				  ipht.iph_unit = IPHASH_GROUPMAP;
1447c478bd9Sstevel@tonic-gate 				  ipht.iph_flags = $2;
1457c478bd9Sstevel@tonic-gate 				}
1467c478bd9Sstevel@tonic-gate 	;
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate inout:	IPT_IN				{ $$ = FR_INQUE; }
1497c478bd9Sstevel@tonic-gate 	| IPT_OUT			{ $$ = FR_OUTQUE; }
1507c478bd9Sstevel@tonic-gate 	;
1517c478bd9Sstevel@tonic-gate role:
1527c478bd9Sstevel@tonic-gate 	IPT_ROLE '=' IPT_IPF		{ $$ = IPL_LOGIPF; }
1537c478bd9Sstevel@tonic-gate 	| IPT_ROLE '=' IPT_NAT		{ $$ = IPL_LOGNAT; }
1547c478bd9Sstevel@tonic-gate 	| IPT_ROLE '=' IPT_AUTH		{ $$ = IPL_LOGAUTH; }
1557c478bd9Sstevel@tonic-gate 	| IPT_ROLE '=' IPT_COUNT	{ $$ = IPL_LOGCOUNT; }
1567c478bd9Sstevel@tonic-gate 	;
1577c478bd9Sstevel@tonic-gate 
1587c478bd9Sstevel@tonic-gate ipftree:
159ab25eeb5Syz 	IPT_TYPE '=' IPT_TREE number start addrlist end
1607c478bd9Sstevel@tonic-gate 					{ strncpy(iplo.ipo_name, $4,
1617c478bd9Sstevel@tonic-gate 						  sizeof(iplo.ipo_name));
162ab25eeb5Syz 					  $$ = $6;
1637c478bd9Sstevel@tonic-gate 					}
1647c478bd9Sstevel@tonic-gate 	;
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate ipfhash:
167ab25eeb5Syz 	IPT_TYPE '=' IPT_HASH number hashopts start hashlist end
1687c478bd9Sstevel@tonic-gate 					{ strncpy(ipht.iph_name, $4,
1697c478bd9Sstevel@tonic-gate 						  sizeof(ipht.iph_name));
170ab25eeb5Syz 					  $$ = $7;
1717c478bd9Sstevel@tonic-gate 					}
1727c478bd9Sstevel@tonic-gate 	;
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate ipfgroup:
175ab25eeb5Syz 	setgroup hashopts start grouplist end
1767c478bd9Sstevel@tonic-gate 					{ iphtent_t *e;
1777c478bd9Sstevel@tonic-gate 					  for (e = $4; e != NULL;
1787c478bd9Sstevel@tonic-gate 					       e = e->ipe_next)
1797c478bd9Sstevel@tonic-gate 						if (e->ipe_group[0] == '\0')
1807c478bd9Sstevel@tonic-gate 							strncpy(e->ipe_group,
1817c478bd9Sstevel@tonic-gate 								$1,
1827c478bd9Sstevel@tonic-gate 								FR_GROUPLEN);
1837c478bd9Sstevel@tonic-gate 					  $$ = $4;
1847c478bd9Sstevel@tonic-gate 					}
185ab25eeb5Syz 	| hashopts start setgrouplist end		{ $$ = $3; }
1867c478bd9Sstevel@tonic-gate 	;
1877c478bd9Sstevel@tonic-gate 
188ab25eeb5Syz number:	IPT_NUM '=' YY_NUMBER			{ snprintf(poolname, FR_GROUPLEN, "%u", $3);
1897c478bd9Sstevel@tonic-gate 						  $$ = poolname;
1907c478bd9Sstevel@tonic-gate 						}
1917c478bd9Sstevel@tonic-gate 	| IPT_NAME '=' YY_STR			{ $$ = $3; }
1927c478bd9Sstevel@tonic-gate 	|					{ $$ = ""; }
1937c478bd9Sstevel@tonic-gate 	;
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate setgroup:
1967c478bd9Sstevel@tonic-gate 	IPT_GROUP '=' YY_STR		{ char tmp[FR_GROUPLEN+1];
1977c478bd9Sstevel@tonic-gate 					  strncpy(tmp, $3, FR_GROUPLEN);
1987c478bd9Sstevel@tonic-gate 					  $$ = strdup(tmp);
1997c478bd9Sstevel@tonic-gate 					}
2007c478bd9Sstevel@tonic-gate 	| IPT_GROUP '=' YY_NUMBER	{ char tmp[FR_GROUPLEN+1];
201ab25eeb5Syz 					  snprintf(tmp, FR_GROUPLEN, "%u", $3);
2027c478bd9Sstevel@tonic-gate 					  $$ = strdup(tmp);
2037c478bd9Sstevel@tonic-gate 					}
2047c478bd9Sstevel@tonic-gate 	;
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate hashopts:
2077c478bd9Sstevel@tonic-gate 	| size
2087c478bd9Sstevel@tonic-gate 	| seed
2097c478bd9Sstevel@tonic-gate 	| size seed
2107c478bd9Sstevel@tonic-gate 	;
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate addrlist:
213ab25eeb5Syz 	';'				{ $$ = NULL; }
214f30f5fa1Sjojemann 	| range next addrlist		{ $1->ipn_next = $3; $$ = $1; }
21519adb7feSjojemann 	| range next			{ $$ = $1; }
216ab25eeb5Syz 	| range
2177c478bd9Sstevel@tonic-gate 	;
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate grouplist:
220ab25eeb5Syz 	';'				{ $$ = NULL; }
221ab25eeb5Syz 	| groupentry next grouplist	{ $$ = $1; $1->ipe_next = $3; }
2227663b816Sml 	| addrmask next grouplist	{ $$ = calloc(1, sizeof(iphtent_t));
2235e985db5Sschuster 					  if ($$ == NULL)
2245e985db5Sschuster 						yyerror("sorry, out of memory");
2257663b816Sml 					  if  (set_ipv6_addr)
2267663b816Sml 					  	$$->ipe_family = AF_INET6;
2277663b816Sml 					  else
2287663b816Sml 						$$->ipe_family = AF_INET;
2297c478bd9Sstevel@tonic-gate 					  bcopy((char *)&($1[0]),
2307c478bd9Sstevel@tonic-gate 						(char *)&($$->ipe_addr),
2317c478bd9Sstevel@tonic-gate 						sizeof($$->ipe_addr));
2327c478bd9Sstevel@tonic-gate 					  bcopy((char *)&($1[1]),
2337c478bd9Sstevel@tonic-gate 						(char *)&($$->ipe_mask),
2347c478bd9Sstevel@tonic-gate 						sizeof($$->ipe_mask));
2357663b816Sml 					  set_ipv6_addr = 0;
236ab25eeb5Syz 					  $$->ipe_next = $3;
237ab25eeb5Syz 					}
2387663b816Sml 	| groupentry next		{ $$ = $1; }
2397663b816Sml 	| addrmask next			{ $$ = calloc(1, sizeof(iphtent_t));
2405e985db5Sschuster 					  if ($$ == NULL)
2415e985db5Sschuster 						yyerror("sorry, out of memory");
2427663b816Sml 					  if  (set_ipv6_addr)
2437663b816Sml 					  	$$->ipe_family = AF_INET6;
2447663b816Sml 					  else
2457663b816Sml 						$$->ipe_family = AF_INET;
2467c478bd9Sstevel@tonic-gate 					  bcopy((char *)&($1[0]),
2477c478bd9Sstevel@tonic-gate 						(char *)&($$->ipe_addr),
2487c478bd9Sstevel@tonic-gate 						sizeof($$->ipe_addr));
2497c478bd9Sstevel@tonic-gate 					  bcopy((char *)&($1[1]),
2507c478bd9Sstevel@tonic-gate 						(char *)&($$->ipe_mask),
2517c478bd9Sstevel@tonic-gate 						sizeof($$->ipe_mask));
2527663b816Sml 					  set_ipv6_addr = 0;
2537c478bd9Sstevel@tonic-gate 					}
2547c478bd9Sstevel@tonic-gate 	;
2557c478bd9Sstevel@tonic-gate 
2567c478bd9Sstevel@tonic-gate setgrouplist:
257ab25eeb5Syz 	';'				{ $$ = NULL; }
258ab25eeb5Syz 	| groupentry next		{ $$ = $1; }
2597663b816Sml 	| groupentry next setgrouplist	{ $1->ipe_next = $3; $$ = $1; }
2607c478bd9Sstevel@tonic-gate 	;
2617c478bd9Sstevel@tonic-gate 
2627c478bd9Sstevel@tonic-gate groupentry:
263ab25eeb5Syz 	addrmask ',' setgroup		{ $$ = calloc(1, sizeof(iphtent_t));
264ab25eeb5Syz 					  if ($$ == NULL)
265ab25eeb5Syz 						yyerror("sorry, out of memory");
266ab25eeb5Syz 					  if  (set_ipv6_addr)
267ab25eeb5Syz 					  	$$->ipe_family = AF_INET6;
268ab25eeb5Syz 					  else
269ab25eeb5Syz 						$$->ipe_family = AF_INET;
270ab25eeb5Syz 					  bcopy((char *)&($1[0]),
271ab25eeb5Syz 						(char *)&($$->ipe_addr),
272ab25eeb5Syz 						sizeof($$->ipe_addr));
273ab25eeb5Syz 					  bcopy((char *)&($1[1]),
274ab25eeb5Syz 						(char *)&($$->ipe_mask),
275ab25eeb5Syz 						sizeof($$->ipe_mask));
276ab25eeb5Syz 					  set_ipv6_addr = 0;
277ab25eeb5Syz 					  strncpy($$->ipe_group, $3,
278ab25eeb5Syz 						  FR_GROUPLEN);
279ab25eeb5Syz 					  free($3);
280ab25eeb5Syz 					}
2817c478bd9Sstevel@tonic-gate 	;
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate range:	addrmask	{ $$ = calloc(1, sizeof(*$$));
2845e985db5Sschuster 			  if ($$ == NULL)
2855e985db5Sschuster 				yyerror("sorry, out of memory");
2867c478bd9Sstevel@tonic-gate 			  $$->ipn_info = 0;
287ab25eeb5Syz 			  $$->ipn_addr.adf_len = sizeof($$->ipn_addr);
288ab25eeb5Syz 			  $$->ipn_mask.adf_len = sizeof($$->ipn_mask);
2897663b816Sml 			  if (set_ipv6_addr) {
2907663b816Sml 				  $$->ipn_addr.adf_family = AF_INET6;
2917663b816Sml 				  $$->ipn_addr.adf_addr = $1[0];
2927663b816Sml 				  $$->ipn_mask.adf_addr = $1[1];
2937663b816Sml 
2947663b816Sml 			  } else {
2957663b816Sml 				  $$->ipn_addr.adf_family = AF_INET;
2967663b816Sml 				  $$->ipn_addr.adf_addr.in4.s_addr = $1[0].in4.s_addr;
2977663b816Sml 				  $$->ipn_mask.adf_addr.in4.s_addr = $1[1].in4.s_addr;
2987663b816Sml 			  }
2997663b816Sml 			  set_ipv6_addr = 0;
3007c478bd9Sstevel@tonic-gate 			}
3017c478bd9Sstevel@tonic-gate 	| '!' addrmask	{ $$ = calloc(1, sizeof(*$$));
3025e985db5Sschuster 			  if ($$ == NULL)
3035e985db5Sschuster 				yyerror("sorry, out of memory");
3047c478bd9Sstevel@tonic-gate 			  $$->ipn_info = 1;
305ab25eeb5Syz 			  $$->ipn_addr.adf_len = sizeof($$->ipn_addr);
306ab25eeb5Syz 			  $$->ipn_mask.adf_len = sizeof($$->ipn_mask);
3077663b816Sml 			  if (set_ipv6_addr) {
3087663b816Sml 				  $$->ipn_addr.adf_family = AF_INET6;
3097663b816Sml 				  $$->ipn_addr.adf_addr = $2[0];
3107663b816Sml 				  $$->ipn_mask.adf_addr = $2[1];
3117663b816Sml 			  } else {
3127663b816Sml 				  $$->ipn_addr.adf_family = AF_INET;
3137663b816Sml 				  $$->ipn_addr.adf_addr.in4.s_addr = $2[0].in4.s_addr;
3147663b816Sml 				  $$->ipn_mask.adf_addr.in4.s_addr = $2[1].in4.s_addr;
3157663b816Sml 			  }
3167663b816Sml 			  set_ipv6_addr = 0;
3177c478bd9Sstevel@tonic-gate 			}
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate hashlist:
320ab25eeb5Syz 	';'				{ $$ = NULL; }
321ab25eeb5Syz 	| hashentry next		{ $$ = $1; }
3227663b816Sml 	| hashentry next hashlist	{ $1->ipe_next = $3; $$ = $1; }
3237c478bd9Sstevel@tonic-gate 	;
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate hashentry:
326ab25eeb5Syz 	addrmask			{ $$ = calloc(1, sizeof(iphtent_t));
3275e985db5Sschuster 					  if ($$ == NULL)
3285e985db5Sschuster 						yyerror("sorry, out of memory");
3297663b816Sml 					  if  (set_ipv6_addr)
3307663b816Sml 					  	$$->ipe_family = AF_INET6;
3317663b816Sml 					  else
3327663b816Sml 						$$->ipe_family = AF_INET;
3337c478bd9Sstevel@tonic-gate 					  bcopy((char *)&($1[0]),
3347c478bd9Sstevel@tonic-gate 						(char *)&($$->ipe_addr),
3357c478bd9Sstevel@tonic-gate 						sizeof($$->ipe_addr));
3367c478bd9Sstevel@tonic-gate 					  bcopy((char *)&($1[1]),
3377c478bd9Sstevel@tonic-gate 						(char *)&($$->ipe_mask),
3387c478bd9Sstevel@tonic-gate 						sizeof($$->ipe_mask));
3397c478bd9Sstevel@tonic-gate 					}
3407c478bd9Sstevel@tonic-gate 	;
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate addrmask:
343ab25eeb5Syz 	ipaddr '/' mask		{ $$[0] = $1; $$[1] = $3;
344ab25eeb5Syz 				  yyexpectaddr = 0;
345ab25eeb5Syz 				}
346*2a8bcb4eSToomas Soome 	| ipaddr		{ $$[0] = $1;
347ab25eeb5Syz 				  yyexpectaddr = 0;
348*2a8bcb4eSToomas Soome 				  if (set_ipv6_addr)
3497663b816Sml 				  	fill6bits(128, (u_32_t *)$$[1].in6.s6_addr);
3507663b816Sml 				  else
351ab25eeb5Syz 				  	$$[1].in4.s_addr = 0xffffffff;
352ab25eeb5Syz 				}
3537c478bd9Sstevel@tonic-gate 	;
3547c478bd9Sstevel@tonic-gate 
3557c478bd9Sstevel@tonic-gate ipaddr:	ipv4			{ $$ = $1; }
3567663b816Sml 	| YY_NUMBER		{ $$.in4.s_addr = htonl($1); }
357ab25eeb5Syz 	| YY_IPV6		{ set_ipv6_addr = 1;
3587663b816Sml 				  bcopy(&$1, &$$, sizeof($$));
3597663b816Sml 				  yyexpectaddr = 0; }
3609b4c7145Sjojemann 	| YY_STR		{ if (gethost($1, &$$, 0) == -1)
361ab25eeb5Syz 					yyerror("Unknown hostname");
362ab25eeb5Syz 				}
3637c478bd9Sstevel@tonic-gate 	;
3647c478bd9Sstevel@tonic-gate 
3657663b816Sml mask:	YY_NUMBER		{ if (set_ipv6_addr)
366ab25eeb5Syz 					ntomask(6, $1, (u_32_t *)$$.in6.s6_addr);
3677663b816Sml 				  else
368ab25eeb5Syz 				  	ntomask(4, $1, (u_32_t *)&$$.in4.s_addr); }
3697c478bd9Sstevel@tonic-gate 	| ipv4			{ $$ = $1; }
3707c478bd9Sstevel@tonic-gate 	;
3717c478bd9Sstevel@tonic-gate 
372ab25eeb5Syz start:	'{'			{ yyexpectaddr = 1; }
373ab25eeb5Syz 	;
374ab25eeb5Syz 
375ab25eeb5Syz end:	'}'			{ yyexpectaddr = 0; }
376ab25eeb5Syz 	;
377ab25eeb5Syz 
378ab25eeb5Syz next:	','			{ yyexpectaddr = 1; }
379ab25eeb5Syz 	| ';'			{ yyexpectaddr = 1; }
380ab25eeb5Syz 	;
381ab25eeb5Syz 
3827c478bd9Sstevel@tonic-gate size:	IPT_SIZE '=' YY_NUMBER	{ ipht.iph_size = $3; }
3837c478bd9Sstevel@tonic-gate 	;
3847c478bd9Sstevel@tonic-gate 
3857c478bd9Sstevel@tonic-gate seed:	IPT_SEED '=' YY_NUMBER	{ ipht.iph_seed = $3; }
3867c478bd9Sstevel@tonic-gate 	;
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate ipv4:	YY_NUMBER '.' YY_NUMBER '.' YY_NUMBER '.' YY_NUMBER
3897c478bd9Sstevel@tonic-gate 		{ if ($1 > 255 || $3 > 255 || $5 > 255 || $7 > 255) {
3907c478bd9Sstevel@tonic-gate 			yyerror("Invalid octet string for IP address");
3917c478bd9Sstevel@tonic-gate 			return 0;
3927c478bd9Sstevel@tonic-gate 		  }
3937663b816Sml 		  $$.in4.s_addr = ($1 << 24) | ($3 << 16) | ($5 << 8) | $7;
3947663b816Sml 		  $$.in4.s_addr = htonl($$.in4.s_addr);
3957c478bd9Sstevel@tonic-gate 		}
3967c478bd9Sstevel@tonic-gate 	;
3977c478bd9Sstevel@tonic-gate %%
3987c478bd9Sstevel@tonic-gate static	wordtab_t	yywords[] = {
3997c478bd9Sstevel@tonic-gate 	{ "auth",	IPT_AUTH },
4007c478bd9Sstevel@tonic-gate 	{ "count",	IPT_COUNT },
4017c478bd9Sstevel@tonic-gate 	{ "group",	IPT_GROUP },
4027c478bd9Sstevel@tonic-gate 	{ "group-map",	IPT_GROUPMAP },
4037c478bd9Sstevel@tonic-gate 	{ "hash",	IPT_HASH },
4047c478bd9Sstevel@tonic-gate 	{ "in",		IPT_IN },
4057c478bd9Sstevel@tonic-gate 	{ "ipf",	IPT_IPF },
4067c478bd9Sstevel@tonic-gate 	{ "name",	IPT_NAME },
4077c478bd9Sstevel@tonic-gate 	{ "nat",	IPT_NAT },
4087c478bd9Sstevel@tonic-gate 	{ "number",	IPT_NUM },
4097c478bd9Sstevel@tonic-gate 	{ "out",	IPT_OUT },
4107c478bd9Sstevel@tonic-gate 	{ "role",	IPT_ROLE },
4117c478bd9Sstevel@tonic-gate 	{ "seed",	IPT_SEED },
4127c478bd9Sstevel@tonic-gate 	{ "size",	IPT_SIZE },
4137c478bd9Sstevel@tonic-gate 	{ "table",	IPT_TABLE },
4147c478bd9Sstevel@tonic-gate 	{ "tree",	IPT_TREE },
4157c478bd9Sstevel@tonic-gate 	{ "type",	IPT_TYPE },
4167c478bd9Sstevel@tonic-gate 	{ NULL,		0 }
4177c478bd9Sstevel@tonic-gate };
4187c478bd9Sstevel@tonic-gate 
4197c478bd9Sstevel@tonic-gate 
ippool_parsefile(fd,filename,iocfunc)4207c478bd9Sstevel@tonic-gate int ippool_parsefile(fd, filename, iocfunc)
4217c478bd9Sstevel@tonic-gate int fd;
4227c478bd9Sstevel@tonic-gate char *filename;
4237c478bd9Sstevel@tonic-gate ioctlfunc_t iocfunc;
4247c478bd9Sstevel@tonic-gate {
4257c478bd9Sstevel@tonic-gate 	FILE *fp = NULL;
4267c478bd9Sstevel@tonic-gate 	char *s;
4277c478bd9Sstevel@tonic-gate 
4287c478bd9Sstevel@tonic-gate 	yylineNum = 1;
4297c478bd9Sstevel@tonic-gate 	(void) yysettab(yywords);
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate 	s = getenv("YYDEBUG");
4327c478bd9Sstevel@tonic-gate 	if (s)
4337c478bd9Sstevel@tonic-gate 		yydebug = atoi(s);
4347c478bd9Sstevel@tonic-gate 	else
4357c478bd9Sstevel@tonic-gate 		yydebug = 0;
4367c478bd9Sstevel@tonic-gate 
4377c478bd9Sstevel@tonic-gate 	if (strcmp(filename, "-")) {
4387c478bd9Sstevel@tonic-gate 		fp = fopen(filename, "r");
4397c478bd9Sstevel@tonic-gate 		if (!fp) {
4407c478bd9Sstevel@tonic-gate 			fprintf(stderr, "fopen(%s) failed: %s\n", filename,
4417c478bd9Sstevel@tonic-gate 				STRERROR(errno));
4427c478bd9Sstevel@tonic-gate 			return -1;
4437c478bd9Sstevel@tonic-gate 		}
4447c478bd9Sstevel@tonic-gate 	} else
4457c478bd9Sstevel@tonic-gate 		fp = stdin;
4467c478bd9Sstevel@tonic-gate 
4477c478bd9Sstevel@tonic-gate 	while (ippool_parsesome(fd, fp, iocfunc) == 1)
4487c478bd9Sstevel@tonic-gate 		;
4497c478bd9Sstevel@tonic-gate 	if (fp != NULL)
4507c478bd9Sstevel@tonic-gate 		fclose(fp);
4517c478bd9Sstevel@tonic-gate 	return 0;
4527c478bd9Sstevel@tonic-gate }
4537c478bd9Sstevel@tonic-gate 
4547c478bd9Sstevel@tonic-gate 
ippool_parsesome(fd,fp,iocfunc)4557c478bd9Sstevel@tonic-gate int ippool_parsesome(fd, fp, iocfunc)
4567c478bd9Sstevel@tonic-gate int fd;
4577c478bd9Sstevel@tonic-gate FILE *fp;
4587c478bd9Sstevel@tonic-gate ioctlfunc_t iocfunc;
4597c478bd9Sstevel@tonic-gate {
4607c478bd9Sstevel@tonic-gate 	char *s;
4617c478bd9Sstevel@tonic-gate 	int i;
4627c478bd9Sstevel@tonic-gate 
4637c478bd9Sstevel@tonic-gate 	poolioctl = iocfunc;
4647c478bd9Sstevel@tonic-gate 
4657c478bd9Sstevel@tonic-gate 	if (feof(fp))
4667c478bd9Sstevel@tonic-gate 		return 0;
4677c478bd9Sstevel@tonic-gate 	i = fgetc(fp);
4687c478bd9Sstevel@tonic-gate 	if (i == EOF)
4697c478bd9Sstevel@tonic-gate 		return 0;
4707c478bd9Sstevel@tonic-gate 	if (ungetc(i, fp) == EOF)
4717c478bd9Sstevel@tonic-gate 		return 0;
4727c478bd9Sstevel@tonic-gate 	if (feof(fp))
4737c478bd9Sstevel@tonic-gate 		return 0;
4747c478bd9Sstevel@tonic-gate 	s = getenv("YYDEBUG");
4757c478bd9Sstevel@tonic-gate 	if (s)
4767c478bd9Sstevel@tonic-gate 		yydebug = atoi(s);
4777c478bd9Sstevel@tonic-gate 	else
4787c478bd9Sstevel@tonic-gate 		yydebug = 0;
4797c478bd9Sstevel@tonic-gate 
4807c478bd9Sstevel@tonic-gate 	yyin = fp;
4817c478bd9Sstevel@tonic-gate 	yyparse();
4827c478bd9Sstevel@tonic-gate 	return 1;
4837c478bd9Sstevel@tonic-gate }
484