tab => spc, year++

This commit is contained in:
TLINDEN
2016-09-22 21:37:30 +02:00
parent 479f954986
commit 019c055e56
13 changed files with 86 additions and 86 deletions

View File

@@ -1,7 +1,7 @@
# #
# This file is part of udpxd. # This file is part of udpxd.
# #
# Copyright (C) 2015 T.v.Dein. # Copyright (C) 2015-2016 T.v.Dein.
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of udpxd. This file is part of udpxd.
Copyright (C) 2015 T.v.Dein. Copyright (C) 2015-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -74,7 +74,7 @@ void client_clean(int asap) {
diff = now - current->lastseen; diff = now - current->lastseen;
if(diff >= MAXAGE || asap) { if(diff >= MAXAGE || asap) {
verbose("closing socket %s:%d for client %s:%d (aged out after %d seconds)\n", verbose("closing socket %s:%d for client %s:%d (aged out after %d seconds)\n",
current->src->ip, current->src->port, current->dst->ip, current->dst->port, MAXAGE); current->src->ip, current->src->port, current->dst->ip, current->dst->port, MAXAGE);
client_close(current); client_close(current);
} }
} }

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of udpxd. This file is part of udpxd.
Copyright (C) 2015 T.v.Dein. Copyright (C) 2015-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by

14
host.c
View File

