GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.sbin/mrouted/cfparse.c Lines: 0 248 0.0 %
Date: 2017-11-07 Branches: 0 195 0.0 %

Line Branch Exec Source
1
#include <stdlib.h>
2
#include <string.h>
3
#define YYBYACC 1
4
#define YYMAJOR 1
5
#define YYMINOR 9
6
#define YYLEX yylex()
7
#define YYEMPTY -1
8
#define yyclearin (yychar=(YYEMPTY))
9
#define yyerrok (yyerrflag=0)
10
#define YYRECOVERING() (yyerrflag!=0)
11
#define YYPREFIX "yy"
12
#line 2 "cfparse.y"
13
/*	$NetBSD: cfparse.y,v 1.4 1995/12/10 10:06:57 mycroft Exp $	*/
14
15
/*
16
 * Configuration file parser for mrouted.
17
 *
18
 * Written by Bill Fenner, NRL, 1994
19
 * Copyright (c) 1994
20
 * Naval Research Laboratory (NRL/CCS)
21
 *                    and the
22
 * Defense Advanced Research Projects Agency (DARPA)
23
 *
24
 * All Rights Reserved.
25
 *
26
 * Permission to use, copy, modify and distribute this software and its
27
 * documentation is hereby granted, provided that both the copyright notice and
28
 * this permission notice appear in all copies of the software, derivative
29
 * works or modified versions, and any portions thereof, and that both notices
30
 * appear in supporting documentation.
31
 *
32
 * NRL AND DARPA ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION AND
33
 * DISCLAIM ANY LIABILITY OF ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM
34
 * THE USE OF THIS SOFTWARE.
35
 */
36
#include <stdio.h>
37
#include <string.h>
38
#include <stdarg.h>
39
#include "defs.h"
40
#include <netdb.h>
41
#include <ifaddrs.h>
42
43
/*
44
 * Local function declarations
45
 */
46
static void		fatal(const char *fmt, ...)
47
    __attribute__((__format__ (printf, 1, 2)))
48
    __attribute__((__nonnull__ (1)));
49
static void		warn(const char *fmt, ...)
50
    __attribute__((__format__ (printf, 1, 2)))
51
    __attribute__((__nonnull__ (1)));
52
static void		yyerror(char *s);
53
static char *		next_word(void);
54
static int		yylex(void);
55
static u_int32_t	valid_if(char *s);
56
static const char *	ifconfaddr(u_int32_t a);
57
int			yyparse(void);
58
59
static FILE *f;
60
61
extern int udp_socket;
62
char *configfilename = _PATH_MROUTED_CONF;
63
64
extern int cache_lifetime;
65
extern int max_prune_lifetime;
66
67
static int lineno;
68
69
static struct uvif *v;
70
71
static int order;
72
73
struct addrmask {
74
	u_int32_t	addr;
75
	int	mask;
76
};
77
78
struct boundnam {
79
	char		*name;
80
	struct addrmask	 bound;
81
};
82
83
#define MAXBOUNDS 20
84
85
struct boundnam boundlist[MAXBOUNDS];	/* Max. of 20 named boundaries */
86
int numbounds = 0;			/* Number of named boundaries */
87
88
#line 79 "cfparse.y"
89
#ifndef YYSTYPE_DEFINED
90
#define YYSTYPE_DEFINED
91
typedef union
92
{
93
	int num;
94
	char *ptr;
95
	struct addrmask addrmask;
96
	u_int32_t addr;
97
} YYSTYPE;
98
#endif /* YYSTYPE_DEFINED */
99
#line 100 "cfparse.c"
100
#define CACHE_LIFETIME 257
101
#define PRUNING 258
102
#define PHYINT 259
103
#define TUNNEL 260
104
#define NAME 261
105
#define DISABLE 262
106
#define IGMPV1 263
107
#define SRCRT 264
108
#define METRIC 265
109
#define THRESHOLD 266
110
#define RATE_LIMIT 267
111
#define BOUNDARY 268
112
#define NETMASK 269
113
#define ALTNET 270
114
#define BOOLEAN 271
115
#define NUMBER 272
116
#define STRING 273
117
#define ADDRMASK 274
118
#define ADDR 275
119
#define YYERRCODE 256
120
const short yylhs[] =
121
	{                                        -1,
122
    0,    6,    6,    7,    9,    7,   11,    7,    7,    7,
123
    7,   10,   10,   12,   12,    8,    8,   14,   14,   14,
124
   14,   14,   14,   14,   13,   13,   13,   13,   13,   13,
125
   13,   13,    1,    1,    2,    2,    3,    3,    4,    5,
126
    5,
127
};
128
const short yylen[] =
129
	{                                         2,
130
    1,    0,    2,    1,    0,    4,    0,    5,    2,    2,
131
    3,    0,    2,    1,    1,    0,    2,    1,    1,    1,
132
    2,    1,    2,    1,    2,    1,    2,    1,    2,    1,
133
    2,    1,    1,    1,    1,    1,    1,    1,    1,    1,
134
    1,
135
};
136
const short yydefred[] =
137
	{                                      2,
138
    0,    0,    4,    0,    0,    0,    0,    0,    3,   10,
139
    9,   34,   33,    5,    0,    0,   16,   36,   35,    7,
140
   39,   11,    0,   12,   19,   20,    0,    0,    0,    0,
141
    0,    0,   18,   17,    0,   27,   25,   29,   38,   31,
142
   37,   21,   40,   41,   23,   15,   13,   14,
143
};
144
const short yydgoto[] =
145
	{                                       1,
146
   14,   20,   40,   22,   45,    2,    9,   23,   17,   35,
147
   24,   47,   33,   34,
148
};
149
const short yysindex[] =
150
	{                                      0,
151
    0, -239,    0, -272, -267, -250, -250, -241,    0,    0,
152
    0,    0,    0,    0, -249, -240,    0,    0,    0,    0,
153
    0,    0, -260,    0,    0,    0, -237, -236, -235, -246,
154
 -249, -245,    0,    0, -253,    0,    0,    0,    0,    0,
155
    0,    0,    0,    0,    0,    0,    0,    0,};
