From 7b55d4d5d91754b2f72658fb6a00847d5bb43c03 Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Wed, 13 Sep 2017 13:10:39 +0200 Subject: [PATCH] ethernet: rework type for ethernet type value Encapsulate the enum into a struct so that it is named Ethernet_frame::Type::Enum, give it the correct storage type uint16_t, and remove those values that are (AFAIK) not used by now (genode, world). Ref #2490 --- repos/os/include/net/arp.h | 2 +- repos/os/include/net/ethernet.h | 48 +++---------------- repos/os/src/lib/net/ethernet.cc | 4 +- .../src/server/nic_bridge/packet_handler.cc | 4 +- repos/os/src/server/nic_router/interface.cc | 6 +-- 5 files changed, 14 insertions(+), 50 deletions(-) diff --git a/repos/os/include/net/arp.h b/repos/os/include/net/arp.h index f02a42a01a..17310000fb 100644 --- a/repos/os/include/net/arp.h +++ b/repos/os/include/net/arp.h @@ -299,7 +299,7 @@ class Net::Arp_packet */ bool ethernet_ipv4() const { return ( host_to_big_endian(_hw_addr_type) == ETHERNET - && host_to_big_endian(_prot_addr_type) == Ethernet_frame::IPV4 + && 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); } diff --git a/repos/os/include/net/ethernet.h b/repos/os/include/net/ethernet.h index 0884b4ff80..f94984dc56 100644 --- a/repos/os/include/net/ethernet.h +++ b/repos/os/include/net/ethernet.h @@ -68,45 +68,9 @@ class Net::Ethernet_frame /** * Id representing encapsulated protocol. */ - enum Ether_type { - IPV4 = 0x0800, - ARP = 0x0806, - WAKE_ON_LAN = 0x0842, - SYN3 = 0x1337, - RARP = 0x8035, - APPLETALK = 0x809B, - AARP = 0x80F3, - VLAN_TAGGED = 0x8100, - IPX = 0x8137, - NOVELL = 0x8138, - IPV6 = 0x86DD, - MAC_CONTROL = 0x8808, - SLOW = 0x8809, - COBRANET = 0x8819, - MPLS_UNICAST = 0x8847, - MPLS_MULTICAST = 0x8848, - PPPOE_DISCOVERY = 0x8863, - PPPOE_STAGE = 0x8864, - NLB = 0x886F, - JUMBO_FRAMES = 0x8870, - EAP = 0x888E, - PROFINET = 0x8892, - HYPERSCSI = 0x889A, - ATAOE = 0x88A2, - ETHERCAT = 0x88A4, - PROVIDER_BRIDGING = 0x88A8, - POWERLINK = 0x88AB, - LLDP = 0x88CC, - SERCOS_III = 0x88CD, - CESOE = 0x88D8, - HOMEPLUG = 0x88E1, - MAC_SEC = 0x88E5, - PRECISION_TIME = 0x88F7, - CFM = 0x8902, - FCOE = 0x8906, - FCOE_Init = 0x8914, - Q_IN_Q = 0x9100, - LLT = 0xCAFE + enum class Type : Genode::uint16_t { + IPV4 = 0x0800, + ARP = 0x0806, }; @@ -138,7 +102,7 @@ class Net::Ethernet_frame /** * \return EtherType - type of encapsulated protocol. */ - Genode::uint16_t type() const { return host_to_big_endian(_type); } + Type type() const { return (Type)host_to_big_endian(_type); } /** * \return payload data. @@ -170,7 +134,7 @@ class Net::Ethernet_frame * * \param type the EtherType to be set. */ - void type(Genode::uint16_t type) { _type = host_to_big_endian(type); } + void type(Type type) { _type = host_to_big_endian((Genode::uint16_t)type); } /*************** @@ -208,7 +172,7 @@ class Net::Ethernet_frame_sized : public Ethernet_frame public: Ethernet_frame_sized(Mac_address dst_in, Mac_address src_in, - Ether_type type_in) + Type type_in) : Ethernet_frame(sizeof(Ethernet_frame)) { diff --git a/repos/os/src/lib/net/ethernet.cc b/repos/os/src/lib/net/ethernet.cc index 8194aea4d5..7946a0b776 100644 --- a/repos/os/src/lib/net/ethernet.cc +++ b/repos/os/src/lib/net/ethernet.cc @@ -24,11 +24,11 @@ void Net::Ethernet_frame::print(Genode::Output &output) const { Genode::print(output, "\033[32mETH\033[0m ", src(), " > ", dst(), " "); switch (type()) { - case Ethernet_frame::ARP: + case Ethernet_frame::Type::ARP: Genode::print(output, *reinterpret_cast(data())); break; - case Ethernet_frame::IPV4: + case Ethernet_frame::Type::IPV4: Genode::print(output, *reinterpret_cast(data())); break; diff --git a/repos/os/src/server/nic_bridge/packet_handler.cc b/repos/os/src/server/nic_bridge/packet_handler.cc index 53eb8ec2fc..ee28e58447 100644 --- a/repos/os/src/server/nic_bridge/packet_handler.cc +++ b/repos/os/src/server/nic_bridge/packet_handler.cc @@ -81,10 +81,10 @@ void Packet_handler::handle_ethernet(void* src, Genode::size_t size) /* parse ethernet frame header */ Ethernet_frame *eth = new (src) Ethernet_frame(size); switch (eth->type()) { - case Ethernet_frame::ARP: + case Ethernet_frame::Type::ARP: if (!handle_arp(eth, size)) return; break; - case Ethernet_frame::IPV4: + case Ethernet_frame::Type::IPV4: if(!handle_ip(eth, size)) return; break; default: diff --git a/repos/os/src/server/nic_router/interface.cc b/repos/os/src/server/nic_router/interface.cc index dd52a49fa4..ab16339e1b 100644 --- a/repos/os/src/server/nic_router/interface.cc +++ b/repos/os/src/server/nic_router/interface.cc @@ -406,7 +406,7 @@ void Interface::_handle_ip(Ethernet_frame ð, void Interface::_broadcast_arp_request(Ipv4_address const &ip) { using Ethernet_arp = Ethernet_frame_sized; - Ethernet_arp eth_arp(Mac_address(0xff), _router_mac, Ethernet_frame::ARP); + Ethernet_arp eth_arp(Mac_address(0xff), _router_mac, Ethernet_frame::Type::ARP); void *const eth_data = eth_arp.data(); size_t const arp_size = sizeof(eth_arp) - sizeof(Ethernet_frame); Arp_packet &arp = *new (eth_data) Arp_packet(arp_size); @@ -536,8 +536,8 @@ void Interface::_handle_eth(void *const eth_base, log("at ", _domain, " handle ", *eth); } switch (eth->type()) { - case Ethernet_frame::ARP: _handle_arp(*eth, eth_size); break; - case Ethernet_frame::IPV4: _handle_ip(*eth, eth_size, pkt); break; + case Ethernet_frame::Type::ARP: _handle_arp(*eth, eth_size); break; + case Ethernet_frame::Type::IPV4: _handle_ip(*eth, eth_size, pkt); break; default: throw Bad_network_protocol(); } } catch (Ethernet_frame::No_ethernet_frame) {