Skip to content

Commit 6180dc9

Browse files
authored
Merge pull request #1222 from AnnikaH/dev
Statman and ICMP
2 parents 89e995d + aab718b commit 6180dc9

56 files changed

Lines changed: 1089 additions & 249 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

api/net/dhcp/dhcpd.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ namespace dhcp {
156156
void clear_offered_ip(IP4::addr ip);
157157
void clear_offered_ips();
158158

159-
void print(const dhcp_packet_t* msg, const dhcp_option_t* opts) {
159+
void print(const dhcp_packet_t* /* msg */, const dhcp_option_t* opts) {
160160
debug("Printing:\n");
161161

162162
debug("OP: %u\n", msg->op);

api/net/ethernet/ethernet.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,17 @@ namespace net {
9090
uint64_t get_packets_dropped()
9191
{ return packets_dropped_; }
9292

93+
uint32_t get_trailer_packets_dropped()
94+
{ return trailer_packets_dropped_; }
95+
9396
private:
9497
const addr& mac_;
9598

9699
/** Stats */
97100
uint64_t& packets_rx_;
98101
uint64_t& packets_tx_;
99102
uint32_t& packets_dropped_;
103+
uint32_t& trailer_packets_dropped_;
100104

101105
/** Upstream OUTPUT connections */
102106
upstream ip4_upstream_ = nullptr;

api/net/ethernet/ethertype.hpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ namespace net {
2525
/** Little-endian ethertypes. More entries here:
2626
http://www.iana.org/assignments/ieee-802-numbers/ieee-802-numbers.xhtml */
2727
enum class Ethertype : uint16_t {
28-
IP4 = 0x8,
29-
ARP = 0x608,
30-
WOL = 0x4208,
31-
IP6 = 0xdd86,
32-
FLOW = 0x888,
33-
JUMBO = 0x7088,
34-
VLAN = 0x81
28+
IP4 = 0x8,
29+
ARP = 0x608,
30+
WOL = 0x4208,
31+
IP6 = 0xdd86,
32+
FLOW = 0x888,
33+
JUMBO = 0x7088,
34+
VLAN = 0x81,
35+
TRAILER_NEGO = 0x0010, // RFC 893 Trailer negotiation
36+
TRAILER_FIRST = 0x0110, // RFC 893, 1122 Trailer encapsulation
37+
TRAILER_LAST = 0x0f10
3538
};
3639

3740
}

api/net/inet.hpp

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,40 +26,45 @@
2626

2727
namespace net {
2828

29-
30-
class TCP;
31-
class UDP;
32-
class DHClient;
29+
class TCP;
30+
class UDP;
31+
class DHClient;
32+
struct ICMPv4;
3333

3434
/**
3535
* An abstract IP-stack interface.
3636
* Provides a common interface for IPv4 and (future) IPv6, simplified with
3737
* no constructors etc.
3838
**/
39-
template <typename IPV >
39+
template <typename IPV>
4040
struct Inet {
4141
using Stack = Inet<IPV>;
4242
using Forward_delg = delegate<void(Stack& source, typename IPV::IP_packet_ptr)>;
4343
using Route_checker = delegate<bool(typename IPV::addr)>;
4444
using IP_packet_factory = delegate<typename IPV::IP_packet_ptr(Protocol)>;
4545

46+
using Error_type = icmp4::Type;
47+
using Error_code = uint8_t;
48+
4649
template <typename IPv>
4750
using resolve_func = delegate<void(typename IPv::addr)>;
4851

49-
5052
///
5153
/// NETWORK CONFIGURATION
5254
///
5355

5456
/** Get IP address of this interface **/
55-
virtual typename IPV::addr ip_addr() = 0;
57+
virtual typename IPV::addr ip_addr() = 0;
5658

5759
/** Get netmask of this interface **/
58-
virtual typename IPV::addr netmask() = 0;
60+
virtual typename IPV::addr netmask() = 0;
5961

6062
/** Get default gateway for this interface **/
6163
virtual typename IPV::addr gateway() = 0;
6264

65+
/** Get default dns for this interface **/
66+
virtual typename IPV::addr dns() = 0;
67+
6368
/** Set default gateway for this interface */
6469
virtual void set_gateway(typename IPV::addr server) = 0;
6570

@@ -94,6 +99,15 @@ namespace net {
9499
/** Get the UDP protocol object for this interface */
95100
virtual UDP& udp() = 0;
96101

102+
/** Get the ICMP protocol object for this interface */
103+
virtual ICMPv4& icmp() = 0;
104+
105+
/**
106+
* Error report in accordance with RFC 1122
107+
* An ICMP error message has been received - forward to transport layer (UDP or TCP)
108+
*/
109+
virtual void error_report(Error_type type, Error_code code, Packet_ptr orig_pckt) = 0;
110+
97111

98112
///
99113
/// DNS

api/net/inet4.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "ip4/arp.hpp"
2323
#include "ip4/ip4.hpp"
2424
#include "ip4/udp.hpp"
25-
#include "ip4/icmpv4.hpp"
25+
#include "ip4/icmp4.hpp"
2626
#include "dns/client.hpp"
2727
#include "tcp/tcp.hpp"
2828
#include <vector>
@@ -53,6 +53,9 @@ namespace net {
5353
IP4::addr gateway() override
5454
{ return gateway_; }
5555

56+
IP4::addr dns() override
57+
{ return dns_server; }
58+
5659
IP4& ip_obj() override
5760
{ return ip4_; }
5861

@@ -71,9 +74,18 @@ namespace net {
7174
/** Get the UDP-object belonging to this stack */
7275
UDP& udp() override { return udp_; }
7376

77+
/** Get the ICMP-object belonging to this stack */
78+
ICMPv4& icmp() override { return icmp_; }
79+
7480
/** Get the DHCP client (if any) */
7581
auto dhclient() { return dhcp_; }
7682

83+
/**
84+
* Error report in accordance with RFC 1122
85+
* An ICMP error message has been received - forward to transport layer (UDP or TCP)
86+
*/
87+
void error_report(Error_type type, Error_code code, Packet_ptr orig_pckt) override;
88+
7789
/**
7890
* Set the forwarding delegate used by this stack.
7991
* If set it will get all incoming packets not intended for this stack.
@@ -125,7 +137,7 @@ namespace net {
125137
void resolve(const std::string& hostname,
126138
resolve_func<IP4> func) override
127139
{
128-
dns.resolve(this->dns_server, hostname, func);
140+
dns_.resolve(this->dns_server, hostname, func);
129141
}
130142

131143
void set_gateway(IP4::addr gateway) override
@@ -253,7 +265,7 @@ namespace net {
253265
TCP tcp_;
254266

255267
// we need this to store the cache per-stack
256-
DNSClient dns;
268+
DNSClient dns_;
257269

258270
std::shared_ptr<net::DHClient> dhcp_{};
259271

api/net/inet64.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#include <vector>
3333

3434
#include <nic.hpp>
35-
#include "ip4/icmpv4.hpp"
35+
#include "ip4/icmp4.hpp"
3636

3737
namespace net {
3838

@@ -96,7 +96,7 @@ namespace net {
9696
static Inet& up()
9797
{
9898
if (_ip4_list.size() < 1)
99-
printf("<Inet> Is bringing up an IP stack without any IP addresses");
99+
printf("<Inet> Is bringing up an IP stack without any IP addresses");
100100
static Inet instance;
101101
return instance;
102102
}

api/net/inet_common.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <net/packet.hpp>
2525
#include <hw/mac_addr.hpp>
2626
#include <net/ethernet/ethertype.hpp>
27+
#include <net/ip4/icmp4_common.hpp>
2728

2829
namespace net {
2930
// Packet must be forward declared to avoid circular dependency
@@ -116,9 +117,9 @@ namespace net {
116117
* http://www.iana.org/assignments/protocol-numbers/protocol-numbers.xhtml
117118
*/
118119
enum class Protocol : uint8_t {
119-
HOPOPT = 0,
120+
HOPOPT = 0,
120121
ICMPv4 = 1,
121-
IP4v4 = 4, // IPv4 encapsulation
122+
IPv4 = 4, // IPv4 encapsulation
122123
TCP = 6,
123124
UDP = 17,
124125
IPv6 = 41, // IPv6 encapsulation

0 commit comments

Comments
 (0)