GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.sbin/ospfd/parse.c Lines: 139 414 33.6 %
Date: 2017-11-13 Branches: 69 319 21.6 %

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 25 "parse.y"
13
#include <sys/types.h>
14
#include <sys/socket.h>
15
#include <sys/stat.h>
16
#include <netinet/in.h>
17
#include <arpa/inet.h>
18
#include <ctype.h>
19
#include <err.h>
20
#include <errno.h>
21
#include <unistd.h>
22
#include <ifaddrs.h>
23
#include <limits.h>
24
#include <stdarg.h>
25
#include <stdio.h>
26
#include <string.h>
27
#include <syslog.h>
28
29
#include "ospf.h"
30
#include "ospfd.h"
31
#include "ospfe.h"
32
#include "log.h"
33
34
TAILQ_HEAD(files, file)		 files = TAILQ_HEAD_INITIALIZER(files);
35
static struct file {
36
	TAILQ_ENTRY(file)	 entry;
37
	FILE			*stream;
38
	char			*name;
39
	int			 lineno;
40
	int			 errors;
41
} *file, *topfile;
42
struct file	*pushfile(const char *, int);
43
int		 popfile(void);
44
int		 check_file_secrecy(int, const char *);
45
int		 yyparse(void);
46
int		 yylex(void);
47
int		 yyerror(const char *, ...)
48
    __attribute__((__format__ (printf, 1, 2)))
49
    __attribute__((__nonnull__ (1)));
50
int		 kw_cmp(const void *, const void *);
51
int		 lookup(char *);
52
int		 lgetc(int);
53
int		 lungetc(int);
54
int		 findeol(void);
55
56
TAILQ_HEAD(symhead, sym)	 symhead = TAILQ_HEAD_INITIALIZER(symhead);
57
struct sym {
58
	TAILQ_ENTRY(sym)	 entry;
59
	int			 used;
60
	int			 persist;
61
	char			*nam;
62
	char			*val;
63
};
64
int		 symset(const char *, const char *, int);
65
char		*symget(const char *);
66
67
void		 clear_config(struct ospfd_conf *xconf);
68
u_int32_t	 get_rtr_id(void);
69
int		 host(const char *, struct in_addr *, struct in_addr *);
70
71
static struct ospfd_conf	*conf;
72
static int			 errors = 0;
73
74
struct area	*area = NULL;
75
struct iface	*iface = NULL;
76
77
struct config_defaults {
78
	char		auth_key[MAX_SIMPLE_AUTH_LEN];
79
	struct auth_md_head	 md_list;
80
	u_int32_t	dead_interval;
81
	u_int32_t	fast_hello_interval;
82
	u_int16_t	transmit_delay;
83
	u_int16_t	hello_interval;
84
	u_int16_t	rxmt_interval;
85
	u_int16_t	metric;
86
	enum auth_type	auth_type;
87
	u_int8_t	auth_keyid;
88
	u_int8_t	priority;
89
};
90
91
struct config_defaults	 globaldefs;
92
struct config_defaults	 areadefs;
93
struct config_defaults	 ifacedefs;
94
struct config_defaults	*defs;
95
96
struct area	*conf_get_area(struct in_addr);
97
struct iface	*conf_get_if(struct kif *, struct kif_addr *);
98
int		 conf_check_rdomain(unsigned int);
99
100
typedef struct {
101
	union {
102
		int64_t		 number;
103
		char		*string;
104
		struct redistribute *redist;
105
	} v;
106
	int lineno;
107
} YYSTYPE;
108
109
#line 110 "parse.c"
110
#define AREA 257
111
#define INTERFACE 258
112
#define ROUTERID 259
113
#define FIBUPDATE 260
114
#define REDISTRIBUTE 261
115
#define RTLABEL 262
116
#define RDOMAIN 263
117
#define RFC1583COMPAT 264
118
#define STUB 265
119
#define ROUTER 266
120
#define SPFDELAY 267
121
#define SPFHOLDTIME 268
122
#define EXTTAG 269
123
#define AUTHKEY 270
124
#define AUTHTYPE 271
125
#define AUTHMD 272
126
#define AUTHMDKEYID 273
127
#define METRIC 274
128
#define PASSIVE 275
129
#define HELLOINTERVAL 276
130
#define FASTHELLOINTERVAL 277
131
#define TRANSMITDELAY 278
132
#define RETRANSMITINTERVAL 279
133
#define ROUTERDEADTIME 280
134
#define ROUTERPRIORITY 281
135
#define SET 282
136
#define TYPE 283
137
#define YES 284
138
#define NO 285
139
#define MSEC 286
140
#define MINIMAL 287
141
#define DEMOTE 288
142
#define INCLUDE 289
143
#define ERROR 290
144
#define STRING 291
145
#define NUMBER 292
146
#define YYERRCODE 256
147
const short yylhs[] =
148
	{                                        -1,
149
    0,    0,    0,    0,    0,    0,    0,   11,    9,    9,
150
    1,    1,    2,    2,    7,    7,   13,   12,   12,   12,
151
   12,   12,   12,   12,   12,   12,   12,   10,   10,   10,
152
    3,    3,    3,    4,    4,    5,    5,   18,   19,   20,
153
   21,   15,   15,   15,   15,   15,   15,   15,   15,   15,
154
   15,   15,    8,    8,   16,   16,   22,   17,   17,   23,
155
   14,    6,    6,   24,   24,   25,   25,   25,   25,   25,
156
   28,   26,   27,   27,   27,   29,   29,   30,   30,   30,
157
};
158
const short yylen[] =
159
	{                                         2,
160
    0,    3,    2,    3,    3,    3,    3,    2,    2,    1,
161
    1,    1,    0,    1,    2,    1,    3,    2,    2,    1,
162
    4,    2,    2,    2,    2,    3,    1,    6,    4,    5,
163
    0,    2,    7,    3,    1,    2,    2,    3,    2,    2,
164
    2,    2,    2,    2,    2,    2,    3,    2,    1,    1,
165
    1,    1,    1,    1,    2,    0,    2,    1,    0,    0,
166
    7,    1,    0,    3,    2,    1,    3,    1,    1,    2,
167
    0,    4,    4,    3,    0,    3,    2,    1,    2,    1,
168
};
169
const short yydefred[] =
170
	{                                      1,
171
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
172
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
173
    0,    0,   14,    0,    0,    3,    0,   20,    0,    0,
174
    0,    0,   27,   52,   51,   49,   50,    7,   60,   18,
175
   11,   12,   19,    0,   22,   23,    0,    0,   16,   24,
176
   25,   41,   40,    0,   39,   42,   46,    0,   45,   48,
177
   54,   53,   44,   43,    8,    0,    0,    2,    4,    5,
178
    6,    0,    0,   26,   15,   38,   47,   10,    0,    0,
179
    0,    0,    0,   21,    9,    0,    0,   29,    0,    0,
180
    0,   30,    0,    0,   32,    0,    0,   55,    0,    0,
181
    0,   68,    0,    0,   66,   36,   37,    0,   28,   71,
182
   70,    0,   61,    0,   65,    0,    0,   62,   67,    0,
183
   64,    0,   35,    0,   72,   57,   58,    0,    0,    0,
184
   33,   34,   78,    0,   74,   80,    0,    0,   79,   73,
185
    0,   77,   76,
186
};
187
const short yydgoto[] =
188
	{                                       1,
189
   43,   27,   88,  122,   95,  119,   50,   63,   79,   28,
190
   29,   30,   31,   32,  102,   91,  129,   34,   35,   36,
191
   37,  121,   72,  103,  104,  105,  125,  117,  137,  138,
192
};
193
const short yysindex[] =
194
	{                                      0,
195
  -10,    6, -261, -260, -272, -255, -273, -272, -234, -275,
196
 -275, -254, -252, -257, -249, -248, -246, -253, -244, -239,
197
 -258, -237,    0, -233,   -4,    0, -197,    0,   62,   64,
198
   65,   69,    0,    0,    0,    0,    0,    0,    0,    0,
199
    0,    0,    0, -189,    0,    0, -272, -210,    0,    0,
200
    0,    0,    0, -203,    0,    0,    0, -196,    0,    0,
201
    0,    0,    0,    0,    0, -193, -241,    0,    0,    0,
202
    0,  -42, -192,    0,    0,    0,    0,    0, -188, -186,
203
 -183,   48,   92,    0,    0, -183,   -9,    0, -185,   92,
204
 -211,    0, -184, -182,    0,  -19, -183,    0, -180, -179,
205
 -178,    0,  -73,   92,    0,    0,    0,   92,    0,    0,
206
    0, -177,    0,   99,    0, -259,  -11,    0,    0,   92,
207
    0,   -3,    0,   92,    0,    0,    0,   -8, -259,  108,
208
    0,    0,    0, -175,    0,    0,  131,   92,    0,    0,
209
   99,    0,    0,};
210
const short yyrindex[] =
211
	{                                      0,
212
 -147,    0,    0,    0,    0,    0,    0,    0,    0,    0,
213
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
214
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
215
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
216
24
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
217
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
218
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
219
    0,    0,    0,    0,    0,    0,    0,    0,  109,    0,
220
   39,    0, -187,    0,    0,   39,   -5,    0,    0, -121,
221
24
    0,    0,    0,    0,    0,    0,   39,    0,    0,   15,
222
    0,    0,    0,  -49,    0,    0,    0, -256,    0,    0,
223
24
    0,   63,    0,    0,    0,    0,   87,    0,    0,  -97,
224
    0, -111,    0,  152,    0,    0,    0,    0,    0,    0,
225
    0,    0,    0,    0,    0,    0,    0,  152,    0,    0,
226
    0,    0,    0,};
