Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/topic/awelzel/record-fields-not-…
Browse files Browse the repository at this point in the history
…just-enum'

* origin/topic/awelzel/record-fields-not-just-enum:
  bifs/record_fields: Include actual enum name in type_name
  • Loading branch information
timwoj committed Oct 31, 2022
2 parents 352705d + 699949c commit 6dec7d6
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 4 deletions.
18 changes: 18 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
5.2.0-dev.169 | 2022-10-31 15:18:04 -0700

* bifs/record_fields: Include actual enum name in type_name (Arne Welzel, Corelight)

One more from @stevesmoot. The record_fields() BIF produced "enum" as
type_name for fields of type enum.

Extend container_type_name() to append the actual name of the enum.

This is changing the format and may break consumers, but those are
likely in a category that are happy to adapt. Not having the actual
enum name available wasn't very helpful.

We could alternatively render only the actual type_name without the
prefixed "enum", but that isn't how it's done for record types currently
and it would make it more difficult to decide which subsequent BIFs to
use for further introspection, like enum_names().

5.2.0-dev.167 | 2022-10-31 14:57:21 -0700

* IPBasedAnalyzer/TCPSessionAdapter: Fix TCP reassembly decision for known port analyzers (Arne Welzel, Corelight)
Expand Down
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ Changed Functionality
- The parameter given to ``enum_names()`` can now be a string naming the
enum type, rather than the type itself.

- The ``type_name`` of enum types produced by ``record_fields()`` now
includes the actual type name rather than just ``"enum"``.

- Passing non-string ``sep`` and ``def`` arguments to ``cat_sep()`` isn't a
fatal error anymore. More descriptive error messages are produced, too.

Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.2.0-dev.167
5.2.0-dev.169
2 changes: 2 additions & 0 deletions src/Type.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,8 @@ static string container_type_name(const Type* ft)
s += container_type_name(ft->Yield().get());
}
}
else if ( ft->Tag() == TYPE_ENUM )
s = "enum " + ft->GetName();
else
s = type_name(ft->Tag());
return s;
Expand Down
14 changes: 11 additions & 3 deletions testing/btest/Baseline/bifs.records_fields/out
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,20 @@ F
{
[a] = [type_name=bool, log=F, value=<uninitialized>, default_val=<uninitialized>],
[d] = [type_name=string, log=T, value=<uninitialized>, default_val=<uninitialized>],
[f] = [type_name=enum Monochrome::color, log=T, value=<uninitialized>, default_val=<uninitialized>],
[b] = [type_name=string, log=F, value=<uninitialized>, default_val=Bar],
[c] = [type_name=double, log=F, value=<uninitialized>, default_val=<uninitialized>],
[m] = [type_name=record myrec, log=F, value=<uninitialized>, default_val=<uninitialized>],
[c] = [type_name=double, log=F, value=<uninitialized>, default_val=<uninitialized>]
[e] = [type_name=enum color, log=F, value=<uninitialized>, default_val=BLUE]
}
{
[a] = [type_name=bool, log=F, value=<uninitialized>, default_val=<uninitialized>],
[d] = [type_name=string, log=T, value=<uninitialized>, default_val=<uninitialized>],
[f] = [type_name=enum Monochrome::color, log=T, value=<uninitialized>, default_val=<uninitialized>],
[b] = [type_name=string, log=F, value=<uninitialized>, default_val=Bar],
[c] = [type_name=double, log=F, value=<uninitialized>, default_val=<uninitialized>],
[m] = [type_name=record myrec, log=F, value=<uninitialized>, default_val=<uninitialized>],
[c] = [type_name=double, log=F, value=<uninitialized>, default_val=<uninitialized>]
[e] = [type_name=enum color, log=F, value=<uninitialized>, default_val=BLUE]
}
{
[a] = [type_name=count, log=F, value=42, default_val=<uninitialized>],
Expand All @@ -38,9 +42,11 @@ F
{
[a] = [type_name=bool, log=F, value=<uninitialized>, default_val=<uninitialized>],
[d] = [type_name=string, log=T, value=<uninitialized>, default_val=<uninitialized>],
[f] = [type_name=enum Monochrome::color, log=T, value=<uninitialized>, default_val=<uninitialized>],
[b] = [type_name=string, log=F, value=<uninitialized>, default_val=Bar],
[c] = [type_name=double, log=F, value=<uninitialized>, default_val=<uninitialized>],
[m] = [type_name=record myrec, log=F, value=<uninitialized>, default_val=<uninitialized>],
[c] = [type_name=double, log=F, value=<uninitialized>, default_val=<uninitialized>]
[e] = [type_name=enum color, log=F, value=<uninitialized>, default_val=BLUE]
}
{
[a] = [type_name=count, log=F, value=<uninitialized>, default_val=<uninitialized>],
Expand All @@ -52,7 +58,9 @@ F
{
[a] = [type_name=set[double], log=F, value=<uninitialized>, default_val=<uninitialized>],
[d] = [type_name=table[double,string] of table[string] of vector of string, log=F, value=<uninitialized>, default_val=<uninitialized>],
[f] = [type_name=vector of enum color, log=F, value=<uninitialized>, default_val=<uninitialized>],
[b] = [type_name=set[double,string], log=F, value=<uninitialized>, default_val=<uninitialized>],
[c] = [type_name=set[double,record tt], log=F, value=<uninitialized>, default_val=<uninitialized>],
[g] = [type_name=table[string] of enum color, log=F, value=<uninitialized>, default_val=<uninitialized>],
[e] = [type_name=vector of vector of string, log=F, value=<uninitialized>, default_val=<uninitialized>]
}
13 changes: 13 additions & 0 deletions testing/btest/bifs/records_fields.zeek
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
# @TEST-EXEC: zeek -b %INPUT >out
# @TEST-EXEC: btest-diff out

module Monochrome;
export {
type color: enum { BLACK, WHITE };
}

module GLOBAL;

type color: enum { RED, BLUE };

type myrec: record {
myfield: bool;
};
Expand All @@ -11,6 +20,8 @@ type tt: record {
b: string &default="Bar";
c: double &optional;
d: string &log;
e: color &default=BLUE;
f: Monochrome::color &log;
m: myrec;
};

Expand All @@ -30,6 +41,8 @@ type cr: record {
c: set[double, tt];
d: table[double, string] of table[string] of vector of string;
e: vector of vector of string;
f: vector of color;
g: table[string] of color;
};

event zeek_init()
Expand Down

0 comments on commit 6dec7d6

Please sign in to comment.