1 %{
2 
3 #include "headers.h"
4 #include "cfgy.h"
5 
6 int ipcacfglineno = 1;
7 
8 %}
9 
10 %option never-interactive
11 %option noinput nounput
12 %option noyywrap stack
13 %option caseless 8bit
14 
15 %pointer
16 
17 %x comment
18 %x string
19 %x ifbody
20 %x filename
21 %x rshdef
22 %x nflowdef
23 %x aggr
24 %x cports
25 
26 %%
27 
28 <*>"/*"		yy_push_state(comment);
29 <comment>{
30 	[^*/\n]		/* Eat */
31 	"*/"	yy_pop_state();
32 	\n		ipcacfglineno++;
33 	.	/* Eat */
34 }
35 
36 <*>";"	{ while(YY_START) yy_pop_state(); yy_top_state(); return SEMICOLON; }
37 "="		{ yy_push_state(string); return EQ; }
38 
39 #[^\n]*[\n]?	{
40 		if(yytext[yyleng-1] == '\n')
41 			ipcacfglineno++;
42 	}
43 
44 <INITIAL,rshdef>ttl		{ return TTL; }
45 pidfile		{ return PIDFILE; }
46 
47 interface|iface		{
48 		yy_push_state(ifbody);
49 		return IFACE;
50 	}
51 <filename>{
52 	[^ \r\n\t\f;]+	{
53 		ipcacfglval.tv_char = strdup(yytext);
54 		yy_pop_state();
55 		return TOK_STRING;
56 	}
57 }
58 <ifbody>{
59 	file	yy_push_state(filename); return IFILE;	/* PCAP file */
60 	divert	return DIVERT;	/* BSD's ipfw(8) divert(4) */
61 	tee	return TEE;	/* BSD's ipfw(8), grep tee */
62 	port	return PORT;	/* port for divert(4) and tee. */
63 	ipq	return IPQ;	/* Linux libipq(3) */
64 	ulog	return ULOG;	/* Linux ULOG */
65 	group	return GROUP;	/* ULOG group */
66 	","	return ',';	/* ULOG groups are comma separated */
67 
68 	input[a-z_-]*	return INONLY;
69 	prom[a-z]*		return PROMISC;
70 	netflow-sampled		return NETFLOW_SAMPLED;
71 	netflow-disable		return NETFLOW_DISABLE;
72 	filter		return FILTER;
73 
74 	[a-z]+[_0-9\*]+[:\.][0-9\*]+	{
75 		ipcacfglval.tv_char = strdup(yytext);
76 		return TOK_STRING;
77 	}
78 	[a-z]+[_0-9*]*	{
79 		ipcacfglval.tv_char = strdup(yytext);
80 		return TOK_STRING;
81 	}
82 	[0-9]+	{
83 		ipcacfglval.tv_int = atoi(yytext);
84 		return TOK_INTEGER;
85 	}
86 
87 	\"[^\"]*\"	{
88 		yytext[yyleng-1] = '\0';
89 		ipcacfglval.tv_char = strdup(yytext+1);
90 		return TOK_STRING;
91 	}
92 }
93 
94 rsh|rcmd	{ yy_push_state(rshdef); return RSH; }
95 
96 <rshdef>{
97 	"@"		return AT;
98 	"="		{ yy_push_state(string); return EQ; }
99 	at		return AT;
100 	timeout				{ yy_pop_state(); return TIMEOUT; }
101 
102 	deny|off|disable|no		return DENY;
103 	allow|on|enable|yes		return ALLOW;
104 	view[a-z-]*		return VIEW_ONLY;
105 	default		return DEFAULT;
106 	backup		return BACKUP;
107 	admin		return ADMIN;
108 
109 	[a-z0-9._]+	{
110 		ipcacfglval.tv_char = strdup(yytext);
111 		return TOK_STRING;
112 	}
113 }
114 
115 netflow	{ yy_push_state(nflowdef); return NETFLOW; }
116 <nflowdef>{
117 	export			return EXPORT;
118 	dst|dest[a-z]*		return DESTINATION;
119 	version			return VERSION;
120 	timeout			return TIMEOUT;
121 	active			return ACTIVE;
122 	inactive		return INACTIVE;
123 	sampling-mode		return SAMPLING_MODE;
124 	packet-interval		return PACKET_INTERVAL;
125 	ifclass			return IFCLASS;
126 	engine-type		return ENGINE_TYPE;
127 	engine-id		return ENGINE_ID;
128 	mapto			return MAPTO;
129 	"-"			return	'-';
130 
131 	[0-9]+	{
132 		ipcacfglval.tv_int = atoi(yytext);
133 		return TOK_INTEGER;
134 		}
135 	[a-z0-9._]+	{
136 		ipcacfglval.tv_char = strdup(yytext);
137 		return TOK_STRING;
138 	}
139 }
140 
141 capture-ports	{ yy_push_state(cports); return CAPTURE_PORTS; }
142 <cports>{
143 	deny|off|disable|no	return DENY;
144 	allow|on|enable|yes	return ALLOW;
145 }
146 
147 mem[a-z_-]*		return MEMSIZE;
148 buf[a-z]*		return BUFFERS;
149 chroot		return CHROOT;
150 uid	return UID;
151 gid	return GID;
152 dump[a-z]*	return DUMP;
153 
154 aggr[a-z]*	{ yy_push_state(aggr); return AGGR; }
155 <aggr>{
156 	[0-9.]+	{
157 		ipcacfglval.tv_char = strdup(yytext);
158 		return TOK_STRING;
159 	}
160 	"/"	return SLASH;
161 	"-"	return	'-';
162 	strip	return STRIP;
163 	into	return INTO;
164 }
165 
166 <string>[a-z0-9./-]+	{
167 		ipcacfglval.tv_char = strdup(yytext);
168 		return TOK_STRING;
169 	}
170 
171 <*>[[:space:]]	{
172 		if(*yytext == '\n')
173 			ipcacfglineno++;
174 	}
175 
176 <*>.	{ return ERROR; }
177 
178 <*><<EOF>>	{ yyterminate(); }
179 
180 %%
181