227
const short yygindex[] =
228
	{                                      0,
229
   -2,    0,  -77,    0, -106,    0,  110,    0,    0,   20,
230
    0,    0,    0,    0,    2,  -82,    0,    0,    0,    0,
231
    0,  -18,    0,    0,   19,    0,    0,    0,    0,  -13,
232
};
233
#define YYTABLESIZE 440
234
const short yytable[] =
235
	{                                      26,
236
   90,   56,   33,   56,   96,   46,   90,   98,   92,  123,
237
   48,   41,   42,   56,   93,   38,   49,   56,   45,  109,
238
   80,  115,  132,   94,   69,  116,   56,   56,   61,   39,
239
   40,   47,   58,   62,   54,   44,   52,  126,   53,  128,
240
  127,  130,   55,   56,   74,   57,   99,   59,   31,   81,
241
   82,  113,   60,  100,   64,  142,   66,   65,   12,   13,
242
   14,   15,   16,   67,   17,   18,   19,   20,   21,   22,
243
   56,   68,   63,   69,   70,   56,  101,   56,   71,   73,
244
   83,   75,   56,   56,   56,   56,   56,   76,   56,   56,
245
   56,   56,   56,   56,   89,   77,   75,   78,   87,   84,
246
   56,   90,   85,  108,   86,   23,   97,  106,  120,  107,
247
  110,  124,  112,   13,  118,  139,  131,   56,   17,  111,
248
   51,  114,  143,  141,    0,    0,    0,    0,    0,    0,
249
    0,  136,    0,    0,    0,    0,   56,    0,  136,   69,
250
    0,    0,    0,   56,    0,    0,    0,    0,   56,   56,
251
   56,   56,   56,   56,   56,   56,   56,   56,   56,   56,
252
   56,   56,   59,   31,    0,    0,   56,   56,    0,    0,
253
    0,   59,   56,   56,   56,   56,   56,   56,   56,   56,
254
   56,   56,   56,   56,   99,    0,    0,   63,    0,    0,
255
   56,  100,    0,    0,    0,    0,   12,   13,   14,   15,
256
   16,    0,   17,   18,   19,   20,   21,   22,   56,    0,
257
    0,   75,    0,    0,  101,   56,    0,    0,    0,    0,
258
   56,   56,   56,   56,   56,    0,   56,   56,   56,   56,
259
   56,   56,  135,    0,    0,    0,    0,    0,   56,    0,
260
    0,    0,    0,    0,    0,    2,    3,    0,    4,    5,
261
    0,    6,    7,    8,    9,  140,   10,   11,    0,   12,
262
   13,   14,   15,   16,   93,   17,   18,   19,   20,   21,
263
   22,    0,   69,   94,   23,   13,   56,    0,   24,   69,
264
   25,    0,    0,    0,   69,   69,   69,   69,   69,    0,
265
   69,   69,   69,   69,   69,   69,   31,    0,    0,    0,
266
    0,    0,   69,   31,    0,    0,    0,    0,   31,   31,
267
   31,   31,   31,    0,   31,   31,   31,   31,   31,   31,
268
   63,    0,    0,    0,    0,    0,   31,   63,    0,    0,
269
    0,    0,   63,   63,   63,   63,   63,    0,   63,   63,
270
   63,   63,   63,   63,   75,    0,    0,    0,    0,    0,
271
   63,   75,    0,    0,    0,    0,   75,   75,   75,   75,
272
   75,    0,   75,   75,   75,   75,   75,   75,    0,    0,
273
    0,    0,    0,    0,   75,    0,    0,   12,   13,   14,
274
   15,   16,  133,   17,   18,   19,   20,   21,   22,    0,
275
    0,    0,    0,    0,    0,  134,    0,    0,    0,    0,
276
   12,   13,   14,   15,   16,  133,   17,   18,   19,   20,
277
   21,   22,    0,    0,    0,    0,    0,    0,  134,    0,
278
    0,   56,   56,   56,   56,   56,   56,   56,   56,   56,
279
   56,   56,   56,    0,    0,    0,    0,    0,    0,   56,
280
};
281
const short yycheck[] =
282
	{                                      10,
283
   10,  123,    1,  125,   87,    8,   10,   90,   86,  116,
284
  286,  284,  285,  125,  274,   10,  292,  274,  292,   97,
285
  262,  104,  129,  283,   10,  108,  283,  125,  287,  291,
286
  291,  266,  286,  292,  292,  291,  291,  120,  291,  122,
287
   44,  124,  292,  292,   47,  292,  258,  292,   10,  291,
288
  292,  125,  292,  265,  292,  138,   61,  291,  270,  271,
289
  272,  273,  274,  261,  276,  277,  278,  279,  280,  281,
290
  258,   10,   10,   10,   10,  125,  288,  265,   10,  269,
291
  123,  292,  270,  271,  272,  273,  274,  291,  276,  277,
292
  278,  279,  280,  281,   47,  292,   10,  291,  282,  292,
293
  288,   10,  291,  123,  291,  285,  292,  292,   10,  292,
294
  291,  123,  291,  261,  292,  291,  125,  123,   10,  100,
295
   11,  103,  141,  137,   -1,   -1,   -1,   -1,   -1,   -1,
296
   -1,  130,   -1,   -1,   -1,   -1,  258,   -1,  137,  125,
297
   -1,   -1,   -1,  265,   -1,   -1,   -1,   -1,  270,  271,
298
  272,  273,  274,  275,  276,  277,  278,  279,  280,  281,
299
  258,  283,  274,  125,   -1,   -1,  288,  265,   -1,   -1,
300
   -1,  283,  270,  271,  272,  273,  274,  275,  276,  277,
301
  278,  279,  280,  281,  258,   -1,   -1,  125,   -1,   -1,
302
  288,  265,   -1,   -1,   -1,   -1,  270,  271,  272,  273,
303
  274,   -1,  276,  277,  278,  279,  280,  281,  258,   -1,
304
   -1,  125,   -1,   -1,  288,  265,   -1,   -1,   -1,   -1,
305
  270,  271,  272,  273,  274,   -1,  276,  277,  278,  279,
306
  280,  281,  125,   -1,   -1,   -1,   -1,   -1,  288,   -1,
307
   -1,   -1,   -1,   -1,   -1,  256,  257,   -1,  259,  260,
308
   -1,  262,  263,  264,  265,  125,  267,  268,   -1,  270,
309
  271,  272,  273,  274,  274,  276,  277,  278,  279,  280,
310
  281,   -1,  258,  283,  285,  261,  125,   -1,  289,  265,
311
  291,   -1,   -1,   -1,  270,  271,  272,  273,  274,   -1,
312
  276,  277,  278,  279,  280,  281,  258,   -1,   -1,   -1,
313
   -1,   -1,  288,  265,   -1,   -1,   -1,   -1,  270,  271,
314
  272,  273,  274,   -1,  276,  277,  278,  279,  280,  281,
315
  258,   -1,   -1,   -1,   -1,   -1,  288,  265,   -1,   -1,
316
   -1,   -1,  270,  271,  272,  273,  274,   -1,  276,  277,
317
  278,  279,  280,  281,  258,   -1,   -1,   -1,   -1,   -1,
318
  288,  265,   -1,   -1,   -1,   -1,  270,  271,  272,  273,
319
  274,   -1,  276,  277,  278,  279,  280,  281,   -1,   -1,
320
   -1,   -1,   -1,   -1,  288,   -1,   -1,  270,  271,  272,
321
  273,  274,  275,  276,  277,  278,  279,  280,  281,   -1,
322
   -1,   -1,   -1,   -1,   -1,  288,   -1,   -1,   -1,   -1,
323
  270,  271,  272,  273,  274,  275,  276,  277,  278,  279,
324
  280,  281,   -1,   -1,   -1,   -1,   -1,   -1,  288,   -1,
325
   -1,  270,  271,  272,  273,  274,  275,  276,  277,  278,
326
  279,  280,  281,   -1,   -1,   -1,   -1,   -1,   -1,  288,
327
};
328
#define YYFINAL 1
329
#ifndef YYDEBUG
330
#define YYDEBUG 0
331
#endif
332
#define YYMAXTOKEN 292
333
#if YYDEBUG
334
const char * const yyname[] =
335
	{
336
"end-of-file",0,0,0,0,0,0,0,0,0,"'\\n'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
337
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,
338
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,
339
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,
340
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,
341
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,
342
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,"AREA",
343
"INTERFACE","ROUTERID","FIBUPDATE","REDISTRIBUTE","RTLABEL","RDOMAIN",
344
"RFC1583COMPAT","STUB","ROUTER","SPFDELAY","SPFHOLDTIME","EXTTAG","AUTHKEY",
345
"AUTHTYPE","AUTHMD","AUTHMDKEYID","METRIC","PASSIVE","HELLOINTERVAL",
346
"FASTHELLOINTERVAL","TRANSMITDELAY","RETRANSMITINTERVAL","ROUTERDEADTIME",
347
"ROUTERPRIORITY","SET","TYPE","YES","NO","MSEC","MINIMAL","DEMOTE","INCLUDE",
348
"ERROR","STRING","NUMBER",
349
};
350
const char * const yyrule[] =
351
	{"$accept : grammar",
352
"grammar :",
353
"grammar : grammar include '\\n'",
354
"grammar : grammar '\\n'",
355
"grammar : grammar conf_main '\\n'",
356
"grammar : grammar varset '\\n'",
357
"grammar : grammar area '\\n'",
358
"grammar : grammar error '\\n'",
359
"include : INCLUDE STRING",
360
"string : string STRING",
361
"string : STRING",
362
"yesno : YES",
363
"yesno : NO",
364
"no :",
365
"no : NO",
366
"msec : MSEC NUMBER",
367
"msec : NUMBER",
368
"varset : STRING '=' string",
369
"conf_main : ROUTERID STRING",
370
"conf_main : FIBUPDATE yesno",
371
"conf_main : redistribute",
372
"conf_main : RTLABEL STRING EXTTAG NUMBER",
373
"conf_main : RDOMAIN NUMBER",
374
"conf_main : RFC1583COMPAT yesno",
375
"conf_main : SPFDELAY msec",
376
"conf_main : SPFHOLDTIME msec",
377
"conf_main : STUB ROUTER yesno",
378
"conf_main : defaults",
379
"redistribute : no REDISTRIBUTE NUMBER '/' NUMBER optlist",
380
"redistribute : no REDISTRIBUTE STRING optlist",
381
"redistribute : no REDISTRIBUTE RTLABEL STRING optlist",
382
"optlist :",
383
"optlist : SET option",
384
"optlist : SET optnl '{' optnl optlist_l optnl '}'",
385
"optlist_l : optlist_l comma option",
386
"optlist_l : option",
387
"option : METRIC NUMBER",
388
"option : TYPE NUMBER",
389
"authmd : AUTHMD NUMBER STRING",
390
"authmdkeyid : AUTHMDKEYID NUMBER",
391
"authtype : AUTHTYPE STRING",
392
"authkey : AUTHKEY STRING",
393
"defaults : METRIC NUMBER",
394
"defaults : ROUTERPRIORITY NUMBER",
395
"defaults : ROUTERDEADTIME deadtime",
396
"defaults : TRANSMITDELAY NUMBER",
397
"defaults : HELLOINTERVAL NUMBER",
398
"defaults : FASTHELLOINTERVAL MSEC NUMBER",
399
"defaults : RETRANSMITINTERVAL NUMBER",
400
"defaults : authtype",
401
"defaults : authkey",
402
"defaults : authmdkeyid",
403
"defaults : authmd",
404
"deadtime : NUMBER",
405
"deadtime : MINIMAL",
406
"optnl : '\\n' optnl",
407
"optnl :",
408
"nl : '\\n' optnl",
409
"comma : ','",
410
"comma :",
411
"$$1 :",
412
"area : AREA STRING $$1 '{' optnl areaopts_l '}'",
413
"demotecount : NUMBER",
414
"demotecount :",
415
"areaopts_l : areaopts_l areaoptsl nl",
416
"areaopts_l : areaoptsl optnl",
417
"areaoptsl : interface",
418
"areaoptsl : DEMOTE STRING demotecount",
419
"areaoptsl : defaults",
420
"areaoptsl : STUB",
421
"areaoptsl : STUB redistribute",
422
"$$2 :",
423
"interface : INTERFACE STRING $$2 interface_block",
424
"interface_block : '{' optnl interfaceopts_l '}'",
425
"interface_block : '{' optnl '}'",
426
"interface_block :",
427
"interfaceopts_l : interfaceopts_l interfaceoptsl nl",
428
"interfaceopts_l : interfaceoptsl optnl",
429
"interfaceoptsl : PASSIVE",
430
"interfaceoptsl : DEMOTE STRING",
431
"interfaceoptsl : defaults",
432
};
433
#endif
434
#ifdef YYSTACKSIZE
435
#undef YYMAXDEPTH
436
#define YYMAXDEPTH YYSTACKSIZE
437
#else
438
#ifdef YYMAXDEPTH
439
#define YYSTACKSIZE YYMAXDEPTH
440
#else
441
#define YYSTACKSIZE 10000
442
#define YYMAXDEPTH 10000
443
#endif
444
#endif
445
#define YYINITSTACKSIZE 200
446
/* LINTUSED */
447
int yydebug;
448
int yynerrs;
449
int yyerrflag;
450
int yychar;
451

