[PATCH] fix several typos in doc/configuration.txt

2020-02-28 Thread Илья Шипицин
Hello,

patch is based on automatic spellcheck

Ilya Shipitcin
From c7f7e0ef97186cec64f43c34f9be896a50ffdc2f Mon Sep 17 00:00:00 2001
From: Ilya Shipitsin 
Date: Sat, 29 Feb 2020 12:34:59 +0500
Subject: [PATCH] CLEANUP: doc/configuration.txt: fix typos

---
 doc/configuration.txt | 36 ++--
 1 file changed, 18 insertions(+), 18 deletions(-)

diff --git a/doc/configuration.txt b/doc/configuration.txt
index b60a8d45c..0a03da780 100644
--- a/doc/configuration.txt
+++ b/doc/configuration.txt
@@ -872,7 +872,7 @@ h1-case-adjust  
   , to change it to  before sending it to HTTP/1 clients or
   servers.  must be in lower case, and  and  must not differ
   except for their case. It may be repeated if several header names need to be
-  ajusted. Duplicate entries are not allowed. If a lot of header names have to
+  adjusted. Duplicate entries are not allowed. If a lot of header names have to
   be adjusted, it might be more convenient to use "h1-case-adjust-file".
   Please note that no transformation will be applied unless "option
   h1-case-adjust-bogus-client" or "option h1-case-adjust-bogus-server" is
@@ -1341,7 +1341,7 @@ ssl-load-extra-files *
   try to gather the files with the same basename in a multi-certificate bundle.
   The bundles were introduced with OpenSSL 1.0.2 and were the only way back
   then to load an ECDSA certificate and a RSA one, with the same SNI. Since
-  OpenSSL 1.1.1 it is not recommended anymore, you can specifiy both the ECDSA
+  OpenSSL 1.1.1 it is not recommended anymore, you can specify both the ECDSA
   and the RSA file on the bind line.
 
   "sctl": Try to load ".sctl" for each crt keyword.
@@ -4338,7 +4338,7 @@ http-after-response strict-mode { on | off }
   performing a rewrite on the responses. When the strict mode is enabled, any
   rewrite failure triggers an internal error. Otherwise, such errors are
   silently ignored. The purpose of the strict rewriting mode is to make some
-  rewrites optionnal while others must be performed to continue the response
+  rewrites optional while others must be performed to continue the response
   processing.
 
   By default, the strict rewriting mode is enabled. Its value is also reset
@@ -4753,7 +4753,7 @@ http-request reject [ { if | unless }  ]
 http-request replace-header   
 [ { if | unless }  ]
 
-  This matches the value of all occurences of header field  against
+  This matches the value of all occurrences of header field  against
   . Matching is performed case-sensitively. Matching values are
   completely replaced by . Format characters are allowed in
and work like  arguments in "http-request add-header".
@@ -4863,12 +4863,12 @@ http-request return [status ] [content-type ]
 	  [ hdr   ]*
   [ { if | unless }  ]
 
-  This stops the evaluation of the rules and immediatly returns a response. The
+  This stops the evaluation of the rules and immediately returns a response. The
   default status code used for the response is 200. It can be optionally
   specified as an arguments to "status". The response content-type may also be
   specified as an argument to "content-type". Finally the response itselft may
   be defined. If can be a full HTTP response specifying the errorfile to use,
-  or the response payload specifing the file or the string to use. These rules
+  or the response payload specifying the file or the string to use. These rules
   are followed to create the response :
 
   * If neither the errorfile nor the payload to use is defined, a dummy
@@ -5222,7 +5222,7 @@ http-request strict-mode { on | off }
   performing a rewrite on the requests. When the strict mode is enabled, any
   rewrite failure triggers an internal error. Otherwise, such errors are
   silently ignored. The purpose of the strict rewriting mode is to make some
-  rewrites optionnal while others must be performed to continue the request
+  rewrites optional while others must be performed to continue the request
   processing.
 
   By default, the strict rewriting mode is enabled. Its value is also reset
@@ -5493,12 +5493,12 @@ http-response return [status ] [content-type ]
 	  [ hdr   ]*
   [ { if | unless }  ]
 
-  This stops the evaluation of the rules and immediatly returns a response. The
+  This stops the evaluation of the rules and immediately returns a response. The
   default status code used for the response is 200. It can be optionally
   specified as an arguments to "status". The response content-type may also be
   specified as an argument to "content-type". Finally the response itselft may
   be defined. If can be a full HTTP response specifying the errorfile to use,
-  or the response payload specifing the file or the string to use. These rules
+  or the response payload specifying the file or the string to use. These rules
   are followed to create the response :
 
   * If neither the errorfile nor the payload to use is defined, a dummy
@@ -5711,7 +5711,7 @@ ht

Re: SRV Record Priority Values

2020-02-28 Thread Luke Seelenbinder
Hi Baptiste,

> What this means is that backup status would use priority 0 or 1 or some kind 
> of. But we burn the remaining 65534 values from this field.

That's a concern, for sure.

> I also think we wanted to have "server groups" first in HAProxy before using 
> the priority. The idea before server groups is that a bunch of server should 
> be used all together until they fail (or enough have failed), and in such 
> case, we want to fail over to the next group, and so on (unless first group 
> recovers, of course).

This would be amazing for us! We're struggling with occasionally having all 
servers "up" in a pool (but struggling), and requests not getting moved to the 
next (backup) pool when they fail. Having groups we could use to control 
failover more closely would be really nice for us. SRV records, or not. :)

> What we can do for now, is consider "active" a priority 0 and backup, any 
> value greater than 0.

I think that's perfectly acceptable for us. I'm not sure of anyone else on the 
mailing list using SRV records, so I don't know who else we could ask about 
that.

Would I have all I need to begin a patch for this in src/dns.c or will it 
require bringing in more pieces to accomplish the task? If it's going to be 
involved, a few pointers before I dive in would be helpful. My C is rusty 
(using mostly Rust now, anyways ;-) ), and my knowledge of the HAProxy codebase 
is weak right now.

Best,
Luke

—
Luke Seelenbinder
Stadia Maps | Founder
stadiamaps.com

> On 28 Feb 2020, at 09:44, Baptiste  wrote:
> 
>> I suspect that it's more a property of the resolvers than the servers.
>> I mean, if you know that you're using your DNS servers this way, this
>> should really have the same meaning for all servers. So you shouldn't
>> have a per-server option to adjust this behavior but a per-resolvers
>> section.
> 
> That's even better! And probably more easily implemented. I'll wait for 
> Baptiste's response.
> 
> Hi There,
> 
> When we first designed support for SRV record, we thought about use cases for 
> this "priority" field.
> That said, at that time, the conclusion was some kind of "it is not possible 
> to match a 'backup' state with an integer, or it is a "waste" of information".
> What this means is that backup status would use priority 0 or 1 or some kind 
> of. But we burn the remaining 65534 values from this field.
> I also think we wanted to have "server groups" first in HAProxy before using 
> the priority. The idea before server groups is that a bunch of server should 
> be used all together until they fail (or enough have failed), and in such 
> case, we want to fail over to the next group, and so on (unless first group 
> recovers, of course). Then, priority could be used to set up the groups, 
> cause HAProxy would assign al server with same priority in the same group.
> 
> What we can do for now, is consider "active" a priority 0 and backup, any 
> value greater than 0.
> 
> Baptiste



Re: using variables in reg-tests

2020-02-28 Thread William Lallemand
Hi Ilya,

On Fri, Feb 28, 2020 at 10:18:10AM +0100, Christopher Faulet wrote:
> Le 28/02/2020 à 09:32, Илья Шипицин a écrit :
> > reg-tests keep logs in ${TMPDIR}
> > 
> > in travis-ci we output logs on failure
> > 
> > after_failure:
> >    - |
> >      for folder in ${TMPDIR}/*regtest*/vtc.*; do
> >        cat $folder/INFO
> >        cat $folder/LOG
> >      done
> > 
> > 
> > 
> > is it ok not to clean ${TMPDIR} between two runs ? (as far as I understand, 
> > each 
> > test run generates unique id, so it should be ok)
> > 
> > 
> 
> Yes, it is safe to keep temp directories between 2 runs.
> 
> 

Not sure what you are trying to do, but keep in mind that the HTTP
legacy support was removed in 2.1, so you can't use 
"no option http-use-htx" anymore.

-- 
William Lallemand



[PATCH v3 4/7] MINOR: ist: Add `struct ist ist_NULL()`

2020-02-28 Thread Tim Duesterhus
`ist_NULL()` returns an `struct ist` with `.ptr = NULL` and `.len = 0`.
---
 include/common/ist.h | 8 +++-
 src/hpack-dec.c  | 4 ++--
 src/http.c   | 4 ++--
 src/http_htx.c   | 2 +-
 4 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/include/common/ist.h b/include/common/ist.h
index 0d8b45721..4d75d8607 100644
--- a/include/common/ist.h
+++ b/include/common/ist.h
@@ -183,6 +183,12 @@ static inline struct ist ist2(const void *ptr, size_t len)
return (struct ist){ .ptr = (char *)ptr, .len = len };
 }
 
