Skip to content

Commit 83c7f9b

Browse files
authored
Merge pull request #811 from alfred-bratterud/master
Alfreds Master into dev
2 parents 033148b + d8efb17 commit 83c7f9b

48 files changed

Lines changed: 551 additions & 224 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/inet4.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,16 @@ namespace net {
157157
}
158158

159159
/** Return the stack on the given Nic */
160-
template <int N>
161-
static auto& stack()
160+
template <int N = 0>
161+
static auto&& stack()
162162
{
163163
static Inet4 inet{hw::Devices::nic(N)};
164164
return inet;
165165
}
166166

167167
/** Static IP config */
168-
template <int N>
169-
static auto& ifconfig(
168+
template <int N = 0>
169+
static auto&& ifconfig(
170170
IP4::addr addr,
171171
IP4::addr nmask,
172172
IP4::addr router,
@@ -177,7 +177,7 @@ namespace net {
177177
}
178178

179179
/** DHCP config */
180-
template <int N>
180+
template <int N = 0>
181181
static auto& ifconfig(double timeout = 10.0, dhcp_timeout_func on_timeout = nullptr)
182182
{
183183
stack<N>().negotiate_dhcp(timeout, on_timeout);

api/net/ip4/addr.hpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,17 @@
1818
#ifndef NET_IP4_ADDR_HPP
1919
#define NET_IP4_ADDR_HPP
2020

21-
#include <gsl/gsl> // Expects/Ensures
2221
#include <regex>
2322
#include <string>
2423
#include <net/util.hpp> // byte order
2524

2625
namespace net {
2726
namespace ip4 {
2827

28+
class Invalid_address : public std::runtime_error {
29+
using runtime_error::runtime_error;
30+
};
31+
2932
/** IP4 address representation */
3033
struct Addr {
3134

@@ -49,20 +52,20 @@ struct Addr {
4952
Addr(const std::string& ipv4_addr)
5053
: Addr{}
5154
{
52-
Expects(ipv4_addr.size() >= 7 && ipv4_addr.size() <= 15); //< [7, 15] minimum and maximum address length
53-
55+
if (not(ipv4_addr.size() >= 7 && ipv4_addr.size() <= 15)) //< [7, 15] minimum and maximum address length
56+
throw Invalid_address(ipv4_addr + " is not a valid IP");
5457
const static std::regex ipv4_address_pattern
5558
{
56-
"^(25[0–5]|2[0–4]\\d|[01]?\\d\\d?)\\."
57-
"(25[0–5]|2[0–4]\\d|[01]?\\d\\d?)\\."
58-
"(25[0–5]|2[0–4]\\d|[01]?\\d\\d?)\\."
59-
"(25[0–5]|2[0–4]\\d|[01]?\\d\\d?)$"
59+
"^\\s*(25[0–5]|2[0–4]\\d|[01]?\\d\\d?)\\."
60+
"(25[0–5]|2[0–4]\\d|[01]?\\d\\d?)\\."
61+
"(25[0–5]|2[0–4]\\d|[01]?\\d\\d?)\\."
62+
"(25[0–5]|2[0–4]\\d|[01]?\\d\\d?)\\s*$"
6063
};
6164

6265
std::smatch ipv4_parts;
6366

6467
if (not std::regex_match(ipv4_addr, ipv4_parts, ipv4_address_pattern)) {
65-
return;
68+
throw Invalid_address(ipv4_addr + " is not a valid IP");
6669
}
6770

6871
const auto p1 = static_cast<uint8_t>(std::stoi(ipv4_parts[1]));
@@ -106,6 +109,13 @@ struct Addr {
106109
Addr operator & (const Addr rhs) const noexcept
107110
{ return Addr(whole & rhs.whole); }
108111

112+
Addr operator | (const Addr rhs) const noexcept
113+
{ return Addr(whole | rhs.whole); }
114+
115+
Addr operator ~ () const noexcept
116+
{ return Addr(~whole); }
117+
118+
109119
/** x.x.x.x string representation */
110120
std::string str() const {
111121
char ipv4_addr[16];

api/net/tcp/write_buffer.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#define NET_TCP_WRITE_BUFFER_HPP
2121

2222
#include "common.hpp"
23+
#include <common>
2324

2425
namespace net {
2526
namespace tcp {
@@ -47,7 +48,7 @@ struct WriteBuffer {
4748
uint8_t* end() const { return buffer.get() + length(); }
4849

4950
bool advance(size_t length) {
50-
assert(length <= remaining);
51+
Expects(length <= remaining);
5152
offset += length;
5253
remaining -= length;
5354
return length > 0;
@@ -71,4 +72,3 @@ struct WriteBuffer {
7172
} // < namespace tcp
7273

7374
#endif // < NET_TCP_WRITE_BUFFER_HPP
74-

examples/demo_service/service.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ void Service::start(const std::string&)
7070
// DHCP on interface 0
7171
auto& inet = net::Inet4::ifconfig<0>(10.0);
7272
// static IP in case DHCP fails
73-
net::Inet4::ifconfig<0>(
73+
net::Inet4::ifconfig(
7474
{ 10,0,0,42 }, // IP
7575
{ 255,255,255,0 }, // Netmask
7676
{ 10,0,0,1 }, // Gateway
77-
{ 10,0,0,1 }); // DNS
77+
{ 10,0,0,1 }); // DNS
7878

7979
// Print some useful netstats every 30 secs
8080
Timers::periodic(5s, 30s,

src/net/ip4/ip4.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ namespace net {
5050

5151
// Drop if my ip address doesn't match destination ip address or broadcast
5252
if(UNLIKELY(hdr->daddr != local_ip() and
53-
hdr->daddr != INADDR_BCAST)) {
53+
(hdr->daddr | stack_.netmask()) != INADDR_BCAST)) {
5454
packets_dropped_++;
5555
return;
5656
}

src/platforms/unik.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ void unik::Client::register_instance(net::Inet4& inet, const net::UDP::port_t po
3131

3232
INFO("Unik client", "Initializing Unik registration service");
3333
INFO("Unik client","Listening for UDP hearbeat on %s:%i", inet.ip_addr().str().c_str(), port);
34+
INFO("Unik client","IP is attached to interface %s ", inet.link_addr().str().c_str());
3435

3536
// Set up an UDP port for receiving UniK heartbeat
3637
auto& sock = inet.udp().bind(port);
38+
CHECK(net::Inet4::stack<0>().udp().is_bound(port), "Unik UDP port is bound as expected");
3739
sock.on_read([&sock, &inet] (auto addr, auto port, const char* data, size_t len) {
3840

3941
static bool registered_with_unik = false;
@@ -56,7 +58,7 @@ void unik::Client::register_instance(net::Inet4& inet, const net::UDP::port_t po
5658
std::string prefix = strdata.substr(0,dotloc);
5759
std::string ip_str = strdata.substr(dotloc + 1);
5860

59-
INFO("Unik client","Prefix: %s , IP: %s \n", prefix.c_str(), ip_str.c_str());
61+
INFO("Unik client","Prefix: %s , IP: '%s' \n", prefix.c_str(), ip_str.c_str());
6062

6163
net::IP4::addr ip{ip_str};
6264
net::tcp::Socket unik_instance_listener { ip , 3000};
@@ -104,7 +106,7 @@ void unik::Client::register_instance(net::Inet4& inet, const net::UDP::port_t po
104106

105107
void unik::Client::register_instance_dhcp() {
106108
// Bring up a network device using DHCP
107-
static auto& inet = net::Inet4::stack<0>();
109+
static auto&& inet = net::Inet4::stack<0>();
108110

109111
net::Inet4::ifconfig<0>(10.0, [](bool timeout) {
110112
if(timeout) {

test/fs/integration/fat16/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ def cleanup():
2424
vm.on_exit(cleanup)
2525

2626
# Boot the VM
27-
vm.make().boot()
27+
vm.make().boot(30)

test/fs/integration/fat32/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ def cleanup():
2424
vm.on_exit(cleanup)
2525

2626
# Boot the VM
27-
vm.make().boot()
27+
vm.make().boot(30)

test/fs/integration/memdisk/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ def cleanup():
4242
vm.on_exit(twosector)
4343

4444
# Make default (nosector) and boot the VM
45-
vm.make().boot()
45+
vm.make().boot(60)

test/fs/integration/virtio_block/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ def failure():
1919
import vmrunner
2020
vmrunner.vms[0].on_success(success)
2121
vmrunner.vms[0].on_panic(failure)
22-
vmrunner.vms[0].make().boot()
22+
vmrunner.vms[0].make().boot(50)

0 commit comments

Comments
 (0)