defining a table of sets

Hello,

I’m trying to use a table of sets in my policy, and can’t figure out how to statically define values. The manual covers use of the add() function, but

Scan.bro

global distinct_peers: table[addr] of set[addr]

redef SMITH::table_of_sets = {
[ “a” ] = [ “alpha”, “anchor”, “armor” ],
[ “b” ] = [ “bravo”, “biscuit”, “blue” ],
};

smith.bro, line 150 (alpha, anchor, armor): bad tag in Val::CONVERTER
(types/table)

redef SMITH::table_of_sets = {
[ “a” ] = { “alpha”, “anchor”, “armor” },
[ “b” ] = { “bravo”, “biscuit”, “blue” },
};

smith.bro, line 149: error: syntax error, at or near “{”

Hello again,

Sorry for the previous email fragment, apparently there is a hot-key in GMail that automagically sends the message. What I meant to say was…

I’m trying to use a table of sets in my policy, and can’t figure out how to statically define values. The manual covers use of the add() function, but I would need to define them just as a redef in my startup policy. The objective here is a hash table of strings with chaining. I define the table as

global table_of_sets: table[string] of set[string]

after the similar definition in scan.bro of

global distinct_peers: table[addr] of set[addr]

Then I try to redef the table and add values:

redef SMITH::table_of_sets = {
[ “a” ] = { “alpha”, “anchor”, “armor” },
[ “b” ] = { “bravo”, “biscuit”, “blue” },
};

This gives me

smith.bro, line 149: error: syntax error, at or near “{”

Just to see what would happen I changed the curly brackets to square brackets, and that changes to error to

smith.bro, line 150 (alpha, anchor, armor): bad tag in Val::CONVERTER (types/table)

I can’t seem to find this being done anywhere else the existing policies, it is always done through the add() function, but I can’t imagine that it is not possible. Is there an explanation in the reference manual and I am just missing it?

Thanks,
Stephen

smith.bro, line 150 (alpha, anchor, armor): bad tag in Val::CONVERTER
(types/table)

This is definitely a bug.

A workaround is to use a temporary variable:

  global t1 = set( "alpha", "anchor", "armor" );
  global distinct_peers: table[string] of set[string] = {
    [ "a" ] = t1, # this works
  };

- Vern

Thanks for the quick reply. The definition data needs to be in a static file, so perhaps I can use a generation function to parse the text and create the table. In the mean time I will see if I can get some further details out of gdb so maybe I can figure out what is going on.

Just so I am clear though, the correct way to define this would be with square brackets enclosing the set? As in,

[ “a” ] = [ “alpha”, “anchor”, “armor” ]

Thanks,
Stephen

In the mean time I will see if I can get some further
details out of gdb so maybe I can figure out what is going on.

I'm pretty sure I already know what the problem is. It comes from confusion
deep inside the initialization code of what type to associate with the
list value. It's messy to fix, which is why it's still there :-(.

Just so I am clear though, the correct way to define this would be with
square brackets enclosing the set? As in,

[ "a" ] = [ "alpha", "anchor", "armor" ]

Better would be:

  [ "a" ] = set("alpha", "anchor", "armor")

We want to deprecate the set initializer.

    Vern