From 6fd54932c7dcf5cdbf52bb6432ad08c1458d9b0d Mon Sep 17 00:00:00 2001 From: Annika Hammervoll Date: Mon, 20 Feb 2017 16:14:57 +0100 Subject: [PATCH 01/41] DHCP: Moved shared consts (between client and server) to dhcp4.hpp and client xid now based on micros_since_boot --- api/net/dhcp/dhcp4.hpp | 160 ++++++++++++++++++++++++++++++++----- src/net/dhcp/dh4client.cpp | 128 +---------------------------- 2 files changed, 144 insertions(+), 144 deletions(-) diff --git a/api/net/dhcp/dhcp4.hpp b/api/net/dhcp/dhcp4.hpp index d4751d8ee0..6b1b3e631a 100644 --- a/api/net/dhcp/dhcp4.hpp +++ b/api/net/dhcp/dhcp4.hpp @@ -6,34 +6,34 @@ // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at -// +// // http://www.apache.org/licenses/LICENSE-2.0 -// +// // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. -#include - #ifndef NET_DHCP_DHCP4_HPP #define NET_DHCP_DHCP4_HPP -#define DHCP_VEND_LEN 304 -#define BOOTP_MIN_LEN 300 -#define DHCP_MIN_LEN 548 -// some clients silently ignore responses less than 300 bytes -#define DEFAULT_PACKET_SIZE 300 +#include + +namespace net { + + static const int DHCP_VEND_LEN = 304; + static const int BOOTP_MIN_LEN = 300; + static const int DHCP_MIN_LEN = 548; + // some clients silently ignore responses less than 300 bytes + static const int DEFAULT_PACKET_SIZE = 300; -namespace net -{ struct dhcp_packet_t { - static const int CHADDR_LEN = 16; - static const int SNAME_LEN = 64; - static const int FILE_LEN = 128; - + static const uint8_t CHADDR_LEN = 16; + static const uint8_t SNAME_LEN = 64; + static const uint8_t FILE_LEN = 128; + uint8_t op; // message opcode uint8_t htype; // hardware addr type uint8_t hlen; // hardware addr length @@ -51,14 +51,138 @@ namespace net uint8_t magic[4]; // option_format aka magic uint8_t options[DHCP_VEND_LEN]; }; - + struct dhcp_option_t { uint8_t code; uint8_t length; uint8_t val[0]; }; - -} + + // BOOTP (rfc951) message types + static const uint8_t BOOTREQUEST = 1; + static const uint8_t BOOTREPLY = 2; + + // Possible values for flags field + static const uint32_t BOOTP_UNICAST = 0x0000; + static const uint32_t BOOTP_BROADCAST = 0x8000; + + // Possible values for hardware type (htype) field + static const uint8_t HTYPE_ETHER = 1; // Ethernet 10Mbps + static const uint8_t HTYPE_IEEE802 = 6; // IEEE 802.2 Token Ring + static const uint8_t HTYPE_FDDI = 8; // FDDI + + /* Magic cookie validating dhcp options field (and bootp vendor + extensions field). */ + static const std::string DHCP_OPTIONS_COOKIE = "\143\202\123\143"; + + // DHCP Option codes + static const uint8_t DHO_PAD = 0; + static const uint8_t DHO_SUBNET_MASK = 1; + static const uint8_t DHO_TIME_OFFSET = 2; + static const uint8_t DHO_ROUTERS = 3; + static const uint8_t DHO_TIME_SERVERS = 4; + static const uint8_t DHO_NAME_SERVERS = 5; + static const uint8_t DHO_DOMAIN_NAME_SERVERS = 6; + static const uint8_t DHO_LOG_SERVERS = 7; + static const uint8_t DHO_COOKIE_SERVERS = 8; + static const uint8_t DHO_LPR_SERVERS = 9; + static const uint8_t DHO_IMPRESS_SERVERS = 10; + static const uint8_t DHO_RESOURCE_LOCATION_SERVERS = 11; + static const uint8_t DHO_HOST_NAME = 12; + static const uint8_t DHO_BOOT_SIZE = 13; + static const uint8_t DHO_MERIT_DUMP = 14; + static const uint8_t DHO_DOMAIN_NAME = 15; + static const uint8_t DHO_SWAP_SERVER = 16; + static const uint8_t DHO_ROOT_PATH = 17; + static const uint8_t DHO_EXTENSIONS_PATH = 18; + static const uint8_t DHO_IP_FORWARDING = 19; + static const uint8_t DHO_NON_LOCAL_SOURCE_ROUTING = 20; + static const uint8_t DHO_POLICY_FILTER = 21; + static const uint8_t DHO_MAX_DGRAM_REASSEMBLY = 22; + static const uint8_t DHO_DEFAULT_IP_TTL = 23; + static const uint8_t DHO_PATH_MTU_AGING_TIMEOUT = 24; + static const uint8_t DHO_PATH_MTU_PLATEAU_TABLE = 25; + static const uint8_t DHO_INTERFACE_MTU = 26; + static const uint8_t DHO_ALL_SUBNETS_LOCAL = 27; + static const uint8_t DHO_BROADCAST_ADDRESS = 28; + static const uint8_t DHO_PERFORM_MASK_DISCOVERY = 29; + static const uint8_t DHO_MASK_SUPPLIER = 30; + static const uint8_t DHO_ROUTER_DISCOVERY = 31; + static const uint8_t DHO_ROUTER_SOLICITATION_ADDRESS = 32; + static const uint8_t DHO_STATIC_ROUTES = 33; + static const uint8_t DHO_TRAILER_ENCAPSULATION = 34; + static const uint8_t DHO_ARP_CACHE_TIMEOUT = 35; + static const uint8_t DHO_IEEE802_3_ENCAPSULATION = 36; + static const uint8_t DHO_DEFAULT_TCP_TTL = 37; + static const uint8_t DHO_TCP_KEEPALIVE_INTERVAL = 38; + static const uint8_t DHO_TCP_KEEPALIVE_GARBAGE = 39; + static const uint8_t DHO_NIS_DOMAIN = 40; + static const uint8_t DHO_NIS_SERVERS = 41; + static const uint8_t DHO_NTP_SERVERS = 42; + static const uint8_t DHO_VENDOR_ENCAPSULATED_OPTIONS = 43; + static const uint8_t DHO_NETBIOS_NAME_SERVERS = 44; + static const uint8_t DHO_NETBIOS_DD_SERVER = 45; + static const uint8_t DHO_NETBIOS_NODE_TYPE = 46; + static const uint8_t DHO_NETBIOS_SCOPE = 47; + static const uint8_t DHO_FONT_SERVERS = 48; + static const uint8_t DHO_X_DISPLAY_MANAGER = 49; + static const uint8_t DHO_DHCP_REQUESTED_ADDRESS = 50; + static const uint8_t DHO_DHCP_LEASE_TIME = 51; + static const uint8_t DHO_DHCP_OPTION_OVERLOAD = 52; + static const uint8_t DHO_DHCP_MESSAGE_TYPE = 53; + static const uint8_t DHO_DHCP_SERVER_IDENTIFIER = 54; + static const uint8_t DHO_DHCP_PARAMETER_REQUEST_LIST = 55; + static const uint8_t DHO_DHCP_MESSAGE = 56; + static const uint8_t DHO_DHCP_MAX_MESSAGE_SIZE = 57; + static const uint8_t DHO_DHCP_RENEWAL_TIME = 58; + static const uint8_t DHO_DHCP_REBINDING_TIME = 59; + static const uint8_t DHO_VENDOR_CLASS_IDENTIFIER = 60; + static const uint8_t DHO_DHCP_CLIENT_IDENTIFIER = 61; + static const uint8_t DHO_NWIP_DOMAIN_NAME = 62; + static const uint8_t DHO_NWIP_SUBOPTIONS = 63; + static const uint8_t DHO_USER_CLASS = 77; + static const uint8_t DHO_FQDN = 81; + static const uint8_t DHO_DHCP_AGENT_OPTIONS = 82; + static const uint8_t DHO_SUBNET_SELECTION = 118; // RFC3011 + /* The DHO_AUTHENTICATE option is not a standard yet, so I've + allocated an option out of the "local" option space for it on a + temporary basis. Once an option code number is assigned, I will + immediately and shamelessly break this, so don't count on it + continuing to work. */ + static const uint8_t DHO_AUTHENTICATE = 210; + static const uint8_t DHO_END = 255; + + // DHCP message types + static const uint8_t DHCPDISCOVER = 1; + static const uint8_t DHCPOFFER = 2; + static const uint8_t DHCPREQUEST = 3; + static const uint8_t DHCPDECLINE = 4; + static const uint8_t DHCPACK = 5; + static const uint8_t DHCPNAK = 6; + static const uint8_t DHCPRELEASE = 7; + static const uint8_t DHCPINFORM = 8; + + // Relay Agent Information option subtypes + static const uint8_t RAI_CIRCUIT_ID = 1; + static const uint8_t RAI_REMOTE_ID = 2; + static const uint8_t RAI_AGENT_ID = 3; + + // FQDN suboptions + static const uint8_t FQDN_NO_CLIENT_UPDATE = 1; + static const uint8_t FQDN_SERVER_UPDATE = 2; + static const uint8_t FQDN_ENCODED = 3; + static const uint8_t FQDN_RCODE1 = 4; + static const uint8_t FQDN_RCODE2 = 5; + static const uint8_t FQDN_HOSTNAME = 6; + static const uint8_t FQDN_DOMAINNAME = 7; + static const uint8_t FQDN_FQDN = 8; + static const uint8_t FQDN_SUBOPTION_COUNT = 8; + + static const uint8_t ETH_ALEN = 6; // octets in one ethernet header + static const uint8_t DHCP_DEST_PORT = 67; + static const uint8_t DHCP_SOURCE_PORT = 68; + +} // < namespace net #endif diff --git a/src/net/dhcp/dh4client.cpp b/src/net/dhcp/dh4client.cpp index 77162a7531..fccf65649d 100644 --- a/src/net/dhcp/dh4client.cpp +++ b/src/net/dhcp/dh4client.cpp @@ -21,133 +21,9 @@ #include #include -#include // RTC::time_since_boot() +#include // OS::micros_since_boot() #include -// BOOTP (rfc951) message types -#define BOOTREQUEST 1 -#define BOOTREPLY 2 - -// Possible values for flags field -#define BOOTP_UNICAST 0x0000 -#define BOOTP_BROADCAST 0x8000 - -// Possible values for hardware type (htype) field -#define HTYPE_ETHER 1 // Ethernet 10Mbps -#define HTYPE_IEEE802 6 // IEEE 802.2 Token Ring -#define HTYPE_FDDI 8 // FDDI - -/* Magic cookie validating dhcp options field (and bootp vendor - extensions field). */ -#define DHCP_OPTIONS_COOKIE "\143\202\123\143" - -// DHCP Option codes -#define DHO_PAD 0 -#define DHO_SUBNET_MASK 1 -#define DHO_TIME_OFFSET 2 -#define DHO_ROUTERS 3 -#define DHO_TIME_SERVERS 4 -#define DHO_NAME_SERVERS 5 -#define DHO_DOMAIN_NAME_SERVERS 6 -#define DHO_LOG_SERVERS 7 -#define DHO_COOKIE_SERVERS 8 -#define DHO_LPR_SERVERS 9 -#define DHO_IMPRESS_SERVERS 10 -#define DHO_RESOURCE_LOCATION_SERVERS 11 -#define DHO_HOST_NAME 12 -#define DHO_BOOT_SIZE 13 -#define DHO_MERIT_DUMP 14 -#define DHO_DOMAIN_NAME 15 -#define DHO_SWAP_SERVER 16 -#define DHO_ROOT_PATH 17 -#define DHO_EXTENSIONS_PATH 18 -#define DHO_IP_FORWARDING 19 -#define DHO_NON_LOCAL_SOURCE_ROUTING 20 -#define DHO_POLICY_FILTER 21 -#define DHO_MAX_DGRAM_REASSEMBLY 22 -#define DHO_DEFAULT_IP_TTL 23 -#define DHO_PATH_MTU_AGING_TIMEOUT 24 -#define DHO_PATH_MTU_PLATEAU_TABLE 25 -#define DHO_INTERFACE_MTU 26 -#define DHO_ALL_SUBNETS_LOCAL 27 -#define DHO_BROADCAST_ADDRESS 28 -#define DHO_PERFORM_MASK_DISCOVERY 29 -#define DHO_MASK_SUPPLIER 30 -#define DHO_ROUTER_DISCOVERY 31 -#define DHO_ROUTER_SOLICITATION_ADDRESS 32 -#define DHO_STATIC_ROUTES 33 -#define DHO_TRAILER_ENCAPSULATION 34 -#define DHO_ARP_CACHE_TIMEOUT 35 -#define DHO_IEEE802_3_ENCAPSULATION 36 -#define DHO_DEFAULT_TCP_TTL 37 -#define DHO_TCP_KEEPALIVE_INTERVAL 38 -#define DHO_TCP_KEEPALIVE_GARBAGE 39 -#define DHO_NIS_DOMAIN 40 -#define DHO_NIS_SERVERS 41 -#define DHO_NTP_SERVERS 42 -#define DHO_VENDOR_ENCAPSULATED_OPTIONS 43 -#define DHO_NETBIOS_NAME_SERVERS 44 -#define DHO_NETBIOS_DD_SERVER 45 -#define DHO_NETBIOS_NODE_TYPE 46 -#define DHO_NETBIOS_SCOPE 47 -#define DHO_FONT_SERVERS 48 -#define DHO_X_DISPLAY_MANAGER 49 -#define DHO_DHCP_REQUESTED_ADDRESS 50 -#define DHO_DHCP_LEASE_TIME 51 -#define DHO_DHCP_OPTION_OVERLOAD 52 -#define DHO_DHCP_MESSAGE_TYPE 53 -#define DHO_DHCP_SERVER_IDENTIFIER 54 -#define DHO_DHCP_PARAMETER_REQUEST_LIST 55 -#define DHO_DHCP_MESSAGE 56 -#define DHO_DHCP_MAX_MESSAGE_SIZE 57 -#define DHO_DHCP_RENEWAL_TIME 58 -#define DHO_DHCP_REBINDING_TIME 59 -#define DHO_VENDOR_CLASS_IDENTIFIER 60 -#define DHO_DHCP_CLIENT_IDENTIFIER 61 -#define DHO_NWIP_DOMAIN_NAME 62 -#define DHO_NWIP_SUBOPTIONS 63 -#define DHO_USER_CLASS 77 -#define DHO_FQDN 81 -#define DHO_DHCP_AGENT_OPTIONS 82 -#define DHO_SUBNET_SELECTION 118 // RFC3011 -/* The DHO_AUTHENTICATE option is not a standard yet, so I've - allocated an option out of the "local" option space for it on a - temporary basis. Once an option code number is assigned, I will - immediately and shamelessly break this, so don't count on it - continuing to work. */ -#define DHO_AUTHENTICATE 210 -#define DHO_END 255 - -// DHCP message types -#define DHCPDISCOVER 1 -#define DHCPOFFER 2 -#define DHCPREQUEST 3 -#define DHCPDECLINE 4 -#define DHCPACK 5 -#define DHCPNAK 6 -#define DHCPRELEASE 7 -#define DHCPINFORM 8 - -// Relay Agent Information option subtypes -#define RAI_CIRCUIT_ID 1 -#define RAI_REMOTE_ID 2 -#define RAI_AGENT_ID 3 - -// FQDN suboptions -#define FQDN_NO_CLIENT_UPDATE 1 -#define FQDN_SERVER_UPDATE 2 -#define FQDN_ENCODED 3 -#define FQDN_RCODE1 4 -#define FQDN_RCODE2 5 -#define FQDN_HOSTNAME 6 -#define FQDN_DOMAINNAME 7 -#define FQDN_FQDN 8 -#define FQDN_SUBOPTION_COUNT 8 - -#define ETH_ALEN 6 // octets in one ethernet header -#define DHCP_DEST_PORT 67 -#define DHCP_SOURCE_PORT 68 - namespace net { inline dhcp_option_t* conv_option(uint8_t* option) @@ -196,7 +72,7 @@ namespace net }); // create a random session ID - this->xid = RTC::time_since_boot() & 0xFFFFFFFF; + this->xid = OS::micros_since_boot() & 0xFFFFFFFF; if (console_spam) MYINFO("Negotiating IP-address (xid=%u)", xid); From 41505391a1079b93531a240d88f305b4d502d225 Mon Sep 17 00:00:00 2001 From: Annika Hammervoll Date: Mon, 20 Feb 2017 16:20:21 +0100 Subject: [PATCH 02/41] DHCP integration tests: Separated into two folders -> One for client and one for server --- .../dhcp/{ => dhclient}/CMakeLists.txt | 0 .../integration/dhcp/{ => dhclient}/README.md | 0 .../dhcp/{ => dhclient}/service.cpp | 0 .../integration/dhcp/{ => dhclient}/test.py | 0 .../integration/dhcp/{ => dhclient}/vm.json | 0 .../net/integration/dhcp/dhcpd/CMakeLists.txt | 33 +++++++++ test/net/integration/dhcp/dhcpd/README.md | 1 + test/net/integration/dhcp/dhcpd/service.cpp | 69 +++++++++++++++++++ test/net/integration/dhcp/dhcpd/test.py | 43 ++++++++++++ test/net/integration/dhcp/dhcpd/vm.json | 9 +++ 10 files changed, 155 insertions(+) rename test/net/integration/dhcp/{ => dhclient}/CMakeLists.txt (100%) rename test/net/integration/dhcp/{ => dhclient}/README.md (100%) rename test/net/integration/dhcp/{ => dhclient}/service.cpp (100%) rename test/net/integration/dhcp/{ => dhclient}/test.py (100%) rename test/net/integration/dhcp/{ => dhclient}/vm.json (100%) create mode 100644 test/net/integration/dhcp/dhcpd/CMakeLists.txt create mode 100644 test/net/integration/dhcp/dhcpd/README.md create mode 100644 test/net/integration/dhcp/dhcpd/service.cpp create mode 100644 test/net/integration/dhcp/dhcpd/test.py create mode 100644 test/net/integration/dhcp/dhcpd/vm.json diff --git a/test/net/integration/dhcp/CMakeLists.txt b/test/net/integration/dhcp/dhclient/CMakeLists.txt similarity index 100% rename from test/net/integration/dhcp/CMakeLists.txt rename to test/net/integration/dhcp/dhclient/CMakeLists.txt diff --git a/test/net/integration/dhcp/README.md b/test/net/integration/dhcp/dhclient/README.md similarity index 100% rename from test/net/integration/dhcp/README.md rename to test/net/integration/dhcp/dhclient/README.md diff --git a/test/net/integration/dhcp/service.cpp b/test/net/integration/dhcp/dhclient/service.cpp similarity index 100% rename from test/net/integration/dhcp/service.cpp rename to test/net/integration/dhcp/dhclient/service.cpp diff --git a/test/net/integration/dhcp/test.py b/test/net/integration/dhcp/dhclient/test.py similarity index 100% rename from test/net/integration/dhcp/test.py rename to test/net/integration/dhcp/dhclient/test.py diff --git a/test/net/integration/dhcp/vm.json b/test/net/integration/dhcp/dhclient/vm.json similarity index 100% rename from test/net/integration/dhcp/vm.json rename to test/net/integration/dhcp/dhclient/vm.json diff --git a/test/net/integration/dhcp/dhcpd/CMakeLists.txt b/test/net/integration/dhcp/dhcpd/CMakeLists.txt new file mode 100644 index 0000000000..0f96526bd0 --- /dev/null +++ b/test/net/integration/dhcp/dhcpd/CMakeLists.txt @@ -0,0 +1,33 @@ +cmake_minimum_required(VERSION 2.8.9) + +# IncludeOS install location +if (NOT DEFINED ENV{INCLUDEOS_PREFIX}) + set(ENV{INCLUDEOS_PREFIX} /usr/local) +endif() + +set(CMAKE_TOOLCHAIN_FILE $ENV{INCLUDEOS_PREFIX}/includeos/i686-elf-toolchain.cmake) + +project(test_dhcp_server) + +# Human-readable name of your service +set(SERVICE_NAME "IncludeOS DHCP server test") + +# Name of your service binary +set(BINARY "test_dhcp_server") + +# Maximum memory can be hard-coded into the binary +set(MAX_MEM 128) + +# Source files to be linked with OS library parts to form bootable image +set(SOURCES + service.cpp + ) + +# DRIVERS / PLUGINS: + +set(DRIVERS + virtionet + ) + +# include service build script +include($ENV{INCLUDEOS_PREFIX}/includeos/service.cmake) diff --git a/test/net/integration/dhcp/dhcpd/README.md b/test/net/integration/dhcp/dhcpd/README.md new file mode 100644 index 0000000000..7f57648461 --- /dev/null +++ b/test/net/integration/dhcp/dhcpd/README.md @@ -0,0 +1 @@ +# Test DHCP server diff --git a/test/net/integration/dhcp/dhcpd/service.cpp b/test/net/integration/dhcp/dhcpd/service.cpp new file mode 100644 index 0000000000..6e3aa2efc5 --- /dev/null +++ b/test/net/integration/dhcp/dhcpd/service.cpp @@ -0,0 +1,69 @@ +// This file is a part of the IncludeOS unikernel - www.includeos.org +// +// Copyright 2015 Oslo and Akershus University College of Applied Sciences +// and Alfred Bratterud +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include +#include +#include + +#include + +std::unique_ptr server; + +void Service::start(const std::string&) +{ + using namespace net; + using namespace dhcp; + + // Server + + auto& inet = Inet4::ifconfig<0>( + { 10,0,100,1 }, // IP + { 255,255,0,0 }, // Netmask + { 10,0,0,1 }, // Gateway + { 10,0,0,1 }); // DNS + + IP4::addr pool_start{10,0,100,13}; + IP4::addr pool_end{10,0,100,20}; + server = std::make_unique(inet.udp(), pool_start, pool_end); + + // Client 1 + + auto& inet1 = Inet4::ifconfig<1>(10.0, [&] (bool timeout) { + if (timeout) + printf("Interface 1 timed out\n"); + else + printf("Interface 1 succeed\n"); + }); + + // Client 2 + + auto& inet2 = Inet4::ifconfig<2>(10.0, [&] (bool timeout) { + if (timeout) + printf("Interface 2 timed out\n"); + else + printf("Interface 2 succeed\n"); + }); + + // Client 3 + + auto& inet3 = Inet4::ifconfig<3>(10.0, [&] (bool timeout) { + if (timeout) + printf("Interface 3 timed out\n"); + else + printf("Interface 3 succeed\n"); + }); +} diff --git a/test/net/integration/dhcp/dhcpd/test.py b/test/net/integration/dhcp/dhcpd/test.py new file mode 100644 index 0000000000..0f7865e6c5 --- /dev/null +++ b/test/net/integration/dhcp/dhcpd/test.py @@ -0,0 +1,43 @@ +#! /usr/bin/env python + +import sys +import os +import time +import subprocess + +includeos_src = os.environ.get('INCLUDEOS_SRC', + os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(__file__))).split('/test')[0]) +sys.path.insert(0,includeos_src) + +from vmrunner import vmrunner +import socket + +from vmrunner.prettify import color + +# Get an auto-created VM from the vmrunner +vm = vmrunner.vms[0] + +ping_count = 3 + +def DHCP_test(trigger_line): + print color.INFO(""),"Got IP" + ip_string = vm.readline() + print color.INFO(""), "Assigned address: ", ip_string + print color.INFO(""), "Trying to ping" + time.sleep(1) + try: + command = ["ping", ip_string.rstrip(), "-c", str(ping_count), "-i", "0.2"] + print color.DATA(" ".join(command)) + print subprocess.check_output(command) + vm.exit(0," Ping test passed. Process returned 0 exit status") + except Exception as e: + print color.FAIL(" Ping FAILED Process threw exception:") + print e + return False + + +# Add custom event-handler +vm.on_output("Got IP from DHCP", DHCP_test) + +# Boot the VM, taking a timeout as parameter +vm.cmake().boot(20).clean() diff --git a/test/net/integration/dhcp/dhcpd/vm.json b/test/net/integration/dhcp/dhcpd/vm.json new file mode 100644 index 0000000000..2779808849 --- /dev/null +++ b/test/net/integration/dhcp/dhcpd/vm.json @@ -0,0 +1,9 @@ +{ + "image" : "test_dhcp_server.img", + "net" : [{"device" : "virtio", "mac" : "c0:01:0a:00:00:2a"}, + {"device" : "virtio", "mac" : "c0:01:0a:00:00:2f"}, + {"device" : "virtio", "mac" : "c0:01:0a:00:00:20"}, + {"device" : "virtio", "mac" : "c0:01:0a:00:00:23"}], + "cpu" : "host", + "mem" : 128 +} From fb7f187efcf931bc028ca0e2f4033fe4b0902853 Mon Sep 17 00:00:00 2001 From: Annika Hammervoll Date: Mon, 20 Feb 2017 17:54:57 +0100 Subject: [PATCH 03/41] IP4 addr: Added method for getting the different parts of the address --- api/net/ip4/addr.hpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/api/net/ip4/addr.hpp b/api/net/ip4/addr.hpp index d1a858cf34..887ada56d6 100644 --- a/api/net/ip4/addr.hpp +++ b/api/net/ip4/addr.hpp @@ -21,6 +21,7 @@ #include #include #include // byte order +#include namespace net { namespace ip4 { @@ -115,6 +116,16 @@ struct Addr { Addr operator ~ () const noexcept { return Addr(~whole); } + uint8_t part(uint8_t i) const noexcept { + Expects(i < 4); + + union addr { + uint8_t parts[4]; + uint32_t whole; + }; + + return ((addr&) whole).parts[3 - i]; + } /** x.x.x.x string representation */ std::string str() const { From 112e3cc58b2dc6f662abcebf1dfb5371db6c7b74 Mon Sep 17 00:00:00 2001 From: Annika Hammervoll Date: Mon, 20 Feb 2017 17:57:47 +0100 Subject: [PATCH 04/41] DHCP Record: Added class for storing IP allocations (moving dhcp server into IncludeOS) --- api/net/dhcp/record.hpp | 113 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 113 insertions(+) create mode 100644 api/net/dhcp/record.hpp diff --git a/api/net/dhcp/record.hpp b/api/net/dhcp/record.hpp new file mode 100644 index 0000000000..4fc5a45341 --- /dev/null +++ b/api/net/dhcp/record.hpp @@ -0,0 +1,113 @@ +// This file is a part of the IncludeOS unikernel - www.includeos.org +// +// Copyright 2015 Oslo and Akershus University College of Applied Sciences +// and Alfred Bratterud +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#pragma once +#ifndef NET_DHCP_RECORD_HPP +#define NET_DHCP_RECORD_HPP + +namespace net { +namespace dhcp { + + enum class Status { + AVAILABLE, + OFFERED, // IP has been offered to another client and is awaiting a DHCPREQUEST for updated status + RELEASED, // Previously allocated IP to a client (reuse) + IN_USE + }; + + // Temp - Instead of database (persistent storage): + + class Record { + + public: + // TODO Remove or use? + using byte_seq = std::vector; + + Record() {} + + Record(const byte_seq& client_id, const IP4::addr& ip, Status status, int64_t lease_start, uint32_t lease_duration) + : client_id_{client_id}, ip_{ip}, status_{status}, lease_start_{lease_start}, lease_duration_{lease_duration} {} + + // Getters + + const byte_seq& client_id() const + { return client_id_; } + + const IP4::addr& ip() const + { return ip_; } + + const Status& status() const + { return status_; } + + uint32_t lease_start() const + { return lease_start_; } + + uint32_t lease_duration() const + { return lease_duration_; } + + // Setters + + void set_client_id(const byte_seq& client_id) + { client_id_ = client_id; } + + void set_ip(const IP4::addr ip) + { ip_ = ip; } + + void set_status(Status status) + { status_ = status; } + + /*void set_lease_start(uint32_t lease_start) + { lease_start_ = lease_start; }*/ + void set_lease_start(int64_t lease_start) + { lease_start_ = lease_start; } + + void set_lease_duration(uint32_t lease_duration) + { lease_duration_ = lease_duration; } + + private: + byte_seq client_id_; + IP4::addr ip_; + + // Because of reuse (client gets its previous IP) ? + Status status_; + + //std::vector