diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | doc/guide/classify.xml | 6 | ||||
-rw-r--r-- | src/lib/eval/lexer.cc | 570 | ||||
-rw-r--r-- | src/lib/eval/lexer.ll | 20 | ||||
-rw-r--r-- | src/lib/eval/location.hh | 8 | ||||
-rw-r--r-- | src/lib/eval/parser.cc | 259 | ||||
-rw-r--r-- | src/lib/eval/parser.h | 59 | ||||
-rw-r--r-- | src/lib/eval/parser.yy | 6 | ||||
-rw-r--r-- | src/lib/eval/position.hh | 8 | ||||
-rw-r--r-- | src/lib/eval/stack.hh | 8 | ||||
-rw-r--r-- | src/lib/eval/tests/context_unittest.cc | 103 | ||||
-rw-r--r-- | src/lib/eval/tests/token_unittest.cc | 45 | ||||
-rw-r--r-- | src/lib/eval/token.cc | 22 | ||||
-rw-r--r-- | src/lib/eval/token.h | 23 |
14 files changed, 690 insertions, 452 deletions
@@ -1,3 +1,8 @@ +1090. [func] fdupont + Added support for IP address (IPv4 and IPv6) literals in + classification expressions. + (Trac #4232, git xxx) + 1089. [func] fdupont Added relay4[X].exists method in classifications that checks whether a sub-option is present in theDHCPv4 RAI (Relay Agent diff --git a/doc/guide/classify.xml b/doc/guide/classify.xml index e18e993e7e..fef363ed9b 100644 --- a/doc/guide/classify.xml +++ b/doc/guide/classify.xml @@ -159,6 +159,7 @@ <tbody> <row><entry>String</entry><entry>'example'</entry><entry>A string</entry></row> <row><entry>Hex String</entry><entry>0XABCD</entry><entry>A hexadecimal string</entry></row> +<row><entry>IP Address</entry><entry>10.0.0.1</entry><entry>An IP address</entry></row> <row><entry>Integer</entry><entry>123</entry><entry>An integer value</entry></row> <!-- Text option not fully defined yet, leave it out <row><entry>Option Text</entry><entry>option[code].text</entry><entry>The value of the option with code "code" from the packet as text</entry></row> @@ -178,6 +179,11 @@ sub-option with code "code" from the DHCPv4 Relay Agent Information option </para> <para> + IP addresses are converted into strings of length 4 or 16. IPv4, IPv6, + and IPv4 embedded IPv6 (e.g., IPv4 mapped IPv6) addresses are supported. + </para> + + <para> Integers in the expression are converted to strings when the expression is read into Kea. </para> diff --git a/src/lib/eval/lexer.cc b/src/lib/eval/lexer.cc index 1be686c8bc..369dc36ce7 100644 --- a/src/lib/eval/lexer.cc +++ b/src/lib/eval/lexer.cc @@ -17,8 +17,8 @@ #define FLEX_SCANNER #define YY_FLEX_MAJOR_VERSION 2 -#define YY_FLEX_MINOR_VERSION 6 -#define YY_FLEX_SUBMINOR_VERSION 0 +#define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_SUBMINOR_VERSION 35 #if YY_FLEX_SUBMINOR_VERSION > 0 #define FLEX_BETA #endif @@ -72,6 +72,7 @@ typedef int16_t flex_int16_t; typedef uint16_t flex_uint16_t; typedef int32_t flex_int32_t; typedef uint32_t flex_uint32_t; +typedef uint64_t flex_uint64_t; #else typedef signed char flex_int8_t; typedef short int flex_int16_t; @@ -79,6 +80,7 @@ typedef int flex_int32_t; typedef unsigned char flex_uint8_t; typedef unsigned short int flex_uint16_t; typedef unsigned int flex_uint32_t; +#endif /* ! C99 */ /* Limits of integral types. */ #ifndef INT8_MIN @@ -109,8 +111,6 @@ typedef unsigned int flex_uint32_t; #define UINT32_MAX (4294967295U) #endif -#endif /* ! C99 */ - #endif /* ! FLEXINT_H */ /* %endif */ @@ -185,15 +185,7 @@ typedef unsigned int flex_uint32_t; /* Size of default input buffer. */ #ifndef YY_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k. - * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. - * Ditto for the __ia64__ case accordingly. - */ -#define YY_BUF_SIZE 32768 -#else #define YY_BUF_SIZE 16384 -#endif /* __ia64__ */ #endif /* The state buf must be large enough to hold one state per character in the main buffer. @@ -233,18 +225,11 @@ extern FILE *yyin, *yyout; */ #define YY_LESS_LINENO(n) \ do { \ - int yyl;\ + yy_size_t yyl;\ for ( yyl = n; yyl < yyleng; ++yyl )\ if ( yytext[yyl] == '\n' )\ --yylineno;\ }while(0) - #define YY_LINENO_REWIND_TO(dst) \ - do {\ - const char *p;\ - for ( p = yy_cp-1; p >= (dst); --p)\ - if ( *p == '\n' )\ - --yylineno;\ - }while(0) /* Return all but the first "n" matched characters back to the input stream. */ #define yyless(n) \ @@ -435,7 +420,7 @@ void yyfree (void * ); /* %% [1.0] yytext/yyin/yyout/yy_state_type/yylineno etc. def's & init go here */ /* Begin user sect3 */ -#define yywrap() (/*CONSTCOND*/1) +#define yywrap(n) 1 #define YY_SKIP_YYWRAP #define FLEX_DEBUG @@ -451,21 +436,13 @@ extern int yylineno; int yylineno = 1; extern char *yytext; -#ifdef yytext_ptr -#undef yytext_ptr -#endif #define yytext_ptr yytext -/* %% [1.5] DFA */ - /* %if-c-only Standard (non-C++) definition */ static yy_state_type yy_get_previous_state (void ); static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); static int yy_get_next_buffer (void ); -#if defined(__GNUC__) && __GNUC__ >= 3 -__attribute__((__noreturn__)) -#endif static void yy_fatal_error (yyconst char msg[] ); /* %endif */ @@ -476,15 +453,15 @@ static void yy_fatal_error (yyconst char msg[] ); #define YY_DO_BEFORE_ACTION \ (yytext_ptr) = yy_bp; \ /* %% [2.0] code to fiddle yytext and yyleng for yymore() goes here \ */\ - yyleng = (size_t) (yy_cp - yy_bp); \ + yyleng = (yy_size_t) (yy_cp - yy_bp); \ (yy_hold_char) = *yy_cp; \ *yy_cp = '\0'; \ /* %% [3.0] code to copy yytext_ptr to yytext[] goes here, if %array \ */\ (yy_c_buf_p) = yy_cp; /* %% [4.0] data tables for the DFA and the user's section 1 definitions go here */ -#define YY_NUM_RULES 26 -#define YY_END_OF_BUFFER 27 +#define YY_NUM_RULES 27 +#define YY_END_OF_BUFFER 28 /* This struct is not used in this scanner, but its presence is necessary. */ struct yy_trans_info @@ -492,53 +469,56 @@ struct yy_trans_info flex_int32_t yy_verify; flex_int32_t yy_nxt; }; -static yyconst flex_int16_t yy_acclist[128] = +static yyconst flex_int16_t yy_acclist[138] = { 0, - 27, 25, 26, 1, 25, 26, 2, 26, 25, 26, - 20, 25, 26, 21, 25, 26, 24, 25, 26, 25, - 26, 19, 25, 26, 5, 25, 26, 5, 25, 26, - 25, 26, 25, 26,16390, 22, 25, 26, 23, 25, - 26, 25, 26,16390, 25, 26,16390, 25, 26,16390, - 25, 26,16390, 25, 26,16390, 25, 26,16390, 25, - 26,16390, 25, 26,16390, 25, 26,16390, 1, 2, - 3, 5, 7,16390, 8198,16390,16390,16390,16390,16390, - 16390,16390, 18,16390,16390,16390,16390, 4, 14,16390, - 17,16390,16390,16390, 11,16390, 16,16390,16390,16390, - - 16390,16390,16390,16390,16390,16390,16390, 10,16390,16390, - 16390,16390,16390,16390, 15,16390, 12,16390, 8,16390, - 9,16390,16390,16390,16390, 13,16390 + 28, 26, 27, 1, 26, 27, 2, 27, 26, 27, + 21, 26, 27, 22, 26, 27, 25, 26, 27, 26, + 27, 20, 26, 27, 5, 26, 27, 5, 26, 27, + 26, 27, 26, 27, 26, 27,16390, 26, 27,16390, + 23, 26, 27, 24, 26, 27, 26, 27,16390, 26, + 27,16390, 26, 27,16390, 26, 27,16390, 26, 27, + 16390, 26, 27,16390, 26, 27,16390, 26, 27,16390, + 26, 27,16390, 1, 2, 3, 5, 5, 7, 8, + 16390,16390, 8198,16390,16390,16390,16390,16390,16390,16390, + 19,16390,16390,16390,16390, 4, 7, 15,16390, 18, + + 16390,16390,16390, 12,16390, 17,16390,16390,16390,16390, + 16390,16390,16390,16390,16390,16390, 11,16390,16390,16390, + 16390,16390,16390, 16,16390, 13,16390, 9,16390, 10, + 16390,16390, 7,16390,16390, 14,16390 } ; -static yyconst flex_int16_t yy_accept[82] = +static yyconst flex_int16_t yy_accept[97] = { 0, 1, 1, 1, 2, 4, 7, 9, 11, 14, 17, - 20, 22, 25, 28, 31, 33, 36, 39, 42, 45, - 48, 51, 54, 57, 60, 63, 66, 69, 70, 71, - 71, 72, 73, 73, 74, 74, 74, 75, 76, 77, - 78, 79, 80, 81, 82, 83, 85, 86, 87, 88, - 89, 91, 93, 94, 95, 97, 99, 100, 101, 102, - 103, 104, 105, 106, 107, 108, 110, 111, 112, 113, - 114, 115, 117, 119, 121, 123, 124, 125, 126, 128, - 128 + 20, 22, 25, 28, 31, 33, 35, 38, 41, 44, + 47, 50, 53, 56, 59, 62, 65, 68, 71, 74, + 75, 76, 76, 77, 78, 78, 79, 79, 79, 79, + 79, 80, 81, 81, 81, 82, 83, 84, 85, 86, + 87, 88, 89, 90, 91, 93, 94, 95, 96, 96, + 97, 98, 100, 102, 103, 104, 106, 108, 109, 110, + 111, 112, 112, 113, 114, 115, 116, 117, 119, 119, + 120, 121, 122, 123, 124, 124, 126, 128, 130, 132, + 133, 134, 135, 136, 138, 138 + } ; -static yyconst YY_CHAR yy_ec[256] = +static yyconst flex_int32_t yy_ec[256] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 4, 5, 6, 1, 1, 7, 8, 9, 1, 10, 11, 11, - 11, 12, 11, 11, 11, 11, 11, 1, 1, 1, - 13, 1, 1, 1, 14, 14, 14, 14, 14, 14, - 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, - 15, 15, 15, 15, 15, 15, 15, 16, 15, 15, - 17, 1, 18, 1, 19, 1, 20, 21, 22, 23, - - 24, 14, 25, 26, 27, 15, 15, 28, 15, 29, - 30, 31, 15, 32, 33, 34, 35, 15, 15, 36, - 37, 15, 1, 1, 1, 1, 1, 1, 1, 1, + 11, 12, 11, 11, 11, 11, 11, 13, 1, 1, + 14, 1, 1, 1, 15, 15, 15, 15, 15, 15, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 17, 16, 16, + 18, 1, 19, 1, 20, 1, 21, 22, 23, 24, + + 25, 15, 26, 27, 28, 16, 16, 29, 16, 30, + 31, 32, 16, 33, 34, 35, 36, 16, 16, 37, + 38, 16, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -555,118 +535,116 @@ static yyconst YY_CHAR yy_ec[256] = 1, 1, 1, 1, 1 } ; -static yyconst YY_CHAR yy_meta[38] = +static yyconst flex_int32_t yy_meta[39] = { 0, - 1, 2, 3, 1, 1, 1, 1, 2, 1, 4, - 4, 4, 1, 4, 2, 2, 1, 2, 2, 4, - 4, 4, 4, 4, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2 + 1, 1, 2, 1, 1, 1, 1, 1, 3, 4, + 4, 4, 5, 1, 4, 1, 1, 1, 1, 1, + 4, 4, 4, 4, 4, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1 } ; -static yyconst flex_uint16_t yy_base[84] = +static yyconst flex_int16_t yy_base[101] = { 0, - 0, 0, 202, 219, 167, 155, 138, 219, 219, 219, - 28, 219, 31, 34, 94, 46, 219, 219, 66, 22, - 27, 29, 31, 44, 42, 51, 53, 103, 80, 74, - 219, 77, 0, 219, 88, 90, 68, 219, 70, 81, - 72, 84, 86, 92, 95, 74, 88, 104, 99, 0, - 102, 108, 112, 110, 116, 118, 121, 131, 124, 127, - 134, 136, 138, 143, 145, 147, 149, 153, 156, 175, - 160, 162, 165, 167, 169, 172, 177, 182, 180, 219, - 211, 214, 58 + 0, 0, 191, 192, 188, 186, 184, 192, 192, 192, + 29, 192, 33, 30, 174, 172, 69, 98, 192, 192, + 22, 154, 147, 158, 151, 27, 156, 144, 154, 176, + 174, 172, 192, 51, 54, 32, 162, 161, 0, 160, + 0, 192, 112, 114, 0, 0, 192, 143, 147, 140, + 141, 131, 132, 131, 0, 136, 142, 126, 64, 0, + 0, 0, 0, 139, 127, 0, 0, 132, 138, 124, + 122, 114, 135, 120, 123, 115, 117, 0, 118, 106, + 98, 88, 100, 54, 124, 0, 0, 0, 0, 55, + 127, 48, 42, 0, 192, 139, 141, 143, 49, 146 + } ; -static yyconst flex_int16_t yy_def[84] = +static yyconst flex_int16_t yy_def[101] = { 0, - 80, 1, 80, 80, 80, 80, 81, 80, 80, 80, - 80, 80, 80, 80, 80, 82, 80, 80, 82, 19, - 19, 19, 19, 19, 19, 19, 19, 80, 80, 81, - 80, 80, 83, 80, 80, 19, 19, 80, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 83, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 19, - 19, 19, 19, 19, 19, 19, 19, 19, 19, 0, - 80, 80, 80 + 95, 1, 95, 95, 95, 95, 96, 95, 95, 95, + 95, 95, 95, 13, 97, 95, 95, 17, 95, 95, + 17, 17, 17, 18, 18, 18, 18, 18, 18, 95, + 95, 96, 95, 95, 95, 13, 97, 98, 99, 97, + 100, 95, 95, 18, 17, 18, 95, 18, 18, 18, + 18, 18, 18, 18, 18, 18, 18, 18, 95, 99, + 100, 18, 18, 18, 18, 18, 18, 18, 18, 18, + 18, 95, 18, 18, 18, 18, 18, 18, 95, 18, + 18, 18, 18, 18, 95, 18, 18, 18, 18, 18, + 95, 18, 18, 18, 0, 95, 95, 95, 95, 95 + } ; -static yyconst flex_uint16_t yy_nxt[257] = +static yyconst flex_int16_t yy_nxt[231] = { 0, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, - 14, 14, 15, 16, 16, 16, 17, 18, 4, 19, - 16, 20, 16, 21, 16, 22, 16, 16, 23, 24, - 16, 25, 26, 27, 16, 16, 16, 32, 32, 32, - 32, 32, 32, 32, 32, 32, 33, 35, 35, 37, - 37, 41, 43, 36, 37, 37, 37, 37, 37, 37, - 44, 50, 42, 38, 36, 47, 33, 35, 35, 37, - 37, 37, 37, 36, 45, 46, 49, 31, 37, 37, - 37, 37, 29, 38, 36, 48, 32, 32, 32, 35, - 35, 80, 80, 39, 40, 37, 37, 51, 37, 37, - - 53, 37, 37, 52, 28, 38, 34, 80, 37, 37, - 54, 37, 37, 37, 37, 58, 37, 37, 37, 37, - 37, 55, 37, 37, 59, 56, 37, 37, 57, 37, - 37, 37, 37, 61, 60, 37, 37, 37, 37, 37, - 37, 31, 62, 37, 37, 37, 37, 63, 37, 37, - 64, 37, 37, 67, 37, 37, 65, 29, 37, 37, - 66, 37, 37, 37, 37, 37, 37, 69, 28, 68, - 37, 37, 37, 37, 37, 37, 37, 37, 71, 70, - 37, 37, 72, 37, 74, 73, 75, 37, 37, 37, - 37, 76, 37, 37, 37, 37, 37, 37, 77, 37, - - 37, 80, 37, 37, 37, 78, 79, 37, 37, 37, - 37, 30, 30, 80, 30, 37, 37, 37, 3, 80, - 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80 + 14, 14, 15, 16, 17, 18, 18, 19, 20, 4, + 21, 17, 22, 17, 23, 18, 24, 18, 18, 25, + 26, 18, 27, 28, 29, 18, 18, 18, 34, 34, + 34, 35, 36, 36, 36, 37, 95, 38, 95, 39, + 48, 49, 60, 38, 38, 38, 38, 38, 54, 55, + 34, 34, 34, 59, 59, 59, 95, 94, 95, 39, + 43, 43, 72, 59, 59, 59, 44, 93, 45, 45, + 45, 37, 92, 45, 46, 46, 90, 47, 44, 45, + 45, 45, 45, 45, 46, 46, 46, 46, 46, 46, + + 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, + 95, 89, 46, 43, 43, 95, 95, 88, 46, 46, + 46, 46, 46, 79, 79, 79, 85, 79, 79, 79, + 47, 87, 95, 91, 91, 91, 91, 91, 91, 32, + 86, 32, 32, 32, 40, 40, 38, 38, 61, 61, + 61, 84, 83, 82, 81, 80, 78, 77, 76, 75, + 74, 73, 71, 70, 69, 68, 67, 66, 65, 64, + 63, 62, 41, 37, 41, 33, 31, 30, 58, 57, + 56, 53, 52, 51, 50, 42, 41, 33, 31, 30, + 95, 3, 95, 95, 95, 95, 95, 95, 95, 95, + + 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, 95, 95 } ; -static yyconst flex_int16_t yy_chk[257] = +static yyconst flex_int16_t yy_chk[231] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 11, 11, 11, - 13, 13, 13, 14, 14, 14, 13, 16, 16, 20, - 20, 20, 22, 16, 21, 21, 22, 22, 23, 23, - 23, 83, 21, 16, 16, 25, 13, 19, 19, 25, - 25, 24, 24, 19, 24, 24, 27, 30, 26, 26, - 27, 27, 29, 19, 19, 26, 32, 32, 32, 35, - 35, 36, 36, 19, 19, 37, 37, 39, 39, 41, - - 41, 46, 46, 40, 28, 35, 15, 36, 40, 40, - 42, 42, 42, 43, 43, 47, 47, 36, 36, 44, - 44, 43, 45, 45, 48, 44, 49, 49, 45, 51, - 51, 48, 48, 53, 49, 52, 52, 54, 54, 53, - 53, 7, 54, 55, 55, 56, 56, 57, 57, 57, - 58, 59, 59, 61, 60, 60, 59, 6, 58, 58, - 60, 61, 61, 62, 62, 63, 63, 63, 5, 62, - 64, 64, 65, 65, 66, 66, 67, 67, 65, 64, - 68, 68, 67, 69, 69, 68, 70, 71, 71, 72, - 72, 71, 73, 73, 74, 74, 75, 75, 76, 76, - - 76, 3, 70, 70, 77, 77, 78, 79, 79, 78, - 78, 81, 81, 0, 81, 82, 82, 82, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80, 80, 80, 80, 80, - 80, 80, 80, 80, 80, 80 + 1, 1, 1, 1, 1, 1, 1, 1, 11, 11, + 11, 13, 13, 13, 13, 13, 14, 13, 36, 13, + 21, 21, 99, 13, 13, 13, 13, 13, 26, 26, + 34, 34, 34, 35, 35, 35, 14, 93, 36, 13, + 17, 17, 59, 59, 59, 59, 17, 92, 17, 17, + 17, 17, 90, 17, 17, 17, 84, 17, 17, 17, + 17, 17, 17, 17, 17, 17, 17, 17, 17, 17, + + 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, + 18, 83, 18, 43, 43, 44, 44, 82, 18, 18, + 18, 18, 18, 72, 72, 72, 79, 79, 79, 79, + 43, 81, 44, 85, 85, 85, 91, 91, 91, 96, + 80, 96, 96, 96, 97, 97, 98, 98, 100, 100, + 100, 77, 76, 75, 74, 73, 71, 70, 69, 68, + 65, 64, 58, 57, 56, 54, 53, 52, 51, 50, + 49, 48, 40, 38, 37, 32, 31, 30, 29, 28, + 27, 25, 24, 23, 22, 16, 15, 7, 6, 5, + 3, 95, 95, 95, 95, 95, 95, 95, 95, 95, + + 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, 95, 95, + 95, 95, 95, 95, 95, 95, 95, 95, 95, 95 } ; /* Table of booleans, true if rule could match eol. */ -static yyconst flex_int32_t yy_rule_can_match_eol[27] = +static yyconst flex_int32_t yy_rule_can_match_eol[28] = { 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, }; + 0, 0, 0, 0, 0, 0, 0, 0, }; extern int yy_flex_debug; int yy_flex_debug = 1; -static yyconst flex_int16_t yy_rule_linenum[26] = +static yyconst flex_int16_t yy_rule_linenum[27] = { 0, - 78, 82, 88, 98, 104, 118, 125, 126, 127, 128, - 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, - 139, 140, 141, 142, 144 + 82, 86, 92, 102, 108, 122, 129, 143, 144, 145, + 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, + 156, 157, 158, 159, 160, 162 } ; static yy_state_type *yy_state_buf=0, *yy_state_ptr=0; @@ -705,6 +683,7 @@ char *yytext; #include <string> #include <eval/eval_context.h> #include <eval/parser.h> +#include <asiolink/io_address.h> #include <boost/lexical_cast.hpp> // Work around an incompatibility in flex (at least versions @@ -737,13 +716,14 @@ static isc::eval::location loc; useful for client classes, which typically are one-liners, but it may be useful in more complex cases. */ /* These are not token expressions yet, just convenience expressions that - can be used during actual token definitions. */ -#line 65 "lexer.ll" + can be used during actual token definitions. Note some can match + incorrect inputs (e.g., IP addresses) which must be checked. */ +#line 69 "lexer.ll" // This code run each time a pattern is matched. It updates the location // by moving it ahead by yyleng bytes. yyleng specifies the length of the // currently matched token. #define YY_USER_ACTION loc.columns(yyleng); -#line 747 "lexer.cc" +#line 727 "lexer.cc" #define INITIAL 0 @@ -789,11 +769,11 @@ void yyset_extra (YY_EXTRA_TYPE user_defined ); FILE *yyget_in (void ); -void yyset_in (FILE * _in_str ); +void yyset_in (FILE * in_str ); FILE *yyget_out (void ); -void yyset_out (FILE * _out_str ); +void yyset_out (FILE * out_str ); yy_size_t yyget_leng (void ); @@ -801,7 +781,7 @@ char *yyget_text (void ); int yyget_lineno (void ); -void yyset_lineno (int _line_number ); +void yyset_lineno (int line_number ); /* %if-bison-bridge */ /* %endif */ @@ -820,9 +800,6 @@ extern int yywrap (void ); /* %not-for-header */ -#ifndef YY_NO_UNPUT - -#endif /* %ok-for-header */ /* %endif */ @@ -855,12 +832,7 @@ static int input (void ); /* Amount of stuff to slurp up with each read. */ #ifndef YY_READ_BUF_SIZE -#ifdef __ia64__ -/* On IA-64, the buffer size is 16k, not 8k */ -#define YY_READ_BUF_SIZE 16384 -#else #define YY_READ_BUF_SIZE 8192 -#endif /* __ia64__ */ #endif /* Copy whatever the last rule matched to the standard output. */ @@ -869,7 +841,7 @@ static int input (void ); /* This used to be an fputs(), but since the string might contain NUL's, * we now use fwrite(). */ -#define ECHO do { if (fwrite( yytext, yyleng, 1, yyout )) {} } while (0) +#define ECHO fwrite( yytext, yyleng, 1, yyout ) /* %endif */ /* %if-c++-only C++ definition */ /* %endif */ @@ -884,7 +856,7 @@ static int input (void ); if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ { \ int c = '*'; \ - size_t n; \ + yy_size_t n; \ for ( n = 0; n < max_size && \ (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ buf[n] = (char) c; \ @@ -973,7 +945,7 @@ extern int yylex (void); /* Code executed at the end of each rule. */ #ifndef YY_BREAK -#define YY_BREAK /*LINTED*/break; +#define YY_BREAK break; #endif /* %% [6.0] YY_RULE_SETUP definition goes here */ @@ -986,10 +958,21 @@ extern int yylex (void); */ YY_DECL { - yy_state_type yy_current_state; - char *yy_cp, *yy_bp; - int yy_act; + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; +/* %% [7.0] user's declarations go here */ +#line 75 "lexer.ll" + + + + // Code run each time yylex is called. + loc.step(); + + +#line 975 "lexer.cc" + if ( !(yy_init) ) { (yy_init) = 1; @@ -1030,19 +1013,7 @@ YY_DECL yy_load_buffer_state( ); } - { -/* %% [7.0] user's declarations go here */ -#line 71 "lexer.ll" - - - - // Code run each time yylex is called. - loc.step(); - - -#line 1044 "lexer.cc" - - while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ + while ( 1 ) /* loops until end-of-file is reached */ { /* %% [8.0] yymore()-related code goes here */ yy_cp = (yy_c_buf_p); @@ -1064,23 +1035,24 @@ YY_DECL yy_match: do { - YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 81 ) + if ( yy_current_state >= 96 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; *(yy_state_ptr)++ = yy_current_state; ++yy_cp; } - while ( yy_current_state != 80 ); + while ( yy_current_state != 95 ); yy_find_action: /* %% [10.0] code to find the action number goes here */ yy_current_state = *--(yy_state_ptr); (yy_lp) = yy_accept[yy_current_state]; +goto find_rule; /* Shut up GCC warning -Wall */ find_rule: /* we branch to this label when backing up */ for ( ; ; ) /* until we find what rule we matched */ { @@ -1138,13 +1110,13 @@ do_action: /* This label is used only to access EOF actions. */ { if ( yy_act == 0 ) fprintf( stderr, "--scanner backing up\n" ); - else if ( yy_act < 26 ) + else if ( yy_act < 27 ) fprintf( stderr, "--accepting rule at line %ld (\"%s\")\n", (long)yy_rule_linenum[yy_act], yytext ); - else if ( yy_act == 26 ) + else if ( yy_act == 27 ) fprintf( stderr, "--accepting default rule (\"%s\")\n", yytext ); - else if ( yy_act == 27 ) + else if ( yy_act == 28 ) fprintf( stderr, "--(end of buffer or a NUL)\n" ); else fprintf( stderr, "--EOF (start condition %d)\n", YY_START ); @@ -1155,7 +1127,7 @@ do_action: /* This label is used only to access EOF actions. */ /* %% [13.0] actions go here */ case 1: YY_RULE_SETUP -#line 78 "lexer.ll" +#line 82 "lexer.ll" { // Ok, we found a with space. Let's ignore it and update loc variable. loc.step(); @@ -1164,7 +1136,7 @@ YY_RULE_SETUP case 2: /* rule 2 can match eol */ YY_RULE_SETUP -#line 82 "lexer.ll" +#line 86 "lexer.ll" { // Newline found. Let's update the location and continue. loc.lines(yyleng); @@ -1173,7 +1145,7 @@ YY_RULE_SETUP YY_BREAK case 3: YY_RULE_SETUP -#line 88 "lexer.ll" +#line 92 "lexer.ll" { // A string has been matched. It contains the actual string and single quotes. // We need to get those quotes out of the way and just use its content, e.g. @@ -1186,7 +1158,7 @@ YY_RULE_SETUP YY_BREAK case 4: YY_RULE_SETUP -#line 98 "lexer.ll" +#line 102 "lexer.ll" { // A hex string has been matched. It contains the '0x' or '0X' header // followed by at least one hexadecimal digit. @@ -1195,7 +1167,7 @@ YY_RULE_SETUP YY_BREAK case 5: YY_RULE_SETUP -#line 104 "lexer.ll" +#line 108 "lexer.ll" { // An integer was found. std::string tmp(yytext); @@ -1213,7 +1185,7 @@ YY_RULE_SETUP case 6: /* rule 6 can match eol */ YY_RULE_SETUP -#line 118 "lexer.ll" +#line 122 "lexer.ll" { // This string specifies option name starting with a letter // and further containing letters, digits, hyphens and @@ -1223,109 +1195,126 @@ YY_RULE_SETUP YY_BREAK case 7: YY_RULE_SETUP -#line 125 "lexer.ll" -return isc::eval::EvalParser::make_EQUAL(loc); +#line 129 "lexer.ll" +{ + // IPv4 or IPv6 address + std::string tmp(yytext); + + // Some incorrect addresses can match so we have to check. + try { + isc::asiolink::IOAddress ip(tmp); + } catch (...) { + driver.error(loc, "Failed to convert " + tmp + " to an IP address."); + } + + return isc::eval::EvalParser::make_IP_ADDRESS(yytext, loc); +} YY_BREAK case 8: YY_RULE_SETUP -#line 126 "lexer.ll" -return isc::eval::EvalParser::make_OPTION(loc); +#line 143 "lexer.ll" +return isc::eval::EvalParser::make_EQUAL(loc); YY_BREAK case 9: YY_RULE_SETUP -#line 127 "lexer.ll" -return isc::eval::EvalParser::make_RELAY4(loc); +#line 144 "lexer.ll" +return isc::eval::EvalParser::make_OPTION(loc); YY_BREAK case 10: YY_RULE_SETUP -#line 128 "lexer.ll" -return isc::eval::EvalParser::make_TEXT(loc); +#line 145 "lexer.ll" +return isc::eval::EvalParser::make_RELAY4(loc); YY_BREAK case 11: YY_RULE_SETUP -#line 129 "lexer.ll" -return isc::eval::EvalParser::make_HEX(loc); +#line 146 "lexer.ll" +return isc::eval::EvalParser::make_TEXT(loc); YY_BREAK case 12: YY_RULE_SETUP -#line 130 "lexer.ll" -return isc::eval::EvalParser::make_EXISTS(loc); +#line 147 "lexer.ll" +return isc::eval::EvalParser::make_HEX(loc); YY_BREAK case 13: YY_RULE_SETUP -#line 131 "lexer.ll" -return isc::eval::EvalParser::make_SUBSTRING(loc); +#line 148 "lexer.ll" +return isc::eval::EvalParser::make_EXISTS(loc); YY_BREAK case 14: YY_RULE_SETUP -#line 132 "lexer.ll" -return isc::eval::EvalParser::make_ALL(loc); +#line 149 "lexer.ll" +return isc::eval::EvalParser::make_SUBSTRING(loc); YY_BREAK case 15: YY_RULE_SETUP -#line 133 "lexer.ll" -return isc::eval::EvalParser::make_CONCAT(loc); +#line 150 "lexer.ll" +return isc::eval::EvalParser::make_ALL(loc); YY_BREAK case 16: YY_RULE_SETUP -#line 134 "lexer.ll" -return isc::eval::EvalParser::make_NOT(loc); +#line 151 "lexer.ll" +return isc::eval::EvalParser::make_CONCAT(loc); YY_BREAK case 17: YY_RULE_SETUP -#line 135 "lexer.ll" -return isc::eval::EvalParser::make_AND(loc); +#line 152 "lexer.ll" +return isc::eval::EvalParser::make_NOT(loc); YY_BREAK case 18: YY_RULE_SETUP -#line 136 "lexer.ll" -return isc::eval::EvalParser::make_OR(loc); +#line 153 "lexer.ll" +return isc::eval::EvalParser::make_AND(loc); YY_BREAK case 19: YY_RULE_SETUP -#line 137 "lexer.ll" -return isc::eval::EvalParser::make_DOT(loc); +#line 154 "lexer.ll" +return isc::eval::EvalParser::make_OR(loc); YY_BREAK case 20: YY_RULE_SETUP -#line 138 "lexer.ll" -return isc::eval::EvalParser::make_LPAREN(loc); +#line 155 "lexer.ll" +return isc::eval::EvalParser::make_DOT(loc); YY_BREAK case 21: YY_RULE_SETUP -#line 139 "lexer.ll" -return isc::eval::EvalParser::make_RPAREN(loc); +#line 156 "lexer.ll" +return isc::eval::EvalParser::make_LPAREN(loc); YY_BREAK case 22: YY_RULE_SETUP -#line 140 "lexer.ll" -return isc::eval::EvalParser::make_LBRACKET(loc); +#line 157 "lexer.ll" +return isc::eval::EvalParser::make_RPAREN(loc); YY_BREAK case 23: YY_RULE_SETUP -#line 141 "lexer.ll" -return isc::eval::EvalParser::make_RBRACKET(loc); +#line 158 "lexer.ll" +return isc::eval::EvalParser::make_LBRACKET(loc); YY_BREAK case 24: YY_RULE_SETUP -#line 142 "lexer.ll" -return isc::eval::EvalParser::make_COMA(loc); +#line 159 "lexer.ll" +return isc::eval::EvalParser::make_RBRACKET(loc); YY_BREAK case 25: YY_RULE_SETUP -#line 144 "lexer.ll" +#line 160 "lexer.ll" +return isc::eval::EvalParser::make_COMA(loc); + YY_BREAK +case 26: +YY_RULE_SETUP +#line 162 "lexer.ll" driver.error (loc, "Invalid character: " + std::string(yytext)); YY_BREAK case YY_STATE_EOF(INITIAL): -#line 145 "lexer.ll" +#line 163 "lexer.ll" return isc::eval::EvalParser::make_END(loc); YY_BREAK -case 26: +case 27: YY_RULE_SETUP -#line 146 "lexer.ll" +#line 164 "lexer.ll" ECHO; YY_BREAK -#line 1329 "lexer.cc" +#line 1318 "lexer.cc" case YY_END_OF_BUFFER: { @@ -1348,11 +1337,7 @@ ECHO; * back-up) that will match for the new input source. */ (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; -/* %if-c-only */ YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; -/* %endif */ -/* %if-c++-only */ -/* %endif */ YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; } @@ -1459,7 +1444,6 @@ ECHO; "fatal flex scanner internal error--no action found" ); } /* end of action switch */ } /* end of scanning one token */ - } /* end of user's declarations */ } /* end of yylex */ /* %ok-for-header */ @@ -1483,9 +1467,9 @@ static int yy_get_next_buffer (void) /* %if-c++-only */ /* %endif */ { - char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; - char *source = (yytext_ptr); - yy_size_t number_to_move, i; + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = (yytext_ptr); + register int number_to_move, i; int ret_val; if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) @@ -1514,7 +1498,7 @@ static int yy_get_next_buffer (void) /* Try to read more data. */ /* First move last chars to start of buffer. */ - number_to_move = (yy_size_t) ((yy_c_buf_p) - (yytext_ptr)) - 1; + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; for ( i = 0; i < number_to_move; ++i ) *(dest++) = *(source++); @@ -1594,8 +1578,8 @@ static int yy_get_next_buffer (void) /* %if-c++-only */ /* %endif */ { - yy_state_type yy_current_state; - char *yy_cp; + register yy_state_type yy_current_state; + register char *yy_cp; /* %% [15.0] code to get the start state into yy_current_state goes here */ yy_current_state = (yy_start); @@ -1606,11 +1590,11 @@ static int yy_get_next_buffer (void) for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) { /* %% [16.0] code to find the next state goes here */ - YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 81 ) + if ( yy_current_state >= 96 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; @@ -1631,29 +1615,27 @@ static int yy_get_next_buffer (void) /* %if-c++-only */ /* %endif */ { - int yy_is_jam; + register int yy_is_jam; /* %% [17.0] code to find the next state, and perhaps do backing up, goes here */ - YY_CHAR yy_c = 1; + register YY_CHAR yy_c = 1; while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 81 ) + if ( yy_current_state >= 96 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 80); + yy_is_jam = (yy_current_state == 95); if ( ! yy_is_jam ) *(yy_state_ptr)++ = yy_current_state; - return yy_is_jam ? 0 : yy_current_state; + return yy_is_jam ? 0 : yy_current_state; } -#ifndef YY_NO_UNPUT /* %if-c-only */ /* %endif */ -#endif /* %if-c-only */ #ifndef YY_NO_INPUT @@ -1707,7 +1689,7 @@ static int yy_get_next_buffer (void) case EOB_ACT_END_OF_FILE: { if ( yywrap( ) ) - return EOF; + return 0; if ( ! (yy_did_buffer_switch_on_eof) ) YY_NEW_FILE; @@ -1763,9 +1745,6 @@ static int yy_get_next_buffer (void) yy_load_buffer_state( ); } -/* %if-c++-only */ -/* %endif */ - /** Switch to a different input buffer. * @param new_buffer The new input buffer. * @@ -1813,11 +1792,7 @@ static void yy_load_buffer_state (void) { (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; -/* %if-c-only */ yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; -/* %endif */ -/* %if-c++-only */ -/* %endif */ (yy_hold_char) = *(yy_c_buf_p); } @@ -1839,7 +1814,7 @@ static void yy_load_buffer_state (void) if ( ! b ) YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); - b->yy_buf_size = (yy_size_t)size; + b->yy_buf_size = size; /* yy_ch_buf has to be 2 characters longer than the size given because * we need to put in 2 end-of-buffer characters. @@ -1855,9 +1830,6 @@ static void yy_load_buffer_state (void) return b; } -/* %if-c++-only */ -/* %endif */ - /** Destroy the buffer. * @param b a buffer created with yy_create_buffer() * @@ -1881,6 +1853,17 @@ static void yy_load_buffer_state (void) yyfree((void *) b ); } +/* %if-c-only */ + +#ifndef __cplusplus +extern int isatty (int ); +#endif /* __cplusplus */ + +/* %endif */ + +/* %if-c++-only */ +/* %endif */ + /* Initializes or reinitializes a buffer. * This function is sometimes called more than once on the same buffer, * such as during a yyrestart() or at EOF. @@ -1896,11 +1879,7 @@ static void yy_load_buffer_state (void) yy_flush_buffer(b ); -/* %if-c-only */ b->yy_input_file = file; -/* %endif */ -/* %if-c++-only */ -/* %endif */ b->yy_fill_buffer = 1; /* If b is the current buffer, then yy_init_buffer was _probably_ @@ -2035,7 +2014,7 @@ static void yyensure_buffer_stack (void) * scanner will even need a stack. We use 2 instead of 1 to avoid an * immediate realloc on the next call. */ - num_to_alloc = 1; // After all that talk, this was set to 1 anyways... + num_to_alloc = 1; (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc (num_to_alloc * sizeof(struct yy_buffer_state*) ); @@ -2052,7 +2031,7 @@ static void yyensure_buffer_stack (void) if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ /* Increase the buffer to prepare for a possible push. */ - yy_size_t grow_size = 8 /* arbitrary grow size */; + int grow_size = 8 /* arbitrary grow size */; num_to_alloc = (yy_buffer_stack_max) + grow_size; (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc @@ -2125,8 +2104,8 @@ YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) /* %if-c-only */ /** Setup the input buffer state to scan the given bytes. The next call to yylex() will * scan from a @e copy of @a bytes. - * @param yybytes the byte buffer to scan - * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. + * @param bytes the byte buffer to scan + * @param len the number of bytes in the buffer pointed to by @a bytes. * * @return the newly allocated buffer state object. */ @@ -2134,8 +2113,7 @@ YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len { YY_BUFFER_STATE b; char *buf; - yy_size_t n; - yy_size_t i; + yy_size_t n, i; /* Get memory for full buffer, including space for trailing EOB's. */ n = _yybytes_len + 2; @@ -2168,7 +2146,7 @@ YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len /* %if-c-only */ static void yy_fatal_error (yyconst char* msg ) { - (void) fprintf( stderr, "%s\n", msg ); + (void) fprintf( stderr, "%s\n", msg ); exit( YY_EXIT_FAILURE ); } /* %endif */ @@ -2244,29 +2222,29 @@ char *yyget_text (void) /* %endif */ /** Set the current line number. - * @param _line_number line number + * @param line_number * */ -void yyset_lineno (int _line_number ) +void yyset_lineno (int line_number ) { - yylineno = _line_number; + yylineno = line_number; } /** Set the input stream. This does not discard the current * input buffer. - * @param _in_str A readable stream. + * @param in_str A readable stream. * * @see yy_switch_to_buffer */ -void yyset_in (FILE * _in_str ) +void yyset_in (FILE * in_str ) { - yyin = _in_str ; + yyin = in_str ; } -void yyset_out (FILE * _out_str ) +void yyset_out (FILE * out_str ) { - yyout = _out_str ; + yyout = out_str ; } int yyget_debug (void) @@ -2274,9 +2252,9 @@ int yyget_debug (void) return yy_flex_debug; } -void yyset_debug (int _bdebug ) +void yyset_debug (int bdebug ) { - yy_flex_debug = _bdebug ; + yy_flex_debug = bdebug ; } /* %endif */ @@ -2360,8 +2338,7 @@ int yylex_destroy (void) #ifndef yytext_ptr static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) { - - int i; + register int i; for ( i = 0; i < n; ++i ) s1[i] = s2[i]; } @@ -2370,7 +2347,7 @@ static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) #ifdef YY_NEED_STRLEN static int yy_flex_strlen (yyconst char * s ) { - int n; + register int n; for ( n = 0; s[n]; ++n ) ; @@ -2380,12 +2357,11 @@ static int yy_flex_strlen (yyconst char * s ) void *yyalloc (yy_size_t size ) { - return (void *) malloc( size ); + return (void *) malloc( size ); } void *yyrealloc (void * ptr, yy_size_t size ) { - /* The cast to (char *) in the following accommodates both * implementations that use char* generic pointers, and those * that use void* generic pointers. It works with the latter @@ -2398,7 +2374,7 @@ void *yyrealloc (void * ptr, yy_size_t size ) void yyfree (void * ptr ) { - free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ } /* %if-tables-serialization definitions */ @@ -2408,7 +2384,7 @@ void yyfree (void * ptr ) /* %ok-for-header */ -#line 146 "lexer.ll" +#line 164 "lexer.ll" diff --git a/src/lib/eval/lexer.ll b/src/lib/eval/lexer.ll index 0ad7285eba..18a4b87591 100644 --- a/src/lib/eval/lexer.ll +++ b/src/lib/eval/lexer.ll @@ -11,6 +11,7 @@ #include <string> #include <eval/eval_context.h> #include <eval/parser.h> +#include <asiolink/io_address.h> #include <boost/lexical_cast.hpp> // Work around an incompatibility in flex (at least versions @@ -56,10 +57,13 @@ static isc::eval::location loc; %option yylineno /* These are not token expressions yet, just convenience expressions that - can be used during actual token definitions. */ + can be used during actual token definitions. Note some can match + incorrect inputs (e.g., IP addresses) which must be checked. */ int \-?[0-9]+ hex [0-9a-fA-F]+ blank [ \t] +addr4 [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ +addr6 [0-9a-fA-F]*\:[0-9a-fA-F]*\:[0-9a-fA-F:.]* %{ // This code run each time a pattern is matched. It updates the location @@ -122,6 +126,20 @@ blank [ \t] return isc::eval::EvalParser::make_OPTION_NAME(yytext, loc); } +{addr4}|{addr6} { + // IPv4 or IPv6 address + std::string tmp(yytext); + + // Some incorrect addresses can match so we have to check. + try { + isc::asiolink::IOAddress ip(tmp); + } catch (...) { + driver.error(loc, "Failed to convert " + tmp + " to an IP address."); + } + + return isc::eval::EvalParser::make_IP_ADDRESS(yytext, loc); +} + "==" return isc::eval::EvalParser::make_EQUAL(loc); "option" return isc::eval::EvalParser::make_OPTION(loc); "relay4" return isc::eval::EvalParser::make_RELAY4(loc); diff --git a/src/lib/eval/location.hh b/src/lib/eval/location.hh index effaa15add..e5fd35d82b 100644 --- a/src/lib/eval/location.hh +++ b/src/lib/eval/location.hh @@ -40,9 +40,9 @@ # include "position.hh" -#line 13 "parser.yy" // location.cc:296 +#line 13 "parser.yy" // location.cc:337 namespace isc { namespace eval { -#line 46 "location.hh" // location.cc:296 +#line 46 "location.hh" // location.cc:337 /// Abstract a location. class location { @@ -186,7 +186,7 @@ namespace isc { namespace eval { return ostr; } -#line 13 "parser.yy" // location.cc:296 +#line 13 "parser.yy" // location.cc:337 } } // isc::eval -#line 192 "location.hh" // location.cc:296 +#line 192 "location.hh" // location.cc:337 #endif // !YY_YY_LOCATION_HH_INCLUDED diff --git a/src/lib/eval/parser.cc b/src/lib/eval/parser.cc index 0effbea998..2887ba9461 100644 --- a/src/lib/eval/parser.cc +++ b/src/lib/eval/parser.cc @@ -251,7 +251,7 @@ namespace isc { namespace eval { { switch (that.type_get ()) { - case 30: // option_repr_type + case 31: // option_repr_type value.move< TokenOption::RepresentationType > (that.value); break; @@ -259,10 +259,11 @@ namespace isc { namespace eval { case 22: // "integer" case 23: // "constant hexstring" case 24: // "option name" + case 25: // "ip address" value.move< std::string > (that.value); break; - case 29: // option_code + case 30: // option_code value.move< uint16_t > (that.value); break; @@ -281,7 +282,7 @@ namespace isc { namespace eval { state = that.state; switch (that.type_get ()) { - case 30: // option_repr_type + case 31: // option_repr_type value.copy< TokenOption::RepresentationType > (that.value); break; @@ -289,10 +290,11 @@ namespace isc { namespace eval { case 22: // "integer" case 23: // "constant hexstring" case 24: // "option name" + case 25: // "ip address" value.copy< std::string > (that.value); break; - case 29: // option_code + case 30: // option_code value.copy< uint16_t > (that.value); break; @@ -334,44 +336,51 @@ namespace isc { namespace eval { { case 21: // "constant string" -#line 72 "parser.yy" // lalr1.cc:636 +#line 73 "parser.yy" // lalr1.cc:636 { yyoutput << yysym.value.template as< std::string > (); } -#line 340 "parser.cc" // lalr1.cc:636 +#line 342 "parser.cc" // lalr1.cc:636 break; case 22: // "integer" -#line 72 "parser.yy" // lalr1.cc:636 +#line 73 "parser.yy" // lalr1.cc:636 { yyoutput << yysym.value.template as< std::string > (); } -#line 347 "parser.cc" // lalr1.cc:636 +#line 349 "parser.cc" // lalr1.cc:636 break; case 23: // "constant hexstring" -#line 72 "parser.yy" // lalr1.cc:636 +#line 73 "parser.yy" // lalr1.cc:636 { yyoutput << yysym.value.template as< std::string > (); } -#line 354 "parser.cc" // lalr1.cc:636 +#line 356 "parser.cc" // lalr1.cc:636 break; case 24: // "option name" -#line 72 "parser.yy" // lalr1.cc:636 +#line 73 "parser.yy" // lalr1.cc:636 { yyoutput << yysym.value.template as< std::string > (); } -#line 361 "parser.cc" // lalr1.cc:636 +#line 363 "parser.cc" // lalr1.cc:636 break; - case 29: // option_code + case 25: // "ip address" -#line 72 "parser.yy" // lalr1.cc:636 +#line 73 "parser.yy" // lalr1.cc:636 + { yyoutput << yysym.value.template as< std::string > (); } +#line 370 "parser.cc" // lalr1.cc:636 + break; + + case 30: // option_code + +#line 73 "parser.yy" // lalr1.cc:636 { yyoutput << yysym.value.template as< uint16_t > (); } -#line 368 "parser.cc" // lalr1.cc:636 +#line 377 "parser.cc" // lalr1.cc:636 break; - case 30: // option_repr_type + case 31: // option_repr_type -#line 72 "parser.yy" // lalr1.cc:636 +#line 73 "parser.yy" // lalr1.cc:636 { yyoutput << yysym.value.template as< TokenOption::RepresentationType > (); } -#line 375 "parser.cc" // lalr1.cc:636 +#line 384 "parser.cc" // lalr1.cc:636 break; @@ -571,7 +580,7 @@ namespace isc { namespace eval { when using variants. */ switch (yyr1_[yyn]) { - case 30: // option_repr_type + case 31: // option_repr_type yylhs.value.build< TokenOption::RepresentationType > (); break; @@ -579,10 +588,11 @@ namespace isc { namespace eval { case 22: // "integer" case 23: // "constant hexstring" case 24: // "option name" + case 25: // "ip address" yylhs.value.build< std::string > (); break; - case 29: // option_code + case 30: // option_code yylhs.value.build< uint16_t > (); break; @@ -604,52 +614,52 @@ namespace isc { namespace eval { switch (yyn) { case 4: -#line 86 "parser.yy" // lalr1.cc:859 +#line 87 "parser.yy" // lalr1.cc:859 { TokenPtr neg(new TokenNot()); ctx.expression.push_back(neg); } -#line 613 "parser.cc" // lalr1.cc:859 +#line 623 "parser.cc" // lalr1.cc:859 break; case 5: -#line 91 "parser.yy" // lalr1.cc:859 +#line 92 "parser.yy" // lalr1.cc:859 { TokenPtr neg(new TokenAnd()); ctx.expression.push_back(neg); } -#line 622 "parser.cc" // lalr1.cc:859 +#line 632 "parser.cc" // lalr1.cc:859 break; case 6: -#line 96 "parser.yy" // lalr1.cc:859 +#line 97 "parser.yy" // lalr1.cc:859 { TokenPtr neg(new TokenOr()); ctx.expression.push_back(neg); } -#line 631 "parser.cc" // lalr1.cc:859 +#line 641 "parser.cc" // lalr1.cc:859 break; case 7: -#line 101 "parser.yy" // lalr1.cc:859 +#line 102 "parser.yy" // lalr1.cc:859 { TokenPtr eq(new TokenEqual()); ctx.expression.push_back(eq); } -#line 640 "parser.cc" // lalr1.cc:859 +#line 650 "parser.cc" // lalr1.cc:859 break; case 8: -#line 106 "parser.yy" // lalr1.cc:859 +#line 107 "parser.yy" // lalr1.cc:859 { TokenPtr opt(new TokenOption(yystack_[3].value.as< uint16_t > (), TokenOption::EXISTS)); ctx.expression.push_back(opt); } -#line 649 "parser.cc" // lalr1.cc:859 +#line 659 "parser.cc" // lalr1.cc:859 break; case 9: -#line 111 "parser.yy" // lalr1.cc:859 +#line 112 "parser.yy" // lalr1.cc:859 { switch (ctx.getUniverse()) { case Option::V4: @@ -669,38 +679,47 @@ namespace isc { namespace eval { error(yystack_[5].location, "relay4 can only be used in DHCPv4."); } } -#line 673 "parser.cc" // lalr1.cc:859 +#line 683 "parser.cc" // lalr1.cc:859 break; case 10: -#line 133 "parser.yy" // lalr1.cc:859 +#line 134 "parser.yy" // lalr1.cc:859 { TokenPtr str(new TokenString(yystack_[0].value.as< std::string > ())); ctx.expression.push_back(str); } -#line 682 "parser.cc" // lalr1.cc:859 +#line 692 "parser.cc" // lalr1.cc:859 break; case 11: -#line 138 "parser.yy" // lalr1.cc:859 +#line 139 "parser.yy" // lalr1.cc:859 { TokenPtr hex(new TokenHexString(yystack_[0].value.as< std::string > ())); ctx.expression.push_back(hex); } -#line 691 "parser.cc" // lalr1.cc:859 +#line 701 "parser.cc" // lalr1.cc:859 break; case 12: -#line 143 "parser.yy" // lalr1.cc:859 +#line 144 "parser.yy" // lalr1.cc:859 + { + TokenPtr ip(new TokenIpAddress(yystack_[0].value.as< std::string > ())); + ctx.expression.push_back(ip); + } +#line 710 "parser.cc" // lalr1.cc:859 + break; + + case 13: +#line 149 "parser.yy" // lalr1.cc:859 { TokenPtr opt(new TokenOption(yystack_[3].value.as< uint16_t > (), yystack_[0].value.as< TokenOption::RepresentationType > ())); ctx.expression.push_back(opt); } -#line 700 "parser.cc" // lalr1.cc:859 +#line 719 "parser.cc" // lalr1.cc:859 break; - case 13: -#line 148 "parser.yy" // lalr1.cc:859 + case 14: +#line 154 "parser.yy" // lalr1.cc:859 { switch (ctx.getUniverse()) { case Option::V4: @@ -720,88 +739,88 @@ namespace isc { namespace eval { error(yystack_[5].location, "relay4 can only be used in DHCPv4."); } } -#line 724 "parser.cc" // lalr1.cc:859 +#line 743 "parser.cc" // lalr1.cc:859 break; - case 14: -#line 168 "parser.yy" // lalr1.cc:859 + case 15: +#line 174 "parser.yy" // lalr1.cc:859 { TokenPtr sub(new TokenSubstring()); ctx.expression.push_back(sub); } -#line 733 "parser.cc" // lalr1.cc:859 +#line 752 "parser.cc" // lalr1.cc:859 break; - case 15: -#line 173 "parser.yy" // lalr1.cc:859 + case 16: +#line 179 "parser.yy" // lalr1.cc:859 { TokenPtr conc(new TokenConcat()); ctx.expression.push_back(conc); } -#line 742 "parser.cc" // lalr1.cc:859 +#line 761 "parser.cc" // lalr1.cc:859 break; - case 16: -#line 180 "parser.yy" // lalr1.cc:859 + case 17: +#line 186 "parser.yy" // lalr1.cc:859 { yylhs.value.as< uint16_t > () = ctx.convertOptionCode(yystack_[0].value.as< std::string > (), yystack_[0].location); } -#line 750 "parser.cc" // lalr1.cc:859 +#line 769 "parser.cc" // lalr1.cc:859 break; - case 17: -#line 184 "parser.yy" // lalr1.cc:859 + case 18: +#line 190 "parser.yy" // lalr1.cc:859 { yylhs.value.as< uint16_t > () = ctx.convertOptionName(yystack_[0].value.as< std::string > (), yystack_[0].location); } -#line 758 "parser.cc" // lalr1.cc:859 +#line 777 "parser.cc" // lalr1.cc:859 break; - case 18: -#line 190 "parser.yy" // lalr1.cc:859 + case 19: +#line 196 "parser.yy" // lalr1.cc:859 { yylhs.value.as< TokenOption::RepresentationType > () = TokenOption::TEXTUAL; } -#line 766 "parser.cc" // lalr1.cc:859 +#line 785 "parser.cc" // lalr1.cc:859 break; - case 19: -#line 194 "parser.yy" // lalr1.cc:859 + case 20: +#line 200 "parser.yy" // lalr1.cc:859 { yylhs.value.as< TokenOption::RepresentationType > () = TokenOption::HEXADECIMAL; } -#line 774 "parser.cc" // lalr1.cc:859 +#line 793 "parser.cc" // lalr1.cc:859 break; - case 20: -#line 200 "parser.yy" // lalr1.cc:859 + case 21: +#line 206 "parser.yy" // lalr1.cc:859 { TokenPtr str(new TokenString(yystack_[0].value.as< std::string > ())); ctx.expression.push_back(str); } -#line 783 "parser.cc" // lalr1.cc:859 +#line 802 "parser.cc" // lalr1.cc:859 break; - case 21: -#line 207 "parser.yy" // lalr1.cc:859 + case 22: +#line 213 "parser.yy" // lalr1.cc:859 { TokenPtr str(new TokenString(yystack_[0].value.as< std::string > ())); ctx.expression.push_back(str); } -#line 792 "parser.cc" // lalr1.cc:859 +#line 811 "parser.cc" // lalr1.cc:859 break; - case 22: -#line 212 "parser.yy" // lalr1.cc:859 + case 23: +#line 218 "parser.yy" // lalr1.cc:859 { TokenPtr str(new TokenString("all")); ctx.expression.push_back(str); } -#line 801 "parser.cc" // lalr1.cc:859 +#line 820 "parser.cc" // lalr1.cc:859 break; -#line 805 "parser.cc" // lalr1.cc:859 +#line 824 "parser.cc" // lalr1.cc:859 default: break; } @@ -1063,91 +1082,89 @@ namespace isc { namespace eval { const signed char EvalParser::yypact_[] = { - -1, -1, -1, 1, 10, 28, 36, -29, -29, 32, - 0, 41, 29, -29, -7, -7, 17, 17, -29, -1, - -1, 17, -29, -29, -29, 38, 39, 42, 43, 37, - 40, -29, 46, -29, 44, 45, -7, -7, 47, 17, - 27, 30, 48, 49, -29, 51, 58, -29, -29, -29, - -29, -29, -29, 50, 52, -4, -29, 33, 33, -29, - -29, 60, -29 + -1, -1, -1, 24, 27, 18, 37, -29, -29, -29, + 50, 6, 43, 11, -29, 10, 10, 16, 16, -29, + -1, -1, 16, -29, -29, -29, 40, 41, 44, 45, + 35, 38, -29, 52, -29, 46, 47, 10, 10, 39, + 16, 28, 31, 51, 53, -29, 48, 58, -29, -29, + -29, -29, -29, -29, 55, 56, -15, -29, 34, 34, + -29, -29, 60, -29 }; const unsigned char EvalParser::yydefact_[] = { - 0, 0, 0, 0, 0, 0, 0, 10, 11, 0, - 2, 0, 0, 4, 0, 0, 0, 0, 1, 0, - 0, 0, 3, 16, 17, 0, 0, 0, 0, 0, - 0, 5, 6, 7, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 20, 0, 0, 18, 19, 8, - 12, 9, 13, 0, 0, 0, 15, 0, 0, 22, - 21, 0, 14 + 0, 0, 0, 0, 0, 0, 0, 10, 11, 12, + 0, 2, 0, 0, 4, 0, 0, 0, 0, 1, + 0, 0, 0, 3, 17, 18, 0, 0, 0, 0, + 0, 0, 5, 6, 7, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 21, 0, 0, 19, 20, + 8, 13, 9, 14, 0, 0, 0, 16, 0, 0, + 23, 22, 0, 15 }; const signed char EvalParser::yypgoto_[] = { - -29, -29, 9, -16, -12, -28, -29, -29 + -29, -29, 9, -17, -10, -28, -29, -29 }; const signed char EvalParser::yydefgoto_[] = { - -1, 9, 10, 11, 25, 50, 45, 61 + -1, 10, 11, 12, 26, 51, 46, 62 }; const unsigned char EvalParser::yytable_[] = { - 29, 30, 1, 26, 2, 33, 19, 20, 3, 4, - 12, 13, 14, 52, 59, 23, 5, 24, 60, 6, - 7, 15, 8, 46, 42, 43, 27, 28, 31, 32, - 52, 16, 18, 22, 5, 19, 20, 6, 7, 17, - 8, 47, 48, 49, 47, 48, 51, 47, 48, 21, - 34, 35, 19, 36, 37, 0, 38, 40, 41, 39, - 53, 54, 56, 57, 62, 58, 0, 0, 0, 44, - 55 + 30, 31, 1, 60, 2, 34, 27, 61, 3, 4, + 13, 14, 20, 21, 53, 23, 5, 20, 21, 6, + 7, 17, 8, 47, 9, 28, 29, 43, 44, 32, + 33, 53, 24, 5, 25, 15, 6, 7, 16, 8, + 18, 9, 48, 49, 50, 48, 49, 52, 48, 49, + 19, 22, 35, 36, 39, 37, 38, 40, 20, 41, + 42, 45, 57, 54, 63, 55, 0, 56, 58, 59 }; const signed char EvalParser::yycheck_[] = { - 16, 17, 3, 15, 5, 21, 6, 7, 9, 10, - 1, 2, 11, 41, 18, 22, 17, 24, 22, 20, - 21, 11, 23, 39, 36, 37, 9, 10, 19, 20, - 58, 3, 0, 4, 17, 6, 7, 20, 21, 3, - 23, 14, 15, 16, 14, 15, 16, 14, 15, 8, - 12, 12, 6, 11, 11, -1, 19, 13, 13, 19, - 12, 12, 4, 13, 4, 13, -1, -1, -1, 22, - 19 + 17, 18, 3, 18, 5, 22, 16, 22, 9, 10, + 1, 2, 6, 7, 42, 4, 17, 6, 7, 20, + 21, 3, 23, 40, 25, 9, 10, 37, 38, 20, + 21, 59, 22, 17, 24, 11, 20, 21, 11, 23, + 3, 25, 14, 15, 16, 14, 15, 16, 14, 15, + 0, 8, 12, 12, 19, 11, 11, 19, 6, 13, + 13, 22, 4, 12, 4, 12, -1, 19, 13, 13 }; const unsigned char EvalParser::yystos_[] = { - 0, 3, 5, 9, 10, 17, 20, 21, 23, 26, - 27, 28, 27, 27, 11, 11, 3, 3, 0, 6, - 7, 8, 4, 22, 24, 29, 29, 9, 10, 28, - 28, 27, 27, 28, 12, 12, 11, 11, 19, 19, - 13, 13, 29, 29, 22, 31, 28, 14, 15, 16, - 30, 16, 30, 12, 12, 19, 4, 13, 13, 18, - 22, 32, 4 + 0, 3, 5, 9, 10, 17, 20, 21, 23, 25, + 27, 28, 29, 28, 28, 11, 11, 3, 3, 0, + 6, 7, 8, 4, 22, 24, 30, 30, 9, 10, + 29, 29, 28, 28, 29, 12, 12, 11, 11, 19, + 19, 13, 13, 30, 30, 22, 32, 29, 14, 15, + 16, 31, 16, 31, 12, 12, 19, 4, 13, 13, + 18, 22, 33, 4 }; const unsigned char EvalParser::yyr1_[] = { - 0, 25, 26, 27, 27, 27, 27, 27, 27, 27, - 28, 28, 28, 28, 28, 28, 29, 29, 30, 30, - 31, 32, 32 + 0, 26, 27, 28, 28, 28, 28, 28, 28, 28, + 29, 29, 29, 29, 29, 29, 29, 30, 30, 31, + 31, 32, 33, 33 }; const unsigned char EvalParser::yyr2_[] = { 0, 2, 1, 3, 2, 3, 3, 3, 6, 6, - 1, 1, 6, 6, 8, 6, 1, 1, 1, 1, - 1, 1, 1 + 1, 1, 1, 6, 6, 8, 6, 1, 1, 1, + 1, 1, 1, 1 }; @@ -1161,18 +1178,18 @@ namespace isc { namespace eval { "\"and\"", "\"or\"", "\"==\"", "\"option\"", "\"relay4\"", "\"[\"", "\"]\"", "\".\"", "\"text\"", "\"hex\"", "\"exists\"", "\"substring\"", "\"all\"", "\",\"", "\"concat\"", "\"constant string\"", "\"integer\"", - "\"constant hexstring\"", "\"option name\"", "$accept", "expression", - "bool_expr", "string_expr", "option_code", "option_repr_type", - "start_expr", "length_expr", YY_NULLPTR + "\"constant hexstring\"", "\"option name\"", "\"ip address\"", "$accept", + "expression", "bool_expr", "string_expr", "option_code", + "option_repr_type", "start_expr", "length_expr", YY_NULLPTR }; #if YYDEBUG const unsigned char EvalParser::yyrline_[] = { - 0, 81, 81, 84, 85, 90, 95, 100, 105, 110, - 132, 137, 142, 147, 167, 172, 179, 183, 189, 193, - 199, 206, 211 + 0, 82, 82, 85, 86, 91, 96, 101, 106, 111, + 133, 138, 143, 148, 153, 173, 178, 185, 189, 195, + 199, 205, 212, 217 }; // Print the state stack on the debug stream. @@ -1207,8 +1224,8 @@ namespace isc { namespace eval { #line 13 "parser.yy" // lalr1.cc:1167 } } // isc::eval -#line 1211 "parser.cc" // lalr1.cc:1167 -#line 218 "parser.yy" // lalr1.cc:1168 +#line 1228 "parser.cc" // lalr1.cc:1167 +#line 224 "parser.yy" // lalr1.cc:1168 void isc::eval::EvalParser::error(const location_type& loc, diff --git a/src/lib/eval/parser.h b/src/lib/eval/parser.h index 27e4a4320b..ac0e3971b3 100644 --- a/src/lib/eval/parser.h +++ b/src/lib/eval/parser.h @@ -40,7 +40,7 @@ #ifndef YY_YY_PARSER_H_INCLUDED # define YY_YY_PARSER_H_INCLUDED // // "%code requires" blocks. -#line 16 "parser.yy" // lalr1.cc:377 +#line 16 "parser.yy" // lalr1.cc:392 #include <string> #include <eval/token.h> @@ -51,7 +51,7 @@ using namespace isc::dhcp; using namespace isc::eval; -#line 55 "parser.h" // lalr1.cc:377 +#line 55 "parser.h" // lalr1.cc:392 # include <cassert> # include <cstdlib> // std::abort @@ -126,9 +126,9 @@ using namespace isc::eval; # define YYDEBUG 1 #endif -#line 13 "parser.yy" // lalr1.cc:377 +#line 13 "parser.yy" // lalr1.cc:392 namespace isc { namespace eval { -#line 132 "parser.h" // lalr1.cc:377 +#line 132 "parser.h" // lalr1.cc:392 @@ -302,6 +302,7 @@ namespace isc { namespace eval { // "integer" // "constant hexstring" // "option name" + // "ip address" char dummy2[sizeof(std::string)]; // option_code @@ -350,7 +351,8 @@ namespace isc { namespace eval { TOKEN_STRING = 276, TOKEN_INTEGER = 277, TOKEN_HEXSTRING = 278, - TOKEN_OPTION_NAME = 279 + TOKEN_OPTION_NAME = 279, + TOKEN_IP_ADDRESS = 280 }; }; @@ -553,6 +555,10 @@ namespace isc { namespace eval { symbol_type make_OPTION_NAME (const std::string& v, const location_type& l); + static inline + symbol_type + make_IP_ADDRESS (const std::string& v, const location_type& l); + /// Build a parser object. EvalParser (EvalContext& ctx_yyarg); @@ -758,12 +764,12 @@ namespace isc { namespace eval { enum { yyeof_ = 0, - yylast_ = 70, ///< Last index in yytable_. + yylast_ = 69, ///< Last index in yytable_. yynnts_ = 8, ///< Number of nonterminal symbols. - yyfinal_ = 18, ///< Termination state number. + yyfinal_ = 19, ///< Termination state number. yyterror_ = 1, yyerrcode_ = 256, - yyntokens_ = 25 ///< Number of tokens. + yyntokens_ = 26 ///< Number of tokens. }; @@ -807,9 +813,10 @@ namespace isc { namespace eval { 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, 24 + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25 }; - const unsigned int user_token_number_max_ = 279; + const unsigned int user_token_number_max_ = 280; const token_number_type undef_token_ = 2; if (static_cast<int>(t) <= yyeof_) @@ -842,7 +849,7 @@ namespace isc { namespace eval { { switch (other.type_get ()) { - case 30: // option_repr_type + case 31: // option_repr_type value.copy< TokenOption::RepresentationType > (other.value); break; @@ -850,10 +857,11 @@ namespace isc { namespace eval { case 22: // "integer" case 23: // "constant hexstring" case 24: // "option name" + case 25: // "ip address" value.copy< std::string > (other.value); break; - case 29: // option_code + case 30: // option_code value.copy< uint16_t > (other.value); break; @@ -874,7 +882,7 @@ namespace isc { namespace eval { (void) v; switch (this->type_get ()) { - case 30: // option_repr_type + case 31: // option_repr_type value.copy< TokenOption::RepresentationType > (v); break; @@ -882,10 +890,11 @@ namespace isc { namespace eval { case 22: // "integer" case 23: // "constant hexstring" case 24: // "option name" + case 25: // "ip address" value.copy< std::string > (v); break; - case 29: // option_code + case 30: // option_code value.copy< uint16_t > (v); break; @@ -951,7 +960,7 @@ namespace isc { namespace eval { // Type destructor. switch (yytype) { - case 30: // option_repr_type + case 31: // option_repr_type value.template destroy< TokenOption::RepresentationType > (); break; @@ -959,10 +968,11 @@ namespace isc { namespace eval { case 22: // "integer" case 23: // "constant hexstring" case 24: // "option name" + case 25: // "ip address" value.template destroy< std::string > (); break; - case 29: // option_code + case 30: // option_code value.template destroy< uint16_t > (); break; @@ -989,7 +999,7 @@ namespace isc { namespace eval { super_type::move(s); switch (this->type_get ()) { - case 30: // option_repr_type + case 31: // option_repr_type value.move< TokenOption::RepresentationType > (s.value); break; @@ -997,10 +1007,11 @@ namespace isc { namespace eval { case 22: // "integer" case 23: // "constant hexstring" case 24: // "option name" + case 25: // "ip address" value.move< std::string > (s.value); break; - case 29: // option_code + case 30: // option_code value.move< uint16_t > (s.value); break; @@ -1061,7 +1072,7 @@ namespace isc { namespace eval { { 0, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, - 275, 276, 277, 278, 279 + 275, 276, 277, 278, 279, 280 }; return static_cast<token_type> (yytoken_number_[type]); } @@ -1204,10 +1215,16 @@ namespace isc { namespace eval { return symbol_type (token::TOKEN_OPTION_NAME, v, l); } + EvalParser::symbol_type + EvalParser::make_IP_ADDRESS (const std::string& v, const location_type& l) + { + return symbol_type (token::TOKEN_IP_ADDRESS, v, l); + } + -#line 13 "parser.yy" // lalr1.cc:377 +#line 13 "parser.yy" // lalr1.cc:392 } } // isc::eval -#line 1211 "parser.h" // lalr1.cc:377 +#line 1228 "parser.h" // lalr1.cc:392 diff --git a/src/lib/eval/parser.yy b/src/lib/eval/parser.yy index 6e4b21670a..d02002e202 100644 --- a/src/lib/eval/parser.yy +++ b/src/lib/eval/parser.yy @@ -61,6 +61,7 @@ using namespace isc::eval; %token <std::string> INTEGER "integer" %token <std::string> HEXSTRING "constant hexstring" %token <std::string> OPTION_NAME "option name" +%token <std::string> IP_ADDRESS "ip address" %type <uint16_t> option_code %type <TokenOption::RepresentationType> option_repr_type @@ -139,6 +140,11 @@ string_expr : STRING TokenPtr hex(new TokenHexString($1)); ctx.expression.push_back(hex); } + | IP_ADDRESS + { + TokenPtr ip(new TokenIpAddress($1)); + ctx.expression.push_back(ip); + } | OPTION "[" option_code "]" "." option_repr_type { TokenPtr opt(new TokenOption($3, $6)); diff --git a/src/lib/eval/position.hh b/src/lib/eval/position.hh index b3eebe04f6..4e09385e65 100644 --- a/src/lib/eval/position.hh +++ b/src/lib/eval/position.hh @@ -50,9 +50,9 @@ # endif # endif -#line 13 "parser.yy" // location.cc:296 +#line 13 "parser.yy" // location.cc:337 namespace isc { namespace eval { -#line 56 "position.hh" // location.cc:296 +#line 56 "position.hh" // location.cc:337 /// Abstract a position. class position { @@ -174,7 +174,7 @@ namespace isc { namespace eval { return ostr << pos.line << '.' << pos.column; } -#line 13 "parser.yy" // location.cc:296 +#line 13 "parser.yy" // location.cc:337 } } // isc::eval -#line 180 "position.hh" // location.cc:296 +#line 180 "position.hh" // location.cc:337 #endif // !YY_YY_POSITION_HH_INCLUDED diff --git a/src/lib/eval/stack.hh b/src/lib/eval/stack.hh index 6bda37bbcf..fa0d0d87a2 100644 --- a/src/lib/eval/stack.hh +++ b/src/lib/eval/stack.hh @@ -40,9 +40,9 @@ # include <vector> -#line 13 "parser.yy" // stack.hh:132 +#line 13 "parser.yy" // stack.hh:151 namespace isc { namespace eval { -#line 46 "stack.hh" // stack.hh:132 +#line 46 "stack.hh" // stack.hh:151 template <class T, class S = std::vector<T> > class stack { @@ -150,8 +150,8 @@ namespace isc { namespace eval { unsigned int range_; }; -#line 13 "parser.yy" // stack.hh:132 +#line 13 "parser.yy" // stack.hh:151 } } // isc::eval -#line 156 "stack.hh" // stack.hh:132 +#line 156 "stack.hh" // stack.hh:151 #endif // !YY_YY_STACK_HH_INCLUDED diff --git a/src/lib/eval/tests/context_unittest.cc b/src/lib/eval/tests/context_unittest.cc index 5f1e71e953..7465bb2df1 100644 --- a/src/lib/eval/tests/context_unittest.cc +++ b/src/lib/eval/tests/context_unittest.cc @@ -10,12 +10,14 @@ #include <eval/token.h> #include <dhcp/option.h> #include <dhcp/pkt4.h> +#include <asiolink/io_address.h> #include <boost/shared_ptr.hpp> #include <boost/scoped_ptr.hpp> #include <gtest/gtest.h> using namespace std; +using namespace isc::asiolink; using namespace isc::dhcp; namespace { @@ -63,6 +65,29 @@ public: EXPECT_EQ(expected, values.top()); } + /// @brief checks if the given token is an IP address with the expected value + void checkTokenIpAddress(const TokenPtr& token, + const std::string& expected) { + ASSERT_TRUE(token); + boost::shared_ptr<TokenIpAddress> ipaddr = + boost::dynamic_pointer_cast<TokenIpAddress>(token); + ASSERT_TRUE(ipaddr); + + Pkt4Ptr pkt4(new Pkt4(DHCPDISCOVER, 12345)); + ValueStack values; + + EXPECT_NO_THROW(token->evaluate(*pkt4, values)); + + ASSERT_EQ(1, values.size()); + string value = values.top(); + + boost::scoped_ptr<IOAddress> exp_ip; + ASSERT_NO_THROW(exp_ip.reset(new IOAddress(expected))); + vector<uint8_t> exp_addr = exp_ip->toBytes(); + ASSERT_EQ(exp_addr.size(), value.size()); + EXPECT_EQ(0, memcmp(&exp_addr[0], &value[0], value.size())); + } + /// @brief checks if the given token is an equal operator void checkTokenEq(const TokenPtr& token) { ASSERT_TRUE(token); @@ -215,6 +240,77 @@ TEST_F(EvalContextTest, oddHexstring) { checkTokenHexString(tmp, "\a"); } +// Test the parsing of an IPv4 address +TEST_F(EvalContextTest, ipaddress4) { + EvalContext eval(Option::V6); + + EXPECT_NO_THROW(parsed_ = eval.parseString("10.0.0.1 == 'foo'")); + EXPECT_TRUE(parsed_); + + ASSERT_EQ(3, eval.expression.size()); + + TokenPtr tmp = eval.expression.at(0); + + checkTokenIpAddress(tmp, "10.0.0.1"); +} + +// Test the parsing of an IPv6 address +TEST_F(EvalContextTest, ipaddress6) { + EvalContext eval(Option::V6); + + EXPECT_NO_THROW(parsed_ = eval.parseString("2001:db8::1 == 'foo'")); + EXPECT_TRUE(parsed_); + + ASSERT_EQ(3, eval.expression.size()); + + TokenPtr tmp = eval.expression.at(0); + + checkTokenIpAddress(tmp, "2001:db8::1"); +} + +// Test the parsing of an IPv4 compatible IPv6 address +TEST_F(EvalContextTest, ipaddress46) { + EvalContext eval(Option::V6); + + EXPECT_NO_THROW(parsed_ = eval.parseString("::10.0.0.1 == 'foo'")); + EXPECT_TRUE(parsed_); + + ASSERT_EQ(3, eval.expression.size()); + + TokenPtr tmp = eval.expression.at(0); + + checkTokenIpAddress(tmp, "::10.0.0.1"); +} + +// Test the parsing of the unspecified IPv6 address +TEST_F(EvalContextTest, ipaddress6unspec) { + EvalContext eval(Option::V6); + + EXPECT_NO_THROW(parsed_ = eval.parseString(":: == 'foo'")); + EXPECT_TRUE(parsed_); + + ASSERT_EQ(3, eval.expression.size()); + + TokenPtr tmp = eval.expression.at(0); + + checkTokenIpAddress(tmp, "::"); +} + +// Test the parsing of an IPv6 prefix +TEST_F(EvalContextTest, ipaddress6prefix) { + EvalContext eval(Option::V6); + + EXPECT_NO_THROW(parsed_ = eval.parseString("2001:db8:: == 'foo'")); + EXPECT_TRUE(parsed_); + + ASSERT_EQ(3, eval.expression.size()); + + TokenPtr tmp = eval.expression.at(0); + + checkTokenIpAddress(tmp, "2001:db8::"); +} + + // Test the parsing of an equal expression TEST_F(EvalContextTest, equal) { EvalContext eval(Option::V4); @@ -486,6 +582,7 @@ TEST_F(EvalContextTest, scanErrors) { checkError("'\''", "<string>:1.3: Invalid character: '"); checkError("'\n'", "<string>:1.1: Invalid character: '"); checkError("0x123h", "<string>:1.6: Invalid character: h"); + checkError(":1", "<string>:1.1: Invalid character: :"); checkError("=", "<string>:1.1: Invalid character: ="); checkError("subtring", "<string>:1.1: Invalid character: s"); checkError("foo", "<string>:1.1: Invalid character: f"); @@ -500,6 +597,12 @@ TEST_F(EvalContextTest, scanParseErrors) { checkError("0x", "<string>:1.1: syntax error, unexpected integer"); checkError("0abc", "<string>:1.1: syntax error, unexpected integer"); + checkError("10.0.1", "<string>:1.1-2: syntax error, unexpected integer"); + checkError("10.256.0.1", + "<string>:1.1-10: Failed to convert 10.256.0.1 to " + "an IP address."); + checkError(":::", + "<string>:1.1-3: Failed to convert ::: to an IP address."); checkError("===", "<string>:1.1-2: syntax error, unexpected =="); checkError("option[-1].text", "<string>:1.8-9: Option code has invalid " diff --git a/src/lib/eval/tests/token_unittest.cc b/src/lib/eval/tests/token_unittest.cc index 5c970f3103..3449281dbd 100644 --- a/src/lib/eval/tests/token_unittest.cc +++ b/src/lib/eval/tests/token_unittest.cc @@ -283,6 +283,51 @@ TEST_F(TokenTest, hexstring6) { EXPECT_EQ("", values_.top()); } +// This test checks that a TokenIpAddress, representing an IP address as +// a constant string, can be used in Pkt4/Pkt6 evaluation. +// (The actual packet is not used) +TEST_F(TokenTest, ipaddress) { + TokenPtr bad4; + TokenPtr bad6; + TokenPtr ip4; + TokenPtr ip6; + + // Bad IP addresses + ASSERT_NO_THROW(bad4.reset(new TokenIpAddress("10.0.0.0.1"))); + ASSERT_NO_THROW(bad6.reset(new TokenIpAddress(":::"))); + + // IP addresses + ASSERT_NO_THROW(ip4.reset(new TokenIpAddress("10.0.0.1"))); + ASSERT_NO_THROW(ip6.reset(new TokenIpAddress("2001:db8::1"))); + + // Make sure that tokens can be evaluated without exceptions. + ASSERT_NO_THROW(ip4->evaluate(*pkt4_, values_)); + ASSERT_NO_THROW(ip6->evaluate(*pkt6_, values_)); + ASSERT_NO_THROW(bad4->evaluate(*pkt4_, values_)); + ASSERT_NO_THROW(bad6->evaluate(*pkt6_, values_)); + + // Check that the evaluation put its value on the values stack. + ASSERT_EQ(4, values_.size()); + + // Check bad addresses (they pushed '' on the value stack) + EXPECT_EQ(0, values_.top().size()); + values_.pop(); + EXPECT_EQ(0, values_.top().size()); + values_.pop(); + + // Check IPv6 address + uint8_t expected6[] = { 0x20, 1, 0xd, 0xb8, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1 }; + EXPECT_EQ(16, values_.top().size()); + EXPECT_EQ(0, memcmp(expected6, &values_.top()[0], 16)); + values_.pop(); + + // Check IPv4 address + uint8_t expected4[] = { 10, 0, 0, 1 }; + EXPECT_EQ(4, values_.top().size()); + EXPECT_EQ(0, memcmp(expected4, &values_.top()[0], 4)); +} + // This test checks if a token representing an option value is able to extract // the option from an IPv4 packet and properly store the option's value. TEST_F(TokenTest, optionString4) { diff --git a/src/lib/eval/token.cc b/src/lib/eval/token.cc index 041b30feb9..fcbdc91057 100644 --- a/src/lib/eval/token.cc +++ b/src/lib/eval/token.cc @@ -7,6 +7,7 @@ #include <eval/token.h> #include <eval/eval_log.h> #include <util/encode/hex.h> +#include <asiolink/io_address.h> #include <boost/lexical_cast.hpp> #include <cstring> #include <string> @@ -54,6 +55,27 @@ TokenHexString::evaluate(const Pkt& /*pkt*/, ValueStack& values) { values.push(value_); } +TokenIpAddress::TokenIpAddress(const string& addr) : value_("") { + // Transform IP address into binary format + vector<uint8_t> binary; + try { + asiolink::IOAddress ip(addr); + binary = ip.toBytes(); + } catch (...) { + return; + } + + // Convert to a string (note that binary.size() is 4 or 16, so not 0) + value_.resize(binary.size()); + memmove(&value_[0], &binary[0], binary.size()); +} + +void +TokenIpAddress::evaluate(const Pkt& /*pkt*/, ValueStack& values) { + // Literals only push, nothing to pop + values.push(value_); +} + OptionPtr TokenOption::getOption(const Pkt& pkt) { return (pkt.getOption(option_code_)); diff --git a/src/lib/eval/token.h b/src/lib/eval/token.h index eb29a06e02..4d4ab7a41b 100644 --- a/src/lib/eval/token.h +++ b/src/lib/eval/token.h @@ -155,6 +155,29 @@ protected: std::string value_; ///< Constant value }; +/// @brief Token representing an IP address as a constant string +/// +/// This token holds the value of an IP address as a constant string, +/// for instance 10.0.0.1 is 0x10000001 +class TokenIpAddress : public Token { +public: + /// Value is set during token construction. + /// + /// @param addr IP address to be represented as a constant string + TokenIpAddress(const std::string& addr); + + /// @brief Token evaluation (puts value of the constant string on + /// the stack after decoding) + /// + /// @param pkt (ignored) + /// @param values (represented IP address will be pushed here) + void evaluate(const Pkt& pkt, ValueStack& values); + +protected: + ///< Constant value (empty string if the IP address cannot be converted) + std::string value_; +}; + /// @brief Token that represents a value of an option /// /// This represents a reference to a given option, e.g. in the expression |