diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-10-27 23:20:24 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-10-28 11:24:36 +0200 |
commit | adc9939a7b9afccb4dbbda7f53d569fe38bfb391 (patch) | |
tree | 9710bfd9b91f328c4a15b34d3b90dc9766950130 /Kernel/Net/IPv4Socket.cpp | |
parent | 20c7fcfedf9866f9a6a091a809014ec7a48d9932 (diff) | |
download | serenity-adc9939a7b9afccb4dbbda7f53d569fe38bfb391.zip |
Kernel+LibC: Add support for the IPv4 TOS field via the IP_TOS sockopt
Diffstat (limited to 'Kernel/Net/IPv4Socket.cpp')
-rw-r--r-- | Kernel/Net/IPv4Socket.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/Kernel/Net/IPv4Socket.cpp b/Kernel/Net/IPv4Socket.cpp index 7d64a68f32..326c2452e4 100644 --- a/Kernel/Net/IPv4Socket.cpp +++ b/Kernel/Net/IPv4Socket.cpp @@ -229,7 +229,7 @@ KResultOr<size_t> IPv4Socket::sendto(OpenFileDescription&, const UserOrKernelBuf if (!packet) return set_so_error(ENOMEM); routing_decision.adapter->fill_in_ipv4_header(*packet, local_address(), routing_decision.next_hop, - m_peer_address, (IPv4Protocol)protocol(), data_length, m_ttl); + m_peer_address, (IPv4Protocol)protocol(), data_length, m_type_of_service, m_ttl); if (auto result = data.read(packet->buffer->data() + ipv4_payload_offset, data_length); result.is_error()) { routing_decision.adapter->release_packet_buffer(*packet); return set_so_error(result); @@ -504,6 +504,16 @@ KResult IPv4Socket::setsockopt(int level, int option, Userspace<const void*> use m_ttl = value; return KSuccess; } + case IP_TOS: { + if (user_value_size < sizeof(int)) + return EINVAL; + int value; + TRY(copy_from_user(&value, static_ptr_cast<const int*>(user_value))); + if (value < 0 || value > 255) + return EINVAL; + m_type_of_service = value; + return KSuccess; + } case IP_MULTICAST_LOOP: { if (user_value_size != 1) return EINVAL; @@ -559,6 +569,14 @@ KResult IPv4Socket::getsockopt(OpenFileDescription& description, int level, int size = sizeof(int); return copy_to_user(value_size, &size); } + case IP_TOS: { + if (size < sizeof(int)) + return EINVAL; + int type_of_service = m_type_of_service; + TRY(copy_to_user(static_ptr_cast<int*>(value), (int*)&type_of_service)); + size = sizeof(int); + return copy_to_user(value_size, &size); + } case IP_MULTICAST_LOOP: { if (size < 1) return EINVAL; |