GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: usr.sbin/ldpd/parse.c Lines: 0 392 0.0 %
Date: 2017-11-07 Branches: 0 345 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 26 "parse.y"
13
#include <sys/stat.h>
14
#include <arpa/inet.h>
15
#include <ctype.h>
16
#include <err.h>
17
#include <unistd.h>
18
#include <ifaddrs.h>
19
#include <net/if_types.h>
20
#include <limits.h>
21
#include <stdio.h>
22
#include <syslog.h>
23
24
#include "ldpd.h"
25
#include "ldpe.h"
26
#include "lde.h"
27
#include "log.h"
28
29
struct file {
30
	TAILQ_ENTRY(file)	 entry;
31
	FILE			*stream;
32
	char			*name;
33
	int			 lineno;
34
	int			 errors;
35
};
36
TAILQ_HEAD(files, file);
37
38
struct sym {
39
	TAILQ_ENTRY(sym)	 entry;
40
	int			 used;
41
	int			 persist;
42
	char			*nam;
43
	char			*val;
44
};
45
TAILQ_HEAD(symhead, sym);
46
47
struct config_defaults {
48
	uint16_t	keepalive;
49
	uint16_t	lhello_holdtime;
50
	uint16_t	lhello_interval;
51
	uint16_t	thello_holdtime;
52
	uint16_t	thello_interval;
53
	union ldpd_addr	trans_addr;
54
	int		afflags;
55
	uint8_t		pwflags;
56
};
57
58
typedef struct {
59
	union {
60
		int64_t		 number;
61
		char		*string;
62
	} v;
63
	int lineno;
64
} YYSTYPE;
65
66
#define MAXPUSHBACK	128
67
68
static int		 yyerror(const char *, ...)
69
    __attribute__((__format__ (printf, 1, 2)))
70
    __attribute__((__nonnull__ (1)));
71
static int		 kw_cmp(const void *, const void *);
72
static int		 lookup(char *);
73
static int		 lgetc(int);
74
static int		 lungetc(int);
75
static int		 findeol(void);
76
static int		 yylex(void);
77
static int		 check_file_secrecy(int, const char *);
78
static struct file	*pushfile(const char *, int);
79
static int		 popfile(void);
80
static int		 yyparse(void);
81
static int		 symset(const char *, const char *, int);
82
static char		*symget(const char *);
83
static struct iface	*conf_get_if(struct kif *);
84
static struct tnbr	*conf_get_tnbr(union ldpd_addr *);
85
static struct nbr_params *conf_get_nbrp(struct in_addr);
86
static struct l2vpn	*conf_get_l2vpn(char *);
87
static struct l2vpn_if	*conf_get_l2vpn_if(struct l2vpn *, struct kif *);
88
static struct l2vpn_pw	*conf_get_l2vpn_pw(struct l2vpn *, struct kif *);
89
int			 conf_check_rdomain(unsigned int);
90
static void		 clear_config(struct ldpd_conf *xconf);
91
static uint32_t		 get_rtr_id(void);
92
static int		 get_address(const char *, union ldpd_addr *);
93
static int		 get_af_address(const char *, int *, union ldpd_addr *);
94
95
static struct file		*file, *topfile;
96
static struct files		 files = TAILQ_HEAD_INITIALIZER(files);
97
static struct symhead		 symhead = TAILQ_HEAD_INITIALIZER(symhead);
98
static struct ldpd_conf		*conf;
99
static int			 errors;
100
101
static int			 af;
102
static struct ldpd_af_conf	*af_conf;
103
static struct iface		*iface;
104
static struct iface_af		*ia;
105
static struct tnbr		*tnbr;
106
static struct nbr_params	*nbrp;
107
static struct l2vpn		*l2vpn;
108
static struct l2vpn_pw		*pw;
109
110
static struct config_defaults	 globaldefs;
111
static struct config_defaults	 afdefs;
112
static struct config_defaults	 ifacedefs;
113
static struct config_defaults	 tnbrdefs;
114
static struct config_defaults	 pwdefs;
115
static struct config_defaults	*defs;
116
117
static unsigned char		*parsebuf;
118
static int			 parseindex;
119
static unsigned char		 pushback_buffer[MAXPUSHBACK];
120
static int			 pushback_index;
121
122
#line 123 "parse.c"
123
#define INTERFACE 257
124
#define TNEIGHBOR 258
125
#define ROUTERID 259
126
#define FIBUPDATE 260
127
#define RDOMAIN 261
128
#define EXPNULL 262
129
#define LHELLOHOLDTIME 263
130
#define LHELLOINTERVAL 264
131
#define THELLOHOLDTIME 265
132
#define THELLOINTERVAL 266
133
#define THELLOACCEPT 267
134
#define AF 268
135
#define IPV4 269
136
#define IPV6 270
137
#define GTSMENABLE 271
138
#define GTSMHOPS 272
139
#define KEEPALIVE 273
140
#define TRANSADDRESS 274
141
#define TRANSPREFERENCE 275
142
#define DSCISCOINTEROP 276
143
#define NEIGHBOR 277
144
#define PASSWORD 278
145
#define L2VPN 279
146
#define TYPE 280
147
#define VPLS 281
148
#define PWTYPE 282
149
#define MTU 283
150
#define BRIDGE 284
151
#define ETHERNET 285
152
#define ETHERNETTAGGED 286
153
#define STATUSTLV 287
154
#define CONTROLWORD 288
155
#define PSEUDOWIRE 289
156
#define NEIGHBORID 290
157
#define NEIGHBORADDR 291
158
#define PWID 292
159
#define EXTTAG 293
160
#define YES 294
161
#define NO 295
162
#define INCLUDE 296
163
#define ERROR 297
164
#define STRING 298
165
#define NUMBER 299
166
#define YYERRCODE 256
167
const short yylhs[] =
168
	{                                        -1,
169
    0,    0,    0,    0,    0,    0,    0,    0,    0,    6,
170
    5,    5,    1,    1,    2,    2,    3,    4,    4,    8,
171
    7,    7,    7,    7,    7,    7,    7,    7,   16,    9,
172
   15,   15,   15,   18,   18,   19,   19,   19,   19,   19,
173
   19,   19,   12,   12,   12,   13,   13,   14,   14,   23,
174
   23,   23,   23,   24,   24,   25,   25,   25,   25,   28,
175
   26,   27,   27,   27,   29,   29,   30,   30,   30,   30,
176
   30,   30,   17,   17,   20,   32,   21,   31,   31,   31,
177
   33,   33,   35,   22,   34,   34,   34,   36,   36,   38,
178
   10,   37,   37,   37,   39,   39,   41,   11,   40,   40,
179
   40,   42,   42,
180
};
181
const short yylen[] =
182
	{                                         2,
183
    0,    3,    2,    3,    3,    3,    3,    3,    3,    2,
184
    2,    1,    1,    1,    1,    1,    1,    1,    1,    3,
185
    2,    2,    2,    2,    2,    1,    1,    1,    0,    4,
186
    4,    3,    0,    3,    2,    2,    2,    1,    1,    1,
187
    1,    1,    2,    2,    2,    2,    2,    2,    2,    2,
188
    2,    2,    2,    2,    2,    2,    2,    2,    1,    0,
189
    4,    4,    3,    0,    3,    2,    2,    2,    1,    2,
190
    2,    1,    2,    0,    2,    0,    4,    4,    3,    0,
191
    3,    2,    0,    4,    4,    3,    0,    3,    2,    0,
192
    4,    4,    3,    0,    3,    2,    0,    6,    4,    3,
193
    0,    3,    2,
194
};
195
const short yydefred[] =
196
	{                                      1,
197
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
198
    0,    0,    0,    0,    0,    0,    0,    0,    0,    3,
199
    0,    0,    0,    0,    0,    0,   26,   27,   28,    9,
200
   21,   13,   14,   22,   23,   44,   46,   47,   48,   49,
201
   43,   15,   16,   29,   45,   24,   25,   90,    0,   10,
202
    0,    2,    4,    5,    6,    7,    8,    0,    0,    0,
203
   12,    0,    0,   30,    0,   91,   17,   97,   11,    0,
204
    0,    0,    0,   73,    0,    0,    0,    0,   32,   38,
205
   39,   40,    0,    0,   41,   42,    0,    0,    0,    0,
206
   93,    0,    0,    0,   98,   76,   83,   37,   36,   31,
207
    0,   35,   52,   53,   50,   51,   96,   92,    0,    0,
208
    0,    0,    0,   34,   95,    0,    0,    0,    0,    0,
209
    0,    0,  100,   69,   72,    0,    0,    0,   77,    0,
210
   84,   75,   71,   18,   19,   67,   68,   70,   54,   55,
211
   60,  103,   99,    0,    0,    0,    0,  102,   79,    0,
212
    0,   86,    0,    0,    0,   61,   82,   78,    0,   89,
213
   85,    0,    0,   81,   88,    0,    0,    0,   63,   59,
214
    0,    0,   57,   58,   56,   66,   62,    0,   65,
215
};
216
const short yydgoto[] =
217
	{                                       1,
218
   34,   44,   68,  136,   62,   21,   22,   23,   24,   25,
219
   26,   80,   81,   82,   64,   58,   71,   83,   84,  114,
220
   85,   86,   92,  124,  171,  125,  156,  147,  172,  126,
221
  129,  111,  151,  131,  112,  154,   66,   59,   93,   95,
222
   73,  127,
223
};
224
const short yysindex[] =
225
	{                                      0,
226
  -10,   -6, -292, -275, -291, -275, -288, -285, -282, -271,
227
 -275, -246, -270, -246, -275, -267, -266, -265,  -27,    0,
228
   25,   26,   28,   29,   30,   32,    0,    0,    0,    0,
229
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
230
    0,    0,    0,    0,    0,    0,    0,    0, -235,    0,
231
 -252,    0,    0,    0,    0,    0,    0,  -75,  -73, -230,
232
    0, -242,   47,    0,   47,    0,    0,    0,    0,   47,
233
  -36, -115,  -60,    0, -240, -239, -275, -234,    0,    0,
234
    0,    0,   67,   47,    0,    0, -275, -233, -232, -229,
235
    0,   47,  -82,   47,    0,    0,    0,    0,    0,    0,
236
   58,    0,    0,    0,    0,    0,    0,    0,   58,  -84,
237
  -53,  -52,   47,    0,    0, -226, -259, -225, -223, -275,
238
 -275, -222,    0,    0,    0,   47,  -72,   47,    0,   47,
239
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
240
    0,    0,    0,   58,  -22, -120,  -46,    0,    0,   47,
241
  -20,    0,   47,  -33,   47,    0,    0,    0,   58,    0,
242
    0,   58, -116,    0,    0, -220, -219, -217,    0,    0,
243
   47, -110,    0,    0,    0,    0,    0,   58,    0,};
