diff options
author | David Härdeman <david@hardeman.nu> | 2020-06-05 22:04:01 +0200 |
---|---|---|
committer | David Härdeman <david@hardeman.nu> | 2020-06-05 22:04:01 +0200 |
commit | 8e301216143cb96d39a941a9c5fcb90319ef53c7 (patch) | |
tree | 066ea8b408ff49e20e2be2303364a35ff1731d15 | |
parent | a683051b05930d1dd2766b98494bbd124817a6dd (diff) |
Add enough functionality to actually be able to proxy a connection
-rw-r--r-- | config.c | 5 | ||||
-rw-r--r-- | main.c | 3 | ||||
-rw-r--r-- | proxy.c | 7 | ||||
-rw-r--r-- | proxy.h | 2 | ||||
-rw-r--r-- | uring.c | 3 |
5 files changed, 17 insertions, 3 deletions
@@ -75,6 +75,7 @@ strtosockaddrs(const char *str, struct list_head *list) if (*str == '[') { /* IPv6, [a:b:c...h]:p or [*]:p */ + fprintf(stderr, "Attempting to parse an IPv6 addr\n"); str++; tmp = strchr(str, ']'); if (!tmp) @@ -105,6 +106,7 @@ strtosockaddrs(const char *str, struct list_head *list) } else if (*str == '*') { /* IPv4, *:p */ + fprintf(stderr, "Attempting to parse an IPv4 wildcard\n"); str++; if (*str != ':') goto out; @@ -204,6 +206,7 @@ strtosockaddrs(const char *str, struct list_head *list) } else if (strtou16_strict(tmp, &port) == 0) { /* Port */ + fprintf(stderr, "Attempting to parse a port\n"); addr = zmalloc(sizeof(*addr)); if (!addr) goto out; @@ -221,6 +224,8 @@ strtosockaddrs(const char *str, struct list_head *list) addr->in4.sin_port = htons(port); addr->addrlen = sizeof(addr->in4); list_add(&addr->list, list); + } else { + goto out; } success: @@ -250,6 +250,9 @@ signalfd_init(struct cfg *cfg) sigaction(SIGHUP, &action, NULL); sigaction(SIGTERM, &action, NULL); + action.sa_handler = SIG_IGN; + sigaction(SIGPIPE, &action, NULL); + sfd = eventfd(0, EFD_CLOEXEC); if (sfd < 0) perrordie("eventfd"); @@ -51,6 +51,7 @@ proxy_client_data_out(struct cfg *cfg, struct uring_task *task, int res) return; } + uring_task_set_fd(&proxy->clienttask, proxy->cfd); uring_read(cfg, task, proxy->clientbuf, sizeof(proxy->clientbuf), 0, proxy_client_data_in); } @@ -64,6 +65,7 @@ proxy_client_data_in(struct cfg *cfg, struct uring_task *task, int res) return; proxy->clientlen = res; + uring_task_set_fd(&proxy->clienttask, proxy->sfd); uring_write(cfg, task, proxy->clientbuf, res, proxy_client_data_out); } @@ -83,6 +85,7 @@ proxy_server_data_out(struct cfg *cfg, struct uring_task *task, int res) return; } + uring_task_set_fd(&proxy->servertask, proxy->sfd); uring_read(cfg, task, proxy->serverbuf, sizeof(proxy->serverbuf), 0, proxy_server_data_in); } @@ -96,6 +99,7 @@ proxy_server_data_in(struct cfg *cfg, struct uring_task *task, int res) return; proxy->serverlen = res; + uring_task_set_fd(&proxy->servertask, proxy->cfd); uring_write(cfg, task, proxy->serverbuf, res, proxy_server_data_out); } @@ -152,6 +156,7 @@ again: goto again; } + proxy->sfd = sfd; uring_task_set_fd(&proxy->servertask, sfd); uring_connect(cfg, &proxy->servertask, &proxy->server, proxy_server_connected); } @@ -167,6 +172,8 @@ proxy_new(struct cfg *cfg, struct server *scfg, struct sockaddr_in46 *client, in return NULL; } + proxy->sfd = -1; + proxy->cfd = fd; proxy->scfg = scfg; proxy->client = *client; sockaddr_to_str(&proxy->client, proxy->clientstr, sizeof(proxy->clientstr)); @@ -7,12 +7,14 @@ struct server_proxy { char clientbuf[4096]; size_t clientlen; struct uring_task clienttask; + int cfd; struct sockaddr_in46 server; char serverstr[ADDRSTRLEN]; char serverbuf[4096]; size_t serverlen; struct uring_task servertask; + int sfd; unsigned next_remote; struct server *scfg; @@ -88,9 +88,6 @@ uring_task_get(struct cfg *cfg, struct uring_task *task) void uring_task_set_fd(struct uring_task *task, int fd) { - if (task->fd >= 0) - error("Leaking fd %i\n", task->fd); - task->fd = fd; } |