[sslh] [PATCH 06/10] Simplify function signatures

ondra+sslh at mistotebe.net ondra+sslh at mistotebe.net
Tue Sep 24 00:30:36 CEST 2013


From: Ondřej Kuzník <ondra at mistotebe.net>

---
 common.c      | 12 ++++++------
 common.h      |  2 +-
 sslh-fork.c   |  4 +---
 sslh-select.c | 11 +++--------
 4 files changed, 11 insertions(+), 18 deletions(-)

diff --git a/common.c b/common.c
index c3def7c..c230328 100644
--- a/common.c
+++ b/common.c
@@ -126,22 +126,22 @@ int bind_peer(int fd, int fd_from)
 /* 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.
- * cnx_name points to the name of the service (for logging) */
-int connect_addr(struct addrinfo *addr, int fd_from, const char* cnx_name)
+ * of new file descriptor. */
+int connect_addr(struct connection *cnx, int fd_from)
 {
     struct addrinfo *a;
     char buf[NI_MAXHOST];
     int fd, res;
 
-    for (a = addr; a; a = a->ai_next) {
+    for (a = cnx->proto->saddr; a; a = a->ai_next) {
         if (verbose) 
             fprintf(stderr, "connecting to %s family %d len %d\n", 
                     sprintaddr(buf, sizeof(buf), a),
                     a->ai_addr->sa_family, a->ai_addrlen);
         fd = socket(a->ai_family, SOCK_STREAM, 0);
         if (fd == -1) {
-            log_message(LOG_ERR, "forward to %s failed:socket: %s\n", cnx_name, strerror(errno));
+            log_message(LOG_ERR, "forward to %s failed:socket: %s\n",
+                        cnx->proto->description, strerror(errno));
         } else {
             if (transparent) {
                 res = bind_peer(fd, fd_from);
@@ -150,7 +150,7 @@ int connect_addr(struct addrinfo *addr, int fd_from, const char* cnx_name)
             res = connect(fd, a->ai_addr, a->ai_addrlen);
             if (res == -1) {
                 log_message(LOG_ERR, "forward to %s failed:connect: %s\n", 
-                            cnx_name, strerror(errno));
+                            cnx->proto->description, strerror(errno));
             } else {
                 return fd;
             }
diff --git a/common.h b/common.h
index c77e51a..1b8e8a6 100644
--- a/common.h
+++ b/common.h
@@ -84,7 +84,7 @@ struct connection {
 
 /* common.c */
 void init_cnx(struct connection *cnx);
-int connect_addr(struct addrinfo *addr, int fd_from, const char* cnx_name);
+int connect_addr(struct connection *cnx, int fd_from);
 int fd2fd(struct queue *target, struct queue *from);
 char* sprintaddr(char* buf, size_t size, struct addrinfo *a);
 void resolve_name(struct addrinfo **out, char* fullname);
diff --git a/sslh-fork.c b/sslh-fork.c
index 05c0c42..02785b5 100644
--- a/sslh-fork.c
+++ b/sslh-fork.c
@@ -69,7 +69,6 @@ void start_shoveler(int in_socket)
 {
    fd_set fds;
    struct timeval tv;
-   struct addrinfo *saddr;
    int res = PROBE_AGAIN;
    int out_socket;
    struct connection cnx;
@@ -99,14 +98,13 @@ void start_shoveler(int in_socket)
        }
    }
 
-   saddr = cnx.proto->saddr;
    if (cnx.proto->service &&
        check_access_rights(in_socket, cnx.proto->service)) {
        exit(0);
    }
 
    /* Connect the target socket */
-   out_socket = connect_addr(saddr, in_socket, cnx.proto->description);
+   out_socket = connect_addr(&cnx, in_socket);
    CHECK_RES_DIE(out_socket, "connect");
 
    cnx.q[1].fd = out_socket;
diff --git a/sslh-select.c b/sslh-select.c
index 02f7cad..5b4b2f0 100644
--- a/sslh-select.c
+++ b/sslh-select.c
@@ -129,13 +129,11 @@ int accept_new_connection(int listen_socket, struct connection *cnx[], int* cnx_
 
 
 /* Connect queue 1 of connection to SSL; returns new file descriptor */
-int connect_queue(struct connection *cnx, struct addrinfo *addr, 
-                  const char* cnx_name,
-                  fd_set *fds_r, fd_set *fds_w)
+int connect_queue(struct connection *cnx, fd_set *fds_r, fd_set *fds_w)
 {
     struct queue *q = &cnx->q[1];
 
-    q->fd = connect_addr(addr, cnx->q[0].fd, cnx_name);
+    q->fd = connect_addr(cnx, cnx->q[0].fd);
     if ((q->fd != -1) && fd_is_in_range(q->fd)) {
         log_connection(cnx);
         set_nonblock(q->fd);
@@ -322,10 +320,7 @@ void main_loop(int listen_sockets[], int num_addr_listen)
                             tidy_connection(&cnx[i], &fds_r, &fds_w);
                             res = -1;
                         } else {
-                            res = connect_queue(&cnx[i], 
-                                                cnx[i].proto->saddr, 
-                                                cnx[i].proto->description, 
-                                                &fds_r, &fds_w);
+                            res = connect_queue(&cnx[i], &fds_r, &fds_w);
                         }
 
                         if (res >= max_fd)
-- 
1.8.4.rc3




More information about the sslh mailing list