244
const short yyrindex[] =
245
	{                                      0,
246
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
247
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
248
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
249
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
250
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
251
    0,    0,    0,    0,    0,    0,    0,   70,   73,    0,
252
    0,   75,   89,    0,  -65,    0,    0,    0,    0, -123,
253
    0,    0,   77,    0,    0,    0,    0,    0,    0,    0,
254
    0,    0,    0,   89,    0,    0,    0,    0,    0,    0,
255
    0,  -65,    0,  -64,    0,    0,    0,    0,    0,    0,
256
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
257
   27,   45, -123,    0,    0,    0,    0,    0,    0,    0,
258
    0,    0,    0,    0,    0,  -64,    0,   -4,    0,  -26,
259
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
260
    0,    0,    0,    0,    0,    0,   -9,    0,    0,   -4,
261
    0,    0,  -26,    0, -104,    0,    0,    0,    0,    0,
262
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
263
 -104,    0,    0,    0,    0,    0,    0,    0,    0,};
264
const short yygindex[] =
265
	{                                      0,
266
    7,   79,    0,    0,    0,    0,    0,    0,    0,    0,
267
    0,   90,    2,   48,    0,    0,  -40,    0,   12,  -97,
268
    0,    0,    3, -156,  -74,    0,    0,    0,    0,  -30,
269
    0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
270
    0,    0,
271
};
272
#define YYTABLESIZE 363
273
const short yytable[] =
274
	{                                      20,
275
   64,   74,   28,   30,  152,   31,  170,   35,  169,   91,
276
   37,  115,   36,   38,  177,  170,   39,   41,   32,   33,
277
   74,   47,   42,   43,   72,  134,  135,   40,   45,   74,
278
   48,   49,   50,   51,   52,   53,   80,   54,   55,   56,
279
  123,   57,  108,  102,   60,   61,  148,   63,   29,   65,
280
   67,  107,  143,  110,   87,   69,   70,   96,   97,   74,
281
   74,  164,   94,   99,  165,  104,  105,  113,  106,  128,
282
  130,  133,  132,  137,  138,  141,  155,  173,  174,   33,
283
  179,  175,   94,   98,   20,  142,  101,  145,   79,  146,
284
   27,  161,   46,  103,  101,  109,  144,  178,   74,    0,
285
    0,    0,  149,    0,  158,    0,    0,    0,    0,  157,
286
    0,    0,  160,    0,  163,   64,    0,    0,    0,    0,
287
   74,    0,    0,    0,    0,    0,  139,  140,    0,    0,
288
  176,    0,    0,   74,   74,    0,    0,    0,   74,   74,
289
   74,   74,   74,   74,    9,   10,  150,   74,   74,   74,
290
   74,   80,  159,    0,   74,   87,   88,   89,   74,   74,
291
   74,    0,   90,   74,   74,   74,   74,   74,   74,   87,
292
  120,  121,  116,  166,  167,  168,  120,  121,    0,  166,
293
  167,  168,   74,   74,  116,   74,   74,   74,   87,   88,
294
   89,  100,   74,  153,    0,   90,    0,  117,  118,  119,
295
    0,  162,  120,  121,  122,   74,   74,   74,    0,  117,
296
  118,  119,   74,   74,  120,  121,  122,   74,   74,   74,
297
   75,   76,   74,   74,   74,    6,    7,    8,    9,   10,
298
   11,    9,   10,    0,   77,    0,   13,   78,   74,   74,
299
    7,    8,    7,    8,    0,    2,    0,   64,    3,    4,
300
    5,    6,    7,    8,    9,   10,   11,   12,   74,   74,
301
    0,    0,   13,    0,   14,   15,   16,    0,   17,    0,
302
    0,    0,   64,   64,   64,    0,    0,   64,   64,   64,
303
    0,    0,    0,   80,   80,   18,    0,   19,   80,   80,
304
   80,   80,   80,   80,    0,    0,    0,   80,    0,   80,
305
   80,   87,   87,    0,    0,    0,   87,   87,   87,   87,
306
   87,   87,    0,    0,    0,   87,    0,   87,   87,    0,
307
    0,    0,    0,   75,   76,    0,    0,    0,    6,    7,
308
    8,    9,   10,   11,    0,    0,    0,   77,    0,   13,
309
   78,    0,    0,    0,    0,   74,   74,    0,    0,    0,
310
   74,   74,   74,   74,   74,   74,    0,    0,    0,   74,
311
    0,   74,   74,
312
};
313
const short yycheck[] =
314
	{                                      10,
315
   10,  125,    1,   10,  125,  298,  163,  299,  125,  125,
316
  299,  109,    6,  299,  125,  172,  299,   11,  294,  295,
317
  125,   15,  269,  270,   65,  285,  286,  299,  299,   70,
318
  298,  298,  298,   61,   10,   10,   10,   10,   10,   10,
319
  125,   10,  125,   84,  280,  298,  144,  123,    1,  123,
320
  281,   92,  125,   94,   10,  298,   10,  298,  298,  125,
321
  125,  159,  123,  298,  162,  299,  299,   10,  298,  123,
322
  123,  298,  113,  299,  298,  298,  123,  298,  298,   10,
323
  178,  299,   10,   77,   10,  126,   10,  128,  125,  130,
324
    1,  125,   14,   87,   83,   93,  127,  172,  125,   -1,
325
   -1,   -1,  125,   -1,  125,   -1,   -1,   -1,   -1,  150,
326
   -1,   -1,  153,   -1,  155,  125,   -1,   -1,   -1,   -1,
327
  125,   -1,   -1,   -1,   -1,   -1,  120,  121,   -1,   -1,
328
  171,   -1,   -1,  257,  258,   -1,   -1,   -1,  262,  263,
329
  264,  265,  266,  267,  265,  266,  145,  271,  272,  273,
330
  274,  125,  151,   -1,  278,  271,  272,  273,  282,  283,
331
  284,   -1,  278,  287,  288,  289,  290,  291,  292,  125,
332
  287,  288,  257,  290,  291,  292,  287,  288,   -1,  290,
333
  291,  292,  287,  288,  257,  290,  291,  292,  271,  272,
334
  273,  125,  257,  146,   -1,  278,   -1,  282,  283,  284,
335
   -1,  154,  287,  288,  289,  271,  272,  273,   -1,  282,
336
  283,  284,  278,  125,  287,  288,  289,  282,  283,  284,
337
  257,  258,  287,  288,  289,  262,  263,  264,  265,  266,
338
  267,  265,  266,   -1,  271,   -1,  273,  274,  265,  266,
339
  263,  264,  263,  264,   -1,  256,   -1,  257,  259,  260,
340
  261,  262,  263,  264,  265,  266,  267,  268,  263,  264,
341
   -1,   -1,  273,   -1,  275,  276,  277,   -1,  279,   -1,
342
   -1,   -1,  282,  283,  284,   -1,   -1,  287,  288,  289,
343
   -1,   -1,   -1,  257,  258,  296,   -1,  298,  262,  263,
344
  264,  265,  266,  267,   -1,   -1,   -1,  271,   -1,  273,
345
  274,  257,  258,   -1,   -1,   -1,  262,  263,  264,  265,
346
  266,  267,   -1,   -1,   -1,  271,   -1,  273,  274,   -1,
347
   -1,   -1,   -1,  257,  258,   -1,   -1,   -1,  262,  263,
348
  264,  265,  266,  267,   -1,   -1,   -1,  271,   -1,  273,
349
  274,   -1,   -1,   -1,   -1,  257,  258,   -1,   -1,   -1,
350
  262,  263,  264,  265,  266,  267,   -1,   -1,   -1,  271,
351
   -1,  273,  274,
352
};
353
#define YYFINAL 1
354
#ifndef YYDEBUG
355
#define YYDEBUG 0
356
#endif
357
#define YYMAXTOKEN 299
358
#if YYDEBUG
359
const char * const yyname[] =
360
	{
361
"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,
362
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,
363
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,
364
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,
365
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,
366
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,
367
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,"INTERFACE",
368
"TNEIGHBOR","ROUTERID","FIBUPDATE","RDOMAIN","EXPNULL","LHELLOHOLDTIME",
369
"LHELLOINTERVAL","THELLOHOLDTIME","THELLOINTERVAL","THELLOACCEPT","AF","IPV4",
370
"IPV6","GTSMENABLE","GTSMHOPS","KEEPALIVE","TRANSADDRESS","TRANSPREFERENCE",
371
"DSCISCOINTEROP","NEIGHBOR","PASSWORD","L2VPN","TYPE","VPLS","PWTYPE","MTU",
372
"BRIDGE","ETHERNET","ETHERNETTAGGED","STATUSTLV","CONTROLWORD","PSEUDOWIRE",
373
"NEIGHBORID","NEIGHBORADDR","PWID","EXTTAG","YES","NO","INCLUDE","ERROR",
374
"STRING","NUMBER",
375
};
376
const char * const yyrule[] =
377
	{"$accept : grammar",
378
"grammar :",
379
"grammar : grammar include '\\n'",
380
"grammar : grammar '\\n'",
381
"grammar : grammar conf_main '\\n'",
382
"grammar : grammar varset '\\n'",
383
"grammar : grammar af '\\n'",
384
"grammar : grammar neighbor '\\n'",
385
"grammar : grammar l2vpn '\\n'",
386
"grammar : grammar error '\\n'",
387
"include : INCLUDE STRING",
388
"string : string STRING",
389
"string : STRING",
390
"yesno : YES",
391
"yesno : NO",
392
"ldp_af : IPV4",
393
"ldp_af : IPV6",
394
"l2vpn_type : VPLS",
395
"pw_type : ETHERNET",
396
"pw_type : ETHERNETTAGGED",
397
"varset : STRING '=' string",
398
"conf_main : ROUTERID STRING",
399
"conf_main : FIBUPDATE yesno",
400
"conf_main : RDOMAIN NUMBER",
401
"conf_main : TRANSPREFERENCE ldp_af",
402
"conf_main : DSCISCOINTEROP yesno",
403
"conf_main : af_defaults",
404
"conf_main : iface_defaults",
405
"conf_main : tnbr_defaults",
406
"$$1 :",
407
"af : AF ldp_af $$1 af_block",
408
"af_block : '{' optnl afopts_l '}'",
409
"af_block : '{' optnl '}'",
410
"af_block :",
411
"afopts_l : afopts_l afoptsl nl",
412
"afopts_l : afoptsl optnl",
413
"afoptsl : TRANSADDRESS STRING",
414
"afoptsl : GTSMENABLE yesno",
415
"afoptsl : af_defaults",
416
"afoptsl : iface_defaults",
417
"afoptsl : tnbr_defaults",
418
"afoptsl : interface",
419
"afoptsl : tneighbor",
420
"af_defaults : THELLOACCEPT yesno",
421
"af_defaults : EXPNULL yesno",
422
"af_defaults : KEEPALIVE NUMBER",
423
"iface_defaults : LHELLOHOLDTIME NUMBER",
424
"iface_defaults : LHELLOINTERVAL NUMBER",
425
"tnbr_defaults : THELLOHOLDTIME NUMBER",
426
"tnbr_defaults : THELLOINTERVAL NUMBER",
427
"nbr_opts : KEEPALIVE NUMBER",
428
"nbr_opts : PASSWORD STRING",
429
"nbr_opts : GTSMENABLE yesno",
430
"nbr_opts : GTSMHOPS NUMBER",
431
"pw_defaults : STATUSTLV yesno",
432
"pw_defaults : CONTROLWORD yesno",
433
"pwopts : PWID NUMBER",
434
"pwopts : NEIGHBORID STRING",
435
"pwopts : NEIGHBORADDR STRING",
436
"pwopts : pw_defaults",
437
"$$2 :",
438
"pseudowire : PSEUDOWIRE STRING $$2 pw_block",
439
"pw_block : '{' optnl pwopts_l '}'",
440
"pw_block : '{' optnl '}'",
441
"pw_block :",
442
"pwopts_l : pwopts_l pwopts nl",
443
"pwopts_l : pwopts optnl",
444
"l2vpnopts : PWTYPE pw_type",
445
"l2vpnopts : MTU NUMBER",
446
"l2vpnopts : pw_defaults",
447
"l2vpnopts : BRIDGE STRING",
448
"l2vpnopts : INTERFACE STRING",
449
"l2vpnopts : pseudowire",
450
"optnl : '\\n' optnl",
451
"optnl :",
452
"nl : '\\n' optnl",
453
"$$3 :",
454
"interface : INTERFACE STRING $$3 interface_block",
455
"interface_block : '{' optnl interfaceopts_l '}'",
456
"interface_block : '{' optnl '}'",
457
"interface_block :",
458
"interfaceopts_l : interfaceopts_l iface_defaults nl",
459
"interfaceopts_l : iface_defaults optnl",
460
"$$4 :",
461
"tneighbor : TNEIGHBOR STRING $$4 tneighbor_block",
462
"tneighbor_block : '{' optnl tneighboropts_l '}'",
463
"tneighbor_block : '{' optnl '}'",
464
"tneighbor_block :",
465
"tneighboropts_l : tneighboropts_l tnbr_defaults nl",
466
"tneighboropts_l : tnbr_defaults optnl",
467
"$$5 :",
468
"neighbor : NEIGHBOR STRING $$5 neighbor_block",
469
"neighbor_block : '{' optnl neighboropts_l '}'",
470
"neighbor_block : '{' optnl '}'",
471
"neighbor_block :",
472
"neighboropts_l : neighboropts_l nbr_opts nl",
473
"neighboropts_l : nbr_opts optnl",
474
"$$6 :",
475
"l2vpn : L2VPN STRING TYPE l2vpn_type $$6 l2vpn_block",
476
"l2vpn_block : '{' optnl l2vpnopts_l '}'",
477
"l2vpn_block : '{' optnl '}'",
478
"l2vpn_block :",
479
"l2vpnopts_l : l2vpnopts_l l2vpnopts nl",
480
"l2vpnopts_l : l2vpnopts optnl",
481
};
482
#endif
483
#ifdef YYSTACKSIZE
484
#undef YYMAXDEPTH
485
#define YYMAXDEPTH YYSTACKSIZE
486
#else
487
#ifdef YYMAXDEPTH
488
#define YYSTACKSIZE YYMAXDEPTH
489
#else
490
#define YYSTACKSIZE 10000
491
#define YYMAXDEPTH 10000
492
#endif
493
#endif
494
#define YYINITSTACKSIZE 200
495
/* LINTUSED */
496
int yydebug;
497
int yynerrs;
498
int yyerrflag;
499
int yychar;
500
short *yyssp;
501
YYSTYPE *yyvsp;
502
YYSTYPE yyval;
503
YYSTYPE yylval;
504
short *yyss;
505
short *yysslim;
506
YYSTYPE *yyvs;
507
unsigned int yystacksize;
508
int yyparse(void);
509
#line 793 "parse.y"
510
511
struct keywords {
512
	const char	*k_name;
513
	int		 k_val;
514
};
515
516
static int
517
yyerror(const char *fmt, ...)
518
{
519
	va_list		 ap;
520
	char		*msg;
521
522
	file->errors++;
523
	va_start(ap, fmt);
524
	if (vasprintf(&msg, fmt, ap) == -1)
525
		fatalx("yyerror vasprintf");
526
	va_end(ap);
527
	logit(LOG_CRIT, "%s:%d: %s", file->name, yylval.lineno, msg);
528
	free(msg);
529
	return (0);
530
}
531
532
static int
533
kw_cmp(const void *k, const void *e)
534
{
535
	return (strcmp(k, ((const struct keywords *)e)->k_name));
536
}
537
538
static int
539
lookup(char *s)
540
{
541
	/* this has to be sorted always */
542
	static const struct keywords keywords[] = {
543
		{"address-family",		AF},
544
		{"bridge",			BRIDGE},
545
		{"control-word",		CONTROLWORD},
546
		{"ds-cisco-interop",		DSCISCOINTEROP},
547
		{"ethernet",			ETHERNET},
548
		{"ethernet-tagged",		ETHERNETTAGGED},
549
		{"explicit-null",		EXPNULL},
550
		{"fib-update",			FIBUPDATE},
551
		{"gtsm-enable",			GTSMENABLE},
552
		{"gtsm-hops",			GTSMHOPS},
553
		{"include",			INCLUDE},
554
		{"interface",			INTERFACE},
555
		{"ipv4",			IPV4},
556
		{"ipv6",			IPV6},
557
		{"keepalive",			KEEPALIVE},
558
		{"l2vpn",			L2VPN},
559
		{"link-hello-holdtime",		LHELLOHOLDTIME},
560
		{"link-hello-interval",		LHELLOINTERVAL},
561
		{"mtu",				MTU},
562
		{"neighbor",			NEIGHBOR},
563
		{"neighbor-addr",		NEIGHBORADDR},
564
		{"neighbor-id",			NEIGHBORID},
565
		{"no",				NO},
566
		{"password",			PASSWORD},
567
		{"pseudowire",			PSEUDOWIRE},
568
		{"pw-id",			PWID},
569
		{"pw-type",			PWTYPE},
570
		{"rdomain",			RDOMAIN},
571
		{"router-id",			ROUTERID},
572
		{"status-tlv",			STATUSTLV},
573
		{"targeted-hello-accept",	THELLOACCEPT},
574
		{"targeted-hello-holdtime",	THELLOHOLDTIME},
575
		{"targeted-hello-interval",	THELLOINTERVAL},
576
		{"targeted-neighbor",		TNEIGHBOR},
577
		{"transport-address",		TRANSADDRESS},
578
		{"transport-preference",	TRANSPREFERENCE},
579
		{"type",			TYPE},
580
		{"vpls",			VPLS},
581
		{"yes",				YES}
582
	};
583
	const struct keywords	*p;
584
585
	p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
586
	    sizeof(keywords[0]), kw_cmp);
