MINOR: listener: move the network namespace to the struct settings

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.
This commit is contained in:
Willy Tarreau 2020-09-03 07:27:34 +02:00
parent 7e307215e8
commit be56c1038f
8 changed files with 18 additions and 22 deletions

View 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 */

View 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,17 +200,15 @@ 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) {
if (conf->settings.netns == NULL) {
ha_alert("Cannot open namespace '%s'.\n", args[cur_arg + 1]);
return ERR_ALERT | ERR_FATAL;
}
}
return 0;
}
#endif

View File

@ -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
}

View 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;

View 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";

View 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);

View 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;

View 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;
}