Initial import from FreeBSD RELENG_4:
[dragonfly.git] / usr.sbin / atm / scspd / scsp_config_parse.y
1 %{
2 /*
3  *
4  * ===================================
5  * HARP  |  Host ATM Research Platform
6  * ===================================
7  *
8  *
9  * This Host ATM Research Platform ("HARP") file (the "Software") is
10  * made available by Network Computing Services, Inc. ("NetworkCS")
11  * "AS IS".  NetworkCS does not provide maintenance, improvements or
12  * support of any kind.
13  *
14  * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
15  * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
16  * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
17  * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
18  * In no event shall NetworkCS be responsible for any damages, including
19  * but not limited to consequential damages, arising from or relating to
20  * any use of the Software or related support.
21  *
22  * Copyright 1994-1998 Network Computing Services, Inc.
23  *
24  * Copies of this Software may be made, however, the above copyright
25  * notice must be reproduced on all copies.
26  *
27  *      @(#) $FreeBSD: src/usr.sbin/atm/scspd/scsp_config_parse.y,v 1.3 1999/08/28 01:15:32 peter Exp $
28  *
29  */
30
31
32 /*
33  * Server Cache Synchronization Protocol (SCSP) Support
34  * ----------------------------------------------------
35  *
36  * YACC input for configuration file processing
37  *
38  */
39
40 #include <sys/types.h>
41 #include <sys/param.h>
42 #include <sys/socket.h>
43 #include <net/if.h>
44 #include <netinet/in.h>
45 #include <netatm/port.h> 
46 #include <netatm/queue.h> 
47 #include <netatm/atm.h>
48 #include <netatm/atm_if.h>
49 #include <netatm/atm_sap.h>
50 #include <netatm/atm_sys.h>
51 #include <netatm/atm_ioctl.h>
52
53 #include <libatm.h>
54 #if __STDC__
55 #include <stdarg.h>
56 #else
57 #include <varargs.h>
58 #endif
59 #include <stdio.h>
60 #include <stdlib.h>
61 #include <string.h>
62 #include <syslog.h>
63
64 #include "scsp_msg.h"
65 #include "scsp_if.h"
66 #include "scsp_var.h"
67
68 #ifndef lint
69 __RCSID("@(#) $FreeBSD: src/usr.sbin/atm/scspd/scsp_config_parse.y,v 1.3 1999/08/28 01:15:32 peter Exp $");
70 #endif
71
72
73 void    yyerror __P((char *));
74 %}
75
76
77 /*
78  * Token value definition
79  */
80 %union {
81         char            *tv_alpha;
82         int             tv_int;
83         char            *tv_hex;
84 }
85
86
87 /*
88  * Token types returned by scanner
89  */
90 %token  <tv_alpha>      TOK_NAME
91 %token  <tv_int>        TOK_INTEGER
92 %token  <tv_hex>        TOK_HEX
93
94 /*
95  * Reserved words
96  */
97 %token                  TOK_ATMARP
98 %token                  TOK_DCS
99 %token                  TOK_DCS_ADDR
100 %token                  TOK_DCS_CA_REXMIT_INT
101 %token                  TOK_DCS_CSUS_REXMIT_INT
102 %token                  TOK_DCS_CSU_REXMIT_INT
103 %token                  TOK_DCS_CSU_REXMIT_MAX
104 %token                  TOK_DCS_HELLO_DF
105 %token                  TOK_DCS_HELLO_INT
106 %token                  TOK_DCS_HOP_CNT
107 %token                  TOK_DCS_ID
108 %token                  TOK_DHCP
109 %token                  TOK_FAMILY
110 %token                  TOK_LFN
111 %token                  TOK_LNNI
112 %token                  TOK_LOG
113 %token                  TOK_MARS
114 %token                  TOK_NETIF
115 %token                  TOK_NHRP
116 %token                  TOK_PROTOCOL
117 %token                  TOK_SERVER
118 %token                  TOK_SRVGRP
119 %token                  TOK_SYSLOG
120
121
122 %%
123 cfg_file: /* Empty */
124         | stmt_seq
125
126 stmt_seq: stmt
127         | stmt_seq stmt
128         ;
129
130 stmt:   server_stmt ';'
131         | log_stmt ';'
132         ;
133
134 /*
135  * SCSP server definition statements
136  */
137 server_stmt: TOK_SERVER TOK_NAME
138         {
139                 int     rc;
140
141                 rc = start_server($2);
142                 UM_FREE($2);
143                 if (rc)
144                         return(rc);
145         }
146         '{' server_def '}'
147         {
148                 int     rc;
149
150                 rc = finish_server();
151                 if (rc)
152                         return(rc);
153         }
154         ;
155
156 server_def: server_spec ';'
157         | server_def server_spec ';'
158         ;
159
160 server_spec: /* Nothing */
161         | dcs_stmt
162         | TOK_NETIF TOK_NAME
163         {
164                 int     rc;
165
166                 /*
167                  * Configure the network interface
168                  */
169                 rc = set_intf($2);
170                 UM_FREE($2);
171                 if (rc)
172                         return(rc);
173         }
174         | TOK_PROTOCOL TOK_ATMARP
175         {
176                 int     rc;
177
178                 /*
179                  * Configure the protocol
180                  */
181                 rc = set_protocol(SCSP_PROTO_ATMARP);
182                 if (rc)
183                         return(rc);
184         }
185         | TOK_PROTOCOL TOK_DHCP | TOK_LNNI | TOK_MARS | TOK_NHRP
186         {
187                 yyerror("Protocol not implemented");
188                 return(1);
189         }
190         | TOK_SRVGRP TOK_INTEGER
191         {
192                 int     rc;
193
194                 /*
195                  * Configure the SCSP server group ID
196                  */
197                 rc = set_server_group($2);
198                 if (rc)
199                         return(rc);
200         }
201         ;
202
203 /*
204  * SCSP DCS definition statements
205  */
206 dcs_stmt: TOK_DCS 
207         {
208                 int     rc;
209
210                 rc = start_dcs();
211                 if (rc)
212                         return(rc);
213         }
214         '{' dcs_def '}'
215         {
216                 int     rc;
217
218                 rc = finish_dcs();
219                 if (rc)
220                         return(rc);
221         }
222         ;
223
224 dcs_def: dcs_spec ';'
225         | dcs_def dcs_spec ';'
226         ;
227
228 dcs_spec: /* Nothing */
229         | TOK_DCS_ADDR TOK_HEX
230         {
231                 int     rc;
232
233                 /*
234                  * Set DCS address
235                  */
236                 rc = set_dcs_addr($2, (char *)0);
237                 UM_FREE($2);
238                 if (rc)
239                         return(rc);
240         }
241         | TOK_DCS_ADDR TOK_HEX TOK_HEX
242         {
243                 int     rc;
244
245                 /*
246                  * Set DCS address and subaddress
247                  */
248                 rc = set_dcs_addr($2, $3);
249                 UM_FREE($2);
250                 UM_FREE($3);
251                 if (rc)
252                         return(rc);
253         }
254         | TOK_DCS_CA_REXMIT_INT TOK_INTEGER
255         {
256                 int     rc;
257
258                 /*
259                  * Configure the CA retransmit interval
260                  */
261                 rc = set_dcs_ca_rexmit($2);
262                 if (rc)
263                         return(rc);
264         }
265         | TOK_DCS_CSUS_REXMIT_INT TOK_INTEGER
266         {
267                 int     rc;
268
269                 /*
270                  * Configure the CSUS retransmit interval
271                  */
272                 rc = set_dcs_csus_rexmit($2);
273                 if (rc)
274                         return(rc);
275         }
276         | TOK_DCS_CSU_REXMIT_INT TOK_INTEGER
277         {
278                 int     rc;
279
280                 /*
281                  * Configure the CSU retransmit interval
282                  */
283                 rc = set_dcs_csu_rexmit($2);
284                 if (rc)
285                         return(rc);
286         }
287         | TOK_DCS_CSU_REXMIT_MAX TOK_INTEGER
288         {
289                 int     rc;
290
291                 /*
292                  * Configure the CSU retransmit limit
293                  */
294                 rc = set_dcs_csu_rexmit_max($2);
295                 if (rc)
296                         return(rc);
297         }
298         | TOK_DCS_HELLO_DF TOK_INTEGER
299         {
300                 int     rc;
301
302                 /*
303                  * Configure the Hello dead factor
304                  */
305                 rc = set_dcs_hello_df($2);
306                 if (rc)
307                         return(rc);
308         }
309         | TOK_DCS_HELLO_INT TOK_INTEGER
310         {
311                 int     rc;
312
313                 /*
314                  * Configure the Hello interval
315                  */
316                 rc = set_dcs_hello_int($2);
317                 if (rc)
318                         return(rc);
319         }
320         | TOK_DCS_HOP_CNT TOK_INTEGER
321         {
322                 int     rc;
323
324                 /*
325                  * Configure the hop count
326                  */
327                 rc = set_dcs_hops($2);
328                 if (rc)
329                         return(rc);
330         }
331         | TOK_DCS_ID TOK_NAME
332         {
333                 int     rc;
334
335                 /*
336                  * Configure the DCS ID
337                  */
338                 rc = set_dcs_id($2);
339                 UM_FREE($2);
340                 if (rc)
341                         return(rc);
342         }
343         ;
344
345
346 /*
347  * Logging option statements
348  */
349 log_stmt: TOK_LOG
350         '{' log_spec '}'
351         ;
352
353 log_spec: /* Nothing */
354         | TOK_LFN TOK_NAME ';'
355         {
356                 /*
357                  * Configure the log file name
358                  */
359                 int     rc;
360
361                 rc = set_log_file($2);
362                 UM_FREE($2);
363                 if (rc)
364                         return(rc);
365         }
366         ;
367         | TOK_SYSLOG ';'
368         {
369                 /*
370                  * Configure logging to syslog
371                  */
372                 scsp_log_syslog = 1;
373         }
374         ;
375
376 %%
377
378 void
379 #if __STDC__
380 parse_error(const char *fmt, ...)
381 #else
382 parse_error(fmt, va_alist)
383         char    *fmt;
384         va_dcl
385 #endif
386 {
387         va_list ap;
388         char    buff[256];
389
390 #if __STDC__
391         va_start(ap, fmt);
392 #else
393         va_start(ap);
394 #endif
395
396         vsprintf(buff, fmt, ap);
397         scsp_log(LOG_ERR, "%s: Config file error at line %d: %s\n",
398                         prog, parse_line, buff);
399 #ifdef NOTDEF
400         fprintf(stderr, "%s: Config file error at line %d: %s\n",
401                         prog, parse_line, buff);
402 #endif
403         va_end(ap);
404 }
405
406
407 void
408 yyerror(s)
409         char    *s;
410 {
411         parse_error(s);
412 }