1 /* A Bison parser, made by GNU Bison 3.3.2. */
2
3 /* Bison implementation for Yacc-like parsers in C
4
5 Copyright (C) 1984, 1989-1990, 2000-2015, 2018-2019 Free Software Foundation,
6 Inc.
7
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20
21 /* As a special exception, you may create a larger work that contains
22 part or all of the Bison parser skeleton and distribute that work
23 under terms of your choice, so long as that work isn't itself a
24 parser generator using the skeleton or a modified version thereof
25 as a parser skeleton. Alternatively, if you modify or redistribute
26 the parser skeleton itself, you may (at your option) remove this
27 special exception, which will cause the skeleton and the resulting
28 Bison output files to be licensed under the GNU General Public
29 License without this special exception.
30
31 This special exception was added by the Free Software Foundation in
32 version 2.2 of Bison. */
33
34 /* C LALR(1) parser skeleton written by Richard Stallman, by
35 simplifying the original so-called "semantic" parser. */
36
37 /* All symbols defined below should begin with yy or YY, to avoid
38 infringing on user name space. This should be done even for local
39 variables, as they might otherwise be expanded by user macros.
40 There are some unavoidable exceptions within include files to
41 define necessary library symbols; they are noted "INFRINGES ON
42 USER NAME SPACE" below. */
43
44 /* Undocumented macros, especially those whose name start with YY_,
45 are private implementation details. Do not rely on them. */
46
47 /* Identify Bison output. */
48 #define YYBISON 1
49
50 /* Bison version. */
51 #define YYBISON_VERSION "3.3.2"
52
53 /* Skeleton name. */
54 #define YYSKELETON_NAME "yacc.c"
55
56 /* Pure parsers. */
57 #define YYPURE 0
58
59 /* Push parsers. */
60 #define YYPUSH 0
61
62 /* Pull parsers. */
63 #define YYPULL 1
64
65
66
67
68 /* First part of user prologue. */
69 #line 25 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:337 */
70
71 #include <sys/types.h>
72 #include <sys/socket.h>
73 #include <sys/stat.h>
74 #include <sys/un.h>
75 #include <netinet/in.h>
76 #include <netinet/ip_ipsp.h>
77 #include <arpa/inet.h>
78
79 #include <ctype.h>
80 #include <endian.h>
81 #include <err.h>
82 #include <unistd.h>
83 #include <errno.h>
84 #include <limits.h>
85 #include <stdarg.h>
86 #include <stdio.h>
87 #include <stdlib.h>
88 #include <string.h>
89 #include <syslog.h>
90
91 #include "bgpd.h"
92 #include "session.h"
93 #include "rde.h"
94 #include "log.h"
95
96 TAILQ_HEAD(files, file) files = TAILQ_HEAD_INITIALIZER(files);
97 static struct file {
98 TAILQ_ENTRY(file) entry;
99 FILE *stream;
100 char *name;
101 size_t ungetpos;
102 size_t ungetsize;
103 u_char *ungetbuf;
104 int eof_reached;
105 int lineno;
106 int errors;
107 } *file, *topfile;
108 struct file *pushfile(const char *, int);
109 int popfile(void);
110 int check_file_secrecy(int, const char *);
111 int yyparse(void);
112 int yylex(void);
113 int yyerror(const char *, ...)
114 __attribute__((__format__ (printf, 1, 2)))
115 __attribute__((__nonnull__ (1)));
116 int kw_cmp(const void *, const void *);
117 int lookup(char *);
118 int igetc(void);
119 int lgetc(int);
120 void lungetc(int);
121 int findeol(void);
122
123 TAILQ_HEAD(symhead, sym) symhead = TAILQ_HEAD_INITIALIZER(symhead);
124 struct sym {
125 TAILQ_ENTRY(sym) entry;
126 int used;
127 int persist;
128 char *nam;
129 char *val;
130 };
131 int symset(const char *, const char *, int);
132 char *symget(const char *);
133
134 static struct bgpd_config *conf;
135 static struct network_head *netconf;
136 static struct peer_head *new_peers, *cur_peers;
137 static struct rtr_config_head *cur_rtrs;
138 static struct peer *curpeer;
139 static struct peer *curgroup;
140 static struct rde_rib *currib;
141 static struct l3vpn *curvpn;
142 static struct prefixset *curpset, *curoset;
143 static struct roa_tree *curroatree;
144 static struct rtr_config *currtr;
145 static struct filter_head *filter_l;
146 static struct filter_head *peerfilter_l;
147 static struct filter_head *groupfilter_l;
148 static struct filter_rule *curpeer_filter[2];
149 static struct filter_rule *curgroup_filter[2];
150
151 struct filter_rib_l {
152 struct filter_rib_l *next;
153 char name[PEER_DESCR_LEN];
154 };
155
156 struct filter_peers_l {
157 struct filter_peers_l *next;
158 struct filter_peers p;
159 };
160
161 struct filter_prefix_l {
162 struct filter_prefix_l *next;
163 struct filter_prefix p;
164 };
165
166 struct filter_prefixlen {
167 enum comp_ops op;
168 int len_min;
169 int len_max;
170 };
171
172 struct filter_as_l {
173 struct filter_as_l *next;
174 struct filter_as a;
175 };
176
177 struct filter_match_l {
178 struct filter_match m;
179 struct filter_prefix_l *prefix_l;
180 struct filter_as_l *as_l;
181 struct filter_prefixset *prefixset;
182 } fmopts;
183
184 struct peer *alloc_peer(void);
185 struct peer *new_peer(void);
186 struct peer *new_group(void);
187 int add_mrtconfig(enum mrt_type, char *, int, struct peer *,
188 char *);
189 struct rde_rib *add_rib(char *);
190 struct rde_rib *find_rib(char *);
191 int rib_add_fib(struct rde_rib *, u_int);
192 int get_id(struct peer *);
193 int merge_prefixspec(struct filter_prefix *,
194 struct filter_prefixlen *);
195 int expand_rule(struct filter_rule *, struct filter_rib_l *,
196 struct filter_peers_l *, struct filter_match_l *,
197 struct filter_set_head *);
198 int str2key(char *, char *, size_t);
199 int neighbor_consistent(struct peer *);
200 int merge_filterset(struct filter_set_head *, struct filter_set *);
201 void optimize_filters(struct filter_head *);
202 struct filter_rule *get_rule(enum action_types);
203
204 int parsecommunity(struct community *, int, char *);
205 int parseextcommunity(struct community *, char *,
206 char *);
207 static int new_as_set(char *);
208 static void add_as_set(u_int32_t);
209 static void done_as_set(void);
210 static struct prefixset *new_prefix_set(char *, int);
211 static void add_roa_set(struct prefixset_item *, u_int32_t, u_int8_t);
212 static struct rtr_config *get_rtr(struct bgpd_addr *);
213 static int insert_rtr(struct rtr_config *);
214
215 typedef struct {
216 union {
217 long long number;
218 char *string;
219 struct bgpd_addr addr;
220 u_int8_t u8;
221 struct filter_rib_l *filter_rib;
222 struct filter_peers_l *filter_peers;
223 struct filter_match_l filter_match;
224 struct filter_prefixset *filter_prefixset;
225 struct filter_prefix_l *filter_prefix;
226 struct filter_as_l *filter_as;
227 struct filter_set *filter_set;
228 struct filter_set_head *filter_set_head;
229 struct {
230 struct bgpd_addr prefix;
231 u_int8_t len;
232 } prefix;
233 struct filter_prefixlen prefixlen;
234 struct prefixset_item *prefixset_item;
235 struct {
236 u_int8_t enc_alg;
237 char enc_key[IPSEC_ENC_KEY_LEN];
238 u_int8_t enc_key_len;
239 } encspec;
240 } v;
241 int lineno;
242 } YYSTYPE;
243
244
245 #line 246 "parse.c" /* yacc.c:337 */
246 # ifndef YY_NULLPTR
247 # if defined __cplusplus
248 # if 201103L <= __cplusplus
249 # define YY_NULLPTR nullptr
250 # else
251 # define YY_NULLPTR 0
252 # endif
253 # else
254 # define YY_NULLPTR ((void*)0)
255 # endif
256 # endif
257
258 /* Enabling verbose error messages. */
259 #ifdef YYERROR_VERBOSE
260 # undef YYERROR_VERBOSE
261 # define YYERROR_VERBOSE 1
262 #else
263 # define YYERROR_VERBOSE 0
264 #endif
265
266
267 /* Debug traces. */
268 #ifndef YYDEBUG
269 # define YYDEBUG 0
270 #endif
271 #if YYDEBUG
272 extern int yydebug;
273 #endif
274
275 /* Token type. */
276 #ifndef YYTOKENTYPE
277 # define YYTOKENTYPE
278 enum yytokentype
279 {
280 AS = 258,
281 ROUTERID = 259,
282 HOLDTIME = 260,
283 YMIN = 261,
284 LISTEN = 262,
285 ON = 263,
286 FIBUPDATE = 264,
287 FIBPRIORITY = 265,
288 RTABLE = 266,
289 NONE = 267,
290 UNICAST = 268,
291 VPN = 269,
292 RD = 270,
293 EXPORT = 271,
294 EXPORTTRGT = 272,
295 IMPORTTRGT = 273,
296 DEFAULTROUTE = 274,
297 RDE = 275,
298 RIB = 276,
299 EVALUATE = 277,
300 IGNORE = 278,
301 COMPARE = 279,
302 RTR = 280,
303 PORT = 281,
304 GROUP = 282,
305 NEIGHBOR = 283,
306 NETWORK = 284,
307 EBGP = 285,
308 IBGP = 286,
309 LOCALAS = 287,
310 REMOTEAS = 288,
311 DESCR = 289,
312 LOCALADDR = 290,
313 MULTIHOP = 291,
314 PASSIVE = 292,
315 MAXPREFIX = 293,
316 RESTART = 294,
317 ANNOUNCE = 295,
318 CAPABILITIES = 296,
319 REFRESH = 297,
320 AS4BYTE = 298,
321 CONNECTRETRY = 299,
322 DEMOTE = 300,
323 ENFORCE = 301,
324 NEIGHBORAS = 302,
325 ASOVERRIDE = 303,
326 REFLECTOR = 304,
327 DEPEND = 305,
328 DOWN = 306,
329 DUMP = 307,
330 IN = 308,
331 OUT = 309,
332 SOCKET = 310,
333 RESTRICTED = 311,
334 LOG = 312,
335 TRANSPARENT = 313,
336 TCP = 314,
337 MD5SIG = 315,
338 PASSWORD = 316,
339 KEY = 317,
340 TTLSECURITY = 318,
341 ALLOW = 319,
342 DENY = 320,
343 MATCH = 321,
344 QUICK = 322,
345 FROM = 323,
346 TO = 324,
347 ANY = 325,
348 CONNECTED = 326,
349 STATIC = 327,
350 COMMUNITY = 328,
351 EXTCOMMUNITY = 329,
352 LARGECOMMUNITY = 330,
353 DELETE = 331,
354 PREFIX = 332,
355 PREFIXLEN = 333,
356 PREFIXSET = 334,
357 ROASET = 335,
358 ORIGINSET = 336,
359 OVS = 337,
360 ASSET = 338,
361 SOURCEAS = 339,
362 TRANSITAS = 340,
363 PEERAS = 341,
364 MAXASLEN = 342,
365 MAXASSEQ = 343,
366 SET = 344,
367 LOCALPREF = 345,
368 MED = 346,
369 METRIC = 347,
370 NEXTHOP = 348,
371 REJECT = 349,
372 BLACKHOLE = 350,
373 NOMODIFY = 351,
374 SELF = 352,
375 PREPEND_SELF = 353,
376 PREPEND_PEER = 354,
377 PFTABLE = 355,
378 WEIGHT = 356,
379 RTLABEL = 357,
380 ORIGIN = 358,
381 PRIORITY = 359,
382 ERROR = 360,
383 INCLUDE = 361,
384 IPSEC = 362,
385 ESP = 363,
386 AH = 364,
387 SPI = 365,
388 IKE = 366,
389 IPV4 = 367,
390 IPV6 = 368,
391 QUALIFY = 369,
392 VIA = 370,
393 NE = 371,
394 LE = 372,
395 GE = 373,
396 XRANGE = 374,
397 LONGER = 375,
398 MAXLEN = 376,
399 STRING = 377,
400 NUMBER = 378
401 };
402 #endif
403 /* Tokens. */
404 #define AS 258
405 #define ROUTERID 259
406 #define HOLDTIME 260
407 #define YMIN 261
408 #define LISTEN 262
409 #define ON 263
410 #define FIBUPDATE 264
411 #define FIBPRIORITY 265
412 #define RTABLE 266
413 #define NONE 267
414 #define UNICAST 268
415 #define VPN 269
416 #define RD 270
417 #define EXPORT 271
418 #define EXPORTTRGT 272
419 #define IMPORTTRGT 273
420 #define DEFAULTROUTE 274
421 #define RDE 275
422 #define RIB 276
423 #define EVALUATE 277
424 #define IGNORE 278
425 #define COMPARE 279
426 #define RTR 280
427 #define PORT 281
428 #define GROUP 282
429 #define NEIGHBOR 283
430 #define NETWORK 284
431 #define EBGP 285
432 #define IBGP 286
433 #define LOCALAS 287
434 #define REMOTEAS 288
435 #define DESCR 289
436 #define LOCALADDR 290
437 #define MULTIHOP 291
438 #define PASSIVE 292
439 #define MAXPREFIX 293
440 #define RESTART 294
441 #define ANNOUNCE 295
442 #define CAPABILITIES 296
443 #define REFRESH 297
444 #define AS4BYTE 298
445 #define CONNECTRETRY 299
446 #define DEMOTE 300
447 #define ENFORCE 301
448 #define NEIGHBORAS 302
449 #define ASOVERRIDE 303
450 #define REFLECTOR 304
451 #define DEPEND 305
452 #define DOWN 306
453 #define DUMP 307
454 #define IN 308
455 #define OUT 309
456 #define SOCKET 310
457 #define RESTRICTED 311
458 #define LOG 312
459 #define TRANSPARENT 313
460 #define TCP 314
461 #define MD5SIG 315
462 #define PASSWORD 316
463 #define KEY 317
464 #define TTLSECURITY 318
465 #define ALLOW 319
466 #define DENY 320
467 #define MATCH 321
468 #define QUICK 322
469 #define FROM 323
470 #define TO 324
471 #define ANY 325
472 #define CONNECTED 326
473 #define STATIC 327
474 #define COMMUNITY 328
475 #define EXTCOMMUNITY 329
476 #define LARGECOMMUNITY 330
477 #define DELETE 331
478 #define PREFIX 332
479 #define PREFIXLEN 333
480 #define PREFIXSET 334
481 #define ROASET 335
482 #define ORIGINSET 336
483 #define OVS 337
484 #define ASSET 338
485 #define SOURCEAS 339
486 #define TRANSITAS 340
487 #define PEERAS 341
488 #define MAXASLEN 342
489 #define MAXASSEQ 343
490 #define SET 344
491 #define LOCALPREF 345
492 #define MED 346
493 #define METRIC 347
494 #define NEXTHOP 348
495 #define REJECT 349
496 #define BLACKHOLE 350
497 #define NOMODIFY 351
498 #define SELF 352
499 #define PREPEND_SELF 353
500 #define PREPEND_PEER 354
501 #define PFTABLE 355
502 #define WEIGHT 356
503 #define RTLABEL 357
504 #define ORIGIN 358
505 #define PRIORITY 359
506 #define ERROR 360
507 #define INCLUDE 361
508 #define IPSEC 362
509 #define ESP 363
510 #define AH 364
511 #define SPI 365
512 #define IKE 366
513 #define IPV4 367
514 #define IPV6 368
515 #define QUALIFY 369
516 #define VIA 370
517 #define NE 371
518 #define LE 372
519 #define GE 373
520 #define XRANGE 374
521 #define LONGER 375
522 #define MAXLEN 376
523 #define STRING 377
524 #define NUMBER 378
525
526 /* Value type. */
527
528
529 extern YYSTYPE yylval;
530
531 int yyparse (void);
532
533
534
535
536
537 #ifdef short
538 # undef short
539 #endif
540
541 #ifdef YYTYPE_UINT8
542 typedef YYTYPE_UINT8 yytype_uint8;
543 #else
544 typedef unsigned char yytype_uint8;
545 #endif
546
547 #ifdef YYTYPE_INT8
548 typedef YYTYPE_INT8 yytype_int8;
549 #else
550 typedef signed char yytype_int8;
551 #endif
552
553 #ifdef YYTYPE_UINT16
554 typedef YYTYPE_UINT16 yytype_uint16;
555 #else
556 typedef unsigned short yytype_uint16;
557 #endif
558
559 #ifdef YYTYPE_INT16
560 typedef YYTYPE_INT16 yytype_int16;
561 #else
562 typedef short yytype_int16;
563 #endif
564
565 #ifndef YYSIZE_T
566 # ifdef __SIZE_TYPE__
567 # define YYSIZE_T __SIZE_TYPE__
568 # elif defined size_t
569 # define YYSIZE_T size_t
570 # elif ! defined YYSIZE_T
571 # include <stddef.h> /* INFRINGES ON USER NAME SPACE */
572 # define YYSIZE_T size_t
573 # else
574 # define YYSIZE_T unsigned
575 # endif
576 #endif
577
578 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
579
580 #ifndef YY_
581 # if defined YYENABLE_NLS && YYENABLE_NLS
582 # if ENABLE_NLS
583 # include <libintl.h> /* INFRINGES ON USER NAME SPACE */
584 # define YY_(Msgid) dgettext ("bison-runtime", Msgid)
585 # endif
586 # endif
587 # ifndef YY_
588 # define YY_(Msgid) Msgid
589 # endif
590 #endif
591
592 #ifndef YY_ATTRIBUTE
593 # if (defined __GNUC__ \
594 && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \
595 || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C
596 # define YY_ATTRIBUTE(Spec) __attribute__(Spec)
597 # else
598 # define YY_ATTRIBUTE(Spec) /* empty */
599 # endif
600 #endif
601
602 #ifndef YY_ATTRIBUTE_PURE
603 # define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__))
604 #endif
605
606 #ifndef YY_ATTRIBUTE_UNUSED
607 # define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__))
608 #endif
609
610 /* Suppress unused-variable warnings by "using" E. */
611 #if ! defined lint || defined __GNUC__
612 # define YYUSE(E) ((void) (E))
613 #else
614 # define YYUSE(E) /* empty */
615 #endif
616
617 #if defined __GNUC__ && ! defined __ICC && 407 <= __GNUC__ * 100 + __GNUC_MINOR__
618 /* Suppress an incorrect diagnostic about yylval being uninitialized. */
619 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
620 _Pragma ("GCC diagnostic push") \
621 _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
622 _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
623 # define YY_IGNORE_MAYBE_UNINITIALIZED_END \
624 _Pragma ("GCC diagnostic pop")
625 #else
626 # define YY_INITIAL_VALUE(Value) Value
627 #endif
628 #ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
629 # define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
630 # define YY_IGNORE_MAYBE_UNINITIALIZED_END
631 #endif
632 #ifndef YY_INITIAL_VALUE
633 # define YY_INITIAL_VALUE(Value) /* Nothing. */
634 #endif
635
636
637 #if ! defined yyoverflow || YYERROR_VERBOSE
638
639 /* The parser invokes alloca or malloc; define the necessary symbols. */
640
641 # ifdef YYSTACK_USE_ALLOCA
642 # if YYSTACK_USE_ALLOCA
643 # ifdef __GNUC__
644 # define YYSTACK_ALLOC __builtin_alloca
645 # elif defined __BUILTIN_VA_ARG_INCR
646 # include <alloca.h> /* INFRINGES ON USER NAME SPACE */
647 # elif defined _AIX
648 # define YYSTACK_ALLOC __alloca
649 # elif defined _MSC_VER
650 # include <malloc.h> /* INFRINGES ON USER NAME SPACE */
651 # define alloca _alloca
652 # else
653 # define YYSTACK_ALLOC alloca
654 # if ! defined _ALLOCA_H && ! defined EXIT_SUCCESS
655 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
656 /* Use EXIT_SUCCESS as a witness for stdlib.h. */
657 # ifndef EXIT_SUCCESS
658 # define EXIT_SUCCESS 0
659 # endif
660 # endif
661 # endif
662 # endif
663 # endif
664
665 # ifdef YYSTACK_ALLOC
666 /* Pacify GCC's 'empty if-body' warning. */
667 # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0)
668 # ifndef YYSTACK_ALLOC_MAXIMUM
669 /* The OS might guarantee only one guard page at the bottom of the stack,
670 and a page size can be as small as 4096 bytes. So we cannot safely
671 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
672 to allow for a few compiler-allocated temporary stack slots. */
673 # define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
674 # endif
675 # else
676 # define YYSTACK_ALLOC YYMALLOC
677 # define YYSTACK_FREE YYFREE
678 # ifndef YYSTACK_ALLOC_MAXIMUM
679 # define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
680 # endif
681 # if (defined __cplusplus && ! defined EXIT_SUCCESS \
682 && ! ((defined YYMALLOC || defined malloc) \
683 && (defined YYFREE || defined free)))
684 # include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
685 # ifndef EXIT_SUCCESS
686 # define EXIT_SUCCESS 0
687 # endif
688 # endif
689 # ifndef YYMALLOC
690 # define YYMALLOC malloc
691 # if ! defined malloc && ! defined EXIT_SUCCESS
692 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
693 # endif
694 # endif
695 # ifndef YYFREE
696 # define YYFREE free
697 # if ! defined free && ! defined EXIT_SUCCESS
698 void free (void *); /* INFRINGES ON USER NAME SPACE */
699 # endif
700 # endif
701 # endif
702 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
703
704
705 #if (! defined yyoverflow \
706 && (! defined __cplusplus \
707 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
708
709 /* A type that is properly aligned for any stack member. */
710 union yyalloc
711 {
712 yytype_int16 yyss_alloc;
713 YYSTYPE yyvs_alloc;
714 };
715
716 /* The size of the maximum gap between one aligned stack and the next. */
717 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
718
719 /* The size of an array large to enough to hold all stacks, each with
720 N elements. */
721 # define YYSTACK_BYTES(N) \
722 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
723 + YYSTACK_GAP_MAXIMUM)
724
725 # define YYCOPY_NEEDED 1
726
727 /* Relocate STACK from its old location to the new one. The
728 local variables YYSIZE and YYSTACKSIZE give the old and new number of
729 elements in the stack, and YYPTR gives the new location of the
730 stack. Advance YYPTR to a properly aligned location for the next
731 stack. */
732 # define YYSTACK_RELOCATE(Stack_alloc, Stack) \
733 do \
734 { \
735 YYSIZE_T yynewbytes; \
736 YYCOPY (&yyptr->Stack_alloc, Stack, yysize); \
737 Stack = &yyptr->Stack_alloc; \
738 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
739 yyptr += yynewbytes / sizeof (*yyptr); \
740 } \
741 while (0)
742
743 #endif
744
745 #if defined YYCOPY_NEEDED && YYCOPY_NEEDED
746 /* Copy COUNT objects from SRC to DST. The source and destination do
747 not overlap. */
748 # ifndef YYCOPY
749 # if defined __GNUC__ && 1 < __GNUC__
750 # define YYCOPY(Dst, Src, Count) \
751 __builtin_memcpy (Dst, Src, (Count) * sizeof (*(Src)))
752 # else
753 # define YYCOPY(Dst, Src, Count) \
754 do \
755 { \
756 YYSIZE_T yyi; \
757 for (yyi = 0; yyi < (Count); yyi++) \
758 (Dst)[yyi] = (Src)[yyi]; \
759 } \
760 while (0)
761 # endif
762 # endif
763 #endif /* !YYCOPY_NEEDED */
764
765 /* YYFINAL -- State number of the termination state. */
766 #define YYFINAL 2
767 /* YYLAST -- Last index in YYTABLE. */
768 #define YYLAST 702
769
770 /* YYNTOKENS -- Number of terminals. */
771 #define YYNTOKENS 134
772 /* YYNNTS -- Number of nonterminals. */
773 #define YYNNTS 95
774 /* YYNRULES -- Number of rules. */
775 #define YYNRULES 312
776 /* YYNSTATES -- Number of states. */
777 #define YYNSTATES 579
778
779 #define YYUNDEFTOK 2
780 #define YYMAXUTOK 378
781
782 /* YYTRANSLATE(TOKEN-NUM) -- Symbol number corresponding to TOKEN-NUM
783 as returned by yylex, with out-of-bounds checking. */
784 #define YYTRANSLATE(YYX) \
785 ((unsigned) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
786
787 /* YYTRANSLATE[TOKEN-NUM] -- Symbol number corresponding to TOKEN-NUM
788 as returned by yylex. */
789 static const yytype_uint8 yytranslate[] =
790 {
791 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
792 124, 2, 2, 2, 2, 2, 2, 2, 2, 2,
793 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
794 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
795 2, 2, 2, 129, 131, 130, 2, 128, 2, 2,
796 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
797 132, 125, 133, 2, 2, 2, 2, 2, 2, 2,
798 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
799 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
800 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
801 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
802 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
803 2, 2, 2, 126, 2, 127, 2, 2, 2, 2,
804 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
805 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
806 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
807 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
808 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
809 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
810 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
811 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
812 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
813 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
814 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
815 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
816 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
817 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
818 15, 16, 17, 18, 19, 20, 21, 22, 23, 24,
819 25, 26, 27, 28, 29, 30, 31, 32, 33, 34,
820 35, 36, 37, 38, 39, 40, 41, 42, 43, 44,
821 45, 46, 47, 48, 49, 50, 51, 52, 53, 54,
822 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
823 65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
824 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
825 85, 86, 87, 88, 89, 90, 91, 92, 93, 94,
826 95, 96, 97, 98, 99, 100, 101, 102, 103, 104,
827 105, 106, 107, 108, 109, 110, 111, 112, 113, 114,
828 115, 116, 117, 118, 119, 120, 121, 122, 123
829 };
830
831 #if YYDEBUG
832 /* YYRLINE[YYN] -- Source line where rule number YYN was defined. */
833 static const yytype_uint16 yyrline[] =
834 {
835 0, 251, 251, 252, 253, 254, 255, 256, 257, 258,
836 259, 260, 261, 262, 263, 264, 265, 266, 269, 280,
837 312, 322, 349, 354, 360, 363, 378, 398, 413, 413,
838 427, 435, 436, 438, 438, 448, 458, 472, 488, 505,
839 505, 510, 513, 513, 525, 537, 547, 559, 568, 568,
840 580, 581, 583, 594, 602, 612, 619, 623, 630, 638,
841 646, 660, 667, 678, 684, 690, 699, 700, 728, 760,
842 761, 771, 781, 794, 807, 820, 836, 843, 859, 859,
843 869, 870, 879, 888, 889, 897, 927, 948, 977, 996,
844 1020, 1040, 1041, 1044, 1045, 1048, 1069, 1087, 1107, 1114,
845 1117, 1118, 1121, 1121, 1166, 1167, 1168, 1169, 1172, 1190,
846 1208, 1226, 1232, 1235, 1236, 1235, 1270, 1270, 1302, 1303,
847 1304, 1305, 1306, 1309, 1310, 1311, 1314, 1315, 1316, 1317,
848 1320, 1323, 1330, 1334, 1345, 1358, 1368, 1375, 1378, 1381,
849 1392, 1408, 1416, 1424, 1443, 1446, 1449, 1452, 1455, 1458,
850 1461, 1467, 1473, 1488, 1496, 1504, 1522, 1538, 1548, 1641,
851 1644, 1651, 1663, 1664, 1674, 1690, 1702, 1726, 1732, 1743,
852 1749, 1764, 1765, 1775, 1776, 1779, 1780, 1781, 1784, 1785,
853 1788, 1789, 1792, 1795, 1828, 1855, 1856, 1857, 1860, 1861,
854 1864, 1865, 1868, 1869, 1870, 1872, 1873, 1879, 1901, 1902,
855 1905, 1906, 1912, 1919, 1939, 1946, 1967, 1973, 1981, 1996,
856 2011, 2012, 2015, 2016, 2017, 2029, 2030, 2036, 2051, 2052,
857 2055, 2056, 2068, 2072, 2079, 2102, 2103, 2104, 2117, 2118,
858 2124, 2132, 2138, 2146, 2160, 2163, 2163, 2171, 2172, 2175,
859 2188, 2195, 2207, 2219, 2237, 2259, 2278, 2286, 2293, 2342,
860 2362, 2372, 2373, 2379, 2390, 2433, 2449, 2450, 2451, 2452,
861 2455, 2456, 2463, 2466, 2471, 2480, 2481, 2484, 2485, 2488,
862 2503, 2513, 2523, 2538, 2548, 2558, 2573, 2583, 2593, 2608,
863 2618, 2628, 2635, 2640, 2645, 2650, 2655, 2665, 2675, 2680,
864 2707, 2721, 2749, 2767, 2783, 2791, 2806, 2821, 2822, 2825,
865 2826, 2827, 2828, 2831, 2832, 2833, 2834, 2835, 2836, 2839,
866 2840, 2843, 2844
867 };
868 #endif
869
870 #if YYDEBUG || YYERROR_VERBOSE || 0
871 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
872 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
873 static const char *const yytname[] =
874 {
875 "$end", "error", "$undefined", "AS", "ROUTERID", "HOLDTIME", "YMIN",
876 "LISTEN", "ON", "FIBUPDATE", "FIBPRIORITY", "RTABLE", "NONE", "UNICAST",
877 "VPN", "RD", "EXPORT", "EXPORTTRGT", "IMPORTTRGT", "DEFAULTROUTE", "RDE",
878 "RIB", "EVALUATE", "IGNORE", "COMPARE", "RTR", "PORT", "GROUP",
879 "NEIGHBOR", "NETWORK", "EBGP", "IBGP", "LOCALAS", "REMOTEAS", "DESCR",
880 "LOCALADDR", "MULTIHOP", "PASSIVE", "MAXPREFIX", "RESTART", "ANNOUNCE",
881 "CAPABILITIES", "REFRESH", "AS4BYTE", "CONNECTRETRY", "DEMOTE",
882 "ENFORCE", "NEIGHBORAS", "ASOVERRIDE", "REFLECTOR", "DEPEND", "DOWN",
883 "DUMP", "IN", "OUT", "SOCKET", "RESTRICTED", "LOG", "TRANSPARENT", "TCP",
884 "MD5SIG", "PASSWORD", "KEY", "TTLSECURITY", "ALLOW", "DENY", "MATCH",
885 "QUICK", "FROM", "TO", "ANY", "CONNECTED", "STATIC", "COMMUNITY",
886 "EXTCOMMUNITY", "LARGECOMMUNITY", "DELETE", "PREFIX", "PREFIXLEN",
887 "PREFIXSET", "ROASET", "ORIGINSET", "OVS", "ASSET", "SOURCEAS",
888 "TRANSITAS", "PEERAS", "MAXASLEN", "MAXASSEQ", "SET", "LOCALPREF", "MED",
889 "METRIC", "NEXTHOP", "REJECT", "BLACKHOLE", "NOMODIFY", "SELF",
890 "PREPEND_SELF", "PREPEND_PEER", "PFTABLE", "WEIGHT", "RTLABEL", "ORIGIN",
891 "PRIORITY", "ERROR", "INCLUDE", "IPSEC", "ESP", "AH", "SPI", "IKE",
892 "IPV4", "IPV6", "QUALIFY", "VIA", "NE", "LE", "GE", "XRANGE", "LONGER",
893 "MAXLEN", "STRING", "NUMBER", "'\\n'", "'='", "'{'", "'}'", "'/'", "'+'",
894 "'-'", "','", "'<'", "'>'", "$accept", "grammar", "asnumber",
895 "as4number", "as4number_any", "string", "yesno", "varset", "include",
896 "as_set", "$@1", "as_set_l", "prefixset", "$@2", "prefixset_l",
897 "prefixset_item", "roa_set", "$@3", "origin_set", "$@4", "roa_set_l",
898 "rtr", "$@5", "rtropt_l", "rtropt", "conf_main", "rib", "$@6", "ribopts",
899 "fibupdate", "mrtdump", "network", "inout", "restricted", "address",
900 "prefix", "addrspec", "optnumber", "l3vpn", "$@7", "l3vpnopts_l",
901 "l3vpnopts", "neighbor", "$@8", "$@9", "group", "$@10", "groupopts_l",
902 "peeropts_h", "peeropts_l", "peeropts", "restart", "family", "safi",
903 "nettype", "espah", "encspec", "filterrule", "action", "quick",
904 "direction", "filter_rib_h", "filter_rib_l", "filter_rib",
905 "filter_peer_h", "filter_peer_l", "filter_peer", "filter_prefix_h",
906 "filter_prefix_m", "filter_prefix_l", "filter_prefix", "filter_as_h",
907 "filter_as_t_l", "filter_as_t", "filter_as_l_h", "filter_as_l",
908 "filter_as", "filter_match_h", "$@11", "filter_match", "filter_elm",
909 "prefixlenop", "filter_as_type", "filter_set", "filter_set_l",
910 "community", "delete", "filter_set_opt", "origincode", "validity",
911 "optnl", "comma", "unaryop", "equalityop", "binaryop", YY_NULLPTR
912 };
913 #endif
914
915 # ifdef YYPRINT
916 /* YYTOKNUM[NUM] -- (External) token number corresponding to the
917 (internal) symbol number NUM (which must be that of a token). */
918 static const yytype_uint16 yytoknum[] =
919 {
920 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
921 265, 266, 267, 268, 269, 270, 271, 272, 273, 274,
922 275, 276, 277, 278, 279, 280, 281, 282, 283, 284,
923 285, 286, 287, 288, 289, 290, 291, 292, 293, 294,
924 295, 296, 297, 298, 299, 300, 301, 302, 303, 304,
925 305, 306, 307, 308, 309, 310, 311, 312, 313, 314,
926 315, 316, 317, 318, 319, 320, 321, 322, 323, 324,
927 325, 326, 327, 328, 329, 330, 331, 332, 333, 334,
928 335, 336, 337, 338, 339, 340, 341, 342, 343, 344,
929 345, 346, 347, 348, 349, 350, 351, 352, 353, 354,
930 355, 356, 357, 358, 359, 360, 361, 362, 363, 364,
931 365, 366, 367, 368, 369, 370, 371, 372, 373, 374,
932 375, 376, 377, 378, 10, 61, 123, 125, 47, 43,
933 45, 44, 60, 62
934 };
935 # endif
936
937 #define YYPACT_NINF -413
938
939 #define yypact_value_is_default(Yystate) \
940 (!!((Yystate) == (-413)))
941
942 #define YYTABLE_NINF -300
943
944 #define yytable_value_is_error(Yytable_value) \
945 0
946
947 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
948 STATE-NUM. */
949 static const yytype_int16 yypact[] =
950 {
951 -413, 476, -413, -81, -24, -48, 21, 99, -10, -8,
952 48, 16, 15, -48, 52, 109, 58, 5, 61, 63,
953 -10, -413, -413, -413, 69, 73, 85, 111, 114, 154,
954 122, 130, -413, 134, 142, 158, 172, 175, 179, 187,
955 195, 220, -413, -413, 222, 223, 250, 224, 225, 249,
956 -413, -413, -413, -413, 211, -413, -413, 227, -413, -48,
957 -413, -413, -413, -413, 337, 233, 234, 335, 201, 236,
958 -413, 238, 241, -413, -413, 239, 240, 275, 96, -413,
959 247, -5, 315, -413, -413, 246, 251, 248, 254, 258,
960 -10, -413, 52, -413, -413, -413, -413, -413, -413, -413,
961 -413, -413, -413, -413, 126, -413, -413, -413, 355, -413,
962 -413, -413, 259, -413, -413, 260, -413, -413, 257, -413,
963 261, 275, 262, 263, 536, -413, -413, -413, 266, 267,
964 275, 269, -413, -413, 274, 270, -413, -413, 251, 251,
965 268, 251, 251, 276, -413, 238, 239, -413, -413, -413,
966 -51, 221, -413, 33, -413, 251, -413, -413, -413, -413,
967 -413, -413, 308, -413, -20, 66, 116, 107, 277, 279,
968 283, 124, 284, 285, 251, 308, -413, 275, 275, -413,
969 288, -413, -413, 274, 287, -413, -413, 191, 289, 290,
970 -413, 292, -413, 251, -413, -413, -413, 30, 294, -10,
971 280, 367, -413, -413, 192, 272, -413, -18, -413, 298,
972 302, -413, 303, 304, -413, 305, 306, -413, -413, -413,
973 -413, -413, -413, -413, -413, -413, 309, 310, -413, -413,
974 -413, 599, 291, -413, -413, 274, -413, -413, 191, 327,
975 82, -27, -413, 191, -413, 203, 556, -413, 293, -24,
976 312, -413, -413, -413, 251, -413, -34, -413, -413, -413,
977 422, -413, 319, 322, -48, 251, -413, 321, 22, 106,
978 390, 324, -24, -24, 52, -48, 333, -413, 334, 45,
979 325, 38, -10, -48, 442, 336, 341, 342, -10, 399,
980 -10, 568, 382, 219, -413, -413, 432, -413, 344, 345,
981 348, 349, -413, -413, -413, -413, -413, -413, -413, -413,
982 82, -413, -413, -413, 82, -413, 203, 251, 350, 346,
983 191, 118, -413, 352, -413, 82, -413, -413, -413, 82,
984 -413, 357, 62, -413, -413, -413, 32, 275, 47, 23,
985 -413, -413, -413, -413, 43, -413, 359, -413, -413, -413,
986 366, -413, 211, -413, 238, -413, -413, 37, -10, -10,
987 -10, -10, 256, -413, -10, -10, -413, -413, 369, -413,
988 286, -413, -413, 281, -413, 251, -413, -10, -413, -413,
989 0, -413, -413, -413, -413, -413, 362, 599, 368, 191,
990 -413, 371, 251, -413, 388, -413, -413, -413, -38, -413,
991 -413, -413, 370, -413, 372, 373, 203, 403, -413, 375,
992 293, 82, -413, -413, -413, -14, 210, 384, 385, 386,
993 -413, -413, -413, 389, 391, 1, -27, -27, 77, -413,
994 -413, -413, 47, -413, 89, 387, 392, -10, 393, 395,
995 396, -413, -413, -413, 397, -413, -413, -413, -413, -413,
996 401, 455, -413, -413, -413, -413, -413, -413, -413, -413,
997 -413, -413, -413, -413, 52, 52, 599, -413, -413, 409,
998 -413, -413, -413, -413, -413, 203, -413, -413, 406, -413,
999 -413, -413, -413, 398, -413, -413, 402, -413, -413, 405,
1000 32, 413, 414, 215, -27, -413, -27, -413, -413, -413,
1001 -413, -413, -413, -413, -413, -413, 132, -413, -413, -413,
1002 415, -413, -413, 94, -38, -413, 203, -413, -413, -413,
1003 -413, 416, 417, -413, -413, -413, 238, 238, 82, 420,
1004 -413, -413, -413, -413, -413, -413, -413, -413, 191, 419,
1005 140, -413, -413, -413, 251, -413, 77, -413, 26, 421,
1006 160, -413, 203, -413, -413, -413, 423, 425, 170, -413,
1007 191, -413, -413, 171, -413, 26, -413, -413, 427, 215,
1008 -413, 94, -413, 429, -413, -413, 430, -413, -413
1009 };
1010
1011 /* YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM.
1012 Performed when YYTABLE does not specify something else to do. Zero
1013 means the default is an error. */
1014 static const yytype_uint16 yydefact[] =
1015 {
1016 2, 0, 1, 0, 0, 0, 0, 0, 0, 0,
1017 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1018 0, 185, 186, 187, 0, 0, 0, 0, 0, 0,
1019 0, 0, 3, 0, 0, 0, 0, 0, 0, 0,
1020 0, 0, 69, 66, 0, 0, 0, 0, 0, 188,
1021 17, 19, 18, 20, 55, 95, 57, 0, 58, 0,
1022 25, 62, 61, 75, 0, 0, 0, 0, 0, 47,
1023 24, 116, 0, 173, 174, 0, 0, 260, 0, 76,
1024 0, 0, 94, 65, 63, 0, 297, 0, 0, 0,
1025 0, 27, 0, 4, 5, 6, 7, 8, 9, 10,
1026 12, 11, 13, 14, 0, 15, 16, 189, 192, 56,
1027 59, 60, 0, 78, 73, 0, 70, 71, 0, 23,
1028 0, 260, 0, 0, 0, 86, 179, 178, 0, 0,
1029 260, 0, 91, 92, 100, 0, 93, 77, 297, 297,
1030 39, 297, 297, 0, 64, 26, 95, 98, 99, 114,
1031 0, 0, 102, 83, 72, 297, 118, 87, 96, 97,
1032 288, 265, 267, 266, 0, 0, 0, 0, 0, 0,
1033 0, 0, 0, 0, 297, 267, 261, 260, 260, 90,
1034 0, 101, 67, 100, 33, 298, 41, 0, 42, 28,
1035 74, 125, 197, 297, 193, 190, 191, 0, 0, 0,
1036 0, 0, 79, 80, 0, 0, 268, 0, 269, 0,
1037 0, 272, 0, 0, 275, 0, 0, 283, 282, 284,
1038 285, 281, 286, 287, 289, 278, 0, 0, 290, 295,
1039 294, 0, 0, 88, 89, 100, 85, 35, 0, 0,
1040 299, 251, 44, 0, 30, 0, 0, 115, 0, 0,
1041 0, 206, 207, 202, 297, 203, 235, 198, 104, 84,
1042 83, 82, 0, 0, 0, 297, 50, 0, 0, 0,
1043 0, 0, 0, 0, 0, 0, 0, 137, 0, 0,
1044 0, 0, 0, 163, 0, 138, 0, 0, 0, 0,
1045 0, 0, 0, 0, 119, 117, 0, 162, 0, 0,
1046 0, 0, 270, 271, 273, 274, 276, 277, 279, 280,
1047 299, 264, 291, 68, 299, 36, 0, 297, 300, 0,
1048 0, 0, 252, 0, 38, 299, 21, 22, 31, 299,
1049 126, 0, 297, 195, 204, 205, 0, 260, 0, 0,
1050 81, 54, 52, 53, 0, 122, 0, 141, 148, 149,
1051 0, 140, 131, 130, 133, 134, 136, 171, 0, 0,
1052 0, 0, 0, 166, 0, 0, 152, 164, 0, 139,
1053 0, 168, 167, 0, 159, 297, 160, 0, 180, 181,
1054 0, 135, 121, 120, 293, 292, 0, 0, 0, 0,
1055 45, 301, 297, 40, 0, 304, 305, 307, 0, 303,
1056 306, 308, 0, 253, 0, 0, 0, 0, 124, 0,
1057 0, 299, 200, 184, 256, 0, 0, 0, 0, 0,
1058 257, 258, 259, 0, 0, 0, 251, 251, 0, 239,
1059 240, 218, 236, 237, 0, 0, 0, 0, 0, 0,
1060 0, 105, 103, 112, 0, 49, 51, 142, 170, 132,
1061 0, 171, 153, 146, 144, 145, 147, 175, 176, 177,
1062 143, 151, 150, 165, 0, 0, 0, 169, 157, 0,
1063 262, 263, 34, 37, 302, 0, 312, 311, 0, 254,
1064 43, 29, 32, 0, 127, 123, 0, 194, 196, 0,
1065 0, 0, 0, 0, 251, 210, 251, 249, 296, 250,
1066 241, 242, 247, 246, 208, 209, 299, 220, 238, 231,
1067 0, 310, 309, 0, 230, 222, 0, 243, 107, 111,
1068 108, 0, 0, 106, 172, 154, 155, 156, 299, 0,
1069 46, 255, 129, 128, 199, 201, 245, 244, 0, 0,
1070 299, 215, 217, 248, 297, 219, 0, 224, 0, 0,
1071 299, 228, 0, 232, 109, 110, 0, 0, 299, 211,
1072 0, 301, 221, 299, 223, 0, 233, 161, 0, 213,
1073 216, 226, 229, 182, 214, 227, 0, 158, 183
1074 };
1075
1076 /* YYPGOTO[NTERM-NUM]. */
1077 static const yytype_int16 yypgoto[] =
1078 {
1079 -413, -413, 13, -177, -237, -87, -7, -413, -413, -413,
1080 -413, -413, -413, -413, -413, -223, -413, -413, -413, -413,
1081 301, -413, -413, -413, 167, -413, -413, -413, -413, 253,
1082 552, 226, 178, -413, -3, -15, -413, -153, -413, -413,
1083 -413, -413, 358, -413, -413, -413, -413, -413, -413, -413,
1084 -227, 113, 295, -413, -413, -413, -413, -413, -413, -413,
1085 -413, -413, -413, -234, -413, -413, -313, -413, -9, 24,
1086 -395, -413, -413, -403, -4, 18, -412, -413, -413, -413,
1087 136, -380, -413, -112, 105, -293, 400, -113, -413, -413,
1088 -135, -298, -413, -413, 59
1089 };
1090
1091 /* YYDEFGOTO[NTERM-NUM]. */
1092 static const yytype_int16 yydefgoto[] =
1093 {
1094 -1, 1, 327, 54, 514, 71, 296, 33, 34, 35,
1095 245, 329, 36, 238, 314, 239, 37, 187, 38, 243,
1096 240, 39, 118, 265, 266, 40, 41, 153, 202, 203,
1097 297, 43, 135, 137, 255, 241, 149, 182, 44, 198,
1098 339, 444, 45, 46, 191, 47, 120, 205, 247, 407,
1099 299, 452, 78, 460, 130, 380, 577, 48, 49, 108,
1100 197, 151, 332, 194, 256, 411, 257, 429, 539, 540,
1101 541, 430, 506, 431, 549, 550, 551, 337, 338, 432,
1102 433, 324, 434, 125, 310, 175, 207, 311, 230, 499,
1103 140, 320, 402, 516, 478
1104 };
1105
1106 /* YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If
1107 positive, shift that token. If negative, reduce the rule whose
1108 number is the opposite. If YYTABLE_NINF, syntax error. */
1109 static const yytype_int16 yytable[] =
1110 {
1111 77, 61, 56, 184, 185, 145, 188, 189, 328, 157,
1112 69, 176, 387, 84, 333, 315, 389, 53, 179, 331,
1113 204, 495, 515, 412, 436, 507, 80, 57, 346, 502,
1114 236, 406, 437, 249, 410, 249, 65, 66, 438, 231,
1115 439, 440, 199, 50, 200, 435, 504, 505, 132, 133,
1116 414, 321, 15, 132, 133, -234, 111, 250, 248, 250,
1117 251, 252, 251, 252, 300, 233, 234, 109, 491, 262,
1118 364, 192, 334, 509, 55, 193, 450, 263, 264, 390,
1119 414, 476, 313, 144, 358, 365, 359, 360, 361, 148,
1120 -234, 451, 477, 322, 323, 352, 353, 394, 51, 52,
1121 253, 147, 253, 208, 301, 319, 67, 59, 492, 209,
1122 210, 468, 60, 490, 542, 62, 543, 134, 348, 336,
1123 161, 415, 163, 55, 416, 349, 417, 81, 418, 419,
1124 344, 420, 421, 422, 423, 424, 509, 68, 64, 435,
1125 425, 509, 511, 562, 58, 347, 201, 441, 326, 52,
1126 442, 512, 55, 572, 55, 60, 254, 73, 74, 426,
1127 427, 420, 421, 422, 221, 570, 473, 126, 127, 482,
1128 445, 63, 510, 428, 70, 386, 488, 535, 376, 388,
1129 486, 79, 391, 82, -299, 83, 317, 354, 72, 211,
1130 404, 85, 259, 318, 405, 212, 213, 409, 128, 86,
1131 129, 217, 218, 219, 220, 511, 317, 87, 546, -297,
1132 511, 326, 52, 318, 512, 513, 326, 52, 262, 512,
1133 548, 73, 74, 116, 117, 413, 263, 264, 89, 55,
1134 387, 75, 76, 88, 395, 396, 397, 90, 530, 214,
1135 466, 398, 560, 399, 91, 215, 216, 225, 146, 76,
1136 400, 401, 565, 226, 227, 92, 544, 474, 93, 545,
1137 560, 343, 53, 318, 544, 565, 94, -212, 457, 458,
1138 459, 318, 355, 267, 471, 366, 489, 268, 104, 553,
1139 367, 372, 95, 374, 544, 53, 53, -225, 269, 195,
1140 196, 318, 270, 271, 544, 544, 96, 569, 571, 97,
1141 -113, 318, 318, 98, 272, 273, 274, 275, 276, 277,
1142 278, 99, 279, 75, 76, 566, 107, 280, 281, 100,
1143 282, 283, 284, 285, 286, 326, 52, 378, 379, 287,
1144 288, 289, 75, 76, 52, 290, 493, 75, 76, 132,
1145 133, 538, 464, 465, 101, 112, 102, 103, 105, 106,
1146 110, 453, 454, 455, 456, 113, 114, 461, 462, 115,
1147 119, 291, -48, 121, 124, 449, 292, 122, 123, 131,
1148 467, 136, 138, 143, 141, 139, 150, 526, 527, 293,
1149 142, 152, 154, 155, 206, 158, 159, 156, 177, 261,
1150 178, 180, 183, 556, 60, 186, 294, 181, 190, 295,
1151 222, 494, 223, 260, 483, 224, 228, 229, 268, 561,
1152 235, 316, 350, 312, 237, 192, 242, 244, 246, 269,
1153 258, 302, 503, 270, 271, 303, 304, 305, 306, 307,
1154 519, 199, 308, 309, 335, 272, 273, 274, 275, 276,
1155 277, 278, 341, 279, 342, 345, 351, 363, 280, 281,
1156 368, 282, 283, 284, 285, 286, 356, 357, 369, 373,
1157 287, 288, 289, 370, 371, 377, 290, 381, 382, 383,
1158 384, 385, 475, 393, 392, 403, 2, 3, 494, 4,
1159 5, 6, 447, 7, 408, 8, 9, 10, 448, 470,
1160 11, 463, 291, 479, 450, 472, 12, 292, -298, 480,
1161 481, 13, 487, 14, -113, 15, 496, 497, 498, 517,
1162 293, 446, 500, 340, 501, 520, 518, 521, 522, 529,
1163 16, 523, 532, 494, 524, 60, 533, 484, 17, 531,
1164 485, 18, 534, 19, 20, 536, 537, 547, 554, 555,
1165 21, 22, 23, 557, 325, 494, 559, 568, 564, 573,
1166 567, 576, 578, 42, 494, 24, 25, 26, 469, 27,
1167 574, 268, 558, 298, 525, 443, 563, 575, 508, 28,
1168 29, 528, 269, 552, 362, 232, 270, 271, 0, 0,
1169 0, 0, 30, 0, 160, 0, 0, 0, 272, 273,
1170 274, 275, 276, 277, 278, 0, 279, 0, 31, 0,
1171 32, 280, 281, 0, 282, 283, 284, 285, 286, 161,
1172 162, 163, 0, 287, 288, 289, 160, 0, 0, 290,
1173 0, 0, 0, 0, 0, 0, 164, 165, 166, 167,
1174 0, 0, 0, 0, 168, 169, 170, 171, 172, 173,
1175 0, 161, 162, 163, 0, 291, 0, 160, 0, 0,
1176 292, 0, 0, 0, 0, 0, 0, 0, 164, 165,
1177 166, 167, 174, 293, 0, 0, 168, 169, 170, 171,
1178 172, 173, 161, 162, 163, 0, 0, 0, 60, 0,
1179 330, 0, 0, 0, 0, 0, 0, 0, 0, 164,
1180 165, 166, 167, 0, 375, 0, 0, 168, 169, 170,
1181 171, 172, 173
1182 };
1183
1184 static const yytype_int16 yycheck[] =
1185 {
1186 15, 8, 5, 138, 139, 92, 141, 142, 245, 121,
1187 13, 124, 310, 20, 248, 238, 314, 4, 130, 246,
1188 155, 416, 434, 336, 1, 428, 21, 6, 6, 28,
1189 183, 329, 9, 3, 332, 3, 21, 22, 15, 174,
1190 17, 18, 9, 124, 11, 338, 426, 427, 53, 54,
1191 3, 78, 29, 53, 54, 89, 59, 27, 193, 27,
1192 30, 31, 30, 31, 82, 177, 178, 54, 82, 26,
1193 32, 122, 249, 47, 122, 126, 39, 34, 35, 316,
1194 3, 119, 235, 90, 39, 47, 41, 42, 43, 104,
1195 124, 54, 130, 120, 121, 272, 273, 320, 122, 123,
1196 70, 104, 70, 123, 122, 240, 91, 8, 122, 129,
1197 130, 111, 122, 411, 494, 123, 496, 122, 12, 254,
1198 73, 74, 75, 122, 77, 19, 79, 122, 81, 82,
1199 265, 84, 85, 86, 87, 88, 47, 122, 122, 432,
1200 93, 47, 116, 546, 123, 123, 153, 124, 122, 123,
1201 127, 125, 122, 565, 122, 122, 126, 112, 113, 112,
1202 113, 84, 85, 86, 167, 560, 389, 71, 72, 406,
1203 127, 123, 83, 126, 122, 310, 410, 490, 291, 314,
1204 407, 123, 317, 122, 122, 122, 124, 274, 79, 123,
1205 325, 122, 199, 131, 329, 129, 130, 332, 102, 126,
1206 104, 94, 95, 96, 97, 116, 124, 122, 506, 127,
1207 116, 122, 123, 131, 125, 126, 122, 123, 26, 125,
1208 126, 112, 113, 22, 23, 337, 34, 35, 114, 122,
1209 528, 122, 123, 122, 116, 117, 118, 83, 475, 123,
1210 375, 123, 540, 125, 122, 129, 130, 123, 122, 123,
1211 132, 133, 550, 129, 130, 125, 124, 392, 124, 127,
1212 558, 264, 249, 131, 124, 563, 124, 127, 12, 13,
1213 14, 131, 275, 1, 387, 282, 411, 5, 28, 516,
1214 283, 288, 124, 290, 124, 272, 273, 127, 16, 68,
1215 69, 131, 20, 21, 124, 124, 124, 127, 127, 124,
1216 28, 131, 131, 124, 32, 33, 34, 35, 36, 37,
1217 38, 124, 40, 122, 123, 552, 67, 45, 46, 124,
1218 48, 49, 50, 51, 52, 122, 123, 108, 109, 57,
1219 58, 59, 122, 123, 123, 63, 126, 122, 123, 53,
1220 54, 126, 61, 62, 124, 8, 124, 124, 124, 124,
1221 123, 358, 359, 360, 361, 122, 122, 364, 365, 24,
1222 122, 89, 126, 122, 89, 352, 94, 128, 128, 122,
1223 377, 56, 126, 115, 126, 124, 21, 464, 465, 107,
1224 126, 122, 122, 126, 76, 123, 123, 126, 122, 22,
1225 123, 122, 122, 528, 122, 127, 124, 123, 122, 127,
1226 123, 416, 123, 123, 1, 122, 122, 122, 5, 544,
1227 122, 84, 22, 122, 127, 122, 127, 127, 126, 16,
1228 126, 123, 425, 20, 21, 123, 123, 123, 123, 123,
1229 437, 9, 123, 123, 122, 32, 33, 34, 35, 36,
1230 37, 38, 123, 40, 122, 124, 122, 122, 45, 46,
1231 8, 48, 49, 50, 51, 52, 123, 123, 122, 60,
1232 57, 58, 59, 122, 122, 83, 63, 35, 124, 124,
1233 122, 122, 84, 127, 124, 123, 0, 1, 493, 3,
1234 4, 5, 123, 7, 127, 9, 10, 11, 122, 127,
1235 14, 122, 89, 123, 39, 127, 20, 94, 127, 127,
1236 127, 25, 127, 27, 28, 29, 122, 122, 122, 122,
1237 107, 344, 123, 260, 123, 122, 124, 122, 122, 110,
1238 44, 124, 124, 538, 123, 122, 124, 124, 52, 123,
1239 127, 55, 127, 57, 58, 122, 122, 122, 122, 122,
1240 64, 65, 66, 123, 243, 560, 127, 122, 127, 122,
1241 127, 122, 122, 1, 569, 79, 80, 81, 380, 83,
1242 569, 5, 538, 205, 451, 339, 548, 571, 432, 93,
1243 94, 466, 16, 514, 279, 175, 20, 21, -1, -1,
1244 -1, -1, 106, -1, 48, -1, -1, -1, 32, 33,
1245 34, 35, 36, 37, 38, -1, 40, -1, 122, -1,
1246 124, 45, 46, -1, 48, 49, 50, 51, 52, 73,
1247 74, 75, -1, 57, 58, 59, 48, -1, -1, 63,
1248 -1, -1, -1, -1, -1, -1, 90, 91, 92, 93,
1249 -1, -1, -1, -1, 98, 99, 100, 101, 102, 103,
1250 -1, 73, 74, 75, -1, 89, -1, 48, -1, -1,
1251 94, -1, -1, -1, -1, -1, -1, -1, 90, 91,
1252 92, 93, 126, 107, -1, -1, 98, 99, 100, 101,
1253 102, 103, 73, 74, 75, -1, -1, -1, 122, -1,
1254 124, -1, -1, -1, -1, -1, -1, -1, -1, 90,
1255 91, 92, 93, -1, 126, -1, -1, 98, 99, 100,
1256 101, 102, 103
1257 };
1258
1259 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
1260 symbol of state STATE-NUM. */
1261 static const yytype_uint8 yystos[] =
1262 {
1263 0, 135, 0, 1, 3, 4, 5, 7, 9, 10,
1264 11, 14, 20, 25, 27, 29, 44, 52, 55, 57,
1265 58, 64, 65, 66, 79, 80, 81, 83, 93, 94,
1266 106, 122, 124, 141, 142, 143, 146, 150, 152, 155,
1267 159, 160, 164, 165, 172, 176, 177, 179, 191, 192,
1268 124, 122, 123, 136, 137, 122, 168, 6, 123, 8,
1269 122, 140, 123, 123, 122, 21, 22, 91, 122, 168,
1270 122, 139, 79, 112, 113, 122, 123, 169, 186, 123,
1271 21, 122, 122, 122, 140, 122, 126, 122, 122, 114,
1272 83, 122, 125, 124, 124, 124, 124, 124, 124, 124,
1273 124, 124, 124, 124, 28, 124, 124, 67, 193, 136,
1274 123, 168, 8, 122, 122, 24, 22, 23, 156, 122,
1275 180, 122, 128, 128, 89, 217, 71, 72, 102, 104,
1276 188, 122, 53, 54, 122, 166, 56, 167, 126, 124,
1277 224, 126, 126, 115, 140, 139, 122, 168, 169, 170,
1278 21, 195, 122, 161, 122, 126, 126, 217, 123, 123,
1279 48, 73, 74, 75, 90, 91, 92, 93, 98, 99,
1280 100, 101, 102, 103, 126, 219, 221, 122, 123, 217,
1281 122, 123, 171, 122, 224, 224, 127, 151, 224, 224,
1282 122, 178, 122, 126, 197, 68, 69, 194, 173, 9,
1283 11, 140, 162, 163, 224, 181, 76, 220, 123, 129,
1284 130, 123, 129, 130, 123, 129, 130, 94, 95, 96,
1285 97, 168, 123, 123, 122, 123, 129, 130, 122, 122,
1286 222, 224, 220, 217, 217, 122, 171, 127, 147, 149,
1287 154, 169, 127, 153, 127, 144, 126, 182, 224, 3,
1288 27, 30, 31, 70, 126, 168, 198, 200, 126, 140,
1289 123, 22, 26, 34, 35, 157, 158, 1, 5, 16,
1290 20, 21, 32, 33, 34, 35, 36, 37, 38, 40,
1291 45, 46, 48, 49, 50, 51, 52, 57, 58, 59,
1292 63, 89, 94, 107, 124, 127, 140, 164, 176, 184,
1293 82, 122, 123, 123, 123, 123, 123, 123, 123, 123,
1294 218, 221, 122, 171, 148, 149, 84, 124, 131, 224,
1295 225, 78, 120, 121, 215, 154, 122, 136, 138, 145,
1296 124, 184, 196, 197, 137, 122, 224, 211, 212, 174,
1297 163, 123, 122, 168, 224, 124, 6, 123, 12, 19,
1298 22, 122, 137, 137, 139, 168, 123, 123, 39, 41,
1299 42, 43, 186, 122, 32, 47, 140, 168, 8, 122,
1300 122, 122, 140, 60, 140, 126, 221, 83, 108, 109,
1301 189, 35, 124, 124, 122, 122, 224, 225, 224, 225,
1302 138, 224, 124, 127, 149, 116, 117, 118, 123, 125,
1303 132, 133, 226, 123, 224, 224, 225, 183, 127, 224,
1304 225, 199, 200, 217, 3, 74, 77, 79, 81, 82,
1305 84, 85, 86, 87, 88, 93, 112, 113, 126, 201,
1306 205, 207, 213, 214, 216, 219, 1, 9, 15, 17,
1307 18, 124, 127, 165, 175, 127, 158, 123, 122, 136,
1308 39, 54, 185, 140, 140, 140, 140, 12, 13, 14,
1309 187, 140, 140, 122, 61, 62, 224, 140, 111, 166,
1310 127, 221, 127, 149, 224, 84, 119, 130, 228, 123,
1311 127, 127, 138, 1, 124, 127, 184, 127, 197, 224,
1312 225, 82, 122, 126, 169, 204, 122, 122, 122, 223,
1313 123, 123, 28, 168, 215, 215, 206, 207, 214, 47,
1314 83, 116, 125, 126, 138, 210, 227, 122, 124, 140,
1315 122, 122, 122, 124, 123, 185, 139, 139, 218, 110,
1316 138, 123, 124, 124, 127, 200, 122, 122, 126, 202,
1317 203, 204, 215, 215, 124, 127, 225, 122, 126, 208,
1318 209, 210, 228, 138, 122, 122, 224, 123, 203, 127,
1319 225, 224, 207, 209, 127, 225, 138, 127, 122, 127,
1320 204, 127, 210, 122, 202, 208, 122, 190, 122
1321 };
1322
1323 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
1324 static const yytype_uint8 yyr1[] =
1325 {
1326 0, 134, 135, 135, 135, 135, 135, 135, 135, 135,
1327 135, 135, 135, 135, 135, 135, 135, 135, 136, 137,
1328 137, 138, 138, 139, 139, 140, 141, 142, 144, 143,
1329 143, 145, 145, 147, 146, 146, 148, 148, 149, 151,
1330 150, 150, 153, 152, 152, 154, 154, 155, 156, 155,
1331 157, 157, 158, 158, 158, 159, 159, 159, 159, 159,
1332 159, 159, 159, 159, 159, 159, 159, 159, 159, 159,
1333 159, 159, 159, 159, 159, 159, 159, 159, 161, 160,
1334 162, 162, 162, 163, 163, 164, 165, 165, 165, 165,
1335 165, 166, 166, 167, 167, 168, 169, 169, 170, 170,
1336 171, 171, 173, 172, 174, 174, 174, 174, 175, 175,
1337 175, 175, 175, 177, 178, 176, 180, 179, 181, 181,
1338 181, 181, 181, 182, 182, 182, 183, 183, 183, 183,
1339 184, 184, 184, 184, 184, 184, 184, 184, 184, 184,
1340 184, 184, 184, 184, 184, 184, 184, 184, 184, 184,
1341 184, 184, 184, 184, 184, 184, 184, 184, 184, 184,
1342 184, 184, 184, 184, 184, 184, 184, 184, 184, 184,
1343 184, 185, 185, 186, 186, 187, 187, 187, 188, 188,
1344 189, 189, 190, 190, 191, 192, 192, 192, 193, 193,
1345 194, 194, 195, 195, 195, 196, 196, 197, 198, 198,
1346 199, 199, 200, 200, 200, 200, 200, 200, 201, 201,
1347 201, 201, 202, 202, 202, 203, 203, 204, 205, 205,
1348 206, 206, 207, 207, 207, 208, 208, 208, 209, 209,
1349 210, 210, 210, 210, 211, 212, 211, 213, 213, 214,
1350 214, 214, 214, 214, 214, 214, 214, 214, 214, 214,
1351 214, 215, 215, 215, 215, 215, 216, 216, 216, 216,
1352 217, 217, 217, 218, 218, 219, 219, 220, 220, 221,
1353 221, 221, 221, 221, 221, 221, 221, 221, 221, 221,
1354 221, 221, 221, 221, 221, 221, 221, 221, 221, 221,
1355 221, 221, 221, 221, 221, 222, 223, 224, 224, 225,
1356 225, 225, 225, 226, 226, 226, 226, 226, 226, 227,
1357 227, 228, 228
1358 };
1359
1360 /* YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. */
1361 static const yytype_uint8 yyr2[] =
1362 {
1363 0, 2, 0, 2, 3, 3, 3, 3, 3, 3,
1364 3, 3, 3, 3, 3, 3, 3, 3, 1, 1,
1365 1, 1, 1, 2, 1, 1, 3, 2, 0, 8,
1366 5, 1, 3, 0, 8, 5, 1, 3, 2, 0,
1367 7, 4, 0, 8, 5, 3, 5, 2, 0, 8,
1368 1, 3, 2, 2, 2, 2, 3, 2, 2, 3,
1369 3, 2, 2, 2, 3, 2, 1, 4, 6, 1,
1370 3, 3, 4, 3, 4, 2, 2, 3, 0, 5,
1371 1, 3, 2, 0, 2, 5, 3, 4, 5, 5,
1372 4, 1, 1, 1, 0, 1, 3, 3, 1, 1,
1373 0, 1, 0, 8, 0, 2, 3, 3, 2, 3,
1374 3, 2, 1, 0, 0, 5, 0, 6, 0, 2,
1375 3, 3, 3, 4, 3, 0, 0, 2, 3, 3,
1376 2, 2, 3, 2, 2, 2, 2, 1, 1, 2,
1377 2, 2, 3, 3, 3, 3, 3, 3, 2, 2,
1378 3, 3, 2, 3, 4, 4, 4, 3, 8, 2,
1379 2, 6, 1, 1, 2, 3, 2, 2, 2, 3,
1380 3, 0, 2, 1, 1, 1, 1, 1, 1, 1,
1381 1, 1, 0, 2, 7, 1, 1, 1, 0, 1,
1382 1, 1, 0, 2, 6, 1, 3, 1, 1, 5,
1383 1, 3, 1, 1, 2, 2, 1, 1, 2, 2,
1384 2, 4, 1, 3, 4, 1, 3, 2, 1, 3,
1385 1, 3, 2, 4, 3, 1, 3, 4, 1, 3,
1386 1, 1, 2, 3, 0, 0, 2, 1, 2, 1,
1387 1, 2, 2, 2, 3, 3, 2, 2, 3, 2,
1388 2, 0, 1, 2, 3, 4, 1, 1, 1, 1,
1389 0, 2, 6, 3, 1, 1, 1, 0, 1, 2,
1390 3, 3, 2, 3, 3, 2, 3, 3, 2, 3,
1391 3, 2, 2, 2, 2, 2, 2, 2, 1, 2,
1392 2, 3, 4, 4, 2, 1, 1, 0, 2, 0,
1393 1, 2, 3, 1, 1, 1, 1, 1, 1, 1,
1394 1, 1, 1
1395 };
1396
1397
1398 #define yyerrok (yyerrstatus = 0)
1399 #define yyclearin (yychar = YYEMPTY)
1400 #define YYEMPTY (-2)
1401 #define YYEOF 0
1402
1403 #define YYACCEPT goto yyacceptlab
1404 #define YYABORT goto yyabortlab
1405 #define YYERROR goto yyerrorlab
1406
1407
1408 #define YYRECOVERING() (!!yyerrstatus)
1409
1410 #define YYBACKUP(Token, Value) \
1411 do \
1412 if (yychar == YYEMPTY) \
1413 { \
1414 yychar = (Token); \
1415 yylval = (Value); \
1416 YYPOPSTACK (yylen); \
1417 yystate = *yyssp; \
1418 goto yybackup; \
1419 } \
1420 else \
1421 { \
1422 yyerror (YY_("syntax error: cannot back up")); \
1423 YYERROR; \
1424 } \
1425 while (0)
1426
1427 /* Error token number */
1428 #define YYTERROR 1
1429 #define YYERRCODE 256
1430
1431
1432
1433 /* Enable debugging if requested. */
1434 #if YYDEBUG
1435
1436 # ifndef YYFPRINTF
1437 # include <stdio.h> /* INFRINGES ON USER NAME SPACE */
1438 # define YYFPRINTF fprintf
1439 # endif
1440
1441 # define YYDPRINTF(Args) \
1442 do { \
1443 if (yydebug) \
1444 YYFPRINTF Args; \
1445 } while (0)
1446
1447 /* This macro is provided for backward compatibility. */
1448 #ifndef YY_LOCATION_PRINT
1449 # define YY_LOCATION_PRINT(File, Loc) ((void) 0)
1450 #endif
1451
1452
1453 # define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
1454 do { \
1455 if (yydebug) \
1456 { \
1457 YYFPRINTF (stderr, "%s ", Title); \
1458 yy_symbol_print (stderr, \
1459 Type, Value); \
1460 YYFPRINTF (stderr, "\n"); \
1461 } \
1462 } while (0)
1463
1464
1465 /*-----------------------------------.
1466 | Print this symbol's value on YYO. |
1467 `-----------------------------------*/
1468
1469 static void
yy_symbol_value_print(FILE * yyo,int yytype,YYSTYPE const * const yyvaluep)1470 yy_symbol_value_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep)
1471 {
1472 FILE *yyoutput = yyo;
1473 YYUSE (yyoutput);
1474 if (!yyvaluep)
1475 return;
1476 # ifdef YYPRINT
1477 if (yytype < YYNTOKENS)
1478 YYPRINT (yyo, yytoknum[yytype], *yyvaluep);
1479 # endif
1480 YYUSE (yytype);
1481 }
1482
1483
1484 /*---------------------------.
1485 | Print this symbol on YYO. |
1486 `---------------------------*/
1487
1488 static void
yy_symbol_print(FILE * yyo,int yytype,YYSTYPE const * const yyvaluep)1489 yy_symbol_print (FILE *yyo, int yytype, YYSTYPE const * const yyvaluep)
1490 {
1491 YYFPRINTF (yyo, "%s %s (",
1492 yytype < YYNTOKENS ? "token" : "nterm", yytname[yytype]);
1493
1494 yy_symbol_value_print (yyo, yytype, yyvaluep);
1495 YYFPRINTF (yyo, ")");
1496 }
1497
1498 /*------------------------------------------------------------------.
1499 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
1500 | TOP (included). |
1501 `------------------------------------------------------------------*/
1502
1503 static void
yy_stack_print(yytype_int16 * yybottom,yytype_int16 * yytop)1504 yy_stack_print (yytype_int16 *yybottom, yytype_int16 *yytop)
1505 {
1506 YYFPRINTF (stderr, "Stack now");
1507 for (; yybottom <= yytop; yybottom++)
1508 {
1509 int yybot = *yybottom;
1510 YYFPRINTF (stderr, " %d", yybot);
1511 }
1512 YYFPRINTF (stderr, "\n");
1513 }
1514
1515 # define YY_STACK_PRINT(Bottom, Top) \
1516 do { \
1517 if (yydebug) \
1518 yy_stack_print ((Bottom), (Top)); \
1519 } while (0)
1520
1521
1522 /*------------------------------------------------.
1523 | Report that the YYRULE is going to be reduced. |
1524 `------------------------------------------------*/
1525
1526 static void
yy_reduce_print(yytype_int16 * yyssp,YYSTYPE * yyvsp,int yyrule)1527 yy_reduce_print (yytype_int16 *yyssp, YYSTYPE *yyvsp, int yyrule)
1528 {
1529 unsigned long yylno = yyrline[yyrule];
1530 int yynrhs = yyr2[yyrule];
1531 int yyi;
1532 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
1533 yyrule - 1, yylno);
1534 /* The symbols being reduced. */
1535 for (yyi = 0; yyi < yynrhs; yyi++)
1536 {
1537 YYFPRINTF (stderr, " $%d = ", yyi + 1);
1538 yy_symbol_print (stderr,
1539 yystos[yyssp[yyi + 1 - yynrhs]],
1540 &yyvsp[(yyi + 1) - (yynrhs)]
1541 );
1542 YYFPRINTF (stderr, "\n");
1543 }
1544 }
1545
1546 # define YY_REDUCE_PRINT(Rule) \
1547 do { \
1548 if (yydebug) \
1549 yy_reduce_print (yyssp, yyvsp, Rule); \
1550 } while (0)
1551
1552 /* Nonzero means print parse trace. It is left uninitialized so that
1553 multiple parsers can coexist. */
1554 int yydebug;
1555 #else /* !YYDEBUG */
1556 # define YYDPRINTF(Args)
1557 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
1558 # define YY_STACK_PRINT(Bottom, Top)
1559 # define YY_REDUCE_PRINT(Rule)
1560 #endif /* !YYDEBUG */
1561
1562
1563 /* YYINITDEPTH -- initial size of the parser's stacks. */
1564 #ifndef YYINITDEPTH
1565 # define YYINITDEPTH 200
1566 #endif
1567
1568 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
1569 if the built-in stack extension method is used).
1570
1571 Do not make this value too large; the results are undefined if
1572 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
1573 evaluated with infinite-precision integer arithmetic. */
1574
1575 #ifndef YYMAXDEPTH
1576 # define YYMAXDEPTH 10000
1577 #endif
1578
1579
1580 #if YYERROR_VERBOSE
1581
1582 # ifndef yystrlen
1583 # if defined __GLIBC__ && defined _STRING_H
1584 # define yystrlen strlen
1585 # else
1586 /* Return the length of YYSTR. */
1587 static YYSIZE_T
yystrlen(const char * yystr)1588 yystrlen (const char *yystr)
1589 {
1590 YYSIZE_T yylen;
1591 for (yylen = 0; yystr[yylen]; yylen++)
1592 continue;
1593 return yylen;
1594 }
1595 # endif
1596 # endif
1597
1598 # ifndef yystpcpy
1599 # if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
1600 # define yystpcpy stpcpy
1601 # else
1602 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
1603 YYDEST. */
1604 static char *
yystpcpy(char * yydest,const char * yysrc)1605 yystpcpy (char *yydest, const char *yysrc)
1606 {
1607 char *yyd = yydest;
1608 const char *yys = yysrc;
1609
1610 while ((*yyd++ = *yys++) != '\0')
1611 continue;
1612
1613 return yyd - 1;
1614 }
1615 # endif
1616 # endif
1617
1618 # ifndef yytnamerr
1619 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
1620 quotes and backslashes, so that it's suitable for yyerror. The
1621 heuristic is that double-quoting is unnecessary unless the string
1622 contains an apostrophe, a comma, or backslash (other than
1623 backslash-backslash). YYSTR is taken from yytname. If YYRES is
1624 null, do not copy; instead, return the length of what the result
1625 would have been. */
1626 static YYSIZE_T
yytnamerr(char * yyres,const char * yystr)1627 yytnamerr (char *yyres, const char *yystr)
1628 {
1629 if (*yystr == '"')
1630 {
1631 YYSIZE_T yyn = 0;
1632 char const *yyp = yystr;
1633
1634 for (;;)
1635 switch (*++yyp)
1636 {
1637 case '\'':
1638 case ',':
1639 goto do_not_strip_quotes;
1640
1641 case '\\':
1642 if (*++yyp != '\\')
1643 goto do_not_strip_quotes;
1644 else
1645 goto append;
1646
1647 append:
1648 default:
1649 if (yyres)
1650 yyres[yyn] = *yyp;
1651 yyn++;
1652 break;
1653
1654 case '"':
1655 if (yyres)
1656 yyres[yyn] = '\0';
1657 return yyn;
1658 }
1659 do_not_strip_quotes: ;
1660 }
1661
1662 if (! yyres)
1663 return yystrlen (yystr);
1664
1665 return (YYSIZE_T) (yystpcpy (yyres, yystr) - yyres);
1666 }
1667 # endif
1668
1669 /* Copy into *YYMSG, which is of size *YYMSG_ALLOC, an error message
1670 about the unexpected token YYTOKEN for the state stack whose top is
1671 YYSSP.
1672
1673 Return 0 if *YYMSG was successfully written. Return 1 if *YYMSG is
1674 not large enough to hold the message. In that case, also set
1675 *YYMSG_ALLOC to the required number of bytes. Return 2 if the
1676 required number of bytes is too large to store. */
1677 static int
yysyntax_error(YYSIZE_T * yymsg_alloc,char ** yymsg,yytype_int16 * yyssp,int yytoken)1678 yysyntax_error (YYSIZE_T *yymsg_alloc, char **yymsg,
1679 yytype_int16 *yyssp, int yytoken)
1680 {
1681 YYSIZE_T yysize0 = yytnamerr (YY_NULLPTR, yytname[yytoken]);
1682 YYSIZE_T yysize = yysize0;
1683 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1684 /* Internationalized format string. */
1685 const char *yyformat = YY_NULLPTR;
1686 /* Arguments of yyformat. */
1687 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1688 /* Number of reported tokens (one for the "unexpected", one per
1689 "expected"). */
1690 int yycount = 0;
1691
1692 /* There are many possibilities here to consider:
1693 - If this state is a consistent state with a default action, then
1694 the only way this function was invoked is if the default action
1695 is an error action. In that case, don't check for expected
1696 tokens because there are none.
1697 - The only way there can be no lookahead present (in yychar) is if
1698 this state is a consistent state with a default action. Thus,
1699 detecting the absence of a lookahead is sufficient to determine
1700 that there is no unexpected or expected token to report. In that
1701 case, just report a simple "syntax error".
1702 - Don't assume there isn't a lookahead just because this state is a
1703 consistent state with a default action. There might have been a
1704 previous inconsistent state, consistent state with a non-default
1705 action, or user semantic action that manipulated yychar.
1706 - Of course, the expected token list depends on states to have
1707 correct lookahead information, and it depends on the parser not
1708 to perform extra reductions after fetching a lookahead from the
1709 scanner and before detecting a syntax error. Thus, state merging
1710 (from LALR or IELR) and default reductions corrupt the expected
1711 token list. However, the list is correct for canonical LR with
1712 one exception: it will still contain any token that will not be
1713 accepted due to an error action in a later state.
1714 */
1715 if (yytoken != YYEMPTY)
1716 {
1717 int yyn = yypact[*yyssp];
1718 yyarg[yycount++] = yytname[yytoken];
1719 if (!yypact_value_is_default (yyn))
1720 {
1721 /* Start YYX at -YYN if negative to avoid negative indexes in
1722 YYCHECK. In other words, skip the first -YYN actions for
1723 this state because they are default actions. */
1724 int yyxbegin = yyn < 0 ? -yyn : 0;
1725 /* Stay within bounds of both yycheck and yytname. */
1726 int yychecklim = YYLAST - yyn + 1;
1727 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1728 int yyx;
1729
1730 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1731 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR
1732 && !yytable_value_is_error (yytable[yyx + yyn]))
1733 {
1734 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1735 {
1736 yycount = 1;
1737 yysize = yysize0;
1738 break;
1739 }
1740 yyarg[yycount++] = yytname[yyx];
1741 {
1742 YYSIZE_T yysize1 = yysize + yytnamerr (YY_NULLPTR, yytname[yyx]);
1743 if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
1744 yysize = yysize1;
1745 else
1746 return 2;
1747 }
1748 }
1749 }
1750 }
1751
1752 switch (yycount)
1753 {
1754 # define YYCASE_(N, S) \
1755 case N: \
1756 yyformat = S; \
1757 break
1758 default: /* Avoid compiler warnings. */
1759 YYCASE_(0, YY_("syntax error"));
1760 YYCASE_(1, YY_("syntax error, unexpected %s"));
1761 YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s"));
1762 YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s"));
1763 YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s"));
1764 YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s"));
1765 # undef YYCASE_
1766 }
1767
1768 {
1769 YYSIZE_T yysize1 = yysize + yystrlen (yyformat);
1770 if (yysize <= yysize1 && yysize1 <= YYSTACK_ALLOC_MAXIMUM)
1771 yysize = yysize1;
1772 else
1773 return 2;
1774 }
1775
1776 if (*yymsg_alloc < yysize)
1777 {
1778 *yymsg_alloc = 2 * yysize;
1779 if (! (yysize <= *yymsg_alloc
1780 && *yymsg_alloc <= YYSTACK_ALLOC_MAXIMUM))
1781 *yymsg_alloc = YYSTACK_ALLOC_MAXIMUM;
1782 return 1;
1783 }
1784
1785 /* Avoid sprintf, as that infringes on the user's name space.
1786 Don't have undefined behavior even if the translation
1787 produced a string with the wrong number of "%s"s. */
1788 {
1789 char *yyp = *yymsg;
1790 int yyi = 0;
1791 while ((*yyp = *yyformat) != '\0')
1792 if (*yyp == '%' && yyformat[1] == 's' && yyi < yycount)
1793 {
1794 yyp += yytnamerr (yyp, yyarg[yyi++]);
1795 yyformat += 2;
1796 }
1797 else
1798 {
1799 yyp++;
1800 yyformat++;
1801 }
1802 }
1803 return 0;
1804 }
1805 #endif /* YYERROR_VERBOSE */
1806
1807 /*-----------------------------------------------.
1808 | Release the memory associated to this symbol. |
1809 `-----------------------------------------------*/
1810
1811 static void
yydestruct(const char * yymsg,int yytype,YYSTYPE * yyvaluep)1812 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1813 {
1814 YYUSE (yyvaluep);
1815 if (!yymsg)
1816 yymsg = "Deleting";
1817 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1818
1819 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
1820 YYUSE (yytype);
1821 YY_IGNORE_MAYBE_UNINITIALIZED_END
1822 }
1823
1824
1825
1826
1827 /* The lookahead symbol. */
1828 int yychar;
1829
1830 /* The semantic value of the lookahead symbol. */
1831 YYSTYPE yylval;
1832 /* Number of syntax errors so far. */
1833 int yynerrs;
1834
1835
1836 /*----------.
1837 | yyparse. |
1838 `----------*/
1839
1840 int
yyparse(void)1841 yyparse (void)
1842 {
1843 int yystate;
1844 /* Number of tokens to shift before error messages enabled. */
1845 int yyerrstatus;
1846
1847 /* The stacks and their tools:
1848 'yyss': related to states.
1849 'yyvs': related to semantic values.
1850
1851 Refer to the stacks through separate pointers, to allow yyoverflow
1852 to reallocate them elsewhere. */
1853
1854 /* The state stack. */
1855 yytype_int16 yyssa[YYINITDEPTH];
1856 yytype_int16 *yyss;
1857 yytype_int16 *yyssp;
1858
1859 /* The semantic value stack. */
1860 YYSTYPE yyvsa[YYINITDEPTH];
1861 YYSTYPE *yyvs;
1862 YYSTYPE *yyvsp;
1863
1864 YYSIZE_T yystacksize;
1865
1866 int yyn;
1867 int yyresult;
1868 /* Lookahead token as an internal (translated) token number. */
1869 int yytoken = 0;
1870 /* The variables used to return semantic value and location from the
1871 action routines. */
1872 YYSTYPE yyval;
1873
1874 #if YYERROR_VERBOSE
1875 /* Buffer for error messages, and its allocated size. */
1876 char yymsgbuf[128];
1877 char *yymsg = yymsgbuf;
1878 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1879 #endif
1880
1881 #define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1882
1883 /* The number of symbols on the RHS of the reduced rule.
1884 Keep to zero when no symbol should be popped. */
1885 int yylen = 0;
1886
1887 yyssp = yyss = yyssa;
1888 yyvsp = yyvs = yyvsa;
1889 yystacksize = YYINITDEPTH;
1890
1891 YYDPRINTF ((stderr, "Starting parse\n"));
1892
1893 yystate = 0;
1894 yyerrstatus = 0;
1895 yynerrs = 0;
1896 yychar = YYEMPTY; /* Cause a token to be read. */
1897 goto yysetstate;
1898
1899
1900 /*------------------------------------------------------------.
1901 | yynewstate -- push a new state, which is found in yystate. |
1902 `------------------------------------------------------------*/
1903 yynewstate:
1904 /* In all cases, when you get here, the value and location stacks
1905 have just been pushed. So pushing a state here evens the stacks. */
1906 yyssp++;
1907
1908
1909 /*--------------------------------------------------------------------.
1910 | yynewstate -- set current state (the top of the stack) to yystate. |
1911 `--------------------------------------------------------------------*/
1912 yysetstate:
1913 *yyssp = (yytype_int16) yystate;
1914
1915 if (yyss + yystacksize - 1 <= yyssp)
1916 #if !defined yyoverflow && !defined YYSTACK_RELOCATE
1917 goto yyexhaustedlab;
1918 #else
1919 {
1920 /* Get the current used size of the three stacks, in elements. */
1921 YYSIZE_T yysize = (YYSIZE_T) (yyssp - yyss + 1);
1922
1923 # if defined yyoverflow
1924 {
1925 /* Give user a chance to reallocate the stack. Use copies of
1926 these so that the &'s don't force the real ones into
1927 memory. */
1928 YYSTYPE *yyvs1 = yyvs;
1929 yytype_int16 *yyss1 = yyss;
1930
1931 /* Each stack pointer address is followed by the size of the
1932 data in use in that stack, in bytes. This used to be a
1933 conditional around just the two extra args, but that might
1934 be undefined if yyoverflow is a macro. */
1935 yyoverflow (YY_("memory exhausted"),
1936 &yyss1, yysize * sizeof (*yyssp),
1937 &yyvs1, yysize * sizeof (*yyvsp),
1938 &yystacksize);
1939 yyss = yyss1;
1940 yyvs = yyvs1;
1941 }
1942 # else /* defined YYSTACK_RELOCATE */
1943 /* Extend the stack our own way. */
1944 if (YYMAXDEPTH <= yystacksize)
1945 goto yyexhaustedlab;
1946 yystacksize *= 2;
1947 if (YYMAXDEPTH < yystacksize)
1948 yystacksize = YYMAXDEPTH;
1949
1950 {
1951 yytype_int16 *yyss1 = yyss;
1952 union yyalloc *yyptr =
1953 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1954 if (! yyptr)
1955 goto yyexhaustedlab;
1956 YYSTACK_RELOCATE (yyss_alloc, yyss);
1957 YYSTACK_RELOCATE (yyvs_alloc, yyvs);
1958 # undef YYSTACK_RELOCATE
1959 if (yyss1 != yyssa)
1960 YYSTACK_FREE (yyss1);
1961 }
1962 # endif
1963
1964 yyssp = yyss + yysize - 1;
1965 yyvsp = yyvs + yysize - 1;
1966
1967 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1968 (unsigned long) yystacksize));
1969
1970 if (yyss + yystacksize - 1 <= yyssp)
1971 YYABORT;
1972 }
1973 #endif /* !defined yyoverflow && !defined YYSTACK_RELOCATE */
1974
1975 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1976
1977 if (yystate == YYFINAL)
1978 YYACCEPT;
1979
1980 goto yybackup;
1981
1982
1983 /*-----------.
1984 | yybackup. |
1985 `-----------*/
1986 yybackup:
1987 /* Do appropriate processing given the current state. Read a
1988 lookahead token if we need one and don't already have one. */
1989
1990 /* First try to decide what to do without reference to lookahead token. */
1991 yyn = yypact[yystate];
1992 if (yypact_value_is_default (yyn))
1993 goto yydefault;
1994
1995 /* Not known => get a lookahead token if don't already have one. */
1996
1997 /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
1998 if (yychar == YYEMPTY)
1999 {
2000 YYDPRINTF ((stderr, "Reading a token: "));
2001 yychar = yylex ();
2002 }
2003
2004 if (yychar <= YYEOF)
2005 {
2006 yychar = yytoken = YYEOF;
2007 YYDPRINTF ((stderr, "Now at end of input.\n"));
2008 }
2009 else
2010 {
2011 yytoken = YYTRANSLATE (yychar);
2012 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
2013 }
2014
2015 /* If the proper action on seeing token YYTOKEN is to reduce or to
2016 detect an error, take that action. */
2017 yyn += yytoken;
2018 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
2019 goto yydefault;
2020 yyn = yytable[yyn];
2021 if (yyn <= 0)
2022 {
2023 if (yytable_value_is_error (yyn))
2024 goto yyerrlab;
2025 yyn = -yyn;
2026 goto yyreduce;
2027 }
2028
2029 /* Count tokens shifted since error; after three, turn off error
2030 status. */
2031 if (yyerrstatus)
2032 yyerrstatus--;
2033
2034 /* Shift the lookahead token. */
2035 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
2036
2037 /* Discard the shifted token. */
2038 yychar = YYEMPTY;
2039
2040 yystate = yyn;
2041 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
2042 *++yyvsp = yylval;
2043 YY_IGNORE_MAYBE_UNINITIALIZED_END
2044
2045 goto yynewstate;
2046
2047
2048 /*-----------------------------------------------------------.
2049 | yydefault -- do the default action for the current state. |
2050 `-----------------------------------------------------------*/
2051 yydefault:
2052 yyn = yydefact[yystate];
2053 if (yyn == 0)
2054 goto yyerrlab;
2055 goto yyreduce;
2056
2057
2058 /*-----------------------------.
2059 | yyreduce -- do a reduction. |
2060 `-----------------------------*/
2061 yyreduce:
2062 /* yyn is the number of a rule to reduce with. */
2063 yylen = yyr2[yyn];
2064
2065 /* If YYLEN is nonzero, implement the default value of the action:
2066 '$$ = $1'.
2067
2068 Otherwise, the following line sets YYVAL to garbage.
2069 This behavior is undocumented and Bison
2070 users should not rely upon it. Assigning to YYVAL
2071 unconditionally makes the parser a bit smaller, and it avoids a
2072 GCC warning that YYVAL may be used uninitialized. */
2073 yyval = yyvsp[1-yylen];
2074
2075
2076 YY_REDUCE_PRINT (yyn);
2077 switch (yyn)
2078 {
2079 case 17:
2080 #line 266 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2081 { file->errors++; }
2082 #line 2083 "parse.c" /* yacc.c:1652 */
2083 break;
2084
2085 case 18:
2086 #line 269 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2087 {
2088 /*
2089 * According to iana 65535 and 4294967295 are reserved
2090 * but enforcing this is not duty of the parser.
2091 */
2092 if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > UINT_MAX) {
2093 yyerror("AS too big: max %u", UINT_MAX);
2094 YYERROR;
2095 }
2096 }
2097 #line 2098 "parse.c" /* yacc.c:1652 */
2098 break;
2099
2100 case 19:
2101 #line 280 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2102 {
2103 const char *errstr;
2104 char *dot;
2105 u_int32_t uvalh = 0, uval;
2106
2107 if ((dot = strchr((yyvsp[0].v.string),'.')) != NULL) {
2108 *dot++ = '\0';
2109 uvalh = strtonum((yyvsp[0].v.string), 0, USHRT_MAX, &errstr);
2110 if (errstr) {
2111 yyerror("number %s is %s", (yyvsp[0].v.string), errstr);
2112 free((yyvsp[0].v.string));
2113 YYERROR;
2114 }
2115 uval = strtonum(dot, 0, USHRT_MAX, &errstr);
2116 if (errstr) {
2117 yyerror("number %s is %s", dot, errstr);
2118 free((yyvsp[0].v.string));
2119 YYERROR;
2120 }
2121 free((yyvsp[0].v.string));
2122 } else {
2123 yyerror("AS %s is bad", (yyvsp[0].v.string));
2124 free((yyvsp[0].v.string));
2125 YYERROR;
2126 }
2127 if (uvalh == 0 && (uval == AS_TRANS || uval == 0)) {
2128 yyerror("AS %u is reserved and may not be used",
2129 uval);
2130 YYERROR;
2131 }
2132 (yyval.v.number) = uval | (uvalh << 16);
2133 }
2134 #line 2135 "parse.c" /* yacc.c:1652 */
2135 break;
2136
2137 case 20:
2138 #line 312 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2139 {
2140 if ((yyvsp[0].v.number) == AS_TRANS || (yyvsp[0].v.number) == 0) {
2141 yyerror("AS %u is reserved and may not be used",
2142 (u_int32_t)(yyvsp[0].v.number));
2143 YYERROR;
2144 }
2145 (yyval.v.number) = (yyvsp[0].v.number);
2146 }
2147 #line 2148 "parse.c" /* yacc.c:1652 */
2148 break;
2149
2150 case 21:
2151 #line 322 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2152 {
2153 const char *errstr;
2154 char *dot;
2155 u_int32_t uvalh = 0, uval;
2156
2157 if ((dot = strchr((yyvsp[0].v.string),'.')) != NULL) {
2158 *dot++ = '\0';
2159 uvalh = strtonum((yyvsp[0].v.string), 0, USHRT_MAX, &errstr);
2160 if (errstr) {
2161 yyerror("number %s is %s", (yyvsp[0].v.string), errstr);
2162 free((yyvsp[0].v.string));
2163 YYERROR;
2164 }
2165 uval = strtonum(dot, 0, USHRT_MAX, &errstr);
2166 if (errstr) {
2167 yyerror("number %s is %s", dot, errstr);
2168 free((yyvsp[0].v.string));
2169 YYERROR;
2170 }
2171 free((yyvsp[0].v.string));
2172 } else {
2173 yyerror("AS %s is bad", (yyvsp[0].v.string));
2174 free((yyvsp[0].v.string));
2175 YYERROR;
2176 }
2177 (yyval.v.number) = uval | (uvalh << 16);
2178 }
2179 #line 2180 "parse.c" /* yacc.c:1652 */
2180 break;
2181
2182 case 22:
2183 #line 349 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2184 {
2185 (yyval.v.number) = (yyvsp[0].v.number);
2186 }
2187 #line 2188 "parse.c" /* yacc.c:1652 */
2188 break;
2189
2190 case 23:
2191 #line 354 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2192 {
2193 if (asprintf(&(yyval.v.string), "%s %s", (yyvsp[-1].v.string), (yyvsp[0].v.string)) == -1)
2194 fatal("string: asprintf");
2195 free((yyvsp[-1].v.string));
2196 free((yyvsp[0].v.string));
2197 }
2198 #line 2199 "parse.c" /* yacc.c:1652 */
2199 break;
2200
2201 case 25:
2202 #line 363 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2203 {
2204 if (!strcmp((yyvsp[0].v.string), "yes"))
2205 (yyval.v.number) = 1;
2206 else if (!strcmp((yyvsp[0].v.string), "no"))
2207 (yyval.v.number) = 0;
2208 else {
2209 yyerror("syntax error, "
2210 "either yes or no expected");
2211 free((yyvsp[0].v.string));
2212 YYERROR;
2213 }
2214 free((yyvsp[0].v.string));
2215 }
2216 #line 2217 "parse.c" /* yacc.c:1652 */
2217 break;
2218
2219 case 26:
2220 #line 378 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2221 {
2222 char *s = (yyvsp[-2].v.string);
2223 if (cmd_opts & BGPD_OPT_VERBOSE)
2224 printf("%s = \"%s\"\n", (yyvsp[-2].v.string), (yyvsp[0].v.string));
2225 while (*s++) {
2226 if (isspace((unsigned char)*s)) {
2227 yyerror("macro name cannot contain "
2228 "whitespace");
2229 free((yyvsp[-2].v.string));
2230 free((yyvsp[0].v.string));
2231 YYERROR;
2232 }
2233 }
2234 if (symset((yyvsp[-2].v.string), (yyvsp[0].v.string), 0) == -1)
2235 fatal("cannot store variable");
2236 free((yyvsp[-2].v.string));
2237 free((yyvsp[0].v.string));
2238 }
2239 #line 2240 "parse.c" /* yacc.c:1652 */
2240 break;
2241
2242 case 27:
2243 #line 398 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2244 {
2245 struct file *nfile;
2246
2247 if ((nfile = pushfile((yyvsp[0].v.string), 1)) == NULL) {
2248 yyerror("failed to include file %s", (yyvsp[0].v.string));
2249 free((yyvsp[0].v.string));
2250 YYERROR;
2251 }
2252 free((yyvsp[0].v.string));
2253
2254 file = nfile;
2255 lungetc('\n');
2256 }
2257 #line 2258 "parse.c" /* yacc.c:1652 */
2258 break;
2259
2260 case 28:
2261 #line 413 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2262 {
2263 if (strlen((yyvsp[-2].v.string)) >= SET_NAME_LEN) {
2264 yyerror("as-set name %s too long", (yyvsp[-2].v.string));
2265 free((yyvsp[-2].v.string));
2266 YYERROR;
2267 }
2268 if (new_as_set((yyvsp[-2].v.string)) != 0) {
2269 free((yyvsp[-2].v.string));
2270 YYERROR;
2271 }
2272 free((yyvsp[-2].v.string));
2273 }
2274 #line 2275 "parse.c" /* yacc.c:1652 */
2275 break;
2276
2277 case 29:
2278 #line 424 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2279 {
2280 done_as_set();
2281 }
2282 #line 2283 "parse.c" /* yacc.c:1652 */
2283 break;
2284
2285 case 30:
2286 #line 427 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2287 {
2288 if (new_as_set((yyvsp[-3].v.string)) != 0) {
2289 free((yyvsp[-3].v.string));
2290 YYERROR;
2291 }
2292 free((yyvsp[-3].v.string));
2293 }
2294 #line 2295 "parse.c" /* yacc.c:1652 */
2295 break;
2296
2297 case 31:
2298 #line 435 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2299 { add_as_set((yyvsp[0].v.number)); }
2300 #line 2301 "parse.c" /* yacc.c:1652 */
2301 break;
2302
2303 case 32:
2304 #line 436 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2305 { add_as_set((yyvsp[0].v.number)); }
2306 #line 2307 "parse.c" /* yacc.c:1652 */
2307 break;
2308
2309 case 33:
2310 #line 438 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2311 {
2312 if ((curpset = new_prefix_set((yyvsp[-2].v.string), 0)) == NULL) {
2313 free((yyvsp[-2].v.string));
2314 YYERROR;
2315 }
2316 free((yyvsp[-2].v.string));
2317 }
2318 #line 2319 "parse.c" /* yacc.c:1652 */
2319 break;
2320
2321 case 34:
2322 #line 444 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2323 {
2324 SIMPLEQ_INSERT_TAIL(&conf->prefixsets, curpset, entry);
2325 curpset = NULL;
2326 }
2327 #line 2328 "parse.c" /* yacc.c:1652 */
2328 break;
2329
2330 case 35:
2331 #line 448 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2332 {
2333 if ((curpset = new_prefix_set((yyvsp[-3].v.string), 0)) == NULL) {
2334 free((yyvsp[-3].v.string));
2335 YYERROR;
2336 }
2337 free((yyvsp[-3].v.string));
2338 SIMPLEQ_INSERT_TAIL(&conf->prefixsets, curpset, entry);
2339 curpset = NULL;
2340 }
2341 #line 2342 "parse.c" /* yacc.c:1652 */
2342 break;
2343
2344 case 36:
2345 #line 458 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2346 {
2347 struct prefixset_item *psi;
2348 if ((yyvsp[0].v.prefixset_item)->p.op != OP_NONE)
2349 curpset->sflags |= PREFIXSET_FLAG_OPS;
2350 psi = RB_INSERT(prefixset_tree, &curpset->psitems, (yyvsp[0].v.prefixset_item));
2351 if (psi != NULL) {
2352 if (cmd_opts & BGPD_OPT_VERBOSE2)
2353 log_warnx("warning: duplicate entry in "
2354 "prefixset \"%s\" for %s/%u",
2355 curpset->name,
2356 log_addr(&(yyvsp[0].v.prefixset_item)->p.addr), (yyvsp[0].v.prefixset_item)->p.len);
2357 free((yyvsp[0].v.prefixset_item));
2358 }
2359 }
2360 #line 2361 "parse.c" /* yacc.c:1652 */
2361 break;
2362
2363 case 37:
2364 #line 472 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2365 {
2366 struct prefixset_item *psi;
2367 if ((yyvsp[0].v.prefixset_item)->p.op != OP_NONE)
2368 curpset->sflags |= PREFIXSET_FLAG_OPS;
2369 psi = RB_INSERT(prefixset_tree, &curpset->psitems, (yyvsp[0].v.prefixset_item));
2370 if (psi != NULL) {
2371 if (cmd_opts & BGPD_OPT_VERBOSE2)
2372 log_warnx("warning: duplicate entry in "
2373 "prefixset \"%s\" for %s/%u",
2374 curpset->name,
2375 log_addr(&(yyvsp[0].v.prefixset_item)->p.addr), (yyvsp[0].v.prefixset_item)->p.len);
2376 free((yyvsp[0].v.prefixset_item));
2377 }
2378 }
2379 #line 2380 "parse.c" /* yacc.c:1652 */
2380 break;
2381
2382 case 38:
2383 #line 488 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2384 {
2385 if ((yyvsp[0].v.prefixlen).op != OP_NONE && (yyvsp[0].v.prefixlen).op != OP_RANGE) {
2386 yyerror("unsupported prefixlen operation in "
2387 "prefix-set");
2388 YYERROR;
2389 }
2390 if (((yyval.v.prefixset_item) = calloc(1, sizeof(*(yyval.v.prefixset_item)))) == NULL)
2391 fatal(NULL);
2392 memcpy(&(yyval.v.prefixset_item)->p.addr, &(yyvsp[-1].v.prefix).prefix, sizeof((yyval.v.prefixset_item)->p.addr));
2393 (yyval.v.prefixset_item)->p.len = (yyvsp[-1].v.prefix).len;
2394 if (merge_prefixspec(&(yyval.v.prefixset_item)->p, &(yyvsp[0].v.prefixlen)) == -1) {
2395 free((yyval.v.prefixset_item));
2396 YYERROR;
2397 }
2398 }
2399 #line 2400 "parse.c" /* yacc.c:1652 */
2400 break;
2401
2402 case 39:
2403 #line 505 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2404 {
2405 curroatree = &conf->roa;
2406 }
2407 #line 2408 "parse.c" /* yacc.c:1652 */
2408 break;
2409
2410 case 40:
2411 #line 507 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2412 {
2413 curroatree = NULL;
2414 }
2415 #line 2416 "parse.c" /* yacc.c:1652 */
2416 break;
2417
2418 case 42:
2419 #line 513 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2420 {
2421 if ((curoset = new_prefix_set((yyvsp[-2].v.string), 1)) == NULL) {
2422 free((yyvsp[-2].v.string));
2423 YYERROR;
2424 }
2425 curroatree = &curoset->roaitems;
2426 free((yyvsp[-2].v.string));
2427 }
2428 #line 2429 "parse.c" /* yacc.c:1652 */
2429 break;
2430
2431 case 43:
2432 #line 520 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2433 {
2434 SIMPLEQ_INSERT_TAIL(&conf->originsets, curoset, entry);
2435 curoset = NULL;
2436 curroatree = NULL;
2437 }
2438 #line 2439 "parse.c" /* yacc.c:1652 */
2439 break;
2440
2441 case 44:
2442 #line 525 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2443 {
2444 if ((curoset = new_prefix_set((yyvsp[-3].v.string), 1)) == NULL) {
2445 free((yyvsp[-3].v.string));
2446 YYERROR;
2447 }
2448 free((yyvsp[-3].v.string));
2449 SIMPLEQ_INSERT_TAIL(&conf->originsets, curoset, entry);
2450 curoset = NULL;
2451 curroatree = NULL;
2452 }
2453 #line 2454 "parse.c" /* yacc.c:1652 */
2454 break;
2455
2456 case 45:
2457 #line 537 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2458 {
2459 if ((yyvsp[-2].v.prefixset_item)->p.len_min != (yyvsp[-2].v.prefixset_item)->p.len) {
2460 yyerror("unsupported prefixlen operation in "
2461 "roa-set");
2462 free((yyvsp[-2].v.prefixset_item));
2463 YYERROR;
2464 }
2465 add_roa_set((yyvsp[-2].v.prefixset_item), (yyvsp[0].v.number), (yyvsp[-2].v.prefixset_item)->p.len_max);
2466 free((yyvsp[-2].v.prefixset_item));
2467 }
2468 #line 2469 "parse.c" /* yacc.c:1652 */
2469 break;
2470
2471 case 46:
2472 #line 547 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2473 {
2474 if ((yyvsp[-2].v.prefixset_item)->p.len_min != (yyvsp[-2].v.prefixset_item)->p.len) {
2475 yyerror("unsupported prefixlen operation in "
2476 "roa-set");
2477 free((yyvsp[-2].v.prefixset_item));
2478 YYERROR;
2479 }
2480 add_roa_set((yyvsp[-2].v.prefixset_item), (yyvsp[0].v.number), (yyvsp[-2].v.prefixset_item)->p.len_max);
2481 free((yyvsp[-2].v.prefixset_item));
2482 }
2483 #line 2484 "parse.c" /* yacc.c:1652 */
2484 break;
2485
2486 case 47:
2487 #line 559 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2488 {
2489 currtr = get_rtr(&(yyvsp[0].v.addr));
2490 currtr->remote_port = 323;
2491 if (insert_rtr(currtr) == -1) {
2492 free(currtr);
2493 YYERROR;
2494 }
2495 currtr = NULL;
2496 }
2497 #line 2498 "parse.c" /* yacc.c:1652 */
2498 break;
2499
2500 case 48:
2501 #line 568 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2502 {
2503 currtr = get_rtr(&(yyvsp[0].v.addr));
2504 currtr->remote_port = 323;
2505 }
2506 #line 2507 "parse.c" /* yacc.c:1652 */
2507 break;
2508
2509 case 49:
2510 #line 571 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2511 {
2512 if (insert_rtr(currtr) == -1) {
2513 free(currtr);
2514 YYERROR;
2515 }
2516 currtr = NULL;
2517 }
2518 #line 2519 "parse.c" /* yacc.c:1652 */
2519 break;
2520
2521 case 52:
2522 #line 583 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2523 {
2524 if (strlcpy(currtr->descr, (yyvsp[0].v.string),
2525 sizeof(currtr->descr)) >=
2526 sizeof(currtr->descr)) {
2527 yyerror("descr \"%s\" too long: max %zu",
2528 (yyvsp[0].v.string), sizeof(currtr->descr) - 1);
2529 free((yyvsp[0].v.string));
2530 YYERROR;
2531 }
2532 free((yyvsp[0].v.string));
2533 }
2534 #line 2535 "parse.c" /* yacc.c:1652 */
2535 break;
2536
2537 case 53:
2538 #line 594 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2539 {
2540 if ((yyvsp[0].v.addr).aid != currtr->remote_addr.aid) {
2541 yyerror("Bad address family %s for "
2542 "local-addr", aid2str((yyvsp[0].v.addr).aid));
2543 YYERROR;
2544 }
2545 currtr->local_addr = (yyvsp[0].v.addr);
2546 }
2547 #line 2548 "parse.c" /* yacc.c:1652 */
2548 break;
2549
2550 case 54:
2551 #line 602 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2552 {
2553 if ((yyvsp[0].v.number) < 1 || (yyvsp[0].v.number) > USHRT_MAX) {
2554 yyerror("local-port must be between %u and %u",
2555 1, USHRT_MAX);
2556 YYERROR;
2557 }
2558 currtr->remote_port = (yyvsp[0].v.number);
2559 }
2560 #line 2561 "parse.c" /* yacc.c:1652 */
2561 break;
2562
2563 case 55:
2564 #line 612 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2565 {
2566 conf->as = (yyvsp[0].v.number);
2567 if ((yyvsp[0].v.number) > USHRT_MAX)
2568 conf->short_as = AS_TRANS;
2569 else
2570 conf->short_as = (yyvsp[0].v.number);
2571 }
2572 #line 2573 "parse.c" /* yacc.c:1652 */
2573 break;
2574
2575 case 56:
2576 #line 619 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2577 {
2578 conf->as = (yyvsp[-1].v.number);
2579 conf->short_as = (yyvsp[0].v.number);
2580 }
2581 #line 2582 "parse.c" /* yacc.c:1652 */
2582 break;
2583
2584 case 57:
2585 #line 623 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2586 {
2587 if ((yyvsp[0].v.addr).aid != AID_INET) {
2588 yyerror("router-id must be an IPv4 address");
2589 YYERROR;
2590 }
2591 conf->bgpid = (yyvsp[0].v.addr).v4.s_addr;
2592 }
2593 #line 2594 "parse.c" /* yacc.c:1652 */
2594 break;
2595
2596 case 58:
2597 #line 630 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2598 {
2599 if ((yyvsp[0].v.number) < MIN_HOLDTIME || (yyvsp[0].v.number) > USHRT_MAX) {
2600 yyerror("holdtime must be between %u and %u",
2601 MIN_HOLDTIME, USHRT_MAX);
2602 YYERROR;
2603 }
2604 conf->holdtime = (yyvsp[0].v.number);
2605 }
2606 #line 2607 "parse.c" /* yacc.c:1652 */
2607 break;
2608
2609 case 59:
2610 #line 638 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2611 {
2612 if ((yyvsp[0].v.number) < MIN_HOLDTIME || (yyvsp[0].v.number) > USHRT_MAX) {
2613 yyerror("holdtime must be between %u and %u",
2614 MIN_HOLDTIME, USHRT_MAX);
2615 YYERROR;
2616 }
2617 conf->min_holdtime = (yyvsp[0].v.number);
2618 }
2619 #line 2620 "parse.c" /* yacc.c:1652 */
2620 break;
2621
2622 case 60:
2623 #line 646 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2624 {
2625 struct listen_addr *la;
2626 struct sockaddr *sa;
2627
2628 if ((la = calloc(1, sizeof(struct listen_addr))) ==
2629 NULL)
2630 fatal("parse conf_main listen on calloc");
2631
2632 la->fd = -1;
2633 la->reconf = RECONF_REINIT;
2634 sa = addr2sa(&(yyvsp[0].v.addr), BGP_PORT, &la->sa_len);
2635 memcpy(&la->sa, sa, la->sa_len);
2636 TAILQ_INSERT_TAIL(conf->listen_addrs, la, entry);
2637 }
2638 #line 2639 "parse.c" /* yacc.c:1652 */
2639 break;
2640
2641 case 61:
2642 #line 660 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2643 {
2644 if ((yyvsp[0].v.number) <= RTP_NONE || (yyvsp[0].v.number) > RTP_MAX) {
2645 yyerror("invalid fib-priority");
2646 YYERROR;
2647 }
2648 conf->fib_priority = (yyvsp[0].v.number);
2649 }
2650 #line 2651 "parse.c" /* yacc.c:1652 */
2651 break;
2652
2653 case 62:
2654 #line 667 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2655 {
2656 struct rde_rib *rr;
2657 rr = find_rib("Loc-RIB");
2658 if (rr == NULL)
2659 fatalx("RTABLE can not find the main RIB!");
2660
2661 if ((yyvsp[0].v.number) == 0)
2662 rr->flags |= F_RIB_NOFIBSYNC;
2663 else
2664 rr->flags &= ~F_RIB_NOFIBSYNC;
2665 }
2666 #line 2667 "parse.c" /* yacc.c:1652 */
2667 break;
2668
2669 case 63:
2670 #line 678 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2671 {
2672 if ((yyvsp[0].v.number) == 1)
2673 conf->flags |= BGPD_FLAG_DECISION_TRANS_AS;
2674 else
2675 conf->flags &= ~BGPD_FLAG_DECISION_TRANS_AS;
2676 }
2677 #line 2678 "parse.c" /* yacc.c:1652 */
2678 break;
2679
2680 case 64:
2681 #line 684 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2682 {
2683 if ((yyvsp[0].v.number) == 1)
2684 conf->flags |= BGPD_FLAG_NO_AS_SET;
2685 else
2686 conf->flags &= ~BGPD_FLAG_NO_AS_SET;
2687 }
2688 #line 2689 "parse.c" /* yacc.c:1652 */
2689 break;
2690
2691 case 65:
2692 #line 690 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2693 {
2694 if (!strcmp((yyvsp[0].v.string), "updates"))
2695 conf->log |= BGPD_LOG_UPDATES;
2696 else {
2697 free((yyvsp[0].v.string));
2698 YYERROR;
2699 }
2700 free((yyvsp[0].v.string));
2701 }
2702 #line 2703 "parse.c" /* yacc.c:1652 */
2703 break;
2704
2705 case 67:
2706 #line 700 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2707 {
2708 int action;
2709
2710 if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) {
2711 yyerror("bad timeout");
2712 free((yyvsp[-2].v.string));
2713 free((yyvsp[-1].v.string));
2714 YYERROR;
2715 }
2716 if (!strcmp((yyvsp[-2].v.string), "table"))
2717 action = MRT_TABLE_DUMP;
2718 else if (!strcmp((yyvsp[-2].v.string), "table-mp"))
2719 action = MRT_TABLE_DUMP_MP;
2720 else if (!strcmp((yyvsp[-2].v.string), "table-v2"))
2721 action = MRT_TABLE_DUMP_V2;
2722 else {
2723 yyerror("unknown mrt dump type");
2724 free((yyvsp[-2].v.string));
2725 free((yyvsp[-1].v.string));
2726 YYERROR;
2727 }
2728 free((yyvsp[-2].v.string));
2729 if (add_mrtconfig(action, (yyvsp[-1].v.string), (yyvsp[0].v.number), NULL, NULL) == -1) {
2730 free((yyvsp[-1].v.string));
2731 YYERROR;
2732 }
2733 free((yyvsp[-1].v.string));
2734 }
2735 #line 2736 "parse.c" /* yacc.c:1652 */
2736 break;
2737
2738 case 68:
2739 #line 728 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2740 {
2741 int action;
2742
2743 if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) {
2744 yyerror("bad timeout");
2745 free((yyvsp[-3].v.string));
2746 free((yyvsp[-2].v.string));
2747 free((yyvsp[-1].v.string));
2748 YYERROR;
2749 }
2750 if (!strcmp((yyvsp[-2].v.string), "table"))
2751 action = MRT_TABLE_DUMP;
2752 else if (!strcmp((yyvsp[-2].v.string), "table-mp"))
2753 action = MRT_TABLE_DUMP_MP;
2754 else if (!strcmp((yyvsp[-2].v.string), "table-v2"))
2755 action = MRT_TABLE_DUMP_V2;
2756 else {
2757 yyerror("unknown mrt dump type");
2758 free((yyvsp[-3].v.string));
2759 free((yyvsp[-2].v.string));
2760 free((yyvsp[-1].v.string));
2761 YYERROR;
2762 }
2763 free((yyvsp[-2].v.string));
2764 if (add_mrtconfig(action, (yyvsp[-1].v.string), (yyvsp[0].v.number), NULL, (yyvsp[-3].v.string)) == -1) {
2765 free((yyvsp[-3].v.string));
2766 free((yyvsp[-1].v.string));
2767 YYERROR;
2768 }
2769 free((yyvsp[-3].v.string));
2770 free((yyvsp[-1].v.string));
2771 }
2772 #line 2773 "parse.c" /* yacc.c:1652 */
2773 break;
2774
2775 case 70:
2776 #line 761 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2777 {
2778 if (!strcmp((yyvsp[-1].v.string), "route-age"))
2779 conf->flags |= BGPD_FLAG_DECISION_ROUTEAGE;
2780 else {
2781 yyerror("unknown route decision type");
2782 free((yyvsp[-1].v.string));
2783 YYERROR;
2784 }
2785 free((yyvsp[-1].v.string));
2786 }
2787 #line 2788 "parse.c" /* yacc.c:1652 */
2788 break;
2789
2790 case 71:
2791 #line 771 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2792 {
2793 if (!strcmp((yyvsp[-1].v.string), "route-age"))
2794 conf->flags &= ~BGPD_FLAG_DECISION_ROUTEAGE;
2795 else {
2796 yyerror("unknown route decision type");
2797 free((yyvsp[-1].v.string));
2798 YYERROR;
2799 }
2800 free((yyvsp[-1].v.string));
2801 }
2802 #line 2803 "parse.c" /* yacc.c:1652 */
2803 break;
2804
2805 case 72:
2806 #line 781 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2807 {
2808 if (!strcmp((yyvsp[0].v.string), "always"))
2809 conf->flags |= BGPD_FLAG_DECISION_MED_ALWAYS;
2810 else if (!strcmp((yyvsp[0].v.string), "strict"))
2811 conf->flags &= ~BGPD_FLAG_DECISION_MED_ALWAYS;
2812 else {
2813 yyerror("rde med compare: "
2814 "unknown setting \"%s\"", (yyvsp[0].v.string));
2815 free((yyvsp[0].v.string));
2816 YYERROR;
2817 }
2818 free((yyvsp[0].v.string));
2819 }
2820 #line 2821 "parse.c" /* yacc.c:1652 */
2821 break;
2822
2823 case 73:
2824 #line 794 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2825 {
2826 if (!strcmp((yyvsp[0].v.string), "all"))
2827 conf->flags |= BGPD_FLAG_DECISION_ALL_PATHS;
2828 else if (!strcmp((yyvsp[0].v.string), "default"))
2829 conf->flags &= ~BGPD_FLAG_DECISION_ALL_PATHS;
2830 else {
2831 yyerror("rde evaluate: "
2832 "unknown setting \"%s\"", (yyvsp[0].v.string));
2833 free((yyvsp[0].v.string));
2834 YYERROR;
2835 }
2836 free((yyvsp[0].v.string));
2837 }
2838 #line 2839 "parse.c" /* yacc.c:1652 */
2839 break;
2840
2841 case 74:
2842 #line 807 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2843 {
2844 if (!strcmp((yyvsp[0].v.string), "bgp"))
2845 conf->flags |= BGPD_FLAG_NEXTHOP_BGP;
2846 else if (!strcmp((yyvsp[0].v.string), "default"))
2847 conf->flags |= BGPD_FLAG_NEXTHOP_DEFAULT;
2848 else {
2849 yyerror("nexthop depend on: "
2850 "unknown setting \"%s\"", (yyvsp[0].v.string));
2851 free((yyvsp[0].v.string));
2852 YYERROR;
2853 }
2854 free((yyvsp[0].v.string));
2855 }
2856 #line 2857 "parse.c" /* yacc.c:1652 */
2857 break;
2858
2859 case 75:
2860 #line 820 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2861 {
2862 struct rde_rib *rr;
2863 if ((yyvsp[0].v.number) > RT_TABLEID_MAX) {
2864 yyerror("rtable %llu too big: max %u", (yyvsp[0].v.number),
2865 RT_TABLEID_MAX);
2866 YYERROR;
2867 }
2868 if (ktable_exists((yyvsp[0].v.number), NULL) != 1) {
2869 yyerror("rtable id %lld does not exist", (yyvsp[0].v.number));
2870 YYERROR;
2871 }
2872 rr = find_rib("Loc-RIB");
2873 if (rr == NULL)
2874 fatalx("RTABLE can not find the main RIB!");
2875 rr->rtableid = (yyvsp[0].v.number);
2876 }
2877 #line 2878 "parse.c" /* yacc.c:1652 */
2878 break;
2879
2880 case 76:
2881 #line 836 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2882 {
2883 if ((yyvsp[0].v.number) > USHRT_MAX || (yyvsp[0].v.number) < 1) {
2884 yyerror("invalid connect-retry");
2885 YYERROR;
2886 }
2887 conf->connectretry = (yyvsp[0].v.number);
2888 }
2889 #line 2890 "parse.c" /* yacc.c:1652 */
2890 break;
2891
2892 case 77:
2893 #line 843 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2894 {
2895 if (strlen((yyvsp[-1].v.string)) >=
2896 sizeof(((struct sockaddr_un *)0)->sun_path)) {
2897 yyerror("socket path too long");
2898 YYERROR;
2899 }
2900 if ((yyvsp[0].v.number)) {
2901 free(conf->rcsock);
2902 conf->rcsock = (yyvsp[-1].v.string);
2903 } else {
2904 free(conf->csock);
2905 conf->csock = (yyvsp[-1].v.string);
2906 }
2907 }
2908 #line 2909 "parse.c" /* yacc.c:1652 */
2909 break;
2910
2911 case 78:
2912 #line 859 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2913 {
2914 if ((currib = add_rib((yyvsp[0].v.string))) == NULL) {
2915 free((yyvsp[0].v.string));
2916 YYERROR;
2917 }
2918 free((yyvsp[0].v.string));
2919 }
2920 #line 2921 "parse.c" /* yacc.c:1652 */
2921 break;
2922
2923 case 79:
2924 #line 865 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2925 {
2926 currib = NULL;
2927 }
2928 #line 2929 "parse.c" /* yacc.c:1652 */
2929 break;
2930
2931 case 81:
2932 #line 870 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2933 {
2934 if ((yyvsp[-1].v.number) > RT_TABLEID_MAX) {
2935 yyerror("rtable %llu too big: max %u", (yyvsp[-1].v.number),
2936 RT_TABLEID_MAX);
2937 YYERROR;
2938 }
2939 if (rib_add_fib(currib, (yyvsp[-1].v.number)) == -1)
2940 YYERROR;
2941 }
2942 #line 2943 "parse.c" /* yacc.c:1652 */
2943 break;
2944
2945 case 82:
2946 #line 879 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2947 {
2948 if ((yyvsp[-1].v.number)) {
2949 yyerror("bad rde rib definition");
2950 YYERROR;
2951 }
2952 currib->flags |= F_RIB_NOEVALUATE;
2953 }
2954 #line 2955 "parse.c" /* yacc.c:1652 */
2955 break;
2956
2957 case 84:
2958 #line 889 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2959 {
2960 if ((yyvsp[0].v.number) == 0)
2961 currib->flags |= F_RIB_NOFIBSYNC;
2962 else
2963 currib->flags &= ~F_RIB_NOFIBSYNC;
2964 }
2965 #line 2966 "parse.c" /* yacc.c:1652 */
2966 break;
2967
2968 case 85:
2969 #line 897 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
2970 {
2971 int action;
2972
2973 if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) {
2974 yyerror("bad timeout");
2975 free((yyvsp[-3].v.string));
2976 free((yyvsp[-1].v.string));
2977 YYERROR;
2978 }
2979 if (!strcmp((yyvsp[-3].v.string), "all"))
2980 action = (yyvsp[-2].v.number) ? MRT_ALL_IN : MRT_ALL_OUT;
2981 else if (!strcmp((yyvsp[-3].v.string), "updates"))
2982 action = (yyvsp[-2].v.number) ? MRT_UPDATE_IN : MRT_UPDATE_OUT;
2983 else {
2984 yyerror("unknown mrt msg dump type");
2985 free((yyvsp[-3].v.string));
2986 free((yyvsp[-1].v.string));
2987 YYERROR;
2988 }
2989 if (add_mrtconfig(action, (yyvsp[-1].v.string), (yyvsp[0].v.number), curpeer, NULL) ==
2990 -1) {
2991 free((yyvsp[-3].v.string));
2992 free((yyvsp[-1].v.string));
2993 YYERROR;
2994 }
2995 free((yyvsp[-3].v.string));
2996 free((yyvsp[-1].v.string));
2997 }
2998 #line 2999 "parse.c" /* yacc.c:1652 */
2999 break;
3000
3001 case 86:
3002 #line 927 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3003 {
3004 struct network *n, *m;
3005
3006 if ((n = calloc(1, sizeof(struct network))) == NULL)
3007 fatal("new_network");
3008 memcpy(&n->net.prefix, &(yyvsp[-1].v.prefix).prefix,
3009 sizeof(n->net.prefix));
3010 n->net.prefixlen = (yyvsp[-1].v.prefix).len;
3011 filterset_move((yyvsp[0].v.filter_set_head), &n->net.attrset);
3012 free((yyvsp[0].v.filter_set_head));
3013 TAILQ_FOREACH(m, netconf, entry) {
3014 if (n->net.type == m->net.type &&
3015 n->net.prefixlen == m->net.prefixlen &&
3016 prefix_compare(&n->net.prefix,
3017 &m->net.prefix, n->net.prefixlen) == 0)
3018 yyerror("duplicate prefix "
3019 "in network statement");
3020 }
3021
3022 TAILQ_INSERT_TAIL(netconf, n, entry);
3023 }
3024 #line 3025 "parse.c" /* yacc.c:1652 */
3025 break;
3026
3027 case 87:
3028 #line 948 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3029 {
3030 struct prefixset *ps;
3031 struct network *n;
3032 if ((ps = find_prefixset((yyvsp[-1].v.string), &conf->prefixsets))
3033 == NULL) {
3034 yyerror("prefix-set '%s' not defined", (yyvsp[-1].v.string));
3035 free((yyvsp[-1].v.string));
3036 filterset_free((yyvsp[0].v.filter_set_head));
3037 free((yyvsp[0].v.filter_set_head));
3038 YYERROR;
3039 }
3040 if (ps->sflags & PREFIXSET_FLAG_OPS) {
3041 yyerror("prefix-set %s has prefixlen operators "
3042 "and cannot be used in network statements.",
3043 ps->name);
3044 free((yyvsp[-1].v.string));
3045 filterset_free((yyvsp[0].v.filter_set_head));
3046 free((yyvsp[0].v.filter_set_head));
3047 YYERROR;
3048 }
3049 if ((n = calloc(1, sizeof(struct network))) == NULL)
3050 fatal("new_network");
3051 strlcpy(n->net.psname, ps->name, sizeof(n->net.psname));
3052 filterset_move((yyvsp[0].v.filter_set_head), &n->net.attrset);
3053 n->net.type = NETWORK_PREFIXSET;
3054 TAILQ_INSERT_TAIL(netconf, n, entry);
3055 free((yyvsp[-1].v.string));
3056 free((yyvsp[0].v.filter_set_head));
3057 }
3058 #line 3059 "parse.c" /* yacc.c:1652 */
3059 break;
3060
3061 case 88:
3062 #line 977 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3063 {
3064 struct network *n;
3065
3066 if ((n = calloc(1, sizeof(struct network))) == NULL)
3067 fatal("new_network");
3068 if (afi2aid((yyvsp[-3].v.number), SAFI_UNICAST, &n->net.prefix.aid) ==
3069 -1) {
3070 yyerror("unknown family");
3071 filterset_free((yyvsp[0].v.filter_set_head));
3072 free((yyvsp[0].v.filter_set_head));
3073 YYERROR;
3074 }
3075 n->net.type = NETWORK_RTLABEL;
3076 n->net.rtlabel = rtlabel_name2id((yyvsp[-1].v.string));
3077 filterset_move((yyvsp[0].v.filter_set_head), &n->net.attrset);
3078 free((yyvsp[0].v.filter_set_head));
3079
3080 TAILQ_INSERT_TAIL(netconf, n, entry);
3081 }
3082 #line 3083 "parse.c" /* yacc.c:1652 */
3083 break;
3084
3085 case 89:
3086 #line 996 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3087 {
3088 struct network *n;
3089 if ((yyvsp[-1].v.number) < RTP_LOCAL && (yyvsp[-1].v.number) > RTP_MAX) {
3090 yyerror("priority %lld > max %d or < min %d", (yyvsp[-1].v.number),
3091 RTP_MAX, RTP_LOCAL);
3092 YYERROR;
3093 }
3094
3095 if ((n = calloc(1, sizeof(struct network))) == NULL)
3096 fatal("new_network");
3097 if (afi2aid((yyvsp[-3].v.number), SAFI_UNICAST, &n->net.prefix.aid) ==
3098 -1) {
3099 yyerror("unknown family");
3100 filterset_free((yyvsp[0].v.filter_set_head));
3101 free((yyvsp[0].v.filter_set_head));
3102 YYERROR;
3103 }
3104 n->net.type = NETWORK_PRIORITY;
3105 n->net.priority = (yyvsp[-1].v.number);
3106 filterset_move((yyvsp[0].v.filter_set_head), &n->net.attrset);
3107 free((yyvsp[0].v.filter_set_head));
3108
3109 TAILQ_INSERT_TAIL(netconf, n, entry);
3110 }
3111 #line 3112 "parse.c" /* yacc.c:1652 */
3112 break;
3113
3114 case 90:
3115 #line 1020 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3116 {
3117 struct network *n;
3118
3119 if ((n = calloc(1, sizeof(struct network))) == NULL)
3120 fatal("new_network");
3121 if (afi2aid((yyvsp[-2].v.number), SAFI_UNICAST, &n->net.prefix.aid) ==
3122 -1) {
3123 yyerror("unknown family");
3124 filterset_free((yyvsp[0].v.filter_set_head));
3125 free((yyvsp[0].v.filter_set_head));
3126 YYERROR;
3127 }
3128 n->net.type = (yyvsp[-1].v.number) ? NETWORK_STATIC : NETWORK_CONNECTED;
3129 filterset_move((yyvsp[0].v.filter_set_head), &n->net.attrset);
3130 free((yyvsp[0].v.filter_set_head));
3131
3132 TAILQ_INSERT_TAIL(netconf, n, entry);
3133 }
3134 #line 3135 "parse.c" /* yacc.c:1652 */
3135 break;
3136
3137 case 91:
3138 #line 1040 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3139 { (yyval.v.number) = 1; }
3140 #line 3141 "parse.c" /* yacc.c:1652 */
3141 break;
3142
3143 case 92:
3144 #line 1041 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3145 { (yyval.v.number) = 0; }
3146 #line 3147 "parse.c" /* yacc.c:1652 */
3147 break;
3148
3149 case 93:
3150 #line 1044 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3151 { (yyval.v.number) = 1; }
3152 #line 3153 "parse.c" /* yacc.c:1652 */
3153 break;
3154
3155 case 94:
3156 #line 1045 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3157 { (yyval.v.number) = 0; }
3158 #line 3159 "parse.c" /* yacc.c:1652 */
3159 break;
3160
3161 case 95:
3162 #line 1048 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3163 {
3164 u_int8_t len;
3165
3166 if (!host((yyvsp[0].v.string), &(yyval.v.addr), &len)) {
3167 yyerror("could not parse address spec \"%s\"",
3168 (yyvsp[0].v.string));
3169 free((yyvsp[0].v.string));
3170 YYERROR;
3171 }
3172 free((yyvsp[0].v.string));
3173
3174 if (((yyval.v.addr).aid == AID_INET && len != 32) ||
3175 ((yyval.v.addr).aid == AID_INET6 && len != 128)) {
3176 /* unreachable */
3177 yyerror("got prefixlen %u, expected %u",
3178 len, (yyval.v.addr).aid == AID_INET ? 32 : 128);
3179 YYERROR;
3180 }
3181 }
3182 #line 3183 "parse.c" /* yacc.c:1652 */
3183 break;
3184
3185 case 96:
3186 #line 1069 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3187 {
3188 char *s;
3189 if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > 128) {
3190 yyerror("bad prefixlen %lld", (yyvsp[0].v.number));
3191 free((yyvsp[-2].v.string));
3192 YYERROR;
3193 }
3194 if (asprintf(&s, "%s/%lld", (yyvsp[-2].v.string), (yyvsp[0].v.number)) == -1)
3195 fatal(NULL);
3196 free((yyvsp[-2].v.string));
3197
3198 if (!host(s, &(yyval.v.prefix).prefix, &(yyval.v.prefix).len)) {
3199 yyerror("could not parse address \"%s\"", s);
3200 free(s);
3201 YYERROR;
3202 }
3203 free(s);
3204 }
3205 #line 3206 "parse.c" /* yacc.c:1652 */
3206 break;
3207
3208 case 97:
3209 #line 1087 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3210 {
3211 char *s;
3212
3213 /* does not match IPv6 */
3214 if ((yyvsp[-2].v.number) < 0 || (yyvsp[-2].v.number) > 255 || (yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > 32) {
3215 yyerror("bad prefix %lld/%lld", (yyvsp[-2].v.number), (yyvsp[0].v.number));
3216 YYERROR;
3217 }
3218 if (asprintf(&s, "%lld/%lld", (yyvsp[-2].v.number), (yyvsp[0].v.number)) == -1)
3219 fatal(NULL);
3220
3221 if (!host(s, &(yyval.v.prefix).prefix, &(yyval.v.prefix).len)) {
3222 yyerror("could not parse address \"%s\"", s);
3223 free(s);
3224 YYERROR;
3225 }
3226 free(s);
3227 }
3228 #line 3229 "parse.c" /* yacc.c:1652 */
3229 break;
3230
3231 case 98:
3232 #line 1107 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3233 {
3234 memcpy(&(yyval.v.prefix).prefix, &(yyvsp[0].v.addr), sizeof(struct bgpd_addr));
3235 if ((yyval.v.prefix).prefix.aid == AID_INET)
3236 (yyval.v.prefix).len = 32;
3237 else
3238 (yyval.v.prefix).len = 128;
3239 }
3240 #line 3241 "parse.c" /* yacc.c:1652 */
3241 break;
3242
3243 case 100:
3244 #line 1117 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3245 { (yyval.v.number) = 0; }
3246 #line 3247 "parse.c" /* yacc.c:1652 */
3247 break;
3248
3249 case 102:
3250 #line 1121 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3251 {
3252 u_int rdomain, label;
3253
3254 if (get_mpe_config((yyvsp[0].v.string), &rdomain, &label) == -1) {
3255 if ((cmd_opts & BGPD_OPT_NOACTION) == 0) {
3256 yyerror("troubles getting config of %s",
3257 (yyvsp[0].v.string));
3258 free((yyvsp[0].v.string));
3259 free((yyvsp[-2].v.string));
3260 YYERROR;
3261 }
3262 }
3263
3264 if (!(curvpn = calloc(1, sizeof(struct l3vpn))))
3265 fatal(NULL);
3266 strlcpy(curvpn->ifmpe, (yyvsp[0].v.string), IFNAMSIZ);
3267
3268 if (strlcpy(curvpn->descr, (yyvsp[-2].v.string),
3269 sizeof(curvpn->descr)) >=
3270 sizeof(curvpn->descr)) {
3271 yyerror("descr \"%s\" too long: max %zu",
3272 (yyvsp[-2].v.string), sizeof(curvpn->descr) - 1);
3273 free((yyvsp[-2].v.string));
3274 free((yyvsp[0].v.string));
3275 free(curvpn);
3276 curvpn = NULL;
3277 YYERROR;
3278 }
3279 free((yyvsp[-2].v.string));
3280 free((yyvsp[0].v.string));
3281
3282 TAILQ_INIT(&curvpn->import);
3283 TAILQ_INIT(&curvpn->export);
3284 TAILQ_INIT(&curvpn->net_l);
3285 curvpn->label = label;
3286 curvpn->rtableid = rdomain;
3287 netconf = &curvpn->net_l;
3288 }
3289 #line 3290 "parse.c" /* yacc.c:1652 */
3290 break;
3291
3292 case 103:
3293 #line 1158 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3294 {
3295 /* insert into list */
3296 SIMPLEQ_INSERT_TAIL(&conf->l3vpns, curvpn, entry);
3297 curvpn = NULL;
3298 netconf = &conf->networks;
3299 }
3300 #line 3301 "parse.c" /* yacc.c:1652 */
3301 break;
3302
3303 case 108:
3304 #line 1172 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3305 {
3306 struct community ext;
3307
3308 memset(&ext, 0, sizeof(ext));
3309 if (parseextcommunity(&ext, "rt", (yyvsp[0].v.string)) == -1) {
3310 free((yyvsp[0].v.string));
3311 YYERROR;
3312 }
3313 free((yyvsp[0].v.string));
3314 /*
3315 * RD is almost encoded like an ext-community,
3316 * but only almost so convert here.
3317 */
3318 if (community_to_rd(&ext, &curvpn->rd) == -1) {
3319 yyerror("bad encoding of rd");
3320 YYERROR;
3321 }
3322 }
3323 #line 3324 "parse.c" /* yacc.c:1652 */
3324 break;
3325
3326 case 109:
3327 #line 1190 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3328 {
3329 struct filter_set *set;
3330
3331 if ((set = calloc(1, sizeof(struct filter_set))) ==
3332 NULL)
3333 fatal(NULL);
3334 set->type = ACTION_SET_COMMUNITY;
3335 if (parseextcommunity(&set->action.community,
3336 (yyvsp[-1].v.string), (yyvsp[0].v.string)) == -1) {
3337 free((yyvsp[0].v.string));
3338 free((yyvsp[-1].v.string));
3339 free(set);
3340 YYERROR;
3341 }
3342 free((yyvsp[0].v.string));
3343 free((yyvsp[-1].v.string));
3344 TAILQ_INSERT_TAIL(&curvpn->export, set, entry);
3345 }
3346 #line 3347 "parse.c" /* yacc.c:1652 */
3347 break;
3348
3349 case 110:
3350 #line 1208 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3351 {
3352 struct filter_set *set;
3353
3354 if ((set = calloc(1, sizeof(struct filter_set))) ==
3355 NULL)
3356 fatal(NULL);
3357 set->type = ACTION_SET_COMMUNITY;
3358 if (parseextcommunity(&set->action.community,
3359 (yyvsp[-1].v.string), (yyvsp[0].v.string)) == -1) {
3360 free((yyvsp[0].v.string));
3361 free((yyvsp[-1].v.string));
3362 free(set);
3363 YYERROR;
3364 }
3365 free((yyvsp[0].v.string));
3366 free((yyvsp[-1].v.string));
3367 TAILQ_INSERT_TAIL(&curvpn->import, set, entry);
3368 }
3369 #line 3370 "parse.c" /* yacc.c:1652 */
3370 break;
3371
3372 case 111:
3373 #line 1226 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3374 {
3375 if ((yyvsp[0].v.number) == 0)
3376 curvpn->flags |= F_RIB_NOFIBSYNC;
3377 else
3378 curvpn->flags &= ~F_RIB_NOFIBSYNC;
3379 }
3380 #line 3381 "parse.c" /* yacc.c:1652 */
3381 break;
3382
3383 case 113:
3384 #line 1235 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3385 { curpeer = new_peer(); }
3386 #line 3387 "parse.c" /* yacc.c:1652 */
3387 break;
3388
3389 case 114:
3390 #line 1236 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3391 {
3392 memcpy(&curpeer->conf.remote_addr, &(yyvsp[0].v.prefix).prefix,
3393 sizeof(curpeer->conf.remote_addr));
3394 curpeer->conf.remote_masklen = (yyvsp[0].v.prefix).len;
3395 if (((yyvsp[0].v.prefix).prefix.aid == AID_INET && (yyvsp[0].v.prefix).len != 32) ||
3396 ((yyvsp[0].v.prefix).prefix.aid == AID_INET6 && (yyvsp[0].v.prefix).len != 128))
3397 curpeer->conf.template = 1;
3398 curpeer->conf.capabilities.mp[
3399 curpeer->conf.remote_addr.aid] = 1;
3400 if (get_id(curpeer)) {
3401 yyerror("get_id failed");
3402 YYERROR;
3403 }
3404 }
3405 #line 3406 "parse.c" /* yacc.c:1652 */
3406 break;
3407
3408 case 115:
3409 #line 1250 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3410 {
3411 if (curpeer_filter[0] != NULL)
3412 TAILQ_INSERT_TAIL(peerfilter_l,
3413 curpeer_filter[0], entry);
3414 if (curpeer_filter[1] != NULL)
3415 TAILQ_INSERT_TAIL(peerfilter_l,
3416 curpeer_filter[1], entry);
3417 curpeer_filter[0] = NULL;
3418 curpeer_filter[1] = NULL;
3419
3420 if (neighbor_consistent(curpeer) == -1) {
3421 free(curpeer);
3422 YYERROR;
3423 }
3424 if (RB_INSERT(peer_head, new_peers, curpeer) != NULL)
3425 fatalx("%s: peer tree is corrupt", __func__);
3426 curpeer = curgroup;
3427 }
3428 #line 3429 "parse.c" /* yacc.c:1652 */
3429 break;
3430
3431 case 116:
3432 #line 1270 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3433 {
3434 curgroup = curpeer = new_group();
3435 if (strlcpy(curgroup->conf.group, (yyvsp[0].v.string),
3436 sizeof(curgroup->conf.group)) >=
3437 sizeof(curgroup->conf.group)) {
3438 yyerror("group name \"%s\" too long: max %zu",
3439 (yyvsp[0].v.string), sizeof(curgroup->conf.group) - 1);
3440 free((yyvsp[0].v.string));
3441 free(curgroup);
3442 YYERROR;
3443 }
3444 free((yyvsp[0].v.string));
3445 if (get_id(curgroup)) {
3446 yyerror("get_id failed");
3447 free(curgroup);
3448 YYERROR;
3449 }
3450 }
3451 #line 3452 "parse.c" /* yacc.c:1652 */
3452 break;
3453
3454 case 117:
3455 #line 1287 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3456 {
3457 if (curgroup_filter[0] != NULL)
3458 TAILQ_INSERT_TAIL(groupfilter_l,
3459 curgroup_filter[0], entry);
3460 if (curgroup_filter[1] != NULL)
3461 TAILQ_INSERT_TAIL(groupfilter_l,
3462 curgroup_filter[1], entry);
3463 curgroup_filter[0] = NULL;
3464 curgroup_filter[1] = NULL;
3465
3466 free(curgroup);
3467 curgroup = NULL;
3468 }
3469 #line 3470 "parse.c" /* yacc.c:1652 */
3470 break;
3471
3472 case 130:
3473 #line 1320 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3474 {
3475 curpeer->conf.remote_as = (yyvsp[0].v.number);
3476 }
3477 #line 3478 "parse.c" /* yacc.c:1652 */
3478 break;
3479
3480 case 131:
3481 #line 1323 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3482 {
3483 curpeer->conf.local_as = (yyvsp[0].v.number);
3484 if ((yyvsp[0].v.number) > USHRT_MAX)
3485 curpeer->conf.local_short_as = AS_TRANS;
3486 else
3487 curpeer->conf.local_short_as = (yyvsp[0].v.number);
3488 }
3489 #line 3490 "parse.c" /* yacc.c:1652 */
3490 break;
3491
3492 case 132:
3493 #line 1330 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3494 {
3495 curpeer->conf.local_as = (yyvsp[-1].v.number);
3496 curpeer->conf.local_short_as = (yyvsp[0].v.number);
3497 }
3498 #line 3499 "parse.c" /* yacc.c:1652 */
3499 break;
3500
3501 case 133:
3502 #line 1334 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3503 {
3504 if (strlcpy(curpeer->conf.descr, (yyvsp[0].v.string),
3505 sizeof(curpeer->conf.descr)) >=
3506 sizeof(curpeer->conf.descr)) {
3507 yyerror("descr \"%s\" too long: max %zu",
3508 (yyvsp[0].v.string), sizeof(curpeer->conf.descr) - 1);
3509 free((yyvsp[0].v.string));
3510 YYERROR;
3511 }
3512 free((yyvsp[0].v.string));
3513 }
3514 #line 3515 "parse.c" /* yacc.c:1652 */
3515 break;
3516
3517 case 134:
3518 #line 1345 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3519 {
3520 if ((yyvsp[0].v.addr).aid == AID_INET)
3521 memcpy(&curpeer->conf.local_addr_v4, &(yyvsp[0].v.addr),
3522 sizeof(curpeer->conf.local_addr_v4));
3523 else if ((yyvsp[0].v.addr).aid == AID_INET6)
3524 memcpy(&curpeer->conf.local_addr_v6, &(yyvsp[0].v.addr),
3525 sizeof(curpeer->conf.local_addr_v6));
3526 else {
3527 yyerror("Unsupported address family %s for "
3528 "local-addr", aid2str((yyvsp[0].v.addr).aid));
3529 YYERROR;
3530 }
3531 }
3532 #line 3533 "parse.c" /* yacc.c:1652 */
3533 break;
3534
3535 case 135:
3536 #line 1358 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3537 {
3538 if ((yyvsp[-1].v.number)) {
3539 yyerror("bad local-address definition");
3540 YYERROR;
3541 }
3542 memset(&curpeer->conf.local_addr_v4, 0,
3543 sizeof(curpeer->conf.local_addr_v4));
3544 memset(&curpeer->conf.local_addr_v6, 0,
3545 sizeof(curpeer->conf.local_addr_v6));
3546 }
3547 #line 3548 "parse.c" /* yacc.c:1652 */
3548 break;
3549
3550 case 136:
3551 #line 1368 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3552 {
3553 if ((yyvsp[0].v.number) < 2 || (yyvsp[0].v.number) > 255) {
3554 yyerror("invalid multihop distance %lld", (yyvsp[0].v.number));
3555 YYERROR;
3556 }
3557 curpeer->conf.distance = (yyvsp[0].v.number);
3558 }
3559 #line 3560 "parse.c" /* yacc.c:1652 */
3560 break;
3561
3562 case 137:
3563 #line 1375 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3564 {
3565 curpeer->conf.passive = 1;
3566 }
3567 #line 3568 "parse.c" /* yacc.c:1652 */
3568 break;
3569
3570 case 138:
3571 #line 1378 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3572 {
3573 curpeer->conf.down = 1;
3574 }
3575 #line 3576 "parse.c" /* yacc.c:1652 */
3576 break;
3577
3578 case 139:
3579 #line 1381 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3580 {
3581 curpeer->conf.down = 1;
3582 if (strlcpy(curpeer->conf.reason, (yyvsp[0].v.string),
3583 sizeof(curpeer->conf.reason)) >=
3584 sizeof(curpeer->conf.reason)) {
3585 yyerror("shutdown reason too long");
3586 free((yyvsp[0].v.string));
3587 YYERROR;
3588 }
3589 free((yyvsp[0].v.string));
3590 }
3591 #line 3592 "parse.c" /* yacc.c:1652 */
3592 break;
3593
3594 case 140:
3595 #line 1392 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3596 {
3597 if (!find_rib((yyvsp[0].v.string))) {
3598 yyerror("rib \"%s\" does not exist.", (yyvsp[0].v.string));
3599 free((yyvsp[0].v.string));
3600 YYERROR;
3601 }
3602 if (strlcpy(curpeer->conf.rib, (yyvsp[0].v.string),
3603 sizeof(curpeer->conf.rib)) >=
3604 sizeof(curpeer->conf.rib)) {
3605 yyerror("rib name \"%s\" too long: max %zu",
3606 (yyvsp[0].v.string), sizeof(curpeer->conf.rib) - 1);
3607 free((yyvsp[0].v.string));
3608 YYERROR;
3609 }
3610 free((yyvsp[0].v.string));
3611 }
3612 #line 3613 "parse.c" /* yacc.c:1652 */
3613 break;
3614
3615 case 141:
3616 #line 1408 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3617 {
3618 if ((yyvsp[0].v.number) < MIN_HOLDTIME || (yyvsp[0].v.number) > USHRT_MAX) {
3619 yyerror("holdtime must be between %u and %u",
3620 MIN_HOLDTIME, USHRT_MAX);
3621 YYERROR;
3622 }
3623 curpeer->conf.holdtime = (yyvsp[0].v.number);
3624 }
3625 #line 3626 "parse.c" /* yacc.c:1652 */
3626 break;
3627
3628 case 142:
3629 #line 1416 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3630 {
3631 if ((yyvsp[0].v.number) < MIN_HOLDTIME || (yyvsp[0].v.number) > USHRT_MAX) {
3632 yyerror("holdtime must be between %u and %u",
3633 MIN_HOLDTIME, USHRT_MAX);
3634 YYERROR;
3635 }
3636 curpeer->conf.min_holdtime = (yyvsp[0].v.number);
3637 }
3638 #line 3639 "parse.c" /* yacc.c:1652 */
3639 break;
3640
3641 case 143:
3642 #line 1424 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3643 {
3644 u_int8_t aid, safi;
3645 u_int16_t afi;
3646
3647 if ((yyvsp[0].v.number) == SAFI_NONE) {
3648 for (aid = 0; aid < AID_MAX; aid++) {
3649 if (aid2afi(aid, &afi, &safi) == -1 ||
3650 afi != (yyvsp[-1].v.number))
3651 continue;
3652 curpeer->conf.capabilities.mp[aid] = 0;
3653 }
3654 } else {
3655 if (afi2aid((yyvsp[-1].v.number), (yyvsp[0].v.number), &aid) == -1) {
3656 yyerror("unknown AFI/SAFI pair");
3657 YYERROR;
3658 }
3659 curpeer->conf.capabilities.mp[aid] = 1;
3660 }
3661 }
3662 #line 3663 "parse.c" /* yacc.c:1652 */
3663 break;
3664
3665 case 144:
3666 #line 1443 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3667 {
3668 curpeer->conf.announce_capa = (yyvsp[0].v.number);
3669 }
3670 #line 3671 "parse.c" /* yacc.c:1652 */
3671 break;
3672
3673 case 145:
3674 #line 1446 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3675 {
3676 curpeer->conf.capabilities.refresh = (yyvsp[0].v.number);
3677 }
3678 #line 3679 "parse.c" /* yacc.c:1652 */
3679 break;
3680
3681 case 146:
3682 #line 1449 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3683 {
3684 curpeer->conf.capabilities.grestart.restart = (yyvsp[0].v.number);
3685 }
3686 #line 3687 "parse.c" /* yacc.c:1652 */
3687 break;
3688
3689 case 147:
3690 #line 1452 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3691 {
3692 curpeer->conf.capabilities.as4byte = (yyvsp[0].v.number);
3693 }
3694 #line 3695 "parse.c" /* yacc.c:1652 */
3695 break;
3696
3697 case 148:
3698 #line 1455 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3699 {
3700 curpeer->conf.export_type = EXPORT_NONE;
3701 }
3702 #line 3703 "parse.c" /* yacc.c:1652 */
3703 break;
3704
3705 case 149:
3706 #line 1458 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3707 {
3708 curpeer->conf.export_type = EXPORT_DEFAULT_ROUTE;
3709 }
3710 #line 3711 "parse.c" /* yacc.c:1652 */
3711 break;
3712
3713 case 150:
3714 #line 1461 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3715 {
3716 if ((yyvsp[0].v.number))
3717 curpeer->conf.enforce_as = ENFORCE_AS_ON;
3718 else
3719 curpeer->conf.enforce_as = ENFORCE_AS_OFF;
3720 }
3721 #line 3722 "parse.c" /* yacc.c:1652 */
3722 break;
3723
3724 case 151:
3725 #line 1467 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3726 {
3727 if ((yyvsp[0].v.number))
3728 curpeer->conf.enforce_local_as = ENFORCE_AS_ON;
3729 else
3730 curpeer->conf.enforce_local_as = ENFORCE_AS_OFF;
3731 }
3732 #line 3733 "parse.c" /* yacc.c:1652 */
3733 break;
3734
3735 case 152:
3736 #line 1473 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3737 {
3738 if ((yyvsp[0].v.number)) {
3739 struct filter_rule *r;
3740 struct filter_set *s;
3741
3742 if ((s = calloc(1, sizeof(struct filter_set)))
3743 == NULL)
3744 fatal(NULL);
3745 s->type = ACTION_SET_AS_OVERRIDE;
3746
3747 r = get_rule(s->type);
3748 if (merge_filterset(&r->set, s) == -1)
3749 YYERROR;
3750 }
3751 }
3752 #line 3753 "parse.c" /* yacc.c:1652 */
3753 break;
3754
3755 case 153:
3756 #line 1488 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3757 {
3758 if ((yyvsp[-1].v.number) < 0 || (yyvsp[-1].v.number) > UINT_MAX) {
3759 yyerror("bad maximum number of prefixes");
3760 YYERROR;
3761 }
3762 curpeer->conf.max_prefix = (yyvsp[-1].v.number);
3763 curpeer->conf.max_prefix_restart = (yyvsp[0].v.number);
3764 }
3765 #line 3766 "parse.c" /* yacc.c:1652 */
3766 break;
3767
3768 case 154:
3769 #line 1496 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3770 {
3771 if ((yyvsp[-2].v.number) < 0 || (yyvsp[-2].v.number) > UINT_MAX) {
3772 yyerror("bad maximum number of prefixes");
3773 YYERROR;
3774 }
3775 curpeer->conf.max_out_prefix = (yyvsp[-2].v.number);
3776 curpeer->conf.max_out_prefix_restart = (yyvsp[0].v.number);
3777 }
3778 #line 3779 "parse.c" /* yacc.c:1652 */
3779 break;
3780
3781 case 155:
3782 #line 1504 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3783 {
3784 if (curpeer->conf.auth.method) {
3785 yyerror("auth method cannot be redefined");
3786 free((yyvsp[0].v.string));
3787 YYERROR;
3788 }
3789 if (strlcpy(curpeer->conf.auth.md5key, (yyvsp[0].v.string),
3790 sizeof(curpeer->conf.auth.md5key)) >=
3791 sizeof(curpeer->conf.auth.md5key)) {
3792 yyerror("tcp md5sig password too long: max %zu",
3793 sizeof(curpeer->conf.auth.md5key) - 1);
3794 free((yyvsp[0].v.string));
3795 YYERROR;
3796 }
3797 curpeer->conf.auth.method = AUTH_MD5SIG;
3798 curpeer->conf.auth.md5key_len = strlen((yyvsp[0].v.string));
3799 free((yyvsp[0].v.string));
3800 }
3801 #line 3802 "parse.c" /* yacc.c:1652 */
3802 break;
3803
3804 case 156:
3805 #line 1522 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3806 {
3807 if (curpeer->conf.auth.method) {
3808 yyerror("auth method cannot be redefined");
3809 free((yyvsp[0].v.string));
3810 YYERROR;
3811 }
3812
3813 if (str2key((yyvsp[0].v.string), curpeer->conf.auth.md5key,
3814 sizeof(curpeer->conf.auth.md5key)) == -1) {
3815 free((yyvsp[0].v.string));
3816 YYERROR;
3817 }
3818 curpeer->conf.auth.method = AUTH_MD5SIG;
3819 curpeer->conf.auth.md5key_len = strlen((yyvsp[0].v.string)) / 2;
3820 free((yyvsp[0].v.string));
3821 }
3822 #line 3823 "parse.c" /* yacc.c:1652 */
3823 break;
3824
3825 case 157:
3826 #line 1538 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3827 {
3828 if (curpeer->conf.auth.method) {
3829 yyerror("auth method cannot be redefined");
3830 YYERROR;
3831 }
3832 if ((yyvsp[-1].v.number))
3833 curpeer->conf.auth.method = AUTH_IPSEC_IKE_ESP;
3834 else
3835 curpeer->conf.auth.method = AUTH_IPSEC_IKE_AH;
3836 }
3837 #line 3838 "parse.c" /* yacc.c:1652 */
3838 break;
3839
3840 case 158:
3841 #line 1548 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3842 {
3843 u_int32_t auth_alg;
3844 u_int8_t keylen;
3845
3846 if (curpeer->conf.auth.method &&
3847 (((curpeer->conf.auth.spi_in && (yyvsp[-5].v.number) == 1) ||
3848 (curpeer->conf.auth.spi_out && (yyvsp[-5].v.number) == 0)) ||
3849 ((yyvsp[-6].v.number) == 1 && curpeer->conf.auth.method !=
3850 AUTH_IPSEC_MANUAL_ESP) ||
3851 ((yyvsp[-6].v.number) == 0 && curpeer->conf.auth.method !=
3852 AUTH_IPSEC_MANUAL_AH))) {
3853 yyerror("auth method cannot be redefined");
3854 free((yyvsp[-2].v.string));
3855 free((yyvsp[-1].v.string));
3856 YYERROR;
3857 }
3858
3859 if (!strcmp((yyvsp[-2].v.string), "sha1")) {
3860 auth_alg = SADB_AALG_SHA1HMAC;
3861 keylen = 20;
3862 } else if (!strcmp((yyvsp[-2].v.string), "md5")) {
3863 auth_alg = SADB_AALG_MD5HMAC;
3864 keylen = 16;
3865 } else {
3866 yyerror("unknown auth algorithm \"%s\"", (yyvsp[-2].v.string));
3867 free((yyvsp[-2].v.string));
3868 free((yyvsp[-1].v.string));
3869 YYERROR;
3870 }
3871 free((yyvsp[-2].v.string));
3872
3873 if (strlen((yyvsp[-1].v.string)) / 2 != keylen) {
3874 yyerror("auth key len: must be %u bytes, "
3875 "is %zu bytes", keylen, strlen((yyvsp[-1].v.string)) / 2);
3876 free((yyvsp[-1].v.string));
3877 YYERROR;
3878 }
3879
3880 if ((yyvsp[-6].v.number))
3881 curpeer->conf.auth.method =
3882 AUTH_IPSEC_MANUAL_ESP;
3883 else {
3884 if ((yyvsp[0].v.encspec).enc_alg) {
3885 yyerror("\"ipsec ah\" doesn't take "
3886 "encryption keys");
3887 free((yyvsp[-1].v.string));
3888 YYERROR;
3889 }
3890 curpeer->conf.auth.method =
3891 AUTH_IPSEC_MANUAL_AH;
3892 }
3893
3894 if ((yyvsp[-3].v.number) <= SPI_RESERVED_MAX || (yyvsp[-3].v.number) > UINT_MAX) {
3895 yyerror("bad spi number %lld", (yyvsp[-3].v.number));
3896 free((yyvsp[-1].v.string));
3897 YYERROR;
3898 }
3899
3900 if ((yyvsp[-5].v.number) == 1) {
3901 if (str2key((yyvsp[-1].v.string), curpeer->conf.auth.auth_key_in,
3902 sizeof(curpeer->conf.auth.auth_key_in)) ==
3903 -1) {
3904 free((yyvsp[-1].v.string));
3905 YYERROR;
3906 }
3907 curpeer->conf.auth.spi_in = (yyvsp[-3].v.number);
3908 curpeer->conf.auth.auth_alg_in = auth_alg;
3909 curpeer->conf.auth.enc_alg_in = (yyvsp[0].v.encspec).enc_alg;
3910 memcpy(&curpeer->conf.auth.enc_key_in,
3911 &(yyvsp[0].v.encspec).enc_key,
3912 sizeof(curpeer->conf.auth.enc_key_in));
3913 curpeer->conf.auth.enc_keylen_in =
3914 (yyvsp[0].v.encspec).enc_key_len;
3915 curpeer->conf.auth.auth_keylen_in = keylen;
3916 } else {
3917 if (str2key((yyvsp[-1].v.string), curpeer->conf.auth.auth_key_out,
3918 sizeof(curpeer->conf.auth.auth_key_out)) ==
3919 -1) {
3920 free((yyvsp[-1].v.string));
3921 YYERROR;
3922 }
3923 curpeer->conf.auth.spi_out = (yyvsp[-3].v.number);
3924 curpeer->conf.auth.auth_alg_out = auth_alg;
3925 curpeer->conf.auth.enc_alg_out = (yyvsp[0].v.encspec).enc_alg;
3926 memcpy(&curpeer->conf.auth.enc_key_out,
3927 &(yyvsp[0].v.encspec).enc_key,
3928 sizeof(curpeer->conf.auth.enc_key_out));
3929 curpeer->conf.auth.enc_keylen_out =
3930 (yyvsp[0].v.encspec).enc_key_len;
3931 curpeer->conf.auth.auth_keylen_out = keylen;
3932 }
3933 free((yyvsp[-1].v.string));
3934 }
3935 #line 3936 "parse.c" /* yacc.c:1652 */
3936 break;
3937
3938 case 159:
3939 #line 1641 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3940 {
3941 curpeer->conf.ttlsec = (yyvsp[0].v.number);
3942 }
3943 #line 3944 "parse.c" /* yacc.c:1652 */
3944 break;
3945
3946 case 160:
3947 #line 1644 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3948 {
3949 struct filter_rule *r;
3950
3951 r = get_rule((yyvsp[0].v.filter_set)->type);
3952 if (merge_filterset(&r->set, (yyvsp[0].v.filter_set)) == -1)
3953 YYERROR;
3954 }
3955 #line 3956 "parse.c" /* yacc.c:1652 */
3956 break;
3957
3958 case 161:
3959 #line 1651 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3960 {
3961 struct filter_rule *r;
3962 struct filter_set *s;
3963
3964 while ((s = TAILQ_FIRST((yyvsp[-2].v.filter_set_head))) != NULL) {
3965 TAILQ_REMOVE((yyvsp[-2].v.filter_set_head), s, entry);
3966 r = get_rule(s->type);
3967 if (merge_filterset(&r->set, s) == -1)
3968 YYERROR;
3969 }
3970 free((yyvsp[-2].v.filter_set_head));
3971 }
3972 #line 3973 "parse.c" /* yacc.c:1652 */
3973 break;
3974
3975 case 163:
3976 #line 1664 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3977 {
3978 if ((conf->flags & BGPD_FLAG_REFLECTOR) &&
3979 conf->clusterid != 0) {
3980 yyerror("only one route reflector "
3981 "cluster allowed");
3982 YYERROR;
3983 }
3984 conf->flags |= BGPD_FLAG_REFLECTOR;
3985 curpeer->conf.reflector_client = 1;
3986 }
3987 #line 3988 "parse.c" /* yacc.c:1652 */
3988 break;
3989
3990 case 164:
3991 #line 1674 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
3992 {
3993 if ((yyvsp[0].v.addr).aid != AID_INET) {
3994 yyerror("route reflector cluster-id must be "
3995 "an IPv4 address");
3996 YYERROR;
3997 }
3998 if ((conf->flags & BGPD_FLAG_REFLECTOR) &&
3999 conf->clusterid != (yyvsp[0].v.addr).v4.s_addr) {
4000 yyerror("only one route reflector "
4001 "cluster allowed");
4002 YYERROR;
4003 }
4004 conf->flags |= BGPD_FLAG_REFLECTOR;
4005 curpeer->conf.reflector_client = 1;
4006 conf->clusterid = (yyvsp[0].v.addr).v4.s_addr;
4007 }
4008 #line 4009 "parse.c" /* yacc.c:1652 */
4009 break;
4010
4011 case 165:
4012 #line 1690 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4013 {
4014 if (strlcpy(curpeer->conf.if_depend, (yyvsp[0].v.string),
4015 sizeof(curpeer->conf.if_depend)) >=
4016 sizeof(curpeer->conf.if_depend)) {
4017 yyerror("interface name \"%s\" too long: "
4018 "max %zu", (yyvsp[0].v.string),
4019 sizeof(curpeer->conf.if_depend) - 1);
4020 free((yyvsp[0].v.string));
4021 YYERROR;
4022 }
4023 free((yyvsp[0].v.string));
4024 }
4025 #line 4026 "parse.c" /* yacc.c:1652 */
4026 break;
4027
4028 case 166:
4029 #line 1702 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4030 {
4031 #ifdef HAVE_CARP
4032 if (strlcpy(curpeer->conf.demote_group, (yyvsp[0].v.string),
4033 sizeof(curpeer->conf.demote_group)) >=
4034 sizeof(curpeer->conf.demote_group)) {
4035 yyerror("demote group name \"%s\" too long: "
4036 "max %zu", (yyvsp[0].v.string),
4037 sizeof(curpeer->conf.demote_group) - 1);
4038 free((yyvsp[0].v.string));
4039 YYERROR;
4040 }
4041 free((yyvsp[0].v.string));
4042 if (carp_demote_init(curpeer->conf.demote_group,
4043 cmd_opts & BGPD_OPT_FORCE_DEMOTE) == -1) {
4044 yyerror("error initializing group \"%s\"",
4045 curpeer->conf.demote_group);
4046 YYERROR;
4047 }
4048 #else
4049 yyerror("carp demote not supported");
4050 free((yyvsp[0].v.string));
4051 YYERROR;
4052 #endif
4053 }
4054 #line 4055 "parse.c" /* yacc.c:1652 */
4055 break;
4056
4057 case 167:
4058 #line 1726 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4059 {
4060 if ((yyvsp[0].v.number) == 1)
4061 curpeer->conf.flags |= PEERFLAG_TRANS_AS;
4062 else
4063 curpeer->conf.flags &= ~PEERFLAG_TRANS_AS;
4064 }
4065 #line 4066 "parse.c" /* yacc.c:1652 */
4066 break;
4067
4068 case 168:
4069 #line 1732 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4070 {
4071 if (!strcmp((yyvsp[0].v.string), "updates"))
4072 curpeer->conf.flags |= PEERFLAG_LOG_UPDATES;
4073 else if (!strcmp((yyvsp[0].v.string), "no"))
4074 curpeer->conf.flags &= ~PEERFLAG_LOG_UPDATES;
4075 else {
4076 free((yyvsp[0].v.string));
4077 YYERROR;
4078 }
4079 free((yyvsp[0].v.string));
4080 }
4081 #line 4082 "parse.c" /* yacc.c:1652 */
4082 break;
4083
4084 case 169:
4085 #line 1743 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4086 {
4087 if ((yyvsp[0].v.number) == 1)
4088 curpeer->conf.flags |= PEERFLAG_NO_AS_SET;
4089 else
4090 curpeer->conf.flags &= ~PEERFLAG_NO_AS_SET;
4091 }
4092 #line 4093 "parse.c" /* yacc.c:1652 */
4093 break;
4094
4095 case 170:
4096 #line 1749 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4097 {
4098 if (!strcmp((yyvsp[0].v.string), "all"))
4099 curpeer->conf.flags |= PEERFLAG_EVALUATE_ALL;
4100 else if (!strcmp((yyvsp[0].v.string), "default"))
4101 curpeer->conf.flags &= ~PEERFLAG_EVALUATE_ALL;
4102 else {
4103 yyerror("rde evaluate: "
4104 "unknown setting \"%s\"", (yyvsp[0].v.string));
4105 free((yyvsp[0].v.string));
4106 YYERROR;
4107 }
4108 free((yyvsp[0].v.string));
4109 }
4110 #line 4111 "parse.c" /* yacc.c:1652 */
4111 break;
4112
4113 case 171:
4114 #line 1764 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4115 { (yyval.v.number) = 0; }
4116 #line 4117 "parse.c" /* yacc.c:1652 */
4117 break;
4118
4119 case 172:
4120 #line 1765 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4121 {
4122 if ((yyvsp[0].v.number) < 1 || (yyvsp[0].v.number) > USHRT_MAX) {
4123 yyerror("restart out of range. 1 to %u minutes",
4124 USHRT_MAX);
4125 YYERROR;
4126 }
4127 (yyval.v.number) = (yyvsp[0].v.number);
4128 }
4129 #line 4130 "parse.c" /* yacc.c:1652 */
4130 break;
4131
4132 case 173:
4133 #line 1775 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4134 { (yyval.v.number) = AFI_IPv4; }
4135 #line 4136 "parse.c" /* yacc.c:1652 */
4136 break;
4137
4138 case 174:
4139 #line 1776 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4140 { (yyval.v.number) = AFI_IPv6; }
4141 #line 4142 "parse.c" /* yacc.c:1652 */
4142 break;
4143
4144 case 175:
4145 #line 1779 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4146 { (yyval.v.number) = SAFI_NONE; }
4147 #line 4148 "parse.c" /* yacc.c:1652 */
4148 break;
4149
4150 case 176:
4151 #line 1780 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4152 { (yyval.v.number) = SAFI_UNICAST; }
4153 #line 4154 "parse.c" /* yacc.c:1652 */
4154 break;
4155
4156 case 177:
4157 #line 1781 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4158 { (yyval.v.number) = SAFI_MPLSVPN; }
4159 #line 4160 "parse.c" /* yacc.c:1652 */
4160 break;
4161
4162 case 178:
4163 #line 1784 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4164 { (yyval.v.number) = 1; }
4165 #line 4166 "parse.c" /* yacc.c:1652 */
4166 break;
4167
4168 case 179:
4169 #line 1785 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4170 { (yyval.v.number) = 0; }
4171 #line 4172 "parse.c" /* yacc.c:1652 */
4172 break;
4173
4174 case 180:
4175 #line 1788 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4176 { (yyval.v.number) = 1; }
4177 #line 4178 "parse.c" /* yacc.c:1652 */
4178 break;
4179
4180 case 181:
4181 #line 1789 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4182 { (yyval.v.number) = 0; }
4183 #line 4184 "parse.c" /* yacc.c:1652 */
4184 break;
4185
4186 case 182:
4187 #line 1792 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4188 {
4189 bzero(&(yyval.v.encspec), sizeof((yyval.v.encspec)));
4190 }
4191 #line 4192 "parse.c" /* yacc.c:1652 */
4192 break;
4193
4194 case 183:
4195 #line 1795 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4196 {
4197 bzero(&(yyval.v.encspec), sizeof((yyval.v.encspec)));
4198 if (!strcmp((yyvsp[-1].v.string), "3des") || !strcmp((yyvsp[-1].v.string), "3des-cbc")) {
4199 (yyval.v.encspec).enc_alg = SADB_EALG_3DESCBC;
4200 (yyval.v.encspec).enc_key_len = 21; /* XXX verify */
4201 } else if (!strcmp((yyvsp[-1].v.string), "aes") ||
4202 !strcmp((yyvsp[-1].v.string), "aes-128-cbc")) {
4203 (yyval.v.encspec).enc_alg = SADB_X_EALG_AES;
4204 (yyval.v.encspec).enc_key_len = 16;
4205 } else {
4206 yyerror("unknown enc algorithm \"%s\"", (yyvsp[-1].v.string));
4207 free((yyvsp[-1].v.string));
4208 free((yyvsp[0].v.string));
4209 YYERROR;
4210 }
4211 free((yyvsp[-1].v.string));
4212
4213 if (strlen((yyvsp[0].v.string)) / 2 != (yyval.v.encspec).enc_key_len) {
4214 yyerror("enc key length wrong: should be %u "
4215 "bytes, is %zu bytes",
4216 (yyval.v.encspec).enc_key_len * 2, strlen((yyvsp[0].v.string)));
4217 free((yyvsp[0].v.string));
4218 YYERROR;
4219 }
4220
4221 if (str2key((yyvsp[0].v.string), (yyval.v.encspec).enc_key, sizeof((yyval.v.encspec).enc_key)) == -1) {
4222 free((yyvsp[0].v.string));
4223 YYERROR;
4224 }
4225 free((yyvsp[0].v.string));
4226 }
4227 #line 4228 "parse.c" /* yacc.c:1652 */
4228 break;
4229
4230 case 184:
4231 #line 1830 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4232 {
4233 struct filter_rule r;
4234 struct filter_rib_l *rb, *rbnext;
4235
4236 bzero(&r, sizeof(r));
4237 r.action = (yyvsp[-6].v.u8);
4238 r.quick = (yyvsp[-5].v.u8);
4239 r.dir = (yyvsp[-3].v.u8);
4240 if ((yyvsp[-4].v.filter_rib)) {
4241 if (r.dir != DIR_IN) {
4242 yyerror("rib only allowed on \"from\" "
4243 "rules.");
4244
4245 for (rb = (yyvsp[-4].v.filter_rib); rb != NULL; rb = rbnext) {
4246 rbnext = rb->next;
4247 free(rb);
4248 }
4249 YYERROR;
4250 }
4251 }
4252 if (expand_rule(&r, (yyvsp[-4].v.filter_rib), (yyvsp[-2].v.filter_peers), &(yyvsp[-1].v.filter_match), (yyvsp[0].v.filter_set_head)) == -1)
4253 YYERROR;
4254 }
4255 #line 4256 "parse.c" /* yacc.c:1652 */
4256 break;
4257
4258 case 185:
4259 #line 1855 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4260 { (yyval.v.u8) = ACTION_ALLOW; }
4261 #line 4262 "parse.c" /* yacc.c:1652 */
4262 break;
4263
4264 case 186:
4265 #line 1856 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4266 { (yyval.v.u8) = ACTION_DENY; }
4267 #line 4268 "parse.c" /* yacc.c:1652 */
4268 break;
4269
4270 case 187:
4271 #line 1857 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4272 { (yyval.v.u8) = ACTION_NONE; }
4273 #line 4274 "parse.c" /* yacc.c:1652 */
4274 break;
4275
4276 case 188:
4277 #line 1860 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4278 { (yyval.v.u8) = 0; }
4279 #line 4280 "parse.c" /* yacc.c:1652 */
4280 break;
4281
4282 case 189:
4283 #line 1861 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4284 { (yyval.v.u8) = 1; }
4285 #line 4286 "parse.c" /* yacc.c:1652 */
4286 break;
4287
4288 case 190:
4289 #line 1864 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4290 { (yyval.v.u8) = DIR_IN; }
4291 #line 4292 "parse.c" /* yacc.c:1652 */
4292 break;
4293
4294 case 191:
4295 #line 1865 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4296 { (yyval.v.u8) = DIR_OUT; }
4297 #line 4298 "parse.c" /* yacc.c:1652 */
4298 break;
4299
4300 case 192:
4301 #line 1868 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4302 { (yyval.v.filter_rib) = NULL; }
4303 #line 4304 "parse.c" /* yacc.c:1652 */
4304 break;
4305
4306 case 193:
4307 #line 1869 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4308 { (yyval.v.filter_rib) = (yyvsp[0].v.filter_rib); }
4309 #line 4310 "parse.c" /* yacc.c:1652 */
4310 break;
4311
4312 case 194:
4313 #line 1870 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4314 { (yyval.v.filter_rib) = (yyvsp[-2].v.filter_rib); }
4315 #line 4316 "parse.c" /* yacc.c:1652 */
4316 break;
4317
4318 case 195:
4319 #line 1872 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4320 { (yyval.v.filter_rib) = (yyvsp[0].v.filter_rib); }
4321 #line 4322 "parse.c" /* yacc.c:1652 */
4322 break;
4323
4324 case 196:
4325 #line 1873 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4326 {
4327 (yyvsp[0].v.filter_rib)->next = (yyvsp[-2].v.filter_rib);
4328 (yyval.v.filter_rib) = (yyvsp[0].v.filter_rib);
4329 }
4330 #line 4331 "parse.c" /* yacc.c:1652 */
4331 break;
4332
4333 case 197:
4334 #line 1879 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4335 {
4336 if (!find_rib((yyvsp[0].v.string))) {
4337 yyerror("rib \"%s\" does not exist.", (yyvsp[0].v.string));
4338 free((yyvsp[0].v.string));
4339 YYERROR;
4340 }
4341 if (((yyval.v.filter_rib) = calloc(1, sizeof(struct filter_rib_l))) ==
4342 NULL)
4343 fatal(NULL);
4344 (yyval.v.filter_rib)->next = NULL;
4345 if (strlcpy((yyval.v.filter_rib)->name, (yyvsp[0].v.string), sizeof((yyval.v.filter_rib)->name)) >=
4346 sizeof((yyval.v.filter_rib)->name)) {
4347 yyerror("rib name \"%s\" too long: "
4348 "max %zu", (yyvsp[0].v.string), sizeof((yyval.v.filter_rib)->name) - 1);
4349 free((yyvsp[0].v.string));
4350 free((yyval.v.filter_rib));
4351 YYERROR;
4352 }
4353 free((yyvsp[0].v.string));
4354 }
4355 #line 4356 "parse.c" /* yacc.c:1652 */
4356 break;
4357
4358 case 199:
4359 #line 1902 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4360 { (yyval.v.filter_peers) = (yyvsp[-2].v.filter_peers); }
4361 #line 4362 "parse.c" /* yacc.c:1652 */
4362 break;
4363
4364 case 200:
4365 #line 1905 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4366 { (yyval.v.filter_peers) = (yyvsp[0].v.filter_peers); }
4367 #line 4368 "parse.c" /* yacc.c:1652 */
4368 break;
4369
4370 case 201:
4371 #line 1906 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4372 {
4373 (yyvsp[0].v.filter_peers)->next = (yyvsp[-2].v.filter_peers);
4374 (yyval.v.filter_peers) = (yyvsp[0].v.filter_peers);
4375 }
4376 #line 4377 "parse.c" /* yacc.c:1652 */
4377 break;
4378
4379 case 202:
4380 #line 1912 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4381 {
4382 if (((yyval.v.filter_peers) = calloc(1, sizeof(struct filter_peers_l))) ==
4383 NULL)
4384 fatal(NULL);
4385 (yyval.v.filter_peers)->p.peerid = (yyval.v.filter_peers)->p.groupid = 0;
4386 (yyval.v.filter_peers)->next = NULL;
4387 }
4388 #line 4389 "parse.c" /* yacc.c:1652 */
4389 break;
4390
4391 case 203:
4392 #line 1919 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4393 {
4394 struct peer *p;
4395
4396 if (((yyval.v.filter_peers) = calloc(1, sizeof(struct filter_peers_l))) ==
4397 NULL)
4398 fatal(NULL);
4399 (yyval.v.filter_peers)->p.remote_as = (yyval.v.filter_peers)->p.groupid = (yyval.v.filter_peers)->p.peerid = 0;
4400 (yyval.v.filter_peers)->next = NULL;
4401 RB_FOREACH(p, peer_head, new_peers)
4402 if (!memcmp(&p->conf.remote_addr,
4403 &(yyvsp[0].v.addr), sizeof(p->conf.remote_addr))) {
4404 (yyval.v.filter_peers)->p.peerid = p->conf.id;
4405 break;
4406 }
4407 if ((yyval.v.filter_peers)->p.peerid == 0) {
4408 yyerror("no such peer: %s", log_addr(&(yyvsp[0].v.addr)));
4409 free((yyval.v.filter_peers));
4410 YYERROR;
4411 }
4412 }
4413 #line 4414 "parse.c" /* yacc.c:1652 */
4414 break;
4415
4416 case 204:
4417 #line 1939 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4418 {
4419 if (((yyval.v.filter_peers) = calloc(1, sizeof(struct filter_peers_l))) ==
4420 NULL)
4421 fatal(NULL);
4422 (yyval.v.filter_peers)->p.groupid = (yyval.v.filter_peers)->p.peerid = 0;
4423 (yyval.v.filter_peers)->p.remote_as = (yyvsp[0].v.number);
4424 }
4425 #line 4426 "parse.c" /* yacc.c:1652 */
4426 break;
4427
4428 case 205:
4429 #line 1946 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4430 {
4431 struct peer *p;
4432
4433 if (((yyval.v.filter_peers) = calloc(1, sizeof(struct filter_peers_l))) ==
4434 NULL)
4435 fatal(NULL);
4436 (yyval.v.filter_peers)->p.remote_as = (yyval.v.filter_peers)->p.peerid = 0;
4437 (yyval.v.filter_peers)->next = NULL;
4438 RB_FOREACH(p, peer_head, new_peers)
4439 if (!strcmp(p->conf.group, (yyvsp[0].v.string))) {
4440 (yyval.v.filter_peers)->p.groupid = p->conf.groupid;
4441 break;
4442 }
4443 if ((yyval.v.filter_peers)->p.groupid == 0) {
4444 yyerror("no such group: \"%s\"", (yyvsp[0].v.string));
4445 free((yyvsp[0].v.string));
4446 free((yyval.v.filter_peers));
4447 YYERROR;
4448 }
4449 free((yyvsp[0].v.string));
4450 }
4451 #line 4452 "parse.c" /* yacc.c:1652 */
4452 break;
4453
4454 case 206:
4455 #line 1967 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4456 {
4457 if (((yyval.v.filter_peers) = calloc(1, sizeof(struct filter_peers_l))) ==
4458 NULL)
4459 fatal(NULL);
4460 (yyval.v.filter_peers)->p.ebgp = 1;
4461 }
4462 #line 4463 "parse.c" /* yacc.c:1652 */
4463 break;
4464
4465 case 207:
4466 #line 1973 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4467 {
4468 if (((yyval.v.filter_peers) = calloc(1, sizeof(struct filter_peers_l))) ==
4469 NULL)
4470 fatal(NULL);
4471 (yyval.v.filter_peers)->p.ibgp = 1;
4472 }
4473 #line 4474 "parse.c" /* yacc.c:1652 */
4474 break;
4475
4476 case 208:
4477 #line 1981 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4478 {
4479 if ((yyvsp[0].v.prefixlen).op == OP_NONE) {
4480 (yyvsp[0].v.prefixlen).op = OP_RANGE;
4481 (yyvsp[0].v.prefixlen).len_min = 0;
4482 (yyvsp[0].v.prefixlen).len_max = -1;
4483 }
4484 if (((yyval.v.filter_prefix) = calloc(1, sizeof(struct filter_prefix_l))) ==
4485 NULL)
4486 fatal(NULL);
4487 (yyval.v.filter_prefix)->p.addr.aid = AID_INET;
4488 if (merge_prefixspec(&(yyval.v.filter_prefix)->p, &(yyvsp[0].v.prefixlen)) == -1) {
4489 free((yyval.v.filter_prefix));
4490 YYERROR;
4491 }
4492 }
4493 #line 4494 "parse.c" /* yacc.c:1652 */
4494 break;
4495
4496 case 209:
4497 #line 1996 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4498 {
4499 if ((yyvsp[0].v.prefixlen).op == OP_NONE) {
4500 (yyvsp[0].v.prefixlen).op = OP_RANGE;
4501 (yyvsp[0].v.prefixlen).len_min = 0;
4502 (yyvsp[0].v.prefixlen).len_max = -1;
4503 }
4504 if (((yyval.v.filter_prefix) = calloc(1, sizeof(struct filter_prefix_l))) ==
4505 NULL)
4506 fatal(NULL);
4507 (yyval.v.filter_prefix)->p.addr.aid = AID_INET6;
4508 if (merge_prefixspec(&(yyval.v.filter_prefix)->p, &(yyvsp[0].v.prefixlen)) == -1) {
4509 free((yyval.v.filter_prefix));
4510 YYERROR;
4511 }
4512 }
4513 #line 4514 "parse.c" /* yacc.c:1652 */
4514 break;
4515
4516 case 210:
4517 #line 2011 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4518 { (yyval.v.filter_prefix) = (yyvsp[0].v.filter_prefix); }
4519 #line 4520 "parse.c" /* yacc.c:1652 */
4520 break;
4521
4522 case 211:
4523 #line 2012 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4524 { (yyval.v.filter_prefix) = (yyvsp[-1].v.filter_prefix); }
4525 #line 4526 "parse.c" /* yacc.c:1652 */
4526 break;
4527
4528 case 213:
4529 #line 2016 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4530 { (yyval.v.filter_prefix) = (yyvsp[-1].v.filter_prefix); }
4531 #line 4532 "parse.c" /* yacc.c:1652 */
4532 break;
4533
4534 case 214:
4535 #line 2018 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4536 {
4537 struct filter_prefix_l *p;
4538
4539 /* merge, both can be lists */
4540 for (p = (yyvsp[-2].v.filter_prefix); p != NULL && p->next != NULL; p = p->next)
4541 ; /* nothing */
4542 if (p != NULL)
4543 p->next = (yyvsp[0].v.filter_prefix);
4544 (yyval.v.filter_prefix) = (yyvsp[-2].v.filter_prefix);
4545 }
4546 #line 4547 "parse.c" /* yacc.c:1652 */
4547 break;
4548
4549 case 215:
4550 #line 2029 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4551 { (yyval.v.filter_prefix) = (yyvsp[0].v.filter_prefix); }
4552 #line 4553 "parse.c" /* yacc.c:1652 */
4553 break;
4554
4555 case 216:
4556 #line 2030 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4557 {
4558 (yyvsp[0].v.filter_prefix)->next = (yyvsp[-2].v.filter_prefix);
4559 (yyval.v.filter_prefix) = (yyvsp[0].v.filter_prefix);
4560 }
4561 #line 4562 "parse.c" /* yacc.c:1652 */
4562 break;
4563
4564 case 217:
4565 #line 2036 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4566 {
4567 if (((yyval.v.filter_prefix) = calloc(1, sizeof(struct filter_prefix_l))) ==
4568 NULL)
4569 fatal(NULL);
4570 memcpy(&(yyval.v.filter_prefix)->p.addr, &(yyvsp[-1].v.prefix).prefix,
4571 sizeof((yyval.v.filter_prefix)->p.addr));
4572 (yyval.v.filter_prefix)->p.len = (yyvsp[-1].v.prefix).len;
4573
4574 if (merge_prefixspec(&(yyval.v.filter_prefix)->p, &(yyvsp[0].v.prefixlen)) == -1) {
4575 free((yyval.v.filter_prefix));
4576 YYERROR;
4577 }
4578 }
4579 #line 4580 "parse.c" /* yacc.c:1652 */
4580 break;
4581
4582 case 219:
4583 #line 2052 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4584 { (yyval.v.filter_as) = (yyvsp[-1].v.filter_as); }
4585 #line 4586 "parse.c" /* yacc.c:1652 */
4586 break;
4587
4588 case 221:
4589 #line 2056 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4590 {
4591 struct filter_as_l *a;
4592
4593 /* merge, both can be lists */
4594 for (a = (yyvsp[-2].v.filter_as); a != NULL && a->next != NULL; a = a->next)
4595 ; /* nothing */
4596 if (a != NULL)
4597 a->next = (yyvsp[0].v.filter_as);
4598 (yyval.v.filter_as) = (yyvsp[-2].v.filter_as);
4599 }
4600 #line 4601 "parse.c" /* yacc.c:1652 */
4601 break;
4602
4603 case 222:
4604 #line 2068 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4605 {
4606 (yyval.v.filter_as) = (yyvsp[0].v.filter_as);
4607 (yyval.v.filter_as)->a.type = (yyvsp[-1].v.u8);
4608 }
4609 #line 4610 "parse.c" /* yacc.c:1652 */
4610 break;
4611
4612 case 223:
4613 #line 2072 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4614 {
4615 struct filter_as_l *a;
4616
4617 (yyval.v.filter_as) = (yyvsp[-1].v.filter_as);
4618 for (a = (yyval.v.filter_as); a != NULL; a = a->next)
4619 a->a.type = (yyvsp[-3].v.u8);
4620 }
4621 #line 4622 "parse.c" /* yacc.c:1652 */
4622 break;
4623
4624 case 224:
4625 #line 2079 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4626 {
4627 if (as_sets_lookup(&conf->as_sets, (yyvsp[0].v.string)) == NULL) {
4628 yyerror("as-set \"%s\" not defined", (yyvsp[0].v.string));
4629 free((yyvsp[0].v.string));
4630 YYERROR;
4631 }
4632 if (((yyval.v.filter_as) = calloc(1, sizeof(struct filter_as_l))) ==
4633 NULL)
4634 fatal(NULL);
4635 (yyval.v.filter_as)->a.type = (yyvsp[-2].v.u8);
4636 (yyval.v.filter_as)->a.flags = AS_FLAG_AS_SET_NAME;
4637 if (strlcpy((yyval.v.filter_as)->a.name, (yyvsp[0].v.string), sizeof((yyval.v.filter_as)->a.name)) >=
4638 sizeof((yyval.v.filter_as)->a.name)) {
4639 yyerror("as-set name \"%s\" too long: "
4640 "max %zu", (yyvsp[0].v.string), sizeof((yyval.v.filter_as)->a.name) - 1);
4641 free((yyvsp[0].v.string));
4642 free((yyval.v.filter_as));
4643 YYERROR;
4644 }
4645 free((yyvsp[0].v.string));
4646 }
4647 #line 4648 "parse.c" /* yacc.c:1652 */
4648 break;
4649
4650 case 226:
4651 #line 2103 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4652 { (yyval.v.filter_as) = (yyvsp[-1].v.filter_as); }
4653 #line 4654 "parse.c" /* yacc.c:1652 */
4654 break;
4655
4656 case 227:
4657 #line 2105 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4658 {
4659 struct filter_as_l *a;
4660
4661 /* merge, both can be lists */
4662 for (a = (yyvsp[-2].v.filter_as); a != NULL && a->next != NULL; a = a->next)
4663 ; /* nothing */
4664 if (a != NULL)
4665 a->next = (yyvsp[0].v.filter_as);
4666 (yyval.v.filter_as) = (yyvsp[-2].v.filter_as);
4667 }
4668 #line 4669 "parse.c" /* yacc.c:1652 */
4669 break;
4670
4671 case 229:
4672 #line 2118 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4673 {
4674 (yyvsp[0].v.filter_as)->next = (yyvsp[-2].v.filter_as);
4675 (yyval.v.filter_as) = (yyvsp[0].v.filter_as);
4676 }
4677 #line 4678 "parse.c" /* yacc.c:1652 */
4678 break;
4679
4680 case 230:
4681 #line 2124 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4682 {
4683 if (((yyval.v.filter_as) = calloc(1, sizeof(struct filter_as_l))) ==
4684 NULL)
4685 fatal(NULL);
4686 (yyval.v.filter_as)->a.as_min = (yyvsp[0].v.number);
4687 (yyval.v.filter_as)->a.as_max = (yyvsp[0].v.number);
4688 (yyval.v.filter_as)->a.op = OP_EQ;
4689 }
4690 #line 4691 "parse.c" /* yacc.c:1652 */
4691 break;
4692
4693 case 231:
4694 #line 2132 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4695 {
4696 if (((yyval.v.filter_as) = calloc(1, sizeof(struct filter_as_l))) ==
4697 NULL)
4698 fatal(NULL);
4699 (yyval.v.filter_as)->a.flags = AS_FLAG_NEIGHBORAS;
4700 }
4701 #line 4702 "parse.c" /* yacc.c:1652 */
4702 break;
4703
4704 case 232:
4705 #line 2138 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4706 {
4707 if (((yyval.v.filter_as) = calloc(1, sizeof(struct filter_as_l))) ==
4708 NULL)
4709 fatal(NULL);
4710 (yyval.v.filter_as)->a.op = (yyvsp[-1].v.u8);
4711 (yyval.v.filter_as)->a.as_min = (yyvsp[0].v.number);
4712 (yyval.v.filter_as)->a.as_max = (yyvsp[0].v.number);
4713 }
4714 #line 4715 "parse.c" /* yacc.c:1652 */
4715 break;
4716
4717 case 233:
4718 #line 2146 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4719 {
4720 if (((yyval.v.filter_as) = calloc(1, sizeof(struct filter_as_l))) ==
4721 NULL)
4722 fatal(NULL);
4723 if ((yyvsp[-2].v.number) >= (yyvsp[0].v.number)) {
4724 yyerror("start AS is bigger than end");
4725 YYERROR;
4726 }
4727 (yyval.v.filter_as)->a.op = (yyvsp[-1].v.u8);
4728 (yyval.v.filter_as)->a.as_min = (yyvsp[-2].v.number);
4729 (yyval.v.filter_as)->a.as_max = (yyvsp[0].v.number);
4730 }
4731 #line 4732 "parse.c" /* yacc.c:1652 */
4732 break;
4733
4734 case 234:
4735 #line 2160 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4736 {
4737 bzero(&(yyval.v.filter_match), sizeof((yyval.v.filter_match)));
4738 }
4739 #line 4740 "parse.c" /* yacc.c:1652 */
4740 break;
4741
4742 case 235:
4743 #line 2163 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4744 {
4745 bzero(&fmopts, sizeof(fmopts));
4746 }
4747 #line 4748 "parse.c" /* yacc.c:1652 */
4748 break;
4749
4750 case 236:
4751 #line 2166 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4752 {
4753 memcpy(&(yyval.v.filter_match), &fmopts, sizeof((yyval.v.filter_match)));
4754 }
4755 #line 4756 "parse.c" /* yacc.c:1652 */
4756 break;
4757
4758 case 239:
4759 #line 2175 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4760 {
4761 if (fmopts.prefix_l != NULL) {
4762 yyerror("\"prefix\" already specified");
4763 YYERROR;
4764 }
4765 if (fmopts.m.prefixset.name[0] != '\0') {
4766 yyerror("\"prefix-set\" already specified, "
4767 "cannot be used with \"prefix\" in the "
4768 "same filter rule");
4769 YYERROR;
4770 }
4771 fmopts.prefix_l = (yyvsp[0].v.filter_prefix);
4772 }
4773 #line 4774 "parse.c" /* yacc.c:1652 */
4774 break;
4775
4776 case 240:
4777 #line 2188 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4778 {
4779 if (fmopts.as_l != NULL) {
4780 yyerror("AS filters already specified");
4781 YYERROR;
4782 }
4783 fmopts.as_l = (yyvsp[0].v.filter_as);
4784 }
4785 #line 4786 "parse.c" /* yacc.c:1652 */
4786 break;
4787
4788 case 241:
4789 #line 2195 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4790 {
4791 if (fmopts.m.aslen.type != ASLEN_NONE) {
4792 yyerror("AS length filters already specified");
4793 YYERROR;
4794 }
4795 if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > UINT_MAX) {
4796 yyerror("bad max-as-len %lld", (yyvsp[0].v.number));
4797 YYERROR;
4798 }
4799 fmopts.m.aslen.type = ASLEN_MAX;
4800 fmopts.m.aslen.aslen = (yyvsp[0].v.number);
4801 }
4802 #line 4803 "parse.c" /* yacc.c:1652 */
4803 break;
4804
4805 case 242:
4806 #line 2207 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4807 {
4808 if (fmopts.m.aslen.type != ASLEN_NONE) {
4809 yyerror("AS length filters already specified");
4810 YYERROR;
4811 }
4812 if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > UINT_MAX) {
4813 yyerror("bad max-as-seq %lld", (yyvsp[0].v.number));
4814 YYERROR;
4815 }
4816 fmopts.m.aslen.type = ASLEN_SEQ;
4817 fmopts.m.aslen.aslen = (yyvsp[0].v.number);
4818 }
4819 #line 4820 "parse.c" /* yacc.c:1652 */
4820 break;
4821
4822 case 243:
4823 #line 2219 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4824 {
4825 int i;
4826 for (i = 0; i < MAX_COMM_MATCH; i++) {
4827 if (fmopts.m.community[i].flags == 0)
4828 break;
4829 }
4830 if (i >= MAX_COMM_MATCH) {
4831 yyerror("too many \"community\" filters "
4832 "specified");
4833 free((yyvsp[0].v.string));
4834 YYERROR;
4835 }
4836 if (parsecommunity(&fmopts.m.community[i], (yyvsp[-1].v.u8), (yyvsp[0].v.string)) == -1) {
4837 free((yyvsp[0].v.string));
4838 YYERROR;
4839 }
4840 free((yyvsp[0].v.string));
4841 }
4842 #line 4843 "parse.c" /* yacc.c:1652 */
4843 break;
4844
4845 case 244:
4846 #line 2237 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4847 {
4848 int i;
4849 for (i = 0; i < MAX_COMM_MATCH; i++) {
4850 if (fmopts.m.community[i].flags == 0)
4851 break;
4852 }
4853 if (i >= MAX_COMM_MATCH) {
4854 yyerror("too many \"community\" filters "
4855 "specified");
4856 free((yyvsp[-1].v.string));
4857 free((yyvsp[0].v.string));
4858 YYERROR;
4859 }
4860 if (parseextcommunity(&fmopts.m.community[i],
4861 (yyvsp[-1].v.string), (yyvsp[0].v.string)) == -1) {
4862 free((yyvsp[-1].v.string));
4863 free((yyvsp[0].v.string));
4864 YYERROR;
4865 }
4866 free((yyvsp[-1].v.string));
4867 free((yyvsp[0].v.string));
4868 }
4869 #line 4870 "parse.c" /* yacc.c:1652 */
4870 break;
4871
4872 case 245:
4873 #line 2259 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4874 {
4875 int i;
4876 for (i = 0; i < MAX_COMM_MATCH; i++) {
4877 if (fmopts.m.community[i].flags == 0)
4878 break;
4879 }
4880 if (i >= MAX_COMM_MATCH) {
4881 yyerror("too many \"community\" filters "
4882 "specified");
4883 free((yyvsp[0].v.string));
4884 YYERROR;
4885 }
4886 if (parseextcommunity(&fmopts.m.community[i],
4887 "ovs", (yyvsp[0].v.string)) == -1) {
4888 free((yyvsp[0].v.string));
4889 YYERROR;
4890 }
4891 free((yyvsp[0].v.string));
4892 }
4893 #line 4894 "parse.c" /* yacc.c:1652 */
4894 break;
4895
4896 case 246:
4897 #line 2278 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4898 {
4899 if (fmopts.m.nexthop.flags) {
4900 yyerror("nexthop already specified");
4901 YYERROR;
4902 }
4903 fmopts.m.nexthop.addr = (yyvsp[0].v.addr);
4904 fmopts.m.nexthop.flags = FILTER_NEXTHOP_ADDR;
4905 }
4906 #line 4907 "parse.c" /* yacc.c:1652 */
4907 break;
4908
4909 case 247:
4910 #line 2286 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4911 {
4912 if (fmopts.m.nexthop.flags) {
4913 yyerror("nexthop already specified");
4914 YYERROR;
4915 }
4916 fmopts.m.nexthop.flags = FILTER_NEXTHOP_NEIGHBOR;
4917 }
4918 #line 4919 "parse.c" /* yacc.c:1652 */
4919 break;
4920
4921 case 248:
4922 #line 2293 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4923 {
4924 struct prefixset *ps;
4925 if (fmopts.prefix_l != NULL) {
4926 yyerror("\"prefix\" already specified, cannot "
4927 "be used with \"prefix-set\" in the same "
4928 "filter rule");
4929 free((yyvsp[-1].v.string));
4930 YYERROR;
4931 }
4932 if (fmopts.m.prefixset.name[0] != '\0') {
4933 yyerror("prefix-set filter already specified");
4934 free((yyvsp[-1].v.string));
4935 YYERROR;
4936 }
4937 if ((ps = find_prefixset((yyvsp[-1].v.string), &conf->prefixsets))
4938 == NULL) {
4939 yyerror("prefix-set '%s' not defined", (yyvsp[-1].v.string));
4940 free((yyvsp[-1].v.string));
4941 YYERROR;
4942 }
4943 if (strlcpy(fmopts.m.prefixset.name, (yyvsp[-1].v.string),
4944 sizeof(fmopts.m.prefixset.name)) >=
4945 sizeof(fmopts.m.prefixset.name)) {
4946 yyerror("prefix-set name too long");
4947 free((yyvsp[-1].v.string));
4948 YYERROR;
4949 }
4950 if (!((yyvsp[0].v.prefixlen).op == OP_NONE ||
4951 ((yyvsp[0].v.prefixlen).op == OP_RANGE &&
4952 (yyvsp[0].v.prefixlen).len_min == -1 && (yyvsp[0].v.prefixlen).len_max == -1))) {
4953 yyerror("prefix-sets can only use option "
4954 "or-longer");
4955 free((yyvsp[-1].v.string));
4956 YYERROR;
4957 }
4958 if ((yyvsp[0].v.prefixlen).op == OP_RANGE && ps->sflags & PREFIXSET_FLAG_OPS) {
4959 yyerror("prefix-set %s contains prefixlen "
4960 "operators and cannot be used with an "
4961 "or-longer filter", (yyvsp[-1].v.string));
4962 free((yyvsp[-1].v.string));
4963 YYERROR;
4964 }
4965 if ((yyvsp[0].v.prefixlen).op == OP_RANGE && (yyvsp[0].v.prefixlen).len_min == -1 &&
4966 (yyvsp[0].v.prefixlen).len_min == -1)
4967 fmopts.m.prefixset.flags |=
4968 PREFIXSET_FLAG_LONGER;
4969 fmopts.m.prefixset.flags |= PREFIXSET_FLAG_FILTER;
4970 free((yyvsp[-1].v.string));
4971 }
4972 #line 4973 "parse.c" /* yacc.c:1652 */
4973 break;
4974
4975 case 249:
4976 #line 2342 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
4977 {
4978 if (fmopts.m.originset.name[0] != '\0') {
4979 yyerror("origin-set filter already specified");
4980 free((yyvsp[0].v.string));
4981 YYERROR;
4982 }
4983 if (find_prefixset((yyvsp[0].v.string), &conf->originsets) == NULL) {
4984 yyerror("origin-set '%s' not defined", (yyvsp[0].v.string));
4985 free((yyvsp[0].v.string));
4986 YYERROR;
4987 }
4988 if (strlcpy(fmopts.m.originset.name, (yyvsp[0].v.string),
4989 sizeof(fmopts.m.originset.name)) >=
4990 sizeof(fmopts.m.originset.name)) {
4991 yyerror("origin-set name too long");
4992 free((yyvsp[0].v.string));
4993 YYERROR;
4994 }
4995 free((yyvsp[0].v.string));
4996 }
4997 #line 4998 "parse.c" /* yacc.c:1652 */
4998 break;
4999
5000 case 250:
5001 #line 2362 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5002 {
5003 if (fmopts.m.ovs.is_set) {
5004 yyerror("ovs filter already specified");
5005 YYERROR;
5006 }
5007 fmopts.m.ovs.validity = (yyvsp[0].v.number);
5008 fmopts.m.ovs.is_set = 1;
5009 }
5010 #line 5011 "parse.c" /* yacc.c:1652 */
5011 break;
5012
5013 case 251:
5014 #line 2372 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5015 { bzero(&(yyval.v.prefixlen), sizeof((yyval.v.prefixlen))); }
5016 #line 5017 "parse.c" /* yacc.c:1652 */
5017 break;
5018
5019 case 252:
5020 #line 2373 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5021 {
5022 bzero(&(yyval.v.prefixlen), sizeof((yyval.v.prefixlen)));
5023 (yyval.v.prefixlen).op = OP_RANGE;
5024 (yyval.v.prefixlen).len_min = -1;
5025 (yyval.v.prefixlen).len_max = -1;
5026 }
5027 #line 5028 "parse.c" /* yacc.c:1652 */
5028 break;
5029
5030 case 253:
5031 #line 2379 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5032 {
5033 bzero(&(yyval.v.prefixlen), sizeof((yyval.v.prefixlen)));
5034 if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > 128) {
5035 yyerror("prefixlen must be >= 0 and <= 128");
5036 YYERROR;
5037 }
5038
5039 (yyval.v.prefixlen).op = OP_RANGE;
5040 (yyval.v.prefixlen).len_min = -1;
5041 (yyval.v.prefixlen).len_max = (yyvsp[0].v.number);
5042 }
5043 #line 5044 "parse.c" /* yacc.c:1652 */
5044 break;
5045
5046 case 254:
5047 #line 2390 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5048 {
5049 int min, max;
5050
5051 bzero(&(yyval.v.prefixlen), sizeof((yyval.v.prefixlen)));
5052 if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > 128) {
5053 yyerror("prefixlen must be >= 0 and <= 128");
5054 YYERROR;
5055 }
5056 /*
5057 * convert the unary operation into the equivalent
5058 * range check
5059 */
5060 (yyval.v.prefixlen).op = OP_RANGE;
5061
5062 switch ((yyvsp[-1].v.u8)) {
5063 case OP_NE:
5064 (yyval.v.prefixlen).op = (yyvsp[-1].v.u8);
5065 case OP_EQ:
5066 min = max = (yyvsp[0].v.number);
5067 break;
5068 case OP_LT:
5069 if ((yyvsp[0].v.number) == 0) {
5070 yyerror("prefixlen must be > 0");
5071 YYERROR;
5072 }
5073 (yyvsp[0].v.number) -= 1;
5074 case OP_LE:
5075 min = -1;
5076 max = (yyvsp[0].v.number);
5077 break;
5078 case OP_GT:
5079 (yyvsp[0].v.number) += 1;
5080 case OP_GE:
5081 min = (yyvsp[0].v.number);
5082 max = -1;
5083 break;
5084 default:
5085 yyerror("unknown prefixlen operation");
5086 YYERROR;
5087 }
5088 (yyval.v.prefixlen).len_min = min;
5089 (yyval.v.prefixlen).len_max = max;
5090 }
5091 #line 5092 "parse.c" /* yacc.c:1652 */
5092 break;
5093
5094 case 255:
5095 #line 2433 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5096 {
5097 bzero(&(yyval.v.prefixlen), sizeof((yyval.v.prefixlen)));
5098 if ((yyvsp[-2].v.number) < 0 || (yyvsp[-2].v.number) > 128 || (yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > 128) {
5099 yyerror("prefixlen must be < 128");
5100 YYERROR;
5101 }
5102 if ((yyvsp[-2].v.number) > (yyvsp[0].v.number)) {
5103 yyerror("start prefixlen is bigger than end");
5104 YYERROR;
5105 }
5106 (yyval.v.prefixlen).op = (yyvsp[-1].v.u8);
5107 (yyval.v.prefixlen).len_min = (yyvsp[-2].v.number);
5108 (yyval.v.prefixlen).len_max = (yyvsp[0].v.number);
5109 }
5110 #line 5111 "parse.c" /* yacc.c:1652 */
5111 break;
5112
5113 case 256:
5114 #line 2449 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5115 { (yyval.v.u8) = AS_ALL; }
5116 #line 5117 "parse.c" /* yacc.c:1652 */
5117 break;
5118
5119 case 257:
5120 #line 2450 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5121 { (yyval.v.u8) = AS_SOURCE; }
5122 #line 5123 "parse.c" /* yacc.c:1652 */
5123 break;
5124
5125 case 258:
5126 #line 2451 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5127 { (yyval.v.u8) = AS_TRANSIT; }
5128 #line 5129 "parse.c" /* yacc.c:1652 */
5129 break;
5130
5131 case 259:
5132 #line 2452 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5133 { (yyval.v.u8) = AS_PEER; }
5134 #line 5135 "parse.c" /* yacc.c:1652 */
5135 break;
5136
5137 case 260:
5138 #line 2455 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5139 { (yyval.v.filter_set_head) = NULL; }
5140 #line 5141 "parse.c" /* yacc.c:1652 */
5141 break;
5142
5143 case 261:
5144 #line 2456 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5145 {
5146 if (((yyval.v.filter_set_head) = calloc(1, sizeof(struct filter_set_head))) ==
5147 NULL)
5148 fatal(NULL);
5149 TAILQ_INIT((yyval.v.filter_set_head));
5150 TAILQ_INSERT_TAIL((yyval.v.filter_set_head), (yyvsp[0].v.filter_set), entry);
5151 }
5152 #line 5153 "parse.c" /* yacc.c:1652 */
5153 break;
5154
5155 case 262:
5156 #line 2463 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5157 { (yyval.v.filter_set_head) = (yyvsp[-2].v.filter_set_head); }
5158 #line 5159 "parse.c" /* yacc.c:1652 */
5159 break;
5160
5161 case 263:
5162 #line 2466 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5163 {
5164 (yyval.v.filter_set_head) = (yyvsp[-2].v.filter_set_head);
5165 if (merge_filterset((yyval.v.filter_set_head), (yyvsp[0].v.filter_set)) == 1)
5166 YYERROR;
5167 }
5168 #line 5169 "parse.c" /* yacc.c:1652 */
5169 break;
5170
5171 case 264:
5172 #line 2471 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5173 {
5174 if (((yyval.v.filter_set_head) = calloc(1, sizeof(struct filter_set_head))) ==
5175 NULL)
5176 fatal(NULL);
5177 TAILQ_INIT((yyval.v.filter_set_head));
5178 TAILQ_INSERT_TAIL((yyval.v.filter_set_head), (yyvsp[0].v.filter_set), entry);
5179 }
5180 #line 5181 "parse.c" /* yacc.c:1652 */
5181 break;
5182
5183 case 265:
5184 #line 2480 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5185 { (yyval.v.u8) = COMMUNITY_TYPE_BASIC; }
5186 #line 5187 "parse.c" /* yacc.c:1652 */
5187 break;
5188
5189 case 266:
5190 #line 2481 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5191 { (yyval.v.u8) = COMMUNITY_TYPE_LARGE; }
5192 #line 5193 "parse.c" /* yacc.c:1652 */
5193 break;
5194
5195 case 267:
5196 #line 2484 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5197 { (yyval.v.u8) = 0; }
5198 #line 5199 "parse.c" /* yacc.c:1652 */
5199 break;
5200
5201 case 268:
5202 #line 2485 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5203 { (yyval.v.u8) = 1; }
5204 #line 5205 "parse.c" /* yacc.c:1652 */
5205 break;
5206
5207 case 269:
5208 #line 2488 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5209 {
5210 if ((yyvsp[0].v.number) < -INT_MAX || (yyvsp[0].v.number) > UINT_MAX) {
5211 yyerror("bad localpref %lld", (yyvsp[0].v.number));
5212 YYERROR;
5213 }
5214 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5215 fatal(NULL);
5216 if ((yyvsp[0].v.number) >= 0) {
5217 (yyval.v.filter_set)->type = ACTION_SET_LOCALPREF;
5218 (yyval.v.filter_set)->action.metric = (yyvsp[0].v.number);
5219 } else {
5220 (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_LOCALPREF;
5221 (yyval.v.filter_set)->action.relative = (yyvsp[0].v.number);
5222 }
5223 }
5224 #line 5225 "parse.c" /* yacc.c:1652 */
5225 break;
5226
5227 case 270:
5228 #line 2503 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5229 {
5230 if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) {
5231 yyerror("bad localpref +%lld", (yyvsp[0].v.number));
5232 YYERROR;
5233 }
5234 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5235 fatal(NULL);
5236 (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_LOCALPREF;
5237 (yyval.v.filter_set)->action.relative = (yyvsp[0].v.number);
5238 }
5239 #line 5240 "parse.c" /* yacc.c:1652 */
5240 break;
5241
5242 case 271:
5243 #line 2513 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5244 {
5245 if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) {
5246 yyerror("bad localpref -%lld", (yyvsp[0].v.number));
5247 YYERROR;
5248 }
5249 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5250 fatal(NULL);
5251 (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_LOCALPREF;
5252 (yyval.v.filter_set)->action.relative = -(yyvsp[0].v.number);
5253 }
5254 #line 5255 "parse.c" /* yacc.c:1652 */
5255 break;
5256
5257 case 272:
5258 #line 2523 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5259 {
5260 if ((yyvsp[0].v.number) < -INT_MAX || (yyvsp[0].v.number) > UINT_MAX) {
5261 yyerror("bad metric %lld", (yyvsp[0].v.number));
5262 YYERROR;
5263 }
5264 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5265 fatal(NULL);
5266 if ((yyvsp[0].v.number) >= 0) {
5267 (yyval.v.filter_set)->type = ACTION_SET_MED;
5268 (yyval.v.filter_set)->action.metric = (yyvsp[0].v.number);
5269 } else {
5270 (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_MED;
5271 (yyval.v.filter_set)->action.relative = (yyvsp[0].v.number);
5272 }
5273 }
5274 #line 5275 "parse.c" /* yacc.c:1652 */
5275 break;
5276
5277 case 273:
5278 #line 2538 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5279 {
5280 if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) {
5281 yyerror("bad metric +%lld", (yyvsp[0].v.number));
5282 YYERROR;
5283 }
5284 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5285 fatal(NULL);
5286 (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_MED;
5287 (yyval.v.filter_set)->action.relative = (yyvsp[0].v.number);
5288 }
5289 #line 5290 "parse.c" /* yacc.c:1652 */
5290 break;
5291
5292 case 274:
5293 #line 2548 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5294 {
5295 if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) {
5296 yyerror("bad metric -%lld", (yyvsp[0].v.number));
5297 YYERROR;
5298 }
5299 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5300 fatal(NULL);
5301 (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_MED;
5302 (yyval.v.filter_set)->action.relative = -(yyvsp[0].v.number);
5303 }
5304 #line 5305 "parse.c" /* yacc.c:1652 */
5305 break;
5306
5307 case 275:
5308 #line 2558 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5309 { /* alias for MED */
5310 if ((yyvsp[0].v.number) < -INT_MAX || (yyvsp[0].v.number) > UINT_MAX) {
5311 yyerror("bad metric %lld", (yyvsp[0].v.number));
5312 YYERROR;
5313 }
5314 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5315 fatal(NULL);
5316 if ((yyvsp[0].v.number) >= 0) {
5317 (yyval.v.filter_set)->type = ACTION_SET_MED;
5318 (yyval.v.filter_set)->action.metric = (yyvsp[0].v.number);
5319 } else {
5320 (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_MED;
5321 (yyval.v.filter_set)->action.relative = (yyvsp[0].v.number);
5322 }
5323 }
5324 #line 5325 "parse.c" /* yacc.c:1652 */
5325 break;
5326
5327 case 276:
5328 #line 2573 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5329 {
5330 if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) {
5331 yyerror("bad metric +%lld", (yyvsp[0].v.number));
5332 YYERROR;
5333 }
5334 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5335 fatal(NULL);
5336 (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_MED;
5337 (yyval.v.filter_set)->action.metric = (yyvsp[0].v.number);
5338 }
5339 #line 5340 "parse.c" /* yacc.c:1652 */
5340 break;
5341
5342 case 277:
5343 #line 2583 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5344 {
5345 if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) {
5346 yyerror("bad metric -%lld", (yyvsp[0].v.number));
5347 YYERROR;
5348 }
5349 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5350 fatal(NULL);
5351 (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_MED;
5352 (yyval.v.filter_set)->action.relative = -(yyvsp[0].v.number);
5353 }
5354 #line 5355 "parse.c" /* yacc.c:1652 */
5355 break;
5356
5357 case 278:
5358 #line 2593 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5359 {
5360 if ((yyvsp[0].v.number) < -INT_MAX || (yyvsp[0].v.number) > UINT_MAX) {
5361 yyerror("bad weight %lld", (yyvsp[0].v.number));
5362 YYERROR;
5363 }
5364 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5365 fatal(NULL);
5366 if ((yyvsp[0].v.number) > 0) {
5367 (yyval.v.filter_set)->type = ACTION_SET_WEIGHT;
5368 (yyval.v.filter_set)->action.metric = (yyvsp[0].v.number);
5369 } else {
5370 (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_WEIGHT;
5371 (yyval.v.filter_set)->action.relative = (yyvsp[0].v.number);
5372 }
5373 }
5374 #line 5375 "parse.c" /* yacc.c:1652 */
5375 break;
5376
5377 case 279:
5378 #line 2608 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5379 {
5380 if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) {
5381 yyerror("bad weight +%lld", (yyvsp[0].v.number));
5382 YYERROR;
5383 }
5384 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5385 fatal(NULL);
5386 (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_WEIGHT;
5387 (yyval.v.filter_set)->action.relative = (yyvsp[0].v.number);
5388 }
5389 #line 5390 "parse.c" /* yacc.c:1652 */
5390 break;
5391
5392 case 280:
5393 #line 2618 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5394 {
5395 if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > INT_MAX) {
5396 yyerror("bad weight -%lld", (yyvsp[0].v.number));
5397 YYERROR;
5398 }
5399 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5400 fatal(NULL);
5401 (yyval.v.filter_set)->type = ACTION_SET_RELATIVE_WEIGHT;
5402 (yyval.v.filter_set)->action.relative = -(yyvsp[0].v.number);
5403 }
5404 #line 5405 "parse.c" /* yacc.c:1652 */
5405 break;
5406
5407 case 281:
5408 #line 2628 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5409 {
5410 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5411 fatal(NULL);
5412 (yyval.v.filter_set)->type = ACTION_SET_NEXTHOP;
5413 memcpy(&(yyval.v.filter_set)->action.nexthop, &(yyvsp[0].v.addr),
5414 sizeof((yyval.v.filter_set)->action.nexthop));
5415 }
5416 #line 5417 "parse.c" /* yacc.c:1652 */
5417 break;
5418
5419 case 282:
5420 #line 2635 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5421 {
5422 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5423 fatal(NULL);
5424 (yyval.v.filter_set)->type = ACTION_SET_NEXTHOP_BLACKHOLE;
5425 }
5426 #line 5427 "parse.c" /* yacc.c:1652 */
5427 break;
5428
5429 case 283:
5430 #line 2640 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5431 {
5432 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5433 fatal(NULL);
5434 (yyval.v.filter_set)->type = ACTION_SET_NEXTHOP_REJECT;
5435 }
5436 #line 5437 "parse.c" /* yacc.c:1652 */
5437 break;
5438
5439 case 284:
5440 #line 2645 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5441 {
5442 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5443 fatal(NULL);
5444 (yyval.v.filter_set)->type = ACTION_SET_NEXTHOP_NOMODIFY;
5445 }
5446 #line 5447 "parse.c" /* yacc.c:1652 */
5447 break;
5448
5449 case 285:
5450 #line 2650 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5451 {
5452 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5453 fatal(NULL);
5454 (yyval.v.filter_set)->type = ACTION_SET_NEXTHOP_SELF;
5455 }
5456 #line 5457 "parse.c" /* yacc.c:1652 */
5457 break;
5458
5459 case 286:
5460 #line 2655 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5461 {
5462 if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > 128) {
5463 yyerror("bad number of prepends");
5464 YYERROR;
5465 }
5466 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5467 fatal(NULL);
5468 (yyval.v.filter_set)->type = ACTION_SET_PREPEND_SELF;
5469 (yyval.v.filter_set)->action.prepend = (yyvsp[0].v.number);
5470 }
5471 #line 5472 "parse.c" /* yacc.c:1652 */
5472 break;
5473
5474 case 287:
5475 #line 2665 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5476 {
5477 if ((yyvsp[0].v.number) < 0 || (yyvsp[0].v.number) > 128) {
5478 yyerror("bad number of prepends");
5479 YYERROR;
5480 }
5481 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5482 fatal(NULL);
5483 (yyval.v.filter_set)->type = ACTION_SET_PREPEND_PEER;
5484 (yyval.v.filter_set)->action.prepend = (yyvsp[0].v.number);
5485 }
5486 #line 5487 "parse.c" /* yacc.c:1652 */
5487 break;
5488
5489 case 288:
5490 #line 2675 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5491 {
5492 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5493 fatal(NULL);
5494 (yyval.v.filter_set)->type = ACTION_SET_AS_OVERRIDE;
5495 }
5496 #line 5497 "parse.c" /* yacc.c:1652 */
5497 break;
5498
5499 case 289:
5500 #line 2680 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5501 {
5502 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5503 fatal(NULL);
5504 (yyval.v.filter_set)->type = ACTION_PFTABLE;
5505 if (!(cmd_opts & BGPD_OPT_NOACTION) &&
5506 pftable_exists((yyvsp[0].v.string)) != 0) {
5507 yyerror("pftable name does not exist");
5508 free((yyvsp[0].v.string));
5509 free((yyval.v.filter_set));
5510 YYERROR;
5511 }
5512 if (strlcpy((yyval.v.filter_set)->action.pftable, (yyvsp[0].v.string),
5513 sizeof((yyval.v.filter_set)->action.pftable)) >=
5514 sizeof((yyval.v.filter_set)->action.pftable)) {
5515 yyerror("pftable name too long");
5516 free((yyvsp[0].v.string));
5517 free((yyval.v.filter_set));
5518 YYERROR;
5519 }
5520 if (pftable_add((yyvsp[0].v.string)) != 0) {
5521 yyerror("Couldn't register table");
5522 free((yyvsp[0].v.string));
5523 free((yyval.v.filter_set));
5524 YYERROR;
5525 }
5526 free((yyvsp[0].v.string));
5527 }
5528 #line 5529 "parse.c" /* yacc.c:1652 */
5529 break;
5530
5531 case 290:
5532 #line 2707 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5533 {
5534 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5535 fatal(NULL);
5536 (yyval.v.filter_set)->type = ACTION_RTLABEL;
5537 if (strlcpy((yyval.v.filter_set)->action.rtlabel, (yyvsp[0].v.string),
5538 sizeof((yyval.v.filter_set)->action.rtlabel)) >=
5539 sizeof((yyval.v.filter_set)->action.rtlabel)) {
5540 yyerror("rtlabel name too long");
5541 free((yyvsp[0].v.string));
5542 free((yyval.v.filter_set));
5543 YYERROR;
5544 }
5545 free((yyvsp[0].v.string));
5546 }
5547 #line 5548 "parse.c" /* yacc.c:1652 */
5548 break;
5549
5550 case 291:
5551 #line 2721 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5552 {
5553 u_int8_t f1, f2, f3;
5554
5555 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5556 fatal(NULL);
5557 if ((yyvsp[-1].v.u8))
5558 (yyval.v.filter_set)->type = ACTION_DEL_COMMUNITY;
5559 else
5560 (yyval.v.filter_set)->type = ACTION_SET_COMMUNITY;
5561
5562 if (parsecommunity(&(yyval.v.filter_set)->action.community, (yyvsp[-2].v.u8), (yyvsp[0].v.string)) ==
5563 -1) {
5564 free((yyvsp[0].v.string));
5565 free((yyval.v.filter_set));
5566 YYERROR;
5567 }
5568 free((yyvsp[0].v.string));
5569 /* Don't allow setting of any match */
5570 f1 = (yyval.v.filter_set)->action.community.flags >> 8;
5571 f2 = (yyval.v.filter_set)->action.community.flags >> 16;
5572 f3 = (yyval.v.filter_set)->action.community.flags >> 24;
5573 if (!(yyvsp[-1].v.u8) && (f1 == COMMUNITY_ANY ||
5574 f2 == COMMUNITY_ANY || f3 == COMMUNITY_ANY)) {
5575 yyerror("'*' is not allowed in set community");
5576 free((yyval.v.filter_set));
5577 YYERROR;
5578 }
5579 }
5580 #line 5581 "parse.c" /* yacc.c:1652 */
5581 break;
5582
5583 case 292:
5584 #line 2749 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5585 {
5586 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5587 fatal(NULL);
5588 if ((yyvsp[-2].v.u8))
5589 (yyval.v.filter_set)->type = ACTION_DEL_COMMUNITY;
5590 else
5591 (yyval.v.filter_set)->type = ACTION_SET_COMMUNITY;
5592
5593 if (parseextcommunity(&(yyval.v.filter_set)->action.community,
5594 (yyvsp[-1].v.string), (yyvsp[0].v.string)) == -1) {
5595 free((yyvsp[-1].v.string));
5596 free((yyvsp[0].v.string));
5597 free((yyval.v.filter_set));
5598 YYERROR;
5599 }
5600 free((yyvsp[-1].v.string));
5601 free((yyvsp[0].v.string));
5602 }
5603 #line 5604 "parse.c" /* yacc.c:1652 */
5604 break;
5605
5606 case 293:
5607 #line 2767 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5608 {
5609 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5610 fatal(NULL);
5611 if ((yyvsp[-2].v.u8))
5612 (yyval.v.filter_set)->type = ACTION_DEL_COMMUNITY;
5613 else
5614 (yyval.v.filter_set)->type = ACTION_SET_COMMUNITY;
5615
5616 if (parseextcommunity(&(yyval.v.filter_set)->action.community,
5617 "ovs", (yyvsp[0].v.string)) == -1) {
5618 free((yyvsp[0].v.string));
5619 free((yyval.v.filter_set));
5620 YYERROR;
5621 }
5622 free((yyvsp[0].v.string));
5623 }
5624 #line 5625 "parse.c" /* yacc.c:1652 */
5625 break;
5626
5627 case 294:
5628 #line 2783 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5629 {
5630 if (((yyval.v.filter_set) = calloc(1, sizeof(struct filter_set))) == NULL)
5631 fatal(NULL);
5632 (yyval.v.filter_set)->type = ACTION_SET_ORIGIN;
5633 (yyval.v.filter_set)->action.origin = (yyvsp[0].v.number);
5634 }
5635 #line 5636 "parse.c" /* yacc.c:1652 */
5636 break;
5637
5638 case 295:
5639 #line 2791 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5640 {
5641 if (!strcmp((yyvsp[0].v.string), "egp"))
5642 (yyval.v.number) = ORIGIN_EGP;
5643 else if (!strcmp((yyvsp[0].v.string), "igp"))
5644 (yyval.v.number) = ORIGIN_IGP;
5645 else if (!strcmp((yyvsp[0].v.string), "incomplete"))
5646 (yyval.v.number) = ORIGIN_INCOMPLETE;
5647 else {
5648 yyerror("unknown origin \"%s\"", (yyvsp[0].v.string));
5649 free((yyvsp[0].v.string));
5650 YYERROR;
5651 }
5652 free((yyvsp[0].v.string));
5653 }
5654 #line 5655 "parse.c" /* yacc.c:1652 */
5655 break;
5656
5657 case 296:
5658 #line 2806 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5659 {
5660 if (!strcmp((yyvsp[0].v.string), "not-found"))
5661 (yyval.v.number) = ROA_NOTFOUND;
5662 else if (!strcmp((yyvsp[0].v.string), "invalid"))
5663 (yyval.v.number) = ROA_INVALID;
5664 else if (!strcmp((yyvsp[0].v.string), "valid"))
5665 (yyval.v.number) = ROA_VALID;
5666 else {
5667 yyerror("unknown validity \"%s\"", (yyvsp[0].v.string));
5668 free((yyvsp[0].v.string));
5669 YYERROR;
5670 }
5671 free((yyvsp[0].v.string));
5672 }
5673 #line 5674 "parse.c" /* yacc.c:1652 */
5674 break;
5675
5676 case 303:
5677 #line 2831 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5678 { (yyval.v.u8) = OP_EQ; }
5679 #line 5680 "parse.c" /* yacc.c:1652 */
5680 break;
5681
5682 case 304:
5683 #line 2832 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5684 { (yyval.v.u8) = OP_NE; }
5685 #line 5686 "parse.c" /* yacc.c:1652 */
5686 break;
5687
5688 case 305:
5689 #line 2833 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5690 { (yyval.v.u8) = OP_LE; }
5691 #line 5692 "parse.c" /* yacc.c:1652 */
5692 break;
5693
5694 case 306:
5695 #line 2834 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5696 { (yyval.v.u8) = OP_LT; }
5697 #line 5698 "parse.c" /* yacc.c:1652 */
5698 break;
5699
5700 case 307:
5701 #line 2835 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5702 { (yyval.v.u8) = OP_GE; }
5703 #line 5704 "parse.c" /* yacc.c:1652 */
5704 break;
5705
5706 case 308:
5707 #line 2836 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5708 { (yyval.v.u8) = OP_GT; }
5709 #line 5710 "parse.c" /* yacc.c:1652 */
5710 break;
5711
5712 case 309:
5713 #line 2839 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5714 { (yyval.v.u8) = OP_EQ; }
5715 #line 5716 "parse.c" /* yacc.c:1652 */
5716 break;
5717
5718 case 310:
5719 #line 2840 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5720 { (yyval.v.u8) = OP_NE; }
5721 #line 5722 "parse.c" /* yacc.c:1652 */
5722 break;
5723
5724 case 311:
5725 #line 2843 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5726 { (yyval.v.u8) = OP_RANGE; }
5727 #line 5728 "parse.c" /* yacc.c:1652 */
5728 break;
5729
5730 case 312:
5731 #line 2844 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1652 */
5732 { (yyval.v.u8) = OP_XRANGE; }
5733 #line 5734 "parse.c" /* yacc.c:1652 */
5734 break;
5735
5736
5737 #line 5738 "parse.c" /* yacc.c:1652 */
5738 default: break;
5739 }
5740 /* User semantic actions sometimes alter yychar, and that requires
5741 that yytoken be updated with the new translation. We take the
5742 approach of translating immediately before every use of yytoken.
5743 One alternative is translating here after every semantic action,
5744 but that translation would be missed if the semantic action invokes
5745 YYABORT, YYACCEPT, or YYERROR immediately after altering yychar or
5746 if it invokes YYBACKUP. In the case of YYABORT or YYACCEPT, an
5747 incorrect destructor might then be invoked immediately. In the
5748 case of YYERROR or YYBACKUP, subsequent parser actions might lead
5749 to an incorrect destructor call or verbose syntax error message
5750 before the lookahead is translated. */
5751 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
5752
5753 YYPOPSTACK (yylen);
5754 yylen = 0;
5755 YY_STACK_PRINT (yyss, yyssp);
5756
5757 *++yyvsp = yyval;
5758
5759 /* Now 'shift' the result of the reduction. Determine what state
5760 that goes to, based on the state we popped back to and the rule
5761 number reduced by. */
5762 {
5763 const int yylhs = yyr1[yyn] - YYNTOKENS;
5764 const int yyi = yypgoto[yylhs] + *yyssp;
5765 yystate = (0 <= yyi && yyi <= YYLAST && yycheck[yyi] == *yyssp
5766 ? yytable[yyi]
5767 : yydefgoto[yylhs]);
5768 }
5769
5770 goto yynewstate;
5771
5772
5773 /*--------------------------------------.
5774 | yyerrlab -- here on detecting error. |
5775 `--------------------------------------*/
5776 yyerrlab:
5777 /* Make sure we have latest lookahead translation. See comments at
5778 user semantic actions for why this is necessary. */
5779 yytoken = yychar == YYEMPTY ? YYEMPTY : YYTRANSLATE (yychar);
5780
5781 /* If not already recovering from an error, report this error. */
5782 if (!yyerrstatus)
5783 {
5784 ++yynerrs;
5785 #if ! YYERROR_VERBOSE
5786 yyerror (YY_("syntax error"));
5787 #else
5788 # define YYSYNTAX_ERROR yysyntax_error (&yymsg_alloc, &yymsg, \
5789 yyssp, yytoken)
5790 {
5791 char const *yymsgp = YY_("syntax error");
5792 int yysyntax_error_status;
5793 yysyntax_error_status = YYSYNTAX_ERROR;
5794 if (yysyntax_error_status == 0)
5795 yymsgp = yymsg;
5796 else if (yysyntax_error_status == 1)
5797 {
5798 if (yymsg != yymsgbuf)
5799 YYSTACK_FREE (yymsg);
5800 yymsg = (char *) YYSTACK_ALLOC (yymsg_alloc);
5801 if (!yymsg)
5802 {
5803 yymsg = yymsgbuf;
5804 yymsg_alloc = sizeof yymsgbuf;
5805 yysyntax_error_status = 2;
5806 }
5807 else
5808 {
5809 yysyntax_error_status = YYSYNTAX_ERROR;
5810 yymsgp = yymsg;
5811 }
5812 }
5813 yyerror (yymsgp);
5814 if (yysyntax_error_status == 2)
5815 goto yyexhaustedlab;
5816 }
5817 # undef YYSYNTAX_ERROR
5818 #endif
5819 }
5820
5821
5822
5823 if (yyerrstatus == 3)
5824 {
5825 /* If just tried and failed to reuse lookahead token after an
5826 error, discard it. */
5827
5828 if (yychar <= YYEOF)
5829 {
5830 /* Return failure if at end of input. */
5831 if (yychar == YYEOF)
5832 YYABORT;
5833 }
5834 else
5835 {
5836 yydestruct ("Error: discarding",
5837 yytoken, &yylval);
5838 yychar = YYEMPTY;
5839 }
5840 }
5841
5842 /* Else will try to reuse lookahead token after shifting the error
5843 token. */
5844 goto yyerrlab1;
5845
5846
5847 /*---------------------------------------------------.
5848 | yyerrorlab -- error raised explicitly by YYERROR. |
5849 `---------------------------------------------------*/
5850 yyerrorlab:
5851 /* Pacify compilers when the user code never invokes YYERROR and the
5852 label yyerrorlab therefore never appears in user code. */
5853 if (0)
5854 YYERROR;
5855
5856 /* Do not reclaim the symbols of the rule whose action triggered
5857 this YYERROR. */
5858 YYPOPSTACK (yylen);
5859 yylen = 0;
5860 YY_STACK_PRINT (yyss, yyssp);
5861 yystate = *yyssp;
5862 goto yyerrlab1;
5863
5864
5865 /*-------------------------------------------------------------.
5866 | yyerrlab1 -- common code for both syntax error and YYERROR. |
5867 `-------------------------------------------------------------*/
5868 yyerrlab1:
5869 yyerrstatus = 3; /* Each real token shifted decrements this. */
5870
5871 for (;;)
5872 {
5873 yyn = yypact[yystate];
5874 if (!yypact_value_is_default (yyn))
5875 {
5876 yyn += YYTERROR;
5877 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
5878 {
5879 yyn = yytable[yyn];
5880 if (0 < yyn)
5881 break;
5882 }
5883 }
5884
5885 /* Pop the current state because it cannot handle the error token. */
5886 if (yyssp == yyss)
5887 YYABORT;
5888
5889
5890 yydestruct ("Error: popping",
5891 yystos[yystate], yyvsp);
5892 YYPOPSTACK (1);
5893 yystate = *yyssp;
5894 YY_STACK_PRINT (yyss, yyssp);
5895 }
5896
5897 YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
5898 *++yyvsp = yylval;
5899 YY_IGNORE_MAYBE_UNINITIALIZED_END
5900
5901
5902 /* Shift the error token. */
5903 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
5904
5905 yystate = yyn;
5906 goto yynewstate;
5907
5908
5909 /*-------------------------------------.
5910 | yyacceptlab -- YYACCEPT comes here. |
5911 `-------------------------------------*/
5912 yyacceptlab:
5913 yyresult = 0;
5914 goto yyreturn;
5915
5916
5917 /*-----------------------------------.
5918 | yyabortlab -- YYABORT comes here. |
5919 `-----------------------------------*/
5920 yyabortlab:
5921 yyresult = 1;
5922 goto yyreturn;
5923
5924
5925 #if !defined yyoverflow || YYERROR_VERBOSE
5926 /*-------------------------------------------------.
5927 | yyexhaustedlab -- memory exhaustion comes here. |
5928 `-------------------------------------------------*/
5929 yyexhaustedlab:
5930 yyerror (YY_("memory exhausted"));
5931 yyresult = 2;
5932 /* Fall through. */
5933 #endif
5934
5935
5936 /*-----------------------------------------------------.
5937 | yyreturn -- parsing is finished, return the result. |
5938 `-----------------------------------------------------*/
5939 yyreturn:
5940 if (yychar != YYEMPTY)
5941 {
5942 /* Make sure we have latest lookahead translation. See comments at
5943 user semantic actions for why this is necessary. */
5944 yytoken = YYTRANSLATE (yychar);
5945 yydestruct ("Cleanup: discarding lookahead",
5946 yytoken, &yylval);
5947 }
5948 /* Do not reclaim the symbols of the rule whose action triggered
5949 this YYABORT or YYACCEPT. */
5950 YYPOPSTACK (yylen);
5951 YY_STACK_PRINT (yyss, yyssp);
5952 while (yyssp != yyss)
5953 {
5954 yydestruct ("Cleanup: popping",
5955 yystos[*yyssp], yyvsp);
5956 YYPOPSTACK (1);
5957 }
5958 #ifndef yyoverflow
5959 if (yyss != yyssa)
5960 YYSTACK_FREE (yyss);
5961 #endif
5962 #if YYERROR_VERBOSE
5963 if (yymsg != yymsgbuf)
5964 YYSTACK_FREE (yymsg);
5965 #endif
5966 return yyresult;
5967 }
5968 #line 2847 "../../../openbgpd-portable/src/bgpd/parse.y" /* yacc.c:1918 */
5969
5970
5971 struct keywords {
5972 const char *k_name;
5973 int k_val;
5974 };
5975
5976 int
yyerror(const char * fmt,...)5977 yyerror(const char *fmt, ...)
5978 {
5979 va_list ap;
5980 char *msg;
5981
5982 file->errors++;
5983 va_start(ap, fmt);
5984 if (vasprintf(&msg, fmt, ap) == -1)
5985 fatalx("yyerror vasprintf");
5986 va_end(ap);
5987 logit(LOG_CRIT, "%s:%d: %s", file->name, yylval.lineno, msg);
5988 free(msg);
5989 return (0);
5990 }
5991
5992 int
kw_cmp(const void * k,const void * e)5993 kw_cmp(const void *k, const void *e)
5994 {
5995 return (strcmp(k, ((const struct keywords *)e)->k_name));
5996 }
5997
5998 int
lookup(char * s)5999 lookup(char *s)
6000 {
6001 /* this has to be sorted always */
6002 static const struct keywords keywords[] = {
6003 { "AS", AS},
6004 { "IPv4", IPV4},
6005 { "IPv6", IPV6},
6006 { "ah", AH},
6007 { "allow", ALLOW},
6008 { "announce", ANNOUNCE},
6009 { "any", ANY},
6010 { "as-4byte", AS4BYTE },
6011 { "as-override", ASOVERRIDE},
6012 { "as-set", ASSET },
6013 { "blackhole", BLACKHOLE},
6014 { "capabilities", CAPABILITIES},
6015 { "community", COMMUNITY},
6016 { "compare", COMPARE},
6017 { "connect-retry", CONNECTRETRY},
6018 { "connected", CONNECTED},
6019 { "default-route", DEFAULTROUTE},
6020 { "delete", DELETE},
6021 { "demote", DEMOTE},
6022 { "deny", DENY},
6023 { "depend", DEPEND},
6024 { "descr", DESCR},
6025 { "down", DOWN},
6026 { "dump", DUMP},
6027 { "ebgp", EBGP},
6028 { "enforce", ENFORCE},
6029 { "esp", ESP},
6030 { "evaluate", EVALUATE},
6031 { "export", EXPORT},
6032 { "export-target", EXPORTTRGT},
6033 { "ext-community", EXTCOMMUNITY},
6034 { "fib-priority", FIBPRIORITY},
6035 { "fib-update", FIBUPDATE},
6036 { "from", FROM},
6037 { "group", GROUP},
6038 { "holdtime", HOLDTIME},
6039 { "ibgp", IBGP},
6040 { "ignore", IGNORE},
6041 { "ike", IKE},
6042 { "import-target", IMPORTTRGT},
6043 { "in", IN},
6044 { "include", INCLUDE},
6045 { "inet", IPV4},
6046 { "inet6", IPV6},
6047 { "ipsec", IPSEC},
6048 { "key", KEY},
6049 { "large-community", LARGECOMMUNITY},
6050 { "listen", LISTEN},
6051 { "local-address", LOCALADDR},
6052 { "local-as", LOCALAS},
6053 { "localpref", LOCALPREF},
6054 { "log", LOG},
6055 { "match", MATCH},
6056 { "max-as-len", MAXASLEN},
6057 { "max-as-seq", MAXASSEQ},
6058 { "max-prefix", MAXPREFIX},
6059 { "maxlen", MAXLEN},
6060 { "md5sig", MD5SIG},
6061 { "med", MED},
6062 { "metric", METRIC},
6063 { "min", YMIN},
6064 { "multihop", MULTIHOP},
6065 { "neighbor", NEIGHBOR},
6066 { "neighbor-as", NEIGHBORAS},
6067 { "network", NETWORK},
6068 { "nexthop", NEXTHOP},
6069 { "no-modify", NOMODIFY},
6070 { "none", NONE},
6071 { "on", ON},
6072 { "or-longer", LONGER},
6073 { "origin", ORIGIN},
6074 { "origin-set", ORIGINSET},
6075 { "out", OUT},
6076 { "ovs", OVS},
6077 { "passive", PASSIVE},
6078 { "password", PASSWORD},
6079 { "peer-as", PEERAS},
6080 { "pftable", PFTABLE},
6081 { "port", PORT},
6082 { "prefix", PREFIX},
6083 { "prefix-set", PREFIXSET},
6084 { "prefixlen", PREFIXLEN},
6085 { "prepend-neighbor", PREPEND_PEER},
6086 { "prepend-self", PREPEND_SELF},
6087 { "priority", PRIORITY},
6088 { "qualify", QUALIFY},
6089 { "quick", QUICK},
6090 { "rd", RD},
6091 { "rde", RDE},
6092 { "refresh", REFRESH },
6093 { "reject", REJECT},
6094 { "remote-as", REMOTEAS},
6095 { "restart", RESTART},
6096 { "restricted", RESTRICTED},
6097 { "rib", RIB},
6098 { "roa-set", ROASET },
6099 { "route-reflector", REFLECTOR},
6100 { "router-id", ROUTERID},
6101 { "rtable", RTABLE},
6102 { "rtlabel", RTLABEL},
6103 { "rtr", RTR},
6104 { "self", SELF},
6105 { "set", SET},
6106 { "socket", SOCKET },
6107 { "source-as", SOURCEAS},
6108 { "spi", SPI},
6109 { "static", STATIC},
6110 { "tcp", TCP},
6111 { "to", TO},
6112 { "transit-as", TRANSITAS},
6113 { "transparent-as", TRANSPARENT},
6114 { "ttl-security", TTLSECURITY},
6115 { "unicast", UNICAST},
6116 { "via", VIA},
6117 { "vpn", VPN},
6118 { "weight", WEIGHT}
6119 };
6120 const struct keywords *p;
6121
6122 p = bsearch(s, keywords, sizeof(keywords)/sizeof(keywords[0]),
6123 sizeof(keywords[0]), kw_cmp);
6124
6125 if (p)
6126 return (p->k_val);
6127 else
6128 return (STRING);
6129 }
6130
6131 #define START_EXPAND 1
6132 #define DONE_EXPAND 2
6133
6134 static int expanding;
6135
6136 int
igetc(void)6137 igetc(void)
6138 {
6139 int c;
6140
6141 while (1) {
6142 if (file->ungetpos > 0)
6143 c = file->ungetbuf[--file->ungetpos];
6144 else
6145 c = getc(file->stream);
6146
6147 if (c == START_EXPAND)
6148 expanding = 1;
6149 else if (c == DONE_EXPAND)
6150 expanding = 0;
6151 else
6152 break;
6153 }
6154 return (c);
6155 }
6156
6157 int
lgetc(int quotec)6158 lgetc(int quotec)
6159 {
6160 int c, next;
6161
6162 if (quotec) {
6163 if ((c = igetc()) == EOF) {
6164 yyerror("reached end of file while parsing "
6165 "quoted string");
6166 if (file == topfile || popfile() == EOF)
6167 return (EOF);
6168 return (quotec);
6169 }
6170 return (c);
6171 }
6172
6173 while ((c = igetc()) == '\\') {
6174 next = igetc();
6175 if (next != '\n') {
6176 c = next;
6177 break;
6178 }
6179 yylval.lineno = file->lineno;
6180 file->lineno++;
6181 }
6182
6183 if (c == EOF) {
6184 /*
6185 * Fake EOL when hit EOF for the first time. This gets line
6186 * count right if last line in included file is syntactically
6187 * invalid and has no newline.
6188 */
6189 if (file->eof_reached == 0) {
6190 file->eof_reached = 1;
6191 return ('\n');
6192 }
6193 while (c == EOF) {
6194 if (file == topfile || popfile() == EOF)
6195 return (EOF);
6196 c = igetc();
6197 }
6198 }
6199 return (c);
6200 }
6201
6202 void
lungetc(int c)6203 lungetc(int c)
6204 {
6205 if (c == EOF)
6206 return;
6207
6208 if (file->ungetpos >= file->ungetsize) {
6209 void *p = reallocarray(file->ungetbuf, file->ungetsize, 2);
6210 if (p == NULL)
6211 err(1, "lungetc");
6212 file->ungetbuf = p;
6213 file->ungetsize *= 2;
6214 }
6215 file->ungetbuf[file->ungetpos++] = c;
6216 }
6217
6218 int
findeol(void)6219 findeol(void)
6220 {
6221 int c;
6222
6223 /* skip to either EOF or the first real EOL */
6224 while (1) {
6225 c = lgetc(0);
6226 if (c == '\n') {
6227 file->lineno++;
6228 break;
6229 }
6230 if (c == EOF)
6231 break;
6232 }
6233 return (ERROR);
6234 }
6235
6236 int
yylex(void)6237 yylex(void)
6238 {
6239 u_char buf[8096];
6240 u_char *p, *val;
6241 int quotec, next, c;
6242 int token;
6243
6244 top:
6245 p = buf;
6246 while ((c = lgetc(0)) == ' ' || c == '\t')
6247 ; /* nothing */
6248
6249 yylval.lineno = file->lineno;
6250 if (c == '#')
6251 while ((c = lgetc(0)) != '\n' && c != EOF)
6252 ; /* nothing */
6253 if (c == '$' && !expanding) {
6254 while (1) {
6255 if ((c = lgetc(0)) == EOF)
6256 return (0);
6257
6258 if (p + 1 >= buf + sizeof(buf) - 1) {
6259 yyerror("string too long");
6260 return (findeol());
6261 }
6262 if (isalnum(c) || c == '_') {
6263 *p++ = c;
6264 continue;
6265 }
6266 *p = '\0';
6267 lungetc(c);
6268 break;
6269 }
6270 val = symget(buf);
6271 if (val == NULL) {
6272 yyerror("macro '%s' not defined", buf);
6273 return (findeol());
6274 }
6275 p = val + strlen(val) - 1;
6276 lungetc(DONE_EXPAND);
6277 while (p >= val) {
6278 lungetc(*p);
6279 p--;
6280 }
6281 lungetc(START_EXPAND);
6282 goto top;
6283 }
6284
6285 switch (c) {
6286 case '\'':
6287 case '"':
6288 quotec = c;
6289 while (1) {
6290 if ((c = lgetc(quotec)) == EOF)
6291 return (0);
6292 if (c == '\n') {
6293 file->lineno++;
6294 continue;
6295 } else if (c == '\\') {
6296 if ((next = lgetc(quotec)) == EOF)
6297 return (0);
6298 if (next == quotec || next == ' ' ||
6299 next == '\t')
6300 c = next;
6301 else if (next == '\n') {
6302 file->lineno++;
6303 continue;
6304 } else
6305 lungetc(next);
6306 } else if (c == quotec) {
6307 *p = '\0';
6308 break;
6309 } else if (c == '\0') {
6310 yyerror("syntax error: unterminated quote");
6311 return (findeol());
6312 }
6313 if (p + 1 >= buf + sizeof(buf) - 1) {
6314 yyerror("string too long");
6315 return (findeol());
6316 }
6317 *p++ = c;
6318 }
6319 yylval.v.string = strdup(buf);
6320 if (yylval.v.string == NULL)
6321 fatal("yylex: strdup");
6322 return (STRING);
6323 case '!':
6324 next = lgetc(0);
6325 if (next == '=')
6326 return (NE);
6327 lungetc(next);
6328 break;
6329 case '<':
6330 next = lgetc(0);
6331 if (next == '=')
6332 return (LE);
6333 lungetc(next);
6334 break;
6335 case '>':
6336 next = lgetc(0);
6337 if (next == '<')
6338 return (XRANGE);
6339 else if (next == '=')
6340 return (GE);
6341 lungetc(next);
6342 break;
6343 }
6344
6345 #define allowed_to_end_number(x) \
6346 (isspace(x) || x == ')' || x ==',' || x == '/' || x == '}' || x == '=')
6347
6348 if (c == '-' || isdigit(c)) {
6349 do {
6350 *p++ = c;
6351 if ((size_t)(p-buf) >= sizeof(buf)) {
6352 yyerror("string too long");
6353 return (findeol());
6354 }
6355 } while ((c = lgetc(0)) != EOF && isdigit(c));
6356 lungetc(c);
6357 if (p == buf + 1 && buf[0] == '-')
6358 goto nodigits;
6359 if (c == EOF || allowed_to_end_number(c)) {
6360 const char *errstr = NULL;
6361
6362 *p = '\0';
6363 yylval.v.number = strtonum(buf, LLONG_MIN,
6364 LLONG_MAX, &errstr);
6365 if (errstr) {
6366 yyerror("\"%s\" invalid number: %s",
6367 buf, errstr);
6368 return (findeol());
6369 }
6370 return (NUMBER);
6371 } else {
6372 nodigits:
6373 while (p > buf + 1)
6374 lungetc(*--p);
6375 c = *--p;
6376 if (c == '-')
6377 return (c);
6378 }
6379 }
6380
6381 #define allowed_in_string(x) \
6382 (isalnum(x) || (ispunct(x) && x != '(' && x != ')' && \
6383 x != '{' && x != '}' && x != '<' && x != '>' && \
6384 x != '!' && x != '=' && x != '/' && x != '#' && \
6385 x != ','))
6386
6387 if (isalnum(c) || c == ':' || c == '_' || c == '*') {
6388 do {
6389 *p++ = c;
6390 if ((size_t)(p-buf) >= sizeof(buf)) {
6391 yyerror("string too long");
6392 return (findeol());
6393 }
6394 } while ((c = lgetc(0)) != EOF && (allowed_in_string(c)));
6395 lungetc(c);
6396 *p = '\0';
6397 if ((token = lookup(buf)) == STRING)
6398 if ((yylval.v.string = strdup(buf)) == NULL)
6399 fatal("yylex: strdup");
6400 return (token);
6401 }
6402 if (c == '\n') {
6403 yylval.lineno = file->lineno;
6404 file->lineno++;
6405 }
6406 if (c == EOF)
6407 return (0);
6408 return (c);
6409 }
6410
6411 int
check_file_secrecy(int fd,const char * fname)6412 check_file_secrecy(int fd, const char *fname)
6413 {
6414 struct stat st;
6415
6416 if (fstat(fd, &st)) {
6417 log_warn("cannot stat %s", fname);
6418 return (-1);
6419 }
6420 return (0);
6421 }
6422
6423 struct file *
pushfile(const char * name,int secret)6424 pushfile(const char *name, int secret)
6425 {
6426 struct file *nfile;
6427
6428 if ((nfile = calloc(1, sizeof(struct file))) == NULL) {
6429 log_warn("%s", __func__);
6430 return (NULL);
6431 }
6432 if ((nfile->name = strdup(name)) == NULL) {
6433 log_warn("%s", __func__);
6434 free(nfile);
6435 return (NULL);
6436 }
6437 if ((nfile->stream = fopen(nfile->name, "r")) == NULL) {
6438 log_warn("%s: %s", __func__, nfile->name);
6439 free(nfile->name);
6440 free(nfile);
6441 return (NULL);
6442 }
6443 if (secret &&
6444 check_file_secrecy(fileno(nfile->stream), nfile->name)) {
6445 fclose(nfile->stream);
6446 free(nfile->name);
6447 free(nfile);
6448 return (NULL);
6449 }
6450 nfile->lineno = TAILQ_EMPTY(&files) ? 1 : 0;
6451 nfile->ungetsize = 16;
6452 nfile->ungetbuf = malloc(nfile->ungetsize);
6453 if (nfile->ungetbuf == NULL) {
6454 log_warn("%s", __func__);
6455 fclose(nfile->stream);
6456 free(nfile->name);
6457 free(nfile);
6458 return (NULL);
6459 }
6460 TAILQ_INSERT_TAIL(&files, nfile, entry);
6461 return (nfile);
6462 }
6463
6464 int
popfile(void)6465 popfile(void)
6466 {
6467 struct file *prev;
6468
6469 if ((prev = TAILQ_PREV(file, files, entry)) != NULL)
6470 prev->errors += file->errors;
6471
6472 TAILQ_REMOVE(&files, file, entry);
6473 fclose(file->stream);
6474 free(file->name);
6475 free(file->ungetbuf);
6476 free(file);
6477 file = prev;
6478 return (file ? 0 : EOF);
6479 }
6480
6481 static void
init_config(struct bgpd_config * c)6482 init_config(struct bgpd_config *c)
6483 {
6484 u_int rdomid;
6485
6486 c->min_holdtime = MIN_HOLDTIME;
6487 c->holdtime = INTERVAL_HOLD;
6488 c->connectretry = INTERVAL_CONNECTRETRY;
6489 c->bgpid = get_bgpid();
6490 c->fib_priority = RTP_BGP;
6491 c->default_tableid = getrtable();
6492 ktable_exists(c->default_tableid, &rdomid);
6493 if (rdomid != c->default_tableid)
6494 fatalx("current routing table %u is not a routing domain",
6495 c->default_tableid);
6496
6497 if (asprintf(&c->csock, "%s.%d", SOCKET_NAME, c->default_tableid) == -1)
6498 fatal(NULL);
6499 }
6500
6501 struct bgpd_config *
parse_config(char * filename,struct peer_head * ph,struct rtr_config_head * rh)6502 parse_config(char *filename, struct peer_head *ph, struct rtr_config_head *rh)
6503 {
6504 struct sym *sym, *next;
6505 struct rde_rib *rr;
6506 struct network *n;
6507 int errors = 0;
6508
6509 conf = new_config();
6510 init_config(conf);
6511
6512 if ((filter_l = calloc(1, sizeof(struct filter_head))) == NULL)
6513 fatal(NULL);
6514 if ((peerfilter_l = calloc(1, sizeof(struct filter_head))) == NULL)
6515 fatal(NULL);
6516 if ((groupfilter_l = calloc(1, sizeof(struct filter_head))) == NULL)
6517 fatal(NULL);
6518 TAILQ_INIT(filter_l);
6519 TAILQ_INIT(peerfilter_l);
6520 TAILQ_INIT(groupfilter_l);
6521
6522 curpeer = NULL;
6523 curgroup = NULL;
6524
6525 cur_peers = ph;
6526 cur_rtrs = rh;
6527 new_peers = &conf->peers;
6528 netconf = &conf->networks;
6529
6530 if ((rr = add_rib("Adj-RIB-In")) == NULL)
6531 fatal("add_rib failed");
6532 rr->flags = F_RIB_NOFIB | F_RIB_NOEVALUATE;
6533 if ((rr = add_rib("Loc-RIB")) == NULL)
6534 fatal("add_rib failed");
6535 rib_add_fib(rr, conf->default_tableid);
6536 rr->flags = F_RIB_LOCAL;
6537
6538 if ((file = pushfile(filename, 1)) == NULL)
6539 goto errors;
6540 topfile = file;
6541
6542 yyparse();
6543 errors = file->errors;
6544 popfile();
6545
6546 /* check that we dont try to announce our own routes */
6547 TAILQ_FOREACH(n, netconf, entry)
6548 if (n->net.priority == conf->fib_priority) {
6549 errors++;
6550 logit(LOG_CRIT, "network priority %d == fib-priority "
6551 "%d is not allowed.",
6552 n->net.priority, conf->fib_priority);
6553 }
6554
6555 /* Free macros and check which have not been used. */
6556 TAILQ_FOREACH_SAFE(sym, &symhead, entry, next) {
6557 if ((cmd_opts & BGPD_OPT_VERBOSE2) && !sym->used)
6558 fprintf(stderr, "warning: macro \"%s\" not "
6559 "used\n", sym->nam);
6560 if (!sym->persist) {
6561 free(sym->nam);
6562 free(sym->val);
6563 TAILQ_REMOVE(&symhead, sym, entry);
6564 free(sym);
6565 }
6566 }
6567
6568 if (!conf->as) {
6569 log_warnx("configuration error: AS not given");
6570 errors++;
6571 }
6572
6573 /* clear the globals */
6574 curpeer = NULL;
6575 curgroup = NULL;
6576 cur_peers = NULL;
6577 new_peers = NULL;
6578 netconf = NULL;
6579
6580 if (errors) {
6581 errors:
6582 while ((rr = SIMPLEQ_FIRST(&ribnames)) != NULL) {
6583 SIMPLEQ_REMOVE_HEAD(&ribnames, entry);
6584 free(rr);
6585 }
6586
6587 filterlist_free(filter_l);
6588 filterlist_free(peerfilter_l);
6589 filterlist_free(groupfilter_l);
6590
6591 free_config(conf);
6592 return (NULL);
6593 } else {
6594 /* update clusterid in case it was not set explicitly */
6595 if ((conf->flags & BGPD_FLAG_REFLECTOR) && conf->clusterid == 0)
6596 conf->clusterid = conf->bgpid;
6597
6598 /*
6599 * Concatenate filter list and static group and peer filtersets
6600 * together. Static group sets come first then peer sets
6601 * last normal filter rules.
6602 */
6603 TAILQ_CONCAT(conf->filters, groupfilter_l, entry);
6604 TAILQ_CONCAT(conf->filters, peerfilter_l, entry);
6605 TAILQ_CONCAT(conf->filters, filter_l, entry);
6606
6607 optimize_filters(conf->filters);
6608
6609 free(filter_l);
6610 free(peerfilter_l);
6611 free(groupfilter_l);
6612
6613 return (conf);
6614 }
6615 }
6616
6617 int
symset(const char * nam,const char * val,int persist)6618 symset(const char *nam, const char *val, int persist)
6619 {
6620 struct sym *sym;
6621
6622 TAILQ_FOREACH(sym, &symhead, entry) {
6623 if (strcmp(nam, sym->nam) == 0)
6624 break;
6625 }
6626
6627 if (sym != NULL) {
6628 if (sym->persist == 1)
6629 return (0);
6630 else {
6631 free(sym->nam);
6632 free(sym->val);
6633 TAILQ_REMOVE(&symhead, sym, entry);
6634 free(sym);
6635 }
6636 }
6637 if ((sym = calloc(1, sizeof(*sym))) == NULL)
6638 return (-1);
6639
6640 sym->nam = strdup(nam);
6641 if (sym->nam == NULL) {
6642 free(sym);
6643 return (-1);
6644 }
6645 sym->val = strdup(val);
6646 if (sym->val == NULL) {
6647 free(sym->nam);
6648 free(sym);
6649 return (-1);
6650 }
6651 sym->used = 0;
6652 sym->persist = persist;
6653 TAILQ_INSERT_TAIL(&symhead, sym, entry);
6654 return (0);
6655 }
6656
6657 int
cmdline_symset(char * s)6658 cmdline_symset(char *s)
6659 {
6660 char *sym, *val;
6661 int ret;
6662
6663 if ((val = strrchr(s, '=')) == NULL)
6664 return (-1);
6665 sym = strndup(s, val - s);
6666 if (sym == NULL)
6667 fatal("%s: strndup", __func__);
6668 ret = symset(sym, val + 1, 1);
6669 free(sym);
6670
6671 return (ret);
6672 }
6673
6674 char *
symget(const char * nam)6675 symget(const char *nam)
6676 {
6677 struct sym *sym;
6678
6679 TAILQ_FOREACH(sym, &symhead, entry) {
6680 if (strcmp(nam, sym->nam) == 0) {
6681 sym->used = 1;
6682 return (sym->val);
6683 }
6684 }
6685 return (NULL);
6686 }
6687
6688 static int
cmpcommunity(struct community * a,struct community * b)6689 cmpcommunity(struct community *a, struct community *b)
6690 {
6691 if (a->flags > b->flags)
6692 return 1;
6693 if (a->flags < b->flags)
6694 return -1;
6695 if (a->data1 > b->data1)
6696 return 1;
6697 if (a->data1 < b->data1)
6698 return -1;
6699 if (a->data2 > b->data2)
6700 return 1;
6701 if (a->data2 < b->data2)
6702 return -1;
6703 if (a->data3 > b->data3)
6704 return 1;
6705 if (a->data3 < b->data3)
6706 return -1;
6707 return 0;
6708 }
6709
6710 static int
getcommunity(char * s,int large,u_int32_t * val,u_int32_t * flag)6711 getcommunity(char *s, int large, u_int32_t *val, u_int32_t *flag)
6712 {
6713 long long max = USHRT_MAX;
6714 const char *errstr;
6715
6716 *flag = 0;
6717 *val = 0;
6718 if (strcmp(s, "*") == 0) {
6719 *flag = COMMUNITY_ANY;
6720 return 0;
6721 } else if (strcmp(s, "neighbor-as") == 0) {
6722 *flag = COMMUNITY_NEIGHBOR_AS;
6723 return 0;
6724 } else if (strcmp(s, "local-as") == 0) {
6725 *flag = COMMUNITY_LOCAL_AS;
6726 return 0;
6727 }
6728 if (large)
6729 max = UINT_MAX;
6730 *val = strtonum(s, 0, max, &errstr);
6731 if (errstr) {
6732 yyerror("Community %s is %s (max: %lld)", s, errstr, max);
6733 return -1;
6734 }
6735 return 0;
6736 }
6737
6738 static void
setcommunity(struct community * c,u_int32_t as,u_int32_t data,u_int32_t asflag,u_int32_t dataflag)6739 setcommunity(struct community *c, u_int32_t as, u_int32_t data,
6740 u_int32_t asflag, u_int32_t dataflag)
6741 {
6742 c->flags = COMMUNITY_TYPE_BASIC;
6743 c->flags |= asflag << 8;
6744 c->flags |= dataflag << 16;
6745 c->data1 = as;
6746 c->data2 = data;
6747 c->data3 = 0;
6748 }
6749
6750 static int
parselargecommunity(struct community * c,char * s)6751 parselargecommunity(struct community *c, char *s)
6752 {
6753 char *p, *q;
6754 u_int32_t dflag1, dflag2, dflag3;
6755
6756 if ((p = strchr(s, ':')) == NULL) {
6757 yyerror("Bad community syntax");
6758 return (-1);
6759 }
6760 *p++ = 0;
6761
6762 if ((q = strchr(p, ':')) == NULL) {
6763 yyerror("Bad community syntax");
6764 return (-1);
6765 }
6766 *q++ = 0;
6767
6768 if (getcommunity(s, 1, &c->data1, &dflag1) == -1 ||
6769 getcommunity(p, 1, &c->data2, &dflag2) == -1 ||
6770 getcommunity(q, 1, &c->data3, &dflag3) == -1)
6771 return (-1);
6772 c->flags = COMMUNITY_TYPE_LARGE;
6773 c->flags |= dflag1 << 8;;
6774 c->flags |= dflag2 << 16;;
6775 c->flags |= dflag3 << 24;;
6776 return (0);
6777 }
6778
6779 int
parsecommunity(struct community * c,int type,char * s)6780 parsecommunity(struct community *c, int type, char *s)
6781 {
6782 char *p;
6783 u_int32_t as, data, asflag, dataflag;
6784
6785 if (type == COMMUNITY_TYPE_LARGE)
6786 return parselargecommunity(c, s);
6787
6788 /* Well-known communities */
6789 if (strcasecmp(s, "GRACEFUL_SHUTDOWN") == 0) {
6790 setcommunity(c, COMMUNITY_WELLKNOWN,
6791 COMMUNITY_GRACEFUL_SHUTDOWN, 0, 0);
6792 return (0);
6793 } else if (strcasecmp(s, "NO_EXPORT") == 0) {
6794 setcommunity(c, COMMUNITY_WELLKNOWN,
6795 COMMUNITY_NO_EXPORT, 0, 0);
6796 return (0);
6797 } else if (strcasecmp(s, "NO_ADVERTISE") == 0) {
6798 setcommunity(c, COMMUNITY_WELLKNOWN,
6799 COMMUNITY_NO_ADVERTISE, 0, 0);
6800 return (0);
6801 } else if (strcasecmp(s, "NO_EXPORT_SUBCONFED") == 0) {
6802 setcommunity(c, COMMUNITY_WELLKNOWN,
6803 COMMUNITY_NO_EXPSUBCONFED, 0, 0);
6804 return (0);
6805 } else if (strcasecmp(s, "NO_PEER") == 0) {
6806 setcommunity(c, COMMUNITY_WELLKNOWN,
6807 COMMUNITY_NO_PEER, 0, 0);
6808 return (0);
6809 } else if (strcasecmp(s, "BLACKHOLE") == 0) {
6810 setcommunity(c, COMMUNITY_WELLKNOWN,
6811 COMMUNITY_BLACKHOLE, 0, 0);
6812 return (0);
6813 }
6814
6815 if ((p = strchr(s, ':')) == NULL) {
6816 yyerror("Bad community syntax");
6817 return (-1);
6818 }
6819 *p++ = 0;
6820
6821 if (getcommunity(s, 0, &as, &asflag) == -1 ||
6822 getcommunity(p, 0, &data, &dataflag) == -1)
6823 return (-1);
6824 setcommunity(c, as, data, asflag, dataflag);
6825 return (0);
6826 }
6827
6828 static int
parsesubtype(char * name,int * type,int * subtype)6829 parsesubtype(char *name, int *type, int *subtype)
6830 {
6831 const struct ext_comm_pairs *cp;
6832 int found = 0;
6833
6834 for (cp = iana_ext_comms; cp->subname != NULL; cp++) {
6835 if (strcmp(name, cp->subname) == 0) {
6836 if (found == 0) {
6837 *type = cp->type;
6838 *subtype = cp->subtype;
6839 }
6840 found++;
6841 }
6842 }
6843 if (found > 1)
6844 *type = -1;
6845 return (found);
6846 }
6847
6848 static int
parseextvalue(int type,char * s,u_int32_t * v,u_int32_t * flag)6849 parseextvalue(int type, char *s, u_int32_t *v, u_int32_t *flag)
6850 {
6851 const char *errstr;
6852 char *p;
6853 struct in_addr ip;
6854 u_int32_t uvalh, uval;
6855
6856 if (type != -1) {
6857 /* nothing */
6858 } else if (strcmp(s, "neighbor-as") == 0) {
6859 *flag = COMMUNITY_NEIGHBOR_AS;
6860 *v = 0;
6861 return EXT_COMMUNITY_TRANS_FOUR_AS;
6862 } else if (strcmp(s, "local-as") == 0) {
6863 *flag = COMMUNITY_LOCAL_AS;
6864 *v = 0;
6865 return EXT_COMMUNITY_TRANS_FOUR_AS;
6866 } else if ((p = strchr(s, '.')) == NULL) {
6867 /* AS_PLAIN number (4 or 2 byte) */
6868 strtonum(s, 0, USHRT_MAX, &errstr);
6869 if (errstr == NULL)
6870 type = EXT_COMMUNITY_TRANS_TWO_AS;
6871 else
6872 type = EXT_COMMUNITY_TRANS_FOUR_AS;
6873 } else if (strchr(p + 1, '.') == NULL) {
6874 /* AS_DOT number (4-byte) */
6875 type = EXT_COMMUNITY_TRANS_FOUR_AS;
6876 } else {
6877 /* more than one dot -> IP address */
6878 type = EXT_COMMUNITY_TRANS_IPV4;
6879 }
6880
6881 switch (type) {
6882 case EXT_COMMUNITY_TRANS_TWO_AS:
6883 uval = strtonum(s, 0, USHRT_MAX, &errstr);
6884 if (errstr) {
6885 yyerror("Bad ext-community %s is %s", s, errstr);
6886 return (-1);
6887 }
6888 *v = uval;
6889 break;
6890 case EXT_COMMUNITY_TRANS_FOUR_AS:
6891 if ((p = strchr(s, '.')) == NULL) {
6892 uval = strtonum(s, 0, UINT_MAX, &errstr);
6893 if (errstr) {
6894 yyerror("Bad ext-community %s is %s", s,
6895 errstr);
6896 return (-1);
6897 }
6898 *v = uval;
6899 break;
6900 }
6901 *p++ = '\0';
6902 uvalh = strtonum(s, 0, USHRT_MAX, &errstr);
6903 if (errstr) {
6904 yyerror("Bad ext-community %s is %s", s, errstr);
6905 return (-1);
6906 }
6907 uval = strtonum(p, 0, USHRT_MAX, &errstr);
6908 if (errstr) {
6909 yyerror("Bad ext-community %s is %s", p, errstr);
6910 return (-1);
6911 }
6912 *v = uval | (uvalh << 16);
6913 break;
6914 case EXT_COMMUNITY_TRANS_IPV4:
6915 if (inet_aton(s, &ip) == 0) {
6916 yyerror("Bad ext-community %s not parseable", s);
6917 return (-1);
6918 }
6919 *v = ntohl(ip.s_addr);
6920 break;
6921 default:
6922 fatalx("%s: unexpected type %d", __func__, type);
6923 }
6924 return (type);
6925 }
6926
6927 int
parseextcommunity(struct community * c,char * t,char * s)6928 parseextcommunity(struct community *c, char *t, char *s)
6929 {
6930 const struct ext_comm_pairs *cp;
6931 char *p, *ep;
6932 u_int64_t ullval;
6933 u_int32_t uval, uval2, dflag1 = 0, dflag2 = 0;
6934 int type = 0, subtype = 0;
6935
6936 if (strcmp(t, "*") == 0 && strcmp(s, "*") == 0) {
6937 c->flags = COMMUNITY_TYPE_EXT;
6938 c->flags |= COMMUNITY_ANY << 24;
6939 return (0);
6940 }
6941 if (parsesubtype(t, &type, &subtype) == 0) {
6942 yyerror("Bad ext-community unknown type");
6943 return (-1);
6944 }
6945
6946 switch (type) {
6947 case EXT_COMMUNITY_TRANS_TWO_AS:
6948 case EXT_COMMUNITY_TRANS_FOUR_AS:
6949 case EXT_COMMUNITY_TRANS_IPV4:
6950 case -1:
6951 if (strcmp(s, "*") == 0) {
6952 dflag1 = COMMUNITY_ANY;
6953 break;
6954 }
6955 if ((p = strchr(s, ':')) == NULL) {
6956 yyerror("Bad ext-community %s", s);
6957 return (-1);
6958 }
6959 *p++ = '\0';
6960 if ((type = parseextvalue(type, s, &uval, &dflag1)) == -1)
6961 return (-1);
6962
6963 switch (type) {
6964 case EXT_COMMUNITY_TRANS_TWO_AS:
6965 if (getcommunity(p, 1, &uval2, &dflag2) == -1)
6966 return (-1);
6967 break;
6968 case EXT_COMMUNITY_TRANS_IPV4:
6969 case EXT_COMMUNITY_TRANS_FOUR_AS:
6970 if (getcommunity(p, 0, &uval2, &dflag2) == -1)
6971 return (-1);
6972 break;
6973 default:
6974 fatalx("parseextcommunity: unexpected result");
6975 }
6976
6977 c->data1 = uval;
6978 c->data2 = uval2;
6979 break;
6980 case EXT_COMMUNITY_TRANS_OPAQUE:
6981 case EXT_COMMUNITY_TRANS_EVPN:
6982 if (strcmp(s, "*") == 0) {
6983 dflag1 = COMMUNITY_ANY;
6984 break;
6985 }
6986 errno = 0;
6987 ullval = strtoull(s, &ep, 0);
6988 if (s[0] == '\0' || *ep != '\0') {
6989 yyerror("Bad ext-community bad value");
6990 return (-1);
6991 }
6992 if (errno == ERANGE && ullval > EXT_COMMUNITY_OPAQUE_MAX) {
6993 yyerror("Bad ext-community value too big");
6994 return (-1);
6995 }
6996 c->data1 = ullval >> 32;
6997 c->data2 = ullval;
6998 break;
6999 case EXT_COMMUNITY_NON_TRANS_OPAQUE:
7000 if (subtype == EXT_COMMUNITY_SUBTYPE_OVS) {
7001 if (strcmp(s, "valid") == 0) {
7002 c->data2 = EXT_COMMUNITY_OVS_VALID;
7003 break;
7004 } else if (strcmp(s, "invalid") == 0) {
7005 c->data2 = EXT_COMMUNITY_OVS_INVALID;
7006 break;
7007 } else if (strcmp(s, "not-found") == 0) {
7008 c->data2 = EXT_COMMUNITY_OVS_NOTFOUND;
7009 break;
7010 } else if (strcmp(s, "*") == 0) {
7011 dflag1 = COMMUNITY_ANY;
7012 break;
7013 }
7014 }
7015 yyerror("Bad ext-community %s", s);
7016 return (-1);
7017 }
7018
7019 c->data3 = type << 8 | subtype;
7020
7021 /* special handling of ext-community rt * since type is not known */
7022 if (dflag1 == COMMUNITY_ANY && type == -1) {
7023 c->flags = COMMUNITY_TYPE_EXT;
7024 c->flags |= dflag1 << 8;
7025 return (0);
7026 }
7027
7028 /* verify type/subtype combo */
7029 for (cp = iana_ext_comms; cp->subname != NULL; cp++) {
7030 if (cp->type == type && cp->subtype == subtype) {
7031 c->flags = COMMUNITY_TYPE_EXT;
7032 c->flags |= dflag1 << 8;
7033 c->flags |= dflag2 << 16;
7034 return (0);
7035 }
7036 }
7037
7038 yyerror("Bad ext-community bad format for type");
7039 return (-1);
7040 }
7041
7042 struct peer *
alloc_peer(void)7043 alloc_peer(void)
7044 {
7045 struct peer *p;
7046 u_int8_t i;
7047
7048 if ((p = calloc(1, sizeof(struct peer))) == NULL)
7049 fatal("new_peer");
7050
7051 /* some sane defaults */
7052 p->state = STATE_NONE;
7053 p->reconf_action = RECONF_REINIT;
7054 p->conf.distance = 1;
7055 p->conf.export_type = EXPORT_UNSET;
7056 p->conf.announce_capa = 1;
7057 for (i = 0; i < AID_MAX; i++)
7058 p->conf.capabilities.mp[i] = 0;
7059 p->conf.capabilities.refresh = 1;
7060 p->conf.capabilities.grestart.restart = 1;
7061 p->conf.capabilities.as4byte = 1;
7062 p->conf.local_as = conf->as;
7063 p->conf.local_short_as = conf->short_as;
7064
7065 if (conf->flags & BGPD_FLAG_DECISION_TRANS_AS)
7066 p->conf.flags |= PEERFLAG_TRANS_AS;
7067 if (conf->flags & BGPD_FLAG_DECISION_ALL_PATHS)
7068 p->conf.flags |= PEERFLAG_EVALUATE_ALL;
7069 if (conf->flags & BGPD_FLAG_NO_AS_SET)
7070 p->conf.flags |= PEERFLAG_NO_AS_SET;
7071
7072 return (p);
7073 }
7074
7075 struct peer *
new_peer(void)7076 new_peer(void)
7077 {
7078 struct peer *p;
7079
7080 p = alloc_peer();
7081
7082 if (curgroup != NULL) {
7083 memcpy(p, curgroup, sizeof(struct peer));
7084 if (strlcpy(p->conf.group, curgroup->conf.group,
7085 sizeof(p->conf.group)) >= sizeof(p->conf.group))
7086 fatalx("new_peer group strlcpy");
7087 if (strlcpy(p->conf.descr, curgroup->conf.descr,
7088 sizeof(p->conf.descr)) >= sizeof(p->conf.descr))
7089 fatalx("new_peer descr strlcpy");
7090 p->conf.groupid = curgroup->conf.id;
7091 }
7092 return (p);
7093 }
7094
7095 struct peer *
new_group(void)7096 new_group(void)
7097 {
7098 return (alloc_peer());
7099 }
7100
7101 int
add_mrtconfig(enum mrt_type type,char * name,int timeout,struct peer * p,char * rib)7102 add_mrtconfig(enum mrt_type type, char *name, int timeout, struct peer *p,
7103 char *rib)
7104 {
7105 struct mrt *m, *n;
7106
7107 LIST_FOREACH(m, conf->mrt, entry) {
7108 if ((rib && strcmp(rib, m->rib)) ||
7109 (!rib && *m->rib))
7110 continue;
7111 if (p == NULL) {
7112 if (m->peer_id != 0 || m->group_id != 0)
7113 continue;
7114 } else {
7115 if (m->peer_id != p->conf.id ||
7116 m->group_id != p->conf.groupid)
7117 continue;
7118 }
7119 if (m->type == type) {
7120 yyerror("only one mrtdump per type allowed.");
7121 return (-1);
7122 }
7123 }
7124
7125 if ((n = calloc(1, sizeof(struct mrt_config))) == NULL)
7126 fatal("add_mrtconfig");
7127
7128 n->type = type;
7129 if (strlcpy(MRT2MC(n)->name, name, sizeof(MRT2MC(n)->name)) >=
7130 sizeof(MRT2MC(n)->name)) {
7131 yyerror("filename \"%s\" too long: max %zu",
7132 name, sizeof(MRT2MC(n)->name) - 1);
7133 free(n);
7134 return (-1);
7135 }
7136 MRT2MC(n)->ReopenTimerInterval = timeout;
7137 if (p != NULL) {
7138 if (curgroup == p) {
7139 n->peer_id = 0;
7140 n->group_id = p->conf.id;
7141 } else {
7142 n->peer_id = p->conf.id;
7143 n->group_id = 0;
7144 }
7145 }
7146 if (rib) {
7147 if (!find_rib(rib)) {
7148 yyerror("rib \"%s\" does not exist.", rib);
7149 free(n);
7150 return (-1);
7151 }
7152 if (strlcpy(n->rib, rib, sizeof(n->rib)) >=
7153 sizeof(n->rib)) {
7154 yyerror("rib name \"%s\" too long: max %zu",
7155 name, sizeof(n->rib) - 1);
7156 free(n);
7157 return (-1);
7158 }
7159 }
7160
7161 LIST_INSERT_HEAD(conf->mrt, n, entry);
7162
7163 return (0);
7164 }
7165
7166 struct rde_rib *
add_rib(char * name)7167 add_rib(char *name)
7168 {
7169 struct rde_rib *rr;
7170
7171 if ((rr = find_rib(name)) == NULL) {
7172 if ((rr = calloc(1, sizeof(*rr))) == NULL) {
7173 log_warn("add_rib");
7174 return (NULL);
7175 }
7176 if (strlcpy(rr->name, name, sizeof(rr->name)) >=
7177 sizeof(rr->name)) {
7178 yyerror("rib name \"%s\" too long: max %zu",
7179 name, sizeof(rr->name) - 1);
7180 free(rr);
7181 return (NULL);
7182 }
7183 rr->flags = F_RIB_NOFIB;
7184 SIMPLEQ_INSERT_TAIL(&ribnames, rr, entry);
7185 }
7186 return (rr);
7187 }
7188
7189 struct rde_rib *
find_rib(char * name)7190 find_rib(char *name)
7191 {
7192 struct rde_rib *rr;
7193
7194 SIMPLEQ_FOREACH(rr, &ribnames, entry) {
7195 if (!strcmp(rr->name, name))
7196 return (rr);
7197 }
7198 return (NULL);
7199 }
7200
7201 int
rib_add_fib(struct rde_rib * rr,u_int rtableid)7202 rib_add_fib(struct rde_rib *rr, u_int rtableid)
7203 {
7204 u_int rdom;
7205
7206 if (ktable_exists(rtableid, &rdom) != 1) {
7207 yyerror("rtable id %u does not exist", rtableid);
7208 return (-1);
7209 }
7210 /*
7211 * conf->default_tableid is also a rdomain because that is checked
7212 * in init_config()
7213 */
7214 if (rdom != conf->default_tableid) {
7215 log_warnx("rtable %u does not belong to rdomain %u",
7216 rtableid, conf->default_tableid);
7217 return (-1);
7218 }
7219 rr->rtableid = rtableid;
7220 rr->flags &= ~F_RIB_NOFIB;
7221 return (0);
7222 }
7223
7224 struct prefixset *
find_prefixset(char * name,struct prefixset_head * p)7225 find_prefixset(char *name, struct prefixset_head *p)
7226 {
7227 struct prefixset *ps;
7228
7229 SIMPLEQ_FOREACH(ps, p, entry) {
7230 if (!strcmp(ps->name, name))
7231 return (ps);
7232 }
7233 return (NULL);
7234 }
7235
7236 int
get_id(struct peer * newpeer)7237 get_id(struct peer *newpeer)
7238 {
7239 static u_int32_t id = PEER_ID_STATIC_MIN;
7240 struct peer *p = NULL;
7241
7242 /* check if the peer already existed before */
7243 if (newpeer->conf.remote_addr.aid) {
7244 /* neighbor */
7245 if (cur_peers)
7246 RB_FOREACH(p, peer_head, cur_peers)
7247 if (p->conf.remote_masklen ==
7248 newpeer->conf.remote_masklen &&
7249 memcmp(&p->conf.remote_addr,
7250 &newpeer->conf.remote_addr,
7251 sizeof(p->conf.remote_addr)) == 0)
7252 break;
7253 if (p) {
7254 newpeer->conf.id = p->conf.id;
7255 return (0);
7256 }
7257 } else {
7258 /* group */
7259 if (cur_peers)
7260 RB_FOREACH(p, peer_head, cur_peers)
7261 if (strcmp(p->conf.group,
7262 newpeer->conf.group) == 0)
7263 break;
7264 if (p) {
7265 newpeer->conf.id = p->conf.groupid;
7266 return (0);
7267 }
7268 }
7269
7270 /* else new one */
7271 if (id < PEER_ID_STATIC_MAX) {
7272 newpeer->conf.id = id++;
7273 return (0);
7274 }
7275
7276 return (-1);
7277 }
7278
7279 int
merge_prefixspec(struct filter_prefix * p,struct filter_prefixlen * pl)7280 merge_prefixspec(struct filter_prefix *p, struct filter_prefixlen *pl)
7281 {
7282 u_int8_t max_len = 0;
7283
7284 switch (p->addr.aid) {
7285 case AID_INET:
7286 case AID_VPN_IPv4:
7287 max_len = 32;
7288 break;
7289 case AID_INET6:
7290 case AID_VPN_IPv6:
7291 max_len = 128;
7292 break;
7293 }
7294
7295 if (pl->op == OP_NONE) {
7296 p->len_min = p->len_max = p->len;
7297 return (0);
7298 }
7299
7300 if (pl->len_min == -1)
7301 pl->len_min = p->len;
7302 if (pl->len_max == -1)
7303 pl->len_max = max_len;
7304
7305 if (pl->len_max > max_len) {
7306 yyerror("prefixlen %d too big, limit %d",
7307 pl->len_max, max_len);
7308 return (-1);
7309 }
7310 if (pl->len_min > pl->len_max) {
7311 yyerror("prefixlen %d too big, limit %d",
7312 pl->len_min, pl->len_max);
7313 return (-1);
7314 }
7315 if (pl->len_min < p->len) {
7316 yyerror("prefixlen %d smaller than prefix, limit %d",
7317 pl->len_min, p->len);
7318 return (-1);
7319 }
7320
7321 p->op = pl->op;
7322 p->len_min = pl->len_min;
7323 p->len_max = pl->len_max;
7324 return (0);
7325 }
7326
7327 int
expand_rule(struct filter_rule * rule,struct filter_rib_l * rib,struct filter_peers_l * peer,struct filter_match_l * match,struct filter_set_head * set)7328 expand_rule(struct filter_rule *rule, struct filter_rib_l *rib,
7329 struct filter_peers_l *peer, struct filter_match_l *match,
7330 struct filter_set_head *set)
7331 {
7332 struct filter_rule *r;
7333 struct filter_rib_l *rb, *rbnext;
7334 struct filter_peers_l *p, *pnext;
7335 struct filter_prefix_l *prefix, *prefix_next;
7336 struct filter_as_l *a, *anext;
7337 struct filter_set *s;
7338
7339 rb = rib;
7340 do {
7341 p = peer;
7342 do {
7343 a = match->as_l;
7344 do {
7345 prefix = match->prefix_l;
7346 do {
7347 if ((r = calloc(1,
7348 sizeof(struct filter_rule))) ==
7349 NULL) {
7350 log_warn("expand_rule");
7351 return (-1);
7352 }
7353
7354 memcpy(r, rule, sizeof(struct filter_rule));
7355 memcpy(&r->match, match,
7356 sizeof(struct filter_match));
7357 filterset_copy(set, &r->set);
7358
7359 if (rb != NULL)
7360 strlcpy(r->rib, rb->name,
7361 sizeof(r->rib));
7362
7363 if (p != NULL)
7364 memcpy(&r->peer, &p->p,
7365 sizeof(struct filter_peers));
7366
7367 if (prefix != NULL)
7368 memcpy(&r->match.prefix, &prefix->p,
7369 sizeof(r->match.prefix));
7370
7371 if (a != NULL)
7372 memcpy(&r->match.as, &a->a,
7373 sizeof(struct filter_as));
7374
7375 TAILQ_INSERT_TAIL(filter_l, r, entry);
7376
7377 if (prefix != NULL)
7378 prefix = prefix->next;
7379 } while (prefix != NULL);
7380
7381 if (a != NULL)
7382 a = a->next;
7383 } while (a != NULL);
7384
7385 if (p != NULL)
7386 p = p->next;
7387 } while (p != NULL);
7388
7389 if (rb != NULL)
7390 rb = rb->next;
7391 } while (rb != NULL);
7392
7393 for (rb = rib; rb != NULL; rb = rbnext) {
7394 rbnext = rb->next;
7395 free(rb);
7396 }
7397
7398 for (p = peer; p != NULL; p = pnext) {
7399 pnext = p->next;
7400 free(p);
7401 }
7402
7403 for (a = match->as_l; a != NULL; a = anext) {
7404 anext = a->next;
7405 free(a);
7406 }
7407
7408 for (prefix = match->prefix_l; prefix != NULL; prefix = prefix_next) {
7409 prefix_next = prefix->next;
7410 free(prefix);
7411 }
7412
7413 if (set != NULL) {
7414 while ((s = TAILQ_FIRST(set)) != NULL) {
7415 TAILQ_REMOVE(set, s, entry);
7416 free(s);
7417 }
7418 free(set);
7419 }
7420
7421 return (0);
7422 }
7423
7424 int
str2key(char * s,char * dest,size_t max_len)7425 str2key(char *s, char *dest, size_t max_len)
7426 {
7427 unsigned i;
7428 char t[3];
7429
7430 if (strlen(s) / 2 > max_len) {
7431 yyerror("key too long");
7432 return (-1);
7433 }
7434
7435 if (strlen(s) % 2) {
7436 yyerror("key must be of even length");
7437 return (-1);
7438 }
7439
7440 for (i = 0; i < strlen(s) / 2; i++) {
7441 t[0] = s[2*i];
7442 t[1] = s[2*i + 1];
7443 t[2] = 0;
7444 if (!isxdigit(t[0]) || !isxdigit(t[1])) {
7445 yyerror("key must be specified in hex");
7446 return (-1);
7447 }
7448 dest[i] = strtoul(t, NULL, 16);
7449 }
7450
7451 return (0);
7452 }
7453
7454 int
neighbor_consistent(struct peer * p)7455 neighbor_consistent(struct peer *p)
7456 {
7457 struct bgpd_addr *local_addr;
7458 struct peer *xp;
7459
7460 switch (p->conf.remote_addr.aid) {
7461 case AID_INET:
7462 local_addr = &p->conf.local_addr_v4;
7463 break;
7464 case AID_INET6:
7465 local_addr = &p->conf.local_addr_v6;
7466 break;
7467 default:
7468 yyerror("Bad address family for remote-addr");
7469 return (-1);
7470 }
7471
7472 /* with any form of ipsec local-address is required */
7473 if ((p->conf.auth.method == AUTH_IPSEC_IKE_ESP ||
7474 p->conf.auth.method == AUTH_IPSEC_IKE_AH ||
7475 p->conf.auth.method == AUTH_IPSEC_MANUAL_ESP ||
7476 p->conf.auth.method == AUTH_IPSEC_MANUAL_AH) &&
7477 local_addr->aid == AID_UNSPEC) {
7478 yyerror("neighbors with any form of IPsec configured "
7479 "need local-address to be specified");
7480 return (-1);
7481 }
7482
7483 /* with static keying we need both directions */
7484 if ((p->conf.auth.method == AUTH_IPSEC_MANUAL_ESP ||
7485 p->conf.auth.method == AUTH_IPSEC_MANUAL_AH) &&
7486 (!p->conf.auth.spi_in || !p->conf.auth.spi_out)) {
7487 yyerror("with manual keyed IPsec, SPIs and keys "
7488 "for both directions are required");
7489 return (-1);
7490 }
7491
7492 if (!conf->as) {
7493 yyerror("AS needs to be given before neighbor definitions");
7494 return (-1);
7495 }
7496
7497 /* set default values if they where undefined */
7498 p->conf.ebgp = (p->conf.remote_as != conf->as);
7499 if (p->conf.enforce_as == ENFORCE_AS_UNDEF)
7500 p->conf.enforce_as = p->conf.ebgp ?
7501 ENFORCE_AS_ON : ENFORCE_AS_OFF;
7502 if (p->conf.enforce_local_as == ENFORCE_AS_UNDEF)
7503 p->conf.enforce_local_as = ENFORCE_AS_ON;
7504
7505 if (p->conf.remote_as == 0 && !p->conf.template) {
7506 yyerror("peer AS may not be zero");
7507 return (-1);
7508 }
7509
7510 /* EBGP neighbors are not allowed in route reflector clusters */
7511 if (p->conf.reflector_client && p->conf.ebgp) {
7512 yyerror("EBGP neighbors are not allowed in route "
7513 "reflector clusters");
7514 return (-1);
7515 }
7516
7517 /* check for duplicate peer definitions */
7518 RB_FOREACH(xp, peer_head, new_peers)
7519 if (xp->conf.remote_masklen ==
7520 p->conf.remote_masklen &&
7521 memcmp(&xp->conf.remote_addr,
7522 &p->conf.remote_addr,
7523 sizeof(p->conf.remote_addr)) == 0)
7524 break;
7525 if (xp != NULL) {
7526 char *descr = log_fmt_peer(&p->conf);
7527 yyerror("duplicate %s", descr);
7528 free(descr);
7529 return (-1);
7530 }
7531
7532 return (0);
7533 }
7534
7535 static void
filterset_add(struct filter_set_head * sh,struct filter_set * s)7536 filterset_add(struct filter_set_head *sh, struct filter_set *s)
7537 {
7538 struct filter_set *t;
7539
7540 TAILQ_FOREACH(t, sh, entry) {
7541 if (s->type < t->type) {
7542 TAILQ_INSERT_BEFORE(t, s, entry);
7543 return;
7544 }
7545 if (s->type == t->type) {
7546 switch (s->type) {
7547 case ACTION_SET_COMMUNITY:
7548 case ACTION_DEL_COMMUNITY:
7549 switch (cmpcommunity(&s->action.community,
7550 &t->action.community)) {
7551 case -1:
7552 TAILQ_INSERT_BEFORE(t, s, entry);
7553 return;
7554 case 0:
7555 break;
7556 case 1:
7557 continue;
7558 }
7559 break;
7560 case ACTION_SET_NEXTHOP:
7561 /* only last nexthop per AF matters */
7562 if (s->action.nexthop.aid <
7563 t->action.nexthop.aid) {
7564 TAILQ_INSERT_BEFORE(t, s, entry);
7565 return;
7566 } else if (s->action.nexthop.aid ==
7567 t->action.nexthop.aid) {
7568 t->action.nexthop = s->action.nexthop;
7569 break;
7570 }
7571 continue;
7572 case ACTION_SET_NEXTHOP_BLACKHOLE:
7573 case ACTION_SET_NEXTHOP_REJECT:
7574 case ACTION_SET_NEXTHOP_NOMODIFY:
7575 case ACTION_SET_NEXTHOP_SELF:
7576 /* set it only once */
7577 break;
7578 case ACTION_SET_LOCALPREF:
7579 case ACTION_SET_MED:
7580 case ACTION_SET_WEIGHT:
7581 /* only last set matters */
7582 t->action.metric = s->action.metric;
7583 break;
7584 case ACTION_SET_RELATIVE_LOCALPREF:
7585 case ACTION_SET_RELATIVE_MED:
7586 case ACTION_SET_RELATIVE_WEIGHT:
7587 /* sum all relative numbers */
7588 t->action.relative += s->action.relative;
7589 break;
7590 case ACTION_SET_ORIGIN:
7591 /* only last set matters */
7592 t->action.origin = s->action.origin;
7593 break;
7594 case ACTION_PFTABLE:
7595 /* only last set matters */
7596 strlcpy(t->action.pftable, s->action.pftable,
7597 sizeof(t->action.pftable));
7598 break;
7599 case ACTION_RTLABEL:
7600 /* only last set matters */
7601 strlcpy(t->action.rtlabel, s->action.rtlabel,
7602 sizeof(t->action.rtlabel));
7603 break;
7604 default:
7605 break;
7606 }
7607 free(s);
7608 return;
7609 }
7610 }
7611
7612 TAILQ_INSERT_TAIL(sh, s, entry);
7613 }
7614
7615 int
merge_filterset(struct filter_set_head * sh,struct filter_set * s)7616 merge_filterset(struct filter_set_head *sh, struct filter_set *s)
7617 {
7618 struct filter_set *t;
7619
7620 TAILQ_FOREACH(t, sh, entry) {
7621 /*
7622 * need to cycle across the full list because even
7623 * if types are not equal filterset_cmp() may return 0.
7624 */
7625 if (filterset_cmp(s, t) == 0) {
7626 if (s->type == ACTION_SET_COMMUNITY)
7627 yyerror("community is already set");
7628 else if (s->type == ACTION_DEL_COMMUNITY)
7629 yyerror("community will already be deleted");
7630 else
7631 yyerror("redefining set parameter %s",
7632 filterset_name(s->type));
7633 return (-1);
7634 }
7635 }
7636
7637 filterset_add(sh, s);
7638 return (0);
7639 }
7640
7641 static int
filter_equal(struct filter_rule * fa,struct filter_rule * fb)7642 filter_equal(struct filter_rule *fa, struct filter_rule *fb)
7643 {
7644 if (fa == NULL || fb == NULL)
7645 return 0;
7646 if (fa->action != fb->action || fa->quick != fb->quick ||
7647 fa->dir != fb->dir)
7648 return 0;
7649 if (memcmp(&fa->peer, &fb->peer, sizeof(fa->peer)))
7650 return 0;
7651 if (memcmp(&fa->match, &fb->match, sizeof(fa->match)))
7652 return 0;
7653
7654 return 1;
7655 }
7656
7657 /* do a basic optimization by folding equal rules together */
7658 void
optimize_filters(struct filter_head * fh)7659 optimize_filters(struct filter_head *fh)
7660 {
7661 struct filter_rule *r, *nr;
7662
7663 TAILQ_FOREACH_SAFE(r, fh, entry, nr) {
7664 while (filter_equal(r, nr)) {
7665 struct filter_set *t;
7666
7667 while ((t = TAILQ_FIRST(&nr->set)) != NULL) {
7668 TAILQ_REMOVE(&nr->set, t, entry);
7669 filterset_add(&r->set, t);
7670 }
7671
7672 TAILQ_REMOVE(fh, nr, entry);
7673 free(nr);
7674 nr = TAILQ_NEXT(r, entry);
7675 }
7676 }
7677 }
7678
7679 struct filter_rule *
get_rule(enum action_types type)7680 get_rule(enum action_types type)
7681 {
7682 struct filter_rule *r;
7683 int out;
7684
7685 switch (type) {
7686 case ACTION_SET_PREPEND_SELF:
7687 case ACTION_SET_NEXTHOP_NOMODIFY:
7688 case ACTION_SET_NEXTHOP_SELF:
7689 out = 1;
7690 break;
7691 default:
7692 out = 0;
7693 break;
7694 }
7695 r = (curpeer == curgroup) ? curgroup_filter[out] : curpeer_filter[out];
7696 if (r == NULL) {
7697 if ((r = calloc(1, sizeof(struct filter_rule))) == NULL)
7698 fatal(NULL);
7699 r->quick = 0;
7700 r->dir = out ? DIR_OUT : DIR_IN;
7701 r->action = ACTION_NONE;
7702 TAILQ_INIT(&r->set);
7703 if (curpeer == curgroup) {
7704 /* group */
7705 r->peer.groupid = curgroup->conf.id;
7706 curgroup_filter[out] = r;
7707 } else {
7708 /* peer */
7709 r->peer.peerid = curpeer->conf.id;
7710 curpeer_filter[out] = r;
7711 }
7712 }
7713 return (r);
7714 }
7715
7716 struct set_table *curset;
7717 static int
new_as_set(char * name)7718 new_as_set(char *name)
7719 {
7720 struct as_set *aset;
7721
7722 if (as_sets_lookup(&conf->as_sets, name) != NULL) {
7723 yyerror("as-set \"%s\" already exists", name);
7724 return -1;
7725 }
7726
7727 aset = as_sets_new(&conf->as_sets, name, 0, sizeof(u_int32_t));
7728 if (aset == NULL)
7729 fatal(NULL);
7730
7731 curset = aset->set;
7732 return 0;
7733 }
7734
7735 static void
add_as_set(u_int32_t as)7736 add_as_set(u_int32_t as)
7737 {
7738 if (curset == NULL)
7739 fatalx("%s: bad mojo jojo", __func__);
7740
7741 if (set_add(curset, &as, 1) != 0)
7742 fatal(NULL);
7743 }
7744
7745 static void
done_as_set(void)7746 done_as_set(void)
7747 {
7748 curset = NULL;
7749 }
7750
7751 static struct prefixset *
new_prefix_set(char * name,int is_roa)7752 new_prefix_set(char *name, int is_roa)
7753 {
7754 const char *type = "prefix-set";
7755 struct prefixset_head *sets = &conf->prefixsets;
7756 struct prefixset *pset;
7757
7758 if (is_roa) {
7759 type = "origin-set";
7760 sets = &conf->originsets;
7761 }
7762
7763 if (find_prefixset(name, sets) != NULL) {
7764 yyerror("%s \"%s\" already exists", type, name);
7765 return NULL;
7766 }
7767 if ((pset = calloc(1, sizeof(*pset))) == NULL)
7768 fatal("prefixset");
7769 if (strlcpy(pset->name, name, sizeof(pset->name)) >=
7770 sizeof(pset->name)) {
7771 yyerror("%s \"%s\" too long: max %zu", type,
7772 name, sizeof(pset->name) - 1);
7773 free(pset);
7774 return NULL;
7775 }
7776 RB_INIT(&pset->psitems);
7777 RB_INIT(&pset->roaitems);
7778 return pset;
7779 }
7780
7781 static void
add_roa_set(struct prefixset_item * npsi,u_int32_t as,u_int8_t max)7782 add_roa_set(struct prefixset_item *npsi, u_int32_t as, u_int8_t max)
7783 {
7784 struct roa *roa, *r;
7785
7786 if ((roa = calloc(1, sizeof(*roa))) == NULL)
7787 fatal("add_roa_set");
7788
7789 roa->aid = npsi->p.addr.aid;
7790 roa->prefixlen = npsi->p.len;
7791 roa->maxlen = max;
7792 roa->asnum = as;
7793 switch (roa->aid) {
7794 case AID_INET:
7795 roa->prefix.inet = npsi->p.addr.v4;
7796 break;
7797 case AID_INET6:
7798 roa->prefix.inet6 = npsi->p.addr.v6;
7799 break;
7800 default:
7801 fatalx("Bad address family for roa_set address");
7802 }
7803
7804 r = RB_INSERT(roa_tree, curroatree, roa);
7805 if (r != NULL)
7806 /* just ignore duplicates */
7807 free(roa);
7808 }
7809
7810 static struct rtr_config *
get_rtr(struct bgpd_addr * addr)7811 get_rtr(struct bgpd_addr *addr)
7812 {
7813 struct rtr_config *n;
7814
7815 n = calloc(1, sizeof(*n));
7816 if (n == NULL) {
7817 yyerror("out of memory");
7818 return NULL;
7819 }
7820
7821 n->remote_addr = *addr;
7822 strlcpy(n->descr, log_addr(addr), sizeof(currtr->descr));
7823
7824 return n;
7825 }
7826
7827 static int
insert_rtr(struct rtr_config * new)7828 insert_rtr(struct rtr_config *new)
7829 {
7830 static uint32_t id;
7831 struct rtr_config *r;
7832
7833 if (id == UINT32_MAX) {
7834 yyerror("out of rtr session IDs");
7835 return -1;
7836 }
7837
7838 SIMPLEQ_FOREACH(r, &conf->rtrs, entry)
7839 if (memcmp(&r->remote_addr, &new->remote_addr,
7840 sizeof(r->remote_addr)) == 0 &&
7841 r->remote_port == new->remote_port) {
7842 yyerror("duplicate rtr session to %s:%u",
7843 log_addr(&new->remote_addr), new->remote_port);
7844 return -1;
7845 }
7846
7847 if (cur_rtrs)
7848 SIMPLEQ_FOREACH(r, cur_rtrs, entry)
7849 if (memcmp(&r->remote_addr, &new->remote_addr,
7850 sizeof(r->remote_addr)) == 0 &&
7851 r->remote_port == new->remote_port) {
7852 new->id = r->id;
7853 break;
7854 }
7855
7856 if (new->id == 0)
7857 new->id = ++id;
7858
7859 SIMPLEQ_INSERT_TAIL(&conf->rtrs, currtr, entry);
7860
7861 return 0;
7862 }
7863