mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:38:10 +00:00
IPv4: Support overriding the default TTL (64)
Made getsockopt() and setsockopt() virtual so we can handle them in the various Socket subclasses. The subclasses map kinda nicely to "levels". This will allow us to implement things like "traceroute", although.. I spent some time trying to do that, but then hit a wall when it turned out that the user-mode networking in QEMU doesn't preserve TTL in the ICMP packets passing through.
This commit is contained in:
parent
482d5295f1
commit
8cfb859368
11 changed files with 58 additions and 10 deletions
|
@ -195,7 +195,7 @@ ssize_t IPv4Socket::sendto(FileDescription&, const void* data, size_t data_lengt
|
|||
#endif
|
||||
|
||||
if (type() == SOCK_RAW) {
|
||||
routing_decision.adapter->send_ipv4(routing_decision.next_hop, m_peer_address, (IPv4Protocol)protocol(), (const u8*)data, data_length);
|
||||
routing_decision.adapter->send_ipv4(routing_decision.next_hop, m_peer_address, (IPv4Protocol)protocol(), (const u8*)data, data_length, m_ttl);
|
||||
return data_length;
|
||||
}
|
||||
|
||||
|
@ -313,3 +313,38 @@ String IPv4Socket::absolute_path(const FileDescription&) const
|
|||
|
||||
return builder.to_string();
|
||||
}
|
||||
|
||||
KResult IPv4Socket::setsockopt(int level, int option, const void* value, socklen_t value_size)
|
||||
{
|
||||
if (level != IPPROTO_IP)
|
||||
return Socket::setsockopt(level, option, value, value_size);
|
||||
|
||||
switch (option) {
|
||||
case IP_TTL:
|
||||
if (value_size < sizeof(int))
|
||||
return KResult(-EINVAL);
|
||||
if (*(const int*)value < 0 || *(const int*)value > 255)
|
||||
return KResult(-EINVAL);
|
||||
m_ttl = (u8)*(const int*)value;
|
||||
return KSuccess;
|
||||
default:
|
||||
return KResult(-ENOPROTOOPT);
|
||||
}
|
||||
}
|
||||
|
||||
KResult IPv4Socket::getsockopt(int level, int option, void* value, socklen_t* value_size)
|
||||
{
|
||||
if (level != IPPROTO_IP)
|
||||
return Socket::getsockopt(level, option, value, value_size);
|
||||
|
||||
|
||||
switch (option) {
|
||||
case IP_TTL:
|
||||
if (*value_size < sizeof(int))
|
||||
return KResult(-EINVAL);
|
||||
*(int*)value = m_ttl;
|
||||
return KSuccess;
|
||||
default:
|
||||
return KResult(-ENOPROTOOPT);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue