]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: listener: move the network namespace to the struct settings
authorWilly Tarreau <w@1wt.eu>
Thu, 3 Sep 2020 05:27:34 +0000 (07:27 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 16 Sep 2020 18:13:13 +0000 (20:13 +0200)
The netns is common to all listeners/receivers and is used to bind the
listening socket so it must be in the receiver settings and not in the
listener. This removes some yet another set of unnecessary loops.

include/haproxy/listener-t.h
src/cfgparse-tcp.c
src/cli.c
src/proto_tcp.c
src/proto_udp.c
src/session.c
src/sock.c
src/tcp_sample.c

index 9d0db4e536879c7d63a0a2d984cdb48cdebf8ae0..8ea7621ed762c4d0d5452993152724e258454052 100644 (file)
@@ -187,6 +187,7 @@ struct bind_conf {
                        mode_t mode;       /* 0 to leave unchanged */
                } ux;
                char *interface;           /* interface name or NULL */
+               const struct netns_entry *netns; /* network namespace of the listener*/
        } settings;                /* all the settings needed for the listening socket */
 };
 
@@ -219,8 +220,6 @@ struct listener {
 
        __decl_thread(HA_SPINLOCK_T lock);
 
-       const struct netns_entry *netns; /* network namespace of the listener*/
-
        /* cache line boundary */
        unsigned int thr_conn[MAX_THREADS]; /* number of connections per thread */
 
index 033a3bdbb35d19bbbd3828fc661858861bef5403..961a726a5bdb08995021d313f856561921522b12 100644 (file)
@@ -192,7 +192,6 @@ static int bind_parse_interface(char **args, int cur_arg, struct proxy *px, stru
 /* parse the "namespace" bind keyword */
 static int bind_parse_namespace(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
 {
-       struct listener *l;
        char *namespace = NULL;
 
        if (!*args[cur_arg + 1]) {
@@ -201,16 +200,14 @@ static int bind_parse_namespace(char **args, int cur_arg, struct proxy *px, stru
        }
        namespace = args[cur_arg + 1];
 
-       list_for_each_entry(l, &conf->listeners, by_bind) {
-               l->netns = netns_store_lookup(namespace, strlen(namespace));
+       conf->settings.netns = netns_store_lookup(namespace, strlen(namespace));
 
-               if (l->netns == NULL)
-                       l->netns = netns_store_insert(namespace);
+       if (conf->settings.netns == NULL)
+               conf->settings.netns = netns_store_insert(namespace);
 
-               if (l->netns == NULL) {
-                       ha_alert("Cannot open namespace '%s'.\n", args[cur_arg + 1]);
-                       return ERR_ALERT | ERR_FATAL;
-               }
+       if (conf->settings.netns == NULL) {
+               ha_alert("Cannot open namespace '%s'.\n", args[cur_arg + 1]);
+               return ERR_ALERT | ERR_FATAL;
        }
        return 0;
 }
index d7ec79aba4c3d2b14b6ecc145d86b0c84bf3c6bb..5a2c5c67b240ead1e5b6f99f023440d4b63f036d 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1716,9 +1716,9 @@ static int _getsocks(char **args, char *payload, struct appctx *appctx, void *pr
                        }
 
 #ifdef USE_NS
-                       if (l->netns) {
-                               ns_name = l->netns->node.key;
-                               ns_nlen = l->netns->name_len;
+                       if (l->bind_conf->settings.netns) {
+                               ns_name = l->bind_conf->settings.netns->node.key;
+                               ns_nlen = l->bind_conf->settings.netns->name_len;
                        }
 #endif
                }
index 7be68820ca9a0453dcc9d1c17e497d6cf9e1d9ec..7bb31b29b3743cba9f507dfa322bd52319bddd4c 100644 (file)
@@ -581,7 +581,7 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen)
        ext = (fd >= 0);
 
        if (!ext) {
-               fd = my_socketat(listener->netns, listener->addr.ss_family, SOCK_STREAM, IPPROTO_TCP);
+               fd = my_socketat(listener->bind_conf->settings.netns, listener->addr.ss_family, SOCK_STREAM, IPPROTO_TCP);
 
                if (fd == -1) {
                        err |= ERR_RETRYABLE | ERR_ALERT;
index 5337ac4bd3e80ec06955a4ab7848744eb279ae08..92dad6afb13c72ddad9edbbdb45c735df5658b86 100644 (file)
@@ -200,7 +200,7 @@ int udp_bind_listener(struct listener *listener, char *errmsg, int errlen)
         * IPPROTO (sockaddr is not enough)
         */
 
-       fd = my_socketat(listener->netns, listener->proto->sock_family, listener->proto->sock_type, listener->proto->sock_prot);
+       fd = my_socketat(listener->bind_conf->settings.netns, listener->proto->sock_family, listener->proto->sock_type, listener->proto->sock_prot);
        if (fd == -1) {
                err |= ERR_RETRYABLE | ERR_ALERT;
                msg = "cannot create listening socket";
index 52d3a1fa17f2501deab1862e382d6c83b484cda8..c30358541092324671ddfda2914fc59a004e8ede 100644 (file)
@@ -153,7 +153,7 @@ int session_accept_fd(struct listener *l, int cfd, struct sockaddr_storage *addr
        cli_conn->handle.fd = cfd;
        *cli_conn->src = *addr;
        cli_conn->flags |= CO_FL_ADDR_FROM_SET;
-       cli_conn->proxy_netns = l->netns;
+       cli_conn->proxy_netns = l->bind_conf->settings.netns;
 
        conn_prepare(cli_conn, l->proto, l->bind_conf->xprt);
        conn_ctrl_init(cli_conn);
index 5899d44b87a597589e7787b66af3593bed62ab34..a9dd5f2ff9ea3f6e817a11d487ae2ce711f0738b 100644 (file)
@@ -388,8 +388,8 @@ int sock_find_compatible_fd(const struct listener *l)
        if (l->bind_conf->settings.interface)
                if_namelen = strlen(l->bind_conf->settings.interface);
 #ifdef USE_NS
-       if (l->netns)
-               ns_namelen = l->netns->name_len;
+       if (l->bind_conf->settings.netns)
+               ns_namelen = l->bind_conf->settings.netns->name_len;
 #endif
 
        while (xfer_sock) {
@@ -398,7 +398,7 @@ int sock_find_compatible_fd(const struct listener *l)
                    (ns_namelen == xfer_sock->ns_namelen) &&
                    (!if_namelen || strcmp(l->bind_conf->settings.interface, xfer_sock->iface) == 0) &&
 #ifdef USE_NS
-                   (!ns_namelen || strcmp(l->netns->node.key, xfer_sock->namespace) == 0) &&
+                   (!ns_namelen || strcmp(l->bind_conf->settings.netns->node.key, xfer_sock->namespace) == 0) &&
 #endif
                    l->proto->addrcmp(&xfer_sock->addr, &l->addr) == 0)
                        break;
index 5f1aa1f9562559b0277607edebf56bb7afeb02f7..680987b4b8a001e3814f7fce9473adf965ae03cb 100644 (file)
@@ -137,7 +137,7 @@ int smp_fetch_dst_is_local(const struct arg *args, struct sample *smp, const cha
 
        smp->data.type = SMP_T_BOOL;
        smp->flags = 0;
-       smp->data.u.sint = addr_is_local(li->netns, conn->dst);
+       smp->data.u.sint = addr_is_local(li->bind_conf->settings.netns, conn->dst);
        return smp->data.u.sint >= 0;
 }
 
@@ -157,7 +157,7 @@ int smp_fetch_src_is_local(const struct arg *args, struct sample *smp, const cha
 
        smp->data.type = SMP_T_BOOL;
        smp->flags = 0;
-       smp->data.u.sint = addr_is_local(li->netns, conn->src);
+       smp->data.u.sint = addr_is_local(li->bind_conf->settings.netns, conn->src);
        return smp->data.u.sint >= 0;
 }