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;
}
m_arp_table.clear();
// Wait for read thread to exit.
if (m_read_thread.joinable())
m_read_thread.join();
@ -206,7 +208,8 @@ void CEXIETHERNET::BuiltInBBAInterface::HandleARP(const Common::ARPPacket& packe
}
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());
@ -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));
}
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)
{
std::lock_guard<std::mutex> lock(m_mtx);

View File

@ -4,6 +4,8 @@
#pragma once
#include <atomic>
#include <map>
#include <mutex>
#include <thread>
#include <vector>
@ -13,7 +15,6 @@
#include <SFML/Network.hpp>
#include <mutex>
#include "Common/Flag.h"
#include "Common/Network.h"
#include "Core/HW/EXI/BBA/BuiltIn.h"
@ -445,6 +446,7 @@ private:
std::string m_local_ip;
u32 m_current_ip = 0;
u32 m_router_ip = 0;
std::map<u32, Common::MACAddress> m_arp_table;
#if defined(WIN32) || defined(__linux__) || defined(__APPLE__) || defined(__FreeBSD__) || \
defined(__OpenBSD__) || defined(__NetBSD__) || defined(__HAIKU__)
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 InitUDPPort(u16 port);
void HandleUDPFrame(const Common::UDPPacket& packet);
const Common::MACAddress& ResolveAddress(u32 inet_ip);
};
std::unique_ptr<NetworkInterface> m_network_interface;