-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathIpReassembler.h
74 lines (64 loc) · 1.92 KB
/
IpReassembler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#pragma once
#include <map>
#include "IpReassemblyBuffer.h"
#include "IpFragment.h"
#include "IntervalKeeper.h"
#include "Config.h"
namespace FeatureExtractor {
using namespace std;
/*
* IP Reassembly
* Techniques to cope with IP fragmentation based od RFC 815
*/
class IpReassembler
{
/**
* Reassembly buffer identification (key for map)
* RFC 815 Section 7:
* The correct reassembly buffer is identified by an equality of the following
* fields: the foreign and local internet address, the protocol ID,
* and the identification field.
*/
class IpReassemblyBufferKey {
uint32_t src;
uint32_t dst;
ip_field_protocol_t proto;
uint16_t id;
public:
IpReassemblyBufferKey();
IpReassemblyBufferKey(const IpFragment *fragment);
bool operator<(const IpReassemblyBufferKey& other) const; // Required for map<> key
};
// IP Reassembly buffers
typedef map<IpReassemblyBufferKey, IpReassemblyBuffer*> BufferMap;
BufferMap buffer_map;
// Timeout values & timeout check interval
Config timeouts;
IntervalKeeper timeout_interval;
/**
* Forwards fragment of fragmented datagram to correct buffer for reassembly.
*
* If reassembly is completed, datagram is returned. Otherwise the return
* values is nullptr.
*/
IpDatagram *forward_to_buffer(IpFragment *fragment);
/**
* Removes timed out reassembly buffers - "drops incomplete datagrams"
*/
void check_timeouts(const Timestamp &now);
public:
IpReassembler();
IpReassembler(Config &timeouts);
~IpReassembler();
/**
* Pass fragment to IP reassembler.
*
* If new datagram/packet is successfully reassembled, it is returned.
* Otherwise nullpter is returned.
* IpFragment object passed by pointer might be deleted after reassembly,
* thus it must not be used after this call. Caller must take care
* of erasing the returned object.
*/
Packet *reassemble(IpFragment *fragment);
};
}