This implementation is directly modeled after `stream_generate_unique_id()` and
the corresponding `unique_id` field on `struct stream`.
It will be used in a future commit to enable the use of the `%[unique-id]`
fetch in check rules.
---
include/haproxy/check-t.h | 1 +
include/haproxy/check.h | 11 +++++++++++
src/check.c | 7 +++++++
3 files changed, 19 insertions(+)
diff --git a/include/haproxy/check-t.h b/include/haproxy/check-t.h
index f9f378e8a..353fc5845 100644
--- a/include/haproxy/check-t.h
+++ b/include/haproxy/check-t.h
@@ -199,6 +199,7 @@ struct check {
const struct mux_proto_list *mux_proto; /* the mux to use for all
outgoing connections (specified by the "proto" keyword) */
struct list check_queue; /* entry in the check queue.
Not empty = in queue. */
int via_socks4; /* check the connection via
socks4 proxy */
+ struct ist unique_id; /* custom unique ID, same as in
struct stream */
};
#endif /* _HAPROXY_CHECKS_T_H */
diff --git a/include/haproxy/check.h b/include/haproxy/check.h
index 09e195a46..e25e987f0 100644
--- a/include/haproxy/check.h
+++ b/include/haproxy/check.h
@@ -26,6 +26,7 @@
#include <haproxy/proxy-t.h>
#include <haproxy/server-t.h>
#include <haproxy/trace-t.h>
+#include <haproxy/log.h>
extern struct trace_source trace_check;
@@ -80,6 +81,16 @@ struct task *srv_chk_io_cb(struct task *t, void *ctx,
unsigned int state);
int check_buf_available(void *target);
struct buffer *check_get_buf(struct check *check, struct buffer *bptr,
unsigned int small_buffer);
void check_release_buf(struct check *check, struct buffer *bptr);
+
+static inline struct ist check_generate_unique_id(struct check *check, struct
lf_expr *format)
+{
+ if (!isttest(check->unique_id)) {
+ generate_unique_id(&check->unique_id, check->sess, NULL,
format);
+ }
+
+ return check->unique_id;
+}
+
const char *init_check(struct check *check, int type);
void free_check(struct check *check);
void check_purge(struct check *check);
diff --git a/src/check.c b/src/check.c
index 45baca979..481cab22f 100644
--- a/src/check.c
+++ b/src/check.c
@@ -458,6 +458,11 @@ void set_server_check_status(struct check *check, short
status, const char *desc
check->result = CHK_RES_UNKNOWN; /* no result yet */
check->desc[0] = '\0';
check->start = now_ns;
+
+ /* Reset unique_id. */
+ pool_free(pool_head_uniqueid, istptr(check->unique_id));
+ check->unique_id = IST_NULL;
+
return;
}
@@ -1558,6 +1563,8 @@ void free_check(struct check *check)
ha_free(&check->tcpcheck);
}
+ pool_free(pool_head_uniqueid, istptr(check->unique_id));
+ check->unique_id = IST_NULL;
ha_free(&check->pool_conn_name);
ha_free(&check->sni);
ha_free(&check->alpn_str);
--
2.53.0