48
short *yyssp;
452
YYSTYPE *yyvsp;
453
YYSTYPE yyval;
454
YYSTYPE yylval;
455
short *yyss;
456
24
short *yysslim;
457
YYSTYPE *yyvs;
458
24
unsigned int yystacksize;
459

48
int yyparse(void);
460
#line 700 "parse.y"
461
462
struct keywords {
463
	const char	*k_name;
464
24
	int		 k_val;
465
};
466
24
467
24
int
468
yyerror(const char *fmt, ...)
469
24
{
470
	va_list		 ap;
471
	char		*msg;
472
473
	file->errors++;
474
	va_start(ap, fmt);
475
	if (vasprintf(&msg, fmt, ap) == -1)
476
		fatalx("yyerror vasprintf");
477
	va_end(ap);
478
	logit(LOG_CRIT, "%s:%d: %s", file->name, yylval.lineno, msg);
479

48
	free(msg);
480
24
	return (0);
481
}
482
483
int
484
kw_cmp(const void *k, const void *e)
485
24
{
486
	return (strcmp(k, ((const struct keywords *)e)->k_name));
487
24
}
488
489
int
490
lookup(char *s)
491
{
492
	/* this has to be sorted always */
493
	static const struct keywords keywords[] = {
494
		{"area",		AREA},
495
		{"auth-key",		AUTHKEY},
496
		{"auth-md",		AUTHMD},
497
		{"auth-md-keyid",	AUTHMDKEYID},
498
		{"auth-type",		AUTHTYPE},
499
		{"demote",		DEMOTE},
500
		{"external-tag",	EXTTAG},
501
		{"fast-hello-interval",	FASTHELLOINTERVAL},
502
		{"fib-update",		FIBUPDATE},
503
		{"hello-interval",	HELLOINTERVAL},
504
		{"include",		INCLUDE},
505
		{"interface",		INTERFACE},
506
		{"metric",		METRIC},
507
		{"minimal",		MINIMAL},
508
		{"msec",		MSEC},
509
		{"no",			NO},
510
		{"passive",		PASSIVE},
511
		{"rdomain",		RDOMAIN},
512
		{"redistribute",	REDISTRIBUTE},
513

48
		{"retransmit-interval",	RETRANSMITINTERVAL},
514
		{"rfc1583compat",	RFC1583COMPAT},
515
		{"router",		ROUTER},
516
		{"router-dead-time",	ROUTERDEADTIME},
517
		{"router-id",		ROUTERID},
518
24
		{"router-priority",	ROUTERPRIORITY},
519
		{"rtlabel",		RTLABEL},
520
24
		{"set",			SET},
521
		{"spf-delay",		SPFDELAY},
522
		{"spf-holdtime",	SPFHOLDTIME},
523
		{"stub",		STUB},
524
		{"transmit-delay",	TRANSMITDELAY},
525
		{"type",		TYPE},
526
		{"yes",			YES}
527
	};
528
	const struct keywords	*p;
529
530
	p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
531
	    sizeof(keywords[0]), kw_cmp);
532
533
	if (p)
534
		return (p->k_val);
535
	else
536
24
		return (STRING);
