Change routing0_data_to_addrs BIF to return vector of addresses.

Because the order of addresses in type 0 routing headers is
interesting/important.
This commit is contained in:
Jon Siwek 2012-03-26 14:35:01 -05:00
parent d889f14638
commit 0ceca706f6
3 changed files with 14 additions and 13 deletions

View file

@ -46,6 +46,13 @@ type index_vec: vector of count;
## then remove this alias. ## then remove this alias.
type string_vec: vector of string; type string_vec: vector of string;
## A vector of addresses.
##
## .. todo:: We need this type definition only for declaring builtin functions via
## ``bifcl``. We should extend ``bifcl`` to understand composite types directly and
## then remove this alias.
type addr_vec: vector of addr;
## A table of strings indexed by strings. ## A table of strings indexed by strings.
## ##
## .. todo:: We need this type definition only for declaring builtin functions via ## .. todo:: We need this type definition only for declaring builtin functions via

View file

@ -2050,18 +2050,15 @@ function is_v6_addr%(a: addr%): bool
# =========================================================================== # ===========================================================================
## Converts the *data* field of :bro:type:`ip6_routing` records that have ## Converts the *data* field of :bro:type:`ip6_routing` records that have
## *rtype* of 0 into a set of addresses. ## *rtype* of 0 into a vector of addresses.
## ##
## s: The *data* field of an :bro:type:`ip6_routing` record that has ## s: The *data* field of an :bro:type:`ip6_routing` record that has
## an *rtype* of 0. ## an *rtype* of 0.
## ##
## Returns: The set of addresses contained in the routing header data. ## Returns: The vector of addresses contained in the routing header data.
function routing0_data_to_addrs%(s: string%): addr_set function routing0_data_to_addrs%(s: string%): addr_vec
%{ %{
BroType* index_type = base_type(TYPE_ADDR); VectorVal* rval = new VectorVal(new VectorType(base_type(TYPE_ADDR)));
TypeList* set_index = new TypeList(index_type);
set_index->Append(index_type);
TableVal* tv = new TableVal(new SetType(set_index, 0));
int len = s->Len(); int len = s->Len();
const u_char* bytes = s->Bytes(); const u_char* bytes = s->Bytes();
@ -2074,12 +2071,12 @@ function routing0_data_to_addrs%(s: string%): addr_set
while ( len > 0 ) while ( len > 0 )
{ {
IPAddr a(IPAddr::IPv6, (const uint32*) bytes, IPAddr::Network); IPAddr a(IPAddr::IPv6, (const uint32*) bytes, IPAddr::Network);
tv->Assign(new AddrVal(a), 0); rval->Assign(rval->Size(), new AddrVal(a), 0);
bytes += 16; bytes += 16;
len -= 16; len -= 16;
} }
return tv; return rval;
%} %}
## Converts a :bro:type:`addr` to a :bro:type:`index_vec`. ## Converts a :bro:type:`addr` to a :bro:type:`index_vec`.

View file

@ -1,4 +1 @@
{ [2001:78:1:32::1, 2001:78:1:32::2]
2001:78:1:32::1,
2001:78:1:32::2
}