]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: log: introduce log_orig flags
authorAurelien DARRAGON <adarragon@haproxy.com>
Mon, 23 Sep 2024 15:22:45 +0000 (17:22 +0200)
committerAurelien DARRAGON <adarragon@haproxy.com>
Thu, 26 Sep 2024 14:53:07 +0000 (16:53 +0200)
Rename 'enum log_orig' to 'enum log_orig_id', since this enum specifically
contains the log origin ids.

Add 'struct log_orig' which wraps 'enum log_orig' with optional flags
(no flags defined for now).

Add log_orig() helper func that takes id and flags as parameter and
returns log_orig struct initialized with input arguments.

Update functions taking log origin as parameter so they explicitly take
log orig id or log orig wrapper as argument depending on the level of
context expected by the function.

include/haproxy/log-t.h
include/haproxy/log.h
include/haproxy/stream-t.h
src/cli.c
src/frontend.c
src/http_ana.c
src/log.c
src/stream.c

index f59d59496eb2bd93d6c11002d5db71280a35c5cb..2a4eb4df58dab3449503525f414ef9b5383432a3 100644 (file)
@@ -261,7 +261,7 @@ struct logger {
 /* integer used to provide some context about the log origin
  * when sending log through logging functions
  */
-enum log_orig {
+enum log_orig_id {
        LOG_ORIG_UNSPEC = 0,         /* unspecified */
        LOG_ORIG_SESS_ERROR,         /* general error during session handling */
        LOG_ORIG_SESS_KILL,          /* during embryonic session kill */
@@ -277,6 +277,16 @@ enum log_orig {
        LOG_ORIG_MAX = 0xFFFF,       /* max log origin number (65k) */
 };
 
+/* log orig flags
+ */
+#define LOG_ORIG_FL_NONE  0x0000
+#define LOG_ORIG_FL_ALL   0xFFFF
+
+struct log_orig {
+       enum log_orig_id id;
+       uint16_t flags; /* any LOG_ORIG_FL_* */
+};
+
 /* max number of extra log origins */
 #define LOG_ORIG_EXTRA_SLOTS LOG_ORIG_MAX - LOG_ORIG_EXTRA
 
index 3cca582be6261c1e085f2be0a9e02f48988ae81a..86f5b9c5f61f248c5c3c94e0b6bd93f5dab11383 100644 (file)
@@ -65,7 +65,7 @@ void syslog_fd_handler(int fd);
 int init_log_buffers(void);
 void deinit_log_buffers(void);
 
-const char *log_orig_to_str(enum log_orig orig);
+const char *log_orig_to_str(enum log_orig_id orig);
 
 void lf_expr_init(struct lf_expr *expr);
 int lf_expr_dup(const struct lf_expr *orig, struct lf_expr *dest);
@@ -82,22 +82,33 @@ int lf_expr_postcheck(struct lf_expr *lf_expr, struct proxy *px, char **err);
 void free_logformat_list(struct list *fmt);
 void free_logformat_node(struct logformat_node *node);
 
+/* helper to build log_orig struct from known id and flags values */
+static inline struct log_orig log_orig(enum log_orig_id id, uint16_t flags)
+{
+       struct log_orig orig;
+
+       orig.id = id;
+       orig.flags = flags;
+       return orig;
+}
+
 /* build a log line for the session and an optional stream */
 int sess_build_logline_orig(struct session *sess, struct stream *s, char *dst, size_t maxsize,
-                            struct lf_expr *lf_expr, enum log_orig orig);
+                            struct lf_expr *lf_expr, struct log_orig orig);
 
 /* wrapper for sess_build_logline_orig(), uses LOG_ORIG_UNSPEC log origin */
 static inline int sess_build_logline(struct session *sess, struct stream *s, char *dst, size_t maxsize,
                                      struct lf_expr *lf_expr)
 {
-       return sess_build_logline_orig(sess, s, dst, maxsize, lf_expr, LOG_ORIG_UNSPEC);
+       return sess_build_logline_orig(sess, s, dst, maxsize, lf_expr,
+                                      log_orig(LOG_ORIG_UNSPEC, LOG_ORIG_FL_NONE));
 }
 
 /*
  * send a log for the stream when we have enough info about it.
  * Will not log if the frontend has no log defined.
  */
-void strm_log(struct stream *s, int origin);
+void strm_log(struct stream *s, struct log_orig origin);
 
 /* send an error log for the session, embryonic version should be used
  * when the log is emitted for a session which is still in embryonic state
@@ -136,7 +147,7 @@ struct logger *dup_logger(struct logger *def);
 void free_logger(struct logger *logger);
 void deinit_log_target(struct log_target *target);
 struct log_profile *log_profile_find_by_name(const char *name);
-enum log_orig log_orig_register(const char *name);
+enum log_orig_id log_orig_register(const char *name);
 
 /* Parse "log" keyword and update the linked list. */
 int parse_logger(char **args, struct list *loggers, int do_del, const char *file, int linenum, char **err);
@@ -175,7 +186,7 @@ char * get_format_pid_sep2(int format, size_t *len);
  * Builds a log line for the stream (must be valid).
  */
 static inline int build_logline_orig(struct stream *s, char *dst, size_t maxsize,
-                                     struct lf_expr *lf_expr, enum log_orig orig)
+                                     struct lf_expr *lf_expr, struct log_orig orig)
 {
        return sess_build_logline_orig(strm_sess(s), s, dst, maxsize, lf_expr, orig);
 }
@@ -185,7 +196,8 @@ static inline int build_logline_orig(struct stream *s, char *dst, size_t maxsize
  */
 static inline int build_logline(struct stream *s, char *dst, size_t maxsize, struct lf_expr *lf_expr)
 {
-       return build_logline_orig(s, dst, maxsize, lf_expr, LOG_ORIG_UNSPEC);
+       return build_logline_orig(s, dst, maxsize, lf_expr,
+                                 log_orig(LOG_ORIG_UNSPEC, LOG_ORIG_FL_NONE));
 }
 
 struct ist *build_log_header(struct log_header hdr, size_t *nbelem);
index 66ac498ce66afe5f7250be8c417467ff0b6baaae..91ef26c5c6b47dd32b15295095d5abc5c533f298 100644 (file)
@@ -30,6 +30,7 @@
 #include <haproxy/dynbuf-t.h>
 #include <haproxy/filters-t.h>
 #include <haproxy/obj_type-t.h>
+#include <haproxy/log-t.h>
 #include <haproxy/show_flags-t.h>
 #include <haproxy/stick_table-t.h>
 #include <haproxy/vars-t.h>
@@ -269,7 +270,7 @@ struct stream {
        struct strm_logs logs;                  /* logs for this stream */
 
        void (*do_log)(struct stream *s,        /* the function to call in order to log (or NULL) */
-                      int origin);
+                      struct log_orig origin);
        void (*srv_error)(struct stream *s,     /* the function to call upon unrecoverable server errors (or NULL) */
                          struct stconn *sc);
 
index c1cbe76bee95507e277ef61ad246266481bec3dc..e2ae2eb7004d1edb2109492e5f82945dee404813 100644 (file)
--- a/src/cli.c
+++ b/src/cli.c
@@ -3148,7 +3148,7 @@ int pcli_wait_for_response(struct stream *s, struct channel *rep, int an_bit)
                if (!lf_expr_isempty(&fe->logformat) && s->logs.logwait &&
                    !(s->flags & SF_MONITOR) &&
                    (!(fe->options & PR_O_NULLNOLOG) || s->req.total)) {
-                       s->do_log(s, LOG_ORIG_TXN_CLOSE);
+                       s->do_log(s, log_orig(LOG_ORIG_TXN_CLOSE, LOG_ORIG_FL_NONE));
                }
 
                /* stop tracking content-based counters */
index 8613926639029bf952408ee8eb48b7a985fdc2df..3d18db94abd47c9003ea89cdaf53e8ee01bc3b69 100644 (file)
@@ -59,7 +59,7 @@ int frontend_accept(struct stream *s)
                        /* we have the client ip */
                        if (s->logs.logwait & LW_CLIP)
                                if (!(s->logs.logwait &= ~(LW_CLIP|LW_INIT)))
-                                       s->do_log(s, LOG_ORIG_TXN_ACCEPT);
+                                       s->do_log(s, log_orig(LOG_ORIG_TXN_ACCEPT, LOG_ORIG_FL_NONE));
                }
                else if (conn) {
                        src = sc_src(s->scf);
index 5a95338b6cc8e5c5358baa29e293046437971a33..175c01cba76f64f35c5c9e4fe93772160a1d1ee2 100644 (file)
@@ -273,7 +273,7 @@ int http_wait_for_request(struct stream *s, struct channel *req, int an_bit)
                        txn->uri[len] = 0;
 
                        if (!(s->logs.logwait &= ~(LW_REQ|LW_INIT)))
-                               s->do_log(s, LOG_ORIG_TXN_REQUEST);
+                               s->do_log(s, log_orig(LOG_ORIG_TXN_REQUEST, LOG_ORIG_FL_NONE));
                } else {
                        ha_alert("HTTP logging : out of memory.\n");
                }
@@ -1911,7 +1911,7 @@ int http_process_res_common(struct stream *s, struct channel *rep, int an_bit, s
        if (!lf_expr_isempty(&sess->fe->logformat) && !(s->logs.logwait & LW_BYTES)) {
                s->logs.t_close = s->logs.t_data; /* to get a valid end date */
                s->logs.bytes_out = htx->data;
-               s->do_log(s, LOG_ORIG_TXN_RESPONSE);
+               s->do_log(s, log_orig(LOG_ORIG_TXN_RESPONSE, LOG_ORIG_FL_NONE));
                s->logs.bytes_out = 0;
        }
 
index 28c6e5c4d059b3afe986a98d99bb6ee95c96312c..69c3411dc8d58d587d33ef6ef1c873e1ec735e43 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -93,7 +93,7 @@ static const struct log_fmt_st log_formats[LOG_FORMATS] = {
 static struct list log_origins = LIST_HEAD_INIT(log_origins);
 
 /* get human readable representation for log_orig enum members */
-const char *log_orig_to_str(enum log_orig orig)
+const char *log_orig_to_str(enum log_orig_id orig)
 {
        switch (orig) {
                case LOG_ORIG_SESS_ERROR:
@@ -2872,7 +2872,7 @@ static inline void __send_log_set_metadata_sd(struct ist *metadata, char *sd, si
 struct process_send_log_ctx {
        struct session *sess;
        struct stream *stream;
-       enum log_orig origin;
+       struct log_orig origin;
 };
 
 static inline void _process_send_log_final(struct logger *logger, struct log_header hdr,
@@ -2895,7 +2895,7 @@ static inline void _process_send_log_override(struct process_send_log_ctx *ctx,
        struct log_profile_step *step = NULL;
        struct ist orig_tag = hdr.metadata[LOG_META_TAG];
        struct ist orig_sd = hdr.metadata[LOG_META_STDATA];
-       enum log_orig orig = (ctx) ? ctx->origin : LOG_ORIG_UNSPEC;
+       enum log_orig_id orig = (ctx) ? ctx->origin.id : LOG_ORIG_UNSPEC;
 
        BUG_ON(!prof);
 
@@ -3812,7 +3812,7 @@ int lf_expr_dup(const struct lf_expr *orig, struct lf_expr *dest)
  */
 int sess_build_logline_orig(struct session *sess, struct stream *s,
                             char *dst, size_t maxsize, struct lf_expr *lf_expr,
-                            enum log_orig log_orig)
+                            struct log_orig log_orig)
 {
        struct lf_buildctx *ctx = &lf_buildctx;
        struct proxy *fe = sess->fe;
@@ -5075,7 +5075,7 @@ int sess_build_logline_orig(struct session *sess, struct stream *s,
                                break;
 
                        case LOG_FMT_ORIGIN: // %OG
-                               ret = lf_text(tmplog, log_orig_to_str(log_orig),
+                               ret = lf_text(tmplog, log_orig_to_str(log_orig.id),
                                              dst + maxsize - tmplog, ctx);
                                if (ret == NULL)
                                        goto out;
@@ -5140,7 +5140,7 @@ out:
  * send a log for the stream when we have enough info about it.
  * Will not log if the frontend has no log defined.
  */
-void strm_log(struct stream *s, int origin)
+void strm_log(struct stream *s, struct log_orig origin)
 {
        struct session *sess = s->sess;
        int size, err, level;
@@ -5212,11 +5212,16 @@ void _sess_log(struct session *sess, int embryonic)
 {
        int size, level;
        int sd_size = 0;
-       int orig = (embryonic) ? LOG_ORIG_SESS_KILL : LOG_ORIG_SESS_ERROR;
+       struct log_orig orig;
 
        if (!sess)
                return;
 
+       if (embryonic)
+               orig = log_orig(LOG_ORIG_SESS_KILL, LOG_ORIG_FL_NONE);
+       else
+               orig = log_orig(LOG_ORIG_SESS_ERROR, LOG_ORIG_FL_NONE);
+
        if (LIST_ISEMPTY(&sess->fe->loggers))
                return;
 
@@ -6469,7 +6474,7 @@ out:
  * Don't forget to update the documentation when new log origins are added
  * (both %OG log alias and on <step> log-profile keyword are concerned)
  */
-enum log_orig log_orig_register(const char *name)
+enum log_orig_id log_orig_register(const char *name)
 {
        struct log_origin_node *cur;
        size_t last = 0;
index 550fd512e55dcac1846b1de4d7c012618acd188d..f955b81297a14b60232d31ad9dd7ca16afe608b5 100644 (file)
@@ -922,7 +922,7 @@ void back_establish(struct stream *s)
                if (!lf_expr_isempty(&strm_fe(s)->logformat) && !(s->logs.logwait & LW_BYTES)) {
                        /* note: no pend_pos here, session is established */
                        s->logs.t_close = s->logs.t_connect; /* to get a valid end date */
-                       s->do_log(s, LOG_ORIG_TXN_CONNECT);
+                       s->do_log(s, log_orig(LOG_ORIG_TXN_CONNECT, LOG_ORIG_FL_NONE));
                }
        }
        else {
@@ -2593,7 +2593,7 @@ struct task *process_stream(struct task *t, void *context, unsigned int state)
                        pendconn_free(s);
 
                        stream_cond_update_cpu_usage(s);
-                       s->do_log(s, LOG_ORIG_TXN_CLOSE);
+                       s->do_log(s, log_orig(LOG_ORIG_TXN_CLOSE, LOG_ORIG_FL_NONE));
                }
 
                /* update time stats for this stream */