537
24
}
538
539
#define MAXPUSHBACK	128
540
541
u_char	*parsebuf;
542
24
int	 parseindex;
543
24
u_char	 pushback_buffer[MAXPUSHBACK];
544
int	 pushback_index = 0;
545
24
546
24
int
547
24
lgetc(int quotec)
548
48
{
549
24
	int		c, next;
550
24
551
24
	if (parsebuf) {
552
		/* Read character from the parsebuffer instead of input. */
553
24
		if (parseindex >= 0) {
554
			c = parsebuf[parseindex++];
555
			if (c != '\0')
556
				return (c);
557
			parsebuf = NULL;
558
		} else
559
			parseindex++;
560
	}
561
562
	if (pushback_index)
563
		return (pushback_buffer[--pushback_index]);
564
565
	if (quotec) {
566
		if ((c = getc(file->stream)) == EOF) {
567
			yyerror("reached end of file while parsing "
568
			    "quoted string");
569
			if (file == topfile || popfile() == EOF)
570
				return (EOF);
571
			return (quotec);
572
		}
573
		return (c);
574
	}
575
576
	while ((c = getc(file->stream)) == '\\') {
577
		next = getc(file->stream);
578
		if (next != '\n') {
579
			c = next;
580
			break;
581
		}
582
		yylval.lineno = file->lineno;
583
		file->lineno++;
584
	}
585
586
	while (c == EOF) {
587
		if (file == topfile || popfile() == EOF)
588
			return (EOF);
589
		c = getc(file->stream);
590
	}
591
	return (c);
592
}
593
594
int
595
lungetc(int c)
596
{
597
	if (c == EOF)
598
		return (EOF);
599
	if (parsebuf) {
600
		parseindex--;
601
		if (parseindex >= 0)
602
			return (c);
603
	}
604
	if (pushback_index < MAXPUSHBACK-1)
605
		return (pushback_buffer[pushback_index++] = c);
606
24
	else
607
		return (EOF);
608
24
}
609
610
24
int
611
24
findeol(void)
612
24
{
613
24
	int	c;
614
615
	parsebuf = NULL;
616
617
	/* skip to either EOF or the first real EOL */
618
	while (1) {
619
		if (pushback_index)
620
			c = pushback_buffer[--pushback_index];
621
		else
622
24
			c = lgetc(0);
623
		if (c == '\n') {
624
			file->lineno++;
625
			break;
626
		}
627
24
		if (c == EOF)
628
			break;
629
	}
630
	return (ERROR);
631
}
632
633
int
634
yylex(void)
635
{
636
24
	u_char	 buf[8096];
637
24
	u_char	*p, *val;
638
24
	int	 quotec, next, c;
639
	int	 token;
640
24
641
48
top:
642
	p = buf;
643
24
	while ((c = lgetc(0)) == ' ' || c == '\t')
644
24
		; /* nothing */
645
24
646
48
	yylval.lineno = file->lineno;
647
24
	if (c == '#')
648
24
		while ((c = lgetc(0)) != '\n' && c != EOF)
649
24
			; /* nothing */
650
24
	if (c == '$' && parsebuf == NULL) {
651
		while (1) {
652
			if ((c = lgetc(0)) == EOF)
653
24
				return (0);
654
24
655
24
			if (p + 1 >= buf + sizeof(buf) - 1) {
656
24
				yyerror("string too long");
657
24
				return (findeol());
658
24
			}
659
24
			if (isalnum(c) || c == '_') {
660
				*p++ = c;
661
24
				continue;
662
24
			}
663
24
			*p = '\0';
664
			lungetc(c);
665
24
			break;
666
		}
667
24
		val = symget(buf);
668
		if (val == NULL) {
669
			yyerror("macro '%s' not defined", buf);
670
			return (findeol());
671
		}
672
		parsebuf = val;
673
		parseindex = 0;
674
		goto top;
675
	}
676
677
	switch (c) {
678
	case '\'':
679
	case '"':
680
		quotec = c;
681
		while (1) {
682
			if ((c = lgetc(quotec)) == EOF)
683
				return (0);
684
			if (c == '\n') {
685
				file->lineno++;
686
				continue;
687
			} else if (c == '\\') {
688
				if ((next = lgetc(quotec)) == EOF)
689
					return (0);
690
				if (next == quotec || c == ' ' || c == '\t')
691
					c = next;
692
				else if (next == '\n') {
693
					file->lineno++;
694
					continue;
695
				} else
696
					lungetc(next);
697
			} else if (c == quotec) {
698
				*p = '\0';
699
				break;
700
			} else if (c == '\0') {
701
				yyerror("syntax error");
702
				return (findeol());
703
			}
704
			if (p + 1 >= buf + sizeof(buf) - 1) {
705
				yyerror("string too long");
706
				return (findeol());
707
			}
708
			*p++ = c;
709
		}
710
		yylval.v.string = strdup(buf);
711
		if (yylval.v.string == NULL)
712
			err(1, "yylex: strdup");
713
		return (STRING);
714
	}
715
716
#define allowed_to_end_number(x) \
717
	(isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=')
718
719
	if (c == '-' || isdigit(c)) {
720
		do {
721
			*p++ = c;
722
			if ((unsigned)(p-buf) >= sizeof(buf)) {
723
				yyerror("string too long");
724
				return (findeol());
725
			}
726
		} while ((c = lgetc(0)) != EOF && isdigit(c));
727
		lungetc(c);
728
		if (p == buf + 1 && buf[0] == '-')
729
			goto nodigits;
730
		if (c == EOF || allowed_to_end_number(c)) {
731
			const char *errstr = NULL;
732
733
			*p = '\0';
734
			yylval.v.number = strtonum(buf, LLONG_MIN,
735
			    LLONG_MAX, &errstr);
736
			if (errstr) {
737
				yyerror("\"%s\" invalid number: %s",
738
				    buf, errstr);
739
				return (findeol());
740
			}
741
			return (NUMBER);
742
		} else {
743
nodigits:
744
			while (p > buf + 1)
745
				lungetc(*--p);
746
			c = *--p;
747
			if (c == '-')
748
				return (c);
749
		}
750
	}
751
752
#define allowed_in_string(x) \
753
	(isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \
754
	x != '{' && x != '}' && \
755
	x != '!' && x != '=' && x != '#' && \
756
	x != ','))
757
758
	if (isalnum(c) || c == ':' || c == '_') {
759
		do {
760
			*p++ = c;
761
			if ((unsigned)(p-buf) >= sizeof(buf)) {
762
				yyerror("string too long");
763
				return (findeol());
764
			}
765
		} while ((c = lgetc(0)) != EOF && (allowed_in_string(c)));
766
		lungetc(c);
767
		*p = '\0';
768
		if ((token = lookup(buf)) == STRING)
769
			if ((yylval.v.string = strdup(buf)) == NULL)
770
				err(1, "yylex: strdup");
771
		return (token);
772
	}
773
	if (c == '\n') {
774
		yylval.lineno = file->lineno;
775
		file->lineno++;
776
	}
777
	if (c == EOF)
778
		return (0);
779
	return (c);
780
}
781
782
int
783
check_file_secrecy(int fd, const char *fname)
784
{
785
	struct stat	st;
786
787
	if (fstat(fd, &st)) {
788
		log_warn("cannot stat %s", fname);
789
		return (-1);
790
	}
791
	if (st.st_uid != 0 && st.st_uid != getuid()) {
792
		log_warnx("%s: owner not root or current user", fname);
793
		return (-1);
794
	}
795
	if (st.st_mode & (S_IWGRP | S_IXGRP | S_IRWXO)) {
796
		log_warnx("%s: group writable or world read/writable", fname);
797
		return (-1);
798
	}
799
	return (0);
800
}
801
802
struct file *
803
pushfile(const char *name, int secret)
804
{
805
	struct file	*nfile;
806
807
	if ((nfile = calloc(1, sizeof(struct file))) == NULL) {
808
		log_warn("malloc");
809
		return (NULL);
810
	}
811
	if ((nfile->name = strdup(name)) == NULL) {
812
		log_warn("malloc");
813
		free(nfile);
814
		return (NULL);
815
	}
816
	if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
817
		log_warn("%s", nfile->name);
818
		free(nfile->name);
819
		free(nfile);
820
		return (NULL);
821
	} else if (secret &&
822
	    check_file_secrecy(fileno(nfile->stream), nfile->name)) {
823
		fclose(nfile->stream);
824
		free(nfile->name);
825
		free(nfile);
826
		return (NULL);
827
	}
828
	nfile->lineno = 1;
829
	TAILQ_INSERT_TAIL(&files, nfile, entry);
830
	return (nfile);
831
}
832
833
int
834
popfile(void)
835
{
836
	struct file	*prev;
837
838
	if ((prev = TAILQ_PREV(file, files, entry)) != NULL)
839
		prev->errors += file->errors;
840
841
	TAILQ_REMOVE(&files, file, entry);
842
	fclose(file->stream);
843
	free(file->name);
844
	free(file);
845
	file = prev;
846
	return (file ? 0 : EOF);
847
}
848
849
struct ospfd_conf *
850
parse_config(char *filename, int opts)
851
{
852
	struct sym	*sym, *next;
853
854
	if ((conf = calloc(1, sizeof(struct ospfd_conf))) == NULL)
855
		fatal("parse_config");
856
	conf->opts = opts;
857
	if (conf->opts & OSPFD_OPT_STUB_ROUTER)
858
		conf->flags |= OSPFD_FLAG_STUB_ROUTER;
859
860
	bzero(&globaldefs, sizeof(globaldefs));
861
	defs = &globaldefs;
862
	TAILQ_INIT(&defs->md_list);
863
	defs->dead_interval = DEFAULT_RTR_DEAD_TIME;
864
	defs->fast_hello_interval = DEFAULT_FAST_INTERVAL;
865
	defs->transmit_delay = DEFAULT_TRANSMIT_DELAY;
866
	defs->hello_interval = DEFAULT_HELLO_INTERVAL;
867
	defs->rxmt_interval = DEFAULT_RXMT_INTERVAL;
868
	defs->metric = DEFAULT_METRIC;
869
	defs->priority = DEFAULT_PRIORITY;
870
871
	conf->spf_delay = DEFAULT_SPF_DELAY;
872
	conf->spf_hold_time = DEFAULT_SPF_HOLDTIME;
873
	conf->spf_state = SPF_IDLE;
874
875
	if ((file = pushfile(filename, !(conf->opts & OSPFD_OPT_NOACTION))) == NULL) {
876
		free(conf);
877
		return (NULL);
878
	}
879
	topfile = file;
880
881
	LIST_INIT(&conf->area_list);
882
	LIST_INIT(&conf->cand_list);
883
	SIMPLEQ_INIT(&conf->redist_list);
884
885
	yyparse();
886
	errors = file->errors;
887
	popfile();
888
889
	/* Free macros and check which have not been used. */
890
	TAILQ_FOREACH_SAFE(sym, &symhead, entry, next) {
891
		if ((conf->opts & OSPFD_OPT_VERBOSE2) && !sym->used)
892
			fprintf(stderr, "warning: macro '%s' not "
893
			    "used\n", sym->nam);
894
		if (!sym->persist) {
895
			free(sym->nam);
896
			free(sym->val);
897
			TAILQ_REMOVE(&symhead, sym, entry);
898
			free(sym);
899
		}
900
	}
901
902
	/* free global config defaults */
903
	md_list_clr(&globaldefs.md_list);
904
905
	/* check that all interfaces belong to the configured rdomain */
906
	errors += conf_check_rdomain(conf->rdomain);
907
908
	if (errors) {
909
		clear_config(conf);
910
		return (NULL);
911
	}
912
913
	if (conf->rtr_id.s_addr == 0)
914
		conf->rtr_id.s_addr = get_rtr_id();
915
916
	return (conf);
917
}
918
919
int
920
symset(const char *nam, const char *val, int persist)
921
{
922
	struct sym	*sym;
923
924
	TAILQ_FOREACH(sym, &symhead, entry) {
925
		if (strcmp(nam, sym->nam) == 0)
926
			break;
927
	}
928
929
	if (sym != NULL) {
930
		if (sym->persist == 1)
931
			return (0);
932
		else {
933
			free(sym->nam);
934
			free(sym->val);
935
			TAILQ_REMOVE(&symhead, sym, entry);
936
			free(sym);
937
		}
938
	}
939
	if ((sym = calloc(1, sizeof(*sym))) == NULL)
940
		return (-1);
941
942
	sym->nam = strdup(nam);
943
	if (sym->nam == NULL) {
944
		free(sym);
945
		return (-1);
946
	}
947
	sym->val = strdup(val);
948
	if (sym->val == NULL) {
949
		free(sym->nam);
950
		free(sym);
951
		return (-1);
952
	}
953
	sym->used = 0;
954
	sym->persist = persist;
955
	TAILQ_INSERT_TAIL(&symhead, sym, entry);
956
	return (0);
957
}
958
959
int
960
cmdline_symset(char *s)
961
{
962
	char	*sym, *val;
963
	int	ret;
964
	size_t	len;
965
966
	if ((val = strrchr(s, '=')) == NULL)
967
		return (-1);
968
969
	len = strlen(s) - strlen(val) + 1;
970
	if ((sym = malloc(len)) == NULL)
971
		errx(1, "cmdline_symset: malloc");
972
973
	strlcpy(sym, s, len);
974
975
	ret = symset(sym, val + 1, 1);
976
	free(sym);
977
978
	return (ret);
979
}
980
981
char *
982
symget(const char *nam)
983
{
984
	struct sym	*sym;
985
986
	TAILQ_FOREACH(sym, &symhead, entry) {
987
		if (strcmp(nam, sym->nam) == 0) {
988
			sym->used = 1;
989
			return (sym->val);
990
		}
991
	}
992
	return (NULL);
993
}
994
995
struct area *
996
conf_get_area(struct in_addr id)
997
{
998
	struct area	*a;
999
1000
	a = area_find(conf, id);
1001
	if (a)
1002
		return (a);
1003
	a = area_new();
1004
	LIST_INSERT_HEAD(&conf->area_list, a, entry);
1005
1006
	a->id.s_addr = id.s_addr;
1007
1008
	return (a);
1009
}
1010
1011
struct iface *
1012
conf_get_if(struct kif *kif, struct kif_addr *ka)
1013
{
1014
	struct area	*a;
1015
	struct iface	*i;
1016
1017
	LIST_FOREACH(a, &conf->area_list, entry)
1018
		LIST_FOREACH(i, &a->iface_list, entry)
1019
			if (i->ifindex == kif->ifindex &&
1020
			    i->addr.s_addr == ka->addr.s_addr) {
1021
				yyerror("interface %s already configured",
1022
				    kif->ifname);
1023
				return (NULL);
1024
			}
1025
1026
	i = if_new(kif, ka);
1027
	i->auth_keyid = 1;
1028
1029
	return (i);
1030
}
1031
1032
int
1033
conf_check_rdomain(unsigned int rdomain)
1034
{
1035
	struct area	*a;
1036
	struct iface	*i;
1037
	int		 errs = 0;
1038
1039
	LIST_FOREACH(a, &conf->area_list, entry)
1040
		LIST_FOREACH(i, &a->iface_list, entry)
1041
			if (i->rdomain != rdomain) {
1042
				logit(LOG_CRIT,
1043
				    "interface %s not in rdomain %u",
1044
				    i->name, rdomain);
1045
				errs++;
1046
			}
1047
1048
	return (errs);
1049
}
1050
1051
void
1052
clear_config(struct ospfd_conf *xconf)
1053
{
1054
	struct area	*a;
1055
1056
	while ((a = LIST_FIRST(&xconf->area_list)) != NULL) {
1057
		LIST_REMOVE(a, entry);
1058
		area_del(a);
1059
	}
1060
1061
	free(xconf);
1062
}
1063
1064
u_int32_t
1065
get_rtr_id(void)
1066
{
1067
	struct ifaddrs		*ifap, *ifa;
1068
	u_int32_t		 ip = 0, cur, localnet;
1069
1070
	localnet = htonl(INADDR_LOOPBACK & IN_CLASSA_NET);
1071
1072
	if (getifaddrs(&ifap) == -1)
1073
		fatal("getifaddrs");
1074
1075
	for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
1076
		if (strncmp(ifa->ifa_name, "carp", 4) == 0)
1077
			continue;
1078
		if (ifa->ifa_addr->sa_family != AF_INET)
1079
			continue;
1080
		cur = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
1081
		if ((cur & localnet) == localnet)	/* skip 127/8 */
1082
			continue;
1083
		if (ntohl(cur) < ntohl(ip) || ip == 0)
1084
			ip = cur;
1085
	}
