[master] 6a3398d Introduce "struct proto" which is opaque to the management process.

Poul-Henning Kamp phk at FreeBSD.org
Tue Feb 9 01:19:11 CET 2016


commit 6a3398d58224b5ea8c0860229b0aa8b72335f899
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Mon Feb 8 20:46:58 2016 +0000

    Introduce "struct proto" which is opaque to the management process.

diff --git a/bin/varnishd/Makefile.am b/bin/varnishd/Makefile.am
index 5c84034..d98065b 100644
--- a/bin/varnishd/Makefile.am
+++ b/bin/varnishd/Makefile.am
@@ -107,6 +107,7 @@ noinst_HEADERS = \
 	cache/cache_esi.h \
 	cache/cache_obj.h \
 	cache/cache_pool.h \
+	cache/cache_proto.h \
 	cache/cache_priv.h \
 	common/heritage.h \
 	hash/hash_slinger.h \
diff --git a/bin/varnishd/cache/cache.h b/bin/varnishd/cache/cache.h
index cfd17bb..7d3e2c7 100644
--- a/bin/varnishd/cache/cache.h
+++ b/bin/varnishd/cache/cache.h
@@ -618,6 +618,12 @@ enum sess_attr {
 	SA_LAST
 };
 
+enum sess_step {
+#define SESS_STEP(l, u)		S_STP_##u,
+#include "tbl/steps.h"
+#undef SESS_STEP
+};
+
 struct sess {
 	unsigned		magic;
 #define SESS_MAGIC		0x2c2f9c5a
diff --git a/bin/varnishd/cache/cache_acceptor.c b/bin/varnishd/cache/cache_acceptor.c
index 5588082..fa9a5ff 100644
--- a/bin/varnishd/cache/cache_acceptor.c
+++ b/bin/varnishd/cache/cache_acceptor.c
@@ -41,6 +41,7 @@
 #include <netinet/tcp.h>
 
 #include "cache.h"
+#include "cache_proto.h"
 #include "cache_pool.h"
 #include "common/heritage.h"
 
@@ -329,7 +330,7 @@ vca_make_session(struct worker *wrk, void *arg)
 
 	sp->fd = wa->acceptsock;
 	wa->acceptsock = -1;
-	sp->sess_step = wa->acceptlsock->first_step;
+	sp->sess_step = wa->acceptlsock->proto->first_step;
 
 	assert(wa->acceptaddrlen <= vsa_suckaddr_len);
 	SES_Reserve_remote_addr(sp, &sa);
@@ -494,6 +495,7 @@ vca_acct(void *arg)
 	(void)vca_tcp_opt_init();
 
 	VTAILQ_FOREACH(ls, &heritage.socks, list) {
+		CHECK_OBJ_NOTNULL(ls->proto, PROTO_MAGIC);
 		assert (ls->sock > 0);		// We know where stdin is
 		AZ(listen(ls->sock, cache_param->listen_depth));
 		vca_tcp_opt_set(ls->sock, 1);
diff --git a/bin/varnishd/cache/cache_proto.h b/bin/varnishd/cache/cache_proto.h
new file mode 100644
index 0000000..c432192
--- /dev/null
+++ b/bin/varnishd/cache/cache_proto.h
@@ -0,0 +1,34 @@
+/*-
+ * Copyright (c) 2016 Varnish Software AS
+ * All rights reserved.
+ *
+ * Author: Poul-Henning Kamp <phk at phk.freebsd.dk>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
+
+struct proto {
+	unsigned		magic;
+#define PROTO_MAGIC		0x711e77c1
+	enum sess_step		first_step;
+};
diff --git a/bin/varnishd/common/common.h b/bin/varnishd/common/common.h
index da489fc..0c23ddf 100644
--- a/bin/varnishd/common/common.h
+++ b/bin/varnishd/common/common.h
@@ -62,12 +62,6 @@ enum obj_flags {
 #undef OBJ_FLAG
 };
 
-enum sess_step {
-#define SESS_STEP(l, u)		S_STP_##u,
-#include "tbl/steps.h"
-#undef SESS_STEP
-};
-
 struct cli;
 
 /**********************************************************************
diff --git a/bin/varnishd/common/heritage.h b/bin/varnishd/common/heritage.h
index 42e9ec7..cbb8f9c 100644
--- a/bin/varnishd/common/heritage.h
+++ b/bin/varnishd/common/heritage.h
@@ -31,6 +31,7 @@
 
 struct vsm_sc;
 struct suckaddr;
+struct proto;
 
 struct listen_sock {
 	unsigned			magic;
@@ -39,10 +40,13 @@ struct listen_sock {
 	int				sock;
 	char				*name;
 	struct suckaddr			*addr;
-	enum sess_step			first_step;
+	const struct proto		*proto;
 	const char			*proto_name;
 };
 
+extern const struct proto VPX_proto;
+extern const struct proto HTTP1_proto;
+
 VTAILQ_HEAD(listen_sock_head, listen_sock);
 
 struct heritage {
diff --git a/bin/varnishd/http1/cache_http1_fsm.c b/bin/varnishd/http1/cache_http1_fsm.c
index 210be90..d86ba28 100644
--- a/bin/varnishd/http1/cache_http1_fsm.c
+++ b/bin/varnishd/http1/cache_http1_fsm.c
@@ -38,6 +38,7 @@
 #include <stdlib.h>
 
 #include "cache/cache.h"
+#include "cache/cache_proto.h"
 #include "cache_http1.h"
 #include "hash/hash_slinger.h"
 
@@ -285,3 +286,8 @@ HTTP1_Session(struct worker *wrk, struct req *req)
 
 	}
 }
+
+const struct proto HTTP1_proto = {
+	.magic =		PROTO_MAGIC,
+	.first_step =		S_STP_H1NEWSESS,
+};
diff --git a/bin/varnishd/mgt/mgt_acceptor.c b/bin/varnishd/mgt/mgt_acceptor.c
index 3cf1bbc..63adbac 100644
--- a/bin/varnishd/mgt/mgt_acceptor.c
+++ b/bin/varnishd/mgt/mgt_acceptor.c
@@ -117,7 +117,7 @@ struct mac_help {
 	int			good;
 	const char		*name;
 	const char		*proto_name;
-	enum sess_step		first_step;
+	const struct proto	*proto;
 };
 
 static int __match_proto__(vss_resolved_f)
@@ -141,7 +141,7 @@ mac_callback(void *priv, const struct suckaddr *sa)
 	ls->name = strdup(mh->name);
 	AN(ls->name);
 	ls->proto_name = mh->proto_name;
-	ls->first_step = mh->first_step;
+	ls->proto = mh->proto;
 	VTAILQ_INSERT_TAIL(&heritage.socks, ls, list);
 	mh->good++;
 	return (0);
@@ -197,12 +197,12 @@ MAC_Arg(const char *arg)
 	mh->name = av[1];
 
 	if (av[2] == NULL || !strcmp(av[2], "HTTP/1")) {
-		mh->first_step = S_STP_H1NEWSESS;
+		mh->proto = &HTTP1_proto;
 		mh->proto_name = "HTTP/1";
 		if (av[2] != NULL && av[3] != NULL)
 			ARGV_ERR("Too many sub-arguments to -a(HTTP/1)\n");
 	} else if (!strcmp(av[2], "PROXY")) {
-		mh->first_step = S_STP_PROXYNEWSESS;
+		mh->proto = &VPX_proto;
 		mh->proto_name = "PROXY";
 		if (av[3] != NULL)
 			ARGV_ERR("Too many sub-arguments to -a(PROXY)\n");
diff --git a/bin/varnishd/proxy/cache_proxy_proto.c b/bin/varnishd/proxy/cache_proxy_proto.c
index 4799e4b..a73f21a 100644
--- a/bin/varnishd/proxy/cache_proxy_proto.c
+++ b/bin/varnishd/proxy/cache_proxy_proto.c
@@ -39,6 +39,7 @@
 #include <string.h>
 
 #include "../cache/cache.h"
+#include "../cache/cache_proto.h"
 
 #include "vend.h"
 #include "vsa.h"
@@ -379,3 +380,8 @@ VPX_Proto_Sess(struct worker *wrk, void *priv)
 	wrk->task.func = SES_Proto_Req;
 	wrk->task.priv = req;
 }
+
+const struct proto VPX_proto = {
+	.magic =		PROTO_MAGIC,
+	.first_step =		S_STP_PROXYNEWSESS,
+};



More information about the varnish-commit mailing list