156
const short yyrindex[] =
157
	{                                      0,
158
    0,   33,    0,    0,    0,    0,    0,    0,    0,    0,
159
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
160
    0,    0,   91,    0,    0,    0,    1,   16,   31,   46,
161
   61,   76,    0,    0,   97,    0,    0,    0,    0,    0,
162
    0,    0,    0,    0,    0,    0,    0,    0,};
163
const short yygindex[] =
164
	{                                      0,
165
   32,    7,    0,   10,    0,    0,    0,    0,    0,    0,
166
    0,    0,    6,    0,
167
};
168
#define YYTABLESIZE 358
169
const short yytable[] =
170
	{                                      10,
171
   28,   25,   26,   11,   27,   28,   29,   30,   31,   32,
172
   46,   27,   28,   29,   30,   26,    3,    4,    5,    6,
173
    7,    8,   12,   18,   13,   19,   39,   21,   43,   44,
174
   30,   16,    1,   21,   36,   37,   38,   42,   15,   41,
175
   48,    0,    0,    0,    0,   32,    0,    0,    0,    0,
176
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
177
   22,    0,    0,    0,    0,    0,    0,    0,    0,    0,
178
    0,    0,    0,    0,    0,   24,    0,    0,    0,    0,
179
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
180
    6,    0,    0,    0,    0,    0,    8,    0,    0,    0,
181
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
182
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
183
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
184
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
185
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
186
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
187
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
188
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
189
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
190
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
191
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
192
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
193
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
194
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
195
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
196
    0,    0,    0,    0,    0,    0,   28,   28,   28,   28,
197
   28,   28,   28,   28,   28,   28,   28,   28,   28,   28,
198
   28,   26,   26,   26,   26,   26,   26,   26,   26,   26,
199
   26,   26,   26,   26,   26,   26,   30,   30,   30,   30,
200
   30,   30,   30,   30,   30,   30,   30,   30,   30,   30,
201
   30,   32,   32,   32,   32,   32,   32,   32,   32,   32,
202
   32,   32,   32,   32,   32,   32,   22,   22,   22,   22,
203
   22,   22,   22,   22,    0,   22,   22,   22,   22,   22,
204
   22,   24,   24,   24,   24,   24,   24,   24,   24,    0,
205
   24,   24,   24,   24,   24,   24,    6,    6,    6,    6,
206
    6,    6,    8,    8,    8,    8,    8,    8,
207
};
208
const short yycheck[] =
209
	{                                     272,
210
    0,  262,  263,  271,  265,  266,  267,  268,  269,  270,
211
  264,  265,  266,  267,  268,    0,  256,  257,  258,  259,
212
  260,  261,  273,  273,  275,  275,  273,  274,  274,  275,
213
    0,  273,    0,  274,  272,  272,  272,   31,    7,   30,
214
   35,   -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,   -1,
215
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
216
    0,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
217
   -1,   -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,   -1,
218
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
219
    0,   -1,   -1,   -1,   -1,   -1,    0,   -1,   -1,   -1,
220
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
221
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
222
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
223
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
224
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
225
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
226
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
227
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
228
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
229
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
230
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
231
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
232
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
233
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
234
   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
235
   -1,   -1,   -1,   -1,   -1,   -1,  256,  257,  258,  259,
236
  260,  261,  262,  263,  264,  265,  266,  267,  268,  269,
237
  270,  256,  257,  258,  259,  260,  261,  262,  263,  264,
238
  265,  266,  267,  268,  269,  270,  256,  257,  258,  259,
239
  260,  261,  262,  263,  264,  265,  266,  267,  268,  269,
240
  270,  256,  257,  258,  259,  260,  261,  262,  263,  264,
241
  265,  266,  267,  268,  269,  270,  256,  257,  258,  259,
242
  260,  261,  262,  263,   -1,  265,  266,  267,  268,  269,
243
  270,  256,  257,  258,  259,  260,  261,  262,  263,   -1,
244
  265,  266,  267,  268,  269,  270,  256,  257,  258,  259,
245
  260,  261,  256,  257,  258,  259,  260,  261,
246
};
247
#define YYFINAL 1
248
#ifndef YYDEBUG
249
#define YYDEBUG 0
250
#endif
251
#define YYMAXTOKEN 275
252
#if YYDEBUG
253
const char * const yyname[] =
254
	{
255
"end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
256
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
257
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
258
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
259
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
260
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
261
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"CACHE_LIFETIME","PRUNING",
262
"PHYINT","TUNNEL","NAME","DISABLE","IGMPV1","SRCRT","METRIC","THRESHOLD",
263
"RATE_LIMIT","BOUNDARY","NETMASK","ALTNET","BOOLEAN","NUMBER","STRING",
264
"ADDRMASK","ADDR",
265
};
266
const char * const yyrule[] =
267
	{"$accept : conf",
268
"conf : stmts",
269
"stmts :",
270
"stmts : stmts stmt",
271
"stmt : error",
272
"$$1 :",
273
"stmt : PHYINT interface $$1 ifmods",
274
"$$2 :",
275
"stmt : TUNNEL interface addrname $$2 tunnelmods",
276
"stmt : PRUNING BOOLEAN",
277
"stmt : CACHE_LIFETIME NUMBER",
278
"stmt : NAME STRING boundary",
279
"tunnelmods :",
280
"tunnelmods : tunnelmods tunnelmod",
281
"tunnelmod : mod",
282
"tunnelmod : SRCRT",
283
"ifmods :",
284
"ifmods : ifmods ifmod",
285
"ifmod : mod",
286
"ifmod : DISABLE",
287
"ifmod : IGMPV1",
288
"ifmod : NETMASK addrname",
289
"ifmod : NETMASK",
290
"ifmod : ALTNET addrmask",
291
"ifmod : ALTNET",
292
"mod : THRESHOLD NUMBER",
293
"mod : THRESHOLD",
294
"mod : METRIC NUMBER",
295
"mod : METRIC",
296
"mod : RATE_LIMIT NUMBER",
297
"mod : RATE_LIMIT",
298
"mod : BOUNDARY bound",
299
"mod : BOUNDARY",
300
"interface : ADDR",
301
"interface : STRING",
302
"addrname : ADDR",
303
"addrname : STRING",
304
"bound : boundary",
305
"bound : STRING",
306
"boundary : ADDRMASK",
307
"addrmask : ADDRMASK",
308
"addrmask : ADDR",
309
};
310
#endif
311
#ifdef YYSTACKSIZE
312
#undef YYMAXDEPTH
313
#define YYMAXDEPTH YYSTACKSIZE
314
#else
315
#ifdef YYMAXDEPTH
316
#define YYSTACKSIZE YYMAXDEPTH
317
#else
318
#define YYSTACKSIZE 10000
319
#define YYMAXDEPTH 10000
320
#endif
321
#endif
322
#define YYINITSTACKSIZE 200
323
/* LINTUSED */
324
int yydebug;
325
int yynerrs;
326
int yyerrflag;
327
int yychar;
328
short *yyssp;
329
YYSTYPE *yyvsp;
330
YYSTYPE yyval;
331
YYSTYPE yylval;
332
short *yyss;
333
short *yysslim;
334
YYSTYPE *yyvs;
335
unsigned int yystacksize;
336
int yyparse(void);
337
#line 374 "cfparse.y"
338
static void
339
fatal(const char *fmt, ...)
340
{
341
	va_list ap;
342
	char buf[200];
343
344
	va_start(ap, fmt);
345
	vsnprintf(buf, sizeof buf, fmt, ap);
346
	va_end(ap);
347
348
	logit(LOG_ERR,0,"%s: %s near line %d", configfilename, buf, lineno);
349
}
350
351
static void
352
warn(const char *fmt, ...)
353
{
354
	va_list ap;
355
	char buf[200];
356
357
	va_start(ap, fmt);
358
	vsnprintf(buf, sizeof buf, fmt, ap);
359
	va_end(ap);
360
361
	logit(LOG_WARNING,0,"%s: %s near line %d", configfilename, buf, lineno);
362
}
363
364
static void
365
yyerror(s)
366
char *s;
367
{
368
	logit(LOG_ERR, 0, "%s: %s near line %d", configfilename, s, lineno);
369
}
370
371
static char *
372
next_word()
373
{
374
	static char buf[1024];
375
	static char *p=NULL;
376
	extern FILE *f;
377
	char *q;
378
379
	while (1) {
380
	    if (!p || !*p) {
381
		lineno++;
382
		if (fgets(buf, sizeof(buf), f) == NULL)
383
		    return NULL;
384
		p = buf;
385
	    }
386
	    while (*p && (*p == ' ' || *p == '\t'))	/* skip whitespace */
387
		p++;
388
	    if (*p == '#') {
389
		p = NULL;		/* skip comments */
390
		continue;
391
	    }
392
	    q = p;
393
	    while (*p && *p != ' ' && *p != '\t' && *p != '\n')
394
		p++;		/* find next whitespace */
395
	    *p++ = '\0';	/* null-terminate string */
396
397
	    if (!*q) {
398
		p = NULL;
399
		continue;	/* if 0-length string, read another line */
400
	    }
401
402
	    return q;
403
	}
404
}
405
406
static int
407
yylex()
408
{
409
	int n;
410
	u_int32_t addr;
411
	char *q;
412
413
	if ((q = next_word()) == NULL) {
414
		return 0;
415
	}
416
417
	if (!strcmp(q,"cache_lifetime"))
418
		return CACHE_LIFETIME;
419
	if (!strcmp(q,"pruning"))
420
		return PRUNING;
421
	if (!strcmp(q,"phyint"))
422
		return PHYINT;
423
	if (!strcmp(q,"tunnel"))
424
		return TUNNEL;
425
	if (!strcmp(q,"disable"))
426
		return DISABLE;
427
	if (!strcmp(q,"metric"))
428
		return METRIC;
429
	if (!strcmp(q,"threshold"))
430
		return THRESHOLD;
431
	if (!strcmp(q,"rate_limit"))
432
		return RATE_LIMIT;
433
	if (!strcmp(q,"srcrt") || !strcmp(q,"sourceroute"))
434
		return SRCRT;
435
	if (!strcmp(q,"boundary"))
436
		return BOUNDARY;
437
	if (!strcmp(q,"netmask"))
438
		return NETMASK;
439
	if (!strcmp(q,"igmpv1"))
440
		return IGMPV1;
441
	if (!strcmp(q,"altnet"))
442
		return ALTNET;
443
	if (!strcmp(q,"name"))
444
		return NAME;
445
	if (!strcmp(q,"on") || !strcmp(q,"yes")) {
446
		yylval.num = 1;
447
		return BOOLEAN;
448
	}
449
	if (!strcmp(q,"off") || !strcmp(q,"no")) {
450
		yylval.num = 0;
451
		return BOOLEAN;
452
	}
453
	if (sscanf(q,"%[.0-9]/%d%c",s1,&n,s2) == 2) {
454
		if ((addr = inet_parse(s1)) != 0xffffffff) {
455
			yylval.addrmask.mask = n;
456
			yylval.addrmask.addr = addr;
457
			return ADDRMASK;
458
		}
459
		/* fall through to returning STRING */
460
	}
461
	if (sscanf(q,"%[.0-9]%c",s1,s2) == 1) {
462
		if ((addr = inet_parse(s1)) != 0xffffffff &&
463
		    inet_valid_host(addr)) {
464
			yylval.addr = addr;
465
			return ADDR;
466
		}
467
	}
468
	if (sscanf(q,"0x%8x%c",&n,s1) == 1) {
469
		yylval.addr = n;
470
		return ADDR;
471
	}
472
	if (sscanf(q,"%d%c",&n,s1) == 1) {
473
		yylval.num = n;
474
		return NUMBER;
475
	}
476
	yylval.ptr = q;
477
	return STRING;
478
}
479
480
void
481
config_vifs_from_file()
482
{
483
	extern FILE *f;
484
485
	order = 0;
486
	numbounds = 0;
487
	lineno = 0;
488
489
	if ((f = fopen(configfilename, "r")) == NULL) {
490
	    if (errno != ENOENT)
491
		logit(LOG_ERR, errno, "can't open %s", configfilename);
492
	    return;
493
	}
494
495
	yyparse();
496
497
	fclose(f);
498
}
499
500
static u_int32_t
501
valid_if(s)
502
char *s;
503
{
504
	register vifi_t vifi;
505
	register struct uvif *v;
506
507
	for (vifi=0, v=uvifs; vifi<numvifs; vifi++, v++)
508
	    if (!strcmp(v->uv_name, s))
509
		return v->uv_lcl_addr;
510
511
	return 0;
512
}
513
514
static const char *
515
ifconfaddr(a)
516
    u_int32_t a;
