Skip to content

Commit d1b1341

Browse files
committed
merged inet / ip4 conflict
2 parents 1b43893 + 1e5f8eb commit d1b1341

110 files changed

Lines changed: 2728 additions & 1061 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.

CMakeLists.txt

Lines changed: 2 additions & 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
@@ -138,6 +138,7 @@ if(tests)
138138
ExternalProject_Add(unittests
139139
PREFIX unittests
140140
SOURCE_DIR ${INCLUDEOS_ROOT}/test
141+
BINARY_DIR unittests
141142
CMAKE_ARGS -DINCLUDEOS_ROOT=${INCLUDEOS_ROOT} -DCMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX}
142143
)
143144
#add_subdirectory(test)

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/http/client.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
namespace http {
3030

31+
using Response_handler = Client_connection::Response_handler;
32+
3133
class Client {
3234
public:
3335
using TCP = net::TCP;
@@ -164,6 +166,15 @@ namespace http {
164166
void on_send(Request_handler cb)
165167
{ on_send_ = std::move(cb); }
166168

169+
/**
170+
* @brief Returns the Origin for the Client as a string.
171+
* Currently returns the IP address to the stack.
172+
*
173+
* @return The origin as a string
174+
*/
175+
std::string origin() const
176+
{ return tcp_.stack().ip_addr().to_string(); }
177+
167178
private:
168179
friend class Client_connection;
169180

api/net/http/header_fields.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ extern Field If_None_Match;
4242
extern Field If_Range;
4343
extern Field If_Unmodified_Since;
4444
extern Field Max_Forwards;
45+
extern Field Origin;
4546
extern Field Proxy_Authorization;
4647
extern Field Range;
4748
extern Field Referer;

0 commit comments

Comments
 (0)