[Bro] binpac accumulated patch
jmzhou.ml at gmail.com
jmzhou.ml at gmail.com
Tue May 8 14:14:31 PDT 2007
Hi there,
The attached patch is for binpac in bro 1.2.1. It fixes a problem
in handling the ``refine'' keyword under flowunit mode. We must
defer the ``MarkIncrementalInput'' till all ``refine'' declarations
have been processed.
The patch also includes two previous patches:
. data dependency between record fields
. format string for module operation
Regards,
Jimmy
____________________________________________________________
The future is not set. There is no fate but what we make
for ourselves. - Terminator II, Judgment Day
------------------------------------------------------------
-------------- next part --------------
diff -ruN bro-1.2.1.orig/src/binpac/pac_common.h bro-1.2.1/src/binpac/pac_common.h
--- bro-1.2.1.orig/src/binpac/pac_common.h 2006-07-26 15:02:40.000000000 -0700
+++ bro-1.2.1/src/binpac/pac_common.h 2007-04-18 11:09:16.000000000 -0700
@@ -105,6 +105,11 @@
if ( pc ) \
for ( ct::iterator i = (pc)->begin(); i != (pc)->end(); ++i )
+#define foreach_rev(i, ct, pc) \
+ if ( pc ) \
+ for ( ct::iterator i = (pc)->end(); i-- != (pc)->begin(); )
+
+
#define delete_list(ct, pc) \
{ \
foreach(delete_list_i, ct, pc) \
diff -ruN bro-1.2.1.orig/src/binpac/pac_decl.cc bro-1.2.1/src/binpac/pac_decl.cc
--- bro-1.2.1.orig/src/binpac/pac_decl.cc 2006-07-26 15:02:40.000000000 -0700
+++ bro-1.2.1/src/binpac/pac_decl.cc 2007-05-08 13:59:22.000000000 -0700
@@ -9,6 +9,7 @@
#include "pac_output.h"
#include "pac_param.h"
#include "pac_record.h"
+#include "pac_flow.h"
#include "pac_type.h"
#include "pac_utils.h"
@@ -70,6 +71,8 @@
if ( ! decl_list_ )
return;
+ get_flow_decl()->MarkIncrementalInput();
+
foreach(i, DeclList, decl_list_)
{
Decl *decl = *i;
diff -ruN bro-1.2.1.orig/src/binpac/pac_expr.def bro-1.2.1/src/binpac/pac_expr.def
--- bro-1.2.1.orig/src/binpac/pac_expr.def 2006-07-26 15:02:39.000000000 -0700
+++ bro-1.2.1/src/binpac/pac_expr.def 2007-04-18 11:06:47.000000000 -0700
@@ -14,7 +14,7 @@
EXPR_DEF(EXPR_MINUS, 2, "%s - %s")
EXPR_DEF(EXPR_TIMES, 2, "%s * %s")
EXPR_DEF(EXPR_DIV, 2, "%s / %s")
-EXPR_DEF(EXPR_MOD, 2, "%s % %s")
+EXPR_DEF(EXPR_MOD, 2, "%s %% %s")
EXPR_DEF(EXPR_BITNOT, 1, "~%s")
EXPR_DEF(EXPR_BITAND, 2, "%s & %s")
EXPR_DEF(EXPR_BITOR, 2, "%s | %s")
diff -ruN bro-1.2.1.orig/src/binpac/pac_field.cc bro-1.2.1/src/binpac/pac_field.cc
--- bro-1.2.1.orig/src/binpac/pac_field.cc 2006-07-26 15:02:39.000000000 -0700
+++ bro-1.2.1/src/binpac/pac_field.cc 2007-04-19 09:23:59.000000000 -0700
@@ -12,6 +12,7 @@
decl_id_ = current_decl_id;
field_id_str_ = strfmt("%s:%s", decl_id()->Name(), id_->Name());
attrs_ = 0;
+ prepared_ = false;
}
Field::~Field()
@@ -73,6 +74,11 @@
void Field::Prepare(Env *env)
{
+ /* prevent infinite recursion */
+ if ( prepared_ )
+ return ;
+ prepared_ = true;
+
if ( type_ )
{
if ( anonymous_field() )
diff -ruN bro-1.2.1.orig/src/binpac/pac_field.h bro-1.2.1/src/binpac/pac_field.h
--- bro-1.2.1.orig/src/binpac/pac_field.h 2006-07-26 15:02:40.000000000 -0700
+++ bro-1.2.1/src/binpac/pac_field.h 2007-04-19 09:24:05.000000000 -0700
@@ -74,6 +74,7 @@
protected:
FieldType tof_;
int flags_;
+ bool prepared_;
ID* id_;
Type *type_;
const ID* decl_id_;
diff -ruN bro-1.2.1.orig/src/binpac/pac_flow.cc bro-1.2.1/src/binpac/pac_flow.cc
--- bro-1.2.1.orig/src/binpac/pac_flow.cc 2006-10-12 14:13:12.000000000 -0700
+++ bro-1.2.1/src/binpac/pac_flow.cc 2007-05-08 13:57:27.000000000 -0700
@@ -15,6 +15,20 @@
#include "pac_varfield.h"
+static FlowDecl* g_flow_decl = NULL;
+
+FlowDecl* get_flow_decl()
+{
+ return g_flow_decl;
+}
+
+void set_flow_decl(FlowDecl* decl)
+{
+ assert (NULL == g_flow_decl);
+ g_flow_decl = decl;
+}
+
+
FlowDecl::FlowDecl(ID *id,
ParamList *params,
AnalyzerElementList *elemlist)
@@ -24,6 +38,8 @@
conn_decl_ = 0;
flow_buffer_var_field_ = 0;
AddElements(elemlist);
+
+ set_flow_decl (this);
}
FlowDecl::~FlowDecl()
@@ -55,6 +71,14 @@
"flow should be defined in only a connection declaration");
}
+void FlowDecl::MarkIncrementalInput()
+ {
+ if ( dataunit_->type() != AnalyzerDataUnit::FLOWUNIT )
+ return;
+
+ dataunit_->data_type()->MarkIncrementalInput();
+ }
+
void FlowDecl::ProcessDataUnitElement(AnalyzerDataUnit *dataunit_elem)
{
if ( dataunit_ )
@@ -66,7 +90,7 @@
if ( dataunit_->type() == AnalyzerDataUnit::FLOWUNIT )
{
- dataunit_->data_type()->MarkIncrementalInput();
+ //dataunit_->data_type()->MarkIncrementalInput();
flow_buffer_var_field_ = new PrivVarField(
flow_buffer_id->clone(),
diff -ruN bro-1.2.1.orig/src/binpac/pac_flow.h bro-1.2.1/src/binpac/pac_flow.h
--- bro-1.2.1.orig/src/binpac/pac_flow.h 2006-07-26 15:02:39.000000000 -0700
+++ bro-1.2.1/src/binpac/pac_flow.h 2007-05-08 14:01:13.000000000 -0700
@@ -3,6 +3,8 @@
#include "pac_analyzer.h"
+FlowDecl* get_flow_decl();
+
class FlowDecl : public AnalyzerDecl
{
public:
@@ -12,6 +14,7 @@
void Prepare();
void set_conn_decl(ConnDecl *c) { conn_decl_ = c; }
+ void MarkIncrementalInput();
static ParameterizedType *flow_buffer_type();
diff -ruN bro-1.2.1.orig/src/binpac/pac_type.cc bro-1.2.1/src/binpac/pac_type.cc
--- bro-1.2.1.orig/src/binpac/pac_type.cc 2006-07-26 15:02:40.000000000 -0700
+++ bro-1.2.1/src/binpac/pac_type.cc 2007-04-19 09:29:56.000000000 -0700
@@ -305,9 +305,40 @@
}
}
+ /* prepare parameter fields first as they may be dependency */
foreach (i, FieldList, fields_)
{
Field *f = *i;
+ if (PARAM_FIELD == f->tof())
+ f->Prepare(env);
+ }
+
+ foreach (i, FieldList, fields_)
+ {
+ Field *f = *i;
+ Expr* req;
+ if (NULL == f->type() /* can be a padding field */ ||
+ NULL == (req = f->type()->attr_requires()))
+ {
+ /* there is no &requires dependents, good! */
+ f->Prepare(env);
+ continue;
+ }
+
+ /* there are dependents on some &let fields :-( */
+ ASSERT(Expr::EXPR_CALLARGS == req->expr_type());
+
+ FieldList::iterator newi = i+1;
+ for (; newi != fields_->end(); ++ newi)
+ {
+ /* not a field of &let, ignore it */
+ Field* newf = *newi;
+ if (LET_FIELD != newf->tof())
+ continue;
+
+ if (req->HasReference (newf->id()))
+ newf->Prepare(env);
+ }
f->Prepare(env);
}
}
@@ -367,7 +398,7 @@
void Type::GenCleanUpCode(Output* out_cc, Env* env)
{
- foreach (i, FieldList, fields_)
+ foreach_rev (i, FieldList, fields_)
{
Field *f = *i;
if ( f->tof() != CASE_FIELD )
diff -ruN bro-1.2.1.orig/src/binpac/pac_type.h bro-1.2.1/src/binpac/pac_type.h
--- bro-1.2.1.orig/src/binpac/pac_type.h 2006-10-17 15:46:32.000000000 -0700
+++ bro-1.2.1/src/binpac/pac_type.h 2007-04-19 09:28:18.000000000 -0700
@@ -155,6 +155,7 @@
Expr *attr_if_expr() const { return attr_if_expr_; }
// TODO: generate the length expression automatically.
Expr *attr_length_expr() const { return attr_length_expr_; }
+ Expr *attr_requires() const { return attr_requires_; }
bool attr_refcount() const { return attr_refcount_; }
bool attr_transient() const { return attr_transient_; }
More information about the Bro
mailing list