1086
	freeifaddrs(ifap);
1087
1088
	if (ip == 0)
1089
		fatal("router-id is 0.0.0.0");
1090
1091
	return (ip);
1092
}
1093
1094
int
1095
host(const char *s, struct in_addr *addr, struct in_addr *mask)
1096
{
1097
	struct in_addr		 ina;
1098
	int			 bits = 32;
1099
1100
	bzero(&ina, sizeof(struct in_addr));
1101
	if (strrchr(s, '/') != NULL) {
1102
		if ((bits = inet_net_pton(AF_INET, s, &ina, sizeof(ina))) == -1)
1103
			return (0);
1104
	} else {
1105
		if (inet_pton(AF_INET, s, &ina) != 1)
1106
			return (0);
1107
	}
1108
1109
	addr->s_addr = ina.s_addr;
1110
	mask->s_addr = prefixlen2mask(bits);
1111
1112
	return (1);
1113
}
1114
#line 1107 "parse.c"
1115
48
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
1116
24
static int yygrowstack(void)
1117
{
1118
    unsigned int newsize;
1119
    long sslen;
1120
    short *newss;
1121
24
    YYSTYPE *newvs;
1122
1123
    if ((newsize = yystacksize) == 0)
1124
        newsize = YYINITSTACKSIZE;
1125
    else if (newsize >= YYMAXDEPTH)
1126
        return -1;
1127

48
    else if ((newsize *= 2) > YYMAXDEPTH)
1128
        newsize = YYMAXDEPTH;
1129
48
    sslen = yyssp - yyss;
1130
24
#ifdef SIZE_MAX
1131
24
#define YY_SIZE_MAX SIZE_MAX
1132
#else
1133
24
#define YY_SIZE_MAX 0xffffffffU
1134
24
#endif
1135

48
    if (newsize && YY_SIZE_MAX / newsize < sizeof *newss)
1136
        goto bail;
1137
48
    newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :
1138
24
      (short *)malloc(newsize * sizeof *newss); /* overflow check above */
1139
24
    if (newss == NULL)
1140
        goto bail;
1141
24
    yyss = newss;
1142
24
    yyssp = newss + sslen;
1143
24
    if (newsize && YY_SIZE_MAX / newsize < sizeof *newvs)
1144
24
        goto bail;
1145
24
    newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :
1146
      (YYSTYPE *)malloc(newsize * sizeof *newvs); /* overflow check above */
1147
    if (newvs == NULL)
1148
        goto bail;
1149
    yyvs = newvs;
1150
    yyvsp = newvs + sslen;
1151
    yystacksize = newsize;
1152
    yysslim = yyss + newsize - 1;
1153
    return 0;
1154
bail:
1155
24
    if (yyss)
1156
            free(yyss);
1157
    if (yyvs)
1158
            free(yyvs);
1159
    yyss = yyssp = NULL;
1160
    yyvs = yyvsp = NULL;
1161
    yystacksize = 0;
1162
    return -1;
1163
}
1164
1165
#define YYABORT goto yyabort
1166
#define YYREJECT goto yyabort
1167
#define YYACCEPT goto yyaccept
1168
#define YYERROR goto yyerrlab
1169
int
1170
yyparse(void)
1171
{
1172
    int yym, yyn, yystate;
1173
#if YYDEBUG
1174
    const char *yys;
1175
1176
48
    if ((yys = getenv("YYDEBUG")))
1177
24
    {
1178
24
        yyn = *yys;
1179
        if (yyn >= '0' && yyn <= '9')
1180

48
            yydebug = yyn - '0';
1181
24
    }
1182
24
#endif /* YYDEBUG */
1183
24
1184
    yynerrs = 0;
1185
    yyerrflag = 0;
1186
1560
    yychar = (-1);
1187
816
1188
    if (yyss == NULL && yygrowstack()) goto yyoverflow;
1189
600
    yyssp = yyss;
1190
    yyvsp = yyvs;
1191
    *yyssp = yystate = 0;
1192
1193
yyloop:
1194
    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
1195
    if (yychar < 0)
1196
    {
1197
        if ((yychar = yylex()) < 0) yychar = 0;
1198
#if YYDEBUG
1199
        if (yydebug)
1200
600
        {
1201

3264
            yys = 0;
1202
1632
            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1203
            if (!yys) yys = "illegal-symbol";
1204
            printf("%sdebug: state %d, reading %d (%s)\n",
1205
                    YYPREFIX, yystate, yychar, yys);
1206
        }
1207
#endif
1208
    }
1209

648
    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
1210
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1211
    {
1212
#if YYDEBUG
1213
648
        if (yydebug)
1214
648
            printf("%sdebug: state %d, shifting to state %d\n",
1215
648
                    YYPREFIX, yystate, yytable[yyn]);
1216
648
#endif
1217
648
        if (yyssp >= yysslim && yygrowstack())
1218
        {
1219

672
            goto yyoverflow;
1220
336
        }
1221
        *++yyssp = yystate = yytable[yyn];
1222
168
        *++yyvsp = yylval;
1223
168
        yychar = (-1);
1224
        if (yyerrflag > 0)  --yyerrflag;
1225
        goto yyloop;
1226
    }
1227
    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
1228
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1229
    {
1230
        yyn = yytable[yyn];
1231
        goto yyreduce;
1232
    }
1233
    if (yyerrflag) goto yyinrecovery;
1234
#if defined(__GNUC__)
1235
    goto yynewerror;
1236
#endif
1237
yynewerror:
1238
    yyerror("syntax error");
1239
#if defined(__GNUC__)
1240
    goto yyerrlab;
1241
#endif
1242
yyerrlab:
1243
    ++yynerrs;
1244
yyinrecovery:
1245
    if (yyerrflag < 3)
1246
    {
1247
        yyerrflag = 3;
1248
        for (;;)
1249
        {
1250
            if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
1251
                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
1252
            {
1253
#if YYDEBUG
1254
                if (yydebug)
1255
                    printf("%sdebug: state %d, error recovery shifting\
1256
 to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
1257
#endif
1258
                if (yyssp >= yysslim && yygrowstack())
1259
                {
1260
                    goto yyoverflow;
1261
                }
1262
                *++yyssp = yystate = yytable[yyn];
1263
                *++yyvsp = yylval;
1264
                goto yyloop;
1265
            }
1266
            else
1267
            {
1268
#if YYDEBUG
1269
                if (yydebug)
1270
                    printf("%sdebug: error recovery discarding state %d\n",
1271
                            YYPREFIX, *yyssp);
1272
#endif
1273
                if (yyssp <= yyss) goto yyabort;
1274
                --yyssp;
1275
                --yyvsp;
1276
            }
1277
        }
1278
    }
1279
    else
1280
    {
1281
        if (yychar == 0) goto yyabort;
1282
#if YYDEBUG
1283
        if (yydebug)
1284
        {
1285
            yys = 0;
1286
            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1287
            if (!yys) yys = "illegal-symbol";
1288
            printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
1289
                    YYPREFIX, yystate, yychar, yys);
1290
        }
1291
#endif
1292
        yychar = (-1);
1293
912
        goto yyloop;
1294
912
    }
1295
672
yyreduce:
1296
#if YYDEBUG
1297
240
    if (yydebug)
1298













1152
        printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1299
                YYPREFIX, yystate, yyn, yyrule[yyn]);
