mirror of
https://github.com/yrutschle/sslh.git
synced 2025-04-20 18:57:39 +03:00
preliminary receive proxyprotocol support
This commit is contained in:
parent
4978641271
commit
9522799421
@ -1,5 +1,5 @@
|
||||
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
|
||||
* on Mon Feb 24 18:37:24 2025.
|
||||
* on Tue Apr 8 22:35:50 2025.
|
||||
|
||||
# conf2struct: generate libconf parsers that read to structs
|
||||
# Copyright (C) 2018-2024 Yves Rutschle
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
|
||||
* on Mon Feb 24 18:37:24 2025.
|
||||
* on Tue Apr 8 22:35:50 2025.
|
||||
|
||||
# conf2struct: generate libconf parsers that read to structs
|
||||
# Copyright (C) 2018-2024 Yves Rutschle
|
||||
|
3
probe.c
3
probe.c
@ -436,9 +436,6 @@ int probe_buffer(char* buf, int len,
|
||||
struct sslhcfg_protocols_item* p;
|
||||
int i, res, again = 0;
|
||||
|
||||
print_message(msg_packets, "hexdump of incoming packet:\n");
|
||||
hexdump(msg_packets, buf, len);
|
||||
|
||||
*proto_out = NULL;
|
||||
for (i = 0; i < proto_len; i++) {
|
||||
char* probe_str[3] = {"PROBE_NEXT", "PROBE_MATCH", "PROBE_AGAIN"};
|
||||
|
1
probe.h
1
probe.h
@ -6,6 +6,7 @@
|
||||
#include "common.h"
|
||||
#include "tls.h"
|
||||
#include "log.h"
|
||||
#include "proxyprotocol.h"
|
||||
|
||||
typedef enum {
|
||||
PROBE_NEXT, /* Enough data, probe failed -- it's some other protocol */
|
||||
|
@ -20,6 +20,10 @@
|
||||
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#if HAVE_PROXYPROTOCOL
|
||||
|
||||
#include <proxy_protocol.h>
|
||||
#include "common.h"
|
||||
#include "log.h"
|
||||
@ -112,3 +116,19 @@ int pp_write_header(int pp_version, struct connection* cnx)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pp_header_len(char* buffer, int buffer_len)
|
||||
{
|
||||
pp_info_t pp_info;
|
||||
|
||||
int header_len = pp_parse_hdr((uint8_t*)buffer, buffer_len, &pp_info);
|
||||
|
||||
print_message(msg_probe_info, "proxyprotocol header %d bytes found\n", header_len);
|
||||
|
||||
if (header_len < 0) header_len = 0;
|
||||
|
||||
return header_len;
|
||||
}
|
||||
|
||||
|
||||
#endif /* HAVE_PROXYPROTOCOL */
|
||||
|
@ -3,12 +3,16 @@
|
||||
|
||||
|
||||
#if HAVE_PROXYPROTOCOL
|
||||
|
||||
|
||||
int pp_write_header(int pp_version, struct connection* cnx);
|
||||
int pp_header_len(char* buffer, int len);
|
||||
|
||||
|
||||
#else /* HAVE_PROXYPROTOCOL */
|
||||
|
||||
static inline int pp_write_header(int pp_version, struct connection* cnx) {}
|
||||
static inline int pp_write_header(int pp_version, struct connection* cnx) { return 0; }
|
||||
static inline int pp_header_len(char*, int) { return 0; }
|
||||
|
||||
#endif /* HAVE_PROXYPROTOCOL */
|
||||
|
||||
|
23
sslh-conf.c
23
sslh-conf.c
@ -1,5 +1,5 @@
|
||||
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
|
||||
* on Mon Feb 24 18:37:24 2025.
|
||||
* on Tue Apr 8 22:35:50 2025.
|
||||
|
||||
# conf2struct: generate libconf parsers that read to structs
|
||||
# Copyright (C) 2018-2024 Yves Rutschle
|
||||
@ -793,7 +793,7 @@ static struct config_desc table_sslhcfg_protocols[] = {
|
||||
},
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
|
||||
static struct config_desc table_sslhcfg_listen[] = {
|
||||
|
||||
|
||||
@ -876,6 +876,22 @@ static struct config_desc table_sslhcfg_listen[] = {
|
||||
/* optional */ 0,
|
||||
/* default_val*/ .default_val.def_bool = 0
|
||||
},
|
||||
|
||||
{
|
||||
/* name */ "proxyprotocol",
|
||||
/* type */ CFG_BOOL,
|
||||
/* sub_group*/ NULL,
|
||||
/* arg_cl */ NULL,
|
||||
/* base_addr */ NULL,
|
||||
/* offset */ offsetof(struct sslhcfg_listen_item, proxyprotocol),
|
||||
/* offset_len */ 0,
|
||||
/* offset_present */ 0,
|
||||
/* size */ sizeof(int),
|
||||
/* array_type */ -1,
|
||||
/* mandatory */ 0,
|
||||
/* optional */ 0,
|
||||
/* default_val*/ .default_val.def_bool = 0
|
||||
},
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
@ -2471,6 +2487,9 @@ static void sslhcfg_listen_fprint(
|
||||
indent(out, depth);
|
||||
fprintf(out, "keepalive: %d", sslhcfg_listen->keepalive);
|
||||
fprintf(out, "\n");
|
||||
indent(out, depth);
|
||||
fprintf(out, "proxyprotocol: %d", sslhcfg_listen->proxyprotocol);
|
||||
fprintf(out, "\n");
|
||||
}
|
||||
|
||||
void sslhcfg_fprint(
|
||||
|
@ -1,5 +1,5 @@
|
||||
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
|
||||
* on Mon Feb 24 18:37:24 2025.
|
||||
* on Tue Apr 8 22:35:50 2025.
|
||||
|
||||
# conf2struct: generate libconf parsers that read to structs
|
||||
# Copyright (C) 2018-2024 Yves Rutschle
|
||||
@ -46,6 +46,7 @@ struct sslhcfg_listen_item {
|
||||
int is_udp;
|
||||
int is_unix;
|
||||
int keepalive;
|
||||
int proxyprotocol;
|
||||
};
|
||||
|
||||
struct sslhcfg_protocols_item {
|
||||
|
@ -99,7 +99,8 @@ config: {
|
||||
{ name: "port"; type: "string"; var: true; },
|
||||
{ name: "is_udp"; type: "bool"; default: false },
|
||||
{ name: "is_unix"; type: "bool"; default: false },
|
||||
{ name: "keepalive"; type: "bool"; default: false; }
|
||||
{ name: "keepalive"; type: "bool"; default: false; },
|
||||
{ name: "proxyprotocol"; type: "bool"; default: false; }
|
||||
)
|
||||
},
|
||||
|
||||
|
16
tcp-probe.c
16
tcp-probe.c
@ -45,8 +45,20 @@ int probe_client_protocol(struct connection *cnx)
|
||||
|
||||
if (n > 0) {
|
||||
defer_write(&cnx->q[1], buffer, n);
|
||||
return probe_buffer(cnx->q[1].begin_deferred_data,
|
||||
cnx->q[1].deferred_data_size,
|
||||
|
||||
print_message(msg_packets, "hexdump of incoming packet:\n");
|
||||
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,
|
||||
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,
|
||||
tcp_protocols, tcp_protocols_len,
|
||||
&cnx->proto
|
||||
);
|
||||
|
6
test.cfg
6
test.cfg
@ -21,7 +21,7 @@ verbose-connections-error: 1; # connection errors
|
||||
verbose-connections-try: 1; # connection attempts towards targets
|
||||
verbose-fd: 0; # file descriptor activity, open/close/whatnot
|
||||
verbose-packets: 1; # hexdump packets on which probing is done
|
||||
verbose-probe-info: 0; # what's happening during the probe process
|
||||
verbose-probe-info: 1; # what's happening during the probe process
|
||||
verbose-probe-error: 1; # failures and problems during probing
|
||||
verbose-system-error: 1; # system call problem, i.e. malloc, fork, failing
|
||||
verbose-int-error: 1; # internal errors, the kind that should never happen
|
||||
@ -30,7 +30,7 @@ verbose-int-error: 1; # internal errors, the kind that should never happen
|
||||
# Options:
|
||||
listen:
|
||||
(
|
||||
{ host: "localhost"; port: "8080"; keepalive: true; },
|
||||
{ host: "localhost"; port: "8080"; keepalive: true; proxyprotocol: true; },
|
||||
{ host: "localhost"; port: "8081"; keepalive: true; },
|
||||
{ host: "ip4-localhost"; is_udp: true; port: "8086"; },
|
||||
{ host: "/tmp/sslh.sock"; is_unix: true; port: ""; }
|
||||
@ -45,7 +45,7 @@ protocols:
|
||||
(
|
||||
{ name: "ssh"; host: "localhost"; port: "9000"; fork: true; transparent: true; resolve_on_forward: true; },
|
||||
{ name: "socks5"; host: "localhost"; port: "9001"; },
|
||||
{ name: "http"; host: "localhost"; port: "80"; proxyprotocol: 2; },
|
||||
{ name: "http"; host: "localhost"; port: "80"; },
|
||||
{ name: "tinc"; host: "localhost"; port: "9003"; },
|
||||
{ name: "openvpn"; host: "localhost"; port: "9004"; },
|
||||
{ name: "xmpp"; host: "localhost"; port: "9009"; },
|
||||
|
Loading…
x
Reference in New Issue
Block a user