From 980f3e9c5c03e5991401110b45c33fb39c18dabf Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Thu, 26 Apr 2018 14:53:29 +0200 Subject: [PATCH] net: use Size_guard for packet-data accessors Instead of handing over the maximum available size to the packet data accessors, hand over a size guard that keeps track of the packets boundaries. This commit also moves the size-guard utilitiy header of Ping and NIC Router to the include/net directory making it a part of the net library. It applies the new approach to all net-lib users in the basic repositories. Ping looses its configurability regarding the ICMP data size as this would require an additional method in the size guard which would be used only by Ping. The size guard was also re-worked to fit the fact that a packet can bring a tail as well as a header (Ethernet). Issue #2788 --- repos/os/include/net/arp.h | 5 + repos/os/include/net/dhcp.h | 6 +- repos/os/include/net/ethernet.h | 52 +++- repos/os/include/net/icmp.h | 24 +- repos/os/include/net/ipv4.h | 17 +- repos/os/include/net/size_guard.h | 66 +++++ repos/os/include/net/udp.h | 18 +- repos/os/run/ping.run | 1 - repos/os/run/ping_nic_router.run | 4 - repos/os/src/app/ping/README | 8 +- repos/os/src/app/ping/config.xsd | 1 - repos/os/src/app/ping/main.cc | 160 +++++------ repos/os/src/app/ping/size_guard.h | 43 --- repos/os/src/server/nic_bridge/component.cc | 20 +- repos/os/src/server/nic_bridge/component.h | 15 +- repos/os/src/server/nic_bridge/nic.cc | 40 ++- repos/os/src/server/nic_bridge/nic.h | 14 +- .../src/server/nic_bridge/packet_handler.cc | 22 +- .../os/src/server/nic_bridge/packet_handler.h | 8 +- repos/os/src/server/nic_dump/packet_log.cc | 15 +- repos/os/src/server/nic_router/dhcp_client.cc | 60 ++-- repos/os/src/server/nic_router/dhcp_client.h | 3 +- repos/os/src/server/nic_router/interface.cc | 268 +++++++++--------- repos/os/src/server/nic_router/interface.h | 34 +-- repos/os/src/server/nic_router/size_guard.h | 46 --- 25 files changed, 456 insertions(+), 494 deletions(-) create mode 100644 repos/os/include/net/size_guard.h delete mode 100644 repos/os/src/app/ping/size_guard.h delete mode 100644 repos/os/src/server/nic_router/size_guard.h diff --git a/repos/os/include/net/arp.h b/repos/os/include/net/arp.h index 1feae1352e..3dc36566b2 100644 --- a/repos/os/include/net/arp.h +++ b/repos/os/include/net/arp.h @@ -123,6 +123,11 @@ class Net::Arp_packet && _protocol_address_size == Ipv4_packet::ADDR_LEN); } + Genode::size_t size(Genode::size_t max_size) const + { + return sizeof(Arp_packet) < max_size ? sizeof(Arp_packet) : max_size; + } + /********* ** Log ** diff --git a/repos/os/include/net/dhcp.h b/repos/os/include/net/dhcp.h index 2ab35b9db5..27a120caa0 100644 --- a/repos/os/include/net/dhcp.h +++ b/repos/os/include/net/dhcp.h @@ -333,7 +333,7 @@ class Net::Dhcp_packet template void append_param_req() { - _size_guard.add(sizeof(_base[0])); + _size_guard.consume_head(sizeof(_base[0])); _base[_size] = (Genode::uint8_t)OPTION::CODE; _size++; } @@ -351,7 +351,7 @@ class Net::Dhcp_packet template void append_option(ARGS &&... args) { - _size_guard.add(sizeof(OPTION)); + _size_guard.consume_head(sizeof(OPTION)); Genode::construct_at