587
588
	if (p)
589
		return (p->k_val);
590
	else
591
		return (STRING);
592
}
593
594
static int
595
lgetc(int quotec)
596
{
597
	int		c, next;
598
599
	if (parsebuf) {
600
		/* Read character from the parsebuffer instead of input. */
601
		if (parseindex >= 0) {
602
			c = parsebuf[parseindex++];
603
			if (c != '\0')
604
				return (c);
605
			parsebuf = NULL;
606
		} else
607
			parseindex++;
608
	}
609
610
	if (pushback_index)
611
		return (pushback_buffer[--pushback_index]);
612
613
	if (quotec) {
614
		if ((c = getc(file->stream)) == EOF) {
615
			yyerror("reached end of file while parsing "
616
			    "quoted string");
617
			if (file == topfile || popfile() == EOF)
618
				return (EOF);
619
			return (quotec);
620
		}
621
		return (c);
622
	}
623
624
	while ((c = getc(file->stream)) == '\\') {
625
		next = getc(file->stream);
626
		if (next != '\n') {
627
			c = next;
628
			break;
629
		}
630
		yylval.lineno = file->lineno;
631
		file->lineno++;
632
	}
633
634
	while (c == EOF) {
635
		if (file == topfile || popfile() == EOF)
636
			return (EOF);
637
		c = getc(file->stream);
638
	}
639
	return (c);
640
}
641
642
static int
643
lungetc(int c)
644
{
645
	if (c == EOF)
646
		return (EOF);
647
	if (parsebuf) {
648
		parseindex--;
649
		if (parseindex >= 0)
650
			return (c);
651
	}
652
	if (pushback_index < MAXPUSHBACK-1)
653
		return (pushback_buffer[pushback_index++] = c);
654
	else
655
		return (EOF);
656
}
657
658
static int
659
findeol(void)
660
{
661
	int	c;
662
663
	parsebuf = NULL;
664
665
	/* skip to either EOF or the first real EOL */
666
	while (1) {
667
		if (pushback_index)
668
			c = pushback_buffer[--pushback_index];
669
		else
670
			c = lgetc(0);
671
		if (c == '\n') {
672
			file->lineno++;
673
			break;
674
		}
675
		if (c == EOF)
676
			break;
677
	}
678
	return (ERROR);
679
}
680
681
static int
682
yylex(void)
683
{
684
	unsigned char	 buf[8096];
685
	unsigned char	*p, *val;
686
	int		 quotec, next, c;
687
	int		 token;
688
689
 top:
690
	p = buf;
691
	while ((c = lgetc(0)) == ' ' || c == '\t')
692
		; /* nothing */
693
694
	yylval.lineno = file->lineno;
695
	if (c == '#')
696
		while ((c = lgetc(0)) != '\n' && c != EOF)
697
			; /* nothing */
698
	if (c == '$' && parsebuf == NULL) {
699
		while (1) {
700
			if ((c = lgetc(0)) == EOF)
701
				return (0);
702
703
			if (p + 1 >= buf + sizeof(buf) - 1) {
704
				yyerror("string too long");
705
				return (findeol());
706
			}
707
			if (isalnum(c) || c == '_') {
708
				*p++ = c;
709
				continue;
710
			}
711
			*p = '\0';
712
			lungetc(c);
713
			break;
714
		}
715
		val = symget(buf);
716
		if (val == NULL) {
717
			yyerror("macro '%s' not defined", buf);
718
			return (findeol());
719
		}
720
		parsebuf = val;
721
		parseindex = 0;
722
		goto top;
723
	}
724
725
	switch (c) {
726
	case '\'':
727
	case '"':
728
		quotec = c;
729
		while (1) {
730
			if ((c = lgetc(quotec)) == EOF)
731
				return (0);
732
			if (c == '\n') {
733
				file->lineno++;
734
				continue;
735
			} else if (c == '\\') {
736
				if ((next = lgetc(quotec)) == EOF)
737
					return (0);
738
				if (next == quotec || c == ' ' || c == '\t')
739
					c = next;
740
				else if (next == '\n') {
741
					file->lineno++;
742
					continue;
743
				} else
744
					lungetc(next);
745
			} else if (c == quotec) {
746
				*p = '\0';
747
				break;
748
			} else if (c == '\0') {
749
				yyerror("syntax error");
750
				return (findeol());
751
			}
752
			if (p + 1 >= buf + sizeof(buf) - 1) {
753
				yyerror("string too long");
754
				return (findeol());
755
			}
756
			*p++ = c;
757
		}
758
		yylval.v.string = strdup(buf);
759
		if (yylval.v.string == NULL)
760
			err(1, "yylex: strdup");
761
		return (STRING);
762
	}
763
764
#define allowed_to_end_number(x) \
765
	(isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=')
766
767
	if (c == '-' || isdigit(c)) {
768
		do {
769
			*p++ = c;
770
			if ((unsigned)(p-buf) >= sizeof(buf)) {
771
				yyerror("string too long");
772
				return (findeol());
773
			}
774
		} while ((c = lgetc(0)) != EOF && isdigit(c));
775
		lungetc(c);
776
		if (p == buf + 1 && buf[0] == '-')
777
			goto nodigits;
778
		if (c == EOF || allowed_to_end_number(c)) {
779
			const char *errstr = NULL;
780
781
			*p = '\0';
782
			yylval.v.number = strtonum(buf, LLONG_MIN,
783
			    LLONG_MAX, &errstr);
784
			if (errstr) {
785
				yyerror("\"%s\" invalid number: %s",
786
				    buf, errstr);
787
				return (findeol());
788
			}
789
			return (NUMBER);
790
		} else {
791
 nodigits:
792
			while (p > buf + 1)
793
				lungetc(*--p);
794
			c = *--p;
795
			if (c == '-')
796
				return (c);
797
		}
798
	}
799
800
#define allowed_in_string(x) \
801
	(isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \
802
	x != '{' && x != '}' && \
803
	x != '!' && x != '=' && x != '#' && \
804
	x != ','))
805
806
	if (isalnum(c) || c == ':' || c == '_') {
807
		do {
808
			*p++ = c;
809
			if ((unsigned)(p-buf) >= sizeof(buf)) {
810
				yyerror("string too long");
811
				return (findeol());
812
			}
813
		} while ((c = lgetc(0)) != EOF && (allowed_in_string(c)));
814
		lungetc(c);
815
		*p = '\0';
816
		if ((token = lookup(buf)) == STRING)
817
			if ((yylval.v.string = strdup(buf)) == NULL)
818
				err(1, "yylex: strdup");
819
		return (token);
820
	}
821
	if (c == '\n') {
822
		yylval.lineno = file->lineno;
823
		file->lineno++;
824
	}
825
	if (c == EOF)
826
		return (0);
827
	return (c);
828
}
829
830
static int
831
check_file_secrecy(int fd, const char *fname)
832
{
833
	struct stat	st;
834
835
	if (fstat(fd, &st)) {
836
		log_warn("cannot stat %s", fname);
837
		return (-1);
838
	}
839
	if (st.st_uid != 0 && st.st_uid != getuid()) {
840
		log_warnx("%s: owner not root or current user", fname);
841
		return (-1);
842
	}
843
	if (st.st_mode & (S_IWGRP | S_IXGRP | S_IRWXO)) {
844
		log_warnx("%s: group writable or world read/writable", fname);
845
		return (-1);
846
	}
847
	return (0);
848
}
849
850
static struct file *
851
pushfile(const char *name, int secret)
852
{
853
	struct file	*nfile;
854
855
	if ((nfile = calloc(1, sizeof(struct file))) == NULL) {
856
		log_warn("calloc");
857
		return (NULL);
858
	}
859
	if ((nfile->name = strdup(name)) == NULL) {
860
		log_warn("strdup");
861
		free(nfile);
862
		return (NULL);
863
	}
864
	if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
865
		log_warn("%s", nfile->name);
866
		free(nfile->name);
867
		free(nfile);
868
		return (NULL);
869
	} else if (secret &&
870
	    check_file_secrecy(fileno(nfile->stream), nfile->name)) {
871
		fclose(nfile->stream);
872
		free(nfile->name);
873
		free(nfile);
874
		return (NULL);
875
	}
