Commit 7917d94e authored by Francis Dupont's avatar Francis Dupont
Browse files

[master] Finished merge of trac4232a (IP address literal)

parents 2bc621d5 f9e7a274
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
......
......@@ -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>
......@@ -177,6 +178,11 @@ sub-option with code "code" from the DHCPv4 Relay Agent Information option
&quot;0&quot; is prepended to it.
</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.
......
This diff is collapsed.
......@@ -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);
......
......@@ -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
......@@ -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\"", "\"[\"",
"\"]\"", "\"