From b0e558f4860f539c31d38d85c2c3bc9fc13f94fb Mon Sep 17 00:00:00 2001 From: Martin Stein Date: Tue, 3 Aug 2021 13:16:00 +0200 Subject: [PATCH] net/icmp: cast from integer to 'Code' enum Add a function to the header for doing this cast. Ref #4236 --- repos/os/include/net/icmp.h | 61 +++++++++++++++++++++++++++++++++++-- 1 file changed, 59 insertions(+), 2 deletions(-) diff --git a/repos/os/include/net/icmp.h b/repos/os/include/net/icmp.h index d7f30f21a9..f1da401979 100644 --- a/repos/os/include/net/icmp.h +++ b/repos/os/include/net/icmp.h @@ -51,10 +51,67 @@ class Net::Icmp_packet enum class Code { DST_NET_UNREACHABLE = 0, - ECHO_REQUEST = 0, - ECHO_REPLY = 0, + DST_HOST_UNREACHABLE = 1, + DST_PROTOCOL_UNREACHABLE = 2, + DST_PORT_UNREACHABLE = 3, + FRAGM_REQUIRED_AND_DF_FLAG_SET = 4, + SOURCE_ROUTE_FAILED = 5, + DST_NET_UNKNOWN = 6, + DST_HOST_UNKNOWN = 7, + SOURCE_HOST_ISOLATED = 8, + NET_ADMINISTRATIVELY_PROHIB = 9, + HOST_ADMINISTRATIVELY_PROHIB = 10, + NET_UNREACHABLE_FOR_TOS = 11, + HOST_UNREACHABLE_FOR_TOS = 12, + COM_ADMINISTRATIVELY_PROHIB = 13, + HOST_PRECEDENCE_VIOLATION = 14, + PRECEDENCE_CUTOFF_IN_EFFECT = 15, + ECHO_REQUEST = 0, + ECHO_REPLY = 0, + INVALID = 255, }; + static Code code_from_uint8(Type type, + Genode::uint8_t code) + { + switch (type) { + case Type::DST_UNREACHABLE: + switch (code) { + case 0: return Code::DST_NET_UNREACHABLE; + case 1: return Code::DST_HOST_UNREACHABLE; + case 2: return Code::DST_PROTOCOL_UNREACHABLE; + case 3: return Code::DST_PORT_UNREACHABLE; + case 4: return Code::FRAGM_REQUIRED_AND_DF_FLAG_SET; + case 5: return Code::SOURCE_ROUTE_FAILED; + case 6: return Code::DST_NET_UNKNOWN; + case 7: return Code::DST_HOST_UNKNOWN; + case 8: return Code::SOURCE_HOST_ISOLATED; + case 9: return Code::NET_ADMINISTRATIVELY_PROHIB; + case 10: return Code::HOST_ADMINISTRATIVELY_PROHIB; + case 11: return Code::NET_UNREACHABLE_FOR_TOS; + case 12: return Code::HOST_UNREACHABLE_FOR_TOS; + case 13: return Code::COM_ADMINISTRATIVELY_PROHIB; + case 14: return Code::HOST_PRECEDENCE_VIOLATION; + case 15: return Code::PRECEDENCE_CUTOFF_IN_EFFECT; + default: break; + } + break; + case Type::ECHO_REPLY: + switch (code) { + case 0: return Code::ECHO_REPLY; + default: break; + } + break; + case Type::ECHO_REQUEST: + switch (code) { + case 0: return Code::ECHO_REQUEST; + default: break; + } + break; + } + return Code::INVALID; + } + void update_checksum(Genode::size_t data_sz); bool checksum_error(Genode::size_t data_sz) const;