Merge remote-tracking branch 'origin/topic/v6-addr' into topic/v6-addr-merge

Conflicts:
	src/DNS_Mgr.cc
	src/Expr.cc
	src/bro.bif
This commit is contained in:
Robin Sommer 2012-02-16 18:28:40 -08:00
commit 5565e19e57
12 changed files with 137 additions and 147 deletions

View file

@ -766,12 +766,20 @@ int DNS_Interpreter::ParseRR_AAAA(DNS_MsgInfo* msg,
if ( len < 0 ) if ( len < 0 )
{ {
analyzer->Weird("DNS_AAAA_neg_length"); if ( msg->atype == TYPE_AAAA )
analyzer->Weird("DNS_AAAA_neg_length");
else
analyzer->Weird("DNS_A6_neg_length");
return 0; return 0;
} }
} }
if ( dns_AAAA_reply && ! msg->skip_event ) EventHandlerPtr event;
if ( msg->atype == TYPE_AAAA )
event = dns_AAAA_reply;
else
event = dns_A6_reply;
if ( event && ! msg->skip_event )
{ {
val_list* vl = new val_list; val_list* vl = new val_list;
@ -779,7 +787,7 @@ int DNS_Interpreter::ParseRR_AAAA(DNS_MsgInfo* msg,
vl->append(msg->BuildHdrVal()); vl->append(msg->BuildHdrVal());
vl->append(msg->BuildAnswerVal()); vl->append(msg->BuildAnswerVal());
vl->append(new AddrVal(addr)); vl->append(new AddrVal(addr));
analyzer->ConnectionEvent(dns_AAAA_reply, vl); analyzer->ConnectionEvent(event, vl);
} }
return 1; return 1;

View file

@ -46,13 +46,13 @@ extern int select(int, fd_set *, fd_set *, fd_set *, struct timeval *);
class DNS_Mgr_Request { class DNS_Mgr_Request {
public: public:
DNS_Mgr_Request(const char* h) { host = copy_string(h); addr = 0; } DNS_Mgr_Request(const char* h) { host = copy_string(h); }
DNS_Mgr_Request(uint32 a) { addr = a; host = 0; } DNS_Mgr_Request(const IPAddr& a) { addr = a; host = 0; }
~DNS_Mgr_Request() { delete [] host; } ~DNS_Mgr_Request() { delete [] host; }
// Returns nil if this was an address request. // Returns nil if this was an address request.
const char* ReqHost() const { return host; } const char* ReqHost() const { return host; }
uint32 ReqAddr() const { return addr; } const IPAddr& ReqAddr() const { return addr; }
int MakeRequest(nb_dns_info* nb_dns); int MakeRequest(nb_dns_info* nb_dns);
int RequestPending() const { return request_pending; } int RequestPending() const { return request_pending; }
@ -61,7 +61,7 @@ public:
protected: protected:
char* host; // if non-nil, this is a host request char* host; // if non-nil, this is a host request
uint32 addr; IPAddr addr;
uint32 ttl; uint32 ttl;
int request_pending; int request_pending;
}; };
@ -77,13 +77,18 @@ int DNS_Mgr_Request::MakeRequest(nb_dns_info* nb_dns)
if ( host ) if ( host )
return nb_dns_host_request(nb_dns, host, (void*) this, err) >= 0; return nb_dns_host_request(nb_dns, host, (void*) this, err) >= 0;
else else
return nb_dns_addr_request(nb_dns, addr, (void*) this, err) >= 0; {
const uint32* bytes;
int len = addr.GetBytes(&bytes);
return nb_dns_addr_request2(nb_dns, (char*) bytes,
len == 1 ? AF_INET : AF_INET6, (void*) this, err) >= 0;
}
} }
class DNS_Mapping { class DNS_Mapping {
public: public:
DNS_Mapping(const char* host, struct hostent* h, uint32 ttl); DNS_Mapping(const char* host, struct hostent* h, uint32 ttl);
DNS_Mapping(uint32 addr, struct hostent* h, uint32 ttl); DNS_Mapping(const IPAddr& addr, struct hostent* h, uint32 ttl);
DNS_Mapping(FILE* f); DNS_Mapping(FILE* f);
int NoMapping() const { return no_mapping; } int NoMapping() const { return no_mapping; }
@ -93,10 +98,10 @@ public:
// Returns nil if this was an address request. // Returns nil if this was an address request.
const char* ReqHost() const { return req_host; } const char* ReqHost() const { return req_host; }
uint32 ReqAddr() const { return req_addr; } IPAddr ReqAddr() const { return req_addr; }
string ReqStr() const string ReqStr() const
{ {
return req_host ? req_host : IPAddr(IPAddr::IPv4, &req_addr, IPAddr::Network); return req_host ? req_host : req_addr;
} }
ListVal* Addrs(); ListVal* Addrs();
@ -123,7 +128,7 @@ protected:
int init_failed; int init_failed;
char* req_host; char* req_host;
uint32 req_addr; IPAddr req_addr;
uint32 req_ttl; uint32 req_ttl;
int num_names; int num_names;
@ -131,7 +136,7 @@ protected:
StringVal* host_val; StringVal* host_val;
int num_addrs; int num_addrs;
uint32* addrs; IPAddr* addrs;
ListVal* addrs_val; ListVal* addrs_val;
int failed; int failed;
@ -156,14 +161,13 @@ DNS_Mapping::DNS_Mapping(const char* host, struct hostent* h, uint32 ttl)
{ {
Init(h); Init(h);
req_host = copy_string(host); req_host = copy_string(host);
req_addr = 0;
req_ttl = ttl; req_ttl = ttl;
if ( names && ! names[0] ) if ( names && ! names[0] )
names[0] = copy_string(host); names[0] = copy_string(host);
} }
DNS_Mapping::DNS_Mapping(uint32 addr, struct hostent* h, uint32 ttl) DNS_Mapping::DNS_Mapping(const IPAddr& addr, struct hostent* h, uint32 ttl)
{ {
Init(h); Init(h);
req_addr = addr; req_addr = addr;
@ -177,7 +181,6 @@ DNS_Mapping::DNS_Mapping(FILE* f)
init_failed = 1; init_failed = 1;
req_host = 0; req_host = 0;
req_addr = 0;
char buf[512]; char buf[512];
@ -197,12 +200,7 @@ DNS_Mapping::DNS_Mapping(FILE* f)
if ( is_req_host ) if ( is_req_host )
req_host = copy_string(req_buf); req_host = copy_string(req_buf);
else else
{ req_addr = IPAddr(req_buf);
IPAddr addr(req_buf);
const uint32* bytes;
addr.GetBytes(&bytes);
req_addr = *bytes; //FIXME: IPv6 support
}
num_names = 1; num_names = 1;
names = new char*[num_names]; names = new char*[num_names];
@ -210,7 +208,7 @@ DNS_Mapping::DNS_Mapping(FILE* f)
if ( num_addrs > 0 ) if ( num_addrs > 0 )
{ {
addrs = new uint32[num_addrs]; addrs = new IPAddr[num_addrs];
for ( int i = 0; i < num_addrs; ++i ) for ( int i = 0; i < num_addrs; ++i )
{ {
@ -224,10 +222,7 @@ DNS_Mapping::DNS_Mapping(FILE* f)
if ( newline ) if ( newline )
*newline = '\0'; *newline = '\0';
IPAddr addr(buf); addrs[i] = IPAddr(buf);
const uint32* bytes;
addr.GetBytes(&bytes);
addrs[i] = *bytes; //FIXME IPv6 support
} }
} }
else else
@ -290,14 +285,6 @@ StringVal* DNS_Mapping::Host()
return host_val; return host_val;
} }
// Converts an array of 4 bytes in network order to the corresponding
// 32-bit network long.
static uint32 raw_bytes_to_addr(const unsigned char b[4])
{
uint32 l = (b[0] << 24) | (b[1] << 16) | (b[2] << 8) | b[3];
return uint32(htonl(l));
}
void DNS_Mapping::Init(struct hostent* h) void DNS_Mapping::Init(struct hostent* h)
{ {
no_mapping = 0; no_mapping = 0;
@ -306,7 +293,7 @@ void DNS_Mapping::Init(struct hostent* h)
host_val = 0; host_val = 0;
addrs_val = 0; addrs_val = 0;
if ( ! h || h->h_addrtype != AF_INET || h->h_length != 4 ) if ( ! h )
{ {
Clear(); Clear();
return; return;
@ -321,10 +308,14 @@ void DNS_Mapping::Init(struct hostent* h)
if ( num_addrs > 0 ) if ( num_addrs > 0 )
{ {
addrs = new uint32[num_addrs]; addrs = new IPAddr[num_addrs];
for ( int i = 0; i < num_addrs; ++i ) for ( int i = 0; i < num_addrs; ++i )
addrs[i] = raw_bytes_to_addr( if ( h->h_addrtype == AF_INET )
(unsigned char*)h->h_addr_list[i]); addrs[i] = IPAddr(IPAddr::IPv4, (uint32*)h->h_addr_list[i],
IPAddr::Network);
else if ( h->h_addrtype == AF_INET6 )
addrs[i] = IPAddr(IPAddr::IPv6, (uint32*)h->h_addr_list[i],
IPAddr::Network);
} }
else else
addrs = 0; addrs = 0;
@ -346,14 +337,12 @@ void DNS_Mapping::Clear()
void DNS_Mapping::Save(FILE* f) const void DNS_Mapping::Save(FILE* f) const
{ {
fprintf(f, "%.0f %d %s %d %s %d\n", creation_time, req_host != 0, fprintf(f, "%.0f %d %s %d %s %d\n", creation_time, req_host != 0,
req_host ? req_host : req_host ? req_host : req_addr.AsString().c_str(),
IPAddr(IPAddr::IPv4, &req_addr, IPAddr::Network).AsString().c_str(),
failed, (names && names[0]) ? names[0] : "*", failed, (names && names[0]) ? names[0] : "*",
num_addrs); num_addrs);
for ( int i = 0; i < num_addrs; ++i ) for ( int i = 0; i < num_addrs; ++i )
fprintf(f, "%s\n", fprintf(f, "%s\n", addrs[i].AsString().c_str());
IPAddr(IPAddr::IPv4, &addrs[i], IPAddr::Network).AsString().c_str());
} }
@ -487,14 +476,14 @@ TableVal* DNS_Mgr::LookupHost(const char* name)
} }
} }
Val* DNS_Mgr::LookupAddr(uint32 addr) Val* DNS_Mgr::LookupAddr(const IPAddr& addr)
{ {
if ( ! did_init ) if ( ! did_init )
Init(); Init();
if ( mode != DNS_PRIME ) if ( mode != DNS_PRIME )
{ {
HashKey h(&addr, 1); HashKey h(addr);
DNS_Mapping* d = addr_mappings.Lookup(&h); DNS_Mapping* d = addr_mappings.Lookup(&h);
if ( d ) if ( d )
@ -503,7 +492,7 @@ Val* DNS_Mgr::LookupAddr(uint32 addr)
return d->Host(); return d->Host();
else else
{ {
string s = IPAddr(IPAddr::IPv4, &addr, IPAddr::Network); string s(addr);
reporter->Warning("can't resolve IP address: %s", s.c_str()); reporter->Warning("can't resolve IP address: %s", s.c_str());
return new StringVal(s.c_str()); return new StringVal(s.c_str());
} }
@ -518,7 +507,7 @@ Val* DNS_Mgr::LookupAddr(uint32 addr)
case DNS_FORCE: case DNS_FORCE:
reporter->FatalError("can't find DNS entry for %s in cache", reporter->FatalError("can't find DNS entry for %s in cache",
IPAddr(IPAddr::IPv4, &addr, IPAddr::Network).AsString().c_str()); addr.AsString().c_str());
return 0; return 0;
case DNS_DEFAULT: case DNS_DEFAULT:
@ -707,14 +696,12 @@ void DNS_Mgr::AddResult(DNS_Mgr_Request* dr, struct nb_dns_result* r)
else else
{ {
new_dm = new DNS_Mapping(dr->ReqAddr(), h, ttl); new_dm = new DNS_Mapping(dr->ReqAddr(), h, ttl);
uint32 tmp_addr = dr->ReqAddr(); HashKey k(dr->ReqAddr());
HashKey k(&tmp_addr, 1);
prev_dm = addr_mappings.Insert(&k, new_dm); prev_dm = addr_mappings.Insert(&k, new_dm);
if ( new_dm->Failed() && prev_dm && prev_dm->Valid() ) if ( new_dm->Failed() && prev_dm && prev_dm->Valid() )
{ {
uint32 tmp_addr = dr->ReqAddr(); HashKey k2(dr->ReqAddr());
HashKey k2(&tmp_addr, 1);
(void) addr_mappings.Insert(&k2, prev_dm); (void) addr_mappings.Insert(&k2, prev_dm);
++keep_prev; ++keep_prev;
} }
@ -826,8 +813,7 @@ void DNS_Mgr::LoadCache(FILE* f)
host_mappings.Insert(m->ReqHost(), m); host_mappings.Insert(m->ReqHost(), m);
else else
{ {
uint32 tmp_addr = m->ReqAddr(); HashKey h(m->ReqAddr());
HashKey h(&tmp_addr, 1);
addr_mappings.Insert(&h, m); addr_mappings.Insert(&h, m);
} }
} }
@ -848,9 +834,9 @@ void DNS_Mgr::Save(FILE* f, PDict(DNS_Mapping)& m)
dm->Save(f); dm->Save(f);
} }
const char* DNS_Mgr::LookupAddrInCache(dns_mgr_addr_type addr) const char* DNS_Mgr::LookupAddrInCache(const IPAddr& addr)
{ {
HashKey h(&addr, 1); HashKey h(addr);
DNS_Mapping* d = dns_mgr->addr_mappings.Lookup(&h); DNS_Mapping* d = dns_mgr->addr_mappings.Lookup(&h);
if ( ! d ) if ( ! d )
@ -886,7 +872,7 @@ TableVal* DNS_Mgr::LookupNameInCache(string name)
return d->AddrsSet(); return d->AddrsSet();
} }
void DNS_Mgr::AsyncLookupAddr(dns_mgr_addr_type host, LookupCallback* callback) void DNS_Mgr::AsyncLookupAddr(const IPAddr& host, LookupCallback* callback)
{ {
if ( ! did_init ) if ( ! did_init )
Init(); Init();
@ -996,7 +982,7 @@ double DNS_Mgr::NextTimestamp(double* network_time)
return asyncs_timeouts.size() ? timer_mgr->Time() : -1.0; return asyncs_timeouts.size() ? timer_mgr->Time() : -1.0;
} }
void DNS_Mgr::CheckAsyncAddrRequest(dns_mgr_addr_type addr, bool timeout) void DNS_Mgr::CheckAsyncAddrRequest(const IPAddr& addr, bool timeout)
{ {
// Note that this code is a mirror of that for CheckAsyncHostRequest. // Note that this code is a mirror of that for CheckAsyncHostRequest.

View file

@ -40,10 +40,6 @@ enum DNS_MgrMode {
// Number of seconds we'll wait for a reply. // Number of seconds we'll wait for a reply.
#define DNS_TIMEOUT 5 #define DNS_TIMEOUT 5
// ### For now, we don't support IPv6 lookups. When we do, this
// should become addr_type.
typedef uint32 dns_mgr_addr_type;
class DNS_Mgr : public IOSource { class DNS_Mgr : public IOSource {
public: public:
DNS_Mgr(DNS_MgrMode mode); DNS_Mgr(DNS_MgrMode mode);
@ -56,7 +52,7 @@ public:
// a set of addr. // a set of addr.
TableVal* LookupHost(const char* host); TableVal* LookupHost(const char* host);
Val* LookupAddr(uint32 addr); Val* LookupAddr(const IPAddr& addr);
// Define the directory where to store the data. // Define the directory where to store the data.
void SetDir(const char* arg_dir) { dir = copy_string(arg_dir); } void SetDir(const char* arg_dir) { dir = copy_string(arg_dir); }
@ -65,7 +61,7 @@ public:
void Resolve(); void Resolve();
int Save(); int Save();
const char* LookupAddrInCache(dns_mgr_addr_type addr); const char* LookupAddrInCache(const IPAddr& addr);
TableVal* LookupNameInCache(string name); TableVal* LookupNameInCache(string name);
// Support for async lookups. // Support for async lookups.
@ -79,7 +75,7 @@ public:
virtual void Timeout() = 0; virtual void Timeout() = 0;
}; };
void AsyncLookupAddr(dns_mgr_addr_type host, LookupCallback* callback); void AsyncLookupAddr(const IPAddr& host, LookupCallback* callback);
void AsyncLookupName(string name, LookupCallback* callback); void AsyncLookupName(string name, LookupCallback* callback);
struct Stats { struct Stats {
@ -121,7 +117,7 @@ protected:
// Finish the request if we have a result. If not, time it out if // Finish the request if we have a result. If not, time it out if
// requested. // requested.
void CheckAsyncAddrRequest(dns_mgr_addr_type addr, bool timeout); void CheckAsyncAddrRequest(const IPAddr& addr, bool timeout);
void CheckAsyncHostRequest(const char* host, bool timeout); void CheckAsyncHostRequest(const char* host, bool timeout);
// Process outstanding requests. // Process outstanding requests.
@ -164,7 +160,7 @@ protected:
struct AsyncRequest { struct AsyncRequest {
double time; double time;
dns_mgr_addr_type host; IPAddr host;
string name; string name;
CallbackList callbacks; CallbackList callbacks;
@ -205,7 +201,7 @@ protected:
}; };
typedef map<dns_mgr_addr_type, AsyncRequest*> AsyncRequestAddrMap; typedef map<IPAddr, AsyncRequest*> AsyncRequestAddrMap;
AsyncRequestAddrMap asyncs_addrs; AsyncRequestAddrMap asyncs_addrs;
typedef map<string, AsyncRequest*> AsyncRequestNameMap; typedef map<string, AsyncRequest*> AsyncRequestNameMap;

View file

@ -17,22 +17,37 @@ ExpectedConn::ExpectedConn(const IPAddr& _orig, const IPAddr& _resp,
if ( _orig == IPAddr(string("0.0.0.0")) ) if ( _orig == IPAddr(string("0.0.0.0")) )
// don't use the IPv4 mapping, use the literal unspecified address // don't use the IPv4 mapping, use the literal unspecified address
// to indicate a wildcard // to indicate a wildcard
orig[0] = orig[1] = orig[2] = orig[3] = 0; orig = IPAddr(string("::"));
else else
_orig.CopyIPv6(orig); orig = _orig;
_resp.CopyIPv6(resp); resp = _resp;
resp_p = _resp_p; resp_p = _resp_p;
proto = _proto; proto = _proto;
} }
ExpectedConn::ExpectedConn(const ExpectedConn& c) ExpectedConn::ExpectedConn(const ExpectedConn& c)
{ {
memcpy(orig, c.orig, sizeof(orig)); orig = c.orig;
memcpy(resp, c.resp, sizeof(resp)); resp = c.resp;
resp_p = c.resp_p; resp_p = c.resp_p;
proto = c.proto; proto = c.proto;
} }
HashKey* ExpectedConn::GetKey() const
{
struct Key {
uint32 orig[4];
uint32 resp[4];
uint16 resp_p;
uint16 proto;
};
Key k;
orig.CopyIPv6(k.orig);
resp.CopyIPv6(k.resp);
k.resp_p = resp_p;
k.proto = proto;
return new HashKey(&k, sizeof(k));
}
DPM::DPM() DPM::DPM()
: expected_conns_queue(AssignedAnalyzer::compare) : expected_conns_queue(AssignedAnalyzer::compare)
@ -134,23 +149,18 @@ AnalyzerTag::Tag DPM::GetExpected(int proto, const Connection* conn)
ExpectedConn c(conn->OrigAddr(), conn->RespAddr(), ExpectedConn c(conn->OrigAddr(), conn->RespAddr(),
ntohs(conn->RespPort()), proto); ntohs(conn->RespPort()), proto);
// Can't use sizeof(c) due to potential alignment issues. HashKey* key = c.GetKey();
// FIXME: I guess this is still not portable ... AssignedAnalyzer* a = expected_conns.Lookup(key);
HashKey key(&c, sizeof(c.orig) + sizeof(c.resp) + delete key;
sizeof(c.resp_p) + sizeof(c.proto));
AssignedAnalyzer* a = expected_conns.Lookup(&key);
if ( ! a ) if ( ! a )
{ {
// Wildcard for originator. // Wildcard for originator.
for ( int i = 0; i < 4; ++i ) c.orig = IPAddr(string("::"));
c.orig[i] = 0;
HashKey key(&c, sizeof(c.orig) + sizeof(c.resp) + HashKey* key = c.GetKey();
sizeof(c.resp_p) + sizeof(c.proto)); a = expected_conns.Lookup(key);
delete key;
a = expected_conns.Lookup(&key);
} }
if ( ! a ) if ( ! a )
@ -393,11 +403,7 @@ void DPM::ExpectConnection(const IPAddr& orig, const IPAddr& resp,
{ {
if ( ! a->deleted ) if ( ! a->deleted )
{ {
HashKey* key = new HashKey(&a->conn, HashKey* key = a->conn.GetKey();
sizeof(a->conn.orig) +
sizeof(a->conn.resp) +
sizeof(a->conn.resp_p) +
sizeof(a->conn.proto));
expected_conns.Remove(key); expected_conns.Remove(key);
delete key; delete key;
} }
@ -416,10 +422,9 @@ void DPM::ExpectConnection(const IPAddr& orig, const IPAddr& resp,
ExpectedConn c(orig, resp, resp_p, proto); ExpectedConn c(orig, resp, resp_p, proto);
HashKey key(&c, sizeof(c.orig) + sizeof(c.resp) + HashKey* key = c.GetKey();
sizeof(c.resp_p) + sizeof(c.proto));
AssignedAnalyzer* a = expected_conns.Lookup(&key); AssignedAnalyzer* a = expected_conns.Lookup(key);
if ( a ) if ( a )
a->deleted = true; a->deleted = true;
@ -431,8 +436,9 @@ void DPM::ExpectConnection(const IPAddr& orig, const IPAddr& resp,
a->timeout = network_time + timeout; a->timeout = network_time + timeout;
a->deleted = false; a->deleted = false;
expected_conns.Insert(&key, a); expected_conns.Insert(key, a);
expected_conns_queue.push(a); expected_conns_queue.push(a);
delete key;
} }
void DPM::Done() void DPM::Done()
@ -443,11 +449,7 @@ void DPM::Done()
AssignedAnalyzer* a = expected_conns_queue.top(); AssignedAnalyzer* a = expected_conns_queue.top();
if ( ! a->deleted ) if ( ! a->deleted )
{ {
HashKey* key = new HashKey(&a->conn, HashKey* key = a->conn.GetKey();
sizeof(a->conn.orig) +
sizeof(a->conn.resp) +
sizeof(a->conn.resp_p) +
sizeof(a->conn.proto));
expected_conns.Remove(key); expected_conns.Remove(key);
delete key; delete key;
} }

View file

@ -32,8 +32,10 @@ public:
ExpectedConn(const ExpectedConn& c); ExpectedConn(const ExpectedConn& c);
uint32 orig[4]; HashKey* GetKey() const;
uint32 resp[4];
IPAddr orig;
IPAddr resp;
uint16 resp_p; uint16 resp_p;
uint16 proto; uint16 proto;
}; };

View file

@ -835,22 +835,30 @@ Val* BinaryExpr::StringFold(Val* v1, Val* v2) const
Val* BinaryExpr::AddrFold(Val* v1, Val* v2) const Val* BinaryExpr::AddrFold(Val* v1, Val* v2) const
{ {
uint32 a1[4]; IPAddr a1 = v1->AsAddr();
uint32 a2[4]; IPAddr a2 = v2->AsAddr();
v1->AsAddr().CopyIPv6(a1);
v2->AsAddr().CopyIPv6(a2);
int result = 0; int result = 0;
switch ( tag ) { switch ( tag ) {
#undef DO_FOLD
#define DO_FOLD(sense) { result = memcmp(a1, a2, 16) sense 0; break; }
case EXPR_LT: DO_FOLD(<) case EXPR_LT:
case EXPR_LE: DO_FOLD(<=) result = a1 < a2;
case EXPR_EQ: DO_FOLD(==) break;
case EXPR_NE: DO_FOLD(!=) case EXPR_LE:
case EXPR_GE: DO_FOLD(>=) result = a1 < a2 || a1 == a2;
case EXPR_GT: DO_FOLD(>) break;
case EXPR_EQ:
result = a1 == a2;
break;
case EXPR_NE:
result = a1 != a2;
break;
case EXPR_GE:
result = ! ( a1 < a2 );
break;
case EXPR_GT:
result = ( ! ( a1 < a2 ) ) && ( a1 != a2 );
break;
default: default:
BadTag("BinaryExpr::AddrFold", expr_name(tag)); BadTag("BinaryExpr::AddrFold", expr_name(tag));

View file

@ -103,6 +103,16 @@ HashKey::HashKey(const BroString* s)
is_our_dynamic = 0; is_our_dynamic = 0;
} }
HashKey::HashKey(const IPAddr& addr)
{
const uint32* bytes;
int len = addr.GetBytes(&bytes);
size = len * sizeof(uint32);
key = CopyKey(bytes, size);
is_our_dynamic = 1;
hash = HashBytes(key, size);
}
HashKey::HashKey(int copy_key, void* arg_key, int arg_size) HashKey::HashKey(int copy_key, void* arg_key, int arg_size)
{ {
size = arg_size; size = arg_size;

View file

@ -6,6 +6,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "BroString.h" #include "BroString.h"
#include "IPAddr.h"
#define UHASH_KEY_SIZE 36 #define UHASH_KEY_SIZE 36
@ -28,6 +29,7 @@ public:
HashKey(const void* p); HashKey(const void* p);
HashKey(const char* s); HashKey(const char* s);
HashKey(const BroString* s); HashKey(const BroString* s);
HashKey(const IPAddr& addr);
~HashKey() ~HashKey()
{ {
if ( is_our_dynamic ) if ( is_our_dynamic )

View file

@ -10,26 +10,22 @@
class IP_Hdr { class IP_Hdr {
public: public:
IP_Hdr(struct ip* arg_ip4) IP_Hdr(struct ip* arg_ip4)
: ip4(arg_ip4), ip6(0), : ip4(arg_ip4), ip6(0), del(1)
src_addr(arg_ip4->ip_src), dst_addr(arg_ip4->ip_dst), del(1)
{ {
} }
IP_Hdr(const struct ip* arg_ip4) IP_Hdr(const struct ip* arg_ip4)
: ip4(arg_ip4), ip6(0), : ip4(arg_ip4), ip6(0), del(0)
src_addr(arg_ip4->ip_src), dst_addr(arg_ip4->ip_dst), del(0)
{ {
} }
IP_Hdr(struct ip6_hdr* arg_ip6) IP_Hdr(struct ip6_hdr* arg_ip6)
: ip4(0), ip6(arg_ip6), : ip4(0), ip6(arg_ip6), del(1)
src_addr(arg_ip6->ip6_src), dst_addr(arg_ip6->ip6_dst), del(1)
{ {
} }
IP_Hdr(const struct ip6_hdr* arg_ip6) IP_Hdr(const struct ip6_hdr* arg_ip6)
: ip4(0), ip6(arg_ip6), : ip4(0), ip6(arg_ip6), del(0)
src_addr(arg_ip6->ip6_src), dst_addr(arg_ip6->ip6_dst), del(0)
{ {
} }
@ -47,8 +43,10 @@ public:
const struct ip* IP4_Hdr() const { return ip4; } const struct ip* IP4_Hdr() const { return ip4; }
const struct ip6_hdr* IP6_Hdr() const { return ip6; } const struct ip6_hdr* IP6_Hdr() const { return ip6; }
const IPAddr& SrcAddr() const { return src_addr; } IPAddr SrcAddr() const
const IPAddr& DstAddr() const { return dst_addr; } { return ip4 ? IPAddr(ip4->ip_src) : IPAddr(ip6->ip6_src); }
IPAddr DstAddr() const
{ return ip4 ? IPAddr(ip4->ip_dst) : IPAddr(ip6->ip6_dst); }
//TODO: needs adapting/replacement for IPv6 support //TODO: needs adapting/replacement for IPv6 support
uint16 ID4() const { return ip4 ? ip4->ip_id : 0; } uint16 ID4() const { return ip4 ? ip4->ip_id : 0; }
@ -92,8 +90,6 @@ public:
private: private:
const struct ip* ip4; const struct ip* ip4;
const struct ip6_hdr* ip6; const struct ip6_hdr* ip6;
IPAddr src_addr;
IPAddr dst_addr;
int del; int del;
}; };

View file

@ -923,7 +923,6 @@ SubNetVal::SubNetVal(const char* text, int width) : Val(TYPE_SUBNET)
val.subnet_val = new IPPrefix(text, width); val.subnet_val = new IPPrefix(text, width);
} }
#if 0
SubNetVal::SubNetVal(uint32 addr, int width) : Val(TYPE_SUBNET) SubNetVal::SubNetVal(uint32 addr, int width) : Val(TYPE_SUBNET)
{ {
IPAddr a(IPAddr::IPv4, &addr, IPAddr::Network); IPAddr a(IPAddr::IPv4, &addr, IPAddr::Network);
@ -935,7 +934,6 @@ SubNetVal::SubNetVal(const uint32* addr, int width) : Val(TYPE_SUBNET)
IPAddr a(IPAddr::IPv6, addr, IPAddr::Network); IPAddr a(IPAddr::IPv6, addr, IPAddr::Network);
val.subnet_val = new IPPrefix(a, width); val.subnet_val = new IPPrefix(a, width);
} }
#endif
SubNetVal::SubNetVal(const IPAddr& addr, int width) : Val(TYPE_SUBNET) SubNetVal::SubNetVal(const IPAddr& addr, int width) : Val(TYPE_SUBNET)
{ {

View file

@ -3441,25 +3441,7 @@ function lookup_addr%(host: addr%) : string
frame->SetDelayed(); frame->SetDelayed();
trigger->Hold(); trigger->Hold();
if ( host->AsAddr().GetFamily() != IPAddr::IPv4 ) dns_mgr->AsyncLookupAddr(host->AsAddr(),
{
// FIXME: This is a temporary work-around until we get this
// fixed. We warn the user once, and always trigger a timeout.
// Ticket #355 records the problem.
static bool warned = false;
if ( ! warned )
{
reporter->Warning("lookup_addr() only supports IPv4 addresses currently");
warned = true;
}
trigger->Timeout();
return 0;
}
const uint32* bytes;
host->AsAddr().GetBytes(&bytes);
dns_mgr->AsyncLookupAddr(*bytes,
new LookupHostCallback(trigger, frame->GetCall(), true)); new LookupHostCallback(trigger, frame->GetCall(), true));
return 0; return 0;
%} %}

View file

@ -186,7 +186,7 @@ _nb_dns_cmpsockaddr(register struct sockaddr *sa1,
#endif #endif
static const char serr[] = "answer from wrong nameserver (%d)"; static const char serr[] = "answer from wrong nameserver (%d)";
if (sa1->sa_family != sa1->sa_family) { if (sa1->sa_family != sa2->sa_family) {
snprintf(errstr, NB_DNS_ERRSIZE, serr, 1); snprintf(errstr, NB_DNS_ERRSIZE, serr, 1);
return (-1); return (-1);
} }
@ -381,7 +381,7 @@ nb_dns_addr_request2(register struct nb_dns_info *nd, char *addrp,
size -= i; size -= i;
cp += i; cp += i;
} }
snprintf(cp, size, "ip6.int"); snprintf(cp, size, "ip6.arpa");
break; break;
#endif #endif