mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Just some cleanup/documentation of new tunnel-handling code.
This commit is contained in:
parent
0bdbeb89e2
commit
beacf581d3
12 changed files with 112 additions and 65 deletions
55
src/TunnelEncapsulation.cc
Normal file
55
src/TunnelEncapsulation.cc
Normal file
|
@ -0,0 +1,55 @@
|
|||
// See the file "COPYING" in the main distribution directory for copyright.
|
||||
|
||||
#include "TunnelEncapsulation.h"
|
||||
#include "util.h"
|
||||
#include "Conn.h"
|
||||
|
||||
EncapsulatingConn::EncapsulatingConn(Connection* c, BifEnum::Tunnel::Type t)
|
||||
: src_addr(c->OrigAddr()), dst_addr(c->RespAddr()),
|
||||
src_port(c->OrigPort()), dst_port(c->RespPort()),
|
||||
proto(c->ConnTransport()), type(t), uid(c->GetUID())
|
||||
{
|
||||
if ( ! uid )
|
||||
{
|
||||
uid = calculate_unique_id();
|
||||
c->SetUID(uid);
|
||||
}
|
||||
}
|
||||
|
||||
RecordVal* EncapsulatingConn::GetRecordVal() const
|
||||
{
|
||||
RecordVal *rv = new RecordVal(BifType::Record::Tunnel::EncapsulatingConn);
|
||||
|
||||
RecordVal* id_val = new RecordVal(conn_id);
|
||||
id_val->Assign(0, new AddrVal(src_addr));
|
||||
id_val->Assign(1, new PortVal(ntohs(src_port), proto));
|
||||
id_val->Assign(2, new AddrVal(dst_addr));
|
||||
id_val->Assign(3, new PortVal(ntohs(dst_port), proto));
|
||||
rv->Assign(0, id_val);
|
||||
rv->Assign(1, new EnumVal(type, BifType::Enum::Tunnel::Type));
|
||||
char tmp[20];
|
||||
rv->Assign(2, new StringVal(uitoa_n(uid, tmp, sizeof(tmp), 62)));
|
||||
return rv;
|
||||
}
|
||||
|
||||
bool operator==(const Encapsulation& e1, const Encapsulation& e2)
|
||||
{
|
||||
if ( e1.conns )
|
||||
if ( e2.conns )
|
||||
{
|
||||
if ( e1.conns->size() != e2.conns->size() )
|
||||
return false;
|
||||
else
|
||||
for ( size_t i = 0; i < e1.conns->size(); ++i )
|
||||
if ( (*e1.conns)[i] != (*e2.conns)[i] )
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
else
|
||||
if ( e2.conns )
|
||||
return false;
|
||||
else
|
||||
return true;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue