summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilly Tarreau <w@1wt.eu>2020-08-27 07:53:59 +0200
committerWilly Tarreau <w@1wt.eu>2020-09-02 11:38:45 +0200
commit01ed7dd81c6bb06bcf1686c52aff650cd559bdc6 (patch)
treebfbeda5ae02510a558f117633d727caa72523017
parent70adc36a58f4b945c5116766816425aa96fb5beb (diff)
downloadhaproxy-01ed7dd81c6bb06bcf1686c52aff650cd559bdc6.tar.gz
REORG: listeners: move the network namespace to struct receiver
The netns completes the address since the address' scope is valid within a namespace, so it must be stored with it.
-rw-r--r--include/haproxy/listener-t.h8
-rw-r--r--src/cfgparse-tcp.c8
-rw-r--r--src/cli.c6
-rw-r--r--src/proto_tcp.c2
-rw-r--r--src/proto_udp.c2
-rw-r--r--src/session.c2
-rw-r--r--src/sock.c6
-rw-r--r--src/tcp_sample.c4
8 files changed, 17 insertions, 21 deletions
diff --git a/include/haproxy/listener-t.h b/include/haproxy/listener-t.h
index bdc223bef..ae0a8b3ee 100644
--- a/include/haproxy/listener-t.h
+++ b/include/haproxy/listener-t.h
@@ -191,8 +191,9 @@ struct bind_conf {
struct receiver {
int options; /* receiver options (RX_O_*) */
+ const struct netns_entry *netns; /* network namespace of the receiving socket */
/* warning: this struct is huge, keep it at the bottom */
- struct sockaddr_storage addr; /* the address the socket is bound to */
+ struct sockaddr_storage addr; /* the address the socket is bound to */
};
/* The listener will be directly referenced by the fdtab[] which holds its
@@ -225,13 +226,8 @@ 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 */
- /* cache line boundary */
-
struct list by_fe; /* chaining in frontend's list of listeners */
struct list by_bind; /* chaining in bind_conf's list of listeners */
struct bind_conf *bind_conf; /* "bind" line settings, include SSL settings among other things */
diff --git a/src/cfgparse-tcp.c b/src/cfgparse-tcp.c
index c4e77eb68..724a54035 100644
--- a/src/cfgparse-tcp.c
+++ b/src/cfgparse-tcp.c
@@ -208,12 +208,12 @@ 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));
+ l->rx.netns = netns_store_lookup(namespace, strlen(namespace));
- if (l->netns == NULL)
- l->netns = netns_store_insert(namespace);
+ if (l->rx.netns == NULL)
+ l->rx.netns = netns_store_insert(namespace);
- if (l->netns == NULL) {
+ if (l->rx.netns == NULL) {
ha_alert("Cannot open namespace '%s'.\n", args[cur_arg + 1]);
return ERR_ALERT | ERR_FATAL;
}
diff --git a/src/cli.c b/src/cli.c
index 05ffd6563..45383e12d 100644
--- 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->rx.netns) {
+ ns_name = l->rx.netns->node.key;
+ ns_nlen = l->rx.netns->name_len;
}
#endif
}
diff --git a/src/proto_tcp.c b/src/proto_tcp.c
index 77004e3af..76a02a3e1 100644
--- a/src/proto_tcp.c
+++ b/src/proto_tcp.c
@@ -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->rx.addr.ss_family, SOCK_STREAM, IPPROTO_TCP);
+ fd = my_socketat(listener->rx.netns, listener->rx.addr.ss_family, SOCK_STREAM, IPPROTO_TCP);
if (fd == -1) {
err |= ERR_RETRYABLE | ERR_ALERT;
diff --git a/src/proto_udp.c b/src/proto_udp.c
index 47a3971e2..2d12e6f03 100644
--- a/src/proto_udp.c
+++ b/src/proto_udp.c
@@ -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->rx.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";
diff --git a/src/session.c b/src/session.c
index b57ba190c..3c2268239 100644
--- a/src/session.c
+++ b/src/session.c
@@ -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->rx.netns;
conn_prepare(cli_conn, l->proto, l->bind_conf->xprt);
conn_ctrl_init(cli_conn);
diff --git a/src/sock.c b/src/sock.c
index a2ce50b87..c9b086832 100644
--- a/src/sock.c
+++ b/src/sock.c
@@ -388,8 +388,8 @@ int sock_find_compatible_fd(const struct listener *l)
if (l->interface)
if_namelen = strlen(l->interface);
#ifdef USE_NS
- if (l->netns)
- ns_namelen = l->netns->name_len;
+ if (l->rx.netns)
+ ns_namelen = l->rx.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->interface, xfer_sock->iface) == 0) &&
#ifdef USE_NS
- (!ns_namelen || strcmp(l->netns->node.key, xfer_sock->namespace) == 0) &&
+ (!ns_namelen || strcmp(l->rx.netns->node.key, xfer_sock->namespace) == 0) &&
#endif
l->proto->addrcmp(&xfer_sock->addr, &l->rx.addr) == 0)
break;
diff --git a/src/tcp_sample.c b/src/tcp_sample.c
index 5f1aa1f95..66b0b055e 100644
--- a/src/tcp_sample.c
+++ b/src/tcp_sample.c
@@ -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->rx.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->rx.netns, conn->src);
return smp->data.u.sint >= 0;
}