diff options
author | Gunnar Beutner <gbeutner@serenityos.org> | 2021-04-26 15:38:26 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-04-26 18:39:59 +0200 |
commit | a85d111cd16e2129a6d6324d6f66b971f353b930 (patch) | |
tree | 71c6153dd2f950aec2888d08c9fd2a3669c605d2 | |
parent | ba9a285d56ec364e3e5b63e2f3c1e7677bfaa738 (diff) | |
download | serenity-a85d111cd16e2129a6d6324d6f66b971f353b930.zip |
Kernel: Respond to packets sent to the directed broadcast address
The last IP address in an IPv4 subnet is considered the directed
broadcast address, e.g. for 192.168.3.0/24 the directed broadcast
address is 192.168.3.255. We need to consider this address as
belonging to the interface.
Here's an example with this fix applied, SerenityOS has 192.168.3.190:
[gunnar@nyx ~]$ ping -b 192.168.3.255
WARNING: pinging broadcast address
PING 192.168.3.255 (192.168.3.255) 56(84) bytes of data.
64 bytes from 192.168.3.175: icmp_seq=1 ttl=64 time=0.950 ms
64 bytes from 192.168.3.188: icmp_seq=1 ttl=64 time=2.33 ms
64 bytes from 192.168.3.46: icmp_seq=1 ttl=64 time=2.77 ms
64 bytes from 192.168.3.41: icmp_seq=1 ttl=64 time=4.15 ms
64 bytes from 192.168.3.190: icmp_seq=1 ttl=64 time=29.4 ms
64 bytes from 192.168.3.42: icmp_seq=1 ttl=64 time=30.8 ms
64 bytes from 192.168.3.55: icmp_seq=1 ttl=64 time=31.0 ms
64 bytes from 192.168.3.30: icmp_seq=1 ttl=64 time=33.2 ms
64 bytes from 192.168.3.31: icmp_seq=1 ttl=64 time=33.2 ms
64 bytes from 192.168.3.173: icmp_seq=1 ttl=64 time=41.7 ms
64 bytes from 192.168.3.43: icmp_seq=1 ttl=64 time=47.7 ms
^C
--- 192.168.3.255 ping statistics ---
1 packets transmitted, 1 received, +10 duplicates, 0% packet loss,
time 0ms, rtt min/avg/max/mdev = 0.950/23.376/47.676/16.539 ms
[gunnar@nyx ~]$
-rw-r--r-- | Kernel/Net/NetworkAdapter.cpp | 2 | ||||
-rw-r--r-- | Kernel/Net/NetworkAdapter.h | 1 |
2 files changed, 2 insertions, 1 deletions
diff --git a/Kernel/Net/NetworkAdapter.cpp b/Kernel/Net/NetworkAdapter.cpp index 658c694a67..07b3e911b9 100644 --- a/Kernel/Net/NetworkAdapter.cpp +++ b/Kernel/Net/NetworkAdapter.cpp @@ -37,7 +37,7 @@ RefPtr<NetworkAdapter> NetworkAdapter::from_ipv4_address(const IPv4Address& addr { Locker locker(all_adapters().lock()); for (auto* adapter : all_adapters().resource()) { - if (adapter->ipv4_address() == address) + if (adapter->ipv4_address() == address || adapter->ipv4_broadcast() == address) return adapter; } if (address[0] == 127) diff --git a/Kernel/Net/NetworkAdapter.h b/Kernel/Net/NetworkAdapter.h index 2892dd34af..148ada3c87 100644 --- a/Kernel/Net/NetworkAdapter.h +++ b/Kernel/Net/NetworkAdapter.h @@ -36,6 +36,7 @@ public: MACAddress mac_address() { return m_mac_address; } IPv4Address ipv4_address() const { return m_ipv4_address; } IPv4Address ipv4_netmask() const { return m_ipv4_netmask; } + IPv4Address ipv4_broadcast() const { return IPv4Address { (m_ipv4_address.to_u32() & m_ipv4_netmask.to_u32()) | ~m_ipv4_netmask.to_u32() }; } IPv4Address ipv4_gateway() const { return m_ipv4_gateway; } virtual bool link_up() { return false; } |