mirror of https://github.com/PCSX2/pcsx2.git
DEV9: Move reconfiguration code into net.cpp
Also make the internal server aware of the reconfiguration
This commit is contained in:
parent
36406e2fd9
commit
221a8dc530
|
@ -1090,26 +1090,10 @@ void ApplyConfigIfRunning(Config oldConfig)
|
|||
return;
|
||||
|
||||
//Eth
|
||||
if (config.ethEnable)
|
||||
{
|
||||
if (oldConfig.ethEnable)
|
||||
{
|
||||
//Reload Net if adapter changed
|
||||
if (strcmp(oldConfig.Eth, config.Eth) != 0 ||
|
||||
oldConfig.EthApi != config.EthApi)
|
||||
{
|
||||
TermNet();
|
||||
InitNet();
|
||||
}
|
||||
}
|
||||
else
|
||||
InitNet();
|
||||
}
|
||||
else if (oldConfig.ethEnable)
|
||||
TermNet();
|
||||
ReconfigureLiveNet(&oldConfig);
|
||||
|
||||
//Hdd
|
||||
//Hdd Validate Path
|
||||
//Hdd
|
||||
//Hdd Validate Path
|
||||
#ifdef _WIN32
|
||||
ghc::filesystem::path hddPath(std::wstring(config.Hdd));
|
||||
#else
|
||||
|
|
|
@ -56,7 +56,7 @@ bool rx_fifo_can_rx();
|
|||
#define HDD_MIN_GB 8
|
||||
#define HDD_MAX_GB 120
|
||||
|
||||
typedef struct
|
||||
struct Config
|
||||
{
|
||||
char Eth[256];
|
||||
NetApi EthApi;
|
||||
|
@ -69,7 +69,7 @@ typedef struct
|
|||
|
||||
int hddEnable;
|
||||
int ethEnable;
|
||||
} Config;
|
||||
};
|
||||
|
||||
EXTERN Config config;
|
||||
|
||||
|
|
|
@ -665,6 +665,17 @@ bool TAPAdapter::send(NetPacket* pkt)
|
|||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void TAPAdapter::reloadSettings()
|
||||
{
|
||||
IP_ADAPTER_ADDRESSES adapter;
|
||||
std::unique_ptr<IP_ADAPTER_ADDRESSES[]> buffer;
|
||||
if (TAPGetWin32Adapter(config.Eth, &adapter, &buffer))
|
||||
ReloadInternalServer(&adapter);
|
||||
else
|
||||
ReloadInternalServer(nullptr);
|
||||
}
|
||||
|
||||
void TAPAdapter::close()
|
||||
{
|
||||
SetEvent(cancel);
|
||||
|
|
|
@ -34,6 +34,7 @@ public:
|
|||
virtual bool recv(NetPacket* pkt);
|
||||
//sends the packet and deletes it when done (if successful).rv :true success
|
||||
virtual bool send(NetPacket* pkt);
|
||||
virtual void reloadSettings();
|
||||
virtual void close();
|
||||
virtual ~TAPAdapter();
|
||||
static std::vector<AdapterEntry> GetAdapters();
|
||||
|
|
|
@ -121,6 +121,31 @@ void InitNet()
|
|||
#endif
|
||||
}
|
||||
|
||||
void ReconfigureLiveNet(Config* oldConfig)
|
||||
{
|
||||
//Eth
|
||||
if (config.ethEnable)
|
||||
{
|
||||
if (oldConfig->ethEnable)
|
||||
{
|
||||
//Reload Net if adapter changed
|
||||
if (strcmp(oldConfig->Eth, config.Eth) != 0 ||
|
||||
oldConfig->EthApi != config.EthApi)
|
||||
{
|
||||
TermNet();
|
||||
InitNet();
|
||||
return;
|
||||
}
|
||||
else
|
||||
nif->reloadSettings();
|
||||
}
|
||||
else
|
||||
InitNet();
|
||||
}
|
||||
else if (oldConfig->ethEnable)
|
||||
TermNet();
|
||||
}
|
||||
|
||||
void TermNet()
|
||||
{
|
||||
if (RxRunning)
|
||||
|
@ -257,6 +282,16 @@ void NetAdapter::InitInternalServer(ifaddrs* adapter)
|
|||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
void NetAdapter::ReloadInternalServer(PIP_ADAPTER_ADDRESSES adapter)
|
||||
#elif defined(__POSIX__)
|
||||
void NetAdapter::ReloadInternalServer(ifaddrs* adapter)
|
||||
#endif
|
||||
{
|
||||
if (adapter == nullptr)
|
||||
Console.Error("DEV9: ReloadInternalServer() got nullptr for adapter");
|
||||
}
|
||||
|
||||
bool NetAdapter::InternalServerRecv(NetPacket* pkt)
|
||||
{
|
||||
return false;
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
|
||||
#include "PacketReader/IP/IP_Address.h"
|
||||
|
||||
struct Config;
|
||||
|
||||
// first three recognized by Xlink as Sony PS2
|
||||
const u8 defaultMAC[6] = {0x00, 0x04, 0x1F, 0x82, 0x30, 0x31};
|
||||
|
||||
|
@ -97,6 +99,7 @@ public:
|
|||
virtual bool isInitialised() = 0;
|
||||
virtual bool recv(NetPacket* pkt); //gets a packet
|
||||
virtual bool send(NetPacket* pkt); //sends the packet and deletes it when done
|
||||
virtual void reloadSettings() = 0;
|
||||
virtual void close(){};
|
||||
virtual ~NetAdapter();
|
||||
|
||||
|
@ -106,8 +109,10 @@ protected:
|
|||
|
||||
#ifdef _WIN32
|
||||
void InitInternalServer(PIP_ADAPTER_ADDRESSES adapter);
|
||||
void ReloadInternalServer(PIP_ADAPTER_ADDRESSES adapter);
|
||||
#elif defined(__POSIX__)
|
||||
void InitInternalServer(ifaddrs* adapter);
|
||||
void ReloadInternalServer(ifaddrs* adapter);
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
@ -120,6 +125,7 @@ private:
|
|||
|
||||
void tx_put(NetPacket* ptr);
|
||||
void InitNet();
|
||||
void ReconfigureLiveNet(Config* oldConfig);
|
||||
void TermNet();
|
||||
|
||||
const char* NetApiToString(NetApi api);
|
||||
|
|
|
@ -427,6 +427,29 @@ bool PCAPAdapter::send(NetPacket* pkt)
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
void PCAPAdapter::reloadSettings()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
IP_ADAPTER_ADDRESSES adapter;
|
||||
std::unique_ptr<IP_ADAPTER_ADDRESSES[]> buffer;
|
||||
if (PCAPGetWin32Adapter(config.Eth, &adapter, &buffer))
|
||||
ReloadInternalServer(&adapter);
|
||||
else
|
||||
ReloadInternalServer(nullptr);
|
||||
#elif defined(__POSIX__)
|
||||
ifaddrs adapter;
|
||||
ifaddrs* buffer;
|
||||
if (PCAPGetIfAdapter(config.Eth, &adapter, &buffer))
|
||||
{
|
||||
ReloadInternalServer(&adapter);
|
||||
freeifaddrs(buffer);
|
||||
}
|
||||
else
|
||||
ReloadInternalServer(nullptr);
|
||||
#endif
|
||||
}
|
||||
|
||||
PCAPAdapter::~PCAPAdapter()
|
||||
{
|
||||
pcap_io_close();
|
||||
|
|
|
@ -181,6 +181,7 @@ public:
|
|||
virtual bool recv(NetPacket* pkt);
|
||||
//sends the packet and deletes it when done (if successful).rv :true success
|
||||
virtual bool send(NetPacket* pkt);
|
||||
virtual void reloadSettings();
|
||||
virtual ~PCAPAdapter();
|
||||
static std::vector<AdapterEntry> GetAdapters();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue