Change IPv6 literal constant syntax to require encasing square brackets

This is to avoid ambiguity between compressed hex notation and
module namespacing, both which use "::". E.g.: "aaaa::bbbb" could
be an identifier or an IPv6 address, but "[aaaa::bbbb]" is now
clearly the address.

Also added IPv6 mixed notation to allow an IPv4 dotted-decimal
address to be specified in the lower 32-bits.
This commit is contained in:
Jon Siwek 2012-03-13 13:47:07 -05:00
parent 1811391cff
commit bf3f184a01
10 changed files with 79 additions and 14 deletions

View file

@ -275,7 +275,7 @@ event ftp_reply(c: connection, code: count, msg: string, cont_resp: bool) &prior
{ {
c$ftp$passive=T; c$ftp$passive=T;
if ( code == 229 && data$h == :: ) if ( code == 229 && data$h == [::] )
data$h = id$resp_h; data$h = id$resp_h;
ftp_data_expected[data$h, data$p] = c$ftp; ftp_data_expected[data$h, data$p] = c$ftp;

View file

@ -228,6 +228,24 @@ ESCSEQ (\\([^\n]|[0-7]+|x[[:xdigit:]]+))
++yylloc.last_line; ++yylloc.last_line;
} }
/* IPv6 literal constant patterns */
"["({HEX}:){7}{HEX}"]" {
string s(yytext+1);
RET_CONST(new AddrVal(s.erase(s.size()-1)))
}
"["0x{HEX}({HEX}|:)*"::"({HEX}|:)*"]" {
string s(yytext+3);
RET_CONST(new AddrVal(s.erase(s.size()-1)))
}
"["({HEX}|:)*"::"({HEX}|:)*"]" {
string s(yytext+1);
RET_CONST(new AddrVal(s.erase(s.size()-1)))
}
"["({HEX}|:)*"::"({HEX}|:)*({D}"."){3}{D}"]" {
string s(yytext+1);
RET_CONST(new AddrVal(s.erase(s.size()-1)))
}
[!%*/+\-,:;<=>?()\[\]{}~$|] return yytext[0]; [!%*/+\-,:;<=>?()\[\]{}~$|] return yytext[0];
"--" return TOK_DECR; "--" return TOK_DECR;
@ -450,11 +468,6 @@ F RET_CONST(new Val(false, TYPE_BOOL))
({D}"."){3}{D} RET_CONST(new AddrVal(yytext)) ({D}"."){3}{D} RET_CONST(new AddrVal(yytext))
({HEX}:){7}{HEX} RET_CONST(new AddrVal(yytext))
0x{HEX}({HEX}|:)*"::"({HEX}|:)* RET_CONST(new AddrVal(yytext+2))
(({D}|:)({HEX}|:)*)?"::"({HEX}|:)* RET_CONST(new AddrVal(yytext))
"0x"{HEX}+ RET_CONST(new Val(static_cast<bro_uint_t>(strtol(yytext, 0, 16)), TYPE_COUNT)) "0x"{HEX}+ RET_CONST(new Val(static_cast<bro_uint_t>(strtol(yytext, 0, 16)), TYPE_COUNT))
{H}("."{H})+ RET_CONST(dns_mgr->LookupHost(yytext)) {H}("."{H})+ RET_CONST(dns_mgr->LookupHost(yytext))

View file

@ -0,0 +1,22 @@
::1
::0.0.255.255
::255.255.255.255
::10.10.255.255
1::1
1::a
1::1:1
1::1:a
a::a
a::1
a::a:a
a::a:1
a:a::a
aaaa::ffff
192.168.1.100
ffff::c0a8:164
::192.168.1.100
805b:2d9d:dc28::fc57:d4c8:1fff
aaaa::bbbb
aaaa:bbbb:cccc:dddd:eeee:ffff:1111:2222
aaaa:bbbb:cccc:dddd:eeee:ffff:1:2222
aaaa:bbbb:cccc:dddd:eeee:ffff::2222

View file