876
	nfile->lineno = 1;
877
	TAILQ_INSERT_TAIL(&files, nfile, entry);
878
	return (nfile);
879
}
880
881
static int
882
popfile(void)
883
{
884
	struct file	*prev;
885
886
	if ((prev = TAILQ_PREV(file, files, entry)) != NULL)
887
		prev->errors += file->errors;
888
889
	TAILQ_REMOVE(&files, file, entry);
890
	fclose(file->stream);
891
	free(file->name);
892
	free(file);
893
	file = prev;
894
	return (file ? 0 : EOF);
895
}
896
897
struct ldpd_conf *
898
parse_config(char *filename)
899
{
900
	struct sym	*sym, *next;
901
902
	conf = config_new_empty();
903
	conf->rdomain = 0;
904
	conf->trans_pref = DUAL_STACK_LDPOV6;
905
906
	defs = &globaldefs;
907
	defs->keepalive = DEFAULT_KEEPALIVE;
908
	defs->lhello_holdtime = LINK_DFLT_HOLDTIME;
909
	defs->lhello_interval = DEFAULT_HELLO_INTERVAL;
910
	defs->thello_holdtime = TARGETED_DFLT_HOLDTIME;
911
	defs->thello_interval = DEFAULT_HELLO_INTERVAL;
912
	defs->pwflags = F_PW_STATUSTLV_CONF|F_PW_CWORD_CONF;
913
914
	if ((file = pushfile(filename,
915
	    !(global.cmd_opts & LDPD_OPT_NOACTION))) == NULL) {
916
		free(conf);
917
		return (NULL);
918
	}
919
	topfile = file;
920
921
	yyparse();
922
	errors = file->errors;
923
	popfile();
924
925
	/* Free macros and check which have not been used. */
926
	TAILQ_FOREACH_SAFE(sym, &symhead, entry, next) {
927
		if ((global.cmd_opts & LDPD_OPT_VERBOSE2) && !sym->used)
928
			fprintf(stderr, "warning: macro '%s' not "
929
			    "used\n", sym->nam);
930
		if (!sym->persist) {
931
			free(sym->nam);
932
			free(sym->val);
933
			TAILQ_REMOVE(&symhead, sym, entry);
934
			free(sym);
935
		}
936
	}
937
938
	/* check that all interfaces belong to the configured rdomain */
939
	errors += conf_check_rdomain(conf->rdomain);
940
941
	/* free global config defaults */
942
	if (errors) {
943
		clear_config(conf);
944
		return (NULL);
945
	}
946
947
	if (conf->rtr_id.s_addr == INADDR_ANY)
948
		conf->rtr_id.s_addr = get_rtr_id();
949
950
	/* if the ipv4 transport-address is not set, use the router-id */
951
	if ((conf->ipv4.flags & F_LDPD_AF_ENABLED) &&
952
	    conf->ipv4.trans_addr.v4.s_addr == INADDR_ANY)
953
		conf->ipv4.trans_addr.v4 = conf->rtr_id;
954
955
	return (conf);
956
}
957
958
static int
959
symset(const char *nam, const char *val, int persist)
960
{
961
	struct sym	*sym;
962
963
	TAILQ_FOREACH(sym, &symhead, entry) {
964
		if (strcmp(nam, sym->nam) == 0)
965
			break;
966
	}
967
968
	if (sym != NULL) {
969
		if (sym->persist == 1)
970
			return (0);
971
		else {
972
			free(sym->nam);
973
			free(sym->val);
974
			TAILQ_REMOVE(&symhead, sym, entry);
975
			free(sym);
976
		}
977
	}
978
	if ((sym = calloc(1, sizeof(*sym))) == NULL)
979
		return (-1);
980
981
	sym->nam = strdup(nam);
982
	if (sym->nam == NULL) {
983
		free(sym);
984
		return (-1);
985
	}
986
	sym->val = strdup(val);
987
	if (sym->val == NULL) {
988
		free(sym->nam);
989
		free(sym);
990
		return (-1);
991
	}
992
	sym->used = 0;
993
	sym->persist = persist;
994
	TAILQ_INSERT_TAIL(&symhead, sym, entry);
995
	return (0);
996
}
997
998
int
999
cmdline_symset(char *s)
1000
{
1001
	char	*sym, *val;
1002
	int	ret;
1003
	size_t	len;
1004
1005
	if ((val = strrchr(s, '=')) == NULL)
1006
		return (-1);
1007
1008
	len = strlen(s) - strlen(val) + 1;
1009
	if ((sym = malloc(len)) == NULL)
1010
		errx(1, "cmdline_symset: malloc");
1011
1012
	strlcpy(sym, s, len);
1013
1014
	ret = symset(sym, val + 1, 1);
1015
	free(sym);
1016
1017
	return (ret);
1018
}
1019
1020
static char *
1021
symget(const char *nam)
1022
{
1023
	struct sym	*sym;
1024
1025
	TAILQ_FOREACH(sym, &symhead, entry) {
1026
		if (strcmp(nam, sym->nam) == 0) {
1027
			sym->used = 1;
1028
			return (sym->val);
1029
		}
1030
	}
1031
	return (NULL);
1032
}
1033
1034
static struct iface *
1035
conf_get_if(struct kif *kif)
1036
{
1037
	struct iface	*i;
1038
	struct l2vpn	*l;
1039
1040
	if (kif->if_type == IFT_LOOP ||
1041
	    kif->if_type == IFT_CARP ||
1042
	    kif->if_type == IFT_BRIDGE ||
1043
	    kif->if_type == IFT_MPLSTUNNEL) {
1044
		yyerror("unsupported interface type on interface %s",
1045
		    kif->ifname);
1046
		return (NULL);
1047
	}
1048
1049
	LIST_FOREACH(l, &conf->l2vpn_list, entry)
1050
		if (l2vpn_if_find(l, kif->ifindex)) {
1051
			yyerror("interface %s already configured under "
1052
			    "l2vpn %s", kif->ifname, l->name);
1053
			return (NULL);
1054
		}
1055
1056
	LIST_FOREACH(i, &conf->iface_list, entry)
1057
		if (i->ifindex == kif->ifindex)
1058
			return (i);
1059
1060
	i = if_new(kif);
1061
	LIST_INSERT_HEAD(&conf->iface_list, i, entry);
1062
	return (i);
1063
}
1064
1065
static struct tnbr *
1066
conf_get_tnbr(union ldpd_addr *addr)
1067
{
1068
	struct tnbr	*t;
1069
1070
	t = tnbr_find(conf, af, addr);
1071
	if (t) {
1072
		yyerror("targeted neighbor %s already configured",
1073
		    log_addr(af, addr));
1074
		return (NULL);
1075
	}
1076
1077
	t = tnbr_new(conf, af, addr);
1078
	t->flags |= F_TNBR_CONFIGURED;
1079
	LIST_INSERT_HEAD(&conf->tnbr_list, t, entry);
1080
	return (t);
1081
}
1082
1083
static struct nbr_params *
1084
conf_get_nbrp(struct in_addr lsr_id)
1085
{
1086
	struct nbr_params	*n;
1087
1088
	LIST_FOREACH(n, &conf->nbrp_list, entry) {
1089
		if (n->lsr_id.s_addr == lsr_id.s_addr) {
1090
			yyerror("neighbor %s already configured",
1091
			    inet_ntoa(lsr_id));
1092
			return (NULL);
1093
		}
1094
	}
1095
1096
	n = nbr_params_new(lsr_id);
1097
	LIST_INSERT_HEAD(&conf->nbrp_list, n, entry);
1098
	return (n);
1099
}
1100
1101
static struct l2vpn *
1102
conf_get_l2vpn(char *name)
1103
{
1104
	struct l2vpn	 *l;
1105
1106
	if (l2vpn_find(conf, name)) {
1107
		yyerror("l2vpn %s already configured", name);
1108
		return (NULL);
1109
	}
1110
1111
	l = l2vpn_new(name);
1112
	LIST_INSERT_HEAD(&conf->l2vpn_list, l, entry);
1113
	return (l);
1114
}
1115
1116
static struct l2vpn_if *
1117
conf_get_l2vpn_if(struct l2vpn *l, struct kif *kif)
1118
{
1119
	struct iface	*i;
1120
	struct l2vpn	*ltmp;
1121
	struct l2vpn_if	*f;
1122
1123
	if (kif->if_type == IFT_LOOP ||
1124
	    kif->if_type == IFT_CARP ||
1125
	    kif->if_type == IFT_BRIDGE ||
1126
	    kif->if_type == IFT_MPLSTUNNEL) {
1127
		yyerror("unsupported interface type on interface %s",
1128
		    kif->ifname);
1129
		return (NULL);
1130
	}
1131
1132
	LIST_FOREACH(ltmp, &conf->l2vpn_list, entry)
1133
		if (l2vpn_if_find(ltmp, kif->ifindex)) {
1134
			yyerror("interface %s already configured under "
1135
			    "l2vpn %s", kif->ifname, ltmp->name);
1136
			return (NULL);
1137
		}
1138
1139
	LIST_FOREACH(i, &conf->iface_list, entry) {
1140
		if (i->ifindex == kif->ifindex) {
1141
			yyerror("interface %s already configured",
1142
			    kif->ifname);
1143
			return (NULL);
1144
		}
1145
	}
1146
1147
	f = l2vpn_if_new(l, kif);
1148
	LIST_INSERT_HEAD(&l2vpn->if_list, f, entry);
1149
	return (f);
1150
}
1151
1152
static struct l2vpn_pw *
1153
conf_get_l2vpn_pw(struct l2vpn *l, struct kif *kif)
1154
{
1155
	struct l2vpn	*ltmp;
1156
	struct l2vpn_pw	*p;
1157
1158
	LIST_FOREACH(ltmp, &conf->l2vpn_list, entry) {
1159
		if (l2vpn_pw_find(ltmp, kif->ifindex)) {
1160
			yyerror("pseudowire %s is already being "
1161
			    "used by l2vpn %s", kif->ifname, ltmp->name);
1162
			return (NULL);
1163
		}
1164
	}
1165
1166
	p = l2vpn_pw_new(l, kif);
1167
	LIST_INSERT_HEAD(&l2vpn->pw_list, p, entry);
1168
	return (p);
1169
}
1170
1171
int
1172
conf_check_rdomain(unsigned int rdomain)
1173
{
1174
	struct iface	*i;
1175
	int		 errs = 0;
1176
1177
	LIST_FOREACH(i, &conf->iface_list, entry) {
1178
		if (i->rdomain != rdomain) {
1179
			logit(LOG_CRIT, "interface %s not in rdomain %u",
1180
			    i->name, rdomain);
1181
			errs++;
1182
		}
1183
	}
1184
1185
	return (errs);
1186
}
1187
1188
static void
1189
clear_config(struct ldpd_conf *xconf)
1190
{
1191
	struct iface		*i;
1192
	struct tnbr		*t;
1193
	struct nbr_params	*n;
1194
	struct l2vpn		*l;
1195
	struct l2vpn_if		*f;
1196
	struct l2vpn_pw		*p;
1197
1198
	while ((i = LIST_FIRST(&xconf->iface_list)) != NULL) {
1199
		LIST_REMOVE(i, entry);
1200
		free(i);
1201
	}
1202
1203
	while ((t = LIST_FIRST(&xconf->tnbr_list)) != NULL) {
1204
		LIST_REMOVE(t, entry);
1205
		free(t);
1206
	}
1207
1208
	while ((n = LIST_FIRST(&xconf->nbrp_list)) != NULL) {
1209
		LIST_REMOVE(n, entry);
1210
		free(n);
1211
	}
1212
1213
	while ((l = LIST_FIRST(&xconf->l2vpn_list)) != NULL) {
1214
		while ((f = LIST_FIRST(&l->if_list)) != NULL) {
1215
			LIST_REMOVE(f, entry);
1216
			free(f);
1217
		}
1218
		while ((p = LIST_FIRST(&l->pw_list)) != NULL) {
1219
			LIST_REMOVE(p, entry);
1220
			free(p);
1221
		}
1222
		LIST_REMOVE(l, entry);
1223
		free(l);
1224
	}
1225
1226
	free(xconf);
1227
}
1228
1229
static uint32_t
1230
get_rtr_id(void)
1231
{
1232
	struct ifaddrs		*ifap, *ifa;
1233
	uint32_t		 ip = 0, cur, localnet;
1234
1235
	localnet = htonl(INADDR_LOOPBACK & IN_CLASSA_NET);
1236
1237
	if (getifaddrs(&ifap) == -1) {
1238
		log_warn("getifaddrs");
1239
		return (0);
1240
	}
1241
1242
	for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
1243
		if (strncmp(ifa->ifa_name, "carp", 4) == 0)
1244
			continue;
1245
		if (ifa->ifa_addr->sa_family != AF_INET)
1246
			continue;
1247
		cur = ((struct sockaddr_in *)ifa->ifa_addr)->sin_addr.s_addr;
1248
		if ((cur & localnet) == localnet)	/* skip 127/8 */
1249
			continue;
1250
		if (ntohl(cur) < ntohl(ip) || ip == 0)
1251
			ip = cur;
1252
	}