1300
#endif
1301
    yym = yylen[yyn];
1302
    if (yym)
1303
        yyval = yyvsp[1-yym];
1304
    else
1305
        memset(&yyval, 0, sizeof yyval);
1306
    switch (yyn)
1307
    {
1308
case 7:
1309
#line 150 "parse.y"
1310
{ file->errors++; }
1311
break;
1312
case 8:
1313
#line 153 "parse.y"
1314
{
1315
			struct file	*nfile;
1316
1317
			if ((nfile = pushfile(yyvsp[0].v.string, 1)) == NULL) {
1318
				yyerror("failed to include file %s", yyvsp[0].v.string);
1319
				free(yyvsp[0].v.string);
1320
				YYERROR;
1321
			}
1322
			free(yyvsp[0].v.string);
1323
1324
			file = nfile;
1325
			lungetc('\n');
1326
		}
1327
break;
1328
case 9:
1329
#line 168 "parse.y"
1330
{
1331
			if (asprintf(&yyval.v.string, "%s %s", yyvsp[-1].v.string, yyvsp[0].v.string) == -1) {
1332
				free(yyvsp[-1].v.string);
1333
				free(yyvsp[0].v.string);
1334
				yyerror("string: asprintf");
1335
				YYERROR;
1336
			}
1337
			free(yyvsp[-1].v.string);
1338
			free(yyvsp[0].v.string);
1339
		}
1340
break;
1341
case 11:
1342
#line 181 "parse.y"
1343
{ yyval.v.number = 1; }
1344
break;
1345
case 12:
1346
#line 182 "parse.y"
1347
{ yyval.v.number = 0; }
1348
break;
1349
case 13:
1350
#line 185 "parse.y"
1351
{ yyval.v.number = 0; }
1352
break;
1353
case 14:
1354
#line 186 "parse.y"
1355
{ yyval.v.number = 1; }
1356
break;
1357
case 15:
1358
#line 189 "parse.y"
1359
{
1360
			yyval.v.number = yyvsp[0].v.number;
1361
		}
1362
break;
1363
case 16:
1364
#line 192 "parse.y"
1365
{
1366
			yyval.v.number = yyvsp[0].v.number * 1000;
1367
		}
1368
break;
1369
case 17:
1370
#line 197 "parse.y"
1371
{
1372
			char *s = yyvsp[-2].v.string;
1373
			if (conf->opts & OSPFD_OPT_VERBOSE)
1374
				printf("%s = \"%s\"\n", yyvsp[-2].v.string, yyvsp[0].v.string);
1375
			while (*s++) {
1376
				if (isspace((unsigned char)*s)) {
1377
					yyerror("macro name cannot contain "
1378
					    "whitespace");
1379
					YYERROR;
1380
				}
1381
			}
1382
			if (symset(yyvsp[-2].v.string, yyvsp[0].v.string, 0) == -1)
1383
				fatal("cannot store variable");
1384
			free(yyvsp[-2].v.string);
1385
			free(yyvsp[0].v.string);
1386
		}
1387
break;
1388
case 18:
1389
#line 215 "parse.y"
1390
{
1391
			if (!inet_aton(yyvsp[0].v.string, &conf->rtr_id)) {
1392
				yyerror("error parsing router-id");
1393
				free(yyvsp[0].v.string);
1394
				YYERROR;
1395
			}
1396
			free(yyvsp[0].v.string);
1397
		}
1398
break;
1399
case 19:
1400
#line 223 "parse.y"
1401
{
1402
			if (yyvsp[0].v.number == 0)
1403
				conf->flags |= OSPFD_FLAG_NO_FIB_UPDATE;
1404
			else
1405
				conf->flags &= ~OSPFD_FLAG_NO_FIB_UPDATE;
1406
		}
1407
break;
1408
case 20:
1409
#line 229 "parse.y"
1410
{
1411
			SIMPLEQ_INSERT_TAIL(&conf->redist_list, yyvsp[0].v.redist, entry);
1412
			conf->redistribute = 1;
1413
		}
1414
break;
1415
case 21:
1416
#line 233 "parse.y"
1417
{
1418
			if (yyvsp[0].v.number < 0 || yyvsp[0].v.number > UINT_MAX) {
1419
				yyerror("invalid external route tag");
1420
				free(yyvsp[-2].v.string);
1421
				YYERROR;
1422
			}
1423
			rtlabel_tag(rtlabel_name2id(yyvsp[-2].v.string), yyvsp[0].v.number);
1424
			free(yyvsp[-2].v.string);
1425
		}
1426
break;
1427
case 22:
1428
#line 242 "parse.y"
1429
{
1430
			if (yyvsp[0].v.number < 0 || yyvsp[0].v.number > RT_TABLEID_MAX) {
1431
				yyerror("invalid rdomain");
1432
				YYERROR;
1433
			}
1434
			conf->rdomain = yyvsp[0].v.number;
1435
		}
1436
break;
1437
case 23:
1438
#line 249 "parse.y"
1439
{
1440
			conf->rfc1583compat = yyvsp[0].v.number;
1441
		}
1442
break;
1443
case 24:
1444
#line 252 "parse.y"
1445
{
1446
			if (yyvsp[0].v.number < MIN_SPF_DELAY || yyvsp[0].v.number > MAX_SPF_DELAY) {
1447
				yyerror("spf-delay out of range "
1448
				    "(%d-%d)", MIN_SPF_DELAY,
1449
				    MAX_SPF_DELAY);
1450
				YYERROR;
1451
			}
1452
			conf->spf_delay = yyvsp[0].v.number;
1453
		}
1454
break;
1455
case 25:
1456
#line 261 "parse.y"
1457
{
1458
			if (yyvsp[0].v.number < MIN_SPF_HOLDTIME || yyvsp[0].v.number > MAX_SPF_HOLDTIME) {
1459
				yyerror("spf-holdtime out of range "
1460
				    "(%d-%d)", MIN_SPF_HOLDTIME,
1461
				    MAX_SPF_HOLDTIME);
1462
				YYERROR;
1463
			}
1464
			conf->spf_hold_time = yyvsp[0].v.number;
1465
		}
1466
break;
1467
case 26:
1468
#line 270 "parse.y"
1469
{
1470
			if (yyvsp[0].v.number)
1471
				conf->flags |= OSPFD_FLAG_STUB_ROUTER;
1472
			else
1473
				/* allow to force non stub mode */
1474
				conf->flags &= ~OSPFD_FLAG_STUB_ROUTER;
1475
		}
1476
break;
1477
case 28:
1478
#line 281 "parse.y"
1479
{
1480
			struct redistribute	*r;
1481
1482
			if ((r = calloc(1, sizeof(*r))) == NULL)
1483
				fatal(NULL);
1484
			r->type = REDIST_ADDR;
1485
			if (yyvsp[-3].v.number < 0 || yyvsp[-3].v.number > 255 || yyvsp[-1].v.number < 1 || yyvsp[-1].v.number > 32) {
1486
				yyerror("bad network: %llu/%llu", yyvsp[-3].v.number, yyvsp[-1].v.number);
1487
				free(r);
1488
				YYERROR;
1489
			}
1490
			r->addr.s_addr = htonl(yyvsp[-3].v.number << IN_CLASSA_NSHIFT);
1491
			r->mask.s_addr = prefixlen2mask(yyvsp[-1].v.number);
1492
1493
			if (yyvsp[-5].v.number)
1494
				r->type |= REDIST_NO;
1495
			r->metric = yyvsp[0].v.number;
1496
			yyval.v.redist = r;
1497
		}
1498
break;
1499
case 29:
1500
#line 300 "parse.y"
1501
{
1502
			struct redistribute	*r;
1503
1504
			if ((r = calloc(1, sizeof(*r))) == NULL)
1505
				fatal(NULL);
1506
			if (!strcmp(yyvsp[-1].v.string, "default"))
1507
				r->type = REDIST_DEFAULT;
1508
			else if (!strcmp(yyvsp[-1].v.string, "static"))
1509
				r->type = REDIST_STATIC;
1510
			else if (!strcmp(yyvsp[-1].v.string, "connected"))
1511
				r->type = REDIST_CONNECTED;
1512
			else if (host(yyvsp[-1].v.string, &r->addr, &r->mask))
1513
				r->type = REDIST_ADDR;
1514
			else {
1515
				yyerror("unknown redistribute type");
1516
				free(yyvsp[-1].v.string);
1517
				free(r);
1518
				YYERROR;
1519
			}
1520
1521
			if (yyvsp[-3].v.number)
1522
				r->type |= REDIST_NO;
1523
			r->metric = yyvsp[0].v.number;
1524
			free(yyvsp[-1].v.string);
1525
			yyval.v.redist = r;
1526
		}
1527
break;
1528
case 30:
1529
#line 326 "parse.y"
1530
{
1531
			struct redistribute	*r;
1532
1533
			if ((r = calloc(1, sizeof(*r))) == NULL)
1534
				fatal(NULL);
1535
			r->type = REDIST_LABEL;
1536
			r->label = rtlabel_name2id(yyvsp[-1].v.string);
1537
			if (yyvsp[-4].v.number)
1538
				r->type |= REDIST_NO;
1539
			r->metric = yyvsp[0].v.number;
1540
			free(yyvsp[-1].v.string);
1541
1542
			yyval.v.redist = r;
1543
		}
1544
break;
1545
case 31:
1546
#line 342 "parse.y"
1547
{ yyval.v.number = DEFAULT_REDIST_METRIC; }
1548
break;
1549
case 32:
1550
#line 343 "parse.y"
1551
{
1552
			yyval.v.number = yyvsp[0].v.number;
1553
			if ((yyval.v.number & LSA_METRIC_MASK) == 0)
1554
				yyval.v.number |= DEFAULT_REDIST_METRIC;
1555
		}
1556
break;
1557
case 33:
1558
#line 348 "parse.y"
1559
{
1560
			yyval.v.number = yyvsp[-2].v.number;
1561
			if ((yyval.v.number & LSA_METRIC_MASK) == 0)
1562
				yyval.v.number |= DEFAULT_REDIST_METRIC;
1563
		}
1564
break;
1565
case 34:
1566
#line 355 "parse.y"
1567
{
1568
			if (yyvsp[-2].v.number & LSA_ASEXT_E_FLAG && yyvsp[0].v.number & LSA_ASEXT_E_FLAG) {
1569
				yyerror("redistribute type already defined");
1570
				YYERROR;
1571
			}
1572
			if (yyvsp[-2].v.number & LSA_METRIC_MASK && yyvsp[0].v.number & LSA_METRIC_MASK) {
1573
				yyerror("redistribute metric already defined");
1574
				YYERROR;
1575
			}
1576
			yyval.v.number = yyvsp[-2].v.number | yyvsp[0].v.number;
1577
		}
1578
break;
1579
case 35:
1580
#line 366 "parse.y"
1581
{ yyval.v.number = yyvsp[0].v.number; }
1582
break;
1583
case 36:
1584
#line 369 "parse.y"
1585
{
1586
			if (yyvsp[0].v.number == 0 || yyvsp[0].v.number > MAX_METRIC) {
1587
				yyerror("invalid redistribute metric");
1588
				YYERROR;
1589
			}
1590
			yyval.v.number = yyvsp[0].v.number;
1591
		}
1592
break;
1593
case 37:
1594
#line 376 "parse.y"
1595
{
1596
			switch (yyvsp[0].v.number) {
1597
			case 1:
1598
				yyval.v.number = 0;
1599
				break;
1600
			case 2:
1601
				yyval.v.number = LSA_ASEXT_E_FLAG;
1602
				break;
1603
			default:
1604
				yyerror("only external type 1 and 2 allowed");
1605
				YYERROR;
1606
			}
1607
		}
1608
break;
1609
case 38:
1610
#line 391 "parse.y"
1611
{
1612
			if (yyvsp[-1].v.number < MIN_MD_ID || yyvsp[-1].v.number > MAX_MD_ID) {
1613
				yyerror("auth-md key-id out of range "
1614
				    "(%d-%d)", MIN_MD_ID, MAX_MD_ID);
1615
				free(yyvsp[0].v.string);
1616
				YYERROR;
1617
			}
1618
			if (strlen(yyvsp[0].v.string) > MD5_DIGEST_LENGTH) {
1619
				yyerror("auth-md key length out of range "
1620
				    "(max length %d)",
1621
				    MD5_DIGEST_LENGTH);
1622
				free(yyvsp[0].v.string);
1623
				YYERROR;
1624
			}
1625
			md_list_add(&defs->md_list, yyvsp[-1].v.number, yyvsp[0].v.string);
1626
			free(yyvsp[0].v.string);
1627
		}
1628
break;
1629
case 39:
1630
#line 409 "parse.y"
1631
{
1632
			if (yyvsp[0].v.number < MIN_MD_ID || yyvsp[0].v.number > MAX_MD_ID) {
1633
				yyerror("auth-md-keyid out of range "
1634
				    "(%d-%d)", MIN_MD_ID, MAX_MD_ID);
1635
				YYERROR;
1636
			}
1637
			defs->auth_keyid = yyvsp[0].v.number;
1638
		}
1639
break;
1640
case 40:
1641
#line 418 "parse.y"
1642
{
1643
			enum auth_type	type;
1644
1645
			if (!strcmp(yyvsp[0].v.string, "none"))
1646
				type = AUTH_NONE;
1647
			else if (!strcmp(yyvsp[0].v.string, "simple"))
1648
				type = AUTH_SIMPLE;
1649
			else if (!strcmp(yyvsp[0].v.string, "crypt"))
1650
				type = AUTH_CRYPT;
1651
			else {
1652
				yyerror("unknown auth-type");
1653
				free(yyvsp[0].v.string);
1654
				YYERROR;
1655
			}
1656
			free(yyvsp[0].v.string);
1657
			defs->auth_type = type;
1658
		}
1659
break;
1660
case 41:
1661
#line 437 "parse.y"
1662
{
1663
			if (strlen(yyvsp[0].v.string) > MAX_SIMPLE_AUTH_LEN) {
1664
				yyerror("auth-key too long (max length %d)",
1665
				    MAX_SIMPLE_AUTH_LEN);
1666
					free(yyvsp[0].v.string);
1667
					YYERROR;
1668
			}
1669
			strncpy(defs->auth_key, yyvsp[0].v.string,
1670
			    sizeof(defs->auth_key));
1671
			free(yyvsp[0].v.string);
1672
		}
1673
break;
1674
case 42:
1675
#line 450 "parse.y"
1676
{
1677
			if (yyvsp[0].v.number < MIN_METRIC || yyvsp[0].v.number > MAX_METRIC) {
1678
				yyerror("metric out of range (%d-%d)",
1679
				    MIN_METRIC, MAX_METRIC);
1680
				YYERROR;
1681
			}
1682
			defs->metric = yyvsp[0].v.number;
1683
		}
1684
break;
1685
case 43:
1686
#line 458 "parse.y"
1687
{
1688
			if (yyvsp[0].v.number < MIN_PRIORITY || yyvsp[0].v.number > MAX_PRIORITY) {
1689
				yyerror("router-priority out of range (%d-%d)",
1690
				    MIN_PRIORITY, MAX_PRIORITY);
1691
				YYERROR;
1692
			}
1693
			defs->priority = yyvsp[0].v.number;
1694
		}
1695
break;
1696
case 44:
1697
#line 466 "parse.y"
1698
{
1699
			defs->dead_interval = yyvsp[0].v.number;
1700
		}
1701
break;
1702
case 45:
1703
#line 469 "parse.y"
1704
{
1705
			if (yyvsp[0].v.number < MIN_TRANSMIT_DELAY ||
1706
			    yyvsp[0].v.number > MAX_TRANSMIT_DELAY) {
1707
				yyerror("transmit-delay out of range (%d-%d)",
1708
				    MIN_TRANSMIT_DELAY, MAX_TRANSMIT_DELAY);
1709
				YYERROR;
1710
			}
1711
			defs->transmit_delay = yyvsp[0].v.number;
1712
		}
1713
break;
1714
case 46:
1715
#line 478 "parse.y"
1716
{
1717
			if (yyvsp[0].v.number < MIN_HELLO_INTERVAL ||
1718
			    yyvsp[0].v.number > MAX_HELLO_INTERVAL) {
1719
				yyerror("hello-interval out of range (%d-%d)",
1720
				    MIN_HELLO_INTERVAL, MAX_HELLO_INTERVAL);
1721
				YYERROR;
1722
			}
1723
			defs->hello_interval = yyvsp[0].v.number;
1724
		}
1725
break;
1726
case 47:
1727
#line 487 "parse.y"
1728
{
1729
			if (yyvsp[0].v.number < MIN_FAST_INTERVAL ||
1730
			    yyvsp[0].v.number > MAX_FAST_INTERVAL) {
1731
				yyerror("fast-hello-interval msec out of "
1732
				    "range (%d-%d)", MIN_FAST_INTERVAL,
1733
				    MAX_FAST_INTERVAL);
1734
				YYERROR;
1735
			}
1736
			defs->fast_hello_interval = yyvsp[0].v.number;
1737
		}
1738
break;
1739
case 48:
1740
#line 497 "parse.y"
1741
{
1742
			if (yyvsp[0].v.number < MIN_RXMT_INTERVAL || yyvsp[0].v.number > MAX_RXMT_INTERVAL) {
1743
				yyerror("retransmit-interval out of range "
1744
				    "(%d-%d)", MIN_RXMT_INTERVAL,
1745
				    MAX_RXMT_INTERVAL);
1746
				YYERROR;
1747
			}
1748
			defs->rxmt_interval = yyvsp[0].v.number;
1749
		}
1750
break;
1751
case 53:
1752
#line 512 "parse.y"
1753
{
1754
			if (yyvsp[0].v.number < MIN_RTR_DEAD_TIME || yyvsp[0].v.number > MAX_RTR_DEAD_TIME) {
1755
				yyerror("router-dead-time out of range (%d-%d)",
1756
				    MIN_RTR_DEAD_TIME, MAX_RTR_DEAD_TIME);
1757
				YYERROR;
1758
			}
1759
			yyval.v.number = yyvsp[0].v.number;
1760
		}
1761
break;
1762
case 54:
1763
#line 520 "parse.y"
1764
{
1765
			yyval.v.number = FAST_RTR_DEAD_TIME;
1766
		}
1767
break;
1768
case 60:
1769
#line 535 "parse.y"
1770
{
1771
			struct in_addr	id;
1772
			if (inet_aton(yyvsp[0].v.string, &id) == 0) {
1773
				yyerror("error parsing area");
1774
				free(yyvsp[0].v.string);
1775
				YYERROR;
1776
			}
1777
			free(yyvsp[0].v.string);
1778
			area = conf_get_area(id);
1779
1780
			memcpy(&areadefs, defs, sizeof(areadefs));
1781
			md_list_copy(&areadefs.md_list, &defs->md_list);
1782
			defs = &areadefs;
1783
		}
1784
break;
1785
case 61:
1786
#line 548 "parse.y"
1787
{
1788
			area = NULL;
1789
			md_list_clr(&defs->md_list);
1790
			defs = &globaldefs;
1791
		}
1792
break;
1793
case 62:
1794
#line 555 "parse.y"
1795
{ yyval.v.number = yyvsp[0].v.number; }
1796
break;
1797
case 63:
1798
#line 556 "parse.y"
1799
{ yyval.v.number = 1; }
1800
break;
1801
case 67:
1802
#line 564 "parse.y"
1803
{
1804
			if (yyvsp[0].v.number < 1 || yyvsp[0].v.number > 255) {
1805
				yyerror("demote count out of range (1-255)");
1806
				free(yyvsp[-1].v.string);
1807
				YYERROR;
1808
			}
1809
			area->demote_level = yyvsp[0].v.number;
1810
			if (strlcpy(area->demote_group, yyvsp[-1].v.string,
1811
			    sizeof(area->demote_group)) >=
1812
			    sizeof(area->demote_group)) {
1813
				yyerror("demote group name \"%s\" too long",
1814
				    yyvsp[-1].v.string);
1815
				free(yyvsp[-1].v.string);
1816
				YYERROR;
1817
			}
1818
			free(yyvsp[-1].v.string);
1819
			if (carp_demote_init(area->demote_group,
1820
			    conf->opts & OSPFD_OPT_FORCE_DEMOTE) == -1) {
1821
				yyerror("error initializing group \"%s\"",
1822
				    area->demote_group);
1823
				YYERROR;
1824
			}
1825
		}
1826
break;
1827
case 69:
1828
#line 588 "parse.y"
1829
{ area->stub = 1; }
1830
break;
1831
case 70:
1832
#line 589 "parse.y"
1833
{
1834
			area->stub = 1;
1835
			if (yyvsp[0].v.redist->type != REDIST_DEFAULT) {
1836
				yyerror("bad redistribute option");
1837
				YYERROR;
1838
			}
1839
			if (!SIMPLEQ_EMPTY(&area->redist_list)) {
1840
				yyerror("area redistribute option only "
1841
				    "allowed once");
1842
				YYERROR;
1843
			}
1844
			SIMPLEQ_INSERT_TAIL(&area->redist_list, yyvsp[0].v.redist, entry);
1845
		}
1846
break;
1847
case 71:
1848
#line 604 "parse.y"
1849
{
1850
			struct kif	*kif;
1851
			struct kif_addr	*ka = NULL;
1852
			char		*s;
1853
			struct in_addr	 addr;
1854
1855
			s = strchr(yyvsp[0].v.string, ':');
1856
			if (s) {
1857
				*s++ = '\0';
1858
				if (inet_aton(s, &addr) == 0) {
1859
					yyerror(
1860
					    "error parsing interface address");
1861
					free(yyvsp[0].v.string);
1862
					YYERROR;
1863
				}
1864
			} else
1865
				addr.s_addr = 0;
1866
1867
			if ((kif = kif_findname(yyvsp[0].v.string, addr, &ka)) == NULL) {
1868
				yyerror("unknown interface %s", yyvsp[0].v.string);
1869
				free(yyvsp[0].v.string);
1870
				YYERROR;
1871
			}
1872
			if (ka == NULL) {
1873
				if (s)
1874
					yyerror("address %s not configured on "
1875
					    "interface %s", s, yyvsp[0].v.string);
1876
				else
1877
					yyerror("unnumbered interface %s", yyvsp[0].v.string);
1878
				free(yyvsp[0].v.string);
1879
				YYERROR;
1880
			}
1881
			free(yyvsp[0].v.string);
1882
			iface = conf_get_if(kif, ka);
1883
			if (iface == NULL)
1884
				YYERROR;
1885
			iface->area = area;
1886
			LIST_INSERT_HEAD(&area->iface_list, iface, entry);
1887
1888
			memcpy(&ifacedefs, defs, sizeof(ifacedefs));
1889
			md_list_copy(&ifacedefs.md_list, &defs->md_list);
1890
			defs = &ifacedefs;
1891
		}
1892
break;
1893
case 72:
1894
#line 646 "parse.y"
1895
{
1896
			iface->dead_interval = defs->dead_interval;
1897
			iface->fast_hello_interval = defs->fast_hello_interval;
1898
			iface->transmit_delay = defs->transmit_delay;
1899
			if (iface->dead_interval == FAST_RTR_DEAD_TIME)
1900
				iface->hello_interval = 0;
1901
			else
1902
				iface->hello_interval = defs->hello_interval;
1903
			iface->rxmt_interval = defs->rxmt_interval;
1904
			iface->metric = defs->metric;
1905
			iface->priority = defs->priority;
1906
			iface->auth_type = defs->auth_type;
1907
			iface->auth_keyid = defs->auth_keyid;
1908
			memcpy(iface->auth_key, defs->auth_key,
1909
			    sizeof(iface->auth_key));
1910
			md_list_copy(&iface->auth_md_list, &defs->md_list);
1911
			md_list_clr(&defs->md_list);
1912
			iface = NULL;
1913
			/* interface is always part of an area */
1914
			defs = &areadefs;
1915
		}
1916
break;
1917
case 78:
1918
#line 678 "parse.y"
1919
{ iface->passive = 1; }
1920
break;
1921
case 79:
1922
#line 679 "parse.y"
1923
{
1924
			if (strlcpy(iface->demote_group, yyvsp[0].v.string,
1925
			    sizeof(iface->demote_group)) >=
1926
			    sizeof(iface->demote_group)) {
1927
				yyerror("demote group name \"%s\" too long",
1928
				    yyvsp[0].v.string);
1929
				free(yyvsp[0].v.string);
1930
				YYERROR;
1931
			}
1932
			free(yyvsp[0].v.string);
1933
			if (carp_demote_init(iface->demote_group,
1934
			    conf->opts & OSPFD_OPT_FORCE_DEMOTE) == -1) {
1935
912
				yyerror("error initializing group \"%s\"",
1936
912
				    iface->demote_group);
1937
912
				YYERROR;
1938
912
			}
1939
912
		}
1940
break;
1941
#line 1934 "parse.c"
1942
    }
