From 00204ab8a6adcad0d62b1e7e76945c58b738cc3d Mon Sep 17 00:00:00 2001 From: Johanna Amann Date: Mon, 13 Apr 2015 16:05:55 -0700 Subject: [PATCH] introduce &weaken attribute, which basically only prevents the describe function for types to descend into record fields that are marked with it. With this, we can actually load the pacf scripts without crashing Bro when running tests :) --- scripts/base/frameworks/pacf/plugin.bro | 4 ++-- scripts/base/init-default.bro | 3 ++- src/Attr.cc | 7 ++++++- src/Attr.h | 3 ++- src/Type.cc | 10 ++++++++-- src/parse.y | 6 ++++-- src/scan.l | 1 + 7 files changed, 25 insertions(+), 9 deletions(-) diff --git a/scripts/base/frameworks/pacf/plugin.bro b/scripts/base/frameworks/pacf/plugin.bro index 944705605f..ab25911d14 100644 --- a/scripts/base/frameworks/pacf/plugin.bro +++ b/scripts/base/frameworks/pacf/plugin.bro @@ -84,8 +84,8 @@ export { # record type from inside itself. redef record PluginState += { ## The plugin that the state belongs to. (Defined separately - ## because of cyclic type dependency.) - plugin: Plugin &optional; + ## because of cyclic type dependency.) + plugin: Plugin &optional &weaken; }; } diff --git a/scripts/base/init-default.bro b/scripts/base/init-default.bro index 0615ce36ef..16650017cb 100644 --- a/scripts/base/init-default.bro +++ b/scripts/base/init-default.bro @@ -37,7 +37,8 @@ @load base/frameworks/reporter @load base/frameworks/sumstats @load base/frameworks/tunnels -#@load base/frameworks/pacf +@load base/frameworks/openflow +@load base/frameworks/pacf @load base/protocols/conn @load base/protocols/dhcp diff --git a/src/Attr.cc b/src/Attr.cc index fc8d3000d1..8b451ca5b1 100644 --- a/src/Attr.cc +++ b/src/Attr.cc @@ -18,7 +18,7 @@ const char* attr_name(attr_tag t) "&encrypt", "&raw_output", "&mergeable", "&priority", "&group", "&log", "&error_handler", "&type_column", - "(&tracked)", "&deprecated", + "(&tracked)", "&deprecated", "&weaken", }; return attr_names[int(t)]; @@ -436,6 +436,11 @@ void Attributes::CheckAttr(Attr* a) Error("&log applied to a type that cannot be logged"); break; + case ATTR_WEAKEN: + if ( ! in_record ) + Error("&weaken applied outside of record"); + break; + case ATTR_TYPE_COLUMN: { if ( type->Tag() != TYPE_PORT ) diff --git a/src/Attr.h b/src/Attr.h index 63f2524c21..f89fb9f119 100644 --- a/src/Attr.h +++ b/src/Attr.h @@ -35,7 +35,8 @@ typedef enum { ATTR_TYPE_COLUMN, // for input framework ATTR_TRACKED, // hidden attribute, tracked by NotifierRegistry ATTR_DEPRECATED, -#define NUM_ATTRS (int(ATTR_DEPRECATED) + 1) + ATTR_WEAKEN, +#define NUM_ATTRS (int(ATTR_WEAKEN) + 1) } attr_tag; class Attr : public BroObj { diff --git a/src/Type.cc b/src/Type.cc index 9aa86da8dc..891c69c50f 100644 --- a/src/Type.cc +++ b/src/Type.cc @@ -1129,7 +1129,10 @@ void RecordType::DescribeFields(ODesc* d) const const TypeDecl* td = FieldDecl(i); d->Add(td->id); d->Add(":"); - td->type->Describe(d); + if ( td->FindAttr(ATTR_WEAKEN) ) + d->Add(""); + else + td->type->Describe(d); d->Add(";"); } } @@ -1170,7 +1173,10 @@ void RecordType::DescribeFieldsReST(ODesc* d, bool func_args) const } const TypeDecl* td = FieldDecl(i); - td->DescribeReST(d); + if ( td->FindAttr(ATTR_WEAKEN) ) + d->Add(""); + else + td->DescribeReST(d); if ( func_args ) continue; diff --git a/src/parse.y b/src/parse.y index 8054718d45..a7e9eadd19 100644 --- a/src/parse.y +++ b/src/parse.y @@ -2,7 +2,7 @@ // See the file "COPYING" in the main distribution directory for copyright. %} -%expect 78 +%expect 81 %token TOK_ADD TOK_ADD_TO TOK_ADDR TOK_ANY %token TOK_ATENDIF TOK_ATELSE TOK_ATIF TOK_ATIFDEF TOK_ATIFNDEF @@ -25,7 +25,7 @@ %token TOK_ATTR_PERSISTENT TOK_ATTR_SYNCHRONIZED %token TOK_ATTR_RAW_OUTPUT TOK_ATTR_MERGEABLE %token TOK_ATTR_PRIORITY TOK_ATTR_LOG TOK_ATTR_ERROR_HANDLER -%token TOK_ATTR_TYPE_COLUMN TOK_ATTR_DEPRECATED +%token TOK_ATTR_TYPE_COLUMN TOK_ATTR_DEPRECATED TOK_ATTR_WEAKEN %token TOK_DEBUG @@ -1291,6 +1291,8 @@ attr: { $$ = new Attr(ATTR_ERROR_HANDLER); } | TOK_ATTR_DEPRECATED { $$ = new Attr(ATTR_DEPRECATED); } + | TOK_ATTR_WEAKEN + { $$ = new Attr(ATTR_WEAKEN); } ; stmt: diff --git a/src/scan.l b/src/scan.l index a6e37a67f7..8103201303 100644 --- a/src/scan.l +++ b/src/scan.l @@ -276,6 +276,7 @@ when return TOK_WHEN; &type_column return TOK_ATTR_TYPE_COLUMN; &read_expire return TOK_ATTR_EXPIRE_READ; &redef return TOK_ATTR_REDEF; +&weaken return TOK_ATTR_WEAKEN; &write_expire return TOK_ATTR_EXPIRE_WRITE; &encrypt {