Implement promiscuous (dumb) mode by binding port on outgoing socket

This mode is useful for services which cannot handle multiple clients.
Also useful for NAT traversal.

All outgoing packets would be transmitted from a single "client" (UDP port).
Moreover, only one (latest) proxy client receives the reply.
This commit is contained in:
ValdikSS
2017-04-13 00:59:14 +03:00
parent 1f8f9b591b
commit b750cefb00
3 changed files with 21 additions and 12 deletions

6
net.c
View File

@@ -185,7 +185,7 @@ int drop_privileges(char *user, char *chrootdir) {
return 0;
}
int start_listener (char *inip, char *inpt, char *srcip, char *dstip,
int start_listener (char *inip, char *inpt, char *srcip, char *srcpt, char *dstip,
char *dstpt, char *pidfile, char *chrootdir, char *user) {
host_t *listen_h, *dst_h, *bind_h;
@@ -208,7 +208,7 @@ int start_listener (char *inip, char *inpt, char *srcip, char *dstip,
bind_h = NULL;
if(srcip != NULL) {
bind_h = get_host(srcip, 0, NULL, NULL);
bind_h = get_host(srcip, atoi(srcpt), NULL, NULL);
}
else {
if(dst_h->is_v6)
@@ -298,6 +298,8 @@ void handle_inside(int inside, host_t *listen_h, host_t *bind_h, host_t *dst_h)
src_h->ip, src_h->port, len, dst_h->ip, dst_h->port);
verb_prbind(bind_h);
if (bind_h->port)
client_clean(1);
output = bindsocket(bind_h);
if (output >= 0) {
/* send req out */