Skip to content

Commit f157f37

Browse files
Merge branch 'dev' of github.com:hioa-cs/IncludeOS into dev
2 parents 7250f62 + 98eb1bc commit f157f37

88 files changed

Lines changed: 1632 additions & 677 deletions

Some content is hidden

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

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ string(STRIP ${OS_VERSION} OS_VERSION)
2626
# create random hex string as stack protector canary
2727
string(RANDOM LENGTH 8 ALPHABET 0123456789ABCDEF STACK_PROTECTOR_VALUE)
2828

29-
set(CAPABS "-msse3 -fstack-protector-strong -D_STACK_GUARD_VALUE_=0x${STACK_PROTECTOR_VALUE} ")
29+
set(CAPABS "-mavx -maes -mfma -fstack-protector-strong -D_STACK_GUARD_VALUE_=0x${STACK_PROTECTOR_VALUE} ")
3030

3131
# Various global defines
3232
# * NO_DEBUG disables output from the debug macro

api/hw/mac_addr.hpp

Lines changed: 142 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// This file is a part of the IncludeOS unikernel - www.includeos.org
22
//
3-
// Copyright 2015-2016 Oslo and Akershus University College of Applied Sciences
3+
// Copyright 2015-2017 Oslo and Akershus University College of Applied Sciences
44
// and Alfred Bratterud
55
//
66
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -14,101 +14,152 @@
1414
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
// See the License for the specific language governing permissions and
1616
// limitations under the License.
17-
#pragma once
1817

18+
#pragma once
1919
#ifndef HW_MAC_ADDR_HPP
2020
#define HW_MAC_ADDR_HPP
2121

22-
#include <stddef.h> // size_t
23-
#include <stdint.h> // uint
24-
#include <cstdio> // snprintf
22+
#include <cstddef>
23+
#include <cstdint>
24+
#include <cstdio>
25+
#include <cstring>
2526
#include <string>
26-
#include <cstring> // strncmp
2727

