Repository navigation
Expand file tree
/
Copy pathnetwork_layer.h
More file actions
65 lines (42 loc) · 1.58 KB
/
Copy pathnetwork_layer.h
File metadata and controls
65 lines (42 loc) · 1.58 KB
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
// (C) 2020-2022 by folkert van heusden <mail@vanheusden.com>, released under Apache License v2.0
#pragma once
#include <atomic>
#include <map>
#include <mutex>
#include <optional>
#include <stdint.h>
#include <thread>
#include <vector>
#include "fifo.h"
#include "packet.h"
#include "router.h"
class icmp;
class transport_layer;
class phys;
typedef struct {
phys *interface;
packet *p;
} fifo_element_t;
class network_layer
{
protected:
fifo<fifo_element_t> *pkts { nullptr };
phys *default_pdev { nullptr };
std::map<uint8_t, transport_layer *> prot_map;
icmp *icmp_ { nullptr };
router *r { nullptr };
public:
network_layer(stats *const s, const std::string & stats_name, router *const r);
virtual ~network_layer();
void ask_to_stop() { pkts->interrupt(); }
virtual any_addr get_addr() const = 0;
void register_default_phys(phys *const p) { default_pdev = p; }
void register_protocol(const uint8_t protocol, transport_layer *const p);
transport_layer *get_transport_layer(const uint8_t protocol);
void register_icmp(icmp *const icmp_) { this->icmp_ = icmp_; }
virtual void queue_incoming_packet(phys *const interface, packet *p);
virtual bool transmit_packet(const std::optional<any_addr> & dst_mac, const any_addr & dst_ip, const any_addr & src_ip, const uint8_t protocol, const uint8_t *payload, const size_t pl_size, const uint8_t *const header_template) = 0;
virtual int get_max_packet_size() const = 0;
virtual void operator()() = 0;
};
uint16_t ip_checksum(const uint16_t *p, const size_t n);