summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@spreadspace.org>2010-12-02 00:28:25 +0000
committerChristian Pointner <equinox@spreadspace.org>2010-12-02 00:28:25 +0000
commit90f403d1f554822be06564ea52498d710d2bf051 (patch)
treed7642107854c778f952bd2876578c627e744eb9e
parentbuffer size can now be configured (diff)
added new options for resolv types (IPv4 vs IPv6)
manpage: new parameters manpage: added short description to each parameter git-svn-id: https://svn.spreadspace.org/tcpproxy/trunk@19 e61f0598-a718-4e21-a8f0-0aadfa62ad6b
-rw-r--r--doc/tcpproxy.845
-rw-r--r--doc/tcpproxy.8.txt36
-rw-r--r--src/listener.c8
-rw-r--r--src/listener.h2
-rw-r--r--src/options.c68
-rw-r--r--src/options.h4
-rw-r--r--src/tcp.c5
-rw-r--r--src/tcpproxy.c2
8 files changed, 131 insertions, 39 deletions
diff --git a/doc/tcpproxy.8 b/doc/tcpproxy.8
index 6739750..d4bcb42 100644
--- a/doc/tcpproxy.8
+++ b/doc/tcpproxy.8
@@ -2,12 +2,12 @@
.\" Title: tcpproxy
.\" Author: [see the "AUTHORS" section]
.\" Generator: DocBook XSL Stylesheets v1.75.2 <http://docbook.sf.net/>
-.\" Date: 11/30/2010
+.\" Date: 12/02/2010
.\" Manual: \ \&
.\" Source: \ \&
.\" Language: English
.\"
-.TH "TCPPROXY" "8" "11/30/2010" "\ \&" "\ \&"
+.TH "TCPPROXY" "8" "12/02/2010" "\ \&" "\ \&"
.\" -----------------------------------------------------------------
.\" * Define some portability stuff
.\" -----------------------------------------------------------------
@@ -42,10 +42,13 @@ tcpproxy \- IPv4/IPv6 tcp connection proxy
[ \fB\-L|\-\-log\fR <target>:<level>[,<param1>[,<param2>[\&.\&.]]] ]
[ \fB\-U|\-\-debug\fR ]
[ \fB\-l|\-\-local\-addr\fR <host> ]
+ [ \fB\-t|\-\-local\-resolv\fR (ipv4|4|ipv6|6) ]
[ \fB\-p|\-\-local\-port\fR <service> ]
[ \fB\-r|\-\-remote\-addr\fR <host> ]
+ [ \fB\-R|\-\-remote\-resolv\fR (ipv4|4|ipv6|6) ]
[ \fB\-o|\-\-remote\-port\fR <service> ]
[ \fB\-s|\-\-source\-addr\fR <host> ]
+ [ \fB\-S|\-\-source\-resolv\fR (ipv4|4|ipv6|6) ]
[ \fB\-b|\-\-buffer\-size\fR <size> ]
[ \fB\-c|\-\-config\fR <file> ]
.fi
@@ -131,37 +134,61 @@ to run in debug mode\&. It implicits
.PP
\fB\-l, \-\-local\-addr <host>\fR
.RS 4
-tba
+The local address to bind to\&. By default
+\fBtcpproxy\fR
+will listen on any interface (IPv6 and IPv4)\&.
+.RE
+.PP
+\fB\-t|\-\-local\-resolv (ipv4|4|ipv6|6)\fR
+.RS 4
+When resolving the local address (see above) use only IPv4 or IPv6\&. The default is to resolv both\&.
.RE
.PP
\fB\-p, \-\-local\-port <service>\fR
.RS 4
-tba
+The local port to bind to\&. By default there is no port defined in which case
+\fBtcpproxy\fR
+will try to read the configuration file\&.
.RE
.PP
\fB\-r, \-\-remote\-addr <host>\fR
.RS 4
-tba
+The remote address to connect to\&. Unless the configuration file should be used this must be set to a valid address or hostname\&.
+.RE
+.PP
+\fB\-R|\-\-remote\-resolv (ipv4|4|ipv6|6)\fR
+.RS 4
+When resolving the remote address (see above) use only IPv4 or IPv6\&. The default is to resolv both\&.
.RE
.PP
\fB\-o, \-\-remote\-port <service>\fR
.RS 4
-tba
+The remote port to connect to\&. Unless the configuration file should be used this must be set to a valid port or servicename\&.
.RE
.PP
\fB\-s, \-\-source\-addr <host>\fR
.RS 4
-tba
+Instruct tcpproxy to use this source address for connections to
+\fB\-R|\-\-remote\-address\fR\&. By default
+\fBtcpproxy\fR
+uses the default source address for the defined remote host\&.
+.RE
+.PP
+\fB\-S|\-\-source\-resolv (ipv4|4|ipv6|6)\fR
+.RS 4
+When resolving the source address (see above) use only IPv4 or IPv6\&. The default is to resolv both\&.
.RE
.PP
\fB\-b, \-\-buffer\-size <size>\fR
.RS 4
-tba
+The size of the transmit buffers to use\&.
+\fBtcpproxy\fR
+will allocate two buffers of this size for any client which is connected\&. By default a value of 10Kbytes is used\&.
.RE
.PP
\fB\-c, \-\-config <file>\fR
.RS 4
-tba
+The path to the configuration file to be used\&. This is only evaluated if the local port is omitted\&.
.RE
.SH "EXAMPLES"
.sp
diff --git a/doc/tcpproxy.8.txt b/doc/tcpproxy.8.txt
index ebbac12..8da0b98 100644
--- a/doc/tcpproxy.8.txt
+++ b/doc/tcpproxy.8.txt
@@ -21,10 +21,13 @@ tcpproxy
[ -L|--log <target>:<level>[,<param1>[,<param2>[..]]] ]
[ -U|--debug ]
[ -l|--local-addr <host> ]
+ [ -t|--local-resolv (ipv4|4|ipv6|6) ]
[ -p|--local-port <service> ]
[ -r|--remote-addr <host> ]
+ [ -R|--remote-resolv (ipv4|4|ipv6|6) ]
[ -o|--remote-port <service> ]
[ -s|--source-addr <host> ]
+ [ -S|--source-resolv (ipv4|4|ipv6|6) ]
[ -b|--buffer-size <size> ]
[ -c|--config <file> ]
....
@@ -85,25 +88,44 @@ The following options can be passed to the *tcpproxy* daemon:
be additional output when this option is supplied.
*-l, --local-addr <host>*::
- tba
+ The local address to bind to. By default *tcpproxy* will listen on any interface
+ (IPv6 and IPv4).
+
+*-t|--local-resolv (ipv4|4|ipv6|6)*::
+ When resolving the local address (see above) use only IPv4 or IPv6. The default is
+ to resolv both.
*-p, --local-port <service>*::
- tba
+ The local port to bind to. By default there is no port defined in which case
+ *tcpproxy* will try to read the configuration file.
*-r, --remote-addr <host>*::
- tba
+ The remote address to connect to. Unless the configuration file should be used this
+ must be set to a valid address or hostname.
+
+*-R|--remote-resolv (ipv4|4|ipv6|6)*::
+ When resolving the remote address (see above) use only IPv4 or IPv6. The default is
+ to resolv both.
*-o, --remote-port <service>*::
- tba
+ The remote port to connect to. Unless the configuration file should be used this
+ must be set to a valid port or servicename.
*-s, --source-addr <host>*::
- tba
+ Instruct tcpproxy to use this source address for connections to *-R|--remote-address*.
+ By default *tcpproxy* uses the default source address for the defined remote host.
+
+*-S|--source-resolv (ipv4|4|ipv6|6)*::
+ When resolving the source address (see above) use only IPv4 or IPv6. The default is
+ to resolv both.
*-b, --buffer-size <size>*::
- tba
+ The size of the transmit buffers to use. *tcpproxy* will allocate two buffers of this
+ size for any client which is connected. By default a value of 10Kbytes is used.
*-c, --config <file>*::
- tba
+ The path to the configuration file to be used. This is only evaluated if the local port
+ is omitted.
EXAMPLES
diff --git a/src/listener.c b/src/listener.c
index bea19e4..a9cfa1e 100644
--- a/src/listener.c
+++ b/src/listener.c
@@ -66,26 +66,26 @@ void listener_clear(listeners_t* list)
slist_clear(list);
}
-int listener_add(listeners_t* list, const char* laddr, const char* lport, const char* raddr, const char* rport, const char* saddr)
+int listener_add(listeners_t* list, const char* laddr, resolv_type_t lrt, const char* lport, const char* raddr, resolv_type_t rrt, const char* rport, const char* saddr, resolv_type_t srt)
{
if(!list)
return -1;
// TODO: what if more than one address is returned here?
- struct addrinfo* re = tcp_resolve_endpoint(raddr, rport, ANY);
+ struct addrinfo* re = tcp_resolve_endpoint(raddr, rport, rrt);
if(!re)
return -1;
struct addrinfo* se = NULL;
if(saddr) {
- se = tcp_resolve_endpoint(saddr, NULL, ANY);
+ se = tcp_resolve_endpoint(saddr, NULL, srt);
if(!se) {
freeaddrinfo(re);
return -1;
}
}
- struct addrinfo* le = tcp_resolve_endpoint(laddr, lport, ANY);
+ struct addrinfo* le = tcp_resolve_endpoint(laddr, lport, lrt);
if(!le) {
freeaddrinfo(re);
if(se)
diff --git a/src/listener.h b/src/listener.h
index 11d5d24..fc3feed 100644
--- a/src/listener.h
+++ b/src/listener.h
@@ -47,7 +47,7 @@ typedef slist_t listeners_t;
int listener_init(listeners_t* list);
void listener_clear(listeners_t* list);
-int listener_add(listeners_t* list, const char* laddr, const char* lport, const char* raddr, const char* rport, const char* saddr);
+int listener_add(listeners_t* list, const char* laddr, resolv_type_t lrt, const char* lport, const char* raddr, resolv_type_t rrt, const char* rport, const char* saddr, resolv_type_t srt);
void listener_remove(listeners_t* list, int fd);
listener_t* listener_find(listeners_t* list, int fd);
void listener_print(listeners_t* list);
diff --git a/src/options.c b/src/options.c
index 30361d4..4e630e5 100644
--- a/src/options.c
+++ b/src/options.c
@@ -30,6 +30,7 @@
#include "options.h"
#include "log.h"
+#include "tcp.h"
#include <stdlib.h>
#include <stdio.h>
@@ -115,6 +116,23 @@
i++; \
}
+#define PARSE_RESOLV_TYPE(SHORT, LONG, VALUE) \
+ else if(!strcmp(str,SHORT) || !strcmp(str,LONG)) \
+ { \
+ if(argc < 1 || argv[i+1][0] == '-') \
+ return i; \
+ if(!strcmp(argv[i+1], "4") || \
+ !strcmp(argv[i+1], "ipv4")) \
+ VALUE = IPV4_ONLY; \
+ else if(!strcmp(argv[i+1], "6") || \
+ !strcmp(argv[i+1], "ipv6")) \
+ VALUE = IPV6_ONLY; \
+ else \
+ return i+1; \
+ argc--; \
+ i++; \
+ }
+
int options_parse_hex_string(const char* hex, buffer_t* buffer)
{
if(!hex || !buffer)
@@ -180,10 +198,13 @@ int options_parse(options_t* opt, int argc, char* argv[])
PARSE_STRING_LIST("-L","--log", opt->log_targets_)
PARSE_BOOL_PARAM("-U", "--debug", opt->debug_)
PARSE_STRING_PARAM("-l","--local-addr", opt->local_addr_)
+ PARSE_RESOLV_TYPE("-t","--local-resolv", opt->lresolv_type_)
PARSE_STRING_PARAM("-p","--local-port", opt->local_port_)
PARSE_STRING_PARAM("-r","--remote-addr", opt->remote_addr_)
+ PARSE_RESOLV_TYPE("-R","--remote-resolv", opt->rresolv_type_)
PARSE_STRING_PARAM("-o","--remote-port", opt->remote_port_)
PARSE_STRING_PARAM("-s","--source-addr", opt->source_addr_)
+ PARSE_RESOLV_TYPE("-S","--source-resolv", opt->sresolv_type_)
PARSE_STRING_PARAM("-c","--config", opt->config_file_)
PARSE_INT_PARAM("-b","--buffer-size", opt->buffer_size_)
else
@@ -225,10 +246,13 @@ void options_default(options_t* opt)
opt->chroot_dir_ = NULL;
opt->pid_file_ = NULL;
opt->local_addr_ = NULL;
+ opt->lresolv_type_ = ANY;
opt->local_port_ = NULL;
opt->remote_addr_ = NULL;
+ opt->rresolv_type_ = ANY;
opt->remote_port_ = NULL;
opt->source_addr_ = NULL;
+ opt->sresolv_type_ = ANY;
opt->config_file_ = strdup(CONFFILE);
string_list_init(&opt->log_targets_);
opt->buffer_size_ = 10 * 1024;
@@ -268,23 +292,26 @@ void options_clear(options_t* opt)
void options_print_usage()
{
printf("USAGE:\n");
- printf("tcpproxy [-h|--help] prints this...\n");
- printf(" [-v|--version] print version info and exit\n");
- printf(" [-D|--nodaemonize] don't run in background\n");
- printf(" [-u|--username] <username> change to this user\n");
- printf(" [-g|--groupname] <groupname> change to this group\n");
- printf(" [-C|--chroot] <path> chroot to this directory\n");
- printf(" [-P|--write-pid] <path> write pid to this file\n");
+ printf("tcpproxy [-h|--help] prints this...\n");
+ printf(" [-v|--version] print version info and exit\n");
+ printf(" [-D|--nodaemonize] don't run in background\n");
+ printf(" [-u|--username] <username> change to this user\n");
+ printf(" [-g|--groupname] <groupname> change to this group\n");
+ printf(" [-C|--chroot] <path> chroot to this directory\n");
+ printf(" [-P|--write-pid] <path> write pid to this file\n");
printf(" [-L|--log] <target>:<level>[,<param1>[,<param2>..]]\n");
- printf(" add a log target, can be invoked several times\n");
- printf(" [-U|--debug] don't daemonize and log to stdout with maximum log level\n");
- printf(" [-l|--local-addr] <host> local address to listen on\n");
- printf(" [-p|--local-port] <service> local port to listen on\n");
- printf(" [-r|--remote-addr] <host> remote address to connect to\n");
- printf(" [-o|--remote-port] <service> remote port to connect to\n");
- printf(" [-s|--source-addr] <host> source address to connect from\n");
- printf(" [-b|--buffer-size] <size> size of transmit buffers\n");
- printf(" [-c|--config] <file> configuration file\n");
+ printf(" add a log target, can be invoked several times\n");
+ printf(" [-U|--debug] don't daemonize and log to stdout with maximum log level\n");
+ printf(" [-l|--local-addr] <host> local address to listen on\n");
+ printf(" [-t|--local-resolv] (ipv4|4|ipv6|6) set IPv4 or IPv6 only resolving for local address\n");
+ printf(" [-p|--local-port] <service> local port to listen on\n");
+ printf(" [-r|--remote-addr] <host> remote address to connect to\n");
+ printf(" [-R|--remote-resolv] (ipv4|4|ipv6|6) set IPv4 or IPv6 only resolving for local address\n");
+ printf(" [-o|--remote-port] <service> remote port to connect to\n");
+ printf(" [-s|--source-addr] <host> source address to connect from\n");
+ printf(" [-S|--source-resolv] (ipv4|4|ipv6|6) set IPv4 or IPv6 only resolving for local address\n");
+ printf(" [-b|--buffer-size] <size> size of transmit buffers\n");
+ printf(" [-c|--config] <file> configuration file\n");
}
void options_print_version()
@@ -307,10 +334,19 @@ void options_print(options_t* opt)
printf("log_targets: \n");
string_list_print(&opt->log_targets_, " '", "'\n");
printf("local_addr: '%s'\n", opt->local_addr_);
+ if(opt->lresolv_type_ == IPV4_ONLY) printf("lresolv_type: IPv4\n");
+ else if(opt->lresolv_type_ == IPV6_ONLY) printf("lresolv_type: IPv6\n");
+ else printf("lresolv_type: Both\n");
printf("local_port: '%s'\n", opt->local_port_);
printf("remote_addr: '%s'\n", opt->remote_addr_);
+ if(opt->rresolv_type_ == IPV4_ONLY) printf("rresolv_type: IPv4\n");
+ else if(opt->rresolv_type_ == IPV6_ONLY) printf("rresolv_type: IPv6\n");
+ else printf("rresolv_type: Both\n");
printf("remote_port: '%s'\n", opt->remote_port_);
printf("source_addr: '%s'\n", opt->source_addr_);
+ if(opt->sresolv_type_ == IPV4_ONLY) printf("sresolv_type: IPv4\n");
+ else if(opt->sresolv_type_ == IPV6_ONLY) printf("sresolv_type: IPv6\n");
+ else printf("sresolv_type: Both\n");
printf("buffer-size: %d\n", opt->buffer_size_);
printf("config_file: '%s'\n", opt->config_file_);
printf("debug: %s\n", !opt->debug_ ? "false" : "true");
diff --git a/src/options.h b/src/options.h
index c48412d..085544c 100644
--- a/src/options.h
+++ b/src/options.h
@@ -30,6 +30,7 @@
#include "string_list.h"
#include "datatypes.h"
+#include "tcp.h"
struct options_struct {
char* progname_;
@@ -40,10 +41,13 @@ struct options_struct {
char* pid_file_;
string_list_t log_targets_;
char* local_addr_;
+ resolv_type_t lresolv_type_;
char* local_port_;
char* remote_addr_;
+ resolv_type_t rresolv_type_;
char* remote_port_;
char* source_addr_;
+ resolv_type_t sresolv_type_;
char* config_file_;
int32_t buffer_size_;
int debug_;
diff --git a/src/tcp.c b/src/tcp.c
index ea2af7d..fa69ba2 100644
--- a/src/tcp.c
+++ b/src/tcp.c
@@ -75,7 +75,10 @@ struct addrinfo* tcp_resolve_endpoint(const char* addr, const char* port, resolv
int errcode = getaddrinfo(addr, port, &hints, &res);
if (errcode != 0) {
- log_printf(ERROR, "Error resolving address (%s:%s): %s", (addr) ? addr : "*", (port) ? port : "0", gai_strerror(errcode));
+ char* type = "";
+ if(rt == IPV4_ONLY) type = "IPv4 ";
+ else if(rt == IPV6_ONLY) type = "IPv6 ";
+ log_printf(ERROR, "Error resolving %saddress (%s:%s): %s", type, (addr) ? addr : "*", (port) ? port : "0", gai_strerror(errcode));
return NULL;
}
if(!res) {
diff --git a/src/tcpproxy.c b/src/tcpproxy.c
index d708770..5423036 100644
--- a/src/tcpproxy.c
+++ b/src/tcpproxy.c
@@ -145,7 +145,7 @@ int main(int argc, char* argv[])
log_close();
exit(-1);
}
- ret = listener_add(&listeners, opt.local_addr_, opt.local_port_, opt.remote_addr_, opt.remote_port_, opt.source_addr_);
+ ret = listener_add(&listeners, opt.local_addr_, opt.lresolv_type_, opt.local_port_, opt.remote_addr_, opt.rresolv_type_, opt.remote_port_, opt.source_addr_, opt.sresolv_type_);
if(ret) {
listener_clear(&listeners);
options_clear(&opt);