mirror of
https://github.com/zeek/zeek.git
synced 2025-10-14 20:48:21 +00:00
Add to_subnet bif (fixes #782).
Also fix IPAddr::Mask/ReverseMask not allowing argument of 0. And clarified return value of to_addr bif when the input string does not parse into a valid IP address.
This commit is contained in:
parent
c84394d07f
commit
32aabe8432
9 changed files with 59 additions and 14 deletions
1
testing/btest/Baseline/bifs.to_addr/error
Normal file
1
testing/btest/Baseline/bifs.to_addr/error
Normal file
|
@ -0,0 +1 @@
|
|||
error: Bad IP address: not an IP
|
|
@ -6,3 +6,4 @@ to_addr(10.20.30.40) = 10.20.30.40 (SUCCESS)
|
|||
to_addr(100.200.30.40) = 100.200.30.40 (SUCCESS)
|
||||
to_addr(10.0.0.0) = 10.0.0.0 (SUCCESS)
|
||||
to_addr(10.00.00.000) = 10.0.0.0 (SUCCESS)
|
||||
to_addr(not an IP) = :: (SUCCESS)
|
||||
|
|
1
testing/btest/Baseline/bifs.to_subnet/error
Normal file
1
testing/btest/Baseline/bifs.to_subnet/error
Normal file
|
@ -0,0 +1 @@
|
|||
error: Bad string in SubNetVal ctor: 10.0.0.0
|
3
testing/btest/Baseline/bifs.to_subnet/output
Normal file
3
testing/btest/Baseline/bifs.to_subnet/output
Normal file
|
@ -0,0 +1,3 @@
|
|||
10.0.0.0/8, T
|
||||
2607:f8b0::/32, T
|
||||
::/0, T
|
|
@ -1,5 +1,6 @@
|
|||
# @TEST-EXEC: bro %INPUT >output
|
||||
# @TEST-EXEC: bro -b %INPUT >output 2>error
|
||||
# @TEST-EXEC: btest-diff output
|
||||
# @TEST-EXEC: btest-diff error
|
||||
|
||||
function test_to_addr(ip: string, expect: addr)
|
||||
{
|
||||
|
@ -16,3 +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("10.0.0.0", 10.0.0.0);
|
||||
test_to_addr("10.00.00.000", 10.0.0.0);
|
||||
test_to_addr("not an IP", ::);
|
||||
|
|
11
testing/btest/bifs/to_subnet.bro
Normal file
11
testing/btest/bifs/to_subnet.bro
Normal file
|
@ -0,0 +1,11 @@
|
|||
# @TEST-EXEC: bro -b %INPUT >output 2>error
|
||||
# @TEST-EXEC: btest-diff output
|
||||
# @TEST-EXEC: btest-diff error
|
||||
|
||||
global sn: subnet;
|
||||
sn = to_subnet("10.0.0.0/8");
|
||||
print sn, sn == 10.0.0.0/8;
|
||||
sn = to_subnet("2607:f8b0::/32");
|
||||
print sn, sn == 2607:f8b0::/32;
|
||||
sn = to_subnet("10.0.0.0");
|
||||
print sn, sn == ::/0;
|
Loading…
Add table
Add a link
Reference in a new issue