+/* returns an `ist` with `.ptr = NULL` and `.len = 0` */
+static inline struct ist ist_NULL()
+{
+   return ist2(NULL, 0);
+}
+
 /* This function MODIFIES the string to add a zero AFTER the end, and returns
  * the start pointer. The purpose is to use it on strings extracted by parsers
  * from larger strings cut with delimiters that are not important and can be
@@ -705,7 +711,7 @@ static inline struct ist istist(const struct ist ist, const 
struct ist pat)
}
return ist2(ret.ptr - 1, ret.len + 1);
}
-   return ist2(NULL, 0);
+   return ist_NULL();
 }
 
 /*
diff --git a/src/hpack-dec.c b/src/hpack-dec.c
index a721fadc4..ab757de29 100644
--- a/src/hpack-dec.c
+++ b/src/hpack-dec.c
@@ -406,7 +406,7 @@ int hpack_decode_frame(struct hpack_dht *dht, const uint8_t 
*raw, uint32_t len,
value = ist2(vtrash, vlen);
}
 
-   name = ist2(NULL, 0);
+   name = ist_NULL();
if (!must_index)
name.len = hpack_idx_to_phdr(idx);
 
@@ -458,7 +458,7 @@ int hpack_decode_frame(struct hpack_dht *dht, const uint8_t 
*raw, uint32_t len,
}
 
/* put an end marker */
-   list[ret].n = list[ret].v = ist2(NULL, 0);
+   list[ret].n = list[ret].v = ist_NULL();
ret++;
 
  leave:
diff --git a/src/http.c b/src/http.c
index 75251992a..a122ef732 100644
--- a/src/http.c
+++ b/src/http.c
@@ -551,7 +551,7 @@ struct ist http_get_authority(const struct ist uri, int 
no_userinfo)
return ist2(start, end - start);
 
   not_found:
-   return ist2(NULL, 0);
+   return ist_NULL();
 }
 
 /* Parse the URI from the given transaction (which is assumed to be in request
@@ -601,7 +601,7 @@ struct ist http_get_path(const struct ist uri)
return ist2(ptr, end - ptr);
 
  not_found:
-   return ist2(NULL, 0);
+   return ist_NULL();
 }
 
 /*
diff --git a/src/http_htx.c b/src/http_htx.c
index 35bb05625..a4829ff81 100644
--- a/src/http_htx.c
+++ b/src/http_htx.c
@@ -533,7 +533,7 @@ int http_remove_header(struct htx *htx, struct http_hdr_ctx 
*ctx)
blk = htx_remove_blk(htx, blk);
if (blk || htx_is_empty(htx)) {
ctx->blk = blk;
-   ctx->value = ist2(NULL, 0);
+   ctx->value = ist_NULL();
ctx->lws_before = ctx->lws_after = 0;
}
else {
-- 
2.25.1




[PATCH v3 1/7] REGTEST: Add unique-id reg-test

2020-02-28 Thread Tim Duesterhus
This reg-test verifies the following behavior:

1. That unique IDs are stable (i.e. the bug fixed in 
530408f976e5fe2f2f2b4b733b39da36770b566f)
2. That unique IDs can use values from the HTTP request (see 
https://www.mail-archive.com/haproxy@formilux.org/msg36436.html)
---
 reg-tests/stream/unique-id.vtc | 47 ++
 1 file changed, 47 insertions(+)
 create mode 100644 reg-tests/stream/unique-id.vtc

diff --git a/reg-tests/stream/unique-id.vtc b/reg-tests/stream/unique-id.vtc
new file mode 100644
index 0..1ff12c7d6
--- /dev/null
+++ b/reg-tests/stream/unique-id.vtc
@@ -0,0 +1,47 @@
+varnishtest "unique-id test"
+
+feature ignore_unknown_macro
+
+server s1 {
+rxreq
+txresp
+} -repeat 2 -start
+
+haproxy h1 -conf {
+defaults
+mode http
+timeout connect 1s
+timeout client  1s
+timeout server  1s
+
+frontend stable
+bind "fd@${fe1}"
+unique-id-format TEST-%[uuid]
+http-response set-header A %[unique-id]
+http-response set-header B %[unique-id]
+default_backend be
+
+frontend request_data
+bind "fd@${fe2}"
+unique-id-format TEST-%[req.hdr(in)]
+http-response set-header out %[unique-id]
+default_backend be
+
+backend be
+server srv1 ${s1_addr}:${s1_port}
+} -start
+
+client c1 -connect ${h1_fe1_sock} {
+txreq -url "/"
+rxresp
+expect resp.status == 200
+expect resp.http.a == resp.http.b
+} -run
+
+client c2 -connect ${h1_fe2_sock} {
+txreq -url "/" \
+  -hdr "in: 12345678"
+rxresp
+expect resp.status == 200
+expect resp.http.out == "TEST-12345678"
+} -run
-- 
2.25.1




[PATCH v3 3/7] MINOR: stream: Use stream_generate_unique_id

2020-02-28 Thread Tim Duesterhus
This patch replaces the ad-hoc generation of stream's `unique_id` values
by calls to `stream_generate_unique_id`.
---
 src/http_ana.c   | 27 ---
 src/http_fetch.c | 17 -
 src/log.c|  3 +--
 3 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/src/http_ana.c b/src/http_ana.c
index 20c7b6e50..094208d63 100644
--- a/src/http_ana.c
+++ b/src/http_ana.c
@@ -787,24 +787,29 @@ int http_process_request(struct stream *s, struct channel 
*req, int an_bit)
if (s->be->cookie_name || sess->fe->capture_name)
http_manage_client_side_cookies(s, req);
 
-   /* add unique-id if "header-unique-id" is specified */
+   /* 8: Generate unique ID if a "unique-id-format" is defined.
+*
+* A unique ID is generated even when it is not sent to ensure that the 
ID can make use of
+* fetches only available in the HTTP request processing stage.
+*/
+   if (!LIST_ISEMPTY(&sess->fe->format_unique_id)) {
+   int length;
 
-   if (!LIST_ISEMPTY(&sess->fe->format_unique_id) && !s->unique_id) {
-   if ((s->unique_id = pool_alloc(pool_head_uniqueid)) == NULL) {
+   if ((length = stream_generate_unique_id(s, 
&sess->fe->format_unique_id)) < 0) {
if (!(s->flags & SF_ERR_MASK))
s->flags |= SF_ERR_RESOURCE;
goto return_int_err;
}
-   s->unique_id[0] = '\0';
-   build_logline(s, s->unique_id, UNIQUEID_LEN, 
&sess->fe->format_unique_id);
-   }
 
-   if (sess->fe->header_unique_id && s->unique_id) {
-   struct ist n = ist2(sess->fe->header_unique_id, 
strlen(sess->fe->header_unique_id));
-   struct ist v = ist2(s->unique_id, strlen(s->unique_id));
+   /* send unique ID if a "unique-id-header" is defined */
+   if (sess->fe->header_unique_id) {
+   struct ist n, v;
+   n = ist2(sess->fe->header_unique_id, 
strlen(sess->fe->header_unique_id));
+   v = ist2(s->unique_id, length);
 
-   if (unlikely(!http_add_header(htx, n, v)))
-   goto return_int_err;
+   if (unlikely(!http_add_header(htx, n, v)))
+   goto return_int_err;
+   }
}
 
/*
diff --git a/src/http_fetch.c b/src/http_fetch.c
index d288e841d..dbbb5ecfd 100644
--- a/src/http_fetch.c
+++ b/src/http_fetch.c
@@ -409,19 +409,18 @@ static int smp_fetch_stcode(const struct arg *args, 
struct sample *smp, const ch
 
 static int smp_fetch_uniqueid(const struct arg *args, struct sample *smp, 
const char *kw, void *private)
 {
+   int length;
+
if (LIST_ISEMPTY(&smp->sess->fe->format_unique_id))
return 0;
 
-   if (!smp->strm->unique_id) {
-   if ((smp->strm->unique_id = pool_alloc(pool_head_uniqueid)) == 
NULL)
-   return 0;
-   smp->strm->unique_id[0] = '\0';
-   build_logline(smp->strm, smp->strm->unique_id,
- UNIQUEID_LEN, &smp->sess->fe->format_unique_id);
-   }
-   smp->data.u.str.data = strlen(smp->strm->unique_id);
-   smp->data.type = SMP_T_STR;
+   length = stream_generate_unique_id(smp->strm, 
&smp->sess->fe->format_unique_id);
+   if (length < 0)
+   return 0;
+
smp->data.u.str.area = smp->strm->unique_id;
+   smp->data.u.str.data = length;
+   smp->data.type = SMP_T_STR;
smp->flags = SMP_F_CONST;
return 1;
 }
diff --git a/src/log.c b/src/log.c
index 60b1a5a4d..b46605b8d 100644
--- a/src/log.c
+++ b/src/log.c
@@ -2983,8 +2983,7 @@ void strm_log(struct stream *s)
 
/* if unique-id was not generated */
if (!s->unique_id && !LIST_ISEMPTY(&sess->fe->format_unique_id)) {
-   if ((s->unique_id = pool_alloc(pool_head_uniqueid)) != NULL)
-   build_logline(s, s->unique_id, UNIQUEID_LEN, 
&sess->fe->format_unique_id);
+   stream_generate_unique_id(s, &sess->fe->format_unique_id);
}
 
if (!LIST_ISEMPTY(&sess->fe->logformat_sd)) {
-- 
2.25.1




[PATCH v3 7/7] MEDIUM: stream: Make the `unique_id` member of `struct stream` a `struct ist`

2020-02-28 Thread Tim Duesterhus
The `unique_id` member of `struct stream` now is a `struct ist`.
---
 include/proto/stream.h |  2 +-
 include/types/stream.h |  2 +-
 src/http_ana.c | 16 ++--
 src/http_fetch.c   | 10 +-
 src/log.c  |  8 +---
 src/stream.c   | 37 ++---
 6 files changed, 40 insertions(+), 35 deletions(-)

diff --git a/include/proto/stream.h b/include/proto/stream.h
index e54ac60cc..69153df5d 100644
--- a/include/proto/stream.h
+++ b/include/proto/stream.h
@@ -66,7 +66,7 @@ void stream_shutdown(struct stream *stream, int why);
 void stream_dump(struct buffer *buf, const struct stream *s, const char *pfx, 
char eol);
 void stream_dump_and_crash(enum obj_type *obj, int rate);
 
-int stream_generate_unique_id(struct stream *strm, struct list *format);
+struct ist stream_generate_unique_id(struct stream *strm, struct list *format);
 
 void stream_process_counters(struct stream *s);
 void sess_change_server(struct stream *sess, struct server *newsrv);
diff --git a/include/types/stream.h b/include/types/stream.h
index 90819e66d..39a68557e 100644
--- a/include/types/stream.h
+++ b/include/types/stream.h
@@ -177,7 +177,7 @@ struct stream {
int pcli_next_pid;  /* next target PID to use for 
the CLI proxy */
int pcli_flags; /* flags for CLI proxy */
 
-   char *unique_id;/* custom unique ID */
+   struct ist unique_id;   /* custom unique ID */
 
/* These two pointers are used to resume the execution of the rule 
lists. */
struct list *current_rule_list; /* this is used to store the 
current executed rule list. */
diff --git a/src/http_ana.c b/src/http_ana.c
index 549d61090..8e651f343 100644
--- a/src/http_ana.c
+++ b/src/http_ana.c
@@ -793,22 +793,18 @@ int http_process_request(struct stream *s, struct channel 
*req, int an_bit)
 * fetches only available in the HTTP request processing stage.
 */
if (!LIST_ISEMPTY(&sess->fe->format_unique_id)) {
-   int length;
+   struct ist unique_id = stream_generate_unique_id(s, 
&sess->fe->format_unique_id);
 
-   if ((length = stream_generate_unique_id(s, 
&sess->fe->format_unique_id)) < 0) {
+   if (unique_id.ptr == NULL) {
if (!(s->flags & SF_ERR_MASK))
s->flags |= SF_ERR_RESOURCE;
goto return_int_err;
}
 
/* send unique ID if a "unique-id-header" is defined */
-   if (sess->fe->header_unique_id.ptr) {
-   struct ist n, v;
-   v = ist2(s->unique_id, length);
-
-   if (unlikely(!http_add_header(htx, 
sess->fe->header_unique_id, v)))
+   if (sess->fe->header_unique_id.ptr
+   && unlikely(!http_add_header(htx, 
sess->fe->header_unique_id, s->unique_id)))
goto return_int_err;
-   }
}
 
/*
@@ -5082,9 +5078,9 @@ void http_end_txn(struct stream *s)
pool_free(pool_head_requri, txn->uri);
pool_free(pool_head_capture, txn->cli_cookie);
pool_free(pool_head_capture, txn->srv_cookie);
-   pool_free(pool_head_uniqueid, s->unique_id);
+   pool_free(pool_head_uniqueid, s->unique_id.ptr);
 
-   s->unique_id = NULL;
+   s->unique_id = ist_NULL();
txn->uri = NULL;
txn->srv_cookie = NULL;
txn->cli_cookie = NULL;
diff --git a/src/http_fetch.c b/src/http_fetch.c
index dbbb5ecfd..67fac6df0 100644
--- a/src/http_fetch.c
+++ b/src/http_fetch.c
@@ -409,17 +409,17 @@ static int smp_fetch_stcode(const struct arg *args, 
struct sample *smp, const ch
 
 static int smp_fetch_uniqueid(const struct arg *args, struct sample *smp, 
const char *kw, void *private)
 {
-   int length;
+   struct ist unique_id;
 
if (LIST_ISEMPTY(&smp->sess->fe->format_unique_id))
return 0;
 
-   length = stream_generate_unique_id(smp->strm, 
&smp->sess->fe->format_unique_id);
-   if (length < 0)
+   unique_id = stream_generate_unique_id(smp->strm, 
&smp->sess->fe->format_unique_id);
+   if (unique_id.ptr == NULL)
return 0;
 
-   smp->data.u.str.area = smp->strm->unique_id;
-   smp->data.u.str.data = length;
+   smp->data.u.str.area = smp->strm->unique_id.ptr;
+   smp->data.u.str.data = smp->strm->unique_id.len;
smp->data.type = SMP_T_STR;
smp->flags = SMP_F_CONST;
return 1;
diff --git a/src/log.c b/src/log.c
index b46605b8d..9a99a6082 100644
--- a/src/log.c
+++ b/src/log.c
@@ -2927,8 +2927,10 @@ int sess_build_logline(struct session *sess, struct 
stream *s, char *dst, size_t
 
case LOG_FMT_UNIQUEID: // %ID
ret = NULL;
-   src = s ? s->unique_id : N

[PATCH v3 6/7] MINOR: proxy: Make `header_unique_id` a `struct ist`

2020-02-28 Thread Tim Duesterhus
The `header_unique_id` member of `struct proxy` now is a `struct ist`.
---
 include/types/proxy.h |  2 +-
 src/cfgparse-listen.c | 23 +++
 src/http_ana.c|  5 ++---
 3 files changed, 22 insertions(+), 8 deletions(-)

diff --git a/include/types/proxy.h b/include/types/proxy.h
index f3b0e6bef..b64d448af 100644
--- a/include/types/proxy.h
+++ b/include/types/proxy.h
@@ -405,7 +405,7 @@ struct proxy {
struct list logformat;  /* log_format linked list */
struct list logformat_sd;   /* log_format linked list for 
the RFC5424 structured-data part */
struct buffer log_tag;   /* override default syslog tag 
*/
-   char *header_unique_id; /* unique-id header */
+   struct ist header_unique_id;/* unique-id header */
struct list format_unique_id;   /* unique-id format */
int to_log; /* things to be logged (LW_*) */
int stop_time;  /* date to stop listening, when 
stopping != 0 (int ticks) */
diff --git a/src/cfgparse-listen.c b/src/cfgparse-listen.c
index bd2275238..8f1d7ef63 100644
--- a/src/cfgparse-listen.c
+++ b/src/cfgparse-listen.c
@@ -429,8 +429,15 @@ int cfg_parse_listen(const char *file, int linenum, char 
**args, int kwm)
}
 
/* copy default header unique id */
-   if (defproxy.header_unique_id)
-   curproxy->header_unique_id = 
strdup(defproxy.header_unique_id);
+   if (defproxy.header_unique_id.ptr) {
+   const struct ist copy = 
istdup(defproxy.header_unique_id);
+   if (copy.ptr == NULL) {
+   ha_alert("parsing [%s:%d] : failed to allocate 
memory for unique-id-header\n", file, linenum);
+   err_code |= ERR_ALERT | ERR_FATAL;
+   goto out;
+   }
+   curproxy->header_unique_id = copy;
+   }
 
/* default compression options */
if (defproxy.comp != NULL) {
@@ -3484,13 +3491,21 @@ stats_error_parsing:
}
 
else if (strcmp(args[0], "unique-id-header") == 0) {
+   char *copy;
if (!*(args[1])) {
ha_alert("parsing [%s:%d] : %s expects an argument.\n", 
file, linenum, args[0]);
err_code |= ERR_ALERT | ERR_FATAL;
goto out;
}
-   free(curproxy->header_unique_id);
-   curproxy->header_unique_id = strdup(args[1]);
+   copy = strdup(args[1]);
+   if (copy == NULL) {
+   ha_alert("parsing [%s:%d] : failed to allocate memory 
for unique-id-header\n", file, linenum);
+   err_code |= ERR_ALERT | ERR_FATAL;
+   goto out;
+   }
+   
+   free(curproxy->header_unique_id.ptr);
+   curproxy->header_unique_id = ist(copy);
}
 
else if (strcmp(args[0], "log-format") == 0) {
diff --git a/src/http_ana.c b/src/http_ana.c
index 094208d63..549d61090 100644
--- a/src/http_ana.c
+++ b/src/http_ana.c
@@ -802,12 +802,11 @@ int http_process_request(struct stream *s, struct channel 
*req, int an_bit)
}
 
/* send unique ID if a "unique-id-header" is defined */
-   if (sess->fe->header_unique_id) {
+   if (sess->fe->header_unique_id.ptr) {
struct ist n, v;
-   n = ist2(sess->fe->header_unique_id, 
strlen(sess->fe->header_unique_id));
v = ist2(s->unique_id, length);
 
-   if (unlikely(!http_add_header(htx, n, v)))
+   if (unlikely(!http_add_header(htx, 
sess->fe->header_unique_id, v)))
goto return_int_err;
}
}
-- 
2.25.1




[PATCH v3 2/7] MINOR: stream: Add stream_generate_unique_id function

2020-02-28 Thread Tim Duesterhus
Currently unique IDs for a stream are generated using repetitive code in
multiple locations, possibly allowing for inconsistent behavior.
---
 include/proto/stream.h |  3 +++
 src/http_ana.c |  1 -
 src/stream.c   | 24 
 3 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/include/proto/stream.h b/include/proto/stream.h
index f8c0887b9..e54ac60cc 100644
--- a/include/proto/stream.h
+++ b/include/proto/stream.h
@@ -53,6 +53,7 @@ extern struct trace_source trace_strm;
 #define IS_HTX_STRM(strm) ((strm)->flags & SF_HTX)
 
 extern struct pool_head *pool_head_stream;
+extern struct pool_head *pool_head_uniqueid;
 extern struct list streams;
 
 extern struct data_cb sess_conn_cb;
@@ -65,6 +66,8 @@ void stream_shutdown(struct stream *stream, int why);
 void stream_dump(struct buffer *buf, const struct stream *s, const char *pfx, 
char eol);
 void stream_dump_and_crash(enum obj_type *obj, int rate);
 
+int stream_generate_unique_id(struct stream *strm, struct list *format);
+
 void stream_process_counters(struct stream *s);
 void sess_change_server(struct stream *sess, struct server *newsrv);
 struct task *process_stream(struct task *t, void *context, unsigned short 
state);
diff --git a/src/http_ana.c b/src/http_ana.c
index e3d22445e..20c7b6e50 100644
--- a/src/http_ana.c
+++ b/src/http_ana.c
@@ -5093,7 +5093,6 @@ void http_end_txn(struct stream *s)
 
 
 DECLARE_POOL(pool_head_http_txn, "http_txn", sizeof(struct http_txn));
-DECLARE_POOL(pool_head_uniqueid, "uniqueid", UNIQUEID_LEN);
 
 __attribute__((constructor))
 static void __http_protocol_init(void)
diff --git a/src/stream.c b/src/stream.c
index 9798c5f0f..306444e89 100644
--- a/src/stream.c
+++ b/src/stream.c
@@ -66,6 +66,7 @@
 #include 
 
 DECLARE_POOL(pool_head_stream, "stream", sizeof(struct stream));
+DECLARE_POOL(pool_head_uniqueid, "uniqueid", UNIQUEID_LEN);
 
 struct list streams = LIST_HEAD_INIT(streams);
 __decl_spinlock(streams_lock);
@@ -2657,6 +2658,29 @@ void stream_dump_and_crash(enum obj_type *obj, int rate)
abort();
 }
 
+/* Generates a unique ID based on the given , stores it in the given 
 and
+ * returns the length of the ID. -1 is returned on memory allocation failure.
+ *
+ * If an ID is already stored within the stream nothing happens and length of 
the stored
+ * ID is returned.
+ */
+int stream_generate_unique_id(struct stream *strm, struct list *format)
+{
+   if (strm->unique_id != NULL) {
+   return strlen(strm->unique_id);
+   }
+   else {
+   char *unique_id;
+   if ((unique_id = pool_alloc(pool_head_uniqueid)) == NULL)
+   return -1;
+
+   strm->unique_id = unique_id;
+   strm->unique_id[0] = 0;
+
+   return build_logline(strm, strm->unique_id, UNIQUEID_LEN, 
format);
+   }
+}
+
 //
 /*   All supported ACL keywords must be declared here.  */
 //
-- 
2.25.1




[PATCH v3 5/7] MINOR: ist: Add `struct ist istdup(const struct ist)`

2020-02-28 Thread Tim Duesterhus
istdup() performs the equivalent of strdup() on a `struct ist`.
---
 include/common/ist.h | 17 +
 1 file changed, 17 insertions(+)

diff --git a/include/common/ist.h b/include/common/ist.h
index 4d75d8607..9614f957d 100644
--- a/include/common/ist.h
+++ b/include/common/ist.h
@@ -420,6 +420,23 @@ static inline ssize_t istscpy(struct ist *dst, const 
struct ist src, size_t coun
return -1;
 }
 
+/* This function performs the equivalent of strdup() on the given .
+ * If this function fails to allocate memory an `ist` with `.ptr = NULL` and 
`.len = 0`
+ * is returned.
+ */
+static inline struct ist istdup(const struct ist src)
+{
+   const size_t alloc_size = src.len;
+   const char *alloc = malloc(alloc_size);
+   struct ist dst = ist2(alloc, 0);
+   
+   if (dst.ptr != NULL) {
+   istcpy(&dst, src, alloc_size);
+   }
+   
+   return dst;
+}
+
 /* appends  after  for a maximum of  total bytes in  
after
  * the copy.  is assumed to be  or less before the call. The new
  * string's length is returned, or -1 if a truncation happened. In all cases,
-- 
2.25.1




Re: [PATCH] BUG/MINOR: dns: ignore trailing dot

2020-02-28 Thread Willy Tarreau
On Fri, Feb 28, 2020 at 09:45:55AM +0100, Baptiste wrote:
> Patch approved!

... and merged now. Thanks guys!
Willy



Re: using variables in reg-tests

2020-02-28 Thread Christopher Faulet

Le 28/02/2020 à 09:32, Илья Шипицин a écrit :

reg-tests keep logs in ${TMPDIR}

in travis-ci we output logs on failure

after_failure:
   - |
     for folder in ${TMPDIR}/*regtest*/vtc.*; do
       cat $folder/INFO
       cat $folder/LOG
     done



is it ok not to clean ${TMPDIR} between two runs ? (as far as I understand, each 
test run generates unique id, so it should be ok)





Yes, it is safe to keep temp directories between 2 runs.


--
Christopher Faulet



Re: [PATCH] BUG/MINOR: dns: ignore trailing dot

2020-02-28 Thread Baptiste
On Thu, Feb 27, 2020 at 3:47 PM Lukas Tribus  wrote:

> As per issue #435 a hostname with a trailing dot confuses our DNS code,
> as for a zero length DNS label we emit a null-byte. This change makes us
> ignore the zero length label instead.
>
> Must be backported to 1.8.
> ---
>
> As discussed in issue #435
>
> ---
>  src/dns.c | 6 ++
>  1 file changed, 6 insertions(+)
>
> diff --git a/src/dns.c b/src/dns.c
> index c131f08..e2fa387 100644
> --- a/src/dns.c
> +++ b/src/dns.c
> @@ -1208,6 +1208,12 @@ int dns_str_to_dn_label(const char *str, int
> str_len, char *dn, int dn_len)
> if (i == offset)
> return -1;
>
> +   /* ignore trailing dot */
> +   if (i + 2 == str_len) {
> +   i++;
> +   break;
> +   }
> +
> dn[offset] = (i - offset);
> offset = i+1;
> continue;
> --
> 2.7.4
>
>
Patch approved!

Baptiste


Re: SRV Record Priority Values

2020-02-28 Thread Baptiste
>
> I suspect that it's more a property of the resolvers than the servers.
> I mean, if you know that you're using your DNS servers this way, this
> should really have the same meaning for all servers. So you shouldn't
> have a per-server option to adjust this behavior but a per-resolvers
> section.
>
>
> That's even better! And probably more easily implemented. I'll wait for
> Baptiste's response.
>

Hi There,

When we first designed support for SRV record, we thought about use cases
for this "priority" field.
That said, at that time, the conclusion was some kind of "it is not
possible to match a 'backup' state with an integer, or it is a "waste" of
information".
What this means is that backup status would use priority 0 or 1 or some
kind of. But we burn the remaining 65534 values from this field.
I also think we wanted to have "server groups" first in HAProxy before
using the priority. The idea before server groups is that a bunch of server
should be used all together until they fail (or enough have failed), and in
such case, we want to fail over to the next group, and so on (unless first
group recovers, of course). Then, priority could be used to set up the
groups, cause HAProxy would assign al server with same priority in the same
group.

What we can do for now, is consider "active" a priority 0 and backup, any
value greater than 0.

Baptiste


Re: using variables in reg-tests

2020-02-28 Thread Илья Шипицин
reg-tests keep logs in ${TMPDIR}

in travis-ci we output logs on failure

after_failure:
  - |
for folder in ${TMPDIR}/*regtest*/vtc.*; do
  cat $folder/INFO
  cat $folder/LOG
done



is it ok not to clean ${TMPDIR} between two runs ? (as far as I understand,
each test run generates unique id, so it should be ok)




пт, 28 февр. 2020 г. в 13:14, Christopher Faulet :

> Le 28/02/2020 à 08:20, Илья Шипицин a écrit :
> > Hello,
> >
> > ${no-htx} option http-use-htx
> >
> > how can setup that variable per test run? I want to run reg-tests with
> and
> > without htx
> >
> > cheers,
> > Ilya Shipitcin
>
> Hi Ilya,
>
> You may pass or not the option '--no-htx' when you run
> "scripts/run-regtests.sh"
> or the "reg-tests" Makefile target:
>
>scripts/run-regtests.sh # with HTX
>scripts/run-regtests.sh --no-htx # without HTX
>
> or
>
>make reg-tests # with HTX
>make reg-test -- --no-htx # without HTX
>
>
> --
> Christopher Faulet
>


Re: using variables in reg-tests

2020-02-28 Thread Christopher Faulet

Le 28/02/2020 à 08:20, Илья Шипицин a écrit :

Hello,

${no-htx} option http-use-htx

how can setup that variable per test run? I want to run reg-tests with and 
without htx


cheers,
Ilya Shipitcin


Hi Ilya,

You may pass or not the option '--no-htx' when you run "scripts/run-regtests.sh" 
or the "reg-tests" Makefile target:


  scripts/run-regtests.sh # with HTX
  scripts/run-regtests.sh --no-htx # without HTX

or

  make reg-tests # with HTX
  make reg-test -- --no-htx # without HTX


--
Christopher Faulet