25 #include <freeradius-devel/bio/bio_priv.h>
26 #include <freeradius-devel/bio/null.h>
27 #include <freeradius-devel/bio/buf.h>
29 #include <freeradius-devel/bio/haproxy.h>
31 #define HAPROXY_HEADER_V1_SIZE (108)
55 char *eos, *argv[5] = {};
58 end =
my->buffer.write;
63 if (memcmp(
my->buffer.read,
"PROXY TCP", 9) != 0) {
73 }
else if (*p ==
'6') {
81 if (*(p++) !=
' ')
goto fail;
87 if (argc > 4)
goto fail;
89 argv[argc++] = (
char *) p;
91 while ((*p >
' ') && (p < end)) p++;
96 if ((end - p) < 3)
goto fail;
98 if (memcmp(p,
"\r\n", 3) != 0)
goto fail;
106 if (*p !=
' ')
goto fail;
127 if (
fr_inet_pton(&
my->info.socket.inet.src_ipaddr, argv[0], -1, af,
false,
false) < 0)
goto fail;
128 if (
fr_inet_pton(&
my->info.socket.inet.dst_ipaddr, argv[1], -1, af,
false,
false) < 0)
goto fail;
130 port = strtoul(argv[2], &eos, 10);
131 if (port > 65535)
goto fail;
133 my->info.socket.inet.src_port = port;
135 port = strtoul(argv[3], &eos, 10);
136 if (port > 65535)
goto fail;
138 my->info.socket.inet.dst_port = port;
143 return (end -
my->buffer.read);
156 my->available =
true;
177 if (
my->cb.connected)
my->cb.connected(bio);
197 if (rcode <= 0)
return rcode;
210 if (rcode <= 0)
return rcode;
229 if (!
my)
return NULL;
253 if (!
my->available)
return NULL;
static int const char char buffer[256]
static fr_bio_t * fr_bio_next(fr_bio_t *bio)
static void fr_bio_chain(fr_bio_t *first, fr_bio_t *second)
Chain one bio after another.
size_t fr_bio_buf_read(fr_bio_buf_t *bio_buf, void *buffer, size_t size)
int fr_bio_buf_alloc(TALLOC_CTX *ctx, fr_bio_buf_t *bio_buf, size_t size)
static size_t fr_bio_buf_write_room(fr_bio_buf_t const *bio_buf)
static size_t fr_bio_buf_used(fr_bio_buf_t const *bio_buf)
fr_bio_t * fr_bio_haproxy_alloc(TALLOC_CTX *ctx, fr_bio_cb_funcs_t *cb, fr_bio_t *next)
Allocate an haproxy bio.
static ssize_t fr_bio_haproxy_read(fr_bio_t *bio, void *packet_ctx, void *buffer, size_t size)
Read from the next bio, and determine if we have an haproxy header.
bool available
is the haxproxy header available and done
static ssize_t fr_bio_haproxy_v1(fr_bio_haproxy_t *my)
Parse the haproxy header, version 1.
#define HAPROXY_HEADER_V1_SIZE
fr_bio_haproxy_info_t info
Information about the "real" client which has connected.
fr_bio_buf_t buffer
intermediate buffer to read the haproxy header
fr_bio_haproxy_info_t const * fr_bio_haproxy_info(fr_bio_t *bio)
Get client information from the haproxy bio.
static ssize_t fr_bio_haproxy_read_next(fr_bio_t *bio, UNUSED void *packet_ctx, void *buffer, size_t size)
Satisfy reads from the "next" bio.
Data structure which describes the "real" client connection.
int fr_inet_pton(fr_ipaddr_t *out, char const *value, ssize_t inlen, int af, bool resolve, bool mask)
Simple wrapper to decide whether an IP value is v4 or v6 and call the appropriate parser.
int fr_bio_destructor(fr_bio_t *bio)
Free this bio.
int fr_bio_shutdown(fr_bio_t *bio)
Shut down a set of BIOs.
ssize_t fr_bio_null_write(UNUSED fr_bio_t *bio, UNUSED void *packet_ctx, UNUSED void const *buffer, UNUSED size_t size)
Always return 0 on write.
#define fr_strerror_const(_msg)