mirror of
https://github.com/yrutschle/sslh.git
synced 2026-11-24 03:06:42 +03:00
proxyprotocol on client-side can be removed on server side, and its info is then logged
This commit is contained in:
1 parent
eea50a97fc
commit
6905498d60
8 files changed
+62
-10
No files matched your search
@@ -514,10 +514,21 @@ void connect_addr(struct connection *cnx, int fd_from, connect_blocking blocking
|
||||
cnx->q[1].fd = fd;
|
||||
|
||||
if (cnx->proto->proxyprotocol_is_present) {
|
||||
pp_write_header(cnx->proto->proxyprotocol, cnx);
|
||||
/* If pp_write_header() fails, it already logs a message and there is
|
||||
* nothing much we can do. The server side will probably close the
|
||||
* connection */
|
||||
if (cnx->proto->proxyprotocol) {
|
||||
pp_write_header(cnx->proto->proxyprotocol, cnx);
|
||||
/* If pp_write_header() fails, it already logs a message and there is
|
||||
* nothing much we can do. The server side will probably close the
|
||||
* connection */
|
||||
} else {
|
||||
/* proxyprotocol == 0 means we remove a proxyprotocol header from
|
||||
* the client-side, and log PP information (as it will be lost
|
||||
* after sslh) */
|
||||
int pp_len = pp_log_connection(cnx->q[1].begin_deferred_data,
|
||||
cnx->q[1].deferred_data_size);
|
||||
if (pp_len > 0) {
|
||||
defer_skip(&cnx->q[1], pp_len);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -540,6 +551,13 @@ int defer_write(struct queue *q, void* data, ssize_t data_size)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* skip (remove) some data from the head of the queue */
|
||||
void defer_skip(struct queue *q, ssize_t data_size)
|
||||
{
|
||||
q->deferred_data += data_size;
|
||||
q->deferred_data_size -= data_size;
|
||||
}
|
||||
|
||||
/* Store some data to write *before* what's already in the queue */
|
||||
int defer_write_before(struct queue *q, void* data, ssize_t data_size)
|
||||
{
|
||||
|
||||
@@ -184,6 +184,7 @@ int resolve_split_name(struct addrinfo **out, char* hostname, char* port);
|
||||
int start_listen_sockets(struct listen_endpoint *sockfd[]);
|
||||
|
||||
int defer_write(struct queue *q, void* data, ssize_t data_size);
|
||||
void defer_skip(struct queue *q, ssize_t data_size);
|
||||
int defer_write_before(struct queue *q, void* data, ssize_t data_size);
|
||||
int flush_deferred(struct queue *q);
|
||||
|
||||
|
||||
@@ -133,6 +133,25 @@ int pp_write_header(int pp_version, struct connection* cnx)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Logs the connection data in the pp header and return header length */
|
||||
int pp_log_connection(char* buffer, ssize_t buffer_len)
|
||||
{
|
||||
pp_info_t pp_info;
|
||||
|
||||
int header_len = pp_parse_hdr((uint8_t*)buffer, buffer_len, &pp_info);
|
||||
|
||||
if (header_len > 0) {
|
||||
print_message(msg_connections, "client had proxyprotocol info: %s:%d to %s:%d not forwarded to server\n",
|
||||
pp_info.src_addr, pp_info.src_port,
|
||||
pp_info.dst_addr, pp_info.dst_port);
|
||||
} else {
|
||||
print_message(msg_connections, "no proxyprotocol data found on client side, forwarding as is\n");
|
||||
header_len = 0;
|
||||
}
|
||||
|
||||
return header_len;
|
||||
}
|
||||
|
||||
int pp_header_len(char* buffer, int buffer_len)
|
||||
{
|
||||
pp_info_t pp_info;
|
||||
|
||||
@@ -6,12 +6,14 @@
|
||||
|
||||
|
||||
int pp_write_header(int pp_version, struct connection* cnx);
|
||||
int pp_log_connection(char* buffer, ssize_t buffer_len);
|
||||
int pp_header_len(char* buffer, int len);
|
||||
|
||||
|
||||
#else /* HAVE_PROXYPROTOCOL */
|
||||
|
||||
static inline int pp_write_header(int pp_version, struct connection* cnx) { return 0; }
|
||||
static int pp_log_connection(char* buffer, ssize_t buffer_len) { return 0; }
|
||||
static inline int pp_header_len(char*, int) { return 0; }
|
||||
|
||||
#endif /* HAVE_PROXYPROTOCOL */
|
||||
|
||||
@@ -346,6 +346,17 @@ my @tests = (
|
||||
expected => "ssh",
|
||||
},
|
||||
|
||||
# test_pp2.cfg has proxyprotocol on port 8080 but
|
||||
# removes it towards "regex_remove_pp" tarbet
|
||||
# TODO: Log the addresses!
|
||||
{
|
||||
desc => "Client-side ProxyProtocol active but removed",
|
||||
run => \&run_test_probe,
|
||||
cfg => "test_pp2.cfg",
|
||||
data => "PROXY TCP4 127.0.0.1 127.0.0.1 8080 8081\x0D\x0Aregex_remove_pp hello",
|
||||
expected => "regex",
|
||||
data_expected => "^regex_remove_pp hello",
|
||||
},
|
||||
|
||||
);
|
||||
|
||||
|
||||
@@ -38,6 +38,8 @@ protocols:
|
||||
(
|
||||
{ name: "ssh"; host: "localhost"; port: "9000"; },
|
||||
{ name: "socks5"; host: "localhost"; port: "9001"; },
|
||||
{ name: "regex"; host: "localhost"; port: "9002";
|
||||
regex_patterns: [ "^regex_remove_pp" ]; proxyprotocol: 0; },
|
||||
{ name: "anyprot"; host: "localhost"; port: "9099"; }
|
||||
);
|
||||
|
||||
|
||||
+4
-5
@@ -50,12 +50,11 @@ int probe_client_protocol(struct connection *cnx)
|
||||
hexdump(msg_packets, cnx->q[1].begin_deferred_data, cnx->q[1].deferred_data_size);
|
||||
|
||||
|
||||
/*
|
||||
TODO il ne faut appeler ca que si on supporte pp sur le lien
|
||||
*/
|
||||
|
||||
int pp_len = pp_header_len(cnx->q[1].begin_deferred_data,
|
||||
size_t pp_len = 0;
|
||||
if (cnx->endpoint->endpoint_cfg->proxyprotocol) {
|
||||
pp_len = pp_header_len(cnx->q[1].begin_deferred_data,
|
||||
cnx->q[1].deferred_data_size);
|
||||
}
|
||||
|
||||
return probe_buffer(cnx->q[1].begin_deferred_data + pp_len,
|
||||
cnx->q[1].deferred_data_size - pp_len,
|
||||
|
||||
Reference in new issue
Block a user