diff --git a/repos/os/include/net/arp.h b/repos/os/include/net/arp.h index 17310000f..77e0e85aa 100644 --- a/repos/os/include/net/arp.h +++ b/repos/os/include/net/arp.h @@ -57,19 +57,15 @@ class Net::Arp_packet { private: - /*********************** - ** ARP header fields ** - ***********************/ - - Genode::uint16_t _hw_addr_type; - Genode::uint16_t _prot_addr_type; - Genode::uint8_t _hw_addr_sz; - Genode::uint8_t _prot_addr_sz; + Genode::uint16_t _hardware_address_type; + Genode::uint16_t _protocol_address_type; + Genode::uint8_t _hardware_address_size; + Genode::uint8_t _protocol_address_size; Genode::uint16_t _opcode; - Genode::uint8_t _src_mac_addr[Ethernet_frame::ADDR_LEN]; - Genode::uint8_t _src_ip_addr[Ipv4_packet::ADDR_LEN]; - Genode::uint8_t _dst_mac_addr[Ethernet_frame::ADDR_LEN]; - Genode::uint8_t _dst_ip_addr[Ipv4_packet::ADDR_LEN]; + Genode::uint8_t _src_mac[Ethernet_frame::ADDR_LEN]; + Genode::uint8_t _src_ip[Ipv4_packet::ADDR_LEN]; + Genode::uint8_t _dst_mac[Ethernet_frame::ADDR_LEN]; + Genode::uint8_t _dst_ip[Ipv4_packet::ADDR_LEN]; public: @@ -166,127 +162,29 @@ class Net::Arp_packet } - /****************************** - ** ARP field read-accessors ** - ******************************/ + /*************** + ** Accessors ** + ***************/ - /** - * \return link layer type (Arp_packet::Hardware_type). - */ - Genode::uint16_t hardware_address_type() { - return host_to_big_endian(_hw_addr_type); } + Genode::uint16_t hardware_address_type() const { return host_to_big_endian(_hardware_address_type); } + Genode::uint16_t protocol_address_type() const { return host_to_big_endian(_protocol_address_type); } + Genode::uint8_t hardware_address_size() const { return _hardware_address_size; } + Genode::uint8_t protocol_address_size() const { return _protocol_address_size; } + Genode::uint16_t opcode() const { return host_to_big_endian(_opcode); } + Mac_address src_mac() const { return Mac_address((void *)&_src_mac); } + Ipv4_address src_ip() const { return Ipv4_address((void *)&_src_ip); } + Mac_address dst_mac() const { return Mac_address((void *)&_dst_mac); } + Ipv4_address dst_ip() const { return Ipv4_address((void *)&_dst_ip); } - /** - * \return network/internet layer type (Ether_frame::EtherType). - */ - Genode::uint16_t protocol_address_type() { - return host_to_big_endian(_prot_addr_type); } - - /** - * \return size in bytes of hardware address. - */ - Genode::uint8_t hardware_address_size() { return _hw_addr_sz; } - - /** - * \return size in bytes of protocol address. - */ - Genode::uint8_t protocol_address_size() { return _prot_addr_sz; } - - /** - * \return operation code (Arp_packet::Opcode). - */ - Genode::uint16_t opcode() const { return host_to_big_endian(_opcode); } - - /** - * \return source MAC address. - */ - Mac_address src_mac() const { - return Mac_address((void *)&_src_mac_addr); } - - /** - * \return source IP address. - */ - Ipv4_address src_ip() const { - return Ipv4_address((void *)&_src_ip_addr); } - - /** - * \return destination MAC address. - */ - Mac_address dst_mac() const { - return Mac_address((void *)&_dst_mac_addr); } - - /** - * \return destination IP address. - */ - Ipv4_address dst_ip() const { - return Ipv4_address((void *)&_dst_ip_addr); } - - - /****************************** - ** ARP field write-accessors ** - ******************************/ - - /** - * \return link layer type (Arp_packet::Hardware_type). - */ - void hardware_address_type(Genode::uint16_t v) { - _hw_addr_type = host_to_big_endian(v); } - - /** - * \return network/internet layer type (Ether_frame::EtherType). - */ - void protocol_address_type(Genode::uint16_t v) { - _prot_addr_type = host_to_big_endian(v); } - - /** - * \return size in bytes of hardware address. - */ - void hardware_address_size(Genode::uint8_t v) { _hw_addr_sz = v; } - - /** - * \return size in bytes of protocol address. - */ - void protocol_address_size(Genode::uint8_t v) { _prot_addr_sz = v; } - - /** - * Set Operation code. - * - * \param opcode Arp_packet::Opcode to set. - */ - void opcode(Genode::uint16_t opcode) { - _opcode = host_to_big_endian(opcode); } - - /** - * Set source MAC address. - * - * \param src_mac_addr MAC address to set. - */ - void src_mac(Mac_address src_mac_addr) { - src_mac_addr.copy(&_src_mac_addr); } - - /** - * Set source IP address. - * - * \param src_ip_addr IP address to set. - */ - void src_ip(Ipv4_address src_ip_addr) { - src_ip_addr.copy(&_src_ip_addr); } - - /** - * Set destination MAC address. - * - * \param src_mac_addr MAC address to set. - */ - void dst_mac(Mac_address dst_mac_addr) { - dst_mac_addr.copy(&_dst_mac_addr); } - - /** - * Set destination IP address. - * - * \param src_ip_addr IP address to set. - */ - void dst_ip(Ipv4_address dst_ip_addr) { - dst_ip_addr.copy(&_dst_ip_addr); } + void hardware_address_type(Genode::uint16_t v) { _hardware_address_type = host_to_big_endian(v); } + void protocol_address_type(Genode::uint16_t v) { _protocol_address_type = host_to_big_endian(v); } + void hardware_address_size(Genode::uint8_t v) { _hardware_address_size = v; } + void protocol_address_size(Genode::uint8_t v) { _protocol_address_size = v; } + void opcode(Genode::uint16_t v) { _opcode = host_to_big_endian(v); } + void src_mac(Mac_address v) { v.copy(&_src_mac); } + void src_ip(Ipv4_address v) { v.copy(&_src_ip); } + void dst_mac(Mac_address v) { v.copy(&_dst_mac); } + void dst_ip(Ipv4_address v) { v.copy(&_dst_ip); } /*************************** @@ -298,10 +196,10 @@ class Net::Arp_packet * address resolution with respect to IPv4 addresses. */ bool ethernet_ipv4() const { - return ( host_to_big_endian(_hw_addr_type) == ETHERNET - && host_to_big_endian(_prot_addr_type) == (Genode::uint16_t)Ethernet_frame::Type::IPV4 - && _hw_addr_sz == Ethernet_frame::ADDR_LEN - && _prot_addr_sz == Ipv4_packet::ADDR_LEN); + return ( host_to_big_endian(_hardware_address_type) == ETHERNET + && host_to_big_endian(_protocol_address_type) == (Genode::uint16_t)Ethernet_frame::Type::IPV4 + && _hardware_address_size == Ethernet_frame::ADDR_LEN + && _protocol_address_size == Ipv4_packet::ADDR_LEN); } diff --git a/repos/os/include/net/dhcp.h b/repos/os/include/net/dhcp.h index 6df51fd42..c37056109 100644 --- a/repos/os/include/net/dhcp.h +++ b/repos/os/include/net/dhcp.h @@ -67,19 +67,8 @@ class Net::Dhcp_packet class No_dhcp_packet : Genode::Exception {}; - - class Client_hw_address - { - public: - Genode::uint8_t addr[16]; - }; - private: - /************************ - ** DHCP packet fields ** - ************************/ - Genode::uint8_t _op; Genode::uint8_t _htype; Genode::uint8_t _hlen; @@ -91,18 +80,18 @@ class Net::Dhcp_packet Genode::uint8_t _yiaddr[Ipv4_packet::ADDR_LEN]; Genode::uint8_t _siaddr[Ipv4_packet::ADDR_LEN]; Genode::uint8_t _giaddr[Ipv4_packet::ADDR_LEN]; - Client_hw_address _chaddr; + Genode::uint8_t _chaddr[16]; Genode::uint8_t _sname[64]; Genode::uint8_t _file[128]; Genode::uint32_t _magic_cookie; Genode::uint8_t _opts[0]; - enum Flag { - BROADCAST = 0x80 - }; + enum Flag { BROADCAST = 0x80 }; public: + enum class Htype : Genode::uint8_t { ETH = 1 }; + /** * This class represents the data layout of an DHCP option. */ @@ -181,33 +170,47 @@ class Net::Dhcp_packet } - /******************************* - ** DHCP field read-accessors ** - *******************************/ + /*************** + ** Accessors ** + ***************/ - Genode::uint8_t op() const { return _op; } - Genode::uint8_t htype() const { return _htype; } - Genode::uint8_t hlen() const { return _hlen; } - Genode::uint8_t hops() const { return _hops; } - Genode::uint32_t xid() const { return host_to_big_endian(_xid); } - Genode::uint16_t secs() const { return host_to_big_endian(_secs); } + Genode::uint8_t op() const { return _op; } + Htype htype() const { return (Htype)_htype; } + Genode::uint8_t hlen() const { return _hlen; } + Genode::uint8_t hops() const { return _hops; } + Genode::uint32_t xid() const { return host_to_big_endian(_xid); } + Genode::uint16_t secs() const { return host_to_big_endian(_secs); } + bool broadcast() const { return _flags & BROADCAST; } + Ipv4_address ciaddr() const { return Ipv4_address((void *)_ciaddr); } + Ipv4_address yiaddr() const { return Ipv4_address((void *)_yiaddr); } + Ipv4_address siaddr() const { return Ipv4_address((void *)_siaddr); } + Ipv4_address giaddr() const { return Ipv4_address((void *)_giaddr); } + Mac_address client_mac() const { return Mac_address((void *)&_chaddr); } + char const *server_name() const { return (char const *)&_sname; } + char const *file() const { return (char const *)&_file; } + Genode::uint32_t magic_cookie() const { return host_to_big_endian(_magic_cookie); } + Genode::uint16_t flags() const { return host_to_big_endian(_flags); } + void *opts() const { return (void *)_opts; } - bool broadcast() { return _flags & BROADCAST; } + void flags(Genode::uint16_t v) { _flags = host_to_big_endian(v); } + void file(const char* v) { Genode::memcpy(_file, v, sizeof(_file)); } + void op(Genode::uint8_t v) { _op = v; } + void htype(Htype v) { _htype = (Genode::uint8_t)v; } + void hlen(Genode::uint8_t v) { _hlen = v; } + void hops(Genode::uint8_t v) { _hops = v; } + void xid(Genode::uint32_t v) { _xid = host_to_big_endian(v); } + void secs(Genode::uint16_t v) { _secs = host_to_big_endian(v); } + void broadcast(bool v) { _flags = v ? BROADCAST : 0; } + void ciaddr(Ipv4_address v) { v.copy(&_ciaddr); } + void yiaddr(Ipv4_address v) { v.copy(&_yiaddr); } + void siaddr(Ipv4_address v) { v.copy(&_siaddr); } + void giaddr(Ipv4_address v) { v.copy(&_giaddr); } + void client_mac(Mac_address v) { v.copy(&_chaddr); } - Ipv4_address ciaddr() { - return Ipv4_address(&_ciaddr); } - Ipv4_address yiaddr() { - return Ipv4_address(&_yiaddr); } - Ipv4_address siaddr() const { - return Ipv4_address((void *)&_siaddr); } - Ipv4_address giaddr() { - return Ipv4_address(&_giaddr); } - Mac_address client_mac() const { - return Mac_address((void *)&_chaddr); } - - const char* server_name() { return (const char*) &_sname; } - const char* file() { return (const char*) &_file; } + /********************** + ** Option utilities ** + **********************/ Option *option(Option_type op) { @@ -224,33 +227,6 @@ class Net::Dhcp_packet } - /******************************* - ** DHCP field write-accessors ** - *******************************/ - - void op(Genode::uint8_t op) { _op = op; } - void htype(Genode::uint8_t htype) { _htype = htype; } - void hlen(Genode::uint8_t hlen) { _hlen = hlen; } - void hops(Genode::uint8_t hops) { _hops = hops; } - void xid(Genode::uint32_t xid) { _xid = host_to_big_endian(_xid); } - void secs(Genode::uint16_t secs) { _secs = host_to_big_endian(_secs); } - - void broadcast(bool broadcast) { - _flags = broadcast ? BROADCAST : 0; } - - void ciaddr(Ipv4_address ciaddr) { - ciaddr.copy(&_ciaddr); } - void yiaddr(Ipv4_address yiaddr) { - yiaddr.copy(&_yiaddr); } - void siaddr(Ipv4_address siaddr) { - siaddr.copy(&_siaddr); } - void giaddr(Ipv4_address giaddr) { - giaddr.copy(&_giaddr); } - - void client_mac(Mac_address mac) { - mac.copy(&_chaddr); } - - /************************* ** Convenience methods ** *************************/ diff --git a/repos/os/include/net/ethernet.h b/repos/os/include/net/ethernet.h index f94984dc5..fa52272d2 100644 --- a/repos/os/include/net/ethernet.h +++ b/repos/os/include/net/ethernet.h @@ -54,10 +54,10 @@ class Net::Ethernet_frame private: - Genode::uint8_t _dst_mac[ADDR_LEN]; /* destination mac address */ - Genode::uint8_t _src_mac[ADDR_LEN]; /* source mac address */ - Genode::uint16_t _type; /* encapsulated protocol */ - unsigned _data[0]; /* encapsulated data */ + Genode::uint8_t _dst[ADDR_LEN]; /* destination mac address */ + Genode::uint8_t _src[ADDR_LEN]; /* source mac address */ + Genode::uint16_t _type; /* encapsulated protocol */ + unsigned _data[0]; /* encapsulated data */ public: @@ -85,56 +85,19 @@ class Net::Ethernet_frame } - /*********************************** - ** Ethernet field read-accessors ** - ***********************************/ + /*************** + ** Accessors ** + ***************/ - /** - * \return destination MAC address of frame. - */ - Mac_address dst() const { return Mac_address((void *)&_dst_mac); } + Mac_address dst() const { return Mac_address((void *)_dst); } + Mac_address src() const { return Mac_address((void *)_src); } + Type type() const { return (Type)host_to_big_endian(_type); } + template T const *data() const { return (T const *)(_data); } + template T *data() { return (T *)(_data); } - /** - * \return source MAC address of frame. - */ - Mac_address src() const { return Mac_address((void *)&_src_mac); } - - /** - * \return EtherType - type of encapsulated protocol. - */ - Type type() const { return (Type)host_to_big_endian(_type); } - - /** - * \return payload data. - */ - template T * data() { return (T *)(_data); } - template T const * data() const { return (T const *)(_data); } - - - /*********************************** - ** Ethernet field write-accessors ** - ***********************************/ - - /** - * Set the destination MAC address of this frame. - * - * \param mac MAC address to be set. - */ - void dst(Mac_address mac) { mac.copy(&_dst_mac); } - - /** - * Set the source MAC address of this frame. - * - * \param mac MAC address to be set. - */ - void src(Mac_address mac) { mac.copy(&_src_mac); } - - /** - * Set type of encapsulated protocol. - * - * \param type the EtherType to be set. - */ - void type(Type type) { _type = host_to_big_endian((Genode::uint16_t)type); } + void dst(Mac_address v) { v.copy(&_dst); } + void src(Mac_address v) { v.copy(&_src); } + void type(Type type) { _type = host_to_big_endian((Genode::uint16_t)type); } /*************** diff --git a/repos/os/include/net/ipv4.h b/repos/os/include/net/ipv4.h index 4f3b74b52..2997cd746 100644 --- a/repos/os/include/net/ipv4.h +++ b/repos/os/include/net/ipv4.h @@ -91,16 +91,17 @@ class Net::Ipv4_packet unsigned _header_length : 4; unsigned _version : 4; - Genode::uint8_t _diff_service; + unsigned _diff_service : 6; + unsigned _ecn : 2; Genode::uint16_t _total_length; Genode::uint16_t _identification; unsigned _flags : 3; unsigned _fragment_offset : 13; Genode::uint8_t _time_to_live; Genode::uint8_t _protocol; - Genode::uint16_t _header_checksum; - Genode::uint8_t _src_addr[ADDR_LEN]; - Genode::uint8_t _dst_addr[ADDR_LEN]; + Genode::uint16_t _checksum; + Genode::uint8_t _src[ADDR_LEN]; + Genode::uint8_t _dst[ADDR_LEN]; unsigned _data[0]; /** @@ -116,6 +117,12 @@ class Net::Ipv4_packet public: + enum class Protocol : Genode::uint8_t + { + TCP = 6, + UDP = 17, + }; + enum Precedence { NETWORK_CONTROL = 7, INTERNETWORK_CONTROL = 6, @@ -150,54 +157,40 @@ class Net::Ipv4_packet } - /******************************* - ** IPv4 field read-accessors ** - *******************************/ + /*************** + ** Accessors ** + ***************/ - Genode::uint8_t version() { return _version; } + Genode::size_t header_length() const { return _header_length; } + Genode::uint8_t version() const { return _version; } + Genode::uint8_t diff_service() const { return _diff_service; } + Genode::uint8_t ecn() const { return _ecn; } + Genode::size_t total_length() const { return host_to_big_endian(_total_length); } + Genode::uint16_t identification() const { return host_to_big_endian(_identification); } + Genode::uint8_t flags() const { return _flags; } + Genode::size_t fragment_offset() const { return _fragment_offset; } + Genode::uint8_t time_to_live() const { return _time_to_live; } + Protocol protocol() const { return (Protocol)_protocol; } + Genode::uint16_t checksum() const { return host_to_big_endian(_checksum); } + Ipv4_address src() const { return Ipv4_address((void *)&_src); } + Ipv4_address dst() const { return Ipv4_address((void *)&_dst); } + template T const * data() const { return (T const *)(_data); } + template T * data() { return (T *)(_data); } - /* returns the number of 32-bit words the header occupies */ - Genode::uint8_t header_length() { return _header_length; } - Genode::uint8_t precedence() { return _diff_service & PRECEDENCE; } + void header_length(Genode::size_t v) { _header_length = v; } + void version(Genode::uint8_t v) { _version = v; } + void diff_service(Genode::uint8_t v) { _diff_service = v; ; } + void ecn(Genode::uint8_t v) { _ecn = v; ; } + void total_length(Genode::size_t v) { _total_length = host_to_big_endian((Genode::uint16_t)v); } + void identification(Genode::uint16_t v) { _identification = host_to_big_endian(v); } + void flags(Genode::uint8_t v) { _flags = v; ; } + void fragment_offset(Genode::size_t v) { _fragment_offset = v; ; } + void time_to_live(Genode::uint8_t v) { _time_to_live = v; } + void protocol(Protocol v) { _protocol = (Genode::uint8_t)v; } + void checksum(Genode::uint16_t checksum) { _checksum = host_to_big_endian(checksum); } + void src(Ipv4_address v) { v.copy(&_src); } + void dst(Ipv4_address v) { v.copy(&_dst); } - bool low_delay() { return _diff_service & DELAY; } - bool high_throughput() { return _diff_service & THROUGHPUT; } - bool high_reliability() { return _diff_service & RELIABILITY;} - bool minimize_monetary_cost() { return _diff_service & COST; } - - Genode::uint16_t total_length() { return host_to_big_endian(_total_length); } - Genode::uint16_t identification() { return host_to_big_endian(_identification); } - - bool no_fragmentation() { return _flags & NO_FRAGMENT; } - bool more_fragments() { return _flags & MORE_FRAGMENTS; } - - Genode::size_t fragment_offset() { return _fragment_offset; } - Genode::uint8_t time_to_live() { return _time_to_live; } - Genode::uint8_t protocol() const { return _protocol; } - - Genode::uint16_t checksum() { return host_to_big_endian(_header_checksum); } - - Ipv4_address dst() const { return Ipv4_address((void *)&_dst_addr); } - Ipv4_address src() const { return Ipv4_address((void *)&_src_addr); } - - template T const * header() const { return (T const *)(this); } - template T * data() { return (T *)(_data); } - template T const * data() const { return (T const *)(_data); } - - /******************************** - ** IPv4 field write-accessors ** - ********************************/ - - void version(Genode::size_t version) { _version = version; } - void header_length(Genode::size_t len) { _header_length = len; } - - void total_length(Genode::uint16_t len) { _total_length = host_to_big_endian(len); } - void time_to_live(Genode::uint8_t ttl) { _time_to_live = ttl; } - - void checksum(Genode::uint16_t checksum) { _header_checksum = host_to_big_endian(checksum); } - - void dst(Ipv4_address ip) { ip.copy(&_dst_addr); } - void src(Ipv4_address ip) { ip.copy(&_src_addr); } /*************** ** Operators ** diff --git a/repos/os/include/net/tcp.h b/repos/os/include/net/tcp.h index 4ba6604ae..6c697d81c 100644 --- a/repos/os/include/net/tcp.h +++ b/repos/os/include/net/tcp.h @@ -46,14 +46,16 @@ class Net::Tcp_packet uint16_t _dst_port; uint32_t _seq_nr; uint32_t _ack_nr; - uint8_t _data_offset; - uint8_t _flags; + unsigned _data_offset : 4; + unsigned _reserved : 3; + unsigned _flags_msb : 1; + uint8_t _flags_lsb; uint16_t _window_size; uint16_t _checksum; uint16_t _urgent_ptr; uint32_t _data[0]; - struct Flags : Genode::Register<8> + struct Flags : Genode::Register<16> { struct Fin : Bitfield<0, 1> { }; struct Syn : Bitfield<1, 1> { }; @@ -61,30 +63,46 @@ class Net::Tcp_packet struct Psh : Bitfield<3, 1> { }; struct Ack : Bitfield<4, 1> { }; struct Urg : Bitfield<5, 1> { }; + struct Ece : Bitfield<6, 1> { }; + struct Crw : Bitfield<7, 1> { }; + struct Ns : Bitfield<8, 1> { }; }; public: - bool fin() const { return Flags::Fin::get(_flags); }; - bool syn() const { return Flags::Syn::get(_flags); }; - bool rst() const { return Flags::Rst::get(_flags); }; - bool psh() const { return Flags::Psh::get(_flags); }; - bool ack() const { return Flags::Ack::get(_flags); }; - bool urg() const { return Flags::Urg::get(_flags); }; - - enum Protocol_id { IP_ID = 6 }; - class No_tcp_packet : Exception {}; + + Tcp_packet(size_t size) { + if (size < sizeof(Tcp_packet)) { throw No_tcp_packet(); } } + + + /*************** + ** Accessors ** + ***************/ + + Port src_port() const { return Port(host_to_big_endian(_src_port)); } + Port dst_port() const { return Port(host_to_big_endian(_dst_port)); } + uint32_t seq_nr() const { return host_to_big_endian(_seq_nr); } + uint32_t ack_nr() const { return host_to_big_endian(_ack_nr); } + uint8_t data_offset() const { return _data_offset; } + uint16_t flags() const { return _flags_lsb | _flags_msb << 8; } + uint16_t window_size() const { return host_to_big_endian(_window_size); } + uint16_t checksum() const { return host_to_big_endian(_checksum); } + uint16_t urgent_ptr() const { return host_to_big_endian(_urgent_ptr); } + bool ns() const { return Flags::Ns::get(flags()); }; + bool ece() const { return Flags::Ece::get(flags()); }; + bool crw() const { return Flags::Crw::get(flags()); }; + bool fin() const { return Flags::Fin::get(flags()); }; + bool syn() const { return Flags::Syn::get(flags()); }; + bool rst() const { return Flags::Rst::get(flags()); }; + bool psh() const { return Flags::Psh::get(flags()); }; + bool ack() const { return Flags::Ack::get(flags()); }; + bool urg() const { return Flags::Urg::get(flags()); }; + void src_port(Port p) { _src_port = host_to_big_endian(p.value); } void dst_port(Port p) { _dst_port = host_to_big_endian(p.value); } - Port src_port() const { return Port(host_to_big_endian(_src_port)); } - Port dst_port() const { return Port(host_to_big_endian(_dst_port)); } - uint16_t flags() const { return host_to_big_endian(_flags); } - - Tcp_packet(size_t size) { - if (size < sizeof(Tcp_packet)) { throw No_tcp_packet(); } } /** * TCP checksum is calculated over the tcp datagram + an IPv4 @@ -111,7 +129,7 @@ class Net::Tcp_packet uint16_t d = ip_dst.addr[i] << 8 | ip_dst.addr[i + 1]; sum += s + d; } - uint8_t prot[] = { 0, IP_ID }; + uint8_t prot[] = { 0, (uint8_t)Ipv4_packet::Protocol::TCP }; sum += host_to_big_endian(*(uint16_t *)&prot) + tcp_size; /* sum up TCP packet itself */ diff --git a/repos/os/include/net/udp.h b/repos/os/include/net/udp.h index c798c2e9f..c47d5a5b4 100644 --- a/repos/os/include/net/udp.h +++ b/repos/os/include/net/udp.h @@ -51,9 +51,6 @@ class Net::Udp_packet public: - enum Protocol_id { IP_ID = 0x11 }; - - /** * Exception used to indicate protocol violation. */ @@ -71,20 +68,20 @@ class Net::Udp_packet } - /****************************** - ** UDP field read-accessors ** - ******************************/ + /*************** + ** Accessors ** + ***************/ - Port src_port() const { return Port(host_to_big_endian(_src_port)); } - Port dst_port() const { return Port(host_to_big_endian(_dst_port)); } - Genode::uint16_t length() const { return host_to_big_endian(_length); } - Genode::uint16_t checksum() const { return host_to_big_endian(_checksum); } + Port src_port() const { return Port(host_to_big_endian(_src_port)); } + Port dst_port() const { return Port(host_to_big_endian(_dst_port)); } + Genode::uint16_t length() const { return host_to_big_endian(_length); } + Genode::uint16_t checksum() const { return host_to_big_endian(_checksum); } + template T const * data() const { return (T const *)(_data); } + template T * data() { return (T *)(_data); } - void src_port(Port p) { _src_port = host_to_big_endian(p.value); } - void dst_port(Port p) { _dst_port = host_to_big_endian(p.value); } - - template T * data() { return (T *)(_data); } - template T const * data() const { return (T const *)(_data); } + void length(Genode::uint16_t v) { _length = host_to_big_endian(v); } + void src_port(Port p) { _src_port = host_to_big_endian(p.value); } + void dst_port(Port p) { _dst_port = host_to_big_endian(p.value); } /*************** @@ -127,7 +124,7 @@ class Net::Udp_packet Genode::uint16_t d = dst.addr[i] << 8 | dst.addr[i + 1]; sum += s + d; } - Genode::uint8_t prot[] = { 0, IP_ID }; + Genode::uint8_t prot[] = { 0, (Genode::uint8_t)Ipv4_packet::Protocol::UDP }; sum += host_to_big_endian(*(Genode::uint16_t*)&prot) + length(); /* diff --git a/repos/os/src/lib/net/ipv4.cc b/repos/os/src/lib/net/ipv4.cc index 76ae764d6..5be75d3b4 100644 --- a/repos/os/src/lib/net/ipv4.cc +++ b/repos/os/src/lib/net/ipv4.cc @@ -26,11 +26,11 @@ void Net::Ipv4_packet::print(Genode::Output &output) const { Genode::print(output, "\033[32mIPV4\033[0m ", src(), " > ", dst(), " "); switch (protocol()) { - case Tcp_packet::IP_ID: + case Protocol::TCP: Genode::print(output, *reinterpret_cast(data())); break; - case Udp_packet::IP_ID: + case Protocol::UDP: Genode::print(output, *reinterpret_cast(data())); break; @@ -84,7 +84,7 @@ Ipv4_address Ipv4_packet::ip_from_string(const char *ip) Genode::uint16_t Ipv4_packet::calculate_checksum(Ipv4_packet const &packet) { - Genode::uint16_t const *data = packet.header(); + Genode::uint16_t const *data = (Genode::uint16_t *)&packet; Genode::uint32_t const sum = host_to_big_endian(data[0]) + host_to_big_endian(data[1]) + host_to_big_endian(data[2]) diff --git a/repos/os/src/lib/net/stat.cc b/repos/os/src/lib/net/stat.cc index f21a78ba2..8d0f287f4 100644 --- a/repos/os/src/lib/net/stat.cc +++ b/repos/os/src/lib/net/stat.cc @@ -30,7 +30,7 @@ enum Measurement::status Measurement::_check(Net::Ethernet_frame * eth, Ipv4_packet *ip = new (eth->data()) Ipv4_packet(size - sizeof(Ethernet_frame)); - if (ip->protocol() != Udp_packet::IP_ID) + if (ip->protocol() != Ipv4_packet::Protocol::UDP) return Measurement::UNKNOWN; Udp_packet *udp = new (ip->data()) Udp_packet(size - sizeof(Ethernet_frame) diff --git a/repos/os/src/lib/net/tcp.cc b/repos/os/src/lib/net/tcp.cc index 84617e8e3..60b6bc40f 100644 --- a/repos/os/src/lib/net/tcp.cc +++ b/repos/os/src/lib/net/tcp.cc @@ -27,5 +27,8 @@ void Net::Tcp_packet::print(Genode::Output &output) const if (psh()) { Genode::print(output, "p"); } if (ack()) { Genode::print(output, "a"); } if (urg()) { Genode::print(output, "u"); } + if (ece()) { Genode::print(output, "e"); } + if (crw()) { Genode::print(output, "c"); } + if (ns()) { Genode::print(output, "n"); } Genode::print(output, "' "); } diff --git a/repos/os/src/server/nic_bridge/component.cc b/repos/os/src/server/nic_bridge/component.cc index 5466ca0a7..cc22b5944 100644 --- a/repos/os/src/server/nic_bridge/component.cc +++ b/repos/os/src/server/nic_bridge/component.cc @@ -54,7 +54,7 @@ bool Session_component::handle_ip(Ethernet_frame *eth, Genode::size_t size) Ipv4_packet *ip = new (eth->data()) Ipv4_packet(size - sizeof(Ethernet_frame)); - if (ip->protocol() == Udp_packet::IP_ID) + if (ip->protocol() == Ipv4_packet::Protocol::UDP) { Udp_packet *udp = new (ip->data()) Udp_packet(size - sizeof(Ipv4_packet)); diff --git a/repos/os/src/server/nic_bridge/nic.cc b/repos/os/src/server/nic_bridge/nic.cc index 5e6ab1a04..5d99fde5b 100644 --- a/repos/os/src/server/nic_bridge/nic.cc +++ b/repos/os/src/server/nic_bridge/nic.cc @@ -70,7 +70,7 @@ bool Net::Nic::handle_ip(Ethernet_frame *eth, Genode::size_t size) { Ipv4_packet(size - sizeof(Ethernet_frame)); /* is it an UDP packet ? */ - if (ip->protocol() == Udp_packet::IP_ID) + if (ip->protocol() == Ipv4_packet::Protocol::UDP) { Udp_packet *udp = new (ip->data()) Udp_packet(size - sizeof(Ipv4_packet)); diff --git a/repos/os/src/server/nic_router/domain.cc b/repos/os/src/server/nic_router/domain.cc index 0b40e4166..cd21e37b2 100644 --- a/repos/os/src/server/nic_router/domain.cc +++ b/repos/os/src/server/nic_router/domain.cc @@ -13,7 +13,7 @@ /* local includes */ #include -#include +#include /* Genode includes */ #include diff --git a/repos/os/src/server/nic_router/interface.cc b/repos/os/src/server/nic_router/interface.cc index ab16339e1..5cf0b0ec7 100644 --- a/repos/os/src/server/nic_router/interface.cc +++ b/repos/os/src/server/nic_router/interface.cc @@ -19,7 +19,7 @@ /* local includes */ #include #include -#include +#include using namespace Net; using namespace Genode; @@ -54,13 +54,13 @@ static void _destroy_links(Link_side_tree &links, } -static void _link_packet(uint8_t const prot, - void *const prot_base, - Link &link, - bool const client) +static void _link_packet(L3_protocol const prot, + void *const prot_base, + Link &link, + bool const client) { switch (prot) { - case Tcp_packet::IP_ID: + case L3_protocol::TCP: if (client) { static_cast(&link)->client_packet(*(Tcp_packet *)(prot_base)); return; @@ -68,77 +68,77 @@ static void _link_packet(uint8_t const prot, static_cast(&link)->server_packet(*(Tcp_packet *)(prot_base)); return; } - case Udp_packet::IP_ID: + case L3_protocol::UDP: static_cast(&link)->packet(); return; default: throw Interface::Bad_transport_protocol(); } } -static void _update_checksum(uint8_t const prot, +static void _update_checksum(L3_protocol const prot, void *const prot_base, size_t const prot_size, Ipv4_address const src, Ipv4_address const dst) { switch (prot) { - case Tcp_packet::IP_ID: + case L3_protocol::TCP: ((Tcp_packet *)prot_base)->update_checksum(src, dst, prot_size); return; - case Udp_packet::IP_ID: + case L3_protocol::UDP: ((Udp_packet *)prot_base)->update_checksum(src, dst); return; default: throw Interface::Bad_transport_protocol(); } } -static Port _dst_port(uint8_t const prot, void *const prot_base) +static Port _dst_port(L3_protocol const prot, void *const prot_base) { switch (prot) { - case Tcp_packet::IP_ID: return (*(Tcp_packet *)prot_base).dst_port(); - case Udp_packet::IP_ID: return (*(Udp_packet *)prot_base).dst_port(); + case L3_protocol::TCP: return (*(Tcp_packet *)prot_base).dst_port(); + case L3_protocol::UDP: return (*(Udp_packet *)prot_base).dst_port(); default: throw Interface::Bad_transport_protocol(); } } -static void _dst_port(uint8_t const prot, - void *const prot_base, - Port const port) +static void _dst_port(L3_protocol const prot, + void *const prot_base, + Port const port) { switch (prot) { - case Tcp_packet::IP_ID: (*(Tcp_packet *)prot_base).dst_port(port); return; - case Udp_packet::IP_ID: (*(Udp_packet *)prot_base).dst_port(port); return; + case L3_protocol::TCP: (*(Tcp_packet *)prot_base).dst_port(port); return; + case L3_protocol::UDP: (*(Udp_packet *)prot_base).dst_port(port); return; default: throw Interface::Bad_transport_protocol(); } } -static Port _src_port(uint8_t const prot, void *const prot_base) +static Port _src_port(L3_protocol const prot, void *const prot_base) { switch (prot) { - case Tcp_packet::IP_ID: return (*(Tcp_packet *)prot_base).src_port(); - case Udp_packet::IP_ID: return (*(Udp_packet *)prot_base).src_port(); + case L3_protocol::TCP: return (*(Tcp_packet *)prot_base).src_port(); + case L3_protocol::UDP: return (*(Udp_packet *)prot_base).src_port(); default: throw Interface::Bad_transport_protocol(); } } -static void _src_port(uint8_t const prot, - void *const prot_base, - Port const port) +static void _src_port(L3_protocol const prot, + void *const prot_base, + Port const port) { switch (prot) { - case Tcp_packet::IP_ID: ((Tcp_packet *)prot_base)->src_port(port); return; - case Udp_packet::IP_ID: ((Udp_packet *)prot_base)->src_port(port); return; + case L3_protocol::TCP: ((Tcp_packet *)prot_base)->src_port(port); return; + case L3_protocol::UDP: ((Udp_packet *)prot_base)->src_port(port); return; default: throw Interface::Bad_transport_protocol(); } } -static void *_prot_base(uint8_t const prot, - size_t const prot_size, - Ipv4_packet &ip) +static void *_prot_base(L3_protocol const prot, + size_t const prot_size, + Ipv4_packet &ip) { switch (prot) { - case Tcp_packet::IP_ID: return new (ip.data()) Tcp_packet(prot_size); - case Udp_packet::IP_ID: return new (ip.data()) Udp_packet(prot_size); + case L3_protocol::TCP: return new (ip.data()) Tcp_packet(prot_size); + case L3_protocol::UDP: return new (ip.data()) Udp_packet(prot_size); default: throw Interface::Bad_transport_protocol(); } } @@ -147,12 +147,12 @@ static void *_prot_base(uint8_t const prot, ** Interface ** ***************/ -void Interface::_pass_prot(Ethernet_frame ð, - size_t const eth_size, - Ipv4_packet &ip, - uint8_t const prot, - void *const prot_base, - size_t const prot_size) +void Interface::_pass_prot(Ethernet_frame ð, + size_t const eth_size, + Ipv4_packet &ip, + L3_protocol const prot, + void *const prot_base, + size_t const prot_size) { _update_checksum(prot, prot_base, prot_size, ip.src(), ip.dst()); _pass_ip(eth, eth_size, ip); @@ -168,33 +168,35 @@ void Interface::_pass_ip(Ethernet_frame ð, } -Forward_rule_tree &Interface::_forward_rules(uint8_t const prot) const +Forward_rule_tree & +Interface::_forward_rules(L3_protocol const prot) const { switch (prot) { - case Tcp_packet::IP_ID: return _domain.tcp_forward_rules(); - case Udp_packet::IP_ID: return _domain.udp_forward_rules(); + case L3_protocol::TCP: return _domain.tcp_forward_rules(); + case L3_protocol::UDP: return _domain.udp_forward_rules(); default: throw Bad_transport_protocol(); } } -Transport_rule_list &Interface::_transport_rules(uint8_t const prot) const +Transport_rule_list & +Interface::_transport_rules(L3_protocol const prot) const { switch (prot) { - case Tcp_packet::IP_ID: return _domain.tcp_rules(); - case Udp_packet::IP_ID: return _domain.udp_rules(); + case L3_protocol::TCP: return _domain.tcp_rules(); + case L3_protocol::UDP: return _domain.udp_rules(); default: throw Bad_transport_protocol(); } } void -Interface::_new_link(uint8_t const protocol, +Interface::_new_link(L3_protocol const protocol, Link_side_id const &local, Pointer const remote_port_alloc, Interface &remote_interface, Link_side_id const &remote) { switch (protocol) { - case Tcp_packet::IP_ID: + case L3_protocol::TCP: { Tcp_link &link = *new (_alloc) Tcp_link(*this, local, remote_port_alloc, remote_interface, @@ -208,7 +210,7 @@ Interface::_new_link(uint8_t const protocol, } return; } - case Udp_packet::IP_ID: + case L3_protocol::UDP: { Udp_link &link = *new (_alloc) Udp_link(*this, local, remote_port_alloc, remote_interface, @@ -226,32 +228,32 @@ Interface::_new_link(uint8_t const protocol, } -Link_side_tree &Interface::_links(uint8_t const protocol) +Link_side_tree &Interface::_links(L3_protocol const protocol) { switch (protocol) { - case Tcp_packet::IP_ID: return _tcp_links; - case Udp_packet::IP_ID: return _udp_links; + case L3_protocol::TCP: return _tcp_links; + case L3_protocol::UDP: return _udp_links; default: throw Bad_transport_protocol(); } } -void Interface::link_closed(Link &link, uint8_t const prot) +void Interface::link_closed(Link &link, L3_protocol const prot) { _closed_links(prot).insert(&link); } -void Interface::dissolve_link(Link_side &link_side, uint8_t const prot) +void Interface::dissolve_link(Link_side &link_side, L3_protocol const prot) { _links(prot).remove(&link_side); } -Link_list &Interface::_closed_links(uint8_t const protocol) +Link_list &Interface::_closed_links(L3_protocol const protocol) { switch (protocol) { - case Tcp_packet::IP_ID: return _closed_tcp_links; - case Udp_packet::IP_ID: return _closed_udp_links; + case L3_protocol::TCP: return _closed_tcp_links; + case L3_protocol::UDP: return _closed_udp_links; default: throw Bad_transport_protocol(); } } @@ -273,14 +275,14 @@ void Interface::_adapt_eth(Ethernet_frame ð, } -void Interface::_nat_link_and_pass(Ethernet_frame ð, - size_t const eth_size, - Ipv4_packet &ip, - uint8_t const prot, - void *const prot_base, - size_t const prot_size, - Link_side_id const &local, - Interface &interface) +void Interface::_nat_link_and_pass(Ethernet_frame ð, + size_t const eth_size, + Ipv4_packet &ip, + L3_protocol const prot, + void *const prot_base, + size_t const prot_size, + Link_side_id const &local, + Interface &interface) { Pointer remote_port_alloc; try { @@ -313,7 +315,7 @@ void Interface::_handle_ip(Ethernet_frame ð, /* try to route via transport layer rules */ try { - uint8_t const prot = ip.protocol(); + L3_protocol const prot = ip.protocol(); size_t const prot_size = ip.total_length() - ip.header_length() * 4; void *const prot_base = _prot_base(prot, prot_size, ip); Link_side_id const local = { ip.src(), _src_port(prot, prot_base), @@ -327,7 +329,7 @@ void Interface::_handle_ip(Ethernet_frame ð, Link_side &remote_side = client ? link.server() : link.client(); Interface &interface = remote_side.interface(); if(_config().verbose()) { - log("Using ", protocol_name(prot), " link: ", link); } + log("Using ", l3_protocol_name(prot), " link: ", link); } _adapt_eth(eth, eth_size, remote_side.src_ip(), pkt, interface); ip.src(remote_side.dst_ip()); @@ -349,7 +351,7 @@ void Interface::_handle_ip(Ethernet_frame ð, Interface &interface = rule.domain().interface().deref(); if(_config().verbose()) { - log("Using forward rule: ", protocol_name(prot), " ", rule); } + log("Using forward rule: ", l3_protocol_name(prot), " ", rule); } _adapt_eth(eth, eth_size, rule.to(), pkt, interface); ip.dst(rule.to()); @@ -369,7 +371,7 @@ void Interface::_handle_ip(Ethernet_frame ð, Interface &interface = permit_rule.domain().interface().deref(); if(_config().verbose()) { - log("Using ", protocol_name(prot), " rule: ", transport_rule, + log("Using ", l3_protocol_name(prot), " rule: ", transport_rule, " ", permit_rule); } _adapt_eth(eth, eth_size, local.dst_ip, pkt, interface); diff --git a/repos/os/src/server/nic_router/interface.h b/repos/os/src/server/nic_router/interface.h index fedada3a0..69b801ba6 100644 --- a/repos/os/src/server/nic_router/interface.h +++ b/repos/os/src/server/nic_router/interface.h @@ -18,6 +18,7 @@ #include #include #include +#include /* Genode includes */ #include @@ -63,15 +64,15 @@ class Net::Interface Link_list _closed_tcp_links; Link_list _closed_udp_links; - void _new_link(Genode::uint8_t const protocol, + void _new_link(L3_protocol const protocol, Link_side_id const &local_id, Pointer const remote_port_alloc, Interface &remote_interface, Link_side_id const &remote_id); - Forward_rule_tree &_forward_rules(Genode::uint8_t const prot) const; + Forward_rule_tree &_forward_rules(L3_protocol const prot) const; - Transport_rule_list &_transport_rules(Genode::uint8_t const prot) const; + Transport_rule_list &_transport_rules(L3_protocol const prot) const; void _handle_arp(Ethernet_frame ð, Genode::size_t const eth_size); @@ -94,7 +95,7 @@ class Net::Interface void _nat_link_and_pass(Ethernet_frame ð, Genode::size_t const eth_size, Ipv4_packet &ip, - Genode::uint8_t const prot, + L3_protocol const prot, void *const prot_base, Genode::size_t const prot_size, Link_side_id const &local_id, @@ -107,7 +108,7 @@ class Net::Interface void _pass_prot(Ethernet_frame ð, Genode::size_t const eth_size, Ipv4_packet &ip, - Genode::uint8_t const prot, + L3_protocol const prot, void *const prot_base, Genode::size_t const prot_size); @@ -117,9 +118,9 @@ class Net::Interface void _continue_handle_eth(Packet_descriptor const &pkt); - Link_list &_closed_links(Genode::uint8_t const protocol); + Link_list &_closed_links(L3_protocol const protocol); - Link_side_tree &_links(Genode::uint8_t const protocol); + Link_side_tree &_links(L3_protocol const protocol); Configuration &_config() const; @@ -162,9 +163,9 @@ class Net::Interface ~Interface(); - void link_closed(Link &link, Genode::uint8_t const prot); + void link_closed(Link &link, L3_protocol const prot); - void dissolve_link(Link_side &link_side, Genode::uint8_t const prot); + void dissolve_link(Link_side &link_side, L3_protocol const prot); /********* diff --git a/repos/os/src/server/nic_router/protocol_name.cc b/repos/os/src/server/nic_router/l3_protocol.cc similarity index 75% rename from repos/os/src/server/nic_router/protocol_name.cc rename to repos/os/src/server/nic_router/l3_protocol.cc index 3347218d2..8e8c93289 100644 --- a/repos/os/src/server/nic_router/protocol_name.cc +++ b/repos/os/src/server/nic_router/l3_protocol.cc @@ -1,5 +1,5 @@ /* - * \brief Provide protocol names as Genode Cstring objects + * \brief Utilities regarding layer 3 protocols in general * \author Martin Stein * \date 2016-08-19 */ @@ -12,7 +12,7 @@ */ /* local includes */ -#include +#include #include /* Genode includes */ @@ -30,10 +30,10 @@ Cstring const &Net::udp_name() { return _udp_name; } Cstring const &Net::tcp_name() { return _tcp_name; } -Cstring const &Net::protocol_name(uint8_t protocol) +Cstring const &Net::l3_protocol_name(L3_protocol protocol) { switch (protocol) { - case Tcp_packet::IP_ID: return tcp_name(); - case Udp_packet::IP_ID: return udp_name(); + case L3_protocol::TCP: return tcp_name(); + case L3_protocol::UDP: return udp_name(); default: throw Interface::Bad_transport_protocol(); } } diff --git a/repos/os/src/server/nic_router/protocol_name.h b/repos/os/src/server/nic_router/l3_protocol.h similarity index 61% rename from repos/os/src/server/nic_router/protocol_name.h rename to repos/os/src/server/nic_router/l3_protocol.h index ef3000d47..8a48262f0 100644 --- a/repos/os/src/server/nic_router/protocol_name.h +++ b/repos/os/src/server/nic_router/l3_protocol.h @@ -1,5 +1,5 @@ /* - * \brief Provide protocol names as Genode Cstring objects + * \brief Utilities regarding layer 3 protocols in general * \author Martin Stein * \date 2016-08-19 */ @@ -11,19 +11,22 @@ * under the terms of the GNU Affero General Public License version 3. */ -#ifndef _PROTOCOL_NAME_H_ -#define _PROTOCOL_NAME_H_ +#ifndef _L3_PROTOCOL_H_ +#define _L3_PROTOCOL_H_ /* Genode includes */ +#include #include namespace Genode { class Cstring; } namespace Net { + using L3_protocol = Ipv4_packet::Protocol; + Genode::Cstring const &tcp_name(); Genode::Cstring const &udp_name(); - Genode::Cstring const &protocol_name(Genode::uint8_t protocol); + Genode::Cstring const &l3_protocol_name(L3_protocol protocol); } -#endif /* _PROTOCOL_NAME_H_ */ +#endif /* _L3_PROTOCOL_H_ */ diff --git a/repos/os/src/server/nic_router/link.cc b/repos/os/src/server/nic_router/link.cc index a1ec89425..b3a74a80f 100644 --- a/repos/os/src/server/nic_router/link.cc +++ b/repos/os/src/server/nic_router/link.cc @@ -18,7 +18,7 @@ #include #include #include -#include +#include using namespace Net; using namespace Genode; @@ -117,7 +117,7 @@ Link::Link(Interface &cln_interface, Link_side_id const &srv_id, Timer::Connection &timer, Configuration &config, - uint8_t const protocol) + L3_protocol const protocol) : _config(config), _client(cln_interface, cln_id, *this), @@ -143,12 +143,12 @@ void Link::dissolve() _client._interface.dissolve_link(_client, _protocol); _server._interface.dissolve_link(_server, _protocol); if (_config.verbose()) { - log("Dissolve ", protocol_name(_protocol), " link: ", *this); } + log("Dissolve ", l3_protocol_name(_protocol), " link: ", *this); } try { _server_port_alloc.deref().free(_server.dst_port()); if (_config.verbose()) { - log("Free ", protocol_name(_protocol), + log("Free ", l3_protocol_name(_protocol), " port ", _server.dst_port(), " at ", _server.interface(), " that was used by ", _client.interface()); @@ -169,7 +169,7 @@ Tcp_link::Tcp_link(Interface &cln_interface, Link_side_id const &srv_id, Timer::Connection &timer, Configuration &config, - uint8_t const protocol) + L3_protocol const protocol) : Link(cln_interface, cln_id, srv_port_alloc, srv_interface, srv_id, timer, config, protocol) @@ -230,7 +230,7 @@ Udp_link::Udp_link(Interface &cln_interface, Link_side_id const &srv_id, Timer::Connection &timer, Configuration &config, - uint8_t const protocol) + L3_protocol const protocol) : Link(cln_interface, cln_id, srv_port_alloc, srv_interface, srv_id, timer, config, protocol) diff --git a/repos/os/src/server/nic_router/link.h b/repos/os/src/server/nic_router/link.h index 56f5c5e2d..31123a536 100644 --- a/repos/os/src/server/nic_router/link.h +++ b/repos/os/src/server/nic_router/link.h @@ -23,6 +23,7 @@ /* local includes */ #include +#include namespace Net { @@ -131,7 +132,7 @@ class Net::Link : public Link_list::Element Link_side _server; Timer::One_shot_timeout _close_timeout; Genode::Microseconds const _close_timeout_us; - Genode::uint8_t const _protocol; + L3_protocol const _protocol; void _handle_close_timeout(Genode::Duration); @@ -148,7 +149,7 @@ class Net::Link : public Link_list::Element Link_side_id const &srv_id, Timer::Connection &timer, Configuration &config, - Genode::uint8_t const protocol); + L3_protocol const protocol); void dissolve(); @@ -190,7 +191,7 @@ class Net::Tcp_link : public Link Link_side_id const &srv_id, Timer::Connection &timer, Configuration &config, - Genode::uint8_t const protocol); + L3_protocol const protocol); void client_packet(Tcp_packet &tcp); @@ -207,7 +208,7 @@ struct Net::Udp_link : Link Link_side_id const &srv_id, Timer::Connection &timer, Configuration &config, - Genode::uint8_t const protocol); + L3_protocol const protocol); void packet() { _packet(); } }; diff --git a/repos/os/src/server/nic_router/nat_rule.cc b/repos/os/src/server/nic_router/nat_rule.cc index 425bbcdc7..abb6a6b9b 100644 --- a/repos/os/src/server/nic_router/nat_rule.cc +++ b/repos/os/src/server/nic_router/nat_rule.cc @@ -75,10 +75,10 @@ void Nat_rule::print(Output &output) const } -Port_allocator_guard &Nat_rule::port_alloc(uint8_t const prot) +Port_allocator_guard &Nat_rule::port_alloc(L3_protocol const prot) { switch (prot) { - case Tcp_packet::IP_ID: return _tcp_port_alloc; - case Udp_packet::IP_ID: return _udp_port_alloc; + case L3_protocol::TCP: return _tcp_port_alloc; + case L3_protocol::UDP: return _udp_port_alloc; default: throw Interface::Bad_transport_protocol(); } } diff --git a/repos/os/src/server/nic_router/nat_rule.h b/repos/os/src/server/nic_router/nat_rule.h index 5723a28ce..d0f9fad0b 100644 --- a/repos/os/src/server/nic_router/nat_rule.h +++ b/repos/os/src/server/nic_router/nat_rule.h @@ -17,6 +17,7 @@ /* local includes */ #include #include +#include /* Genode includes */ #include @@ -47,7 +48,7 @@ class Net::Nat_rule : public Leaf_rule, Nat_rule &find_by_domain(Domain &domain); - Port_allocator_guard &port_alloc(Genode::uint8_t const prot); + Port_allocator_guard &port_alloc(L3_protocol const prot); /********* diff --git a/repos/os/src/server/nic_router/target.mk b/repos/os/src/server/nic_router/target.mk index 298a1200f..9fb66be04 100644 --- a/repos/os/src/server/nic_router/target.mk +++ b/repos/os/src/server/nic_router/target.mk @@ -6,7 +6,7 @@ SRC_CC += arp_waiter.cc ip_rule.cc SRC_CC += component.cc port_allocator.cc forward_rule.cc SRC_CC += nat_rule.cc mac_allocator.cc main.cc SRC_CC += uplink.cc interface.cc arp_cache.cc configuration.cc -SRC_CC += domain.cc protocol_name.cc direct_rule.cc link.cc +SRC_CC += domain.cc l3_protocol.cc direct_rule.cc link.cc SRC_CC += transport_rule.cc leaf_rule.cc permit_rule.cc INC_DIR += $(PRG_DIR)