diff options
author | Nick Mathewson <nickm@torproject.org> | 2020-01-06 13:41:20 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2020-01-06 13:41:20 -0500 |
commit | 1b63eea66cbb8793a3cff05de8d856ce3b93fc17 (patch) | |
tree | 2cf4f6ff12522ed24a610b3acab0b107f73b1977 /src/core/proto | |
parent | 9276c07a916e4dc3b159c95c578e43be102f26e6 (diff) | |
parent | 14d781fff6bd88c4e0cd5b741629c3e79c8612d9 (diff) | |
download | tor-1b63eea66cbb8793a3cff05de8d856ce3b93fc17.tar.gz tor-1b63eea66cbb8793a3cff05de8d856ce3b93fc17.zip |
Merge branch 'haxxpop/tcp_proxy_squashed' into tcp_proxy_squshed_and_merged
Diffstat (limited to 'src/core/proto')
-rw-r--r-- | src/core/proto/.may_include | 6 | ||||
-rw-r--r-- | src/core/proto/proto_haproxy.c | 45 | ||||
-rw-r--r-- | src/core/proto/proto_haproxy.h | 12 |
3 files changed, 62 insertions, 1 deletions
diff --git a/src/core/proto/.may_include b/src/core/proto/.may_include index c1647a5cf9..a66c3f83a6 100644 --- a/src/core/proto/.may_include +++ b/src/core/proto/.may_include @@ -4,7 +4,11 @@ orconfig.h lib/crypt_ops/*.h lib/buf/*.h +lib/malloc/*.h +lib/string/*.h + +lib/net/address.h trunnel/*.h -core/proto/*.h
\ No newline at end of file +core/proto/*.h diff --git a/src/core/proto/proto_haproxy.c b/src/core/proto/proto_haproxy.c new file mode 100644 index 0000000000..856f2ab152 --- /dev/null +++ b/src/core/proto/proto_haproxy.c @@ -0,0 +1,45 @@ +/* Copyright (c) 2019, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +#define PROTO_HAPROXY_PRIVATE +#include "lib/malloc/malloc.h" +#include "lib/net/address.h" +#include "lib/string/printf.h" +#include "core/proto/proto_haproxy.h" + +/** Return a newly allocated PROXY header null-terminated string. Returns NULL + * if addr_port->addr is incompatible with the proxy protocol. + */ +char * +haproxy_format_proxy_header_line(const tor_addr_port_t *addr_port) +{ + tor_assert(addr_port); + + sa_family_t family = tor_addr_family(&addr_port->addr); + const char *family_string = NULL; + const char *src_addr_string = NULL; + + switch (family) { + case AF_INET: + family_string = "TCP4"; + src_addr_string = "0.0.0.0"; + break; + case AF_INET6: + family_string = "TCP6"; + src_addr_string = "::"; + break; + default: + /* Unknown family. */ + return NULL; + } + + char *buf; + char addrbuf[TOR_ADDR_BUF_LEN]; + + tor_addr_to_str(addrbuf, &addr_port->addr, sizeof(addrbuf), 0); + + tor_asprintf(&buf, "PROXY %s %s %s 0 %d\r\n", family_string, src_addr_string, + addrbuf, addr_port->port); + + return buf; +} diff --git a/src/core/proto/proto_haproxy.h b/src/core/proto/proto_haproxy.h new file mode 100644 index 0000000000..fd4240f5dd --- /dev/null +++ b/src/core/proto/proto_haproxy.h @@ -0,0 +1,12 @@ +/* Copyright (c) 2019, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +#ifndef TOR_PROTO_HAPROXY_H +#define TOR_PROTO_HAPROXY_H + +struct tor_addr_port_t; + +char *haproxy_format_proxy_header_line( + const struct tor_addr_port_t *addr_port); + +#endif /* !defined(TOR_PROTO_HAPROXY_H) */ |