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)
56 char *eos, *argv[5] = {};
59 end =
my->buffer.write;
66 if (memcmp(
my->buffer.read,
"PROXY TCP", 9) != 0) {
76 }
else if (*p ==
'6') {
84 if (*(p++) !=
' ')
goto fail;
90 if (argc > 4)
goto fail;
92 argv[argc++] = (
char *) p;
94 while ((p < end) && (*p >
' ')) p++;
99 if ((end - p) < 2)
goto fail;
101 if (memcmp(p,
"\r\n", 2) != 0)
goto fail;
109 if (*p !=
' ')
goto fail;
130 if (
fr_inet_pton(&
my->info.socket.inet.src_ipaddr, argv[0], -1, af,
false,
false) < 0)
goto fail;
131 if (
fr_inet_pton(&
my->info.socket.inet.dst_ipaddr, argv[1], -1, af,
false,
false) < 0)
goto fail;
133 port = strtoul(argv[2], &eos, 10);
134 if (port > 65535)
goto fail;
136 my->info.socket.inet.src_port = port;
138 port = strtoul(argv[3], &eos, 10);
139 if (port > 65535)
goto fail;
141 my->info.socket.inet.dst_port = port;
146 return (end -
my->buffer.read);
159 my->available =
true;
180 if (
my->cb.connected)
my->cb.connected(bio);
200 if (rcode <= 0)
return rcode;
215 if (rcode <= 0)
return rcode;
234 if (!
my)
return NULL;
258 if (!
my->available)
return NULL;
static int const char char buffer[256]
fr_bio_write_t _CONST write
write to the underlying bio
fr_bio_read_t _CONST read
read from the underlying bio
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)
uint8_t * read
where in the buffer reads are taken from
static int fr_bio_buf_write_alloc(fr_bio_buf_t *bio_buf, size_t size)
void fr_bio_shutdown & my
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_haproxy_info_t const * fr_bio_haproxy_info(fr_bio_t *bio)
Get client information from the haproxy bio.
fr_bio_buf_t buffer
intermediate buffer to read the haproxy header
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)