refactor: isolate inet connection

This commit is contained in:
Yves Rutschle 2024-12-22 00:06:54 +01:00
parent 16ef412663
commit 9e6b4fae29
6 changed files with 19 additions and 11 deletions

View File

@ -337,11 +337,8 @@ int set_nonblock(int fd)
}
/* Connect to first address that works and returns a file descriptor, or -1 if
* none work.
* If transparent proxying is on, use fd_from peer address on external address
* of new file descriptor. */
int connect_addr(struct connection *cnx, int fd_from, connect_blocking blocking)
/* Connects to INET/INET6 domain sockets and return a fd */
static int connect_inet(struct connection *cnx, int fd_from, connect_blocking blocking)
{
struct addrinfo *a, from;
struct sockaddr_storage ss;
@ -360,7 +357,6 @@ int connect_addr(struct connection *cnx, int fd_from, connect_blocking blocking)
resolve_split_name(&(cnx->proto->saddr), cnx->proto->host,
cnx->proto->port);
}
for (a = cnx->proto->saddr; a; a = a->ai_next) {
/* When transparent, make sure both connections use the same address family */
if (transparent && a->ai_family != from.ai_addr->sa_family)
@ -408,6 +404,18 @@ int connect_addr(struct connection *cnx, int fd_from, connect_blocking blocking)
return -1;
}
/* Connect to first address that works and returns a file descriptor, or -1 if
* none work.
* If transparent proxying is on, use fd_from peer address on external address
* of new file descriptor. */
int connect_addr(struct connection *cnx, int fd_from, connect_blocking blocking)
{
int fd = connect_inet(cnx, fd_from, blocking);
return fd;
}
/* Store some data to write to the queue later */
int defer_write(struct queue *q, void* data, ssize_t data_size)
{

View File

@ -1,5 +1,5 @@
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
* on Sun Sep 8 23:10:29 2024.
* on Sun Dec 22 00:05:31 2024.
# conf2struct: generate libconf parsers that read to structs
# Copyright (C) 2018-2024 Yves Rutschle

View File

@ -1,5 +1,5 @@
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
* on Sun Sep 8 23:10:29 2024.
* on Sun Dec 22 00:05:31 2024.
# conf2struct: generate libconf parsers that read to structs
# Copyright (C) 2018-2024 Yves Rutschle

View File

@ -1,5 +1,5 @@
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
* on Sun Sep 8 23:10:29 2024.
* on Sun Dec 22 00:05:31 2024.
# conf2struct: generate libconf parsers that read to structs
# Copyright (C) 2018-2024 Yves Rutschle

View File

@ -1,5 +1,5 @@
/* Generated by conf2struct (https://www.rutschle.net/tech/conf2struct/README)
* on Sun Sep 8 23:10:29 2024.
* on Sun Dec 22 00:05:31 2024.
# conf2struct: generate libconf parsers that read to structs
# Copyright (C) 2018-2024 Yves Rutschle

View File

@ -1,5 +1,5 @@
#ifndef VERSION_H
#define VERSION_H
#define VERSION "v2.1.1-50-g686d1f7-dirty"
#define VERSION "v2.1.4-21-g16ef412-dirty"
#endif