Skip to content

Commit

Permalink
refactor: isolate inet connection
Browse files Browse the repository at this point in the history
  • Loading branch information
yrutschle committed Dec 21, 2024
1 parent 16ef412 commit 9e6b4fa
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 11 deletions.
20 changes: 14 additions & 6 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion echosrv-conf.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion echosrv-conf.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion sslh-conf.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion sslh-conf.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion version.h
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9e6b4fa

Please sign in to comment.