blob: d23717687078ba5266358bb8ee492854779a08ac [file] [log] [blame]
Chung-yih Wang0a1907d2009-04-23 12:26:00 +08001/* A Bison parser, made by GNU Bison 2.3. */
2
3/* Skeleton implementation for Bison's Yacc-like parsers in C
4
5 Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6 Free Software Foundation, 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 2, or (at your option)
11 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, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
22
23/* As a special exception, you may create a larger work that contains
24 part or all of the Bison parser skeleton and distribute that work
25 under terms of your choice, so long as that work isn't itself a
26 parser generator using the skeleton or a modified version thereof
27 as a parser skeleton. Alternatively, if you modify or redistribute
28 the parser skeleton itself, you may (at your option) remove this
29 special exception, which will cause the skeleton and the resulting
30 Bison output files to be licensed under the GNU General Public
31 License without this special exception.
32
33 This special exception was added by the Free Software Foundation in
34 version 2.2 of Bison. */
35
36/* C LALR(1) parser skeleton written by Richard Stallman, by
37 simplifying the original so-called "semantic" parser. */
38
39/* All symbols defined below should begin with yy or YY, to avoid
40 infringing on user name space. This should be done even for local
41 variables, as they might otherwise be expanded by user macros.
42 There are some unavoidable exceptions within include files to
43 define necessary library symbols; they are noted "INFRINGES ON
44 USER NAME SPACE" below. */
45
46/* Identify Bison output. */
47#define YYBISON 1
48
49/* Bison version. */
50#define YYBISON_VERSION "2.3"
51
52/* Skeleton name. */
53#define YYSKELETON_NAME "yacc.c"
54
55/* Pure parsers. */
56#define YYPURE 0
57
58/* Using locations. */
59#define YYLSP_NEEDED 0
60
61/* Substitute the variable and function names. */
62#define yyparse __libipsecparse
63#define yylex __libipseclex
64#define yyerror __libipsecerror
65#define yylval __libipseclval
66#define yychar __libipsecchar
67#define yydebug __libipsecdebug
68#define yynerrs __libipsecnerrs
69
70
71/* Tokens. */
72#ifndef YYTOKENTYPE
73# define YYTOKENTYPE
74 /* Put the tokens into the symbol table, so that GDB and other debuggers
75 know about them. */
76 enum yytokentype {
77 DIR = 258,
78 PRIORITY = 259,
79 PLUS = 260,
80 PRIO_BASE = 261,
81 PRIO_OFFSET = 262,
82 ACTION = 263,
83 PROTOCOL = 264,
84 MODE = 265,
85 LEVEL = 266,
86 LEVEL_SPECIFY = 267,
87 IPADDRESS = 268,
88 PORT = 269,
89 ME = 270,
90 ANY = 271,
91 SLASH = 272,
92 HYPHEN = 273
93 };
94#endif
95/* Tokens. */
96#define DIR 258
97#define PRIORITY 259
98#define PLUS 260
99#define PRIO_BASE 261
100#define PRIO_OFFSET 262
101#define ACTION 263
102#define PROTOCOL 264
103#define MODE 265
104#define LEVEL 266
105#define LEVEL_SPECIFY 267
106#define IPADDRESS 268
107#define PORT 269
108#define ME 270
109#define ANY 271
110#define SLASH 272
111#define HYPHEN 273
112
113
114
115
116/* Copy the first part of user declarations. */
117#line 65 "policy_parse.y"
118
119#ifdef HAVE_CONFIG_H
120#include "config.h"
121#endif
122
123#include <sys/types.h>
124#include <sys/param.h>
125#include <sys/socket.h>
126
127#include <netinet/in.h>
128#include PATH_IPSEC_H
129
130#include <stdlib.h>
131#include <stdio.h>
132#include <string.h>
133#include <netdb.h>
134
135#include <errno.h>
136
137#include "config.h"
138
139#include "ipsec_strerror.h"
140#include "libpfkey.h"
141
142#ifndef INT32_MAX
143#define INT32_MAX (0xffffffff)
144#endif
145
146#ifndef INT32_MIN
147#define INT32_MIN (-INT32_MAX-1)
148#endif
149
150#define ATOX(c) \
151 (isdigit(c) ? (c - '0') : (isupper(c) ? (c - 'A' + 10) : (c - 'a' + 10) ))
152
153static u_int8_t *pbuf = NULL; /* sadb_x_policy buffer */
154static int tlen = 0; /* total length of pbuf */
155static int offset = 0; /* offset of pbuf */
156static int p_dir, p_type, p_protocol, p_mode, p_level, p_reqid;
157static u_int32_t p_priority = 0;
158static long p_priority_offset = 0;
159static struct sockaddr *p_src = NULL;
160static struct sockaddr *p_dst = NULL;
161
162struct _val;
163extern void yyerror __P((char *msg));
164static struct sockaddr *parse_sockaddr __P((struct _val *addrbuf,
165 struct _val *portbuf));
166static int rule_check __P((void));
167static int init_x_policy __P((void));
168static int set_x_request __P((struct sockaddr *, struct sockaddr *));
169static int set_sockaddr __P((struct sockaddr *));
170static void policy_parse_request_init __P((void));
171static void *policy_parse __P((const char *, int));
172
173extern void __policy__strbuffer__init__ __P((const char *));
174extern void __policy__strbuffer__free__ __P((void));
175extern int yyparse __P((void));
176extern int yylex __P((void));
177
178extern char *__libipsectext; /*XXX*/
179
180
181
182/* Enabling traces. */
183#ifndef YYDEBUG
184# define YYDEBUG 0
185#endif
186
187/* Enabling verbose error messages. */
188#ifdef YYERROR_VERBOSE
189# undef YYERROR_VERBOSE
190# define YYERROR_VERBOSE 1
191#else
192# define YYERROR_VERBOSE 0
193#endif
194
195/* Enabling the token table. */
196#ifndef YYTOKEN_TABLE
197# define YYTOKEN_TABLE 0
198#endif
199
200#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
201typedef union YYSTYPE
202#line 129 "policy_parse.y"
203{
204 u_int num;
205 u_int32_t num32;
206 struct _val {
207 int len;
208 char *buf;
209 } val;
210}
211/* Line 187 of yacc.c. */
212#line 213 "policy_parse.c"
213 YYSTYPE;
214# define yystype YYSTYPE /* obsolescent; will be withdrawn */
215# define YYSTYPE_IS_DECLARED 1
216# define YYSTYPE_IS_TRIVIAL 1
217#endif
218
219
220
221/* Copy the second part of user declarations. */
222
223
224/* Line 216 of yacc.c. */
225#line 226 "policy_parse.c"
226
227#ifdef short
228# undef short
229#endif
230
231#ifdef YYTYPE_UINT8
232typedef YYTYPE_UINT8 yytype_uint8;
233#else
234typedef unsigned char yytype_uint8;
235#endif
236
237#ifdef YYTYPE_INT8
238typedef YYTYPE_INT8 yytype_int8;
239#elif (defined __STDC__ || defined __C99__FUNC__ \
240 || defined __cplusplus || defined _MSC_VER)
241typedef signed char yytype_int8;
242#else
243typedef short int yytype_int8;
244#endif
245
246#ifdef YYTYPE_UINT16
247typedef YYTYPE_UINT16 yytype_uint16;
248#else
249typedef unsigned short int yytype_uint16;
250#endif
251
252#ifdef YYTYPE_INT16
253typedef YYTYPE_INT16 yytype_int16;
254#else
255typedef short int yytype_int16;
256#endif
257
258#ifndef YYSIZE_T
259# ifdef __SIZE_TYPE__
260# define YYSIZE_T __SIZE_TYPE__
261# elif defined size_t
262# define YYSIZE_T size_t
263# elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
264 || defined __cplusplus || defined _MSC_VER)
265# include <stddef.h> /* INFRINGES ON USER NAME SPACE */
266# define YYSIZE_T size_t
267# else
268# define YYSIZE_T unsigned int
269# endif
270#endif
271
272#define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
273
274#ifndef YY_
275# if YYENABLE_NLS
276# if ENABLE_NLS
277# include <libintl.h> /* INFRINGES ON USER NAME SPACE */
278# define YY_(msgid) dgettext ("bison-runtime", msgid)
279# endif
280# endif
281# ifndef YY_
282# define YY_(msgid) msgid
283# endif
284#endif
285
286/* Suppress unused-variable warnings by "using" E. */
287#if ! defined lint || defined __GNUC__
288# define YYUSE(e) ((void) (e))
289#else
290# define YYUSE(e) /* empty */
291#endif
292
293/* Identity function, used to suppress warnings about constant conditions. */
294#ifndef lint
295# define YYID(n) (n)
296#else
297#if (defined __STDC__ || defined __C99__FUNC__ \
298 || defined __cplusplus || defined _MSC_VER)
299static int
300YYID (int i)
301#else
302static int
303YYID (i)
304 int i;
305#endif
306{
307 return i;
308}
309#endif
310
311#if ! defined yyoverflow || YYERROR_VERBOSE
312
313/* The parser invokes alloca or malloc; define the necessary symbols. */
314
315# ifdef YYSTACK_USE_ALLOCA
316# if YYSTACK_USE_ALLOCA
317# ifdef __GNUC__
318# define YYSTACK_ALLOC __builtin_alloca
319# elif defined __BUILTIN_VA_ARG_INCR
320# include <alloca.h> /* INFRINGES ON USER NAME SPACE */
321# elif defined _AIX
322# define YYSTACK_ALLOC __alloca
323# elif defined _MSC_VER
324# include <malloc.h> /* INFRINGES ON USER NAME SPACE */
325# define alloca _alloca
326# else
327# define YYSTACK_ALLOC alloca
328# if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
329 || defined __cplusplus || defined _MSC_VER)
330# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
331# ifndef _STDLIB_H
332# define _STDLIB_H 1
333# endif
334# endif
335# endif
336# endif
337# endif
338
339# ifdef YYSTACK_ALLOC
340 /* Pacify GCC's `empty if-body' warning. */
341# define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
342# ifndef YYSTACK_ALLOC_MAXIMUM
343 /* The OS might guarantee only one guard page at the bottom of the stack,
344 and a page size can be as small as 4096 bytes. So we cannot safely
345 invoke alloca (N) if N exceeds 4096. Use a slightly smaller number
346 to allow for a few compiler-allocated temporary stack slots. */
347# define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
348# endif
349# else
350# define YYSTACK_ALLOC YYMALLOC
351# define YYSTACK_FREE YYFREE
352# ifndef YYSTACK_ALLOC_MAXIMUM
353# define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
354# endif
355# if (defined __cplusplus && ! defined _STDLIB_H \
356 && ! ((defined YYMALLOC || defined malloc) \
357 && (defined YYFREE || defined free)))
358# include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
359# ifndef _STDLIB_H
360# define _STDLIB_H 1
361# endif
362# endif
363# ifndef YYMALLOC
364# define YYMALLOC malloc
365# if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
366 || defined __cplusplus || defined _MSC_VER)
367void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
368# endif
369# endif
370# ifndef YYFREE
371# define YYFREE free
372# if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
373 || defined __cplusplus || defined _MSC_VER)
374void free (void *); /* INFRINGES ON USER NAME SPACE */
375# endif
376# endif
377# endif
378#endif /* ! defined yyoverflow || YYERROR_VERBOSE */
379
380
381#if (! defined yyoverflow \
382 && (! defined __cplusplus \
383 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
384
385/* A type that is properly aligned for any stack member. */
386union yyalloc
387{
388 yytype_int16 yyss;
389 YYSTYPE yyvs;
390 };
391
392/* The size of the maximum gap between one aligned stack and the next. */
393# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
394
395/* The size of an array large to enough to hold all stacks, each with
396 N elements. */
397# define YYSTACK_BYTES(N) \
398 ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
399 + YYSTACK_GAP_MAXIMUM)
400
401/* Copy COUNT objects from FROM to TO. The source and destination do
402 not overlap. */
403# ifndef YYCOPY
404# if defined __GNUC__ && 1 < __GNUC__
405# define YYCOPY(To, From, Count) \
406 __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
407# else
408# define YYCOPY(To, From, Count) \
409 do \
410 { \
411 YYSIZE_T yyi; \
412 for (yyi = 0; yyi < (Count); yyi++) \
413 (To)[yyi] = (From)[yyi]; \
414 } \
415 while (YYID (0))
416# endif
417# endif
418
419/* Relocate STACK from its old location to the new one. The
420 local variables YYSIZE and YYSTACKSIZE give the old and new number of
421 elements in the stack, and YYPTR gives the new location of the
422 stack. Advance YYPTR to a properly aligned location for the next
423 stack. */
424# define YYSTACK_RELOCATE(Stack) \
425 do \
426 { \
427 YYSIZE_T yynewbytes; \
428 YYCOPY (&yyptr->Stack, Stack, yysize); \
429 Stack = &yyptr->Stack; \
430 yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
431 yyptr += yynewbytes / sizeof (*yyptr); \
432 } \
433 while (YYID (0))
434
435#endif
436
437/* YYFINAL -- State number of the termination state. */
438#define YYFINAL 5
439/* YYLAST -- Last index in YYTABLE. */
440#define YYLAST 48
441
442/* YYNTOKENS -- Number of terminals. */
443#define YYNTOKENS 19
444/* YYNNTS -- Number of nonterminals. */
445#define YYNNTS 16
446/* YYNRULES -- Number of rules. */
447#define YYNRULES 34
448/* YYNRULES -- Number of states. */
449#define YYNSTATES 60
450
451/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */
452#define YYUNDEFTOK 2
453#define YYMAXUTOK 273
454
455#define YYTRANSLATE(YYX) \
456 ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
457
458/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
459static const yytype_uint8 yytranslate[] =
460{
461 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
462 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
463 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
464 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
465 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
466 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
467 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
468 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
469 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
470 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
471 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
472 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
473 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
474 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
475 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
476 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
477 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
478 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
479 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
480 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
481 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
482 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
483 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
484 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
485 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
486 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
487 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,
488 15, 16, 17, 18
489};
490
491#if YYDEBUG
492/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
493 YYRHS. */
494static const yytype_uint8 yyprhs[] =
495{
496 0, 0, 3, 4, 9, 10, 17, 18, 26, 27,
497 34, 35, 44, 45, 54, 56, 57, 60, 68, 75,
498 81, 86, 93, 97, 100, 102, 104, 106, 108, 110,
499 111, 116, 117, 124, 128
500};
501
502/* YYRHS -- A `-1'-separated list of the rules' RHS. */
503static const yytype_int8 yyrhs[] =
504{
505 20, 0, -1, -1, 3, 8, 21, 27, -1, -1,
506 3, 4, 7, 8, 22, 27, -1, -1, 3, 4,
507 18, 7, 8, 23, 27, -1, -1, 3, 4, 6,
508 8, 24, 27, -1, -1, 3, 4, 6, 5, 7,
509 8, 25, 27, -1, -1, 3, 4, 6, 18, 7,
510 8, 26, 27, -1, 3, -1, -1, 27, 28, -1,
511 29, 17, 30, 17, 32, 17, 31, -1, 29, 17,
512 30, 17, 32, 17, -1, 29, 17, 30, 17, 32,
513 -1, 29, 17, 30, 17, -1, 29, 17, 30, 17,
514 17, 31, -1, 29, 17, 30, -1, 29, 17, -1,
515 29, -1, 9, -1, 10, -1, 11, -1, 12, -1,
516 -1, 13, 33, 18, 13, -1, -1, 13, 14, 34,
517 18, 13, 14, -1, 15, 18, 16, -1, 16, 18,
518 15, -1
519};
520
521/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
522static const yytype_uint16 yyrline[] =
523{
524 0, 151, 151, 150, 166, 165, 202, 201, 224, 223,
525 235, 234, 257, 256, 278, 290, 292, 304, 305, 306,
526 307, 308, 309, 310, 314, 321, 325, 329, 333, 340,
527 340, 351, 351, 362, 368
528};
529#endif
530
531#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
532/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
533 First, the terminals, then, starting at YYNTOKENS, nonterminals. */
534static const char *const yytname[] =
535{
536 "$end", "error", "$undefined", "DIR", "PRIORITY", "PLUS", "PRIO_BASE",
537 "PRIO_OFFSET", "ACTION", "PROTOCOL", "MODE", "LEVEL", "LEVEL_SPECIFY",
538 "IPADDRESS", "PORT", "ME", "ANY", "SLASH", "HYPHEN", "$accept",
539 "policy_spec", "@1", "@2", "@3", "@4", "@5", "@6", "rules", "rule",
540 "protocol", "mode", "level", "addresses", "@7", "@8", 0
541};
542#endif
543
544# ifdef YYPRINT
545/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
546 token YYLEX-NUM. */
547static const yytype_uint16 yytoknum[] =
548{
549 0, 256, 257, 258, 259, 260, 261, 262, 263, 264,
550 265, 266, 267, 268, 269, 270, 271, 272, 273
551};
552# endif
553
554/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
555static const yytype_uint8 yyr1[] =
556{
557 0, 19, 21, 20, 22, 20, 23, 20, 24, 20,
558 25, 20, 26, 20, 20, 27, 27, 28, 28, 28,
559 28, 28, 28, 28, 28, 29, 30, 31, 31, 33,
560 32, 34, 32, 32, 32
561};
562
563/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
564static const yytype_uint8 yyr2[] =
565{
566 0, 2, 0, 4, 0, 6, 0, 7, 0, 6,
567 0, 8, 0, 8, 1, 0, 2, 7, 6, 5,
568 4, 6, 3, 2, 1, 1, 1, 1, 1, 0,
569 4, 0, 6, 3, 3
570};
571
572/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
573 STATE-NUM when YYTABLE doesn't specify something else to do. Zero
574 means the default is an error. */
575static const yytype_uint8 yydefact[] =
576{
577 0, 14, 0, 0, 2, 1, 0, 0, 0, 15,
578 0, 8, 0, 4, 0, 3, 0, 15, 0, 15,
579 6, 25, 16, 24, 10, 9, 12, 5, 15, 23,
580 15, 15, 7, 26, 22, 11, 13, 20, 29, 0,
581 0, 0, 19, 31, 0, 0, 0, 27, 28, 21,
582 18, 0, 0, 33, 34, 17, 0, 30, 0, 32
583};
584
585/* YYDEFGOTO[NTERM-NUM]. */
586static const yytype_int8 yydefgoto[] =
587{
588 -1, 2, 9, 19, 28, 17, 30, 31, 15, 22,
589 23, 34, 49, 42, 44, 51
590};
591
592/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
593 STATE-NUM. */
594#define YYPACT_NINF -18
595static const yytype_int8 yypact[] =
596{
597 6, -3, 4, 1, -18, -18, -2, 2, 8, -18,
598 10, -18, 18, -18, 19, 3, 20, -18, 21, -18,
599 -18, -18, -18, 9, -18, 3, -18, 3, -18, 22,
600 -18, -18, 3, -18, 13, 3, 3, 5, 17, 15,
601 16, 12, 23, -18, 24, 25, 28, -18, -18, -18,
602 12, 26, 32, -18, -18, -18, 33, -18, 34, -18
603};
604
605/* YYPGOTO[NTERM-NUM]. */
606static const yytype_int8 yypgoto[] =
607{
608 -18, -18, -18, -18, -18, -18, -18, -18, -17, -18,
609 -18, -18, -15, -18, -18, -18
610};
611
612/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
613 positive, shift that token. If negative, reduce the rule which
614 number is the opposite. If zero, do what YYDEFACT says.
615 If YYTABLE_NINF, syntax error. */
616#define YYTABLE_NINF -1
617static const yytype_uint8 yytable[] =
618{
619 25, 3, 27, 10, 5, 4, 11, 6, 7, 1,
620 13, 32, 21, 35, 36, 14, 12, 16, 38, 8,
621 39, 40, 41, 47, 48, 18, 29, 20, 24, 26,
622 37, 43, 33, 45, 46, 55, 0, 0, 0, 0,
623 50, 53, 52, 54, 56, 57, 58, 0, 59
624};
625
626static const yytype_int8 yycheck[] =
627{
628 17, 4, 19, 5, 0, 8, 8, 6, 7, 3,
629 8, 28, 9, 30, 31, 7, 18, 7, 13, 18,
630 15, 16, 17, 11, 12, 7, 17, 8, 8, 8,
631 17, 14, 10, 18, 18, 50, -1, -1, -1, -1,
632 17, 16, 18, 15, 18, 13, 13, -1, 14
633};
634
635/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
636 symbol of state STATE-NUM. */
637static const yytype_uint8 yystos[] =
638{
639 0, 3, 20, 4, 8, 0, 6, 7, 18, 21,
640 5, 8, 18, 8, 7, 27, 7, 24, 7, 22,
641 8, 9, 28, 29, 8, 27, 8, 27, 23, 17,
642 25, 26, 27, 10, 30, 27, 27, 17, 13, 15,
643 16, 17, 32, 14, 33, 18, 18, 11, 12, 31,
644 17, 34, 18, 16, 15, 31, 18, 13, 13, 14
645};
646
647#define yyerrok (yyerrstatus = 0)
648#define yyclearin (yychar = YYEMPTY)
649#define YYEMPTY (-2)
650#define YYEOF 0
651
652#define YYACCEPT goto yyacceptlab
653#define YYABORT goto yyabortlab
654#define YYERROR goto yyerrorlab
655
656
657/* Like YYERROR except do call yyerror. This remains here temporarily
658 to ease the transition to the new meaning of YYERROR, for GCC.
659 Once GCC version 2 has supplanted version 1, this can go. */
660
661#define YYFAIL goto yyerrlab
662
663#define YYRECOVERING() (!!yyerrstatus)
664
665#define YYBACKUP(Token, Value) \
666do \
667 if (yychar == YYEMPTY && yylen == 1) \
668 { \
669 yychar = (Token); \
670 yylval = (Value); \
671 yytoken = YYTRANSLATE (yychar); \
672 YYPOPSTACK (1); \
673 goto yybackup; \
674 } \
675 else \
676 { \
677 yyerror (YY_("syntax error: cannot back up")); \
678 YYERROR; \
679 } \
680while (YYID (0))
681
682
683#define YYTERROR 1
684#define YYERRCODE 256
685
686
687/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
688 If N is 0, then set CURRENT to the empty location which ends
689 the previous symbol: RHS[0] (always defined). */
690
691#define YYRHSLOC(Rhs, K) ((Rhs)[K])
692#ifndef YYLLOC_DEFAULT
693# define YYLLOC_DEFAULT(Current, Rhs, N) \
694 do \
695 if (YYID (N)) \
696 { \
697 (Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
698 (Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
699 (Current).last_line = YYRHSLOC (Rhs, N).last_line; \
700 (Current).last_column = YYRHSLOC (Rhs, N).last_column; \
701 } \
702 else \
703 { \
704 (Current).first_line = (Current).last_line = \
705 YYRHSLOC (Rhs, 0).last_line; \
706 (Current).first_column = (Current).last_column = \
707 YYRHSLOC (Rhs, 0).last_column; \
708 } \
709 while (YYID (0))
710#endif
711
712
713/* YY_LOCATION_PRINT -- Print the location on the stream.
714 This macro was not mandated originally: define only if we know
715 we won't break user code: when these are the locations we know. */
716
717#ifndef YY_LOCATION_PRINT
718# if YYLTYPE_IS_TRIVIAL
719# define YY_LOCATION_PRINT(File, Loc) \
720 fprintf (File, "%d.%d-%d.%d", \
721 (Loc).first_line, (Loc).first_column, \
722 (Loc).last_line, (Loc).last_column)
723# else
724# define YY_LOCATION_PRINT(File, Loc) ((void) 0)
725# endif
726#endif
727
728
729/* YYLEX -- calling `yylex' with the right arguments. */
730
731#ifdef YYLEX_PARAM
732# define YYLEX yylex (YYLEX_PARAM)
733#else
734# define YYLEX yylex ()
735#endif
736
737/* Enable debugging if requested. */
738#if YYDEBUG
739
740# ifndef YYFPRINTF
741# include <stdio.h> /* INFRINGES ON USER NAME SPACE */
742# define YYFPRINTF fprintf
743# endif
744
745# define YYDPRINTF(Args) \
746do { \
747 if (yydebug) \
748 YYFPRINTF Args; \
749} while (YYID (0))
750
751# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
752do { \
753 if (yydebug) \
754 { \
755 YYFPRINTF (stderr, "%s ", Title); \
756 yy_symbol_print (stderr, \
757 Type, Value); \
758 YYFPRINTF (stderr, "\n"); \
759 } \
760} while (YYID (0))
761
762
763/*--------------------------------.
764| Print this symbol on YYOUTPUT. |
765`--------------------------------*/
766
767/*ARGSUSED*/
768#if (defined __STDC__ || defined __C99__FUNC__ \
769 || defined __cplusplus || defined _MSC_VER)
770static void
771yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
772#else
773static void
774yy_symbol_value_print (yyoutput, yytype, yyvaluep)
775 FILE *yyoutput;
776 int yytype;
777 YYSTYPE const * const yyvaluep;
778#endif
779{
780 if (!yyvaluep)
781 return;
782# ifdef YYPRINT
783 if (yytype < YYNTOKENS)
784 YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
785# else
786 YYUSE (yyoutput);
787# endif
788 switch (yytype)
789 {
790 default:
791 break;
792 }
793}
794
795
796/*--------------------------------.
797| Print this symbol on YYOUTPUT. |
798`--------------------------------*/
799
800#if (defined __STDC__ || defined __C99__FUNC__ \
801 || defined __cplusplus || defined _MSC_VER)
802static void
803yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
804#else
805static void
806yy_symbol_print (yyoutput, yytype, yyvaluep)
807 FILE *yyoutput;
808 int yytype;
809 YYSTYPE const * const yyvaluep;
810#endif
811{
812 if (yytype < YYNTOKENS)
813 YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
814 else
815 YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
816
817 yy_symbol_value_print (yyoutput, yytype, yyvaluep);
818 YYFPRINTF (yyoutput, ")");
819}
820
821/*------------------------------------------------------------------.
822| yy_stack_print -- Print the state stack from its BOTTOM up to its |
823| TOP (included). |
824`------------------------------------------------------------------*/
825
826#if (defined __STDC__ || defined __C99__FUNC__ \
827 || defined __cplusplus || defined _MSC_VER)
828static void
829yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
830#else
831static void
832yy_stack_print (bottom, top)
833 yytype_int16 *bottom;
834 yytype_int16 *top;
835#endif
836{
837 YYFPRINTF (stderr, "Stack now");
838 for (; bottom <= top; ++bottom)
839 YYFPRINTF (stderr, " %d", *bottom);
840 YYFPRINTF (stderr, "\n");
841}
842
843# define YY_STACK_PRINT(Bottom, Top) \
844do { \
845 if (yydebug) \
846 yy_stack_print ((Bottom), (Top)); \
847} while (YYID (0))
848
849
850/*------------------------------------------------.
851| Report that the YYRULE is going to be reduced. |
852`------------------------------------------------*/
853
854#if (defined __STDC__ || defined __C99__FUNC__ \
855 || defined __cplusplus || defined _MSC_VER)
856static void
857yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
858#else
859static void
860yy_reduce_print (yyvsp, yyrule)
861 YYSTYPE *yyvsp;
862 int yyrule;
863#endif
864{
865 int yynrhs = yyr2[yyrule];
866 int yyi;
867 unsigned long int yylno = yyrline[yyrule];
868 YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
869 yyrule - 1, yylno);
870 /* The symbols being reduced. */
871 for (yyi = 0; yyi < yynrhs; yyi++)
872 {
873 fprintf (stderr, " $%d = ", yyi + 1);
874 yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
875 &(yyvsp[(yyi + 1) - (yynrhs)])
876 );
877 fprintf (stderr, "\n");
878 }
879}
880
881# define YY_REDUCE_PRINT(Rule) \
882do { \
883 if (yydebug) \
884 yy_reduce_print (yyvsp, Rule); \
885} while (YYID (0))
886
887/* Nonzero means print parse trace. It is left uninitialized so that
888 multiple parsers can coexist. */
889int yydebug;
890#else /* !YYDEBUG */
891# define YYDPRINTF(Args)
892# define YY_SYMBOL_PRINT(Title, Type, Value, Location)
893# define YY_STACK_PRINT(Bottom, Top)
894# define YY_REDUCE_PRINT(Rule)
895#endif /* !YYDEBUG */
896
897
898/* YYINITDEPTH -- initial size of the parser's stacks. */
899#ifndef YYINITDEPTH
900# define YYINITDEPTH 200
901#endif
902
903/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
904 if the built-in stack extension method is used).
905
906 Do not make this value too large; the results are undefined if
907 YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
908 evaluated with infinite-precision integer arithmetic. */
909
910#ifndef YYMAXDEPTH
911# define YYMAXDEPTH 10000
912#endif
913
914
915
916#if YYERROR_VERBOSE
917
918# ifndef yystrlen
919# if defined __GLIBC__ && defined _STRING_H
920# define yystrlen strlen
921# else
922/* Return the length of YYSTR. */
923#if (defined __STDC__ || defined __C99__FUNC__ \
924 || defined __cplusplus || defined _MSC_VER)
925static YYSIZE_T
926yystrlen (const char *yystr)
927#else
928static YYSIZE_T
929yystrlen (yystr)
930 const char *yystr;
931#endif
932{
933 YYSIZE_T yylen;
934 for (yylen = 0; yystr[yylen]; yylen++)
935 continue;
936 return yylen;
937}
938# endif
939# endif
940
941# ifndef yystpcpy
942# if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
943# define yystpcpy stpcpy
944# else
945/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
946 YYDEST. */
947#if (defined __STDC__ || defined __C99__FUNC__ \
948 || defined __cplusplus || defined _MSC_VER)
949static char *
950yystpcpy (char *yydest, const char *yysrc)
951#else
952static char *
953yystpcpy (yydest, yysrc)
954 char *yydest;
955 const char *yysrc;
956#endif
957{
958 char *yyd = yydest;
959 const char *yys = yysrc;
960
961 while ((*yyd++ = *yys++) != '\0')
962 continue;
963
964 return yyd - 1;
965}
966# endif
967# endif
968
969# ifndef yytnamerr
970/* Copy to YYRES the contents of YYSTR after stripping away unnecessary
971 quotes and backslashes, so that it's suitable for yyerror. The
972 heuristic is that double-quoting is unnecessary unless the string
973 contains an apostrophe, a comma, or backslash (other than
974 backslash-backslash). YYSTR is taken from yytname. If YYRES is
975 null, do not copy; instead, return the length of what the result
976 would have been. */
977static YYSIZE_T
978yytnamerr (char *yyres, const char *yystr)
979{
980 if (*yystr == '"')
981 {
982 YYSIZE_T yyn = 0;
983 char const *yyp = yystr;
984
985 for (;;)
986 switch (*++yyp)
987 {
988 case '\'':
989 case ',':
990 goto do_not_strip_quotes;
991
992 case '\\':
993 if (*++yyp != '\\')
994 goto do_not_strip_quotes;
995 /* Fall through. */
996 default:
997 if (yyres)
998 yyres[yyn] = *yyp;
999 yyn++;
1000 break;
1001
1002 case '"':
1003 if (yyres)
1004 yyres[yyn] = '\0';
1005 return yyn;
1006 }
1007 do_not_strip_quotes: ;
1008 }
1009
1010 if (! yyres)
1011 return yystrlen (yystr);
1012
1013 return yystpcpy (yyres, yystr) - yyres;
1014}
1015# endif
1016
1017/* Copy into YYRESULT an error message about the unexpected token
1018 YYCHAR while in state YYSTATE. Return the number of bytes copied,
1019 including the terminating null byte. If YYRESULT is null, do not
1020 copy anything; just return the number of bytes that would be
1021 copied. As a special case, return 0 if an ordinary "syntax error"
1022 message will do. Return YYSIZE_MAXIMUM if overflow occurs during
1023 size calculation. */
1024static YYSIZE_T
1025yysyntax_error (char *yyresult, int yystate, int yychar)
1026{
1027 int yyn = yypact[yystate];
1028
1029 if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1030 return 0;
1031 else
1032 {
1033 int yytype = YYTRANSLATE (yychar);
1034 YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1035 YYSIZE_T yysize = yysize0;
1036 YYSIZE_T yysize1;
1037 int yysize_overflow = 0;
1038 enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1039 char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1040 int yyx;
1041
1042# if 0
1043 /* This is so xgettext sees the translatable formats that are
1044 constructed on the fly. */
1045 YY_("syntax error, unexpected %s");
1046 YY_("syntax error, unexpected %s, expecting %s");
1047 YY_("syntax error, unexpected %s, expecting %s or %s");
1048 YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1049 YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1050# endif
1051 char *yyfmt;
1052 char const *yyf;
1053 static char const yyunexpected[] = "syntax error, unexpected %s";
1054 static char const yyexpecting[] = ", expecting %s";
1055 static char const yyor[] = " or %s";
1056 char yyformat[sizeof yyunexpected
1057 + sizeof yyexpecting - 1
1058 + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1059 * (sizeof yyor - 1))];
1060 char const *yyprefix = yyexpecting;
1061
1062 /* Start YYX at -YYN if negative to avoid negative indexes in
1063 YYCHECK. */
1064 int yyxbegin = yyn < 0 ? -yyn : 0;
1065
1066 /* Stay within bounds of both yycheck and yytname. */
1067 int yychecklim = YYLAST - yyn + 1;
1068 int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1069 int yycount = 1;
1070
1071 yyarg[0] = yytname[yytype];
1072 yyfmt = yystpcpy (yyformat, yyunexpected);
1073
1074 for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1075 if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1076 {
1077 if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1078 {
1079 yycount = 1;
1080 yysize = yysize0;
1081 yyformat[sizeof yyunexpected - 1] = '\0';
1082 break;
1083 }
1084 yyarg[yycount++] = yytname[yyx];
1085 yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1086 yysize_overflow |= (yysize1 < yysize);
1087 yysize = yysize1;
1088 yyfmt = yystpcpy (yyfmt, yyprefix);
1089 yyprefix = yyor;
1090 }
1091
1092 yyf = YY_(yyformat);
1093 yysize1 = yysize + yystrlen (yyf);
1094 yysize_overflow |= (yysize1 < yysize);
1095 yysize = yysize1;
1096
1097 if (yysize_overflow)
1098 return YYSIZE_MAXIMUM;
1099
1100 if (yyresult)
1101 {
1102 /* Avoid sprintf, as that infringes on the user's name space.
1103 Don't have undefined behavior even if the translation
1104 produced a string with the wrong number of "%s"s. */
1105 char *yyp = yyresult;
1106 int yyi = 0;
1107 while ((*yyp = *yyf) != '\0')
1108 {
1109 if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1110 {
1111 yyp += yytnamerr (yyp, yyarg[yyi++]);
1112 yyf += 2;
1113 }
1114 else
1115 {
1116 yyp++;
1117 yyf++;
1118 }
1119 }
1120 }
1121 return yysize;
1122 }
1123}
1124#endif /* YYERROR_VERBOSE */
1125
1126
1127/*-----------------------------------------------.
1128| Release the memory associated to this symbol. |
1129`-----------------------------------------------*/
1130
1131/*ARGSUSED*/
1132#if (defined __STDC__ || defined __C99__FUNC__ \
1133 || defined __cplusplus || defined _MSC_VER)
1134static void
1135yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1136#else
1137static void
1138yydestruct (yymsg, yytype, yyvaluep)
1139 const char *yymsg;
1140 int yytype;
1141 YYSTYPE *yyvaluep;
1142#endif
1143{
1144 YYUSE (yyvaluep);
1145
1146 if (!yymsg)
1147 yymsg = "Deleting";
1148 YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1149
1150 switch (yytype)
1151 {
1152
1153 default:
1154 break;
1155 }
1156}
1157
1158
1159/* Prevent warnings from -Wmissing-prototypes. */
1160
1161#ifdef YYPARSE_PARAM
1162#if defined __STDC__ || defined __cplusplus
1163int yyparse (void *YYPARSE_PARAM);
1164#else
1165int yyparse ();
1166#endif
1167#else /* ! YYPARSE_PARAM */
1168#if defined __STDC__ || defined __cplusplus
1169int yyparse (void);
1170#else
1171int yyparse ();
1172#endif
1173#endif /* ! YYPARSE_PARAM */
1174
1175
1176
1177/* The look-ahead symbol. */
1178int yychar;
1179
1180/* The semantic value of the look-ahead symbol. */
1181YYSTYPE yylval;
1182
1183/* Number of syntax errors so far. */
1184int yynerrs;
1185
1186
1187
1188/*----------.
1189| yyparse. |
1190`----------*/
1191
1192#ifdef YYPARSE_PARAM
1193#if (defined __STDC__ || defined __C99__FUNC__ \
1194 || defined __cplusplus || defined _MSC_VER)
1195int
1196yyparse (void *YYPARSE_PARAM)
1197#else
1198int
1199yyparse (YYPARSE_PARAM)
1200 void *YYPARSE_PARAM;
1201#endif
1202#else /* ! YYPARSE_PARAM */
1203#if (defined __STDC__ || defined __C99__FUNC__ \
1204 || defined __cplusplus || defined _MSC_VER)
1205int
1206yyparse (void)
1207#else
1208int
1209yyparse ()
1210
1211#endif
1212#endif
1213{
1214
1215 int yystate;
1216 int yyn;
1217 int yyresult;
1218 /* Number of tokens to shift before error messages enabled. */
1219 int yyerrstatus;
1220 /* Look-ahead token as an internal (translated) token number. */
1221 int yytoken = 0;
1222#if YYERROR_VERBOSE
1223 /* Buffer for error messages, and its allocated size. */
1224 char yymsgbuf[128];
1225 char *yymsg = yymsgbuf;
1226 YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1227#endif
1228
1229 /* Three stacks and their tools:
1230 `yyss': related to states,
1231 `yyvs': related to semantic values,
1232 `yyls': related to locations.
1233
1234 Refer to the stacks thru separate pointers, to allow yyoverflow
1235 to reallocate them elsewhere. */
1236
1237 /* The state stack. */
1238 yytype_int16 yyssa[YYINITDEPTH];
1239 yytype_int16 *yyss = yyssa;
1240 yytype_int16 *yyssp;
1241
1242 /* The semantic value stack. */
1243 YYSTYPE yyvsa[YYINITDEPTH];
1244 YYSTYPE *yyvs = yyvsa;
1245 YYSTYPE *yyvsp;
1246
1247
1248
1249#define YYPOPSTACK(N) (yyvsp -= (N), yyssp -= (N))
1250
1251 YYSIZE_T yystacksize = YYINITDEPTH;
1252
1253 /* The variables used to return semantic value and location from the
1254 action routines. */
1255 YYSTYPE yyval;
1256
1257
1258 /* The number of symbols on the RHS of the reduced rule.
1259 Keep to zero when no symbol should be popped. */
1260 int yylen = 0;
1261
1262 YYDPRINTF ((stderr, "Starting parse\n"));
1263
1264 yystate = 0;
1265 yyerrstatus = 0;
1266 yynerrs = 0;
1267 yychar = YYEMPTY; /* Cause a token to be read. */
1268
1269 /* Initialize stack pointers.
1270 Waste one element of value and location stack
1271 so that they stay on the same level as the state stack.
1272 The wasted elements are never initialized. */
1273
1274 yyssp = yyss;
1275 yyvsp = yyvs;
1276
1277 goto yysetstate;
1278
1279/*------------------------------------------------------------.
1280| yynewstate -- Push a new state, which is found in yystate. |
1281`------------------------------------------------------------*/
1282 yynewstate:
1283 /* In all cases, when you get here, the value and location stacks
1284 have just been pushed. So pushing a state here evens the stacks. */
1285 yyssp++;
1286
1287 yysetstate:
1288 *yyssp = yystate;
1289
1290 if (yyss + yystacksize - 1 <= yyssp)
1291 {
1292 /* Get the current used size of the three stacks, in elements. */
1293 YYSIZE_T yysize = yyssp - yyss + 1;
1294
1295#ifdef yyoverflow
1296 {
1297 /* Give user a chance to reallocate the stack. Use copies of
1298 these so that the &'s don't force the real ones into
1299 memory. */
1300 YYSTYPE *yyvs1 = yyvs;
1301 yytype_int16 *yyss1 = yyss;
1302
1303
1304 /* Each stack pointer address is followed by the size of the
1305 data in use in that stack, in bytes. This used to be a
1306 conditional around just the two extra args, but that might
1307 be undefined if yyoverflow is a macro. */
1308 yyoverflow (YY_("memory exhausted"),
1309 &yyss1, yysize * sizeof (*yyssp),
1310 &yyvs1, yysize * sizeof (*yyvsp),
1311
1312 &yystacksize);
1313
1314 yyss = yyss1;
1315 yyvs = yyvs1;
1316 }
1317#else /* no yyoverflow */
1318# ifndef YYSTACK_RELOCATE
1319 goto yyexhaustedlab;
1320# else
1321 /* Extend the stack our own way. */
1322 if (YYMAXDEPTH <= yystacksize)
1323 goto yyexhaustedlab;
1324 yystacksize *= 2;
1325 if (YYMAXDEPTH < yystacksize)
1326 yystacksize = YYMAXDEPTH;
1327
1328 {
1329 yytype_int16 *yyss1 = yyss;
1330 union yyalloc *yyptr =
1331 (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1332 if (! yyptr)
1333 goto yyexhaustedlab;
1334 YYSTACK_RELOCATE (yyss);
1335 YYSTACK_RELOCATE (yyvs);
1336
1337# undef YYSTACK_RELOCATE
1338 if (yyss1 != yyssa)
1339 YYSTACK_FREE (yyss1);
1340 }
1341# endif
1342#endif /* no yyoverflow */
1343
1344 yyssp = yyss + yysize - 1;
1345 yyvsp = yyvs + yysize - 1;
1346
1347
1348 YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1349 (unsigned long int) yystacksize));
1350
1351 if (yyss + yystacksize - 1 <= yyssp)
1352 YYABORT;
1353 }
1354
1355 YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1356
1357 goto yybackup;
1358
1359/*-----------.
1360| yybackup. |
1361`-----------*/
1362yybackup:
1363
1364 /* Do appropriate processing given the current state. Read a
1365 look-ahead token if we need one and don't already have one. */
1366
1367 /* First try to decide what to do without reference to look-ahead token. */
1368 yyn = yypact[yystate];
1369 if (yyn == YYPACT_NINF)
1370 goto yydefault;
1371
1372 /* Not known => get a look-ahead token if don't already have one. */
1373
1374 /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol. */
1375 if (yychar == YYEMPTY)
1376 {
1377 YYDPRINTF ((stderr, "Reading a token: "));
1378 yychar = YYLEX;
1379 }
1380
1381 if (yychar <= YYEOF)
1382 {
1383 yychar = yytoken = YYEOF;
1384 YYDPRINTF ((stderr, "Now at end of input.\n"));
1385 }
1386 else
1387 {
1388 yytoken = YYTRANSLATE (yychar);
1389 YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1390 }
1391
1392 /* If the proper action on seeing token YYTOKEN is to reduce or to
1393 detect an error, take that action. */
1394 yyn += yytoken;
1395 if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1396 goto yydefault;
1397 yyn = yytable[yyn];
1398 if (yyn <= 0)
1399 {
1400 if (yyn == 0 || yyn == YYTABLE_NINF)
1401 goto yyerrlab;
1402 yyn = -yyn;
1403 goto yyreduce;
1404 }
1405
1406 if (yyn == YYFINAL)
1407 YYACCEPT;
1408
1409 /* Count tokens shifted since error; after three, turn off error
1410 status. */
1411 if (yyerrstatus)
1412 yyerrstatus--;
1413
1414 /* Shift the look-ahead token. */
1415 YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1416
1417 /* Discard the shifted token unless it is eof. */
1418 if (yychar != YYEOF)
1419 yychar = YYEMPTY;
1420
1421 yystate = yyn;
1422 *++yyvsp = yylval;
1423
1424 goto yynewstate;
1425
1426
1427/*-----------------------------------------------------------.
1428| yydefault -- do the default action for the current state. |
1429`-----------------------------------------------------------*/
1430yydefault:
1431 yyn = yydefact[yystate];
1432 if (yyn == 0)
1433 goto yyerrlab;
1434 goto yyreduce;
1435
1436
1437/*-----------------------------.
1438| yyreduce -- Do a reduction. |
1439`-----------------------------*/
1440yyreduce:
1441 /* yyn is the number of a rule to reduce with. */
1442 yylen = yyr2[yyn];
1443
1444 /* If YYLEN is nonzero, implement the default value of the action:
1445 `$$ = $1'.
1446
1447 Otherwise, the following line sets YYVAL to garbage.
1448 This behavior is undocumented and Bison
1449 users should not rely upon it. Assigning to YYVAL
1450 unconditionally makes the parser a bit smaller, and it avoids a
1451 GCC warning that YYVAL may be used uninitialized. */
1452 yyval = yyvsp[1-yylen];
1453
1454
1455 YY_REDUCE_PRINT (yyn);
1456 switch (yyn)
1457 {
1458 case 2:
1459#line 151 "policy_parse.y"
1460 {
1461 p_dir = (yyvsp[(1) - (2)].num);
1462 p_type = (yyvsp[(2) - (2)].num);
1463
1464#ifdef HAVE_PFKEY_POLICY_PRIORITY
1465 p_priority = PRIORITY_DEFAULT;
1466#else
1467 p_priority = 0;
1468#endif
1469
1470 if (init_x_policy())
1471 return -1;
1472 }
1473 break;
1474
1475 case 4:
1476#line 166 "policy_parse.y"
1477 {
1478 char *offset_buf;
1479
1480 p_dir = (yyvsp[(1) - (4)].num);
1481 p_type = (yyvsp[(4) - (4)].num);
1482
1483 /* buffer big enough to hold a prepended negative sign */
1484 offset_buf = malloc((yyvsp[(3) - (4)].val).len + 2);
1485 if (offset_buf == NULL)
1486 {
1487 __ipsec_errcode = EIPSEC_NO_BUFS;
1488 return -1;
1489 }
1490
1491 /* positive input value means higher priority, therefore lower
1492 actual value so that is closer to the beginning of the list */
1493 sprintf (offset_buf, "-%s", (yyvsp[(3) - (4)].val).buf);
1494
1495 errno = 0;
1496 p_priority_offset = atol(offset_buf);
1497
1498 free(offset_buf);
1499
1500 if (errno != 0 || p_priority_offset < INT32_MIN)
1501 {
1502 __ipsec_errcode = EIPSEC_INVAL_PRIORITY_OFFSET;
1503 return -1;
1504 }
1505
1506 p_priority = PRIORITY_DEFAULT + (u_int32_t) p_priority_offset;
1507
1508 if (init_x_policy())
1509 return -1;
1510 }
1511 break;
1512
1513 case 6:
1514#line 202 "policy_parse.y"
1515 {
1516 p_dir = (yyvsp[(1) - (5)].num);
1517 p_type = (yyvsp[(5) - (5)].num);
1518
1519 errno = 0;
1520 p_priority_offset = atol((yyvsp[(4) - (5)].val).buf);
1521
1522 if (errno != 0 || p_priority_offset > INT32_MAX)
1523 {
1524 __ipsec_errcode = EIPSEC_INVAL_PRIORITY_OFFSET;
1525 return -1;
1526 }
1527
1528 /* negative input value means lower priority, therefore higher
1529 actual value so that is closer to the end of the list */
1530 p_priority = PRIORITY_DEFAULT + (u_int32_t) p_priority_offset;
1531
1532 if (init_x_policy())
1533 return -1;
1534 }
1535 break;
1536
1537 case 8:
1538#line 224 "policy_parse.y"
1539 {
1540 p_dir = (yyvsp[(1) - (4)].num);
1541 p_type = (yyvsp[(4) - (4)].num);
1542
1543 p_priority = (yyvsp[(3) - (4)].num32);
1544
1545 if (init_x_policy())
1546 return -1;
1547 }
1548 break;
1549
1550 case 10:
1551#line 235 "policy_parse.y"
1552 {
1553 p_dir = (yyvsp[(1) - (6)].num);
1554 p_type = (yyvsp[(6) - (6)].num);
1555
1556 errno = 0;
1557 p_priority_offset = atol((yyvsp[(5) - (6)].val).buf);
1558
1559 if (errno != 0 || p_priority_offset > PRIORITY_OFFSET_NEGATIVE_MAX)
1560 {
1561 __ipsec_errcode = EIPSEC_INVAL_PRIORITY_BASE_OFFSET;
1562 return -1;
1563 }
1564
1565 /* adding value means higher priority, therefore lower
1566 actual value so that is closer to the beginning of the list */
1567 p_priority = (yyvsp[(3) - (6)].num32) - (u_int32_t) p_priority_offset;
1568
1569 if (init_x_policy())
1570 return -1;
1571 }
1572 break;
1573
1574 case 12:
1575#line 257 "policy_parse.y"
1576 {
1577 p_dir = (yyvsp[(1) - (6)].num);
1578 p_type = (yyvsp[(6) - (6)].num);
1579
1580 errno = 0;
1581 p_priority_offset = atol((yyvsp[(5) - (6)].val).buf);
1582
1583 if (errno != 0 || p_priority_offset > PRIORITY_OFFSET_POSITIVE_MAX)
1584 {
1585 __ipsec_errcode = EIPSEC_INVAL_PRIORITY_BASE_OFFSET;
1586 return -1;
1587 }
1588
1589 /* subtracting value means lower priority, therefore higher
1590 actual value so that is closer to the end of the list */
1591 p_priority = (yyvsp[(3) - (6)].num32) + (u_int32_t) p_priority_offset;
1592
1593 if (init_x_policy())
1594 return -1;
1595 }
1596 break;
1597
1598 case 14:
1599#line 279 "policy_parse.y"
1600 {
1601 p_dir = (yyvsp[(1) - (1)].num);
1602 p_type = 0; /* ignored it by kernel */
1603
1604 p_priority = 0;
1605
1606 if (init_x_policy())
1607 return -1;
1608 }
1609 break;
1610
1611 case 16:
1612#line 292 "policy_parse.y"
1613 {
1614 if (rule_check() < 0)
1615 return -1;
1616
1617 if (set_x_request(p_src, p_dst) < 0)
1618 return -1;
1619
1620 policy_parse_request_init();
1621 }
1622 break;
1623
1624 case 23:
1625#line 310 "policy_parse.y"
1626 {
1627 __ipsec_errcode = EIPSEC_FEW_ARGUMENTS;
1628 return -1;
1629 }
1630 break;
1631
1632 case 24:
1633#line 314 "policy_parse.y"
1634 {
1635 __ipsec_errcode = EIPSEC_FEW_ARGUMENTS;
1636 return -1;
1637 }
1638 break;
1639
1640 case 25:
1641#line 321 "policy_parse.y"
1642 { p_protocol = (yyvsp[(1) - (1)].num); }
1643 break;
1644
1645 case 26:
1646#line 325 "policy_parse.y"
1647 { p_mode = (yyvsp[(1) - (1)].num); }
1648 break;
1649
1650 case 27:
1651#line 329 "policy_parse.y"
1652 {
1653 p_level = (yyvsp[(1) - (1)].num);
1654 p_reqid = 0;
1655 }
1656 break;
1657
1658 case 28:
1659#line 333 "policy_parse.y"
1660 {
1661 p_level = IPSEC_LEVEL_UNIQUE;
1662 p_reqid = atol((yyvsp[(1) - (1)].val).buf); /* atol() is good. */
1663 }
1664 break;
1665
1666 case 29:
1667#line 340 "policy_parse.y"
1668 {
1669 p_src = parse_sockaddr(&(yyvsp[(1) - (1)].val), NULL);
1670 if (p_src == NULL)
1671 return -1;
1672 }
1673 break;
1674
1675 case 30:
1676#line 346 "policy_parse.y"
1677 {
1678 p_dst = parse_sockaddr(&(yyvsp[(4) - (4)].val), NULL);
1679 if (p_dst == NULL)
1680 return -1;
1681 }
1682 break;
1683
1684 case 31:
1685#line 351 "policy_parse.y"
1686 {
1687 p_src = parse_sockaddr(&(yyvsp[(1) - (2)].val), &(yyvsp[(2) - (2)].val));
1688 if (p_src == NULL)
1689 return -1;
1690 }
1691 break;
1692
1693 case 32:
1694#line 357 "policy_parse.y"
1695 {
1696 p_dst = parse_sockaddr(&(yyvsp[(5) - (6)].val), &(yyvsp[(6) - (6)].val));
1697 if (p_dst == NULL)
1698 return -1;
1699 }
1700 break;
1701
1702 case 33:
1703#line 362 "policy_parse.y"
1704 {
1705 if (p_dir != IPSEC_DIR_OUTBOUND) {
1706 __ipsec_errcode = EIPSEC_INVAL_DIR;
1707 return -1;
1708 }
1709 }
1710 break;
1711
1712 case 34:
1713#line 368 "policy_parse.y"
1714 {
1715 if (p_dir != IPSEC_DIR_INBOUND) {
1716 __ipsec_errcode = EIPSEC_INVAL_DIR;
1717 return -1;
1718 }
1719 }
1720 break;
1721
1722
1723/* Line 1267 of yacc.c. */
1724#line 1725 "policy_parse.c"
1725 default: break;
1726 }
1727 YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1728
1729 YYPOPSTACK (yylen);
1730 yylen = 0;
1731 YY_STACK_PRINT (yyss, yyssp);
1732
1733 *++yyvsp = yyval;
1734
1735
1736 /* Now `shift' the result of the reduction. Determine what state
1737 that goes to, based on the state we popped back to and the rule
1738 number reduced by. */
1739
1740 yyn = yyr1[yyn];
1741
1742 yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1743 if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1744 yystate = yytable[yystate];
1745 else
1746 yystate = yydefgoto[yyn - YYNTOKENS];
1747
1748 goto yynewstate;
1749
1750
1751/*------------------------------------.
1752| yyerrlab -- here on detecting error |
1753`------------------------------------*/
1754yyerrlab:
1755 /* If not already recovering from an error, report this error. */
1756 if (!yyerrstatus)
1757 {
1758 ++yynerrs;
1759#if ! YYERROR_VERBOSE
1760 yyerror (YY_("syntax error"));
1761#else
1762 {
1763 YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
1764 if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
1765 {
1766 YYSIZE_T yyalloc = 2 * yysize;
1767 if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
1768 yyalloc = YYSTACK_ALLOC_MAXIMUM;
1769 if (yymsg != yymsgbuf)
1770 YYSTACK_FREE (yymsg);
1771 yymsg = (char *) YYSTACK_ALLOC (yyalloc);
1772 if (yymsg)
1773 yymsg_alloc = yyalloc;
1774 else
1775 {
1776 yymsg = yymsgbuf;
1777 yymsg_alloc = sizeof yymsgbuf;
1778 }
1779 }
1780
1781 if (0 < yysize && yysize <= yymsg_alloc)
1782 {
1783 (void) yysyntax_error (yymsg, yystate, yychar);
1784 yyerror (yymsg);
1785 }
1786 else
1787 {
1788 yyerror (YY_("syntax error"));
1789 if (yysize != 0)
1790 goto yyexhaustedlab;
1791 }
1792 }
1793#endif
1794 }
1795
1796
1797
1798 if (yyerrstatus == 3)
1799 {
1800 /* If just tried and failed to reuse look-ahead token after an
1801 error, discard it. */
1802
1803 if (yychar <= YYEOF)
1804 {
1805 /* Return failure if at end of input. */
1806 if (yychar == YYEOF)
1807 YYABORT;
1808 }
1809 else
1810 {
1811 yydestruct ("Error: discarding",
1812 yytoken, &yylval);
1813 yychar = YYEMPTY;
1814 }
1815 }
1816
1817 /* Else will try to reuse look-ahead token after shifting the error
1818 token. */
1819 goto yyerrlab1;
1820
1821
1822/*---------------------------------------------------.
1823| yyerrorlab -- error raised explicitly by YYERROR. |
1824`---------------------------------------------------*/
1825yyerrorlab:
1826
1827 /* Pacify compilers like GCC when the user code never invokes
1828 YYERROR and the label yyerrorlab therefore never appears in user
1829 code. */
1830 if (/*CONSTCOND*/ 0)
1831 goto yyerrorlab;
1832
1833 /* Do not reclaim the symbols of the rule which action triggered
1834 this YYERROR. */
1835 YYPOPSTACK (yylen);
1836 yylen = 0;
1837 YY_STACK_PRINT (yyss, yyssp);
1838 yystate = *yyssp;
1839 goto yyerrlab1;
1840
1841
1842/*-------------------------------------------------------------.
1843| yyerrlab1 -- common code for both syntax error and YYERROR. |
1844`-------------------------------------------------------------*/
1845yyerrlab1:
1846 yyerrstatus = 3; /* Each real token shifted decrements this. */
1847
1848 for (;;)
1849 {
1850 yyn = yypact[yystate];
1851 if (yyn != YYPACT_NINF)
1852 {
1853 yyn += YYTERROR;
1854 if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1855 {
1856 yyn = yytable[yyn];
1857 if (0 < yyn)
1858 break;
1859 }
1860 }
1861
1862 /* Pop the current state because it cannot handle the error token. */
1863 if (yyssp == yyss)
1864 YYABORT;
1865
1866
1867 yydestruct ("Error: popping",
1868 yystos[yystate], yyvsp);
1869 YYPOPSTACK (1);
1870 yystate = *yyssp;
1871 YY_STACK_PRINT (yyss, yyssp);
1872 }
1873
1874 if (yyn == YYFINAL)
1875 YYACCEPT;
1876
1877 *++yyvsp = yylval;
1878
1879
1880 /* Shift the error token. */
1881 YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1882
1883 yystate = yyn;
1884 goto yynewstate;
1885
1886
1887/*-------------------------------------.
1888| yyacceptlab -- YYACCEPT comes here. |
1889`-------------------------------------*/
1890yyacceptlab:
1891 yyresult = 0;
1892 goto yyreturn;
1893
1894/*-----------------------------------.
1895| yyabortlab -- YYABORT comes here. |
1896`-----------------------------------*/
1897yyabortlab:
1898 yyresult = 1;
1899 goto yyreturn;
1900
1901#ifndef yyoverflow
1902/*-------------------------------------------------.
1903| yyexhaustedlab -- memory exhaustion comes here. |
1904`-------------------------------------------------*/
1905yyexhaustedlab:
1906 yyerror (YY_("memory exhausted"));
1907 yyresult = 2;
1908 /* Fall through. */
1909#endif
1910
1911yyreturn:
1912 if (yychar != YYEOF && yychar != YYEMPTY)
1913 yydestruct ("Cleanup: discarding lookahead",
1914 yytoken, &yylval);
1915 /* Do not reclaim the symbols of the rule which action triggered
1916 this YYABORT or YYACCEPT. */
1917 YYPOPSTACK (yylen);
1918 YY_STACK_PRINT (yyss, yyssp);
1919 while (yyssp != yyss)
1920 {
1921 yydestruct ("Cleanup: popping",
1922 yystos[*yyssp], yyvsp);
1923 YYPOPSTACK (1);
1924 }
1925#ifndef yyoverflow
1926 if (yyss != yyssa)
1927 YYSTACK_FREE (yyss);
1928#endif
1929#if YYERROR_VERBOSE
1930 if (yymsg != yymsgbuf)
1931 YYSTACK_FREE (yymsg);
1932#endif
1933 /* Make sure YYID is used. */
1934 return YYID (yyresult);
1935}
1936
1937
1938#line 379 "policy_parse.y"
1939
1940
1941void
1942yyerror(msg)
1943 char *msg;
1944{
1945 fprintf(stderr, "libipsec: %s while parsing \"%s\"\n",
1946 msg, __libipsectext);
1947
1948 return;
1949}
1950
1951static struct sockaddr *
1952parse_sockaddr(addrbuf, portbuf)
1953 struct _val *addrbuf;
1954 struct _val *portbuf;
1955{
1956 struct addrinfo hints, *res;
1957 char *addr;
1958 char *serv = NULL;
1959 int error;
1960 struct sockaddr *newaddr = NULL;
1961
1962 if ((addr = malloc(addrbuf->len + 1)) == NULL) {
1963 yyerror("malloc failed");
1964 __ipsec_set_strerror(strerror(errno));
1965 return NULL;
1966 }
1967
1968 if (portbuf && ((serv = malloc(portbuf->len + 1)) == NULL)) {
1969 free(addr);
1970 yyerror("malloc failed");
1971 __ipsec_set_strerror(strerror(errno));
1972 return NULL;
1973 }
1974
1975 strncpy(addr, addrbuf->buf, addrbuf->len);
1976 addr[addrbuf->len] = '\0';
1977
1978 if (portbuf) {
1979 strncpy(serv, portbuf->buf, portbuf->len);
1980 serv[portbuf->len] = '\0';
1981 }
1982
1983 memset(&hints, 0, sizeof(hints));
1984 hints.ai_family = PF_UNSPEC;
1985 hints.ai_flags = AI_NUMERICHOST;
1986 hints.ai_socktype = SOCK_DGRAM;
1987 error = getaddrinfo(addr, serv, &hints, &res);
1988 free(addr);
1989 if (serv != NULL)
1990 free(serv);
1991 if (error != 0) {
1992 yyerror("invalid IP address");
1993 __ipsec_set_strerror(gai_strerror(error));
1994 return NULL;
1995 }
1996
1997 if (res->ai_addr == NULL) {
1998 yyerror("invalid IP address");
1999 __ipsec_set_strerror(gai_strerror(error));
2000 return NULL;
2001 }
2002
2003 newaddr = malloc(res->ai_addrlen);
2004 if (newaddr == NULL) {
2005 __ipsec_errcode = EIPSEC_NO_BUFS;
2006 freeaddrinfo(res);
2007 return NULL;
2008 }
2009 memcpy(newaddr, res->ai_addr, res->ai_addrlen);
2010
2011 freeaddrinfo(res);
2012
2013 __ipsec_errcode = EIPSEC_NO_ERROR;
2014 return newaddr;
2015}
2016
2017static int
2018rule_check()
2019{
2020 if (p_type == IPSEC_POLICY_IPSEC) {
2021 if (p_protocol == IPPROTO_IP) {
2022 __ipsec_errcode = EIPSEC_NO_PROTO;
2023 return -1;
2024 }
2025
2026 if (p_mode != IPSEC_MODE_TRANSPORT
2027 && p_mode != IPSEC_MODE_TUNNEL) {
2028 __ipsec_errcode = EIPSEC_INVAL_MODE;
2029 return -1;
2030 }
2031
2032 if (p_src == NULL && p_dst == NULL) {
2033 if (p_mode != IPSEC_MODE_TRANSPORT) {
2034 __ipsec_errcode = EIPSEC_INVAL_ADDRESS;
2035 return -1;
2036 }
2037 }
2038 else if (p_src->sa_family != p_dst->sa_family) {
2039 __ipsec_errcode = EIPSEC_FAMILY_MISMATCH;
2040 return -1;
2041 }
2042 }
2043
2044 __ipsec_errcode = EIPSEC_NO_ERROR;
2045 return 0;
2046}
2047
2048static int
2049init_x_policy()
2050{
2051 struct sadb_x_policy *p;
2052
2053 if (pbuf) {
2054 free(pbuf);
2055 tlen = 0;
2056 }
2057 pbuf = malloc(sizeof(struct sadb_x_policy));
2058 if (pbuf == NULL) {
2059 __ipsec_errcode = EIPSEC_NO_BUFS;
2060 return -1;
2061 }
2062 tlen = sizeof(struct sadb_x_policy);
2063
2064 memset(pbuf, 0, tlen);
2065 p = (struct sadb_x_policy *)pbuf;
2066 p->sadb_x_policy_len = 0; /* must update later */
2067 p->sadb_x_policy_exttype = SADB_X_EXT_POLICY;
2068 p->sadb_x_policy_type = p_type;
2069 p->sadb_x_policy_dir = p_dir;
2070 p->sadb_x_policy_id = 0;
2071#ifdef HAVE_PFKEY_POLICY_PRIORITY
2072 p->sadb_x_policy_priority = p_priority;
2073#else
2074 /* fail if given a priority and libipsec was not compiled with
2075 priority support */
2076 if (p_priority != 0)
2077 {
2078 __ipsec_errcode = EIPSEC_PRIORITY_NOT_COMPILED;
2079 return -1;
2080 }
2081#endif
2082
2083 offset = tlen;
2084
2085 __ipsec_errcode = EIPSEC_NO_ERROR;
2086 return 0;
2087}
2088
2089static int
2090set_x_request(src, dst)
2091 struct sockaddr *src, *dst;
2092{
2093 struct sadb_x_ipsecrequest *p;
2094 int reqlen;
2095 u_int8_t *n;
2096
2097 reqlen = sizeof(*p)
2098 + (src ? sysdep_sa_len(src) : 0)
2099 + (dst ? sysdep_sa_len(dst) : 0);
2100 tlen += reqlen; /* increment to total length */
2101
2102 n = realloc(pbuf, tlen);
2103 if (n == NULL) {
2104 __ipsec_errcode = EIPSEC_NO_BUFS;
2105 return -1;
2106 }
2107 pbuf = n;
2108
2109 p = (struct sadb_x_ipsecrequest *)&pbuf[offset];
2110 p->sadb_x_ipsecrequest_len = reqlen;
2111 p->sadb_x_ipsecrequest_proto = p_protocol;
2112 p->sadb_x_ipsecrequest_mode = p_mode;
2113 p->sadb_x_ipsecrequest_level = p_level;
2114 p->sadb_x_ipsecrequest_reqid = p_reqid;
2115 offset += sizeof(*p);
2116
2117 if (set_sockaddr(src) || set_sockaddr(dst))
2118 return -1;
2119
2120 __ipsec_errcode = EIPSEC_NO_ERROR;
2121 return 0;
2122}
2123
2124static int
2125set_sockaddr(addr)
2126 struct sockaddr *addr;
2127{
2128 if (addr == NULL) {
2129 __ipsec_errcode = EIPSEC_NO_ERROR;
2130 return 0;
2131 }
2132
2133 /* tlen has already incremented */
2134
2135 memcpy(&pbuf[offset], addr, sysdep_sa_len(addr));
2136
2137 offset += sysdep_sa_len(addr);
2138
2139 __ipsec_errcode = EIPSEC_NO_ERROR;
2140 return 0;
2141}
2142
2143static void
2144policy_parse_request_init()
2145{
2146 p_protocol = IPPROTO_IP;
2147 p_mode = IPSEC_MODE_ANY;
2148 p_level = IPSEC_LEVEL_DEFAULT;
2149 p_reqid = 0;
2150 if (p_src != NULL) {
2151 free(p_src);
2152 p_src = NULL;
2153 }
2154 if (p_dst != NULL) {
2155 free(p_dst);
2156 p_dst = NULL;
2157 }
2158
2159 return;
2160}
2161
2162static void *
2163policy_parse(msg, msglen)
2164 const char *msg;
2165 int msglen;
2166{
2167 int error;
2168
2169 pbuf = NULL;
2170 tlen = 0;
2171
2172 /* initialize */
2173 p_dir = IPSEC_DIR_INVALID;
2174 p_type = IPSEC_POLICY_DISCARD;
2175 policy_parse_request_init();
2176 __policy__strbuffer__init__(msg);
2177
2178 error = yyparse(); /* it must be set errcode. */
2179 __policy__strbuffer__free__();
2180
2181 if (error) {
2182 if (pbuf != NULL)
2183 free(pbuf);
2184 return NULL;
2185 }
2186
2187 /* update total length */
2188 ((struct sadb_x_policy *)pbuf)->sadb_x_policy_len = PFKEY_UNIT64(tlen);
2189
2190 __ipsec_errcode = EIPSEC_NO_ERROR;
2191
2192 return pbuf;
2193}
2194
2195ipsec_policy_t
2196ipsec_set_policy(msg, msglen)
2197 __ipsec_const char *msg;
2198 int msglen;
2199{
2200 caddr_t policy;
2201
2202 policy = policy_parse(msg, msglen);
2203 if (policy == NULL) {
2204 if (__ipsec_errcode == EIPSEC_NO_ERROR)
2205 __ipsec_errcode = EIPSEC_INVAL_ARGUMENT;
2206 return NULL;
2207 }
2208
2209 __ipsec_errcode = EIPSEC_NO_ERROR;
2210 return policy;
2211}
2212