Skip to content

Commit

Permalink
Forward ports using PORT_FORWARDING environment variable
Browse files Browse the repository at this point in the history
  • Loading branch information
mafik committed Sep 5, 2024
1 parent 7023a5f commit 0b54e02
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/firewall.cc
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,23 @@ void Start(Status &status) {
sa.sa_handler = sig_handler;
sigaction(SIGUSR1, &sa, nullptr);

if (char *port_forwarding = getenv("PORT_FORWARDING")) {
while (true) {
int pos;
IP ip;
U16 port;
int toks =
sscanf(port_forwarding, "%hhu.%hhu.%hhu.%hhu:%hu%n", &ip.bytes[0],
&ip.bytes[1], &ip.bytes[2], &ip.bytes[3], &port, &pos);
if (toks != 6) {
break;
}
port_forwarding += pos;
FullConeNAT::Lookup(ProtocolID::TCP, port).lan_host_ip = ip;
FullConeNAT::Lookup(ProtocolID::UDP, port).lan_host_ip = ip;
}
}

loop = std::thread(Loop);
}

Expand Down

0 comments on commit 0b54e02

Please sign in to comment.