[PATCH] : Inversion for options

From: Krzysztof Oledzki <ole#ans.pl>
Date: Tue, 04 Dec 2007 23:18:49 +0100


[RFC]: Inversion for options

This RFC-quality patch adds a possibility to invert most of available options. It allows to use all options from a current defaults section except selected ones, for example:

listen stats 1.2.3.4:80

        option !contstats
--- cut here ---

The patch splits val into val (actual binary option id) and ival (implied option id) and moves ival and last_checks calculation at the and of the readcfgfile() function so it is possible to invert forceclose without breaking httpclose (and vice versa) and to invert tcpsplice in one proxy but to keep a proper last_checks value when tcpsplice is used in another proxy. I also decided to depreciate "redisp" and "redispatch" keywords as it is IMHO better to use "option redispatch" which can be inverted.

Some useful documentation were added and at the same time I sorted (alfabetically) all valid options both in the code and documentation.

diff --git a/doc/configuration.txt b/doc/configuration.txt index d37008b..6757909 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt

@@ -232,7 +232,8 @@ A "listen" section defines a complete proxy with its frontend and backend  parts combined in one section. It is generally useful for TCP-only traffic.  

 The following list of keywords is supported. Most of them may only be used in a -limited set of section types.
+limited set of section types. Options listed with [!] can be optionally
+inverted using the ! character (ex. option !contstats).
 

 keyword                 defaults   frontend   listen    backend
 ----------------------+----------+----------+---------+---------
@@ -263,31 +264,31 @@ maxconn                     X          X         X         -
 mode                        X          X         X         X
 monitor-net                 X          X         X         -
 monitor-uri                 X          X         X         -
-option abortonclose         X          -         X         X
-option allbackups           X          -         X         X
-option checkcache           X          -         X         X
-option clitcpka             X          X         X         -
-option contstats            X          X         X         -
-option dontlognull          X          X         X         -
-option forceclose           X          -         X         X

+option [!]abortonclose X - X X
+option [!]allbackups X - X X
+option [!]checkcache X - X X
+option [!]clitcpka X X X -
+option [!]contstats X X X -
+option [!]dontlognull X X X -
+option [!]forceclose X - X X
option forwardfor X X X X
+option [!]http_proxy X X X X
option httpchk X - X X -option httpclose X X X X
+option [!]httpclose X X X X
option httplog X X X X -option logasap X X X - -option nolinger X X X X -option http_proxy X X X X -option persist X - X X -option redispatch X - X X
+option [!]logasap X X X -
+option [!]nolinger X X X X
+option [!]persist X - X X
+option [!]redispatch X - X X
option smtpchk X - X X -option srvtcpka X - X X
+option [!]srvtcpka X - X X
option ssl-hello-chk X - X X option tcpka X X X X option tcplog X X X X -option tcpsplice X X X X -option transparent X X X - -redisp X - X X -redispatch X - X X
+option [!]tcpsplice X X X X
+option [!]transparent X X X -
+redisp(*1) X - X X
+redispatch(*1) X - X X
reqadd - X X X reqallow - X X X reqdel - X X X @@ -327,6 +328,7 @@ usesrc X - X X ----------------------+----------+----------+---------+--------- keyword defaults frontend listen backend

+ *1) deprecated, please use "option redispatch" instead.
 

 2.1) using ACLs



diff --git a/src/cfgparse.c b/src/cfgparse.c index 232ae1c..d3600ed 100644
--- a/src/cfgparse.c
+++ b/src/cfgparse.c

@@ -85,34 +85,34 @@ const char sslv3_client_hello_pkt[] = {  /* some of the most common options which are also the easiest to handle */  static const struct {
 	const char *name;
-	unsigned int val;

+ unsigned int val, ival;
unsigned int cap; unsigned int checks;

 } cfg_opts[] =
 {
-#ifdef TPROXY
-	{ "transparent",  PR_O_TRANSP,     PR_CAP_FE },
-#endif
-	{ "redispatch",   PR_O_REDISP,     PR_CAP_BE, 0 },
-	{ "keepalive",    PR_O_KEEPALIVE,  PR_CAP_NONE, 0 },
-	{ "httpclose",    PR_O_HTTP_CLOSE, PR_CAP_FE | PR_CAP_BE, 0 },
-	{ "nolinger",     PR_O_TCP_NOLING, PR_CAP_FE | PR_CAP_BE, 0 },
-	{ "http_proxy",	  PR_O_HTTP_PROXY, PR_CAP_FE | PR_CAP_BE, 0 },
-	{ "logasap",      PR_O_LOGASAP,    PR_CAP_FE, 0 },
-	{ "contstats",    PR_O_CONTSTATS,  PR_CAP_FE, 0 },
-	{ "abortonclose", PR_O_ABRT_CLOSE, PR_CAP_BE, 0 },
-	{ "checkcache",   PR_O_CHK_CACHE,  PR_CAP_BE, 0 },
-	{ "dontlognull",  PR_O_NULLNOLOG,  PR_CAP_FE, 0 },
-	{ "clitcpka",     PR_O_TCP_CLI_KA, PR_CAP_FE, 0 },
-	{ "srvtcpka",     PR_O_TCP_SRV_KA, PR_CAP_BE, 0 },
-	{ "allbackups",   PR_O_USE_ALL_BK, PR_CAP_BE, 0 },
-	{ "persist",      PR_O_PERSIST,    PR_CAP_BE, 0 },
-	{ "forceclose",   PR_O_FORCE_CLO | PR_O_HTTP_CLOSE, PR_CAP_BE, 0 },

+ { "abortonclose", PR_O_ABRT_CLOSE, 0, PR_CAP_BE, 0 },
+ { "allbackups", PR_O_USE_ALL_BK, 0, PR_CAP_BE, 0 },
+ { "checkcache", PR_O_CHK_CACHE, 0, PR_CAP_BE, 0 },
+ { "clitcpka", PR_O_TCP_CLI_KA, 0, PR_CAP_FE, 0 },
+ { "contstats", PR_O_CONTSTATS, 0, PR_CAP_FE, 0 },
+ { "dontlognull", PR_O_NULLNOLOG, 0, PR_CAP_FE, 0 },
+ { "forceclose", PR_O_FORCE_CLO, PR_O_HTTP_CLOSE, PR_CAP_BE, 0 },
+ { "http_proxy", PR_O_HTTP_PROXY, 0, PR_CAP_FE | PR_CAP_BE, 0 },
+ { "httpclose", PR_O_HTTP_CLOSE, 0, PR_CAP_FE | PR_CAP_BE, 0 },
+ { "keepalive", PR_O_KEEPALIVE, 0, PR_CAP_NONE, 0 },
+ { "logasap", PR_O_LOGASAP, 0, PR_CAP_FE, 0 },
+ { "nolinger", PR_O_TCP_NOLING, 0, PR_CAP_FE | PR_CAP_BE, 0 },
+ { "persist", PR_O_PERSIST, 0, PR_CAP_BE, 0 },
+ { "redispatch", PR_O_REDISP, 0, PR_CAP_BE, 0 },
+ { "srvtcpka", PR_O_TCP_SRV_KA, 0, PR_CAP_BE, 0 },
#ifdef CONFIG_HAP_TCPSPLICE - { "tcpsplice", PR_O_TCPSPLICE , PR_CAP_BE|PR_CAP_FE, LSTCHK_TCPSPLICE|LSTCHK_NETADM },
+ { "tcpsplice", PR_O_TCPSPLICE, 0, PR_CAP_BE|PR_CAP_FE, LSTCHK_TCPSPLICE|LSTCHK_NETADM },
+#endif
+#ifdef TPROXY
+ { "transparent", PR_O_TRANSP, 0, PR_CAP_FE, 0 },
 #endif  

@@ -1147,9 +1147,16 @@ int cfg_parse_listen(const char *file, int linenum, char **args)

 	}
 	else if (!strcmp(args[0], "option")) {
 		int optnum;

+ int inv;
- if (*(args[1]) == 0) { - Alert("parsing [%s:%d] : '%s' expects an option name.\n", file, linenum, args[0]);
+ if (*args[1] == '!') {
+ args[1]++;
+ inv=1;
+ } else
+ inv=0;
+
+ if (*(args[1]) == '\0') {
+ Alert("parsing [%s:%d]: expected option name.\n", file, linenum);
return -1; } @@ -1157,12 +1164,22 @@ int cfg_parse_listen(const char *file, int linenum, char **args) if (!strcmp(args[1], cfg_opts[optnum].name)) { if (warnifnotcap(curproxy, cfg_opts[optnum].cap, file, linenum, args[1], NULL)) return 0; - curproxy->options |= cfg_opts[optnum].val; - global.last_checks |= cfg_opts[optnum].checks;
+
+ if (!inv)
+ curproxy->options |= cfg_opts[optnum].val;
+ else
+ curproxy->options &= ~cfg_opts[optnum].val;
+
return 0; } }
+ if (inv) {
+ Alert("parsing [%s:%d]: option '%s' does not support inversion.\n",
+ file, linenum, args[1]);
+ return -1;
+ }
+
if (!strcmp(args[1], "httplog")) /* generate a complete HTTP log */ curproxy->to_log |= LW_DATE | LW_CLIP | LW_SVID | LW_REQ | LW_PXID | LW_RESP | LW_BYTES; @@ -1290,6 +1307,9 @@ int cfg_parse_listen(const char *file, int linenum, char **args) if (warnifnotcap(curproxy, PR_CAP_BE, file, linenum, args[0], NULL)) return 0;
+ Warning("parsing [%s:%d]: keyword '%s' is deprecated, please use 'option redispatch' instead.\n",
+ file, linenum, args[0]);
+
/* enable reconnections to dispatch */ curproxy->options |= PR_O_REDISP; }

@@ -2785,12 +2805,39 @@ int readcfgfile(const char *file)  
 		curproxy = curproxy->next;
 	}

+
if (cfgerr > 0) { Alert("Errors found in configuration file, aborting.\n"); return -1; } - else - return 0;
+
+ /*
+ * Add implied options and set required checks.
+ */
+
+ for(curproxy=proxy; curproxy; curproxy=curproxy->next) {
+ int optnum;
+ int iopts=0;
+
+ for (optnum = 0; cfg_opts[optnum].name; optnum++) {
+ if (!(curproxy->options & cfg_opts[optnum].val))
+ continue;
+
+#if 1 //tmp debug
+ Alert("proxy %s: %s\n", curproxy->id, cfg_opts[optnum].name);
+#endif
+
+ iopts |= cfg_opts[optnum].ival;
+ global.last_checks |= cfg_opts[optnum].checks;
+ }
+ curproxy->options |= iopts;
+ }
+
+#if 1 //tmp debug
+ Alert("global.last_checks=%X\n", global.last_checks);
+#endif
+
+ return 0;

 }     Received on 2007/12/04 23:18

This archive was generated by hypermail 2.2.0 : 2007/12/05 00:00 CET