1253
	freeifaddrs(ifap);
1254
1255
	return (ip);
1256
}
1257
1258
static int
1259
get_address(const char *s, union ldpd_addr *addr)
1260
{
1261
	switch (af) {
1262
	case AF_INET:
1263
		if (inet_pton(AF_INET, s, &addr->v4) != 1)
1264
			return (-1);
1265
		break;
1266
	case AF_INET6:
1267
		if (inet_pton(AF_INET6, s, &addr->v6) != 1)
1268
			return (-1);
1269
		break;
1270
	default:
1271
		return (-1);
1272
	}
1273
1274
	return (0);
1275
}
1276
1277
static int
1278
get_af_address(const char *s, int *family, union ldpd_addr *addr)
1279
{
1280
	if (inet_pton(AF_INET, s, &addr->v4) == 1) {
1281
		*family = AF_INET;
1282
		return (0);
1283
	}
1284
1285
	if (inet_pton(AF_INET6, s, &addr->v6) == 1) {
1286
		*family = AF_INET6;
1287
		return (0);
1288
	}
1289
1290
	return (-1);
1291
}
1292
#line 1285 "parse.c"
1293
/* allocate initial stack or double stack size, up to YYMAXDEPTH */
1294
static int yygrowstack(void)
1295
{
1296
    unsigned int newsize;
1297
    long sslen;
1298
    short *newss;
1299
    YYSTYPE *newvs;
1300
1301
    if ((newsize = yystacksize) == 0)
1302
        newsize = YYINITSTACKSIZE;
1303
    else if (newsize >= YYMAXDEPTH)
1304
        return -1;
1305
    else if ((newsize *= 2) > YYMAXDEPTH)
1306
        newsize = YYMAXDEPTH;
1307
    sslen = yyssp - yyss;
1308
#ifdef SIZE_MAX
1309
#define YY_SIZE_MAX SIZE_MAX
1310
#else
1311
#define YY_SIZE_MAX 0xffffffffU
1312
#endif
1313
    if (newsize && YY_SIZE_MAX / newsize < sizeof *newss)
1314
        goto bail;
1315
    newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) :
1316
      (short *)malloc(newsize * sizeof *newss); /* overflow check above */
1317
    if (newss == NULL)
1318
        goto bail;
1319
    yyss = newss;
1320
    yyssp = newss + sslen;
1321
    if (newsize && YY_SIZE_MAX / newsize < sizeof *newvs)
1322
        goto bail;
1323
    newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) :
1324
      (YYSTYPE *)malloc(newsize * sizeof *newvs); /* overflow check above */
1325
    if (newvs == NULL)
1326
        goto bail;
1327
    yyvs = newvs;
