mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
teredo: Move conn member from analyzer to encapsulation
There's only a single instance of the Teredo analyzer. Mutating the conn member for every new packet and leaving it set after processing the packet is confusing. Move conn into TeredoEncapsulation instead, or pass it explicitly.
This commit is contained in:
parent
ba91de59b0
commit
6a930c1cf8
2 changed files with 9 additions and 10 deletions
|
@ -153,14 +153,14 @@ bool TeredoAnalyzer::AnalyzePacket(size_t len, const uint8_t* data, Packet* pack
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
conn = static_cast<Connection*>(packet->session);
|
auto* conn = static_cast<Connection*>(packet->session);
|
||||||
zeek::detail::ConnKey conn_key = conn->Key();
|
zeek::detail::ConnKey conn_key = conn->Key();
|
||||||
|
|
||||||
OrigRespMap::iterator or_it = orig_resp_map.find(conn_key);
|
OrigRespMap::iterator or_it = orig_resp_map.find(conn_key);
|
||||||
if ( or_it == orig_resp_map.end() )
|
if ( or_it == orig_resp_map.end() )
|
||||||
or_it = orig_resp_map.insert(or_it, {conn_key, {}});
|
or_it = orig_resp_map.insert(or_it, {conn_key, {}});
|
||||||
|
|
||||||
detail::TeredoEncapsulation te(this);
|
detail::TeredoEncapsulation te(this, conn);
|
||||||
if ( ! te.Parse(data, len) ) {
|
if ( ! te.Parse(data, len) ) {
|
||||||
AnalyzerViolation("Bad Teredo encapsulation", conn, (const char*)data, len);
|
AnalyzerViolation("Bad Teredo encapsulation", conn, (const char*)data, len);
|
||||||
return false;
|
return false;
|
||||||
|
@ -175,7 +175,7 @@ bool TeredoAnalyzer::AnalyzePacket(size_t len, const uint8_t* data, Packet* pack
|
||||||
if ( inner->NextProto() == IPPROTO_NONE && inner->PayloadLen() == 0 )
|
if ( inner->NextProto() == IPPROTO_NONE && inner->PayloadLen() == 0 )
|
||||||
// Teredo bubbles having data after IPv6 header isn't strictly a
|
// Teredo bubbles having data after IPv6 header isn't strictly a
|
||||||
// violation, but a little weird.
|
// violation, but a little weird.
|
||||||
Weird("Teredo_bubble_with_payload", true);
|
Weird(conn, "Teredo_bubble_with_payload", true);
|
||||||
else {
|
else {
|
||||||
AnalyzerViolation("Teredo payload length", conn, (const char*)data, len);
|
AnalyzerViolation("Teredo payload length", conn, (const char*)data, len);
|
||||||
return false;
|
return false;
|
||||||
|
@ -193,7 +193,7 @@ bool TeredoAnalyzer::AnalyzePacket(size_t len, const uint8_t* data, Packet* pack
|
||||||
else
|
else
|
||||||
or_it->second.valid_resp = true;
|
or_it->second.valid_resp = true;
|
||||||
|
|
||||||
Confirm(or_it->second.valid_orig, or_it->second.valid_resp);
|
Confirm(conn, or_it->second.valid_orig, or_it->second.valid_resp);
|
||||||
|
|
||||||
ValPtr teredo_hdr;
|
ValPtr teredo_hdr;
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ public:
|
||||||
* than helpful. The *force* param is meant for cases where just one side
|
* than helpful. The *force* param is meant for cases where just one side
|
||||||
* has a valid encapsulation and so the weird would be informative.
|
* has a valid encapsulation and so the weird would be informative.
|
||||||
*/
|
*/
|
||||||
void Weird(const char* name, bool force = false) const {
|
void Weird(Connection* conn, const char* name, bool force = false) const {
|
||||||
if ( AnalyzerConfirmed(conn) || force )
|
if ( AnalyzerConfirmed(conn) || force )
|
||||||
reporter->Weird(conn, name, "", GetAnalyzerName());
|
reporter->Weird(conn, name, "", GetAnalyzerName());
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ public:
|
||||||
* If the delayed confirmation option is set, then a valid encapsulation
|
* If the delayed confirmation option is set, then a valid encapsulation
|
||||||
* seen from both end points is required before confirming.
|
* seen from both end points is required before confirming.
|
||||||
*/
|
*/
|
||||||
void Confirm(bool valid_orig, bool valid_resp) {
|
void Confirm(Connection* conn, bool valid_orig, bool valid_resp) {
|
||||||
if ( ! BifConst::Tunnel::delay_teredo_confirmation || (valid_orig && valid_resp) ) {
|
if ( ! BifConst::Tunnel::delay_teredo_confirmation || (valid_orig && valid_resp) ) {
|
||||||
AnalyzerConfirmation(conn);
|
AnalyzerConfirmation(conn);
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,6 @@ public:
|
||||||
void RemoveConnection(const zeek::detail::ConnKey& conn_key) { orig_resp_map.erase(conn_key); }
|
void RemoveConnection(const zeek::detail::ConnKey& conn_key) { orig_resp_map.erase(conn_key); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Connection* conn = nullptr;
|
|
||||||
|
|
||||||
struct OrigResp {
|
struct OrigResp {
|
||||||
bool valid_orig = false;
|
bool valid_orig = false;
|
||||||
bool valid_resp = false;
|
bool valid_resp = false;
|
||||||
|
@ -63,7 +61,7 @@ namespace detail {
|
||||||
|
|
||||||
class TeredoEncapsulation {
|
class TeredoEncapsulation {
|
||||||
public:
|
public:
|
||||||
explicit TeredoEncapsulation(const TeredoAnalyzer* ta) : analyzer(ta) {}
|
TeredoEncapsulation(const TeredoAnalyzer* ta, Connection* conn) : analyzer(ta), conn(conn) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns whether input data parsed as a valid Teredo encapsulation type.
|
* Returns whether input data parsed as a valid Teredo encapsulation type.
|
||||||
|
@ -82,12 +80,13 @@ public:
|
||||||
private:
|
private:
|
||||||
bool DoParse(const u_char* data, size_t& len, bool found_orig, bool found_au);
|
bool DoParse(const u_char* data, size_t& len, bool found_orig, bool found_au);
|
||||||
|
|
||||||
void Weird(const char* name) const { analyzer->Weird(name); }
|
void Weird(const char* name) const { analyzer->Weird(conn, name); }
|
||||||
|
|
||||||
const u_char* inner_ip = nullptr;
|
const u_char* inner_ip = nullptr;
|
||||||
const u_char* origin_indication = nullptr;
|
const u_char* origin_indication = nullptr;
|
||||||
const u_char* auth = nullptr;
|
const u_char* auth = nullptr;
|
||||||
const TeredoAnalyzer* analyzer = nullptr;
|
const TeredoAnalyzer* analyzer = nullptr;
|
||||||
|
Connection* conn = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace detail
|
} // namespace detail
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue