Annotation of embedaddon/ipsec-tools/src/libipsec/policy_parse.c, revision 1.1.1.2

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>