mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-09 22:56:35 +00:00
dns.mitm: make line ordering explicit, rather than implicit.
This doesn't actually change functionality, because this is how std::unordered_map worked anyway... ...but it's better for us to be explicit, I think.
This commit is contained in:
parent
408b81b881
commit
bcda834980
2 changed files with 22 additions and 6 deletions
|
@ -11,6 +11,8 @@ In particular, hosts files parsed by DNS.mitm have the following extensions to t
|
||||||
+ `*` is treated as a wildcard character, matching any collection of 0 or more characters wherever it occurs in a hostname.
|
+ `*` is treated as a wildcard character, matching any collection of 0 or more characters wherever it occurs in a hostname.
|
||||||
+ `%` is treated as a stand-in for the value of `nsd!environment_identifier`. This is always `lp1`, on production devices.
|
+ `%` is treated as a stand-in for the value of `nsd!environment_identifier`. This is always `lp1`, on production devices.
|
||||||
|
|
||||||
|
If multiple entries in a host file match a domain, the last-defined match is used.
|
||||||
|
|
||||||
Please note that homebrew may trigger a hosts file re-parse by sending the extension IPC command 65000 ("AtmosphereReloadHostsFile") to a connected `sfdnsres` session.
|
Please note that homebrew may trigger a hosts file re-parse by sending the extension IPC command 65000 ("AtmosphereReloadHostsFile") to a connected `sfdnsres` session.
|
||||||
|
|
||||||
### Hosts file selection
|
### Hosts file selection
|
||||||
|
|
|
@ -69,7 +69,21 @@ namespace ams::mitm::socket::resolver {
|
||||||
"127.0.0.1 receive-%.dg.srv.nintendo.net receive-%.er.srv.nintendo.net\n";
|
"127.0.0.1 receive-%.dg.srv.nintendo.net receive-%.er.srv.nintendo.net\n";
|
||||||
|
|
||||||
constinit os::SdkMutex g_redirection_lock;
|
constinit os::SdkMutex g_redirection_lock;
|
||||||
std::unordered_map<std::string, ams::socket::InAddrT> g_redirection_map;
|
std::vector<std::pair<std::string, ams::socket::InAddrT>> g_redirection_list;
|
||||||
|
|
||||||
|
void RemoveRedirection(const char *hostname) {
|
||||||
|
for (auto it = g_redirection_list.begin(); it != g_redirection_list.end(); ++it) {
|
||||||
|
if (std::strcmp(it->first.c_str(), hostname) == 0) {
|
||||||
|
g_redirection_list.erase(it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddRedirection(const char *hostname, ams::socket::InAddrT addr) {
|
||||||
|
RemoveRedirection(hostname);
|
||||||
|
g_redirection_list.emplace(g_redirection_list.begin(), std::string(hostname), addr);
|
||||||
|
}
|
||||||
|
|
||||||
constinit char g_specific_emummc_hosts_path[0x40] = {};
|
constinit char g_specific_emummc_hosts_path[0x40] = {};
|
||||||
|
|
||||||
|
@ -206,7 +220,7 @@ namespace ams::mitm::socket::resolver {
|
||||||
AMS_ABORT_UNLESS(work < sizeof(current_hostname));
|
AMS_ABORT_UNLESS(work < sizeof(current_hostname));
|
||||||
current_hostname[work] = '\x00';
|
current_hostname[work] = '\x00';
|
||||||
|
|
||||||
g_redirection_map[static_cast<const char *>(current_hostname)] = current_address;
|
AddRedirection(current_hostname, current_address);
|
||||||
work = 0;
|
work = 0;
|
||||||
|
|
||||||
if (c == '\n') {
|
if (c == '\n') {
|
||||||
|
@ -229,7 +243,7 @@ namespace ams::mitm::socket::resolver {
|
||||||
AMS_ABORT_UNLESS(work < sizeof(current_hostname));
|
AMS_ABORT_UNLESS(work < sizeof(current_hostname));
|
||||||
current_hostname[work] = '\x00';
|
current_hostname[work] = '\x00';
|
||||||
|
|
||||||
g_redirection_map[static_cast<const char *>(current_hostname)] = current_address;
|
AddRedirection(current_hostname, current_address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -293,7 +307,7 @@ namespace ams::mitm::socket::resolver {
|
||||||
std::scoped_lock lk(g_redirection_lock);
|
std::scoped_lock lk(g_redirection_lock);
|
||||||
|
|
||||||
/* Clear the redirections map. */
|
/* Clear the redirections map. */
|
||||||
g_redirection_map.clear();
|
g_redirection_list.clear();
|
||||||
|
|
||||||
/* Open log file. */
|
/* Open log file. */
|
||||||
::FsFile log_file;
|
::FsFile log_file;
|
||||||
|
@ -362,7 +376,7 @@ namespace ams::mitm::socket::resolver {
|
||||||
|
|
||||||
/* Print the redirections. */
|
/* Print the redirections. */
|
||||||
Log(log_file, "Redirections:\n");
|
Log(log_file, "Redirections:\n");
|
||||||
for (const auto &[host, address] : g_redirection_map) {
|
for (const auto &[host, address] : g_redirection_list) {
|
||||||
Log(log_file, " `%s` -> %u.%u.%u.%u\n", host.c_str(), (address >> 0) & 0xFF, (address >> 8) & 0xFF, (address >> 16) & 0xFF, (address >> 24) & 0xFF);
|
Log(log_file, " `%s` -> %u.%u.%u.%u\n", host.c_str(), (address >> 0) & 0xFF, (address >> 8) & 0xFF, (address >> 16) & 0xFF, (address >> 24) & 0xFF);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -370,7 +384,7 @@ namespace ams::mitm::socket::resolver {
|
||||||
bool GetRedirectedHostByName(ams::socket::InAddrT *out, const char *hostname) {
|
bool GetRedirectedHostByName(ams::socket::InAddrT *out, const char *hostname) {
|
||||||
std::scoped_lock lk(g_redirection_lock);
|
std::scoped_lock lk(g_redirection_lock);
|
||||||
|
|
||||||
for (const auto &[host, address] : g_redirection_map) {
|
for (const auto &[host, address] : g_redirection_list) {
|
||||||
if (wildcardcmp(host.c_str(), hostname)) {
|
if (wildcardcmp(host.c_str(), hostname)) {
|
||||||
*out = address;
|
*out = address;
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in a new issue