1818#ifndef NET_INET_HPP
1919#define NET_INET_HPP
2020
21+ #include < chrono>
22+
2123#include < net/inet_common.hpp>
2224#include < hw/mac_addr.hpp>
2325#include < hw/nic.hpp>
@@ -44,25 +46,106 @@ namespace net {
4446 template <typename IPv>
4547 using resolve_func = delegate<void (typename IPv::addr)>;
4648
49+
50+ // /
51+ // / NETWORK CONFIGURATION
52+ // /
53+
54+ /* * Get IP address of this interface **/
4755 virtual typename IPV::addr ip_addr () = 0;
56+
57+ /* * Get netmask of this interface **/
4858 virtual typename IPV::addr netmask () = 0;
59+
60+ /* * Get default gateway for this interface **/
4961 virtual typename IPV::addr gateway () = 0;
50- virtual std::string ifname () const = 0;
51- virtual MAC::Addr link_addr () = 0;
52- virtual hw::Nic& nic () = 0;
5362
63+ /* * Set default gateway for this interface */
64+ virtual void set_gateway (typename IPV::addr server) = 0;
65+
66+ /* * Set DNS server for this interface */
67+ virtual void set_dns_server (typename IPV::addr server) = 0;
68+
69+ /* * Configure network for this interface */
70+ virtual void network_config (typename IPV::addr ip,
71+ typename IPV::addr nmask,
72+ typename IPV::addr gateway,
73+ typename IPV::addr dnssrv = IPV::ADDR_ANY) = 0;
74+
75+ /* * Reset network configuration for this interface */
76+ virtual void reset_config () = 0;
77+
78+ using dhcp_timeout_func = delegate<void (bool timed_out)>;
79+
80+ /* * Use DHCP to configure this interface */
81+ virtual void negotiate_dhcp (double timeout = 10.0 , dhcp_timeout_func = nullptr ) = 0;
82+
83+
84+ // /
85+ // / PROTOCOL OBJECTS
86+ // /
87+
88+ /* * Get the IP protocol object for this interface */
5489 virtual IPV& ip_obj () = 0;
90+
91+ /* * Get the TCP protocol object for this interface */
5592 virtual TCP& tcp () = 0;
93+
94+ /* * Get the UDP protocol object for this interface */
5695 virtual UDP& udp () = 0;
5796
97+
98+ // /
99+ // / DNS
100+ // /
101+
102+ /* * DNS resolution */
103+ virtual void resolve (const std::string& hostname, resolve_func<IPV> func) = 0;
104+
105+
106+ // /
107+ // / LINK LAYER
108+ // /
109+
110+ /* * Get the network interface device */
111+ virtual hw::Nic& nic () = 0;
112+
113+ /* * Get interface name for this interface **/
114+ virtual std::string ifname () const = 0;
115+
116+ /* * Get linklayer address for this interface **/
117+ virtual MAC::Addr link_addr () = 0;
118+
119+ /* * Add cache entry to the link / IP address cache */
120+ virtual void cache_link_addr (typename IPV::addr, MAC::Addr) = 0;
121+
122+ /* * Flush link / IP address cache */
123+ virtual void flush_link_cache () = 0;
124+
125+ /* * Set the regular interval for link address cache flushing */
126+ virtual void set_link_cache_flush_interval (std::chrono::minutes);
127+
128+
129+ // /
130+ // / ROUTING
131+ // /
132+
133+ /* * Set an IP forwarding delegate. E.g. used to enable routing */
58134 virtual void set_forward_delg (Forward_delg) = 0;
135+
136+ /* * Assign boolean function to determine if we have route to a given IP */
59137 virtual void set_route_checker (Route_checker) = 0;
60- virtual void cache_link_ip ( typename IPV::addr, MAC::Addr) = 0;
61- virtual void flush_link_ip_cache () = 0;
138+
139+ /* * Get the IP forwarding delegate */
62140 virtual Forward_delg forward_delg () = 0;
63141
64- virtual constexpr uint16_t MTU () const = 0;
65142
143+ // /
144+ // / PACKET MANAGEMENT
145+ // /
146+
147+ /* * Get Maximum Transmission Unit **/
148+ virtual constexpr uint16_t MTU () const = 0;
66149
67150 /* * Provision empty anonymous packet **/
68151 virtual Packet_ptr create_packet () = 0;
@@ -73,21 +156,6 @@ namespace net {
73156 /* * Provision empty IP packet **/
74157 virtual typename IPV::IP_packet_ptr create_ip_packet (Protocol) = 0;
75158
76- virtual void resolve (const std::string& hostname, resolve_func<IPV> func) = 0;
77-
78- virtual void set_gateway (typename IPV::addr server) = 0;
79-
80- virtual void set_dns_server (typename IPV::addr server) = 0;
81-
82- virtual void network_config (typename IPV::addr ip,
83- typename IPV::addr nmask,
84- typename IPV::addr gateway,
85- typename IPV::addr dnssrv = IPV::ADDR_ANY) = 0;
86- virtual void reset_config () = 0;
87-
88- using dhcp_timeout_func = delegate<void (bool timed_out)>;
89- virtual void negotiate_dhcp (double timeout = 10.0 , dhcp_timeout_func = nullptr ) = 0;
90-
91159 /* * Event triggered when there are available buffers in the transmit queue */
92160 virtual void on_transmit_queue_available (transmit_avail_delg del) = 0;
93161
@@ -97,8 +165,15 @@ namespace net {
97165 /* * Number of buffers available in the bufstore */
98166 virtual size_t buffers_available () = 0;
99167
168+ /* * Start TCP (e.g. after system suspension). */
100169 virtual void force_start_send_queues () = 0;
101170
171+
172+ // /
173+ // / SMP
174+ // /
175+
176+ /* * Move this interface to the CPU executing the call */
102177 virtual void move_to_this_cpu () = 0;
103178 virtual int get_cpu_id () const noexcept = 0;
104179
0 commit comments