1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-29 11:45:11 +00:00

Kernel+LibC: Add support for the IPv4 TOS field via the IP_TOS sockopt

This commit is contained in:
Idan Horowitz 2021-10-27 23:20:24 +03:00 committed by Andreas Kling
parent 20c7fcfedf
commit adc9939a7b
9 changed files with 37 additions and 8 deletions

View file

@ -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;