mirror of
https://github.com/zeek/zeek.git
synced 2025-10-05 08:08:19 +00:00
GH-1119: add base/protcols/conn/removal-hooks.zeek
This adds two new functions: `Conn::register_removal_hook()` and `Conn::unregister_removal_hook()` for registering a hook function to be called back during `connection_state_remove`. The benefit of using hook callback approach is better scalability: the overhead of unrelated protocols having to dispatch no-op `connection_state_remove` handlers is avoided.
This commit is contained in:
parent
49e2047da0
commit
05cf511f18
31 changed files with 659 additions and 386 deletions
27
testing/btest/scripts/base/protocols/conn/removal-hooks.zeek
Normal file
27
testing/btest/scripts/base/protocols/conn/removal-hooks.zeek
Normal file
|
@ -0,0 +1,27 @@
|
|||
# @TEST-EXEC: zeek -b -r $TRACES/http/get.trace %INPUT >out
|
||||
# @TEST-EXEC: zeek -b -r $TRACES/http/get.trace %INPUT test_unregister=T >>out
|
||||
# @TEST-EXEC: btest-diff out
|
||||
|
||||
@load base/protocols/conn/removal-hooks
|
||||
|
||||
option test_unregister = F;
|
||||
|
||||
hook my_removal_hook(c: connection)
|
||||
{
|
||||
print "my_removal_hook", c$id;
|
||||
}
|
||||
|
||||
event new_connection(c: connection)
|
||||
{
|
||||
print "new_connection", c$id;
|
||||
print Conn::register_removal_hook(c, my_removal_hook);
|
||||
print Conn::register_removal_hook(c, my_removal_hook);
|
||||
print Conn::register_removal_hook(c, my_removal_hook);
|
||||
|
||||
if ( test_unregister )
|
||||
{
|
||||
print Conn::unregister_removal_hook(c, my_removal_hook);
|
||||
print Conn::unregister_removal_hook(c, my_removal_hook);
|
||||
print Conn::unregister_removal_hook(c, my_removal_hook);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue