[master] f115bca Parameter definition must not depend upon defines

Nils Goroll nils.goroll at uplex.de
Mon Nov 28 18:55:05 CET 2016


commit f115bcad262c5464dceafe7fd616963b7a0b3f4f
Author: Nils Goroll <nils.goroll at uplex.de>
Date:   Mon Nov 28 17:48:41 2016 +0100

    Parameter definition must not depend upon defines
    
    Previously, unless HAVE_TCP_KEEP was defined equally for varnishd
    and an API client (vmod), the latter used a wrong struct declaration
    and, consequently, struct params members were accessed at a wrong
    location. This could have adverse effects from reading bogus
    values to overwriting wrong parameters or other memory.
    
    For consistency, we keep uninplemented parameters also in the
    cli and rst output with an appropriate description.
    
    Setting them over the cli is not an error, but has no effect.

diff --git a/bin/varnishd/mgt/mgt_param.c b/bin/varnishd/mgt/mgt_param.c
index dc247b4..a6411ab 100644
--- a/bin/varnishd/mgt/mgt_param.c
+++ b/bin/varnishd/mgt/mgt_param.c
@@ -97,6 +97,10 @@ static const char ONLY_ROOT_TEXT[] =
 	"\n\n"
 	"NB: This parameter only works if varnishd is run as root.";
 
+static const char NOT_IMPLEMENTED_TEXT[] =
+	"This parameter depends on a feature which is not available"
+	" on this platform.";
+
 /*--------------------------------------------------------------------*/
 
 static struct parspec *
@@ -257,19 +261,34 @@ mcf_param_show(struct cli *cli, const char * const *av, void *priv)
 		if (chg && pp->def != NULL && !strcmp(pp->def, VSB_data(vsb)))
 			continue;
 
