BBA/BuiltIn: Add an ARP table

This commit is contained in:
Sepalani 2022-07-30 23:17:34 +04:00
parent fb45ed3981
commit ec60416c00
2 changed files with 23 additions and 2 deletions

View file

@ -174,6 +174,8 @@ void CEXIETHERNET::BuiltInBBAInterface::Deactivate()
ref.ip = 0; ref.ip = 0;
} }
m_arp_table.clear();
// Wait for read thread to exit. // Wait for read thread to exit.
if (m_read_thread.joinable()) if (m_read_thread.joinable())
m_read_thread.join(); m_read_thread.join();
@ -206,7 +208,8 @@ void CEXIETHERNET::BuiltInBBAInterface::HandleARP(const Common::ARPPacket& packe
} }
else else
{ {
response.arp_header = Common::ARPHeader(arpdata.target_ip, m_fake_mac, m_current_ip, bba_mac); response.arp_header = Common::ARPHeader(arpdata.target_ip, ResolveAddress(arpdata.target_ip),
m_current_ip, bba_mac);
} }
WriteToQueue(response.Build()); WriteToQueue(response.Build());
@ -488,6 +491,21 @@ void CEXIETHERNET::BuiltInBBAInterface::HandleUDPFrame(const Common::UDPPacket&
ref->udp_socket.send(data.data(), data.size(), target, ntohs(udp_header.destination_port)); ref->udp_socket.send(data.data(), data.size(), target, ntohs(udp_header.destination_port));
} }
const Common::MACAddress& CEXIETHERNET::BuiltInBBAInterface::ResolveAddress(u32 inet_ip)
{
auto it = m_arp_table.lower_bound(inet_ip);
if (it != m_arp_table.end() && it->first == inet_ip)
{
return it->second;
}
else
{
return m_arp_table
.emplace_hint(it, inet_ip, Common::GenerateMacAddress(Common::MACConsumer::BBA))
->second;
}
}
bool CEXIETHERNET::BuiltInBBAInterface::SendFrame(const u8* frame, u32 size) bool CEXIETHERNET::BuiltInBBAInterface::SendFrame(const u8* frame, u32 size)
{ {
std::lock_guard<std::mutex> lock(m_mtx); std::lock_guard<std::mutex> lock(m_mtx);

View file

@ -4,6 +4,8 @@
#pragma once #pragma once
#include <atomic> #include <atomic>
#include <map>
#include <mutex>
#include <thread> #include <thread>
#include <vector> #include <vector>
@ -13,7 +15,6 @@
#include <SFML/Network.hpp> #include <SFML/Network.hpp>
#include <mutex>
#include "Common/Flag.h" #include "Common/Flag.h"
#include "Common/Network.h" #include "Common/Network.h"
#include "Core/HW/EXI/BBA/BuiltIn.h" #include "Core/HW/EXI/BBA/BuiltIn.h"
@ -445,6 +446,7 @@ private:
std::string m_local_ip; std::string m_local_ip;
u32 m_current_ip = 0; u32 m_current_ip = 0;
u32 m_router_ip = 0; u32 m_router_ip = 0;
std::map<u32, Common::MACAddress> m_arp_table;
#if defined(WIN32) || defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \ #if defined(WIN32) || defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__) defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__)
std::array<StackRef, 10> network_ref{}; // max 10 at same time, i think most gc game had a std::array<StackRef, 10> network_ref{}; // max 10 at same time, i think most gc game had a
@ -464,6 +466,7 @@ private:
void HandleTCPFrame(const Common::TCPPacket& packet); void HandleTCPFrame(const Common::TCPPacket& packet);
void InitUDPPort(u16 port); void InitUDPPort(u16 port);
void HandleUDPFrame(const Common::UDPPacket& packet); void HandleUDPFrame(const Common::UDPPacket& packet);
const Common::MACAddress& ResolveAddress(u32 inet_ip);
}; };
std::unique_ptr<NetworkInterface> m_network_interface; std::unique_ptr<NetworkInterface> m_network_interface;