Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
d388312
Socket.hpp: Moved api/net/tcp/socket.hpp -> api/net/socket.hpp so tha…
AnnikaH Mar 21, 2017
d7fc622
ICMP_error created, inheriting from Error
AnnikaH Mar 21, 2017
713f40c
Statman iterators: last_used gotten a const version, cend returning i…
AnnikaH Mar 21, 2017
76d20d0
Inet, ICMP, TCP: Error_report now taking an ICMP_error, some refactor…
AnnikaH Mar 21, 2017
9f66daf
Merge branch 'dev' of github.com:hioa-cs/IncludeOS into dev
AnnikaH Mar 21, 2017
8d84a95
Merge branch 'dev' of github.com:hioa-cs/IncludeOS into dev
AnnikaH Mar 22, 2017
42a45d6
DNS integration test: Files added
AnnikaH Mar 22, 2017
0ace456
Inet: Refactoring dns and error_report method only giving destination…
AnnikaH Mar 23, 2017
7e6db87
Error and ICMP_error: Adding empty constructor and default ICMP type …
AnnikaH Mar 23, 2017
fdab751
UDP, UDPSocket, TCP, ICMP: UDP sendto_handler taking Error and new er…
AnnikaH Mar 23, 2017
65d3717
Merge branch 'dev' of github.com:hioa-cs/IncludeOS into dev
AnnikaH Mar 23, 2017
e88d96e
Merge branch 'dev' of github.com:AnnikaH/IncludeOS into dev
AnnikaH Mar 23, 2017
5468d1e
TCP merge dev: Socket no longer in namespace tcp (moved to net earlier)
AnnikaH Mar 23, 2017
22a33d1
ICMP4 and integration test: ICMP_packet -> ICMP_view to avoid confusi…
AnnikaH Mar 24, 2017
ebab22d
Error_report in Inet, TCP, UDP: New signature taking Error instead of…
AnnikaH Mar 24, 2017
4f72b35
DNS resolve now with Error (ICMP f.ex.). Refactor ICMP_error construc…
AnnikaH Mar 27, 2017
1aa3839
Merge branch 'dev' of github.com:AndreasAakesson/IncludeOS into dev
AnnikaH Mar 27, 2017
5da9e3e
icmp4::Packet: New calculation of payload index (start of payload of …
AnnikaH Mar 27, 2017
8dcc39a
icmp4::Packet: Added comment explaining payload_index()
AnnikaH Mar 27, 2017
75f2a52
Inet: DNS resolution with specified server IP possible
AnnikaH Mar 27, 2017
a1f800d
ICMP4: Configurable seconds to wait for ping reply. Added methods for…
AnnikaH Mar 27, 2017
ddb34e7
DNS integration test complete
AnnikaH Mar 27, 2017
3458b8a
ICMP integration test: Setting seconds to wait for ping reply and add…
AnnikaH Mar 27, 2017
2dde19e
ICMP ping with DNS resolution completed (using make_packed)
AnnikaH Mar 28, 2017
e0229c5
Merge branch 'dev' of github.com:hioa-cs/IncludeOS into dev
AnnikaH Mar 29, 2017
1b54c66
Merge branch 'dev' of github.com:hioa-cs/IncludeOS into dev
AnnikaH Mar 29, 2017
b51a543
Merge branch 'dev' of github.com:hioa-cs/IncludeOS into dev
AnnikaH Mar 29, 2017
87b8228
Inet: Added getter for broadcast address
AnnikaH Mar 30, 2017
98316e4
IP4: Path MTU cache container added
AnnikaH Mar 30, 2017
4e79ce1
Merge branch 'dev' of github.com:hioa-cs/IncludeOS into dev
AnnikaH Mar 30, 2017
bfa0923
Error and ICMP_error: Error passed as reference in delegates (prevent…
AnnikaH Mar 30, 2017
51785fc
Merge branch 'dev' of github.com:hioa-cs/IncludeOS into dev
AnnikaH Mar 30, 2017
8248772
IP4 Addr: Added is_multicast method and removed is_illegal_src (an ad…
AnnikaH Mar 30, 2017
4054f9c
Merge branch 'dev' of github.com:hioa-cs/IncludeOS into dev
AnnikaH Mar 30, 2017
a59a8a4
Addr: Note previously removed added back in
AnnikaH Mar 30, 2017
a9685ba
TCP example and integration test: Running with previous changes made …
AnnikaH Mar 30, 2017
44bfa57
UDPSocket: sendto and bcast taking both a send callback and an error …
AnnikaH Mar 31, 2017
ad320fa
Merge branch 'dev' of github.com:hioa-cs/IncludeOS into dev
AnnikaH Mar 31, 2017
d03392b
Merge branch 'dev' of github.com:hioa-cs/IncludeOS into dev
AnnikaH Apr 2, 2017
08c7b66
dns_test: Added setup.sh which sets up env for dns test
mnordsletten Apr 4, 2017
b38451d
Merge pull request #1 from mnordsletten/annika_dev
AnnikaH Apr 4, 2017
7287073
DNS integration test: Gateway 10.0.0.1 works as DNS server on Jenkins…
AnnikaH Apr 5, 2017
3ba47f8
Socket unit test: File renamed after namespace-move
AnnikaH Apr 5, 2017
268e534
Merge RicoAntonioFelix:socket
AnnikaH Apr 6, 2017
0620f43
Socket.hpp: Added previous changes after merge with RicoAntonioFelix
AnnikaH Apr 6, 2017
2bfe5d1
Merge branch 'dev' of github.com:hioa-cs/IncludeOS into dev
AnnikaH Apr 6, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion api/net/dns/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ namespace net
}

void finish()
{ callback(request.getFirstIP4()); }
{
Error err;
callback(request.getFirstIP4(), err);
}

void start_timeout(Timer::duration_t timeout)
{ timer.start(timeout); }
Expand Down
4 changes: 2 additions & 2 deletions api/net/http/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace http {
class Client {
public:
using TCP = net::TCP;
using Host = net::tcp::Socket;
using Host = net::Socket;

using Response_handler = Client_connection::Response_handler;
struct Options;
Expand Down Expand Up @@ -67,7 +67,7 @@ namespace http {
};

private:
using ResolveCallback = delegate<void(net::ip4::Addr)>;
using ResolveCallback = delegate<void(net::ip4::Addr, net::Error&)>;

public:
explicit Client(TCP& tcp, Request_handler on_send = nullptr);
Expand Down
2 changes: 1 addition & 1 deletion api/net/http/connection.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace http {
public:
using Stream = net::tcp::Connection::Stream;
using Stream_ptr = std::unique_ptr<Stream>;
using Peer = net::tcp::Socket;
using Peer = net::Socket;
using buffer_t = net::tcp::buffer_t;

public:
Expand Down
2 changes: 1 addition & 1 deletion api/net/http/websocket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class WebSocket {
// When a handshake is established and the WebSocket is created
using Connect_handler = delegate<void(WebSocket_ptr)>;
// Whether to accept the client or not before handshake
using Accept_handler = delegate<bool(net::tcp::Socket, std::string)>;
using Accept_handler = delegate<bool(net::Socket, std::string)>;
// data read (data, length)
typedef delegate<void(const char*, size_t)> read_func;
// closed (status code)
Expand Down
2 changes: 1 addition & 1 deletion api/net/http/ws_connector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class WS_connector {
*/
class WS_server_connector : public WS_connector {
public:
using AcceptCallback = delegate<bool(net::tcp::Socket peer, const std::string& origin)>;
using AcceptCallback = delegate<bool(net::Socket peer, const std::string& origin)>;
using Request_handler = delegate<void(Request_ptr, Response_writer_ptr)>;

/**
Expand Down
28 changes: 15 additions & 13 deletions api/net/inet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace net {
class TCP;
class UDP;
class DHClient;
struct ICMPv4;
class ICMPv4;

/**
* An abstract IP-stack interface.
Expand All @@ -44,28 +44,28 @@ namespace net {
using Route_checker = delegate<bool(typename IPV::addr)>;
using IP_packet_factory = delegate<typename IPV::IP_packet_ptr(Protocol)>;

using Error_type = icmp4::Type;
using Error_code = uint8_t;

template <typename IPv>
using resolve_func = delegate<void(typename IPv::addr)>;
using resolve_func = delegate<void(typename IPv::addr, Error&)>;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Are there use cases where Error is modified inside the callback? If not, maybe pass it as const reference?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No seems like Error& can be const here =)

using Vip_list = std::unordered_set<typename IPV::addr>;

///
/// NETWORK CONFIGURATION
///

/** Get IP address of this interface **/
virtual typename IPV::addr ip_addr() = 0;
virtual typename IPV::addr ip_addr() = 0;

/** Get netmask of this interface **/
virtual typename IPV::addr netmask() = 0;
virtual typename IPV::addr netmask() = 0;

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

/** Get default dns for this interface **/
virtual typename IPV::addr dns() = 0;
virtual typename IPV::addr dns_addr() = 0;

/** Get broadcast address for this interface **/
virtual typename IPV::addr broadcast_addr() = 0;

/** Set default gateway for this interface */
virtual void set_gateway(typename IPV::addr server) = 0;
Expand Down Expand Up @@ -120,13 +120,15 @@ namespace net {
virtual UDP& udp() = 0;

/** Get the ICMP protocol object for this interface */
virtual ICMPv4& icmp() = 0;
virtual ICMPv4& icmp() = 0;

/**
* Error report in accordance with RFC 1122
* Error reporting
* Incl. ICMP error report in accordance with RFC 1122
* An ICMP error message has been received - forward to transport layer (UDP or TCP)
*/
virtual void error_report(Error_type type, Error_code code, Packet_ptr orig_pckt) = 0;
virtual void error_report(Error& err, Packet_ptr orig_pckt) = 0;



///
Expand All @@ -135,7 +137,7 @@ namespace net {

/** DNS resolution */
virtual void resolve(const std::string& hostname, resolve_func<IPV> func) = 0;

virtual void resolve(const std::string& hostname, typename IPV::addr server, resolve_func<IPV> func) = 0;

///
/// LINK LAYER
Expand Down
29 changes: 20 additions & 9 deletions api/net/inet4.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ namespace net {
IP4::addr gateway() override
{ return gateway_; }

IP4::addr dns() override
{ return dns_server; }
IP4::addr dns_addr() override
{ return dns_server_; }

IP4::addr broadcast_addr() override
{ return ip4_addr_ | ( ~ netmask_); }

IP4& ip_obj() override
{ return ip4_; }
Expand All @@ -86,10 +89,11 @@ namespace net {
auto dhclient() { return dhcp_; }

/**
* Error report in accordance with RFC 1122
* Error reporting
* Incl. ICMP error report in accordance with RFC 1122
* An ICMP error message has been received - forward to transport layer (UDP or TCP)
*/
void error_report(Error_type type, Error_code code, Packet_ptr orig_pckt) override;
void error_report(Error& err, Packet_ptr orig_pckt) override;

/**
* Set the forwarding delegate used by this stack.
Expand Down Expand Up @@ -141,7 +145,14 @@ namespace net {
void resolve(const std::string& hostname,
resolve_func<IP4> func) override
{
dns_.resolve(this->dns_server, hostname, func);
dns_.resolve(this->dns_server_, hostname, func);
}

void resolve(const std::string& hostname,
IP4::addr server,
resolve_func<IP4> func) override
{
dns_.resolve(server, hostname, func);
}

void set_gateway(IP4::addr gateway) override
Expand All @@ -151,7 +162,7 @@ namespace net {

void set_dns_server(IP4::addr server) override
{
this->dns_server = server;
this->dns_server_ = server;
}

/**
Expand Down Expand Up @@ -181,12 +192,12 @@ namespace net {
this->ip4_addr_ = addr;
this->netmask_ = nmask;
this->gateway_ = gateway;
this->dns_server = (dns == IP4::ADDR_ANY) ? gateway : dns;
this->dns_server_ = (dns == IP4::ADDR_ANY) ? gateway : dns;
INFO("Inet4", "Network configured");
INFO2("IP: \t\t%s", ip4_addr_.str().c_str());
INFO2("Netmask: \t%s", netmask_.str().c_str());
INFO2("Gateway: \t%s", gateway_.str().c_str());
INFO2("DNS Server: \t%s", dns_server.str().c_str());
INFO2("DNS Server: \t%s", dns_server_.str().c_str());
}

virtual void
Expand Down Expand Up @@ -298,7 +309,7 @@ namespace net {
IP4::addr ip4_addr_;
IP4::addr netmask_;
IP4::addr gateway_;
IP4::addr dns_server;
IP4::addr dns_server_;

Vip4_list vip4s_ = {{127,0,0,1}};

Expand Down
83 changes: 68 additions & 15 deletions api/net/inet_common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,45 +59,98 @@ namespace net {
return std::static_pointer_cast<T>(packet);
}


template<typename Derived, typename Base>
auto static_unique_ptr_cast( std::unique_ptr<Base>&& p )
{
auto* d = static_cast<Derived *>(p.release());
return std::unique_ptr<Derived>(d);
}

/**
* General Error class for the OS
* ICMP_error f.ex. inherits from this class
*/
class Error {
public:

enum class Type : uint8_t {
no_error,
general_IO,
ifdown,
ICMP
// Add more as needed
};

virtual Type type()
{ return t_; }

virtual const char* what()
{ return msg_; }

virtual ~Error() = default;
};

Error() = default;

Error(Type t, const char* msg)
: t_{t}, msg_{msg}
{};
{}

operator bool()
virtual ~Error() = default;

Type type()
{ return t_; }

operator bool() const noexcept
{ return t_ != Type::no_error; }

bool is_icmp() const noexcept
{ return t_ == Type::ICMP; }

virtual const char* what() const noexcept
{ return msg_; }

private:
Type t_ = Type::no_error;
const char* msg_ = "No error";
};
Type t_{Type::no_error};
const char* msg_{"No error"};

}; // < class Error


/**
* An object of this error class is sent to UDP and TCP (via Inet) when an ICMP error message
* is received in ICMPv4::receive
*/
class ICMP_error : public Error {

public:
using ICMP_type = icmp4::Type;
using ICMP_code = uint8_t; // Codes in icmp4_common.hpp in namespace icmp4::code
// icmp4::code::Dest_unreachable::PORT f.ex.

ICMP_error()
: Error{}
{}

ICMP_error(ICMP_type icmp_type, ICMP_code icmp_code)
: Error{Error::Type::ICMP, "ICMP error message received"},
icmp_type_{icmp_type}, icmp_code_{icmp_code}
{}

ICMP_type icmp_type() const noexcept
{ return icmp_type_; }

std::string icmp_type_str() const
{ return icmp4::get_type_string(icmp_type_); }

void set_icmp_type(ICMP_type icmp_type)
{ icmp_type_ = icmp_type; }

ICMP_code icmp_code() const noexcept
{ return icmp_code_; }

std::string icmp_code_str() const
{ return icmp4::get_code_string(icmp_type_, icmp_code_); }

void set_icmp_code(ICMP_code icmp_code)
{ icmp_code_ = icmp_code; }

private:
ICMP_type icmp_type_{ICMP_type::NO_ERROR};
ICMP_code icmp_code_{0};

}; // < class ICMP_error


/* RFC 6335 - IANA */
Expand Down
12 changes: 4 additions & 8 deletions api/net/ip4/addr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,11 @@ struct Addr {
{ return part(3) == 127; }

/**
* Determine if an address is a-priori illegal as source address in *all* cases.
*
* @note: The class E range 240/4 for "future use" is not illegal here
* @note: RFC-1122 prohibits 0.0.0.0 as source, but with exceptions
* @note: The class E range 240/4 for "future use" is not included here
* RFC-5771 defining multicast address range from 224.0.0.0 to 239.255.255.255
*/
bool is_illegal_src() const noexcept {
return (part(3) >= 224 and part(3) < 240) // Multicast
or (part(0) == 255); // Limited and directed broadcast
}
bool is_multicast() const noexcept
{ return part(3) >= 224 and part(3) < 240; }

/* Data member */
uint32_t whole;
Expand Down
Loading