[Bro] Questions about bro module declarations

francois.pennaneach at free.fr francois.pennaneach at free.fr
Tue Nov 15 08:20:29 PST 2016


Hi Bro people,

I have a few questions about Bro Module declarations (more specifically the GLOBAL module), see below.


I tried this script :

export {
    const var : string = "GLOBAL::var_1";
}

module GLOBAL;

export {
    const var : string = "GLOBAL::var_2";
}

Bro returns an error, which is what I was expecting. Great.
error in ././trybro.bro, line 3 and ././trybro.bro, line 9: already defined (var)
internal warning in ././trybro.bro, line 9: Duplicate identifier documentation: var

So I guess I have defined a variable with scope GLOBAL::var in both cases ?


Then I tried this second script :

export {
    const var : string = "GLOBAL::var_1";
}
 
module Module1;

export {
    function test_func() { print var; }
}


event bro_init() {
    Module1::test_func();
}


It prints "GLOBAL::var_1". Good. So Module1::test_func() has "default" visibility on GLOBAL module.

Third try :

export {
    const var : string = "GLOBAL::var_1";
}

 
module Module1;
    const var : string = "Module1::var";
    function test_func() { print var; }
}

It prints "Module1::var". Why not.
However, I was expecting Bro to report a conflict between using GLOBAL::var or Module1::var, as both are visible...


Fourth test : try to force the use of GLOBAL::var in test_func().

export {
    const var : string = "GLOBAL::var_1";
}

 
module Module1;
    const var : string = "Module1::var";
    function test_func() { print GLOBAL::var; }
}

Bro reports an error : 
 line 15: unknown identifier GLOBAL::var, at or near "GLOBAL::var"


Did I miss something ?
What exactly is GLOBAL and what are its visibility rules and how does Bro search for identifiers in modules ?
How to explicitly make a reference to an identifier in GLOBAL module, as GLOBAL:: does not work ?


Thank you for all helpful tips !

François








More information about the Bro mailing list