# eval?

**URL:** <https://community.zeek.org/t/eval/1901>\
**Category:** Development\
**Tags:** development\
**Created:** [June 15, 2011, 7:15pm UTC](https://community.zeek.org/t/eval/1901 "2011-06-15T19:15:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seth\_Hall3](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Seth\_Hall3](https://community.zeek.org/u/Seth_Hall3)\
**Post date:** [June 15, 2011, 7:15pm UTC](https://community.zeek.org/t/eval/1901/1 "2011-06-15T19:15:14Z")

</div>

I imagine that an eval BiF would be pretty easy to write and it would make it possible for me to do what I'm working on now. I'll write a bit about what I'm working on to justify an eval BiF. 🙂

I'm reworking most of the notice framework to make it simpler and make it's features more well defined, mostly by removed the notice action filters. The notice action filters are confusing because they are applied after the notice policy but that's effectively creating two different ways for actions to be applied to notices but it just makes things confusing in the end. I think the notice action filters were originally created as a shorthand way to provide broad brush strokes to the notice policy by directing entire notice types toward certain actions.

If we had an eval function, I could essentially replicate this functionality in the notice policy which would keep everything much clearer. As things stand now (before I do a commit), here's how it looks to filter out entire notice types:

redef Notice::action\_filters += {  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[[DPD::ProtocolViolation]] = Notice::ignore\_action,  
};

I would like to do something like this...

redef Notice::policy += {  
&nbsp;&nbsp;Notice::ignore\_it(DPD::ProtocolViolation),  
};

The problem is that to implement the ignore\_it function requires me to dynamically implement the predicate for the notice policy which Bro doesn't currently like. I tried implementing it similarly to this:

function ignore\_it(nt: Notice::Type): Notice::PolicyItem  
&nbsp;&nbsp;{  
&nbsp;&nbsp;return [$result=ACTION\_IGNORE,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$pred(n: Notice::Info) = { return n$note == nt; },  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$priority=5];  
&nbsp;&nbsp;}

I think the problem comes up when Bro is interpreting "n$note == nt". It isn't pulling the values from the correct namespace. If I could call an eval function, I could implement it this way:

function ignore\_it(nt: Notice::Type): Notice::PolicyItem  
&nbsp;&nbsp;{  
&nbsp;&nbsp;eval(cat("return [$result=ACTION\_IGNORE, $pred(n: Notice::Info) = { return n$note == ",  
&nbsp;&nbsp;&nbsp;&nbsp;nt,  
&nbsp;&nbsp;&nbsp;&nbsp;"; }, $priority=5]");  
&nbsp;&nbsp;}

I think it would be fairly reasonable for eval to only work at init time too. It scares me to think of eval being usable at runtime. Sorry for the long email, but any thoughts?

&nbsp;&nbsp;.Seth

---

<div class="post-metadata">

**Author:** ![Vern](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/vern/32/630_2.png) [@Vern](https://community.zeek.org/u/Vern)\
**Post date:** [June 16, 2011, 2:24am UTC](https://community.zeek.org/t/eval/1901/2 "2011-06-16T02:24:50Z")

</div>

Yuck.

This strikes me as definitely going down the wrong path - making code less  
clear rather than more clear.

> redef Notice::action\_filters += {  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[[DPD::ProtocolViolation]] = Notice::ignore\_action,  
> };
> 
> I would like to do something like this...
> 
> redef Notice::policy += {  
> &nbsp;&nbsp;Notice::ignore\_it(DPD::ProtocolViolation),  
> };

I'm not understanding how the second is better than the first. Indeed,  
now I have to go look at how ignore\_it works to know what's going on.

> The problem is that to implement the ignore\_it function requires me to dynamically implement the predicate for the notice policy which Bro doesn't currently like. I tried implementing it similarly to this:
> 
> function ignore\_it(nt: Notice::Type): Notice::PolicyItem  
> &nbsp;&nbsp;{  
> &nbsp;&nbsp;return [$result=ACTION\_IGNORE,  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$pred(n: Notice::Info) = { return n$note == nt; },  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$priority=5];  
> &nbsp;&nbsp;}

Here it seems if you must go this route, the right fix is either a notion  
of currying (or partial application) of functions, or to have a single  
PolicyItem for ignoring that looks up n$note in a table, and just add  
DPD::ProtocolViolation to that table.

&nbsp;&nbsp;&nbsp;&nbsp;Vern

---

<div class="post-metadata">

**Author:** ![Seth\_Hall3](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Seth\_Hall3](https://community.zeek.org/u/Seth_Hall3)\
**Post date:** [June 16, 2011, 3:36am UTC](https://community.zeek.org/t/eval/1901/3 "2011-06-16T03:36:16Z")

</div>

> This strikes me as definitely going down the wrong path - making code less  
> clear rather than more clear.

Heh, exactly why I was looking for feedback. 🙂

> I'm not understanding how the second is better than the first. Indeed,  
> now I have to go look at how ignore\_it works to know what's going on.

Syntactically it wasn't really any better. I guess I wasn't very clear in my email earlier. What it was doing was clearing up a somewhat ambiguously defined area internally in the notice code by getting rid of the action\_filters since the notice policy does essentially the same thing but in a different way. Having both methods can bite you because you have to know the internal organization of the notice framework to effectively use it.

> Here it seems if you must go this route, the right fix is either a notion  
> of currying (or partial application) of functions, or to have a single  
> PolicyItem for ignoring that looks up n$note in a table, and just add  
> DPD::ProtocolViolation to that table.

That's exactly what I ended up doing right after I sent the email. 🙂

I'm almost certain I've still missed some use case for the notice framework or made some odd design decisions (I think I'm well known for those!), but I'll fix everything once the script gets reviewed more closely.

Thanks for trudging through that whole email.

&nbsp;&nbsp;.Seth

---

<div class="post-metadata">

**Author:** ![robin](https://yyz1.discourse-cdn.com/flex011/user_avatar/community.zeek.org/robin/32/599_2.png) [@robin](https://community.zeek.org/u/robin)\
**Post date:** [June 17, 2011, 12:34am UTC](https://community.zeek.org/t/eval/1901/4 "2011-06-17T00:34:59Z")

</div>

For the record, I don't think this would be easy at all. 🙂

Robin

---

<div class="post-metadata">

**Author:** ![Seth\_Hall3](https://avatars.discourse-cdn.com/v4/letter/s/d6d6ee/32.png) [@Seth\_Hall3](https://community.zeek.org/u/Seth_Hall3)\
**Post date:** [June 17, 2011, 1:23pm UTC](https://community.zeek.org/t/eval/1901/5 "2011-06-17T13:23:12Z")

</div>

Hah, ok. 🙂

&nbsp;&nbsp;.Seth

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/zeek/original/1X/f09d732bc2cc7c7cc7e35db67cf4e1d5233ce7a7.png) [@system](https://community.zeek.org/u/system)\
**Post date:** [May 6, 2022, 3:39pm UTC](https://community.zeek.org/t/eval/1901/6 "2022-05-06T15:39:36Z")

</div>