@ -3,7 +3,7 @@
global v: index_vec; global v: index_vec;
v = addr_to_counts(2001:0db8:85a3:0000:0000:8a2e:0370:7334); v = addr_to_counts([2001:0db8:85a3:0000:0000:8a2e:0370:7334]);
print v; print v;
print counts_to_addr(v); print counts_to_addr(v);
v = addr_to_counts(1.2.3.4); v = addr_to_counts(1.2.3.4);

View file

@ -1,6 +1,6 @@
# @TEST-EXEC: bro %INPUT >output # @TEST-EXEC: bro %INPUT >output
# @TEST-EXEC: btest-diff output # @TEST-EXEC: btest-diff output
print addr_to_ptr_name(2607:f8b0:4009:802::1012); print addr_to_ptr_name([2607:f8b0:4009:802::1012]);
print addr_to_ptr_name(74.125.225.52); print addr_to_ptr_name(74.125.225.52);

View file

@ -2,6 +2,6 @@
# @TEST-EXEC: btest-diff out # @TEST-EXEC: btest-diff out
print is_v4_addr(1.2.3.4); print is_v4_addr(1.2.3.4);
print is_v4_addr(::1); print is_v4_addr([::1]);
print is_v6_addr(1.2.3.4); print is_v6_addr(1.2.3.4);
print is_v6_addr(::1); print is_v6_addr([::1]);

View file

@ -17,4 +17,4 @@ test_to_addr("10.20.30.40", 10.20.30.40);
test_to_addr("100.200.30.40", 100.200.30.40); test_to_addr("100.200.30.40", 100.200.30.40);
test_to_addr("10.0.0.0", 10.0.0.0); test_to_addr("10.0.0.0", 10.0.0.0);
test_to_addr("10.00.00.000", 10.0.0.0); test_to_addr("10.00.00.000", 10.0.0.0);
test_to_addr("not an IP", ::); test_to_addr("not an IP", [::]);

View file

@ -6,6 +6,6 @@ global sn: subnet;
sn = to_subnet("10.0.0.0/8"); sn = to_subnet("10.0.0.0/8");
print sn, sn == 10.0.0.0/8; print sn, sn == 10.0.0.0/8;
sn = to_subnet("2607:f8b0::/32"); sn = to_subnet("2607:f8b0::/32");
print sn, sn == 2607:f8b0::/32; print sn, sn == [2607:f8b0::]/32;
sn = to_subnet("10.0.0.0"); sn = to_subnet("10.0.0.0");
print sn, sn == ::/0; print sn, sn == [::]/0;

View file

@ -0,0 +1,30 @@
# @TEST-EXEC: bro -b %INPUT >output
# @TEST-EXEC: btest-diff output
local v: vector of addr = vector();
v[|v|] = [::1];
v[|v|] = [::ffff];
v[|v|] = [::ffff:ffff];
v[|v|] = [::0a0a:ffff];
v[|v|] = [1::1];
v[|v|] = [1::a];
v[|v|] = [1::1:1];
v[|v|] = [1::1:a];
v[|v|] = [a::a];
v[|v|] = [a::1];
v[|v|] = [a::a:a];
v[|v|] = [a::a:1];
v[|v|] = [a:a::a];
v[|v|] = [aaaa:0::ffff];
v[|v|] = [::ffff:192.168.1.100];
v[|v|] = [ffff::192.168.1.100];
v[|v|] = [::192.168.1.100];
v[|v|] = [805B:2D9D:DC28::FC57:212.200.31.255];
v[|v|] = [0xaaaa::bbbb];
v[|v|] = [aaaa:bbbb:cccc:dddd:eeee:ffff:1111:2222];
v[|v|] = [aaaa:bbbb:cccc:dddd:eeee:ffff:1:2222];
v[|v|] = [aaaa:bbbb:cccc:dddd:eeee:ffff:0:2222];
for (i in v)
print v[i];

View file

@ -20,7 +20,7 @@ type example_record: record {
}; };
global a: addr = 1.2.3.4; global a: addr = 1.2.3.4;
global a6: addr = ::1; global a6: addr = [::1];
global b: bool = T; global b: bool = T;
global c: count = 10; global c: count = 10;
global d: double = -1.23; global d: double = -1.23;