1943
    yyssp -= yym;
1944
    yystate = *yyssp;
1945
    yyvsp -= yym;
1946
    yym = yylhs[yyn];
1947
72
    if (yystate == 0 && yym == 0)
1948
72
    {
1949
72
#if YYDEBUG
1950
        if (yydebug)
1951
72
            printf("%sdebug: after reduction, shifting from state 0 to\
1952
 state %d\n", YYPREFIX, YYFINAL);
1953
#endif
1954
        yystate = YYFINAL;
1955
        *++yyssp = YYFINAL;
1956
        *++yyvsp = yyval;
1957
        if (yychar < 0)
1958
        {
1959
            if ((yychar = yylex()) < 0) yychar = 0;
1960
#if YYDEBUG
1961
            if (yydebug)
1962
72
            {
1963
72
                yys = 0;
1964
48
                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1965
                if (!yys) yys = "illegal-symbol";
1966

2496
                printf("%sdebug: state %d, reading %d (%s)\n",
1967
1104
                        YYPREFIX, YYFINAL, yychar, yys);
1968
480
            }
1969
#endif
1970
360
        }
1971
        if (yychar == 0) goto yyaccept;
1972
        goto yyloop;
1973
    }
1974
    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
1975
            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
1976

840
        yystate = yytable[yyn];
1977
    else
1978
        yystate = yydgoto[yym];
1979
#if YYDEBUG
1980
840
    if (yydebug)
1981
840
        printf("%sdebug: after reduction, shifting from state %d \
1982
840
to state %d\n", YYPREFIX, *yyssp, yystate);
1983
#endif
1984
    if (yyssp >= yysslim && yygrowstack())
1985
    {
1986
        goto yyoverflow;
1987
    }
1988
    *++yyssp = yystate;
1989
    *++yyvsp = yyval;
1990
    goto yyloop;
1991
yyoverflow:
1992
    yyerror("yacc stack overflow");
1993
yyabort:
1994
    if (yyss)
1995
24
            free(yyss);
1996
24
    if (yyvs)
1997
24
            free(yyvs);
1998
24
    yyss = yyssp = NULL;
1999
24
    yyvs = yyvsp = NULL;
2000
24
    yystacksize = 0;
2001
24
    return (1);
2002
24
yyaccept:
2003
24
    if (yyss)
2004
            free(yyss);
2005
    if (yyvs)
2006
            free(yyvs);
2007
    yyss = yyssp = NULL;
2008
    yyvs = yyvsp = NULL;
2009
    yystacksize = 0;
2010
    return (0);
2011
}