Branch data Line data Source code
1 : : // $Id:$
2 : : //
3 : : // See the file "COPYING" in the main distribution directory for copyright.
4 : :
5 : : #ifndef dns_rewriter_h
6 : : #define dns_rewriter_h
7 : :
8 : : #include "UDP.h"
9 : : #include "UDP_Rewriter.h"
10 : : #include "Rewriter.h"
11 : :
12 : : #define DNS_HDR_SIZE 12
13 : :
14 : : // DNS packets size. 512 is the *normal* size, but some packets are bigger
15 : : // than this, and the anonymization process can expand packets, so we
16 : : // pad this way out.
17 : : #define DNS_PKT_SIZE (512*4)
18 : :
19 : : class DNS_Rewriter: public UDP_Rewriter {
20 : : public:
21 : : DNS_Rewriter(Analyzer* analyzer, int arg_MTU, PacketDumper* dumper);
22 [ # # ][ # # ]: 0 : virtual ~DNS_Rewriter() { delete pkt;}
23 : :
24 : : void DnsCopyHeader(Val* val);
25 : :
26 : : int DnsCopyQuery(const BroString* query, uint32 qtype, uint32 qclass);
27 : : int DnsCopyQuery(Val* val);
28 : :
29 : : void DnsCopyNS(Val* ans, const BroString* name);
30 : : void DnsCopyPTR(Val* ans, const BroString* name);
31 : : void DnsCopyCNAME(Val* ans, const BroString* name);
32 : : void DnsCopyTXT(Val* ans, const BroString* name);
33 : : void DnsCopyA(Val* ans, uint32 addr);
34 : :
35 : : // AAAA is weird, because the address is an IPv4 type.
36 : : // If we don't have IPv6, and if it's IPv6, it's a pointer
37 : : // to valid data.
38 : : void DnsCopyAAAA(Val* ans, addr_type addr, const BroString* addrstr);
39 : :
40 : : void DnsCopyMX(Val* ans, const BroString* name, uint32 preference);
41 : : void DnsCopySOA(Val* ans, Val* soa);
42 : : void DnsCopyEDNSaddl(Val* ans);
43 : :
44 : : int DnsPktMatch(Val* val);
45 : 0 : const u_char* Packet() const { return pkt; }
46 : 0 : int PacketSize() const { return pkt_size; }
47 : 0 : void SetOrig( int orig ) { is_orig = orig; }
48 : 0 : int IsOrig() { return is_orig; }
49 : :
50 : 0 : int WriteDoubleAsInt(double d) { return WriteVal(uint32(d)); }
51 : 0 : int WriteShortVal(uint16 val) { return WriteVal(uint16(val)); }
52 : : int WriteVal(uint32 val);
53 : : int WriteVal(uint16 val);
54 : : int WriteVal(uint8 val);
55 : : int WriteVal(const uint32* val);
56 : : int WriteVal(const BroString* val);
57 : :
58 : : private:
59 : : u_char* pkt; // the DNS packet
60 : : int pkt_size; // size of the packet
61 : : int current_pkt_id; // current ID (sanity checking)
62 : :
63 : : int is_orig;
64 : :
65 : : u_char* dn_ptrs[30]; // pointer to names in DNS packet
66 : : u_char** dpp; // points to current position in DNS packet
67 : : u_char** last_dn_ptr; // points to last entry in dn_ptrs
68 : : };
69 : :
70 : : #endif
|