/* A Bison parser, made by GNU Bison 1.875c. */ /* Skeleton parser for Yacc-like parsing with Bison, Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* As a special exception, when this file is copied by Bison into a Bison output file, you may use that output file without restriction. This special exception was added by the Free Software Foundation in version 1.24 of Bison. */ /* Written by Richard Stallman by simplifying the original so called ``semantic'' parser. */ /* All symbols defined below should begin with yy or YY, to avoid infringing on user name space. This should be done even for local variables, as they might otherwise be expanded by user macros. There are some unavoidable exceptions within include files to define necessary library symbols; they are noted "INFRINGES ON USER NAME SPACE" below. */ /* Identify Bison output. */ #define YYBISON 1 /* Skeleton name. */ #define YYSKELETON_NAME "yacc.c" /* Pure parsers. */ #define YYPURE 0 /* Using locations. */ #define YYLSP_NEEDED 0 /* Tokens. */ #ifndef YYTOKENTYPE # define YYTOKENTYPE /* Put the tokens into the symbol table, so that GDB and other debuggers know about them. */ enum yytokentype { ACCEPT_FROM_HOST_T = 258, CLASS_T = 259, COMMA = 260, EOL = 261, ISP_IP_T = 262, LISTEN_AS_HOST_T = 263, LISTEN_ON_PORT_T = 264, LISTEN_ON_USOCKET_T = 265, LOG_FLAGS_T = 266, PRIORITY_T = 267, PROBE_NAME_T = 268, PROBE_TYPE_T = 269, PROTOCOL_T = 270, READ_FROM_FILE_T = 271, POLL_DIRECTORY_T = 272, REMAINDER_T = 273, SENSOR_PROBE_T = 274, SENSOR_T = 275, ID = 276, INTERFACE = 277, IPBLOCK = 278 }; #endif #define ACCEPT_FROM_HOST_T 258 #define CLASS_T 259 #define COMMA 260 #define EOL 261 #define ISP_IP_T 262 #define LISTEN_AS_HOST_T 263 #define LISTEN_ON_PORT_T 264 #define LISTEN_ON_USOCKET_T 265 #define LOG_FLAGS_T 266 #define PRIORITY_T 267 #define PROBE_NAME_T 268 #define PROBE_TYPE_T 269 #define PROTOCOL_T 270 #define READ_FROM_FILE_T 271 #define POLL_DIRECTORY_T 272 #define REMAINDER_T 273 #define SENSOR_PROBE_T 274 #define SENSOR_T 275 #define ID 276 #define INTERFACE 277 #define IPBLOCK 278 /* Copy the first part of user declarations. */ #line 1 "probeconfparse.y" /* ** Copyright (C) 2005-2007 by Carnegie Mellon University. ** ** @OPENSOURCE_HEADER_START@ ** ** Use of the SILK system and related source code is subject to the terms ** of the following licenses: ** ** GNU Public License (GPL) Rights pursuant to Version 2, June 1991 ** Government Purpose License Rights (GPLR) pursuant to DFARS 252.225-7013 ** ** NO WARRANTY ** ** ANY INFORMATION, MATERIALS, SERVICES, INTELLECTUAL PROPERTY OR OTHER ** PROPERTY OR RIGHTS GRANTED OR PROVIDED BY CARNEGIE MELLON UNIVERSITY ** PURSUANT TO THIS LICENSE (HEREINAFTER THE "DELIVERABLES") ARE ON AN ** "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY ** KIND, EITHER EXPRESS OR IMPLIED AS TO ANY MATTER INCLUDING, BUT NOT ** LIMITED TO, WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE, ** MERCHANTABILITY, INFORMATIONAL CONTENT, NONINFRINGEMENT, OR ERROR-FREE ** OPERATION. CARNEGIE MELLON UNIVERSITY SHALL NOT BE LIABLE FOR INDIRECT, ** SPECIAL OR CONSEQUENTIAL DAMAGES, SUCH AS LOSS OF PROFITS OR INABILITY ** TO USE SAID INTELLECTUAL PROPERTY, UNDER THIS LICENSE, REGARDLESS OF ** WHETHER SUCH PARTY WAS AWARE OF THE POSSIBILITY OF SUCH DAMAGES. ** LICENSEE AGREES THAT IT WILL NOT MAKE ANY WARRANTY ON BEHALF OF ** CARNEGIE MELLON UNIVERSITY, EXPRESS OR IMPLIED, TO ANY PERSON ** CONCERNING THE APPLICATION OF OR THE RESULTS TO BE OBTAINED WITH THE ** DELIVERABLES UNDER THIS LICENSE. ** ** Licensee hereby agrees to defend, indemnify, and hold harmless Carnegie ** Mellon University, its trustees, officers, employees, and agents from ** all claims or demands made against them (and any related losses, ** expenses, or attorney's fees) arising out of, or relating to Licensee's ** and/or its sub licensees' negligent use or willful misuse of or ** negligent conduct or willful misconduct regarding the Software, ** facilities, or other rights or assistance granted by Carnegie Mellon ** University under this License, including, but not limited to, any ** claims of product liability, personal injury, death, damage to ** property, or violation of any laws or regulations. ** ** Carnegie Mellon University Software Engineering Institute authored ** documents are sponsored by the U.S. Department of Defense under ** Contract F19628-00-C-0003. Carnegie Mellon University retains ** copyrights in all material produced under this contract. The U.S. ** Government retains a non-exclusive, royalty-free license to publish or ** reproduce these documents, or allow others to do so, for U.S. ** Government purposes only pursuant to the copyright license under the ** contract clause at 252.227.7013. ** ** @OPENSOURCE_HEADER_END@ */ /* ** Parser for probe configuration file ** */ #define DECLARE_IFMAP_VARIABLES 1 #include "silk.h" RCSIDENT("$SiLK: probeconfparse.y 6821 2007-04-06 16:20:51Z mthomas $"); #include "probeconf.h" #include "probeconfscan.h" #include "silk_site.h" #include "sksite.h" #include "libflowsource.h" /* LOCAL DEFINES AND TYPEDEFS */ /* Set DEBUG to 1 to enable debugging printf messasges, 0 otherwise. * Generally best to leave this commented out so gcc -DDEBUG=1 will * work */ /* #define DEBUG 1 */ /* Verify DEBUG is set */ #ifndef DEBUG # define DEBUG 0 #endif /* For printing messages when DEBUG is non-zero. Use as: * DEBUG_PRINTF(("x is %d\n", x)); * Note ((double parens)) */ #if DEBUG # define DEBUG_PRINTF(x) printf x #else # define DEBUG_PRINTF(x) #endif /* magic value used to denote that a uint16_t---which are stored in * uint32_t's in the parser---has not yet been given a value. */ #define UINT16_NO_VALUE 0x10000 /* 0xFFFF + 1 */ /* to avoid repeatedly creating and destroying number lists, we keep a * pool of free number_lists. this is the size of the pool. */ #define NUMBER_LIST_POOL_CAPACITY 16 /* as NUMBER_LIST_POOL_CAPACITY, except for lists of strings (char*) */ #define STRING_LIST_POOL_CAPACITY 2 /* as NUMBER_LIST_POOL_CAPACITY, except for lists of wildcard ips */ #define WILDCARD_IP_LIST_POOL_CAPACITY 2 /* parsing a probe fills in this struct; then we use it to create an * skProbe. */ typedef struct { /* probe's name: either sensor name or based on type */ char *probe_name; /* empty if probe_name is unique, otherwise sensor name */ char uniq_prefix[3 + SK_MAX_STRLEN_SENSOR]; /* SNMP interface map */ number_list_t *interfaces[NUM_IFMAPS]; /* categorize based on IP blocks */ wildcard_ip_list_t *ipblocks[NUM_IFMAPS]; /* whether the ipblocks are negative blocks */ int negated[NUM_IFMAPS]; /* the list of ISP IPs; for 'forrouter' support */ number_list_t *isp_ip; /* index that should cover all IP-blocks or SNMP-interfaces not * covered by other indexes */ uint32_t remainder; /* priority for probe */ uint32_t priority; /* host to accept from */ name_ip_pair_t accept_from_host; /* IP to bind as when being to listen for connections */ in_addr_t listen_as_host; /* port to bind to when listening for connections */ uint32_t listen_on_port; /* path to unix domain socket to listen on */ char *listen_on_usocket; /* path to regular file to read data from */ char *read_from_file; /* path to directory to poll for newly inserted files */ char *poll_directory; /* number of errors encountered during parsing */ int error_count; /* first *-index seen */ int interface_first_seen; /* first *-ipblock seen */ int ipblock_first_seen; /* sensor id this probe collects for */ sensorID_t sid; /* the type of this probe */ probe_enum_t probe_type; /* the protocol of this probe */ probe_proto_t protocol; /* log flags for this probe */ uint32_t log_flags; } probe_attr_t; /* LOCAL FUNCTIONS */ /* wrappers around an sk_vector_t of integers, of skOctetMap_t*, and * of char* */ static number_list_t *number_list_new(void); static void number_list_append_value(number_list_t *nl, uint32_t value); static string_list_t *string_list_new(void); static void string_list_append_value(string_list_t *sl, char *value); static wildcard_ip_list_t *wildcard_ip_list_new(void); static void wildcard_ip_list_append_value( wildcard_ip_list_t *wipl, skOctetMap_t *value); /* add a new flag to the log flags */ static uint32_t log_flags_add_flag(uint32_t old_val, uint32_t value); /* create a sensor */ static void sensor_new_sensor(char *s, string_list_t *sl); /* functions to set attributes of a probe_attr_t */ static void sensor_probe(char *s); static void probe_name(char *s); static void probe_priority(uint32_t n); static void probe_probe_type(probe_enum_t t); static void probe_protocol(probe_proto_t t); static void probe_isp_ip(number_list_t *nl); static void probe_interface(uint32_t idx, number_list_t *nl); static void probe_ipblock( uint32_t idx, wildcard_ip_list_t *wipl, int negated); static void probe_listen_as_host(uint32_t a); static void probe_listen_on_port(uint32_t n); static void probe_listen_on_usocket(char *s); static void probe_read_from_file(char *s); static void probe_poll_directory(char *s); static void probe_accept_from_host(name_ip_pair_t *a); static void probe_log_flags(uint32_t n); /* functions to convert string input to another form */ static uint32_t parse_int_u16(const char *s); static uint32_t parse_ip_addr(const char *s); static skOctetMap_t *parse_wildcard_addr(const char *s); static name_ip_pair_t *parse_resolvable_host(const char *s); static probe_enum_t parse_probe_type(const char *s); static probe_proto_t parse_protocol(const char *s); static char *parse_sensor_name(const char *s); static uint32_t parse_log_flag(const char *s); /* LOCAL VARIABLES */ /* the size of the free number_list pool and the number of entries in * the pool. */ static number_list_t *number_list_pool[NUMBER_LIST_POOL_CAPACITY]; static int number_list_pool_count = 0; /* the size of the free string_list pool and the number of entries in * the pool. */ static string_list_t *string_list_pool[STRING_LIST_POOL_CAPACITY]; static int string_list_pool_count = 0; /* the size of the free wildcard_ip_list pool and the number of * entries in the pool. */ static wildcard_ip_list_t *wildcard_ip_list_pool[WILDCARD_IP_LIST_POOL_CAPACITY]; static int wildcard_ip_list_pool_count = 0; /* The parser works on a single global set of probe attributes */ static probe_attr_t g_static_probe; static probe_attr_t *p = &g_static_probe; /* Enabling traces. */ #ifndef YYDEBUG # define YYDEBUG 0 #endif /* Enabling verbose error messages. */ #ifdef YYERROR_VERBOSE # undef YYERROR_VERBOSE # define YYERROR_VERBOSE 1 #else # define YYERROR_VERBOSE 0 #endif #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) #line 230 "probeconfparse.y" typedef union YYSTYPE { char *string; number_list_t *u32_list; string_list_t *str_list; name_ip_pair_t *addr; wildcard_ip_list_t *omap_list; skOctetMap_t *oct_map; uint32_t u32; probe_enum_t p_type; probe_proto_t p_proto; } YYSTYPE; /* Line 191 of yacc.c. */ #line 364 "probeconfparse.c" # define yystype YYSTYPE /* obsolescent; will be withdrawn */ # define YYSTYPE_IS_DECLARED 1 # define YYSTYPE_IS_TRIVIAL 1 #endif /* Copy the second part of user declarations. */ /* Line 214 of yacc.c. */ #line 376 "probeconfparse.c" #if ! defined (yyoverflow) || YYERROR_VERBOSE # ifndef YYFREE # define YYFREE free # endif # ifndef YYMALLOC # define YYMALLOC malloc # endif /* The parser invokes alloca or malloc; define the necessary symbols. */ # ifdef YYSTACK_USE_ALLOCA # if YYSTACK_USE_ALLOCA # define YYSTACK_ALLOC alloca # endif # else # if defined (alloca) || defined (_ALLOCA_H) # define YYSTACK_ALLOC alloca # else # ifdef __GNUC__ # define YYSTACK_ALLOC __builtin_alloca # endif # endif # endif # ifdef YYSTACK_ALLOC /* Pacify GCC's `empty if-body' warning. */ # define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) # else # if defined (__STDC__) || defined (__cplusplus) # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # endif # define YYSTACK_ALLOC YYMALLOC # define YYSTACK_FREE YYFREE # endif #endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */ #if (! defined (yyoverflow) \ && (! defined (__cplusplus) \ || (defined (YYSTYPE_IS_TRIVIAL) && YYSTYPE_IS_TRIVIAL))) /* A type that is properly aligned for any stack member. */ union yyalloc { short yyss; YYSTYPE yyvs; }; /* The size of the maximum gap between one aligned stack and the next. */ # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) /* The size of an array large to enough to hold all stacks, each with N elements. */ # define YYSTACK_BYTES(N) \ ((N) * (sizeof (short) + sizeof (YYSTYPE)) \ + YYSTACK_GAP_MAXIMUM) /* Copy COUNT objects from FROM to TO. The source and destination do not overlap. */ # ifndef YYCOPY # if defined (__GNUC__) && 1 < __GNUC__ # define YYCOPY(To, From, Count) \ __builtin_memcpy (To, From, (Count) * sizeof (*(From))) # else # define YYCOPY(To, From, Count) \ do \ { \ register YYSIZE_T yyi; \ for (yyi = 0; yyi < (Count); yyi++) \ (To)[yyi] = (From)[yyi]; \ } \ while (0) # endif # endif /* Relocate STACK from its old location to the new one. The local variables YYSIZE and YYSTACKSIZE give the old and new number of elements in the stack, and YYPTR gives the new location of the stack. Advance YYPTR to a properly aligned location for the next stack. */ # define YYSTACK_RELOCATE(Stack) \ do \ { \ YYSIZE_T yynewbytes; \ YYCOPY (&yyptr->Stack, Stack, yysize); \ Stack = &yyptr->Stack; \ yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ yyptr += yynewbytes / sizeof (*yyptr); \ } \ while (0) #endif #if defined (__STDC__) || defined (__cplusplus) typedef signed char yysigned_char; #else typedef short yysigned_char; #endif /* YYFINAL -- State number of the termination state. */ #define YYFINAL 12 /* YYLAST -- Last index in YYTABLE. */ #define YYLAST 85 /* YYNTOKENS -- Number of terminals. */ #define YYNTOKENS 24 /* YYNNTS -- Number of nonterminals. */ #define YYNNTS 37 /* YYNRULES -- Number of rules. */ #define YYNRULES 67 /* YYNRULES -- Number of states. */ #define YYNSTATES 111 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ #define YYUNDEFTOK 2 #define YYMAXUTOK 278 #define YYTRANSLATE(YYX) \ ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ static const unsigned char yytranslate[] = { 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 }; #if YYDEBUG /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in YYRHS. */ static const unsigned char yyprhs[] = { 0, 0, 3, 5, 8, 10, 12, 14, 21, 24, 25, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 62, 66, 70, 74, 78, 82, 86, 90, 94, 98, 102, 106, 110, 114, 118, 122, 126, 128, 131, 135, 137, 139, 142, 146, 148, 150, 153, 157, 159, 161, 164, 168, 170, 172, 174, 176, 178, 180, 182, 185, 189 }; /* YYRHS -- A `-1'-separated list of the rules' RHS. */ static const yysigned_char yyrhs[] = { 25, 0, -1, 26, -1, 25, 26, -1, 1, -1, 27, -1, 28, -1, 20, 57, 6, 4, 48, 6, -1, 31, 29, -1, -1, 29, 30, -1, 33, -1, 32, -1, 34, -1, 35, -1, 36, -1, 37, -1, 38, -1, 39, -1, 40, -1, 41, -1, 42, -1, 43, -1, 44, -1, 45, -1, 1, -1, 19, 57, 6, -1, 12, 47, 6, -1, 13, 57, 6, -1, 14, 55, 6, -1, 15, 56, 6, -1, 7, 52, 6, -1, 22, 46, 6, -1, 22, 18, 6, -1, 23, 50, 6, -1, 23, 18, 6, -1, 8, 53, 6, -1, 9, 47, 6, -1, 10, 58, 6, -1, 16, 58, 6, -1, 17, 58, 6, -1, 3, 54, 6, -1, 11, 59, 6, -1, 47, -1, 46, 47, -1, 46, 5, 47, -1, 21, -1, 49, -1, 48, 49, -1, 48, 5, 49, -1, 21, -1, 51, -1, 50, 51, -1, 50, 5, 51, -1, 21, -1, 53, -1, 52, 53, -1, 52, 5, 53, -1, 21, -1, 21, -1, 21, -1, 21, -1, 21, -1, 21, -1, 60, -1, 59, 60, -1, 59, 5, 60, -1, 21, -1 }; /* YYRLINE[YYN] -- source line where rule number YYN was defined. */ static const unsigned short yyrline[] = { 0, 287, 287, 288, 289, 297, 298, 305, 316, 319, 320, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 346, 353, 358, 363, 368, 373, 378, 382, 387, 391, 396, 401, 406, 411, 416, 421, 426, 436, 442, 447, 453, 464, 470, 475, 481, 492, 498, 503, 510, 521, 527, 532, 539, 549, 559, 569, 579, 589, 599, 603, 608, 614 }; #endif #if YYDEBUG || YYERROR_VERBOSE /* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. First, the terminals, then, starting at YYNTOKENS, nonterminals. */ static const char *const yytname[] = { "$end", "error", "$undefined", "ACCEPT_FROM_HOST_T", "CLASS_T", "COMMA", "EOL", "ISP_IP_T", "LISTEN_AS_HOST_T", "LISTEN_ON_PORT_T", "LISTEN_ON_USOCKET_T", "LOG_FLAGS_T", "PRIORITY_T", "PROBE_NAME_T", "PROBE_TYPE_T", "PROTOCOL_T", "READ_FROM_FILE_T", "POLL_DIRECTORY_T", "REMAINDER_T", "SENSOR_PROBE_T", "SENSOR_T", "ID", "INTERFACE", "IPBLOCK", "$accept", "input", "input_block", "sensor_defn", "probe_defn", "probe_clauses", "probe_clause", "sensor_probe_clause", "priority_clause", "probe_name_clause", "probe_type_clause", "probe_protocol_clause", "isp_ip_clause", "interface_clause", "ipblock_clause", "listen_host_clause", "listen_port_clause", "listen_usocket_clause", "read_file_clause", "poll_directory_clause", "accept_host_clause", "log_flags_clause", "int_u16_list", "int_u16", "class_list", "class", "wildcard_ip_list", "wildcard_ip", "dotted_quad_list", "dotted_quad", "resolvable_host", "probe_type", "probe_protocol", "sensor_name", "syspath", "log_flags_list", "log_flag", 0 }; #endif # ifdef YYPRINT /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to token YYLEX-NUM. */ static const unsigned short yytoknum[] = { 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278 }; # endif /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ static const unsigned char yyr1[] = { 0, 24, 25, 25, 25, 26, 26, 27, 28, 29, 29, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 31, 32, 33, 34, 35, 36, 37, 37, 38, 38, 39, 40, 41, 42, 43, 44, 45, 46, 46, 46, 47, 48, 48, 48, 49, 50, 50, 50, 51, 52, 52, 52, 53, 54, 55, 56, 57, 58, 59, 59, 59, 60 }; /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ static const unsigned char yyr2[] = { 0, 2, 1, 2, 1, 1, 1, 6, 2, 0, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 1, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1 }; /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state STATE-NUM when YYTABLE doesn't specify something else to do. Zero means the default is an error. */ static const unsigned char yydefact[] = { 0, 4, 0, 0, 0, 2, 5, 6, 9, 62, 0, 0, 1, 3, 0, 26, 0, 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 12, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 0, 59, 0, 58, 0, 55, 0, 46, 0, 63, 0, 67, 0, 64, 0, 0, 60, 0, 61, 0, 0, 0, 0, 0, 43, 0, 54, 0, 51, 50, 0, 47, 41, 0, 31, 56, 36, 37, 38, 0, 42, 65, 27, 28, 29, 30, 39, 40, 33, 0, 32, 44, 35, 0, 34, 52, 0, 7, 48, 57, 66, 45, 53, 49 }; /* YYDEFGOTO[NTERM-NUM]. */ static const yysigned_char yydefgoto[] = { -1, 4, 5, 6, 7, 14, 32, 8, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 70, 55, 77, 78, 74, 75, 51, 52, 49, 64, 66, 10, 57, 59, 60 }; /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing STATE-NUM. */ #define YYPACT_NINF -74 static const yysigned_char yypact[] = { 14, -74, -9, -9, 7, -74, -74, -74, -74, -74, 12, 13, -74, -74, 40, -74, 24, -74, 16, 18, 18, 21, 23, 37, 21, -9, 47, 48, 23, 23, -8, -7, -74, -74, -74, -74, -74, -74, -74, -74, -74, -74, -74, -74, -74, -74, -74, 49, -74, 29, -74, 3, -74, 39, -74, 65, -74, 67, -74, 15, -74, 68, 69, -74, 70, -74, 71, 72, 73, 75, 17, -74, 77, -74, 59, -74, -74, 61, -74, -74, 18, -74, -74, -74, -74, -74, 37, -74, -74, -74, -74, -74, -74, -74, -74, -74, 21, -74, -74, -74, 63, -74, -74, 49, -74, -74, -74, -74, -74, -74, -74 }; /* YYPGOTO[NTERM-NUM]. */ static const yysigned_char yypgoto[] = { -74, -74, 81, -74, -74, -74, -74, -74, -74, -74, -74, -74, -74, -74, -74, -74, -74, -74, -74, -74, -74, -74, -74, -24, -74, -73, -74, -69, -74, -19, -74, -74, -74, 0, -12, -74, -57 }; /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If positive, shift that token. If negative, reduce the rule which number is the opposite. If zero, do what YYDEFACT says. If YYTABLE_NINF, syntax error. */ #define YYTABLE_NINF -9 static const yysigned_char yytable[] = { 61, 53, 88, 11, 105, 102, 71, 12, 80, 81, 69, 72, 9, 54, 73, 1, 67, 68, 15, 16, 86, 87, 96, 97, 50, 62, 2, 3, 47, 107, 110, 109, 82, 2, 3, 79, 58, 48, 54, 50, -8, 17, 54, 18, 56, 83, 98, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 58, -8, -8, 106, 30, 31, 100, 101, 103, 104, 63, 65, 76, 84, 108, 85, 89, 90, 91, 92, 93, 94, 73, 95, 76, 99, 73, 13 }; static const unsigned char yycheck[] = { 24, 20, 59, 3, 77, 74, 30, 0, 5, 6, 18, 18, 21, 21, 21, 1, 28, 29, 6, 6, 5, 6, 5, 6, 21, 25, 19, 20, 4, 86, 103, 100, 51, 19, 20, 6, 21, 21, 21, 21, 0, 1, 21, 3, 21, 6, 70, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 21, 19, 20, 80, 22, 23, 5, 6, 5, 6, 21, 21, 21, 6, 96, 6, 6, 6, 6, 6, 6, 6, 21, 6, 21, 6, 21, 4 }; /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing symbol of state STATE-NUM. */ static const unsigned char yystos[] = { 0, 1, 19, 20, 25, 26, 27, 28, 31, 21, 57, 57, 0, 26, 29, 6, 6, 1, 3, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 22, 23, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 4, 21, 54, 21, 52, 53, 53, 21, 47, 21, 58, 21, 59, 60, 47, 57, 21, 55, 21, 56, 58, 58, 18, 46, 47, 18, 21, 50, 51, 21, 48, 49, 6, 5, 6, 53, 6, 6, 6, 5, 6, 60, 6, 6, 6, 6, 6, 6, 6, 5, 6, 47, 6, 5, 6, 51, 5, 6, 49, 53, 60, 47, 51, 49 }; #if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) # define YYSIZE_T __SIZE_TYPE__ #endif #if ! defined (YYSIZE_T) && defined (size_t) # define YYSIZE_T size_t #endif #if ! defined (YYSIZE_T) # if defined (__STDC__) || defined (__cplusplus) # include /* INFRINGES ON USER NAME SPACE */ # define YYSIZE_T size_t # endif #endif #if ! defined (YYSIZE_T) # define YYSIZE_T unsigned int #endif #define yyerrok (yyerrstatus = 0) #define yyclearin (yychar = YYEMPTY) #define YYEMPTY (-2) #define YYEOF 0 #define YYACCEPT goto yyacceptlab #define YYABORT goto yyabortlab #define YYERROR goto yyerrorlab /* Like YYERROR except do call yyerror. This remains here temporarily to ease the transition to the new meaning of YYERROR, for GCC. Once GCC version 2 has supplanted version 1, this can go. */ #define YYFAIL goto yyerrlab #define YYRECOVERING() (!!yyerrstatus) #define YYBACKUP(Token, Value) \ do \ if (yychar == YYEMPTY && yylen == 1) \ { \ yychar = (Token); \ yylval = (Value); \ yytoken = YYTRANSLATE (yychar); \ YYPOPSTACK; \ goto yybackup; \ } \ else \ { \ yyerror ("syntax error: cannot back up");\ YYERROR; \ } \ while (0) #define YYTERROR 1 #define YYERRCODE 256 /* YYLLOC_DEFAULT -- Compute the default location (before the actions are run). */ #ifndef YYLLOC_DEFAULT # define YYLLOC_DEFAULT(Current, Rhs, N) \ ((Current).first_line = (Rhs)[1].first_line, \ (Current).first_column = (Rhs)[1].first_column, \ (Current).last_line = (Rhs)[N].last_line, \ (Current).last_column = (Rhs)[N].last_column) #endif /* YYLEX -- calling `yylex' with the right arguments. */ #ifdef YYLEX_PARAM # define YYLEX yylex (YYLEX_PARAM) #else # define YYLEX yylex () #endif /* Enable debugging if requested. */ #if YYDEBUG # ifndef YYFPRINTF # include /* INFRINGES ON USER NAME SPACE */ # define YYFPRINTF fprintf # endif # define YYDPRINTF(Args) \ do { \ if (yydebug) \ YYFPRINTF Args; \ } while (0) # define YYDSYMPRINT(Args) \ do { \ if (yydebug) \ yysymprint Args; \ } while (0) # define YYDSYMPRINTF(Title, Token, Value, Location) \ do { \ if (yydebug) \ { \ YYFPRINTF (stderr, "%s ", Title); \ yysymprint (stderr, \ Token, Value); \ YYFPRINTF (stderr, "\n"); \ } \ } while (0) /*------------------------------------------------------------------. | yy_stack_print -- Print the state stack from its BOTTOM up to its | | TOP (included). | `------------------------------------------------------------------*/ #if defined (__STDC__) || defined (__cplusplus) static void yy_stack_print (short *bottom, short *top) #else static void yy_stack_print (bottom, top) short *bottom; short *top; #endif { YYFPRINTF (stderr, "Stack now"); for (/* Nothing. */; bottom <= top; ++bottom) YYFPRINTF (stderr, " %d", *bottom); YYFPRINTF (stderr, "\n"); } # define YY_STACK_PRINT(Bottom, Top) \ do { \ if (yydebug) \ yy_stack_print ((Bottom), (Top)); \ } while (0) /*------------------------------------------------. | Report that the YYRULE is going to be reduced. | `------------------------------------------------*/ #if defined (__STDC__) || defined (__cplusplus) static void yy_reduce_print (int yyrule) #else static void yy_reduce_print (yyrule) int yyrule; #endif { int yyi; unsigned int yylno = yyrline[yyrule]; YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ", yyrule - 1, yylno); /* Print the symbols being reduced, and their result. */ for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++) YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]); YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]); } # define YY_REDUCE_PRINT(Rule) \ do { \ if (yydebug) \ yy_reduce_print (Rule); \ } while (0) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ int yydebug; #else /* !YYDEBUG */ # define YYDPRINTF(Args) # define YYDSYMPRINT(Args) # define YYDSYMPRINTF(Title, Token, Value, Location) # define YY_STACK_PRINT(Bottom, Top) # define YY_REDUCE_PRINT(Rule) #endif /* !YYDEBUG */ /* YYINITDEPTH -- initial size of the parser's stacks. */ #ifndef YYINITDEPTH # define YYINITDEPTH 200 #endif /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only if the built-in stack extension method is used). Do not make this value too large; the results are undefined if SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH) evaluated with infinite-precision integer arithmetic. */ #if defined (YYMAXDEPTH) && YYMAXDEPTH == 0 # undef YYMAXDEPTH #endif #ifndef YYMAXDEPTH # define YYMAXDEPTH 10000 #endif #if YYERROR_VERBOSE # ifndef yystrlen # if defined (__GLIBC__) && defined (_STRING_H) # define yystrlen strlen # else /* Return the length of YYSTR. */ static YYSIZE_T # if defined (__STDC__) || defined (__cplusplus) yystrlen (const char *yystr) # else yystrlen (yystr) const char *yystr; # endif { register const char *yys = yystr; while (*yys++ != '\0') continue; return yys - yystr - 1; } # endif # endif # ifndef yystpcpy # if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE) # define yystpcpy stpcpy # else /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in YYDEST. */ static char * # if defined (__STDC__) || defined (__cplusplus) yystpcpy (char *yydest, const char *yysrc) # else yystpcpy (yydest, yysrc) char *yydest; const char *yysrc; # endif { register char *yyd = yydest; register const char *yys = yysrc; while ((*yyd++ = *yys++) != '\0') continue; return yyd - 1; } # endif # endif #endif /* !YYERROR_VERBOSE */ #if YYDEBUG /*--------------------------------. | Print this symbol on YYOUTPUT. | `--------------------------------*/ #if defined (__STDC__) || defined (__cplusplus) static void yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep) #else static void yysymprint (yyoutput, yytype, yyvaluep) FILE *yyoutput; int yytype; YYSTYPE *yyvaluep; #endif { /* Pacify ``unused variable'' warnings. */ (void) yyvaluep; if (yytype < YYNTOKENS) { YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); # ifdef YYPRINT YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); # endif } else YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); switch (yytype) { default: break; } YYFPRINTF (yyoutput, ")"); } #endif /* ! YYDEBUG */ /*-----------------------------------------------. | Release the memory associated to this symbol. | `-----------------------------------------------*/ #if defined (__STDC__) || defined (__cplusplus) static void yydestruct (int yytype, YYSTYPE *yyvaluep) #else static void yydestruct (yytype, yyvaluep) int yytype; YYSTYPE *yyvaluep; #endif { /* Pacify ``unused variable'' warnings. */ (void) yyvaluep; switch (yytype) { default: break; } } /* Prevent warnings from -Wmissing-prototypes. */ #ifdef YYPARSE_PARAM # if defined (__STDC__) || defined (__cplusplus) int yyparse (void *YYPARSE_PARAM); # else int yyparse (); # endif #else /* ! YYPARSE_PARAM */ #if defined (__STDC__) || defined (__cplusplus) int yyparse (void); #else int yyparse (); #endif #endif /* ! YYPARSE_PARAM */ /* The lookahead symbol. */ int yychar; /* The semantic value of the lookahead symbol. */ YYSTYPE yylval; /* Number of syntax errors so far. */ int yynerrs; /*----------. | yyparse. | `----------*/ #ifdef YYPARSE_PARAM # if defined (__STDC__) || defined (__cplusplus) int yyparse (void *YYPARSE_PARAM) # else int yyparse (YYPARSE_PARAM) void *YYPARSE_PARAM; # endif #else /* ! YYPARSE_PARAM */ #if defined (__STDC__) || defined (__cplusplus) int yyparse (void) #else int yyparse () #endif #endif { register int yystate; register int yyn; int yyresult; /* Number of tokens to shift before error messages enabled. */ int yyerrstatus; /* Lookahead token as an internal (translated) token number. */ int yytoken = 0; /* Three stacks and their tools: `yyss': related to states, `yyvs': related to semantic values, `yyls': related to locations. Refer to the stacks thru separate pointers, to allow yyoverflow to reallocate them elsewhere. */ /* The state stack. */ short yyssa[YYINITDEPTH]; short *yyss = yyssa; register short *yyssp; /* The semantic value stack. */ YYSTYPE yyvsa[YYINITDEPTH]; YYSTYPE *yyvs = yyvsa; register YYSTYPE *yyvsp; #define YYPOPSTACK (yyvsp--, yyssp--) YYSIZE_T yystacksize = YYINITDEPTH; /* The variables used to return semantic value and location from the action routines. */ YYSTYPE yyval; /* When reducing, the number of symbols on the RHS of the reduced rule. */ int yylen; YYDPRINTF ((stderr, "Starting parse\n")); yystate = 0; yyerrstatus = 0; yynerrs = 0; yychar = YYEMPTY; /* Cause a token to be read. */ /* Initialize stack pointers. Waste one element of value and location stack so that they stay on the same level as the state stack. The wasted elements are never initialized. */ yyssp = yyss; yyvsp = yyvs; goto yysetstate; /*------------------------------------------------------------. | yynewstate -- Push a new state, which is found in yystate. | `------------------------------------------------------------*/ yynewstate: /* In all cases, when you get here, the value and location stacks have just been pushed. so pushing a state here evens the stacks. */ yyssp++; yysetstate: *yyssp = yystate; if (yyss + yystacksize - 1 <= yyssp) { /* Get the current used size of the three stacks, in elements. */ YYSIZE_T yysize = yyssp - yyss + 1; #ifdef yyoverflow { /* Give user a chance to reallocate the stack. Use copies of these so that the &'s don't force the real ones into memory. */ YYSTYPE *yyvs1 = yyvs; short *yyss1 = yyss; /* Each stack pointer address is followed by the size of the data in use in that stack, in bytes. This used to be a conditional around just the two extra args, but that might be undefined if yyoverflow is a macro. */ yyoverflow ("parser stack overflow", &yyss1, yysize * sizeof (*yyssp), &yyvs1, yysize * sizeof (*yyvsp), &yystacksize); yyss = yyss1; yyvs = yyvs1; } #else /* no yyoverflow */ # ifndef YYSTACK_RELOCATE goto yyoverflowlab; # else /* Extend the stack our own way. */ if (YYMAXDEPTH <= yystacksize) goto yyoverflowlab; yystacksize *= 2; if (YYMAXDEPTH < yystacksize) yystacksize = YYMAXDEPTH; { short *yyss1 = yyss; union yyalloc *yyptr = (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); if (! yyptr) goto yyoverflowlab; YYSTACK_RELOCATE (yyss); YYSTACK_RELOCATE (yyvs); # undef YYSTACK_RELOCATE if (yyss1 != yyssa) YYSTACK_FREE (yyss1); } # endif #endif /* no yyoverflow */ yyssp = yyss + yysize - 1; yyvsp = yyvs + yysize - 1; YYDPRINTF ((stderr, "Stack size increased to %lu\n", (unsigned long int) yystacksize)); if (yyss + yystacksize - 1 <= yyssp) YYABORT; } YYDPRINTF ((stderr, "Entering state %d\n", yystate)); goto yybackup; /*-----------. | yybackup. | `-----------*/ yybackup: /* Do appropriate processing given the current state. */ /* Read a lookahead token if we need one and don't already have one. */ /* yyresume: */ /* First try to decide what to do without reference to lookahead token. */ yyn = yypact[yystate]; if (yyn == YYPACT_NINF) goto yydefault; /* Not known => get a lookahead token if don't already have one. */ /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ if (yychar == YYEMPTY) { YYDPRINTF ((stderr, "Reading a token: ")); yychar = YYLEX; } if (yychar <= YYEOF) { yychar = yytoken = YYEOF; YYDPRINTF ((stderr, "Now at end of input.\n")); } else { yytoken = YYTRANSLATE (yychar); YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc); } /* If the proper action on seeing token YYTOKEN is to reduce or to detect an error, take that action. */ yyn += yytoken; if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) goto yydefault; yyn = yytable[yyn]; if (yyn <= 0) { if (yyn == 0 || yyn == YYTABLE_NINF) goto yyerrlab; yyn = -yyn; goto yyreduce; } if (yyn == YYFINAL) YYACCEPT; /* Shift the lookahead token. */ YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken])); /* Discard the token being shifted unless it is eof. */ if (yychar != YYEOF) yychar = YYEMPTY; *++yyvsp = yylval; /* Count tokens shifted since error; after three, turn off error status. */ if (yyerrstatus) yyerrstatus--; yystate = yyn; goto yynewstate; /*-----------------------------------------------------------. | yydefault -- do the default action for the current state. | `-----------------------------------------------------------*/ yydefault: yyn = yydefact[yystate]; if (yyn == 0) goto yyerrlab; goto yyreduce; /*-----------------------------. | yyreduce -- Do a reduction. | `-----------------------------*/ yyreduce: /* yyn is the number of a rule to reduce with. */ yylen = yyr2[yyn]; /* If YYLEN is nonzero, implement the default value of the action: `$$ = $1'. Otherwise, the following line sets YYVAL to garbage. This behavior is undocumented and Bison users should not rely upon it. Assigning to YYVAL unconditionally makes the parser a bit smaller, and it avoids a GCC warning that YYVAL may be used uninitialized. */ yyval = yyvsp[1-yylen]; YY_REDUCE_PRINT (yyn); switch (yyn) { case 4: #line 290 "probeconfparse.y" { skAppPrintErr((PARSE_MSG_ERROR "\tMisplaced or unrecognized keyword"), probescan_filename, probescan_line); } break; case 7: #line 306 "probeconfparse.y" { probe_end(); sensor_new_sensor(yyvsp[-4].string, yyvsp[-1].str_list); } break; case 25: #line 338 "probeconfparse.y" { skAppPrintErr((PARSE_MSG_ERROR "\tBad keyword or missing value"), probescan_filename, probescan_line); } break; case 26: #line 347 "probeconfparse.y" { probe_end(); probe_start(); sensor_probe(yyvsp[-1].string); } break; case 27: #line 354 "probeconfparse.y" { probe_priority(yyvsp[-1].u32); } break; case 28: #line 359 "probeconfparse.y" { probe_name(yyvsp[-1].string); } break; case 29: #line 364 "probeconfparse.y" { probe_probe_type(yyvsp[-1].p_type); } break; case 30: #line 369 "probeconfparse.y" { probe_protocol(yyvsp[-1].p_proto); } break; case 31: #line 374 "probeconfparse.y" { probe_isp_ip(yyvsp[-1].u32_list); } break; case 32: #line 379 "probeconfparse.y" { probe_interface(yyvsp[-2].u32, yyvsp[-1].u32_list); } break; case 33: #line 383 "probeconfparse.y" { probe_interface(yyvsp[-2].u32, NULL); } break; case 34: #line 388 "probeconfparse.y" { probe_ipblock(yyvsp[-2].u32, yyvsp[-1].omap_list, 0); } break; case 35: #line 392 "probeconfparse.y" { probe_ipblock(yyvsp[-2].u32, NULL, 0); } break; case 36: #line 397 "probeconfparse.y" { probe_listen_as_host(yyvsp[-1].u32); } break; case 37: #line 402 "probeconfparse.y" { probe_listen_on_port(yyvsp[-1].u32); } break; case 38: #line 407 "probeconfparse.y" { probe_listen_on_usocket(yyvsp[-1].string); } break; case 39: #line 412 "probeconfparse.y" { probe_read_from_file(yyvsp[-1].string); } break; case 40: #line 417 "probeconfparse.y" { probe_poll_directory(yyvsp[-1].string); } break; case 41: #line 422 "probeconfparse.y" { probe_accept_from_host(yyvsp[-1].addr); } break; case 42: #line 427 "probeconfparse.y" { probe_log_flags(yyvsp[-1].u32); } break; case 43: #line 437 "probeconfparse.y" { number_list_t *nl = number_list_new(); number_list_append_value(nl, yyvsp[0].u32); yyval.u32_list = nl; } break; case 44: #line 443 "probeconfparse.y" { number_list_append_value(yyvsp[-1].u32_list, yyvsp[0].u32); yyval.u32_list = yyvsp[-1].u32_list; } break; case 45: #line 448 "probeconfparse.y" { number_list_append_value(yyvsp[-2].u32_list, yyvsp[0].u32); yyval.u32_list = yyvsp[-2].u32_list; } break; case 46: #line 454 "probeconfparse.y" { yyval.u32 = parse_int_u16(yyvsp[0].string); } break; case 47: #line 465 "probeconfparse.y" { string_list_t *sl = string_list_new(); string_list_append_value(sl, yyvsp[0].string); yyval.str_list = sl; } break; case 48: #line 471 "probeconfparse.y" { string_list_append_value(yyvsp[-1].str_list, yyvsp[0].string); yyval.str_list = yyvsp[-1].str_list; } break; case 49: #line 476 "probeconfparse.y" { string_list_append_value(yyvsp[-2].str_list, yyvsp[0].string); yyval.str_list = yyvsp[-2].str_list; } break; case 50: #line 482 "probeconfparse.y" { yyval.string = strdup(yyvsp[0].string); } break; case 51: #line 493 "probeconfparse.y" { wildcard_ip_list_t *wipl = wildcard_ip_list_new(); wildcard_ip_list_append_value(wipl, yyvsp[0].oct_map); yyval.omap_list = wipl; } break; case 52: #line 499 "probeconfparse.y" { wildcard_ip_list_append_value(yyvsp[-1].omap_list, yyvsp[0].oct_map); yyval.omap_list = yyvsp[-1].omap_list; } break; case 53: #line 504 "probeconfparse.y" { wildcard_ip_list_append_value(yyvsp[-2].omap_list, yyvsp[0].oct_map); yyval.omap_list = yyvsp[-2].omap_list; } break; case 54: #line 511 "probeconfparse.y" { yyval.oct_map = parse_wildcard_addr(yyvsp[0].string); } break; case 55: #line 522 "probeconfparse.y" { number_list_t *nl = number_list_new(); number_list_append_value(nl, yyvsp[0].u32); yyval.u32_list = nl; } break; case 56: #line 528 "probeconfparse.y" { number_list_append_value(yyvsp[-1].u32_list, yyvsp[0].u32); yyval.u32_list = yyvsp[-1].u32_list; } break; case 57: #line 533 "probeconfparse.y" { number_list_append_value(yyvsp[-2].u32_list, yyvsp[0].u32); yyval.u32_list = yyvsp[-2].u32_list; } break; case 58: #line 540 "probeconfparse.y" { yyval.u32 = parse_ip_addr(yyvsp[0].string); } break; case 59: #line 550 "probeconfparse.y" { yyval.addr = parse_resolvable_host(yyvsp[0].string); } break; case 60: #line 560 "probeconfparse.y" { yyval.p_type = parse_probe_type(yyvsp[0].string); } break; case 61: #line 570 "probeconfparse.y" { yyval.p_proto = parse_protocol(yyvsp[0].string); } break; case 62: #line 580 "probeconfparse.y" { yyval.string = parse_sensor_name(yyval.string); } break; case 63: #line 590 "probeconfparse.y" { yyval.string = strdup(yyvsp[0].string); } break; case 64: #line 600 "probeconfparse.y" { yyval.u32 = yyvsp[0].u32; } break; case 65: #line 604 "probeconfparse.y" { uint32_t n = log_flags_add_flag(yyvsp[-1].u32, yyvsp[0].u32); yyval.u32 = n; } break; case 66: #line 609 "probeconfparse.y" { uint32_t n = log_flags_add_flag(yyvsp[-2].u32, yyvsp[0].u32); yyval.u32 = n; } break; case 67: #line 615 "probeconfparse.y" { yyval.u32 = parse_log_flag(yyvsp[0].string); } break; } /* Line 1000 of yacc.c. */ #line 1699 "probeconfparse.c" yyvsp -= yylen; yyssp -= yylen; YY_STACK_PRINT (yyss, yyssp); *++yyvsp = yyval; /* Now `shift' the result of the reduction. Determine what state that goes to, based on the state we popped back to and the rule number reduced by. */ yyn = yyr1[yyn]; yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) yystate = yytable[yystate]; else yystate = yydefgoto[yyn - YYNTOKENS]; goto yynewstate; /*------------------------------------. | yyerrlab -- here on detecting error | `------------------------------------*/ yyerrlab: /* If not already recovering from an error, report this error. */ if (!yyerrstatus) { ++yynerrs; #if YYERROR_VERBOSE yyn = yypact[yystate]; if (YYPACT_NINF < yyn && yyn < YYLAST) { YYSIZE_T yysize = 0; int yytype = YYTRANSLATE (yychar); const char* yyprefix; char *yymsg; int yyx; /* Start YYX at -YYN if negative to avoid negative indexes in YYCHECK. */ int yyxbegin = yyn < 0 ? -yyn : 0; /* Stay within bounds of both yycheck and yytname. */ int yychecklim = YYLAST - yyn; int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS; int yycount = 0; yyprefix = ", expecting "; for (yyx = yyxbegin; yyx < yyxend; ++yyx) if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) { yysize += yystrlen (yyprefix) + yystrlen (yytname [yyx]); yycount += 1; if (yycount == 5) { yysize = 0; break; } } yysize += (sizeof ("syntax error, unexpected ") + yystrlen (yytname[yytype])); yymsg = (char *) YYSTACK_ALLOC (yysize); if (yymsg != 0) { char *yyp = yystpcpy (yymsg, "syntax error, unexpected "); yyp = yystpcpy (yyp, yytname[yytype]); if (yycount < 5) { yyprefix = ", expecting "; for (yyx = yyxbegin; yyx < yyxend; ++yyx) if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) { yyp = yystpcpy (yyp, yyprefix); yyp = yystpcpy (yyp, yytname[yyx]); yyprefix = " or "; } } yyerror (yymsg); YYSTACK_FREE (yymsg); } else yyerror ("syntax error; also virtual memory exhausted"); } else #endif /* YYERROR_VERBOSE */ yyerror ("syntax error"); } if (yyerrstatus == 3) { /* If just tried and failed to reuse lookahead token after an error, discard it. */ if (yychar <= YYEOF) { /* If at end of input, pop the error token, then the rest of the stack, then return failure. */ if (yychar == YYEOF) for (;;) { YYPOPSTACK; if (yyssp == yyss) YYABORT; YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); yydestruct (yystos[*yyssp], yyvsp); } } else { YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc); yydestruct (yytoken, &yylval); yychar = YYEMPTY; } } /* Else will try to reuse lookahead token after shifting the error token. */ goto yyerrlab1; /*---------------------------------------------------. | yyerrorlab -- error raised explicitly by YYERROR. | `---------------------------------------------------*/ yyerrorlab: #ifdef __GNUC__ /* Pacify GCC when the user code never invokes YYERROR and the label yyerrorlab therefore never appears in user code. */ if (0) goto yyerrorlab; #endif yyvsp -= yylen; yyssp -= yylen; yystate = *yyssp; goto yyerrlab1; /*-------------------------------------------------------------. | yyerrlab1 -- common code for both syntax error and YYERROR. | `-------------------------------------------------------------*/ yyerrlab1: yyerrstatus = 3; /* Each real token shifted decrements this. */ for (;;) { yyn = yypact[yystate]; if (yyn != YYPACT_NINF) { yyn += YYTERROR; if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) { yyn = yytable[yyn]; if (0 < yyn) break; } } /* Pop the current state because it cannot handle the error token. */ if (yyssp == yyss) YYABORT; YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); yydestruct (yystos[yystate], yyvsp); YYPOPSTACK; yystate = *yyssp; YY_STACK_PRINT (yyss, yyssp); } if (yyn == YYFINAL) YYACCEPT; YYDPRINTF ((stderr, "Shifting error token, ")); *++yyvsp = yylval; yystate = yyn; goto yynewstate; /*-------------------------------------. | yyacceptlab -- YYACCEPT comes here. | `-------------------------------------*/ yyacceptlab: yyresult = 0; goto yyreturn; /*-----------------------------------. | yyabortlab -- YYABORT comes here. | `-----------------------------------*/ yyabortlab: yyresult = 1; goto yyreturn; #ifndef yyoverflow /*----------------------------------------------. | yyoverflowlab -- parser overflow comes here. | `----------------------------------------------*/ yyoverflowlab: yyerror ("parser stack overflow"); yyresult = 2; /* Fall through. */ #endif yyreturn: #ifndef yyoverflow if (yyss != yyssa) YYSTACK_FREE (yyss); #endif return yyresult; } #line 620 "probeconfparse.y" /* * ******************* SUPPORTING CODE ****************************** */ /* * ***** Number Lists *********************************************** * * * number_list, a sk_vector_t of uint32_t's */ /* get a new number_list from the free-pool; if pool is empty, create * a new one */ static number_list_t *number_list_new(void) { number_list_t *nl; /* if there are any in the pool, return one. Otherwise create one. */ if (number_list_pool_count) { --number_list_pool_count; nl = number_list_pool[number_list_pool_count]; skVectorClear(nl); } else { nl = skVectorNew(sizeof(uint32_t)); } return nl; } /* add the number_list to the free-pool. If the pool is full, just * destroy the number_list. */ static void number_list_destroy(number_list_t *nl) { /* If the pool is full, destroy the list we were handed; otherwise * add it to the pool. */ if (number_list_pool_count == NUMBER_LIST_POOL_CAPACITY) { skVectorDestroy(nl); } else { number_list_pool[number_list_pool_count] = nl; ++number_list_pool_count; } } /* remove all number_list's from the pool and destroy them */ static void number_list_pool_empty(void) { int i; for (i = 0; i < number_list_pool_count; ++i) { skVectorDestroy(number_list_pool[i]); } number_list_pool_count = 0; } /* append the value to the number_list */ static void number_list_append_value(number_list_t *nl, uint32_t value) { skVectorAppendValue(nl, &value); } /* get the number of entries in the number_list */ static size_t number_list_entries(number_list_t *nl) { return skVectorGetCount(nl); } /* get the value at the specified position */ static uint32_t number_list_get_value(number_list_t *nl, size_t position) { uint32_t val; skVectorGetValue(&val, nl, position); return val; } /* * ***** String Lists *********************************************** * * * string_list, a sk_vector_t of char*'s, where each char* is a strdup() */ /* get a new string_list from the free-pool; if pool is empty, create * a new one */ static string_list_t *string_list_new(void) { string_list_t *sl; /* if there are any in the pool, return one. Otherwise create one. */ if (string_list_pool_count) { --string_list_pool_count; sl = string_list_pool[string_list_pool_count]; skVectorClear(sl); } else { sl = skVectorNew(sizeof(char*)); } return sl; } /* add the string_list to the free-pool. If the pool is full, just * destroy the string_list. */ static void string_list_destroy(string_list_t *sl) { size_t i, c; char *s; /* free the strings in the vector */ c = skVectorGetCount(sl); for (i = 0; i < c; ++i) { skVectorGetValue(&s, sl, i); if (s != NULL) { free(s); } } /* If the pool is full, destroy the list we were handed; otherwise * add it to the pool. */ if (string_list_pool_count == STRING_LIST_POOL_CAPACITY) { skVectorDestroy(sl); } else { string_list_pool[string_list_pool_count] = sl; ++string_list_pool_count; } } /* remove all string_list's from the pool and destroy them */ static void string_list_pool_empty(void) { int i; for (i = 0; i < string_list_pool_count; ++i) { skVectorDestroy(string_list_pool[i]); } string_list_pool_count = 0; } /* append the value to the string_list */ static void string_list_append_value(string_list_t *sl, char *value) { skVectorAppendValue(sl, &value); } /* get the string of entries in the string_list */ static size_t string_list_entries(string_list_t *sl) { return skVectorGetCount(sl); } /* get the value at the specified position */ static const char* string_list_get_value(string_list_t *sl, size_t position) { char *val; skVectorGetValue(&val, sl, position); return val; } /* * ***** Wildcard IP Lists ****************************************** * * * wildcard_ip_list, an sk_vector_t of skOctetMap_t's */ /* get a new wildcard_ip_list from the free-pool; if pool is empty, * create a new one */ static wildcard_ip_list_t *wildcard_ip_list_new(void) { wildcard_ip_list_t *wipl; /* if there are any in the pool, return one. Otherwise create one. */ if (wildcard_ip_list_pool_count) { --wildcard_ip_list_pool_count; wipl = wildcard_ip_list_pool[wildcard_ip_list_pool_count]; skVectorClear(wipl); } else { wipl = skVectorNew(sizeof(skOctetMap_t*)); } return wipl; } /* add the wildcard_ip_list to the free-pool. If the pool is full, * just destroy the wildcard_ip_list. */ static void wildcard_ip_list_destroy(wildcard_ip_list_t *wipl) { size_t i, c; skOctetMap_t *omap; /* free the octet-maps in the vector */ c = skVectorGetCount(wipl); for (i = 0; i < c; ++i) { skVectorGetValue(&omap, wipl, i); if (omap != NULL) { free(omap); } } /* If the pool is full, destroy the list we were handed; otherwise * add it to the pool. */ if (wildcard_ip_list_pool_count == WILDCARD_IP_LIST_POOL_CAPACITY) { skVectorDestroy(wipl); } else { wildcard_ip_list_pool[wildcard_ip_list_pool_count] = wipl; ++wildcard_ip_list_pool_count; } } /* remove all wildcard_ip_list's from the pool and destroy them */ static void wildcard_ip_list_pool_empty(void) { int i; for (i = 0; i < wildcard_ip_list_pool_count; ++i) { skVectorDestroy(wildcard_ip_list_pool[i]); } wildcard_ip_list_pool_count = 0; } /* append the value to the wildcard_ip_list */ static void wildcard_ip_list_append_value( wildcard_ip_list_t *wipl, skOctetMap_t *value) { skVectorAppendValue(wipl, &value); } /* get the wildcard_ip of entries in the wildcard_ip_list */ static size_t wildcard_ip_list_entries(wildcard_ip_list_t *wipl) { return skVectorGetCount(wipl); } /* get the value at the specified position */ static skOctetMap_t *wildcard_ip_list_get_value( wildcard_ip_list_t *wipl, size_t position) { skOctetMap_t *omap; skVectorGetValue(&omap, wipl, position); return omap; } /* * ***** Sensors **************************************************** */ /* * sensor_new_sensor(name, class_list); * * Create sensor 'name' that belongs to classes 'class_list'. */ static void sensor_new_sensor(char *s, string_list_t *sl) { int rv = sksiteCreateTemporarySensor(s, (sk_vector_t*)sl); if (rv > 0) { /* invalid class */ skAppPrintErr((PARSE_MSG_ERROR "\tDo not recognize class name '%s'"), probescan_filename, probescan_line, string_list_get_value(sl, rv-1)); } else if (rv < 0) { switch (rv) { case -2: /* invalid sensor name */ skAppPrintErr((PARSE_MSG_ERROR "\tSensor name '%s' is not of correct form"), probescan_filename, probescan_line, s); break; case -3: /* duplicate sensor */ skAppPrintErr((PARSE_MSG_ERROR "\tA sensor named '%s' already exists"), probescan_filename, probescan_line, s); break; case -4: /* too many or too few classes */ if (string_list_entries(sl) == 0) { skAppPrintErr((PARSE_MSG_ERROR "\tNo classes given for test sensor '%s'"), probescan_filename, probescan_line, s); } else { skAppPrintErr((PARSE_MSG_ERROR "\tToo many classes given " "for test sensor '%s'"), probescan_filename, probescan_line, s); } break; case -1: /* bad input */ default: skAppPrintErr((PARSE_MSG_ERROR "\tUnexpected value from sksite: %d"), probescan_filename, probescan_line, rv); break; } } if (s) { free(s); s = NULL; } if (sl) { string_list_destroy(sl); } } /* * ***** Probes ***************************************************** */ /* print the probe attributes -- for debugging */ static void probe_print(void) { #if DEBUG size_t if_count; size_t isp_count; size_t i, j; DEBUG_PRINTF((("Got a probe (%d errors)\n" "\t probe_name = '%s'\n" "\t sensor_for_probe = '%u'\n" "\t priority = '%u'\n" "\t probe_type = '%u'\n" "\t protocol = '%u'\n"), p->error_count, p->probe_name, p->sid, p->priority, p->probe_type, p->protocol)); isp_count = ((p->isp_ip != NULL) ? number_list_entries(p->isp_ip) : 0); DEBUG_PRINTF(("\t isp_count = '%u'", (unsigned int)isp_count)); if (isp_count > 0) { for (i = 0; i < isp_count; ++i) { uint32_t val = number_list_get_value(p->isp_ip, i); DEBUG_PRINTF(("%s%u(%s)", ((0 == i) ? " [" : ","), val, num2dot(val))); } DEBUG_PRINTF(("]")); } DEBUG_PRINTF(("\n")); for (i = 0; i < NUM_IFMAPS; ++i) { if_count = ((p->interfaces[i] != NULL) ? number_list_entries(p->interfaces[i]) : 0); DEBUG_PRINTF(("\t interface_count[%lu] = '%lu'", i, if_count)); if (if_count > 0) { for (j = 0; j < if_count; ++j) { DEBUG_PRINTF(("%s%u", ((0 == j) ? " [" : ","), number_list_get_value(p->interfaces[i], j))); } DEBUG_PRINTF(("]")); } DEBUG_PRINTF(("\n")); } DEBUG_PRINTF((("\t listen_as_host = '%u' '%s'\n" "\t listen_on_port = '%u'\n" "\t listen_on_usocket = '%s'\n" "\t read_from_file = '%s'\n" "\t poll_directory = '%s'\n" "\t log_flags = '%u'\n"), p->listen_as_host, num2dot(p->listen_as_host), p->listen_on_port, (p->listen_on_usocket ? p->listen_on_usocket : "NULL"), (p->read_from_file ? p->read_from_file : "NULL"), (p->poll_directory ? p->poll_directory : "NULL"), p->log_flags)); DEBUG_PRINTF((("\t accept_from_host = '%s' '%u' '%s'\n"), (p->accept_from_host.name ? p->accept_from_host.name : "NULL"), p->accept_from_host.ip, num2dot(p->accept_from_host.ip))); #endif /* DEBUG */ } /* Take all the data on the global probe_attr_t and use it to create a * new skProbe. */ static void probe_attr_to_sk_probe(void) { probe_def_t *probe = NULL; int rv = 0; size_t i; rv = skProbeCreate(&probe); if (rv) { goto END; } rv = skProbeSetSensor(probe, p->sid); if (rv) { goto END; } rv = skProbeSetName(probe, p->probe_name); if (rv) { goto END; } if (p->priority != UINT16_NO_VALUE) { rv = skProbeSetPriority(probe, p->priority); if (rv) { goto END; } } if (p->probe_type != PROBE_ENUM_INVALID) { rv = skProbeSetType(probe, p->probe_type); if (rv) { goto END; } } if (p->protocol != PROBE_PROTO_UNSET) { rv = skProbeSetProtocol(probe, p->protocol); if (rv) { goto END; } } if (p->isp_ip) { rv = skProbeSetIspIps(probe, p->isp_ip); if (rv) { goto END; } } if (p->log_flags != UINT16_NO_VALUE) { rv = skProbeSetLogFlags(probe, p->log_flags); if (rv) { goto END; } } for (i = 0; i < NUM_IFMAPS; ++i) { if (p->interfaces[i]) { rv = skProbeSetInterfaces(probe, p->interfaces[i], i); if (rv) { goto END; } } else if (p->ipblocks[i]) { rv = skProbeSetIpBlock(probe, p->ipblocks[i], p->negated[i], i); if (rv) { goto END; } /* the probe is now managing the skOctetMap_t's; clear the * vector of ipblocks so the maps do not get * deallocated. */ skVectorClear(p->ipblocks[i]); } } if (p->remainder != UINT16_NO_VALUE) { if (p->ipblock_first_seen != UINT16_NO_VALUE) { rv = skProbeSetIpBlockRemainingIps(probe, p->remainder); } else { assert(p->interface_first_seen != UINT16_NO_VALUE); rv = skProbeSetInterfaceToRemainder(probe, p->remainder); } if (rv) { goto END; } } if (p->listen_as_host) { rv = skProbeSetListenAsAddr(probe, p->listen_as_host); if (rv) { goto END; } } if (p->listen_on_port != UINT16_NO_VALUE) { rv = skProbeSetListenOnPort(probe, p->listen_on_port); if (rv) { goto END; } } if (p->listen_on_usocket) { rv = skProbeSetListenOnUnixDomainSocket(probe, p->listen_on_usocket); if (rv) { goto END; } } if (p->read_from_file) { rv = skProbeSetFileSource(probe, p->read_from_file); if (rv) { goto END; } } if (p->poll_directory) { rv = 0 /* skProbeSetPollDirectory(probe, p->poll_directory) */; if (rv) { goto END; } } if (p->accept_from_host.name) { rv = skProbeSetAcceptFromHost(probe, p->accept_from_host.name, p->accept_from_host.ip); if (rv) { goto END; } } rv = probeConfProbeVerify(probe); END: if ((rv != 0) && (NULL != probe)) { ++g_probe_err; skProbeDestroy(&probe); } } /* This should be called just before starting a new probe and when we * finish reading a file (to complete the last probe). It will try to * convert the data from config file---which is stored in the global * probe_attr_t---to an skProbe, and then it will free() all memory * the parser has allocated for this probe_attr_t */ void probe_end(void) { int i; if (p->probe_name != NULL) { probe_print(); if (p->error_count == 0) { probe_attr_to_sk_probe(); } } /* Free everything we allocated */ if (p->probe_name) { free(p->probe_name); } if (p->isp_ip) { number_list_destroy(p->isp_ip); } for (i = 0; i < NUM_IFMAPS; ++i) { if (p->interfaces[i]) { number_list_destroy(p->interfaces[i]); } } if (p->listen_on_usocket) { free(p->listen_on_usocket); } if (p->accept_from_host.name) { free(p->accept_from_host.name); } memset(p, 0, sizeof(probe_attr_t)); } /* Begin a new probe by setting the memory of the global probe_attr_t * into its initial state. */ void probe_start(void) { memset(p, 0, sizeof(probe_attr_t)); p->priority = UINT16_NO_VALUE; p->probe_type = PROBE_ENUM_INVALID; p->protocol = PROBE_PROTO_UNSET; p->listen_on_port = UINT16_NO_VALUE; p->sid = SK_INVALID_SENSOR; p->remainder = UINT16_NO_VALUE; p->interface_first_seen = UINT16_NO_VALUE; p->ipblock_first_seen = UINT16_NO_VALUE; p->log_flags = UINT16_NO_VALUE; } /* * sensor_probe(sensor_name); * * Start a new probe that belongs to the sensor 'sensor_name'. Set * the probe's name to 'sensor_name' as well. */ static void sensor_probe(char *s) { /* see if this is a defined sensor */ p->sid = sksiteSensorLookup(s); if (p->sid == SK_INVALID_SENSOR) { skAppPrintErr((PARSE_MSG_ERROR "\tName '%s' is not the name of a sensor"), probescan_filename, probescan_line, s); ++p->error_count; } /* Set the probe's name to 's' */ p->probe_name = s; } /* * probe_name(probe_name); * * Set the name of the global probe to 'probe_name'. */ static void probe_name(char *s) { size_t len; /* name is legal? */ if (0 != sksiteSensorNameIsLegal(s)) { /* message already printed */ ++p->error_count; } if (p->probe_name) { free(p->probe_name); } /* store info */ p->probe_name = s; /* set the unique prefix used when printing error messages, but * don't set it if the probe-name is the same as the probe's * sensor */ if (p->sid != SK_INVALID_SENSOR && sksiteSensorLookup(s) != p->sid) { /* probe's name is different than sensor's name */ if ( sksiteSensorExists(p->sid) ) { sksiteSensorGetName(p->uniq_prefix, sizeof(p->uniq_prefix), p->sid); len = strlen(p->uniq_prefix); assert(len <= SK_MAX_STRLEN_SENSOR); p->uniq_prefix[len] = '/'; p->uniq_prefix[len+1] = '\0'; } } } /* * probe_priority(n); * * Set the priority of the global probe to n. */ static void probe_priority(uint32_t n) { /* see if parser got valid value(s) */ if (n == UINT16_NO_VALUE) { /* error msg printed by parser */ ++p->error_count; return; } /* check for value out of range */ if (n > PROBE_MAX_PRIORITY) { skAppPrintErr((PARSE_MSG_ERROR "\tPriority %u too large; use 0 <= n <= %d"), probescan_filename, probescan_line, n, PROBE_MAX_PRIORITY); ++p->error_count; return; } /* warn on overwrite */ if (p->priority != UINT16_NO_VALUE) { skAppPrintErr((PARSE_MSG_WARN "\tOverwriting previous %s value for probe %s%s"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name); } /* store info */ p->priority = n; } /* * probe_probe_type(t); * * Set the probe-type of the global probe to 't'. */ static void probe_probe_type(probe_enum_t t) { /* see if parser got valid value(s) */ if (t == PROBE_ENUM_INVALID) { /* error msg printed by parser */ ++p->error_count; return; } /* warn on overwrite */ if (p->probe_type != PROBE_ENUM_INVALID) { skAppPrintErr((PARSE_MSG_WARN "\tOverwriting previous %s value for probe %s%s"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name); } /* store info */ p->probe_type = t; } /* * probe_protocol(t); * * Set the probe-type of the global probe to 't'. */ static void probe_protocol(probe_proto_t t) { /* see if parser got valid value(s) */ if (t == PROBE_PROTO_UNSET) { /* error msg printed by parser */ ++p->error_count; return; } /* warn on overwrite */ if (p->protocol != PROBE_PROTO_UNSET) { skAppPrintErr((PARSE_MSG_WARN "\tOverwriting previous %s value for probe %s%s"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name); } /* store info */ p->protocol = t; } /* * probe_isp_ip(list); * * Set the isp-ip's on the global probe to 'list'. */ static void probe_isp_ip(number_list_t *nl) { size_t i; size_t count = number_list_entries(nl); uint32_t val; /* see if parser got valid value(s) */ for (i = 0; i < count; ++i) { val = number_list_get_value(nl, i); if (val == 0) { ++p->error_count; return; } } /* warn on overwrite */ if (p->isp_ip != NULL) { skAppPrintErr((PARSE_MSG_WARN "\tOverwriting previous %s value for probe %s%s"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name); number_list_destroy(p->isp_ip); } /* store info */ p->isp_ip = nl; } /* * probe_interface(idx, list); * * Set the ifmap-interface list indexed by 'idx' on the global * probe to 'list'. * * If 'list' is NULL, set the ifmap-interface list to all the * indexes NOT listed on other interfaces---set it to the * 'remainder' of the interfaces. */ static void probe_interface(uint32_t idx, number_list_t *nl) { size_t i; size_t count; uint32_t val; assert(idx < NUM_IFMAPS); if (nl) { count = number_list_entries(nl); /* see if parser got valid value(s) */ for (i = 0; i < count; ++i) { val = number_list_get_value(nl, i); if (val == UINT16_NO_VALUE) { ++p->error_count; return; } } } /* cannot set interface when ip-block already set */ if (p->ipblock_first_seen != UINT16_NO_VALUE) { skAppPrintErr((PARSE_MSG_ERROR "\tCannot set %s for probe %s%s because\n" "\t%s-index was previously set"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name, ifmap_group_id_name[p->ipblock_first_seen]); ++p->error_count; return; } /* only one interface may contain the remainding SNMP values */ if ((nl == NULL) && (p->remainder != UINT16_NO_VALUE)) { if (p->remainder == idx) { /* repeated: "foo-index remainder". ignore */ return; } skAppPrintErr((PARSE_MSG_ERROR "\tCannot set %s for probe %s%s because\n" "\tthe %s interface has already claimed the" "remaining SNMP values"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name, ifmap_group_id_name[p->remainder]); ++p->error_count; return; } /* warn on overwrite */ if (p->interfaces[idx] != NULL) { skAppPrintErr((PARSE_MSG_WARN "\tOverwriting previous %s value for probe %s%s"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name); number_list_destroy(p->interfaces[idx]); p->interfaces[idx] = NULL; } else if (p->remainder == idx) { skAppPrintErr((PARSE_MSG_WARN "\tOverwriting previous %s value for probe %s%s"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name); p->remainder = UINT16_NO_VALUE; } /* store info */ if (nl) { p->interfaces[idx] = nl; } else { p->remainder = idx; } if (p->interface_first_seen == UINT16_NO_VALUE) { p->interface_first_seen = idx; } } /* * probe_ipblock(idx, ip_list, negated); * * When 'ip_list' is NULL, set a flag for this 'idx' noting that * its interface-ipblock list should be set to any IP addresses not * covered by other IP blocks. * * When 'negated' is 0, set the interface-ipblocks for the * 'idx' interface of the global probe to 'ip_list'. * * When negated is non-zero, set the interface-ipblocks for the * 'idx' interface of the global probe to the inverse of 'ip_list'. */ static void probe_ipblock( uint32_t idx, wildcard_ip_list_t *wipl, int negated) { size_t i; size_t count; skOctetMap_t *val; assert(idx < NUM_IFMAPS); if (wipl) { count = wildcard_ip_list_entries(wipl); /* see if parser got valid value(s) */ for (i = 0; i < count; ++i) { val = wildcard_ip_list_get_value(wipl, i); if (val == NULL) { ++p->error_count; return; } } } /* cannot set ip-block when interface already set */ if (p->interface_first_seen != UINT16_NO_VALUE) { skAppPrintErr((PARSE_MSG_ERROR "\tCannot set %s for probe %s%s because\n" "\t%s-index was previously set"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name, ifmap_group_id_name[p->interface_first_seen]); ++p->error_count; return; } /* only one interface may contain the remainding IPs */ if ((wipl == NULL) && (p->remainder != UINT16_NO_VALUE)) { if (p->remainder == idx) { /* repeated: "foo-ipblock remainder". ignore */ return; } skAppPrintErr((PARSE_MSG_ERROR "\tCannot set %s for probe %s%s because\n" "\tthe %s interface has already claimed the" "remaining IP space"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name, ifmap_group_id_name[p->remainder]); ++p->error_count; return; } /* warn on overwrite */ if (p->ipblocks[idx] != NULL) { skAppPrintErr((PARSE_MSG_WARN "\tOverwriting previous %s value for probe %s%s"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name); wildcard_ip_list_destroy(p->ipblocks[idx]); p->ipblocks[idx] = NULL; } else if (p->remainder == idx) { skAppPrintErr((PARSE_MSG_WARN "\tOverwriting previous %s value for probe %s%s"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name); p->remainder = UINT16_NO_VALUE; } /* store info */ if (wipl) { p->negated[idx] = negated; p->ipblocks[idx] = wipl; } else { p->remainder = idx; } if (p->ipblock_first_seen == UINT16_NO_VALUE) { p->ipblock_first_seen = idx; } } /* * probe_listen_as_host(n); * * Set the global probe to listen for flows as the host IP 'n'. */ static void probe_listen_as_host(uint32_t n) { /* see if parser got valid value(s) */ if (n == 0) { /* error msg printed by parser */ ++p->error_count; return; } /* warn on overwrite */ if (p->listen_as_host != 0) { skAppPrintErr((PARSE_MSG_WARN "\tOverwriting previous %s value for probe %s%s"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name); } /* store info */ p->listen_as_host = n; } /* * probe_listen_on_port(n); * * Set the global probe to listen for flows on port 'n'. */ static void probe_listen_on_port(uint32_t n) { /* see if parser got valid value(s) */ if (n == UINT16_NO_VALUE) { /* error msg printed by parser */ ++p->error_count; return; } /* warn on overwrite */ if (p->listen_on_port != UINT16_NO_VALUE) { skAppPrintErr((PARSE_MSG_WARN "\tOverwriting previous %s value for probe %s%s"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name); } /* store info */ p->listen_on_port = n; } /* * probe_listen_on_usocket(s); * * Set the global probe to listen for flows on the unix domain socket 's'. */ static void probe_listen_on_usocket(char *s) { /* warn on overwrite */ if (p->listen_on_usocket != NULL) { skAppPrintErr((PARSE_MSG_WARN "\tOverwriting previous %s value for probe %s%s"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name); } /* store info; we already made a copy of 's' */ p->listen_on_usocket = s; } /* * probe_read_from_file(s); * * Set the global probe to read flows from the file 's'. */ static void probe_read_from_file(char *s) { /* warn on overwrite */ if (p->read_from_file != NULL) { skAppPrintErr((PARSE_MSG_WARN "\tOverwriting previous %s value for probe %s%s"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name); } /* store info; we already made a copy of 's' */ p->read_from_file = s; } /* * probe_poll_directory(s); * * Set the global probe to read flows from files that appear in the * directory 's'. */ static void probe_poll_directory(char *s) { /* warn on overwrite */ if (p->poll_directory != NULL) { skAppPrintErr((PARSE_MSG_WARN "\tOverwriting previous %s value for probe %s%s"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name); } /* store info; we already made a copy of 's' */ p->poll_directory = s; } /* * probe_accept_from_host(a); * * Set the global probe to accept data from the host a. */ static void probe_accept_from_host(name_ip_pair_t *a) { /* see if parser got valid value(s) */ if (a->ip == 0) { /* error msg printed by parser */ ++p->error_count; if (a->name) { free(a->name); } } else { /* warn on overwrite */ if (p->accept_from_host.name != NULL) { skAppPrintErr((PARSE_MSG_WARN "\tOverwriting previous %s value for probe %s%s"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name); free(p->accept_from_host.name); } /* store info */ p->accept_from_host.ip = a->ip; p->accept_from_host.name = a->name; } a->name = NULL; } /* * probe_log_flags(n); * * Set the log flags on the probe to 'n'; */ static void probe_log_flags(uint32_t n) { /* warn on overwrite */ if (p->log_flags != UINT16_NO_VALUE) { skAppPrintErr((PARSE_MSG_WARN "\tOverwriting previous %s value for probe %s%s"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name); } if (n == UINT16_NO_VALUE) { /* some error in parsing log flags */ ++p->error_count; } /* store value */ p->log_flags = n; } /* * val = parse_int_u16(s); * * Parse 's' as a integer from 0 to 0xFFFF inclusive. */ static uint32_t parse_int_u16(const char *s) { uint32_t num; int rv; rv = skStringParseUint32(&num, s, 0, 0xFFFF); if (rv == 0) { /* everything is good. */ } else if (rv == -12) { skAppPrintErr((PARSE_MSG_ERROR "\tValue (%s) for %s is too large; use 0 <= n < 65536"), probescan_filename, probescan_line, s, probescan_clause); num = UINT16_NO_VALUE; } else { skAppPrintErr((PARSE_MSG_ERROR "\tUnable to parse %s value '%s'"), probescan_filename, probescan_line, probescan_clause, s); num = UINT16_NO_VALUE; } return num; } /* * octet_map = parse_wildcard_addr(ip); * * Parse 'ip' as an IP address block in SiLK wildcard notation. * Because the scanner does not allow comma as part of an ID, we * will never see things like "10.20.30.40,50". * * Return the set of ips as an skOctetMap_t*, or NULL on error. */ static skOctetMap_t *parse_wildcard_addr(const char *s) { skOctetMap_t *omap; omap = malloc(sizeof(skOctetMap_t)); if (!omap) { return NULL; } if (skStringParseWildcardIP(omap, s)) { skAppPrintErr((PARSE_MSG_ERROR "\tCannot parse IP address block '%s'"), probescan_filename, probescan_line, s); free(omap); return NULL; } return omap; } /* * ip = parse_ip_addr(ip); * * Parse 'ip' as an IP address. Return the IP. */ static uint32_t parse_ip_addr(const char *s) { uint32_t num; if (skStringParseIP(&num, s)) { skAppPrintErr((PARSE_MSG_ERROR "\tCannot parse IP addresses '%s'"), probescan_filename, probescan_line, s); num = 0; } return num; } /* * name_ip = parse_resolvable_host(name); * * Parse 'name' as a resolvable host, i.e., pass 'name' to * gethostbyname(). Returns a pointer to a static struct that * contains the name and the IP address. */ static name_ip_pair_t *parse_resolvable_host(const char *s) { static name_ip_pair_t a = {(in_addr_t)0, NULL}; struct hostent *he; in_addr_t addr; if (a.name) { free(a.name); } memset(&a, 0, sizeof(name_ip_pair_t)); a.name = strdup(s); he = gethostbyname(s); if (he == NULL || he->h_length != sizeof(in_addr_t)) { skAppPrintErr((PARSE_MSG_ERROR "\tUnable to resolve %s value '%s'"), probescan_filename, probescan_line, probescan_clause, s); } else { memcpy(&addr, he->h_addr, sizeof(in_addr_t)); a.ip = ntohl(addr); } return &a; } /* * type = parse_probe_type(s); * * Parse 's' as the type of a probe. Return the type. */ static probe_enum_t parse_probe_type(const char *s) { probe_enum_t type; type = skProbetypeNameToEnum(s); if (type == PROBE_ENUM_INVALID) { skAppPrintErr((PARSE_MSG_ERROR "\tDo not recognize probe type '%s'"), probescan_filename, probescan_line, s); } return type; } /* * proto = parse_protocol(s); * * Parse 's' as a protocol. Return the protocol. */ static probe_proto_t parse_protocol(const char *s) { probe_proto_t proto = PROBE_PROTO_UNSET; uint32_t num; if (isdigit((int)*s)) { /* parse as a number */ if (skStringParseUint32(&num, s, 0, 255)) { skAppPrintErr((PARSE_MSG_ERROR "\tInvalid protocol value '%s'"), probescan_filename, probescan_line, s); } else { switch (num) { case 6: proto = PROBE_PROTO_TCP; break; case 17: proto = PROBE_PROTO_UDP; break; case 132: proto = PROBE_PROTO_SCTP; break; default: skAppPrintErr((PARSE_MSG_ERROR "\tInvalid protocol value '%u'"), probescan_filename, probescan_line, num); break; } } } else { proto = skProbeNameToProtocol(s); if (proto == PROBE_PROTO_UNSET) { skAppPrintErr((PARSE_MSG_ERROR "\tDo not recognize protocol '%s'"), probescan_filename, probescan_line, s); } } return proto; } /* * sensor_name = parse_sensor_name(s); * * Complain if 's' is an illegal sensor name. Return a copy of s. */ static char *parse_sensor_name(const char *s) { int rv; rv = sksiteSensorNameIsLegal(s); if (rv != 0) { if (rv > 0) { skAppPrintErr((PARSE_MSG_ERROR "\tSensor name '%s'" " contains the illegal character '%c'"), probescan_filename, probescan_line, s, s[rv-1]); } else if (rv == -1) { skAppPrintErr((PARSE_MSG_ERROR "\tSensor name '%s'" " is too short."), probescan_filename, probescan_line, s); } else if (rv == -2) { skAppPrintErr((PARSE_MSG_ERROR "\tSensor name '%s' " " is too long; only %d characters permitted."), probescan_filename, probescan_line, s, SK_MAX_STRLEN_SENSOR); } } return strdup(s); } /* * new_flags = log_flags_add_flag(old_flags, flag); * * Add 'flag' to the 'old_flags' and return the new flags. Warn if * either value is explicitly "NONE". */ static uint32_t log_flags_add_flag(uint32_t old_flags, uint32_t flag) { if ((old_flags == SOURCE_LOG_NONE) || (flag == SOURCE_LOG_NONE)) { skAppPrintErr((PARSE_MSG_ERROR "\tThe %s 'none' ignored when" " mixed with other values on probe %s%s"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name); } return (old_flags | flag); } /* * flag = parse_log_flag(s); * * Parse the string 's' as a log flag. */ static uint32_t parse_log_flag(const char *s) { if (!s || !*s) { skAppPrintErr((PARSE_MSG_ERROR "\tMissing value for %s on probe %s%s"), probescan_filename, probescan_line, probescan_clause, p->uniq_prefix, p->probe_name); return UINT16_NO_VALUE; } switch (*s) { case 'a': if (0 == strcmp(s, "all")) { return SOURCE_LOG_ALL; } break; case 'b': if (0 == strcmp(s, "bad")) { return SOURCE_LOG_BAD; } break; case 'm': if (0 == strcmp(s, "missing")) { return SOURCE_LOG_MISSING; } break; case 'n': if (0 == strcmp(s, "none")) { return SOURCE_LOG_NONE; } break; } skAppPrintErr((PARSE_MSG_ERROR "\tDo not recognize %s value '%s' on probe %s%s"), probescan_filename, probescan_line, probescan_clause, s, p->uniq_prefix, p->probe_name); return UINT16_NO_VALUE; } int yyerror(char UNUSED(*s)) { return 0; } void probeConfParseTeardown(void) { number_list_pool_empty(); string_list_pool_empty(); wildcard_ip_list_pool_empty(); } /* ** Local variables: ** mode:c ** indent-tabs-mode:nil ** c-basic-offset:4 ** End: */