File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / ipsec-tools / src / libipsec / policy_parse.c
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Tue Feb 21 22:39:10 2012 UTC (12 years, 4 months ago) by misho
Branches: ipsec-tools, MAIN
CVS tags: v0_8_0p0, v0_8_0, HEAD
ipsec-tools

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

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