diff options
author | Christoph Liebender <christoph.liebender@posteo.de> | 2024-06-17 20:47:24 +0000 |
---|---|---|
committer | Omar Polo <op@omarpolo.com> | 2024-06-17 20:47:24 +0000 |
commit | 3db5bc7ccbc3fea3868a31926a338d7909220bba (patch) | |
tree | fb388c898a6946647356cac4139baf44b809317b /gmid.h | |
parent | be3218cb6df5fc444b1aa9add2fb7d287dcf4ebf (diff) |
add support for the proxy protocol v1
This allows to use proxies like nginx or haproxy in front of gmid and
still have the correct information about the originating client.
This will need explicit opt-in via the `proxy-v1' listen flag which
will be added in a follow-up commit.
Merges https://github.com/omar-polo/gmid/pull/30
Diffstat (limited to 'gmid.h')
-rw-r--r-- | gmid.h | 54 |
1 files changed, 45 insertions, 9 deletions
@@ -34,6 +34,7 @@ #include <time.h> #include <tls.h> #include <unistd.h> +#include <assert.h> #include <openssl/x509.h> @@ -59,6 +60,8 @@ #define GMID_VERSION "gmid/" VERSION +#define ASSERT_MSG(expr, msg) assert(((void)msg, (expr))) + #define GEMINI_URL_LEN (1024+3) /* URL max len + \r\n + \0 */ #define SUCCESS 20 @@ -281,17 +284,44 @@ enum { REQUEST_DONE, }; +enum proto { + PROTO_V4, + PROTO_V6, + PROTO_UNKNOWN, +}; + +struct proxy_protocol_v1 { + enum proto proto; + union { + struct in_addr v4; + struct in6_addr v6; + } srcaddr, dstaddr; + uint16_t srcport, dstport; +}; + +#define BUFLAYER_MAX 108 + +struct buflayer +{ + char data[BUFLAYER_MAX]; + size_t len; + ssize_t read_pos; + int has_tail; +}; + struct client { - struct conf *conf; + struct conf *conf; struct address *addr; - uint32_t id; - struct tls *ctx; - char *req; - size_t reqlen; - struct iri iri; - char domain[DOMAIN_NAME_LEN]; - char rhost[NI_MAXHOST]; - char rserv[NI_MAXSERV]; + int should_buffer; + struct buflayer buf; + uint32_t id; + struct tls *ctx; + char *req; + size_t reqlen; + struct iri iri; + char domain[DOMAIN_NAME_LEN]; + char rhost[NI_MAXHOST]; + char rserv[NI_MAXSERV]; struct bufferevent *bev; @@ -464,4 +494,10 @@ struct vhost *new_vhost(void); struct location *new_location(void); struct proxy *new_proxy(void); +/* proxy-proto.c */ +#define PROXY_PROTO_PARSE_FAIL -1 +#define PROXY_PROTO_PARSE_SUCCESS 0 +int proxy_proto_v1_parse(struct proxy_protocol_v1 *, char *, size_t, size_t *); +int proxy_proto_v1_string(const struct proxy_protocol_v1 *, char*, size_t); + #endif |