1328
    yyvsp = newvs + sslen;
1329
    yystacksize = newsize;
1330
    yysslim = yyss + newsize - 1;
1331
    return 0;
1332
bail:
1333
    if (yyss)
1334
            free(yyss);
1335
    if (yyvs)
1336
            free(yyvs);
1337
    yyss = yyssp = NULL;
1338
    yyvs = yyvsp = NULL;
1339
    yystacksize = 0;
1340
    return -1;
1341
}
1342
1343
#define YYABORT goto yyabort
1344
#define YYREJECT goto yyabort
1345
#define YYACCEPT goto yyaccept
1346
#define YYERROR goto yyerrlab
1347
int
1348
yyparse(void)
1349
{
1350
    int yym, yyn, yystate;
1351
#if YYDEBUG
1352
    const char *yys;
1353
1354
    if ((yys = getenv("YYDEBUG")))
1355
    {
1356
        yyn = *yys;
1357
        if (yyn >= '0' && yyn <= '9')
1358
            yydebug = yyn - '0';
1359
    }
1360
#endif /* YYDEBUG */
1361
1362
    yynerrs = 0;
1363
    yyerrflag = 0;
1364
    yychar = (-1);
1365
1366
    if (yyss == NULL && yygrowstack()) goto yyoverflow;
1367
    yyssp = yyss;
1368
    yyvsp = yyvs;
1369
    *yyssp = yystate = 0;
1370
1371
yyloop:
1372
    if ((yyn = yydefred[yystate]) != 0) goto yyreduce;
1373
    if (yychar < 0)
1374
    {
1375
        if ((yychar = yylex()) < 0) yychar = 0;
1376
#if YYDEBUG
1377
        if (yydebug)
1378
        {
1379
            yys = 0;
1380
            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1381
            if (!yys) yys = "illegal-symbol";
1382
            printf("%sdebug: state %d, reading %d (%s)\n",
1383
                    YYPREFIX, yystate, yychar, yys);
1384
        }
1385
#endif
1386
    }
1387
    if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 &&
1388
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1389
    {
1390
#if YYDEBUG
1391
        if (yydebug)
1392
            printf("%sdebug: state %d, shifting to state %d\n",
1393
                    YYPREFIX, yystate, yytable[yyn]);
1394
#endif
1395
        if (yyssp >= yysslim && yygrowstack())
1396
        {
1397
            goto yyoverflow;
1398
        }
1399
        *++yyssp = yystate = yytable[yyn];
1400
        *++yyvsp = yylval;
1401
        yychar = (-1);
1402
        if (yyerrflag > 0)  --yyerrflag;
1403
        goto yyloop;
1404
    }
1405
    if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 &&
1406
            yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
1407
    {
1408
        yyn = yytable[yyn];
1409
        goto yyreduce;
1410
    }
1411
    if (yyerrflag) goto yyinrecovery;
1412
#if defined(__GNUC__)
1413
    goto yynewerror;
1414
#endif
1415
yynewerror:
1416
    yyerror("syntax error");
1417
#if defined(__GNUC__)
1418
    goto yyerrlab;
1419
#endif
1420
yyerrlab:
1421
    ++yynerrs;
1422
yyinrecovery:
1423
    if (yyerrflag < 3)
1424
    {
1425
        yyerrflag = 3;
1426
        for (;;)
1427
        {
1428
            if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 &&
1429
                    yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
1430
            {
1431
#if YYDEBUG
1432
                if (yydebug)
1433
                    printf("%sdebug: state %d, error recovery shifting\
1434
 to state %d\n", YYPREFIX, *yyssp, yytable[yyn]);
1435
#endif
1436
                if (yyssp >= yysslim && yygrowstack())
1437
                {
1438
                    goto yyoverflow;
1439
                }
1440
                *++yyssp = yystate = yytable[yyn];
1441
                *++yyvsp = yylval;
1442
                goto yyloop;
1443
            }
1444
            else
1445
            {
1446
#if YYDEBUG
1447
                if (yydebug)
1448
                    printf("%sdebug: error recovery discarding state %d\n",
1449
                            YYPREFIX, *yyssp);
1450
#endif
1451
                if (yyssp <= yyss) goto yyabort;
1452
                --yyssp;
1453
                --yyvsp;
1454
            }
1455
        }
1456
    }
1457
    else
1458
    {
1459
        if (yychar == 0) goto yyabort;
1460
#if YYDEBUG
1461
        if (yydebug)
1462
        {
1463
            yys = 0;
1464
            if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
1465
            if (!yys) yys = "illegal-symbol";
1466
            printf("%sdebug: state %d, error recovery discards token %d (%s)\n",
1467
                    YYPREFIX, yystate, yychar, yys);
1468
        }
1469
#endif
1470
        yychar = (-1);
1471
        goto yyloop;
1472
    }
1473
yyreduce:
1474
#if YYDEBUG
1475
    if (yydebug)
1476
        printf("%sdebug: state %d, reducing by rule %d (%s)\n",
1477
                YYPREFIX, yystate, yyn, yyrule[yyn]);
1478
#endif
1479
    yym = yylen[yyn];
1480
    if (yym)
1481
        yyval = yyvsp[1-yym];
1482
    else
1483
        memset(&yyval, 0, sizeof yyval);
1484
    switch (yyn)
1485
    {
1486
case 9:
1487
#line 165 "parse.y"
1488
{ file->errors++; }
1489
break;
1490
case 10:
1491
#line 168 "parse.y"
1492
{
1493
			struct file	*nfile;
1494
1495
			if ((nfile = pushfile(yyvsp[0].v.string, 1)) == NULL) {
1496
				yyerror("failed to include file %s", yyvsp[0].v.string);
1497
				free(yyvsp[0].v.string);
1498
				YYERROR;
1499
			}
1500
			free(yyvsp[0].v.string);
1501
1502
			file = nfile;
1503
			lungetc('\n');
1504
		}
1505
break;
1506
case 11:
1507
#line 183 "parse.y"
1508
{
1509
			if (asprintf(&yyval.v.string, "%s %s", yyvsp[-1].v.string, yyvsp[0].v.string) == -1) {
1510
				free(yyvsp[-1].v.string);
1511
				free(yyvsp[0].v.string);
1512
				yyerror("string: asprintf");
1513
				YYERROR;
1514
			}
1515
			free(yyvsp[-1].v.string);
1516
			free(yyvsp[0].v.string);
1517
		}
1518
break;
1519
case 13:
1520
#line 196 "parse.y"
1521
{ yyval.v.number = 1; }
1522
break;
1523
case 14:
1524
#line 197 "parse.y"
1525
{ yyval.v.number = 0; }
1526
break;
1527
case 15:
1528
#line 200 "parse.y"
1529
{ yyval.v.number = AF_INET; }
1530
break;
1531
case 16:
1532
#line 201 "parse.y"
1533
{ yyval.v.number = AF_INET6; }
1534
break;
1535
case 17:
1536
#line 204 "parse.y"
1537
{ yyval.v.number = L2VPN_TYPE_VPLS; }
1538
break;
1539
case 18:
1540
#line 207 "parse.y"
1541
{ yyval.v.number = PW_TYPE_ETHERNET; }
1542
break;
1543
case 19:
1544
#line 208 "parse.y"
1545
{ yyval.v.number = PW_TYPE_ETHERNET_TAGGED; }
1546
break;
1547
case 20:
1548
#line 211 "parse.y"
1549
{
1550
			char *s = yyvsp[-2].v.string;
1551
			if (global.cmd_opts & LDPD_OPT_VERBOSE)
1552
				printf("%s = \"%s\"\n", yyvsp[-2].v.string, yyvsp[0].v.string);
1553
			while (*s++) {
1554
				if (isspace((unsigned char)*s)) {
1555
					yyerror("macro name cannot contain "
1556
					    "whitespace");
1557
					YYERROR;
1558
				}
1559
			}
1560
			if (symset(yyvsp[-2].v.string, yyvsp[0].v.string, 0) == -1)
1561
				fatal("cannot store variable");
1562
			free(yyvsp[-2].v.string);
1563
			free(yyvsp[0].v.string);
1564
		}
1565
break;
1566
case 21:
1567
#line 229 "parse.y"
1568
{
1569
			if (!inet_aton(yyvsp[0].v.string, &conf->rtr_id)) {
1570
				yyerror("error parsing router-id");
1571
				free(yyvsp[0].v.string);
1572
				YYERROR;
1573
			}
1574
			free(yyvsp[0].v.string);
1575
			if (bad_addr_v4(conf->rtr_id)) {
1576
				yyerror("invalid router-id");
1577
				YYERROR;
1578
			}
1579
		}
1580
break;
1581
case 22:
1582
#line 241 "parse.y"
1583
{
1584
			if (yyvsp[0].v.number == 0)
1585
				conf->flags |= F_LDPD_NO_FIB_UPDATE;
1586
			else
1587
				conf->flags &= ~F_LDPD_NO_FIB_UPDATE;
1588
		}
1589
break;
1590
case 23:
1591
#line 247 "parse.y"
1592
{
1593
			if (yyvsp[0].v.number < 0 || yyvsp[0].v.number > RT_TABLEID_MAX) {
1594
				yyerror("invalid rdomain");
1595
				YYERROR;
1596
			}
1597
			conf->rdomain = yyvsp[0].v.number;
1598
		}
1599
break;
1600
case 24:
1601
#line 254 "parse.y"
1602
{
1603
			conf->trans_pref = yyvsp[0].v.number;
1604
1605
			switch (conf->trans_pref) {
1606
			case AF_INET:
1607
				conf->trans_pref = DUAL_STACK_LDPOV4;
1608
				break;
1609
			case AF_INET6:
1610
				conf->trans_pref = DUAL_STACK_LDPOV6;
1611
				break;
1612
			default:
1613
				yyerror("invalid address-family");
1614
				YYERROR;
1615
			}
1616
		}
1617
break;
1618
case 25:
1619
#line 269 "parse.y"
1620
{
1621
			if (yyvsp[0].v.number == 1)
1622
				conf->flags |= F_LDPD_DS_CISCO_INTEROP;
1623
			else
1624
				conf->flags &= ~F_LDPD_DS_CISCO_INTEROP;
1625
		}
1626
break;
1627
case 29:
1628
#line 280 "parse.y"
1629
{
1630
			af = yyvsp[0].v.number;
1631
			switch (af) {
1632
			case AF_INET:
1633
				af_conf = &conf->ipv4;
1634
				break;
1635
			case AF_INET6:
1636
				af_conf = &conf->ipv6;
1637
				break;
1638
			default:
1639
				yyerror("invalid address-family");
1640
				YYERROR;
1641
			}
1642
1643
			afdefs = *defs;
1644
			defs = &afdefs;
1645
		}
1646
break;
1647
case 30:
1648
#line 296 "parse.y"
1649
{
1650
			af_conf->keepalive = defs->keepalive;
1651
			af_conf->thello_holdtime = defs->thello_holdtime;
1652
			af_conf->thello_interval = defs->thello_interval;
1653
			af_conf->flags = defs->afflags;
1654
			af_conf->flags |= F_LDPD_AF_ENABLED;
1655
			af_conf = NULL;
1656
			af = AF_UNSPEC;
1657
			defs = &globaldefs;
1658
		}
1659
break;
1660
case 36:
1661
#line 317 "parse.y"
1662
{
1663
			if (get_address(yyvsp[0].v.string, &af_conf->trans_addr) == -1) {
1664
				yyerror("error parsing transport-address");
1665
				free(yyvsp[0].v.string);
1666
				YYERROR;
1667
			}
1668
			free(yyvsp[0].v.string);
1669
			if (bad_addr(af, &af_conf->trans_addr)) {
1670
				yyerror("invalid transport-address");
1671
				YYERROR;
1672
			}
1673
			if (af == AF_INET6 &&
1674
			   IN6_IS_SCOPE_EMBED(&af_conf->trans_addr.v6)) {
1675
				yyerror("ipv6 transport-address can not be "
1676
				    "link-local");
1677
				YYERROR;
1678
			}
1679
		}
1680
break;
1681
case 37:
1682
#line 335 "parse.y"
1683
{
1684
			if (yyvsp[0].v.number == 0)
1685
				defs->afflags |= F_LDPD_AF_NO_GTSM;
1686
		}
1687
break;
1688
case 43:
1689
#line 346 "parse.y"
1690
{
1691
			if (yyvsp[0].v.number == 0)
1692
				defs->afflags &= ~F_LDPD_AF_THELLO_ACCEPT;
1693
			else
1694
				defs->afflags |= F_LDPD_AF_THELLO_ACCEPT;
1695
		}
1696
break;
1697
case 44:
1698
#line 352 "parse.y"
1699
{
1700
			if (yyvsp[0].v.number == 0)
1701
				defs->afflags &= ~F_LDPD_AF_EXPNULL;
1702
			else
1703
				defs->afflags |= F_LDPD_AF_EXPNULL;
1704
		}
1705
break;
1706
case 45:
1707
#line 358 "parse.y"
1708
{
1709
			if (yyvsp[0].v.number < MIN_KEEPALIVE || yyvsp[0].v.number > MAX_KEEPALIVE) {
1710
				yyerror("keepalive out of range (%d-%d)",
1711
				    MIN_KEEPALIVE, MAX_KEEPALIVE);
1712
				YYERROR;
1713
			}
1714
			defs->keepalive = yyvsp[0].v.number;
1715
		}
1716
break;
1717
case 46:
1718
#line 368 "parse.y"
1719
{
1720
			if (yyvsp[0].v.number < MIN_HOLDTIME || yyvsp[0].v.number > MAX_HOLDTIME) {
1721
				yyerror("hello-holdtime out of range (%d-%d)",
1722
				    MIN_HOLDTIME, MAX_HOLDTIME);
1723
				YYERROR;
1724
			}
1725
			defs->lhello_holdtime = yyvsp[0].v.number;
1726
		}
1727
break;
1728
case 47:
1729
#line 376 "parse.y"
1730
{
1731
			if (yyvsp[0].v.number < MIN_HELLO_INTERVAL ||
1732
			    yyvsp[0].v.number > MAX_HELLO_INTERVAL) {
1733
				yyerror("hello-interval out of range (%d-%d)",
1734
				    MIN_HELLO_INTERVAL, MAX_HELLO_INTERVAL);
1735
				YYERROR;
1736
			}
1737
			defs->lhello_interval = yyvsp[0].v.number;
1738
		}
1739
break;
1740
case 48:
1741
#line 387 "parse.y"
1742
{
1743
			if (yyvsp[0].v.number < MIN_HOLDTIME || yyvsp[0].v.number > MAX_HOLDTIME) {
1744
				yyerror("hello-holdtime out of range (%d-%d)",
1745
				    MIN_HOLDTIME, MAX_HOLDTIME);
1746
				YYERROR;
1747
			}
1748
			defs->thello_holdtime = yyvsp[0].v.number;
1749
		}
1750
break;
1751
case 49:
1752
#line 395 "parse.y"
1753
{
1754
			if (yyvsp[0].v.number < MIN_HELLO_INTERVAL ||
1755
			    yyvsp[0].v.number > MAX_HELLO_INTERVAL) {
1756
				yyerror("hello-interval out of range (%d-%d)",
1757
				    MIN_HELLO_INTERVAL, MAX_HELLO_INTERVAL);
1758
				YYERROR;
1759
			}
1760
			defs->thello_interval = yyvsp[0].v.number;
1761
		}
1762
break;
1763
case 50:
1764
#line 406 "parse.y"
1765
{
1766
			if (yyvsp[0].v.number < MIN_KEEPALIVE || yyvsp[0].v.number > MAX_KEEPALIVE) {
1767
				yyerror("keepalive out of range (%d-%d)",
1768
				    MIN_KEEPALIVE, MAX_KEEPALIVE);
1769
				YYERROR;
1770
			}
1771
			nbrp->keepalive = yyvsp[0].v.number;
1772
			nbrp->flags |= F_NBRP_KEEPALIVE;
1773
		}
1774
break;
1775
case 51:
1776
#line 415 "parse.y"
1777
{
1778
			if (strlcpy(nbrp->auth.md5key, yyvsp[0].v.string,
1779
			    sizeof(nbrp->auth.md5key)) >=
1780
			    sizeof(nbrp->auth.md5key)) {
1781
				yyerror("tcp md5sig password too long: max %zu",
1782
				    sizeof(nbrp->auth.md5key) - 1);
1783
				free(yyvsp[0].v.string);
1784
				YYERROR;
1785
			}
1786
			nbrp->auth.md5key_len = strlen(yyvsp[0].v.string);
1787
			nbrp->auth.method = AUTH_MD5SIG;
1788
			free(yyvsp[0].v.string);
1789
		}
1790
break;
1791
case 52:
1792
#line 428 "parse.y"
1793
{
1794
			nbrp->flags |= F_NBRP_GTSM;
1795
			nbrp->gtsm_enabled = yyvsp[0].v.number;
1796
		}
1797
break;
1798
case 53:
1799
#line 432 "parse.y"
1800
{
1801
			if (yyvsp[0].v.number < 1 || yyvsp[0].v.number > 255) {
1802
				yyerror("invalid number of hops %lld", yyvsp[0].v.number);
1803
				YYERROR;
1804
			}
1805
			nbrp->gtsm_hops = yyvsp[0].v.number;
1806
			nbrp->flags |= F_NBRP_GTSM_HOPS;
1807
		}
1808
break;
1809
case 54:
1810
#line 442 "parse.y"
1811
{
1812
			if (yyvsp[0].v.number == 1)
1813
				defs->pwflags |= F_PW_STATUSTLV_CONF;
1814
			else
1815
				defs->pwflags &= ~F_PW_STATUSTLV_CONF;
1816
		}
1817
break;
1818
case 55:
1819
#line 448 "parse.y"
1820
{
1821
			if (yyvsp[0].v.number == 1)
1822
				defs->pwflags |= F_PW_CWORD_CONF;
1823
			else
1824
				defs->pwflags &= ~F_PW_CWORD_CONF;
1825
		}
1826
break;
1827
case 56:
1828
#line 456 "parse.y"
1829
{
1830
			if (yyvsp[0].v.number < MIN_PWID_ID ||
1831
			    yyvsp[0].v.number > MAX_PWID_ID) {
1832
				yyerror("pw-id out of range (%d-%d)",
1833
				    MIN_PWID_ID, MAX_PWID_ID);
1834
				YYERROR;
1835
			}
1836
1837
			pw->pwid = yyvsp[0].v.number;
1838
		}
1839
break;
1840
case 57:
1841
#line 466 "parse.y"
1842
{
1843
			struct in_addr	 addr;
1844
1845
			if (!inet_aton(yyvsp[0].v.string, &addr)) {
1846
				yyerror("error parsing neighbor-id");
1847
				free(yyvsp[0].v.string);
1848
				YYERROR;
1849
			}
1850
			free(yyvsp[0].v.string);
1851
			if (bad_addr_v4(addr)) {
1852
				yyerror("invalid neighbor-id");
1853
				YYERROR;
1854
			}
1855
1856
			pw->lsr_id = addr;
1857
		}
1858
break;
1859
case 58:
1860
#line 482 "parse.y"
1861
{
1862
			int		 family;
1863
			union ldpd_addr	 addr;
1864
1865
			if (get_af_address(yyvsp[0].v.string, &family, &addr) == -1) {
1866
				yyerror("error parsing neighbor address");
1867
				free(yyvsp[0].v.string);
1868
				YYERROR;
1869
			}
1870
			free(yyvsp[0].v.string);
1871
			if (bad_addr(family, &addr)) {
1872
				yyerror("invalid neighbor address");
1873
				YYERROR;
1874
			}
1875
			if (family == AF_INET6 &&
1876
			    IN6_IS_SCOPE_EMBED(&addr.v6)) {
1877
				yyerror("neighbor address can not be "
1878
				    "link-local");
1879
				YYERROR;
1880
			}
1881
1882
			pw->af = family;
1883
			pw->addr = addr;
1884
		}
1885
break;
1886
case 60:
1887
#line 509 "parse.y"
1888
{
1889
			struct kif	*kif;
1890
1891
			if ((kif = kif_findname(yyvsp[0].v.string)) == NULL) {
1892
				yyerror("unknown interface %s", yyvsp[0].v.string);
1893
				free(yyvsp[0].v.string);
1894
				YYERROR;
1895
			}
1896
			free(yyvsp[0].v.string);
1897
1898
			if (kif->if_type != IFT_MPLSTUNNEL) {
1899
				yyerror("unsupported interface type on "
1900
				    "interface %s", kif->ifname);
1901
				YYERROR;
1902
			}
1903
1904
			pw = conf_get_l2vpn_pw(l2vpn, kif);
1905
			if (pw == NULL)
1906
				YYERROR;
1907
1908
			pwdefs = *defs;
1909
			defs = &pwdefs;
1910
		}
1911
break;
1912
case 61:
1913
#line 531 "parse.y"
1914
{
1915
			struct l2vpn	*l;
1916
			struct l2vpn_pw *p;
1917
1918
			/* check for errors */
1919
			if (pw->pwid == 0) {
1920
				yyerror("missing pseudowire id");
1921
				YYERROR;
1922
			}
1923
			if (pw->lsr_id.s_addr == INADDR_ANY) {
1924
				yyerror("missing pseudowire neighbor-id");
1925
				YYERROR;
1926
			}
1927
			LIST_FOREACH(l, &conf->l2vpn_list, entry) {
1928
				LIST_FOREACH(p, &l->pw_list, entry) {
1929
					if (pw != p &&
1930
					    pw->pwid == p->pwid &&
1931
					    pw->af == p->af &&
1932
					    pw->lsr_id.s_addr ==
1933
					    p->lsr_id.s_addr) {
1934
						yyerror("pseudowire already "
1935
						    "configured");
1936
						YYERROR;
1937
					}
1938
				}
1939
			}
1940
1941
			/*
1942
			 * If the neighbor address is not specified, use the
1943
			 * neighbor id.
1944
			 */
1945
			if (pw->af == AF_UNSPEC) {
1946
				pw->af = AF_INET;
1947
				pw->addr.v4 = pw->lsr_id;
1948
			}
1949
1950
			pw->flags = defs->pwflags;
1951
			pw = NULL;
1952
			defs = &globaldefs;
1953
		}
1954
break;
1955
case 67:
1956
#line 582 "parse.y"
1957
{
1958
			l2vpn->pw_type = yyvsp[0].v.number;
1959
		}
1960
break;
1961
case 68:
1962
#line 585 "parse.y"
1963
{
1964
			if (yyvsp[0].v.number < MIN_L2VPN_MTU ||
1965
			    yyvsp[0].v.number > MAX_L2VPN_MTU) {
1966
				yyerror("l2vpn mtu out of range (%d-%d)",
1967
				    MIN_L2VPN_MTU, MAX_L2VPN_MTU);
1968
				YYERROR;
1969
			}
1970
			l2vpn->mtu = yyvsp[0].v.number;
1971
		}
1972
break;
1973
case 70:
1974
#line 595 "parse.y"
1975
{
1976
			struct l2vpn	 *l;
1977
			struct kif	 *kif;
1978
1979
			if ((kif = kif_findname(yyvsp[0].v.string)) == NULL) {
1980
				yyerror("unknown interface %s", yyvsp[0].v.string);
1981
				free(yyvsp[0].v.string);
1982
				YYERROR;
1983
			}
1984
			free(yyvsp[0].v.string);
1985
1986
			if (l2vpn->br_ifindex != 0) {
1987
				yyerror("bridge interface cannot be "
1988
				    "redefined on l2vpn %s", l2vpn->name);
1989
				YYERROR;
1990
			}
1991
1992
			if (kif->if_type != IFT_BRIDGE) {
1993
				yyerror("unsupported interface type on "
1994
				    "interface %s", kif->ifname);
1995
				YYERROR;
1996
			}
1997
1998
			LIST_FOREACH(l, &conf->l2vpn_list, entry) {
1999
				if (l->br_ifindex == kif->ifindex) {
2000
					yyerror("bridge %s is already being "
2001
					    "used by l2vpn %s", kif->ifname,
2002
					    l->name);
2003
					YYERROR;
2004
				}
2005
			}
2006
2007
			l2vpn->br_ifindex = kif->ifindex;
2008
			strlcpy(l2vpn->br_ifname, kif->ifname,
2009
			    sizeof(l2vpn->br_ifname));
2010
		}
2011
break;
2012
case 71:
2013
#line 631 "parse.y"
2014
{
2015
			struct kif	*kif;
2016
			struct l2vpn_if	*lif;
2017
2018
			if ((kif = kif_findname(yyvsp[0].v.string)) == NULL) {
2019
				yyerror("unknown interface %s", yyvsp[0].v.string);
2020
				free(yyvsp[0].v.string);
2021
				YYERROR;
2022
			}
2023
			free(yyvsp[0].v.string);
2024
2025
			lif = conf_get_l2vpn_if(l2vpn, kif);
2026
			if (lif == NULL)
2027
				YYERROR;
2028
		}
2029
break;
2030
case 76:
2031
#line 656 "parse.y"
2032
{
2033
			struct kif	*kif;
2034
2035
			if ((kif = kif_findname(yyvsp[0].v.string)) == NULL) {
2036
				yyerror("unknown interface %s", yyvsp[0].v.string);
2037
				free(yyvsp[0].v.string);
2038
				YYERROR;
2039
			}
2040
			free(yyvsp[0].v.string);
2041
2042
			iface = conf_get_if(kif);
2043
			if (iface == NULL)
2044
				YYERROR;
2045
2046
			ia = iface_af_get(iface, af);
2047
			if (ia->enabled) {
2048
				yyerror("interface %s already configured for "
2049
				    "address-family %s", kif->ifname,
2050
				    af_name(af));
2051
				YYERROR;
2052
			}
2053
			ia->enabled = 1;
2054
2055
			ifacedefs = *defs;
2056
			defs = &ifacedefs;
2057
		}
2058
break;
2059
case 77:
2060
#line 681 "parse.y"
2061
{
2062
			ia->hello_holdtime = defs->lhello_holdtime;
2063
			ia->hello_interval = defs->lhello_interval;
2064
			iface = NULL;
2065
			defs = &afdefs;
2066
		}
2067
break;
2068
case 83:
2069
#line 698 "parse.y"
2070
{
2071
			union ldpd_addr	 addr;
2072
2073
			if (get_address(yyvsp[0].v.string, &addr) == -1) {
2074
				yyerror("error parsing targeted-neighbor "
2075
				    "address");
2076
				free(yyvsp[0].v.string);
2077
				YYERROR;
2078
			}
2079
			free(yyvsp[0].v.string);
2080
			if (bad_addr(af, &addr)) {
2081
				yyerror("invalid targeted-neighbor address");
2082
				YYERROR;
2083
			}
2084
			if (af == AF_INET6 &&
2085
			   IN6_IS_SCOPE_EMBED(&addr.v6)) {
2086
				yyerror("targeted-neighbor address can not be "
2087
				    "link-local");
2088
				YYERROR;
2089
			}
2090
2091
			tnbr = conf_get_tnbr(&addr);
2092
			if (tnbr == NULL)
2093
				YYERROR;
2094
2095
			tnbrdefs = *defs;
2096
			defs = &tnbrdefs;
2097
		}
2098
break;
2099
case 84:
2100
#line 725 "parse.y"
2101
{
2102
			tnbr->hello_holdtime = defs->thello_holdtime;
2103
			tnbr->hello_interval = defs->thello_interval;
2104
			tnbr = NULL;
2105
			defs = &afdefs;
2106
		}
2107
break;
2108
case 90:
2109
#line 742 "parse.y"
2110
{
2111
			struct in_addr	 addr;
2112
2113
			if (inet_aton(yyvsp[0].v.string, &addr) == 0) {
2114
				yyerror("error parsing neighbor-id");
2115
				free(yyvsp[0].v.string);
2116
				YYERROR;
2117
			}
2118
			free(yyvsp[0].v.string);
2119
			if (bad_addr_v4(addr)) {
2120
				yyerror("invalid neighbor-id");
2121
				YYERROR;
2122
			}
2123
2124
			nbrp = conf_get_nbrp(addr);
2125
			if (nbrp == NULL)
2126
				YYERROR;
2127
		}
2128
break;
2129
case 91:
2130
#line 759 "parse.y"
2131
{
2132
			nbrp = NULL;
2133
		}
2134
break;
2135
case 97:
2136
#line 773 "parse.y"
2137
{
2138
			l2vpn = conf_get_l2vpn(yyvsp[-2].v.string);
2139
			if (l2vpn == NULL)
2140
				YYERROR;
2141
			l2vpn->type = yyvsp[0].v.number;
2142
		}
2143
break;
2144
case 98:
2145
#line 778 "parse.y"
2146
{
2147
			l2vpn = NULL;
2148
		}
2149
break;
2150
#line 2143 "parse.c"
2151
    }
2152
    yyssp -= yym;
2153
    yystate = *yyssp;
2154
    yyvsp -= yym;
2155
    yym = yylhs[yyn];
2156
    if (yystate == 0 && yym == 0)
2157
    {
2158
#if YYDEBUG
2159
        if (yydebug)
2160
            printf("%sdebug: after reduction, shifting from state 0 to\
2161
 state %d\n", YYPREFIX, YYFINAL);
2162
#endif
2163
        yystate = YYFINAL;
2164
        *++yyssp = YYFINAL;
2165
        *++yyvsp = yyval;
2166
        if (yychar < 0)
2167
        {
2168
            if ((yychar = yylex()) < 0) yychar = 0;
2169
#if YYDEBUG
2170
            if (yydebug)
2171
            {
2172
                yys = 0;
2173
                if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
2174
                if (!yys) yys = "illegal-symbol";
2175
                printf("%sdebug: state %d, reading %d (%s)\n",
2176
                        YYPREFIX, YYFINAL, yychar, yys);
2177
            }
2178
#endif
2179
        }
2180
        if (yychar == 0) goto yyaccept;
2181
        goto yyloop;
2182
    }
2183
    if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 &&
2184
            yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
2185
        yystate = yytable[yyn];
2186
    else
2187
        yystate = yydgoto[yym];
2188
#if YYDEBUG
2189
    if (yydebug)
2190
        printf("%sdebug: after reduction, shifting from state %d \
2191
to state %d\n", YYPREFIX, *yyssp, yystate);
2192
#endif
2193
    if (yyssp >= yysslim && yygrowstack())
2194
    {
2195
        goto yyoverflow;
2196
    }
2197
    *++yyssp = yystate;
2198
    *++yyvsp = yyval;
2199
    goto yyloop;
2200
yyoverflow:
2201
    yyerror("yacc stack overflow");
2202
yyabort:
2203
    if (yyss)
2204
            free(yyss);
2205
    if (yyvs)
2206
            free(yyvs);
2207
    yyss = yyssp = NULL;
2208
    yyvs = yyvsp = NULL;
2209
    yystacksize = 0;
2210
    return (1);
2211
yyaccept:
2212
    if (yyss)
2213
            free(yyss);
2214
    if (yyvs)
2215
            free(yyvs);
2216
    yyss = yyssp = NULL;
2217
    yyvs = yyvsp = NULL;
2218
    yystacksize = 0;
2219
    return (0);
2220
}