[master] 741c872c7 vca: Pass higher-level types to sock_opt functions
Nils Goroll
nils.goroll at uplex.de
Tue Nov 23 12:31:11 UTC 2021
commit 741c872c756e8ed665f2e0c395aaae6c6aa295b3
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date: Mon Sep 27 08:19:09 2021 +0200
vca: Pass higher-level types to sock_opt functions
The sess and listen_sock structs contain everything we need to find or
infer the former `sock`, `uds` and `force` arguments. In particular, it
helps distinguish between working on a connection vs listen socket.
diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c
index a89f9e044..5669383ba 100644
--- a/bin/varnishd/cache/cache_acceptor.c
+++ b/bin/varnishd/cache/cache_acceptor.c
@@ -217,22 +217,25 @@ vca_sock_opt_init(void)
}
static void
-vca_sock_opt_test(const int sock, const unsigned uds)
+vca_sock_opt_test(const struct listen_sock *ls, const struct sess *sp)
{
int i, n;
struct sock_opt *so;
socklen_t l;
void *ptr;
+ CHECK_OBJ_NOTNULL(ls, LISTEN_SOCK_MAGIC);
+ CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
+
for (n = 0; n < n_sock_opts; n++) {
so = &sock_opts[n];
- if (so->level == IPPROTO_TCP && uds)
+ if (so->level == IPPROTO_TCP && ls->uds)
continue;
so->need = 1;
ptr = calloc(1, so->sz);
AN(ptr);
l = so->sz;
- i = getsockopt(sock, so->level, so->optname, ptr, &l);
+ i = getsockopt(sp->fd, so->level, so->optname, ptr, &l);
if (i == 0 && !memcmp(ptr, so->ptr, so->sz))
so->need = 0;
free(ptr);
@@ -242,16 +245,20 @@ vca_sock_opt_test(const int sock, const unsigned uds)
}
static void
-vca_sock_opt_set(const int sock, const unsigned uds, const int force)
+vca_sock_opt_set(const struct listen_sock *ls, const struct sess *sp)
{
- int n;
+ int n, sock;
struct sock_opt *so;
+ CHECK_OBJ_NOTNULL(ls, LISTEN_SOCK_MAGIC);
+ CHECK_OBJ_ORNULL(sp, SESS_MAGIC);
+ sock = sp != NULL ? sp->fd : ls->sock;
+
for (n = 0; n < n_sock_opts; n++) {
so = &sock_opts[n];
- if (so->level == IPPROTO_TCP && uds)
+ if (so->level == IPPROTO_TCP && ls->uds)
continue;
- if (so->need || force) {
+ if (so->need || sp == NULL) {
VTCP_Assert(setsockopt(sock,
so->level, so->optname, so->ptr, so->sz));
}
@@ -401,10 +408,10 @@ vca_make_session(struct worker *wrk, void *arg)
wrk->stats->sess_conn++;
if (need_test) {
- vca_sock_opt_test(sp->fd, wa->acceptlsock->uds);
+ vca_sock_opt_test(wa->acceptlsock, sp);
need_test = 0;
}
- vca_sock_opt_set(sp->fd, wa->acceptlsock->uds, 0);
+ vca_sock_opt_set(wa->acceptlsock, sp);
req = Req_New(wrk, sp);
CHECK_OBJ_NOTNULL(req, REQ_MAGIC);
@@ -596,7 +603,7 @@ vca_acct(void *arg)
if (ls->sock == -2)
continue; // VCA_Shutdown
assert (ls->sock > 0);
- vca_sock_opt_set(ls->sock, ls->uds, 1);
+ vca_sock_opt_set(ls, NULL);
}
AZ(pthread_mutex_unlock(&shut_mtx));
}
@@ -632,7 +639,7 @@ ccf_start(struct cli *cli, const char * const *av, void *priv)
ls->endpoint, VAS_errtxt(errno));
return;
}
- vca_sock_opt_set(ls->sock, ls->uds, 1);
+ vca_sock_opt_set(ls, NULL);
if (cache_param->accept_filter && VTCP_filter_http(ls->sock))
VSL(SLT_Error, 0,
"Kernel filtering: sock=%d, errno=%d %s",
More information about the varnish-commit
mailing list