@@ -1,7 +1,7 @@
/* /*
This file is part of udpxd. This file is part of udpxd.
Copyright (C) 2015 T.v.Dein. Copyright (C) 2015-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -43,20 +43,20 @@ host_t *get_host(char *ip, int port, struct sockaddr_in *v4, struct sockaddr_in6
unsigned int scope = get_v6_scope(ip); unsigned int scope = get_v6_scope(ip);
if (is_linklocal((struct in6_addr*)&tmp->sin6_addr)) if (is_linklocal((struct in6_addr*)&tmp->sin6_addr))
tmp->sin6_scope_id = scope; tmp->sin6_scope_id = scope;
else else
tmp->sin6_scope_id = 0; tmp->sin6_scope_id = 0;
host->is_v6 = 1; host->is_v6 = 1;
host->sock = (struct sockaddr*)tmp; host->sock = (struct sockaddr*)tmp;
host->size = sizeof(struct sockaddr_in6); host->size = sizeof(struct sockaddr_in6);
if(tmp->sin6_scope_id != 0) { if(tmp->sin6_scope_id != 0) {
host->ip = malloc(INET6_ADDRSTRLEN + 9); /* plus [ % ] \0 , scope*/ host->ip = malloc(INET6_ADDRSTRLEN + 9); /* plus [ % ] \0 , scope*/
sprintf(host->ip, "[%s%%%d]", ip, scope); sprintf(host->ip, "[%s%%%d]", ip, scope);
} }
else { else {
host->ip = malloc(INET6_ADDRSTRLEN + 3); /* plus [ ] \0 */ host->ip = malloc(INET6_ADDRSTRLEN + 3); /* plus [ ] \0 */
sprintf(host->ip, "[%s]", ip); sprintf(host->ip, "[%s]", ip);
} }
} }
else { else {

2
host.h
View File

@@ -1,7 +1,7 @@
/* /*
This file is part of udpxd. This file is part of udpxd.
Copyright (C) 2015 T.v.Dein. Copyright (C) 2015-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by

6
log.c
View File

@@ -1,7 +1,7 @@
/* /*
This file is part of udpxd. This file is part of udpxd.
Copyright (C) 2015 T.v.Dein. Copyright (C) 2015-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -33,10 +33,10 @@ void verbose(const char * fmt, ...) {
va_end(ap); va_end(ap);
if(FORKED) { if(FORKED) {
syslog(LOG_INFO, "%s", msg); syslog(LOG_INFO, "%s", msg);
} }
else { else {
fprintf(stderr, "%s", msg); fprintf(stderr, "%s", msg);
} }
} }
else { else {

2
log.h
View File

@@ -1,7 +1,7 @@
/* /*
This file is part of udpxd. This file is part of udpxd.
Copyright (C) 2015 T.v.Dein. Copyright (C) 2015-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by

80
net.c
View File

@@ -1,7 +1,7 @@
/* /*
This file is part of udpxd. This file is part of udpxd.
Copyright (C) 2015 T.v.Dein. Copyright (C) 2015-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -34,7 +34,7 @@ int fill_set(fd_set *fds) {
client_iter(clients, current) { client_iter(clients, current) {
if (current->socket < (int)FD_SETSIZE) { if (current->socket < (int)FD_SETSIZE) {
if (current->socket > max) if (current->socket > max)
max = current->socket; max = current->socket;
FD_SET(current->socket, fds); FD_SET(current->socket, fds);
} }
else { else {
@@ -104,12 +104,12 @@ int daemonize(char *pidfile) {
if (pid > 0) { if (pid > 0) {
/* leave parent */ /* leave parent */
if((fd = fopen(pidfile, "w")) == NULL) { if((fd = fopen(pidfile, "w")) == NULL) {
perror("failed to write pidfile"); perror("failed to write pidfile");
return -1; return -1;
} }
else { else {
fprintf(fd, "%d\n", pid); fprintf(fd, "%d\n", pid);
fclose(fd); fclose(fd);
} }
return 1; return 1;
} }
@@ -186,7 +186,7 @@ int drop_privileges(char *user, char *chrootdir) {
} }
int start_listener (char *inip, char *inpt, char *srcip, char *dstip, int start_listener (char *inip, char *inpt, char *srcip, char *dstip,
char *dstpt, char *pidfile, char *chrootdir, char *user) { char *dstpt, char *pidfile, char *chrootdir, char *user) {
host_t *listen_h, *dst_h, *bind_h; host_t *listen_h, *dst_h, *bind_h;
int dm = daemonize(pidfile); int dm = daemonize(pidfile);
@@ -224,7 +224,7 @@ int start_listener (char *inip, char *inpt, char *srcip, char *dstip,
if(VERBOSE) { if(VERBOSE) {
verbose("Listening on %s:%s, forwarding to %s:%s", verbose("Listening on %s:%s, forwarding to %s:%s",
listen_h->ip, inpt, dst_h->ip, dstpt); listen_h->ip, inpt, dst_h->ip, dstpt);
if(srcip != NULL) if(srcip != NULL)
verbose(", binding to %s\n", bind_h->ip); verbose(", binding to %s\n", bind_h->ip);
else else
@@ -266,7 +266,7 @@ void handle_inside(int inside, host_t *listen_h, host_t *bind_h, host_t *dst_h)
src = malloc(size); src = malloc(size);
len = recvfrom( inside, buffer, sizeof( buffer ), 0, len = recvfrom( inside, buffer, sizeof( buffer ), 0,
(struct sockaddr*)src, (socklen_t *)&size ); (struct sockaddr*)src, (socklen_t *)&size );
if(listen_h->is_v6) if(listen_h->is_v6)
src_h = get_host(NULL, 0, NULL, (struct sockaddr_in6 *)src); src_h = get_host(NULL, 0, NULL, (struct sockaddr_in6 *)src);
@@ -281,49 +281,49 @@ void handle_inside(int inside, host_t *listen_h, host_t *bind_h, host_t *dst_h)
if(client != NULL) { if(client != NULL) {
/* yes, we know it, send req out via existing bind socket */ /* yes, we know it, send req out via existing bind socket */
verbose("Client %s:%d is known, forwarding %d bytes to %s:%d ", verbose("Client %s:%d is known, forwarding %d bytes to %s:%d ",
src_h->ip, src_h->port, len, dst_h->ip, dst_h->port); src_h->ip, src_h->port, len, dst_h->ip, dst_h->port);
verb_prbind(bind_h); verb_prbind(bind_h);
if(sendto(client->socket, buffer, len, 0, (struct sockaddr*)dst_h->sock, dst_h->size) < 0) { if(sendto(client->socket, buffer, len, 0, (struct sockaddr*)dst_h->sock, dst_h->size) < 0) {
fprintf(stderr, "unable to forward to %s:%d\n", dst_h->ip, dst_h->port); fprintf(stderr, "unable to forward to %s:%d\n", dst_h->ip, dst_h->port);
perror(NULL); perror(NULL);
} }
else { else {
client_seen(client); client_seen(client);
} }
} }
else { else {
/* unknown client, open new out socket */ /* unknown client, open new out socket */
verbose("Client %s:%d is unknown, forwarding %d bytes to %s:%d ", verbose("Client %s:%d is unknown, forwarding %d bytes to %s:%d ",
src_h->ip, src_h->port, len, dst_h->ip, dst_h->port); src_h->ip, src_h->port, len, dst_h->ip, dst_h->port);
verb_prbind(bind_h); verb_prbind(bind_h);
output = bindsocket(bind_h); output = bindsocket(bind_h);
/* send req out */ /* send req out */
if(sendto(output, buffer, len, 0, (struct sockaddr*)dst_h->sock, dst_h->size) < 0) { if(sendto(output, buffer, len, 0, (struct sockaddr*)dst_h->sock, dst_h->size) < 0) {
fprintf(stderr, "unable to forward to %s:%d\n", dst_h->ip, dst_h->port); fprintf(stderr, "unable to forward to %s:%d\n", dst_h->ip, dst_h->port);
perror(NULL); perror(NULL);
} }
else { else {
size = listen_h->size; size = listen_h->size;
host_t *ret_h; host_t *ret_h;
if(listen_h->is_v6) { if(listen_h->is_v6) {
struct sockaddr_in6 *ret = malloc(size); struct sockaddr_in6 *ret = malloc(size);
getsockname(output, (struct sockaddr*)ret, (socklen_t *)&size); getsockname(output, (struct sockaddr*)ret, (socklen_t *)&size);
ret_h = get_host(NULL, 0, NULL, ret); ret_h = get_host(NULL, 0, NULL, ret);
free(ret); free(ret);
client = client_new(output, src_h, ret_h); client = client_new(output, src_h, ret_h);
} }
else { else {
struct sockaddr_in *ret = malloc(size); struct sockaddr_in *ret = malloc(size);
getsockname(output, (struct sockaddr*)ret, (socklen_t *)&size); getsockname(output, (struct sockaddr*)ret, (socklen_t *)&size);
ret_h = get_host(NULL, 0, ret, NULL); ret_h = get_host(NULL, 0, ret, NULL);
free(ret); free(ret);
client = client_new(output, src_h, ret_h); client = client_new(output, src_h, ret_h);
} }
client_add(client); client_add(client);
} }
} }
} }
@@ -349,9 +349,9 @@ void handle_outside(int inside, int outside, host_t *outside_h) {
/* yes, we know it */ /* yes, we know it */
/* FIXME: check src vs. client->src ? */ /* FIXME: check src vs. client->src ? */
if(sendto(inside, buffer, len, 0, if(sendto(inside, buffer, len, 0,
(struct sockaddr*)client->src->sock, client->src->size) < 0) { (struct sockaddr*)client->src->sock, client->src->size) < 0) {
perror("unable to send back to client"); /* FIXME: add src+port */ perror("unable to send back to client"); /* FIXME: add src+port */
client_close(client); client_close(client);
} }
} }
else { else {
@@ -388,8 +388,8 @@ int main_loop(int listensocket, host_t *listen_h, host_t *bind_h, host_t *dst_h)
select(max + 1, &fds, NULL, NULL, NULL); select(max + 1, &fds, NULL, NULL, NULL);
if (FD_ISSET(listensocket, &fds)) { if (FD_ISSET(listensocket, &fds)) {
/* incoming client on the inside, get src, bind output fd, add to list /* incoming client on the inside, get src, bind output fd, add
if known, otherwise just handle it */ to list if known, otherwise just handle it */
handle_inside(listensocket, listen_h, bind_h, dst_h); handle_inside(listensocket, listen_h, bind_h, dst_h);
} }
else { else {

2
net.h
View File

@@ -1,7 +1,7 @@
/* /*
This file is part of udpxd. This file is part of udpxd.
Copyright (C) 2015 T.v.Dein. Copyright (C) 2015-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by

View File

@@ -124,7 +124,7 @@
.\" ======================================================================== .\" ========================================================================
.\" .\"
.IX Title "UDPXD 1" .IX Title "UDPXD 1"
.TH UDPXD 1 "2015-04-27" "perl v5.14.2" "User Contributed Perl Documentation" .TH UDPXD 1 "2015-2016-04-27" "perl v5.14.2" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents. .\" way too many mistakes in technical documents.
.if n .ad l .if n .ad l
@@ -280,7 +280,7 @@ or to submit a patch, please open an issue on github:
.IX Header "LICENSE" .IX Header "LICENSE"
This software is licensed under the \s-1GNU\s0 \s-1GENERAL\s0 \s-1PUBLIC\s0 \s-1LICENSE\s0 version 3. This software is licensed under the \s-1GNU\s0 \s-1GENERAL\s0 \s-1PUBLIC\s0 \s-1LICENSE\s0 version 3.
.PP .PP
Copyright (c) 2015 by T. v. Dein. Copyright (c) 2015-2016 by T. v. Dein.
.PP .PP
This software uses \fButhash\fR (bundled), which is This software uses \fButhash\fR (bundled), which is
Copyright (c) 2003\-2013 by Troy D. Hanson. Copyright (c) 2003\-2013 by Troy D. Hanson.

48
udpxd.c
View File

@@ -1,7 +1,7 @@
/* /*
This file is part of udpxd. This file is part of udpxd.
Copyright (C) 2015 T.v.Dein. Copyright (C) 2015-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by
@@ -71,8 +71,8 @@ int parse_ip(char *src, char *ip, char *pt) {
} }
else { else {
if(atoi(ptr) > 65535) { if(atoi(ptr) > 65535) {
fprintf(stderr, "maximum port number possible: 65535!\n"); fprintf(stderr, "maximum port number possible: 65535!\n");
return 1; return 1;
} }
strncpy(pt, ptr, strlen(ptr)+1); strncpy(pt, ptr, strlen(ptr)+1);
} }
@@ -89,21 +89,21 @@ int parse_ip(char *src, char *ip, char *pt) {
void usage() { void usage() {
fprintf(stderr, fprintf(stderr,
"Usage: udpxd [-lbdfpvhV]\n\n" "Usage: udpxd [-lbdfpvhV]\n\n"
"Options:\n" "Options:\n"
"--listen -l <ip:port> listen for incoming requests\n" "--listen -l <ip:port> listen for incoming requests\n"
"--bind -b <ip> bind ip used for outgoing requests\n" "--bind -b <ip> bind ip used for outgoing requests\n"
"--to -t <ip:port> destination to forward requests to\n" "--to -t <ip:port> destination to forward requests to\n"
"--daemon -d daemon mode, fork into background\n" "--daemon -d daemon mode, fork into background\n"
"--pidfile -p <file> pidfile, default: /var/run/udpxd.pid\n" "--pidfile -p <file> pidfile, default: /var/run/udpxd.pid\n"
"--user -u <user> run as user (only in daemon mode)\n" "--user -u <user> run as user (only in daemon mode)\n"
"--chroot -c <path> chroot to <path> (only in daemon mode)\n" "--chroot -c <path> chroot to <path> (only in daemon mode)\n"
"--help -h -? print help message\n" "--help -h -? print help message\n"
"--version -V print program version\n" "--version -V print program version\n"
"--verbose -v enable verbose logging\n\n" "--verbose -v enable verbose logging\n\n"
"Options -l and -t are mandatory.\n\n" "Options -l and -t are mandatory.\n\n"
"This is udpxd version %s.\n", UDPXD_VERSION "This is udpxd version %s.\n", UDPXD_VERSION
); );
} }
@@ -163,22 +163,22 @@ int main ( int argc, char* argv[] ) {
inip = malloc(INET6_ADDRSTRLEN+1); inip = malloc(INET6_ADDRSTRLEN+1);
inpt = malloc(6); inpt = malloc(6);
if (parse_ip(optarg, inip, inpt) != 0) { if (parse_ip(optarg, inip, inpt) != 0) {
fprintf(stderr, "Parameter -l has the format <ip-address:port>!\n"); fprintf(stderr, "Parameter -l has the format <ip-address:port>!\n");
err = 1; err = 1;
} }
break; break;
case 't': case 't':
dstip = malloc(INET6_ADDRSTRLEN+1); dstip = malloc(INET6_ADDRSTRLEN+1);
dstpt = malloc(6); dstpt = malloc(6);
if (parse_ip(optarg, dstip, dstpt) != 0) { if (parse_ip(optarg, dstip, dstpt) != 0) {
fprintf(stderr, "Parameter -d has the format <ip-address:port>!\n"); fprintf(stderr, "Parameter -d has the format <ip-address:port>!\n");
err = 1; err = 1;
} }
break; break;
case 'b': case 'b':
if(strlen(optarg) > INET6_ADDRSTRLEN) { if(strlen(optarg) > INET6_ADDRSTRLEN) {
fprintf(stderr, "Bind ip address is too long!\n"); fprintf(stderr, "Bind ip address is too long!\n");
err = 1; err = 1;
} }
srcip = malloc(INET6_ADDRSTRLEN+1); srcip = malloc(INET6_ADDRSTRLEN+1);
strncpy(srcip, optarg, strlen(optarg)); strncpy(srcip, optarg, strlen(optarg));

View File

@@ -1,7 +1,7 @@
/* /*
This file is part of udpxd. This file is part of udpxd.
Copyright (C) 2015 T.v.Dein. Copyright (C) 2015-2016 T.v.Dein.
This program is free software: you can redistribute it and/or modify This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by it under the terms of the GNU General Public License as published by

View File

@@ -140,7 +140,7 @@ L<https://github.com/TLINDEN/udpxd/issues>.
This software is licensed under the GNU GENERAL PUBLIC LICENSE version 3. This software is licensed under the GNU GENERAL PUBLIC LICENSE version 3.
Copyright (c) 2015 by T. v. Dein. Copyright (c) 2015-2016 by T. v. Dein.
This software uses B<uthash> (bundled), which is This software uses B<uthash> (bundled), which is
Copyright (c) 2003-2013 by Troy D. Hanson. Copyright (c) 2003-2013 by Troy D. Hanson.