]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: listener: move the interface to the struct settings
authorWilly Tarreau <w@1wt.eu>
Thu, 3 Sep 2020 05:23:34 +0000 (07:23 +0200)
committerWilly Tarreau <w@1wt.eu>
Wed, 16 Sep 2020 18:13:13 +0000 (20:13 +0200)
The interface 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 unnecessary loops.

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

index 45f30d38723dbab4dfaec7d89754c0e1a4136b89..9d0db4e536879c7d63a0a2d984cdb48cdebf8ae0 100644 (file)
@@ -186,6 +186,7 @@ struct bind_conf {
                        gid_t gid;         /* -1 to leave unchanged */
                        mode_t mode;       /* 0 to leave unchanged */
                } ux;
+               char *interface;           /* interface name or NULL */
        } settings;                /* all the settings needed for the listening socket */
 };
 
@@ -214,7 +215,6 @@ struct listener {
        unsigned int analysers;         /* bitmap of required protocol analysers */
        int maxseg;                     /* for TCP, advertised MSS */
        int tcp_ut;                     /* for TCP, user timeout */
-       char *interface;                /* interface name or NULL */
        char *name;                     /* listener's name */
 
        __decl_thread(HA_SPINLOCK_T lock);
index c13674b7c25c0ec2fab218798f8458e7483dd5d6..033a3bdbb35d19bbbd3828fc661858861bef5403 100644 (file)
@@ -178,18 +178,12 @@ static int bind_parse_tcp_ut(char **args, int cur_arg, struct proxy *px, struct
 /* parse the "interface" bind keyword */
 static int bind_parse_interface(char **args, int cur_arg, struct proxy *px, struct bind_conf *conf, char **err)
 {
-       struct listener *l;
-
        if (!*args[cur_arg + 1]) {
                memprintf(err, "'%s' : missing interface name", args[cur_arg]);
                return ERR_ALERT | ERR_FATAL;
        }
 
-       list_for_each_entry(l, &conf->listeners, by_bind) {
-               if (l->addr.ss_family == AF_INET || l->addr.ss_family == AF_INET6)
-                       l->interface = strdup(args[cur_arg + 1]);
-       }
-
+       conf->settings.interface = strdup(args[cur_arg + 1]);
        return 0;
 }
 #endif
index a455be148dfcd53ccb33ac0210ee46da949616d0..d7ec79aba4c3d2b14b6ecc145d86b0c84bf3c6bb 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -1710,8 +1710,8 @@ static int _getsocks(char **args, char *payload, struct appctx *appctx, void *pr
                if (fdtab[cur_fd].iocb == listener_accept) {
                        const struct listener *l = fdtab[cur_fd].owner;
 
-                       if (l->interface) {
-                               if_name = l->interface;
+                       if (l->bind_conf->settings.interface) {
+                               if_name = l->bind_conf->settings.interface;
                                if_nlen = strlen(if_name);
                        }
 
index 57bef860076821ee5686c4a87fd6d36a253aed20..7be68820ca9a0453dcc9d1c17e497d6cf9e1d9ec 100644 (file)
@@ -649,9 +649,10 @@ int tcp_bind_listener(struct listener *listener, char *errmsg, int errlen)
 
 #ifdef SO_BINDTODEVICE
        /* Note: this might fail if not CAP_NET_RAW */
-       if (!ext && listener->interface) {
+       if (!ext && listener->bind_conf->settings.interface) {
                if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,
-                              listener->interface, strlen(listener->interface) + 1) == -1) {
+                              listener->bind_conf->settings.interface,
+                              strlen(listener->bind_conf->settings.interface) + 1) == -1) {
                        msg = "cannot bind listener to device";
                        err |= ERR_WARN;
                }
index 5ec8bc742a23795a23652024312f6adde4290649..5337ac4bd3e80ec06955a4ab7848744eb279ae08 100644 (file)
@@ -252,9 +252,10 @@ int udp_bind_listener(struct listener *listener, char *errmsg, int errlen)
 
 #ifdef SO_BINDTODEVICE
        /* Note: this might fail if not CAP_NET_RAW */
-       if (listener->interface) {
+       if (listener->bind_conf->settings.interface) {
                if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,
-                              listener->interface, strlen(listener->interface) + 1) == -1) {
+                              listener->bind_conf->settings.interface,
+                              strlen(listener->bind_conf->settings.interface) + 1) == -1) {
                        msg = "cannot bind listener to device";
                        err |= ERR_WARN;
                }
index 1614d954271554fee78bf03c8ad3236fe8edb806..5899d44b87a597589e7787b66af3593bed62ab34 100644 (file)
@@ -385,8 +385,8 @@ int sock_find_compatible_fd(const struct listener *l)
                        options |= SOCK_XFER_OPT_V6ONLY;
        }
 
-       if (l->interface)
-               if_namelen = strlen(l->interface);
+       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;
@@ -396,7 +396,7 @@ int sock_find_compatible_fd(const struct listener *l)
                if ((options == xfer_sock->options) &&
                    (if_namelen == xfer_sock->if_namelen) &&
                    (ns_namelen == xfer_sock->ns_namelen) &&
-                   (!if_namelen || strcmp(l->interface, xfer_sock->iface) == 0) &&
+                   (!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) &&
 #endif