517
{
518
    static char ifname[IFNAMSIZ];
519
    struct ifaddrs *ifap, *ifa;
520
521
    if (getifaddrs(&ifap) != 0)
522
	return (NULL);
523
524
    for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
525
	    if (ifa->ifa_addr->sa_family == AF_INET &&
526
		((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr == a) {
527
		strlcpy(ifname, ifa->ifa_name, sizeof(ifname));
528
		freeifaddrs(ifap);
529
		return (ifname);
530
	    }
531
    }
532
    freeifaddrs(ifap);
533
    return (0);
534
}
535
#line 528 "cfparse.c"
536
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
537
static int yygrowstack(void)
538
{
539
    unsigned int newsize;
540
    long sslen;
541
    short *newss;
542
    YYSTYPE *newvs;
543
544
    if ((newsize = yystacksize) == 0)
545
        newsize = YYINITSTACKSIZE;
546
    else if (newsize >= YYMAXDEPTH)
547
        return -1;
548
    else if ((newsize *= 2) > YYMAXDEPTH)
549
        newsize = YYMAXDEPTH;
550
    sslen = yyssp - yyss;
551
#ifdef SIZE_MAX
552
#define YY_SIZE_MAX SIZE_MAX
553
#else
554
#define YY_SIZE_MAX 0xffffffffU
555
#endif
556
    if (newsize && YY_SIZE_MAX / newsize < sizeof *newss)
557
        goto bail;
558
    newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :
559
      (short *)malloc(newsize * sizeof *newss); /* overflow check above */
560
    if (newss == NULL)
561
        goto bail;
562
    yyss = newss;
563
    yyssp = newss + sslen;
564
    if (newsize && YY_SIZE_MAX / newsize < sizeof *newvs)
565
        goto bail;
566
    newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :
567
      (YYSTYPE *)malloc(newsize * sizeof *newvs); /* overflow check above */
568
    if (newvs == NULL)
569
        goto bail;
570
    yyvs = newvs;
571
    yyvsp = newvs + sslen;
572
    yystacksize = newsize;
573
    yysslim = yyss + newsize - 1;
574
    return 0;
575
bail:
576
    if (yyss)
577
            free(yyss);
578
    if (yyvs)
579
            free(yyvs);
580
    yyss = yyssp = NULL;
581
    yyvs = yyvsp = NULL;
582
    yystacksize = 0;
583
    return -1;
584
}
585
586
#define YYABORT goto yyabort
587
#define YYREJECT goto yyabort
588
#define YYACCEPT goto yyaccept
589
#define YYERROR goto yyerrlab
590
int
591
yyparse(void)
592
{
593
    int yym, yyn, yystate;
594
#if YYDEBUG
595
    const char *yys;
596
597
    if ((yys = getenv("YYDEBUG")))
598
    {
599
        yyn = *yys;
600
        if (yyn >= '0' && yyn <= '9')
601
            yydebug = yyn - '0';
602
    }
603
#endif /* YYDEBUG */
604
605
    yynerrs = 0;
606
    yyerrflag = 0;
607
    yychar = (-1);
608
609
    if (yyss == NULL && yygrowstack()) goto yyoverflow;
610
    yyssp = yyss;
611
    yyvsp = yyvs;
612
    *yyssp = yystate = 0;
613
614
yyloop:
615
    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
616
    if (yychar < 0)
617
    {
618
        if ((yychar = yylex()) < 0) yychar = 0;
619
#if YYDEBUG
620
        if (yydebug)
621
        {
622
            yys = 0;
623
            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
624
            if (!yys) yys = "illegal-symbol";
625
            printf("%sdebug: state %d, reading %d (%s)\n",
626
                    YYPREFIX, yystate, yychar, yys);
627
        }
628
#endif
629
    }
630
    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
631
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
632
    {
633
#if YYDEBUG
634
        if (yydebug)
635
            printf("%sdebug: state %d, shifting to state %d\n",
636
                    YYPREFIX, yystate, yytable[yyn]);
637
#endif
638
        if (yyssp >= yysslim && yygrowstack())
639
        {
640
            goto yyoverflow;
641
        }
642
        *++yyssp = yystate = yytable[yyn];
643
        *++yyvsp = yylval;
644
        yychar = (-1);
645
        if (yyerrflag > 0)  --yyerrflag;
646
        goto yyloop;
647
    }
648
    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
649
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
650
    {
651
        yyn = yytable[yyn];
652
        goto yyreduce;
653
    }
654
    if (yyerrflag) goto yyinrecovery;
655
#if defined(__GNUC__)
656
    goto yynewerror;
657
#endif
658
yynewerror:
659
    yyerror("syntax error");
660
#if defined(__GNUC__)
661
    goto yyerrlab;
662
#endif
663
yyerrlab:
664
    ++yynerrs;
665
yyinrecovery:
666
    if (yyerrflag < 3)
667
    {
668
        yyerrflag = 3;
669
        for (;;)
670
        {
671
            if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
672
                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
673
            {
674
#if YYDEBUG
675
                if (yydebug)
676
                    printf("%sdebug: state %d, error recovery shifting\
677
 to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
678
#endif
679
                if (yyssp >= yysslim && yygrowstack())
680
                {
681
                    goto yyoverflow;
682
                }
683
                *++yyssp = yystate = yytable[yyn];
684
                *++yyvsp = yylval;
685
                goto yyloop;
686
            }
687
            else
688
            {
689
#if YYDEBUG
690
                if (yydebug)
691
                    printf("%sdebug: error recovery discarding state %d\n",
692
                            YYPREFIX, *yyssp);
693
#endif
694
                if (yyssp <= yyss) goto yyabort;
695
                --yyssp;
696
                --yyvsp;
697
            }
698
        }
699
    }
700
    else
701
    {
702
        if (yychar == 0) goto yyabort;
703
#if YYDEBUG
704
        if (yydebug)
705
        {
706
            yys = 0;
707
            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
708
            if (!yys) yys = "illegal-symbol";
709
            printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
710
                    YYPREFIX, yystate, yychar, yys);
711
        }
712
#endif
713
        yychar = (-1);
714
        goto yyloop;
715
    }
716
yyreduce:
717
#if YYDEBUG
718
    if (yydebug)
719
        printf("%sdebug: state %d, reducing by rule %d (%s)\n",
720
                YYPREFIX, yystate, yyn, yyrule[yyn]);
721
#endif
722
    yym = yylen[yyn];
723
    if (yym)
724
        yyval = yyvsp[1-yym];
725
    else
726
        memset(&yyval, 0, sizeof yyval);
727
    switch (yyn)
728
    {
729
case 5:
730
#line 112 "cfparse.y"
731
{
732
733
			vifi_t vifi;
734
735
			if (order)
736
			    fatal("phyints must appear before tunnels");
737
738
			for (vifi = 0, v = uvifs;
739
			     vifi < numvifs;
740
			     ++vifi, ++v)
741
			    if (!(v->uv_flags & VIFF_TUNNEL) &&
742
				yyvsp[0].addr == v->uv_lcl_addr)
743
				break;
744
745
			if (vifi == numvifs)
746
			    fatal("%s is not a configured interface",
747
				inet_fmt(yyvsp[0].addr,s1));
748
749
					}
750
break;
751
case 7:
752
#line 132 "cfparse.y"
753
{
754
			const char *ifname;
755
			struct ifreq ffr;
756
			vifi_t vifi;
757
758
			order++;
759
760
			ifname = ifconfaddr(yyvsp[-1].addr);
761
			if (ifname == 0)
762
			    fatal("Tunnel local address %s is not mine",
763
				inet_fmt(yyvsp[-1].addr, s1));
764
765
			strlcpy(ffr.ifr_name, ifname, sizeof(ffr.ifr_name));
766
			if (ioctl(udp_socket, SIOCGIFFLAGS, (char *)&ffr)<0)
767
			    fatal("ioctl SIOCGIFFLAGS on %s",ffr.ifr_name);
768
			if (ffr.ifr_flags & IFF_LOOPBACK)
769
			    fatal("Tunnel local address %s is a loopback interface",
770
				inet_fmt(yyvsp[-1].addr, s1));
771
772
			if (ifconfaddr(yyvsp[0].addr) != 0)
773
			    fatal("Tunnel remote address %s is one of mine",
774
				inet_fmt(yyvsp[0].addr, s1));
775
776
			for (vifi = 0, v = uvifs;
777
			     vifi < numvifs;
778
			     ++vifi, ++v)
779
			    if (v->uv_flags & VIFF_TUNNEL) {
780
				if (yyvsp[0].addr == v->uv_rmt_addr)
781
				    fatal("Duplicate tunnel to %s",
782
					inet_fmt(yyvsp[0].addr, s1));
783
			    } else if (!(v->uv_flags & VIFF_DISABLED)) {
784
				if ((yyvsp[0].addr & v->uv_subnetmask) == v->uv_subnet)
785
				    fatal("Unnecessary tunnel to %s",
786
					inet_fmt(yyvsp[0].addr,s1));
787
			    }
788
789
			if (numvifs == MAXVIFS)
790
			    fatal("too many vifs");
791
792
			v = &uvifs[numvifs];
793
			v->uv_flags	= VIFF_TUNNEL;
794
			v->uv_metric	= DEFAULT_METRIC;
795
			v->uv_rate_limit= DEFAULT_TUN_RATE_LIMIT;
796
			v->uv_threshold	= DEFAULT_THRESHOLD;
797
			v->uv_lcl_addr	= yyvsp[-1].addr;
798
			v->uv_rmt_addr	= yyvsp[0].addr;
799
			v->uv_subnet	= 0;
800
			v->uv_subnetmask= 0;
801
			v->uv_subnetbcast= 0;
802
			strncpy(v->uv_name, ffr.ifr_name, IFNAMSIZ);
803
			v->uv_groups	= NULL;
804
			v->uv_neighbors	= NULL;
805
			v->uv_acl	= NULL;
806
			v->uv_addrs	= NULL;
807
808
			if (!(ffr.ifr_flags & IFF_UP)) {
809
			    v->uv_flags |= VIFF_DOWN;
810
			    vifs_down = TRUE;
811
			}
812
					}
813
break;
814
case 8:
815
#line 193 "cfparse.y"
816
{
817
			logit(LOG_INFO, 0,
818
			    "installing tunnel from %s to %s as vif #%u - rate=%d",
819
			    inet_fmt(yyvsp[-3].addr, s1), inet_fmt(yyvsp[-2].addr, s2),
820
			    numvifs, v->uv_rate_limit);
821
822
			++numvifs;
823
					}
824
break;
825
case 9:
826
#line 201 "cfparse.y"
827
{ pruning = yyvsp[0].num; }
828
break;
829
case 10:
830
#line 202 "cfparse.y"
831
{ cache_lifetime = yyvsp[0].num;
832
				      max_prune_lifetime = cache_lifetime * 2;
833
				    }
834
break;
835
case 11:
836
#line 205 "cfparse.y"
837
{ if (numbounds >= MAXBOUNDS) {
838
					fatal("Too many named boundaries (max %d)", MAXBOUNDS);
839
				      }
840
841
				      boundlist[numbounds].name = strdup(yyvsp[-1].ptr);
842
				      boundlist[numbounds++].bound = yyvsp[0].addrmask;
843
				    }
844
break;
845
case 15:
846
#line 219 "cfparse.y"
847
{ fatal("Source-route tunnels not supported"); }
848
break;
849
case 19:
850
#line 227 "cfparse.y"
851
{ v->uv_flags |= VIFF_DISABLED; }
852
break;
853
case 20:
854
#line 228 "cfparse.y"
855
{ v->uv_flags |= VIFF_IGMPV1; }
856
break;
857
case 21:
858
#line 229 "cfparse.y"
859
{
860
				  u_int32_t subnet, mask;
861
862
				  mask = yyvsp[0].addr;
863
				  subnet = v->uv_lcl_addr & mask;
864
				  if (!inet_valid_subnet(subnet, mask))
865
					fatal("Invalid netmask");
866
				  v->uv_subnet = subnet;
867
				  v->uv_subnetmask = mask;
868
				  v->uv_subnetbcast = subnet | ~mask;
869
				}
870
break;
871
case 22:
872
#line 240 "cfparse.y"
873
{
874
875
		    warn("Expected address after netmask keyword, ignored");
876
877
				}
878
break;
879
case 23:
880
#line 245 "cfparse.y"
881
{
882
883
		    struct phaddr *ph;
884
885
		    ph = malloc(sizeof(struct phaddr));
886
		    if (ph == NULL)
887
			fatal("out of memory");
888
		    if (yyvsp[0].addrmask.mask) {
889
			VAL_TO_MASK(ph->pa_subnetmask, yyvsp[0].addrmask.mask);
890
		    } else
891
			ph->pa_subnetmask = v->uv_subnetmask;
892
		    ph->pa_subnet = yyvsp[0].addrmask.addr & ph->pa_subnetmask;
893
		    ph->pa_subnetbcast = ph->pa_subnet | ~ph->pa_subnetmask;
894
		    if (yyvsp[0].addrmask.addr & ~ph->pa_subnetmask)
895
			warn("Extra subnet %s/%d has host bits set",
896
				inet_fmt(yyvsp[0].addrmask.addr,s1), yyvsp[0].addrmask.mask);
897
		    ph->pa_next = v->uv_addrs;
898
		    v->uv_addrs = ph;
899
900
				}
901
break;
902
case 24:
903
#line 265 "cfparse.y"
904
{
905
906
		    warn("Expected address after altnet keyword, ignored");
907
908
				}
909
break;
910
case 25:
911
#line 272 "cfparse.y"
912
{ if (yyvsp[0].num < 1 || yyvsp[0].num > 255)
913
				    fatal("Invalid threshold %d",yyvsp[0].num);
914
				  v->uv_threshold = yyvsp[0].num;
915
				}
916
break;
917
case 26:
918
#line 276 "cfparse.y"
919
{
920
921
		    warn("Expected number after threshold keyword, ignored");
922
923
				}
924
break;
925
case 27:
926
#line 281 "cfparse.y"
927
{ if (yyvsp[0].num < 1 || yyvsp[0].num > UNREACHABLE)
928
				    fatal("Invalid metric %d",yyvsp[0].num);
929
				  v->uv_metric = yyvsp[0].num;
930
				}
931
break;
932
case 28:
933
#line 285 "cfparse.y"
934
{
935
936
		    warn("Expected number after metric keyword, ignored");
937
938
				}
939
break;
940
case 29:
941
#line 290 "cfparse.y"
942
{ if (yyvsp[0].num > MAX_RATE_LIMIT)
943
				    fatal("Invalid rate_limit %d",yyvsp[0].num);
944
				  v->uv_rate_limit = yyvsp[0].num;
945
				}
946
break;
947
case 30:
948
#line 294 "cfparse.y"
949
{
950
951
		    warn("Expected number after rate_limit keyword, ignored");
952
953
				}
954
break;
955
case 31:
956
#line 299 "cfparse.y"
957
{
958
959
		    struct vif_acl *v_acl;
960
961
		    v_acl = malloc(sizeof(struct vif_acl));
962
		    if (v_acl == NULL)
963
			fatal("out of memory");
964
		    VAL_TO_MASK(v_acl->acl_mask, yyvsp[0].addrmask.mask);
965
		    v_acl->acl_addr = yyvsp[0].addrmask.addr & v_acl->acl_mask;
966
		    if (yyvsp[0].addrmask.addr & ~v_acl->acl_mask)
967
			warn("Boundary spec %s/%d has host bits set",
968
				inet_fmt(yyvsp[0].addrmask.addr,s1),yyvsp[0].addrmask.mask);
969
		    v_acl->acl_next = v->uv_acl;
970
		    v->uv_acl = v_acl;
971
972
				}
973
break;
974
case 32:
975
#line 315 "cfparse.y"
976
{
977
978
		warn("Expected boundary spec after boundary keyword, ignored");
979
980
				}
981
break;
982
case 33:
983
#line 322 "cfparse.y"
984
{ yyval.addr = yyvsp[0].addr; }
985
break;
986
case 34:
987
#line 323 "cfparse.y"
988
{
989
				  yyval.addr = valid_if(yyvsp[0].ptr);
990
				  if (yyval.addr == 0)
991
					fatal("Invalid interface name %s",yyvsp[0].ptr);
992
				}
993
break;
994
case 35:
995
#line 330 "cfparse.y"
996
{ yyval.addr = yyvsp[0].addr; }
997
break;
998
case 36:
999
#line 331 "cfparse.y"
1000
{ struct hostent *hp;
1001
1002
				  if ((hp = gethostbyname(yyvsp[0].ptr)) == NULL)
1003
				    fatal("No such host %s", yyvsp[0].ptr);
1004
1005
				  if (hp->h_addr_list[1])
1006
				    fatal("Hostname %s does not %s",
1007
					yyvsp[0].ptr, "map to a unique address");
1008
1009
				  bcopy(hp->h_addr_list[0], &yyval.addr,
1010
					    hp->h_length);
1011
				}
1012
break;
1013
case 37:
1014
#line 344 "cfparse.y"
1015
{ yyval.addrmask = yyvsp[0].addrmask; }
1016
break;
1017
case 38:
1018
#line 345 "cfparse.y"
1019
{ int i;
1020
1021
				  for (i=0; i < numbounds; i++) {
1022
				    if (!strcmp(boundlist[i].name, yyvsp[0].ptr)) {
1023
					yyval.addrmask = boundlist[i].bound;
1024
					break;
1025
				    }
1026
				  }
1027
				  if (i == numbounds) {
1028
				    fatal("Invalid boundary name %s",yyvsp[0].ptr);
1029
				  }
1030
				}
1031
break;
1032
case 39:
1033
#line 359 "cfparse.y"
1034
{
1035
1036
			if ((ntohl(yyvsp[0].addrmask.addr) & 0xff000000) != 0xef000000) {
1037
			    fatal("Boundaries must be 239.x.x.x, not %s/%d",
1038
				inet_fmt(yyvsp[0].addrmask.addr, s1), yyvsp[0].addrmask.mask);
1039
			}
1040
			yyval.addrmask = yyvsp[0].addrmask;
1041
1042
				}
1043
break;
1044
case 40:
1045
#line 370 "cfparse.y"
1046
{ yyval.addrmask = yyvsp[0].addrmask; }
1047
break;
1048
case 41:
1049
#line 371 "cfparse.y"
1050
{ yyval.addrmask.addr = yyvsp[0].addr; yyval.addrmask.mask = 0; }
1051
break;
1052
#line 1045 "cfparse.c"
1053
    }
1054
    yyssp -= yym;
1055
    yystate = *yyssp;
1056
    yyvsp -= yym;
1057
    yym = yylhs[yyn];
1058
    if (yystate == 0 && yym == 0)
1059
    {
1060
#if YYDEBUG
1061
        if (yydebug)
1062
            printf("%sdebug: after reduction, shifting from state 0 to\
1063
 state %d\n", YYPREFIX, YYFINAL);
1064
#endif
1065
        yystate = YYFINAL;
1066
        *++yyssp = YYFINAL;
1067
        *++yyvsp = yyval;
1068
        if (yychar < 0)
1069
        {
1070
            if ((yychar = yylex()) < 0) yychar = 0;
1071
#if YYDEBUG
1072
            if (yydebug)
1073
            {
1074
                yys = 0;
1075
                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1076
                if (!yys) yys = "illegal-symbol";
1077
                printf("%sdebug: state %d, reading %d (%s)\n",
1078
                        YYPREFIX, YYFINAL, yychar, yys);
1079
            }
1080
#endif
1081
        }
1082
        if (yychar == 0) goto yyaccept;
1083
        goto yyloop;
1084
    }
1085
    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
1086
            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
1087
        yystate = yytable[yyn];
1088
    else
1089
        yystate = yydgoto[yym];
1090
#if YYDEBUG
1091
    if (yydebug)
1092
        printf("%sdebug: after reduction, shifting from state %d \
1093
to state %d\n", YYPREFIX, *yyssp, yystate);
1094
#endif
1095
    if (yyssp >= yysslim && yygrowstack())
1096
    {
1097
        goto yyoverflow;
1098
    }
1099
    *++yyssp = yystate;
1100
    *++yyvsp = yyval;
1101
    goto yyloop;
1102
yyoverflow:
1103
    yyerror("yacc stack overflow");
1104
yyabort:
1105
    if (yyss)
1106
            free(yyss);
1107
    if (yyvs)
1108
            free(yyvs);
1109
    yyss = yyssp = NULL;
1110
    yyvs = yyvsp = NULL;
1111
    yystacksize = 0;
1112
    return (1);
1113
yyaccept:
1114
    if (yyss)
1115
            free(yyss);
1116
    if (yyvs)
1117
            free(yyvs);
1118
    yyss = yyssp = NULL;
1119
    yyvs = yyvsp = NULL;
1120
    yystacksize = 0;
1121
    return (0);
1122
}