Ver Fonte

Kernel: Add update option to remove an entry from the ARP table

Allows for specifying whether to set/delete an entry from the table.
brapru há 4 anos atrás
pai
commit
f8c104aaaf
3 ficheiros alterados com 13 adições e 5 exclusões
  1. 2 2
      Kernel/Net/NetworkTask.cpp
  2. 5 2
      Kernel/Net/Routing.cpp
  3. 6 1
      Kernel/Net/Routing.h

+ 2 - 2
Kernel/Net/NetworkTask.cpp

@@ -151,7 +151,7 @@ void handle_arp(const EthernetFrameHeader& eth, size_t frame_size)
         // Someone has this IPv4 address. I guess we can try to remember that.
         // Someone has this IPv4 address. I guess we can try to remember that.
         // FIXME: Protect against ARP spamming.
         // FIXME: Protect against ARP spamming.
         // FIXME: Support static ARP table entries.
         // FIXME: Support static ARP table entries.
-        update_arp_table(packet.sender_protocol_address(), packet.sender_hardware_address());
+        update_arp_table(packet.sender_protocol_address(), packet.sender_hardware_address(), UpdateArp::Set);
     }
     }
 
 
     if (packet.operation() == ARPOperation::Request) {
     if (packet.operation() == ARPOperation::Request) {
@@ -199,7 +199,7 @@ void handle_ipv4(const EthernetFrameHeader& eth, size_t frame_size, const Time&
             auto my_net = adapter.ipv4_address().to_u32() & adapter.ipv4_netmask().to_u32();
             auto my_net = adapter.ipv4_address().to_u32() & adapter.ipv4_netmask().to_u32();
             auto their_net = packet.source().to_u32() & adapter.ipv4_netmask().to_u32();
             auto their_net = packet.source().to_u32() & adapter.ipv4_netmask().to_u32();
             if (my_net == their_net)
             if (my_net == their_net)
-                update_arp_table(packet.source(), eth.source());
+                update_arp_table(packet.source(), eth.source(), UpdateArp::Set);
         }
         }
     });
     });
 
 

+ 5 - 2
Kernel/Net/Routing.cpp

@@ -104,10 +104,13 @@ Lockable<HashMap<IPv4Address, MACAddress>>& arp_table()
     return *s_arp_table;
     return *s_arp_table;
 }
 }
 
 
-void update_arp_table(const IPv4Address& ip_addr, const MACAddress& addr)
+void update_arp_table(const IPv4Address& ip_addr, const MACAddress& addr, UpdateArp update)
 {
 {
     MutexLocker locker(arp_table().lock());
     MutexLocker locker(arp_table().lock());
-    arp_table().resource().set(ip_addr, addr);
+    if (update == UpdateArp::Set)
+        arp_table().resource().set(ip_addr, addr);
+    if (update == UpdateArp::Delete)
+        arp_table().resource().remove(ip_addr);
     s_arp_table_block_condition->unblock(ip_addr, addr);
     s_arp_table_block_condition->unblock(ip_addr, addr);
 
 
     if constexpr (ROUTING_DEBUG) {
     if constexpr (ROUTING_DEBUG) {

+ 6 - 1
Kernel/Net/Routing.h

@@ -18,7 +18,12 @@ struct RoutingDecision {
     bool is_zero() const;
     bool is_zero() const;
 };
 };
 
 
-void update_arp_table(const IPv4Address&, const MACAddress&);
+enum class UpdateArp {
+    Set,
+    Delete,
+};
+
+void update_arp_table(const IPv4Address&, const MACAddress&, UpdateArp update);
 RoutingDecision route_to(const IPv4Address& target, const IPv4Address& source, const RefPtr<NetworkAdapter> through = nullptr);
 RoutingDecision route_to(const IPv4Address& target, const IPv4Address& source, const RefPtr<NetworkAdapter> through = nullptr);
 
 
 Lockable<HashMap<IPv4Address, MACAddress>>& arp_table();
 Lockable<HashMap<IPv4Address, MACAddress>>& arp_table();