-		if (lfmt) {
-			VCLI_Out(cli, "%s\n", pp->name);
-			VCLI_Out(cli, "%-*sValue is: ", margin1, " ");
+		if (pp->flags & NOT_IMPLEMENTED) {
+			if (lfmt) {
+				VCLI_Out(cli, "%s\n", pp->name);
+				VCLI_Out(cli, "%-*sNot available", margin1, " ");
+			} else {
+				VCLI_Out(cli, "%-*s-", margin2, pp->name);
+			}
 		} else {
-			VCLI_Out(cli, "%-*s", margin2, pp->name);
+			if (lfmt) {
+				VCLI_Out(cli, "%s\n", pp->name);
+				VCLI_Out(cli, "%-*sValue is: ", margin1, " ");
+			} else {
+				VCLI_Out(cli, "%-*s", margin2, pp->name);
+			}
+
+			VCLI_Out(cli, "%s", VSB_data(vsb));
+			if (pp->units != NULL && *pp->units != '\0')
+				VCLI_Out(cli, " [%s]", pp->units);
+			if (pp->def != NULL && !strcmp(pp->def, VSB_data(vsb)))
+				VCLI_Out(cli, " (default)");
 		}
-		VCLI_Out(cli, "%s", VSB_data(vsb));
-		if (pp->units != NULL && *pp->units != '\0')
-			VCLI_Out(cli, " [%s]", pp->units);
-		if (pp->def != NULL && !strcmp(pp->def, VSB_data(vsb)))
-			VCLI_Out(cli, " (default)");
 		VCLI_Out(cli, "\n");
-		if (lfmt) {
+
+		if (lfmt && pp->flags & NOT_IMPLEMENTED) {
+			VCLI_Out(cli, "\n");
+			mcf_wrap(cli, NOT_IMPLEMENTED_TEXT);
+			VCLI_Out(cli, "\n\n");
+		} else if (lfmt) {
 			if (pp->def != NULL && strcmp(pp->def, VSB_data(vsb)))
 				VCLI_Out(cli, "%-*sDefault is: %s\n",
 				    margin1, "", pp->def);
@@ -466,6 +485,8 @@ MCF_InitParams(struct cli *cli)
 	VTAILQ_FOREACH(pl, &phead, list) {
 		pp = pl->spec;
 
+		if (pp->flags & NOT_IMPLEMENTED)
+			continue;
 		if (pp->min != NULL)
 			mcf_wash_param(cli, pp, &pp->min, "minimum", vsb);
 		if (pp->max != NULL)
@@ -540,6 +561,13 @@ MCF_DumpRstParam(void)
 		for (j = 0; j < strlen(pp->name); j++)
 			printf("~");
 		printf("\n");
+
+		if (pp->flags && pp->flags & NOT_IMPLEMENTED) {
+			printf("\nNot Available: %s\n\n",
+			    NOT_IMPLEMENTED_TEXT);
+			continue;
+		}
+
 		if (pp->units != NULL && *pp->units != '\0')
 			printf("\t* Units: %s\n", pp->units);
 		printf("\t* Default: %s\n", pp->def);
@@ -555,6 +583,9 @@ MCF_DumpRstParam(void)
 		if (pp->flags) {
 			printf("\t* Flags: ");
 			q = "";
+
+			AZ(pp->flags & NOT_IMPLEMENTED);
+
 			if (pp->flags & DELAYED_EFFECT) {
 				printf("%sdelayed", q);
 				q = ", ";
diff --git a/bin/varnishd/mgt/mgt_param.h b/bin/varnishd/mgt/mgt_param.h
index 58b2dd6..855ba58 100644
--- a/bin/varnishd/mgt/mgt_param.h
+++ b/bin/varnishd/mgt/mgt_param.h
@@ -48,6 +48,8 @@ struct parspec {
 #define PROTECTED	(1<<5)
 #define OBJ_STICKY	(1<<6)
 #define ONLY_ROOT	(1<<7)
+#define NOT_IMPLEMENTED	(1<<8)
+
 	const char	*def;
 	const char	*units;
 };
diff --git a/include/tbl/params.h b/include/tbl/params.h
index bf1080d..50a754a 100644
--- a/include/tbl/params.h
+++ b/include/tbl/params.h
@@ -1008,6 +1008,11 @@ PARAM(
 )
 
 #if defined(HAVE_TCP_KEEP)
+#define TCP_KEEP_FLAGS	EXPERIMENTAL
+#else
+#define TCP_KEEP_FLAGS	NOT_IMPLEMENTED
+#endif
+
 PARAM(
 	/* name */	tcp_keepalive_intvl,
 	/* typ */	timeout,
@@ -1015,7 +1020,7 @@ PARAM(
 	/* max */	"100",
 	/* default */	"",
 	/* units */	"seconds",
-	/* flags */	EXPERIMENTAL,
+	/* flags */	TCP_KEEP_FLAGS,
 	/* s-text */
 	"The number of seconds between TCP keep-alive probes.",
 	/* l-text */	"",
@@ -1029,7 +1034,7 @@ PARAM(
 	/* max */	"100",
 	/* default */	"",
 	/* units */	"probes",
-	/* flags */	EXPERIMENTAL,
+	/* flags */	TCP_KEEP_FLAGS,
 	/* s-text */
 	"The maximum number of TCP keep-alive probes to send before giving "
 	"up and killing the connection if no response is obtained from the "
@@ -1045,7 +1050,7 @@ PARAM(
 	/* max */	"7200",
 	/* default */	"",
 	/* units */	"seconds",
-	/* flags */	EXPERIMENTAL,
+	/* flags */	TCP_KEEP_FLAGS,
 	/* s-text */
 	"The number of seconds a connection needs to be idle before TCP "
 	"begins sending out keep-alive probes.",
@@ -1053,8 +1058,6 @@ PARAM(
 	/* func */	NULL
 )
 
-#endif /* HAVE_TCP_KEEP */
-
 #if 0
 /* actual location mgt_pool.c */
 PARAM(



More information about the varnish-commit mailing list