2828
namespace MAC {
2929

30-
// MAC address
31-
union Addr {
32-
// no. parts in a MAC address
33-
static constexpr size_t PARTS_LEN = 6;
34-
// The parts of the MAC address
35-
uint8_t part[PARTS_LEN];
36-
37-
struct {
38-
uint16_t minor;
39-
uint32_t major;
40-
} __attribute__((packed));
41-
42-
Addr() noexcept : part{} {}
43-
44-
Addr(const uint8_t a, const uint8_t b, const uint8_t c,
45-
const uint8_t d, const uint8_t e, const uint8_t f) noexcept
46-
: part{a,b,c,d,e,f}
47-
{}
48-
49-
Addr& operator=(const Addr cpy) noexcept {
50-
minor = cpy.minor;
51-
major = cpy.major;
52-
return *this;
53-
}
54-
55-
56-
/**
57-
* @brief Hex representation of a MAC address
58-
*
59-
* @return hex string representation
60-
*/
61-
std::string hex_str() const {
62-
char hex_addr[18];
63-
snprintf(hex_addr, sizeof(hex_addr), "%02x:%02x:%02x:%02x:%02x:%02x",
64-
part[0], part[1], part[2],
65-
part[3], part[4], part[5]);
66-
return hex_addr;
67-
}
68-
69-
/**
70-
* @brief String representation of a MAC address
71-
* @note default is hex
72-
* @return string representation of the MAC address
73-
*/
74-
std::string str() const
75-
{ return hex_str(); }
76-
77-
std::string to_string() const
78-
{ return str(); }
79-
80-
operator std::string () const
81-
{ return str(); }
82-
83-
/** Check for equality */
84-
bool operator==(const Addr mac) const noexcept
85-
{
86-
return strncmp(
87-
reinterpret_cast<const char*>(part),
88-
reinterpret_cast<const char*>(mac.part),
89-
PARTS_LEN) == 0;
90-
}
91-
92-
bool operator!=(const Addr mac) const noexcept
93-
{ return not(*this == mac); }
94-
95-
} __attribute__((packed)); //< union addr
96-
97-
const Addr EMPTY {0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
98-
99-
// uint16_t(0xFFFF), uint32_t(0xFFFFFFFF)
100-
const Addr BROADCAST {0xff,0xff,0xff,0xff,0xff,0xff};
101-
102-
// uint16_t(0x0000), uint32_t(0x01000000)
103-
const Addr MULTICAST {0,0,0x01,0,0,0};
104-
105-
// uint16_t(0x3333), uint32_t(0x01000000)
106-
const Addr IPv6mcast_01 {0x33,0x33,0x01,0,0,0};
107-
108-
// uint16_t(0x3333), uint32_t(0x02000000)
109-
const Addr IPv6mcast_02 {0x33,0x33,0x02,0,0,0};
110-
111-
112-
}
113-
114-
#endif
30+
/**
31+
* MAC address representation
32+
*/
33+
union Addr {
34+
/**
35+
* Default constructor
36+
*/
37+
constexpr Addr() noexcept : part{} {}
38+
39+
/**
40+
* Constructor
41+
*
42+
* Create a MAC address by specifying each part of the address
43+
*
44+
* @param a
45+
* The first part of the MAC address
46+
*
47+
* @param b
48+
* The second part of the MAC address
49+
*
50+
* @param c
51+
* The third part of the MAC address
52+
*
53+
* @param d
54+
* The fourth part of the MAC address
55+
*
56+
* @param e
57+
* The fifth part of the MAC address
58+
*
59+
* @param f
60+
* The sixth part of the MAC address
61+
*/
62+
constexpr Addr(const uint8_t a, const uint8_t b, const uint8_t c,
63+
const uint8_t d, const uint8_t e, const uint8_t f) noexcept
64+
: part{a,b,c,d,e,f}
65+
{}
66+
67+
/**
68+
* Assignment operator
69+
*
70+
* @param other
71+
* The MAC address object to assign from
72+
*
73+
* @return The object that invoked this method
74+
*/
75+
constexpr Addr& operator=(const Addr other) noexcept {
76+
minor = other.minor;
77+
major = other.major;
78+
return *this;
79+
}
80+
81+
82+
/**
83+
* Get a hex string representation of a MAC address
84+
*
85+
* @return A hex string representation of a MAC address
86+
*/
87+
std::string hex_str() const {
88+
char hex_addr[18];
89+
90+
snprintf(hex_addr, sizeof(hex_addr), "%02x:%02x:%02x:%02x:%02x:%02x",
91+
part[0], part[1], part[2], part[3], part[4], part[5]);
92+
93+
return hex_addr;
94+
}
95+
96+
/**
97+
* Get a string representation of this type
98+
*
99+
* @return A string representation of this type
100+
*
101+
* @note String representation format is in hex
102+
*/
103+
std::string str() const
104+
{ return hex_str(); }
105+
106+
/**
107+
* Get a string representation of this type
108+
*
109+
* @return A string representation of this type
110+
*
111+
* @note String representation format is in hex
112+
*/
113+
std::string to_string() const
114+
{ return hex_str(); }
115+
116+
/**
117+
* Operator to transform this type into string form
118+
*
119+
* @note String representation format is in hex
120+
*/
121+
operator std::string () const
122+
{ return hex_str(); }
123+
124+
/**
125+
* Operator to check for equality
126+
*
127+
* @param other
128+
* The MAC address object to check for equality
129+
*
130+
* @return true if this object is equal to other, false otherwise
131+
*/
132+
constexpr bool operator==(const Addr other) const noexcept {
133+
return (minor == other.minor)
134+
and (major == other.major);
135+
}
136+
137+
/**
138+
* Operator to check for inequality
139+
*
140+
* @param other
141+
* The MAC address object to check for inequality
142+
*
143+
* @return true if this object is not equal to other, false otherwise
144+
*/
145+
constexpr bool operator!=(const Addr other) const noexcept
146+
{ return not (*this == other); }
147+
148+
149+
static constexpr const size_t PARTS_LEN {6}; //< Number of parts in a MAC address
150+
uint8_t part[PARTS_LEN]; //< The parts of the MAC address
151+
152+
struct {
153+
uint16_t minor;
154+
uint32_t major;
155+
} __attribute__((packed));
156+
} __attribute__((packed)); //< union Addr
157+
158+
constexpr const Addr EMPTY {};
159+
constexpr const Addr BROADCAST {0xff,0xff,0xff,0xff,0xff,0xff}; //< uint16_t(0xFFFF), uint32_t(0xFFFFFFFF)
160+
constexpr const Addr MULTICAST {0x00,0x00,0x01,0x00,0x00,0x00}; //< uint16_t(0x0000), uint32_t(0x01000000)
161+
constexpr const Addr IPv6mcast_01 {0x33,0x33,0x01,0x00,0x00,0x00}; //< uint16_t(0x3333), uint32_t(0x01000000)
162+
constexpr const Addr IPv6mcast_02 {0x33,0x33,0x02,0x00,0x00,0x00}; //< uint16_t(0x3333), uint32_t(0x02000000)
163+
} //< namespace MAC
164+
165+
#endif //< HW_MAC_ADDR_HPP

api/kernel/os.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ class OS {
137137
static constexpr uint32_t page_size() noexcept {
138138
return 4096;
139139
}
140-
static constexpr uint32_t page_nr_from_addr(uint32_t x) noexcept {
141-
return x >> PAGE_SHIFT;
140+
static constexpr uint32_t addr_to_page(uintptr_t addr) noexcept {
141+
return addr >> PAGE_SHIFT;
142142
}
143-
static constexpr uint32_t base_from_page_nr(uint32_t x) noexcept {
144-
return x << PAGE_SHIFT;
143+
static constexpr uintptr_t page_to_addr(uint32_t page) noexcept {
144+
return page << PAGE_SHIFT;
145145
}
146146

147147
/** Total used dynamic memory, in bytes */

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

0 commit comments

Comments
 (0)