diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2023-11-17 22:41:16 +0000 |
---|---|---|
committer | Laurent Bercot <ska@appnovation.com> | 2023-11-17 22:41:16 +0000 |
commit | bdcd701136294f1d3a5e93047edb8bd40b54a27a (patch) | |
tree | 84c5a100390c9a22140f44a7108d1918536435bb | |
parent | 7ec647fa64c0a6f29cbb83cc264868b15e4bb046 (diff) | |
download | tipidee-bdcd701136294f1d3a5e93047edb8bd40b54a27a.tar.gz tipidee-bdcd701136294f1d3a5e93047edb8bd40b54a27a.tar.xz tipidee-bdcd701136294f1d3a5e93047edb8bd40b54a27a.zip |
Add X-Forwarded-For logging support
Signed-off-by: Laurent Bercot <ska@appnovation.com>
-rw-r--r-- | src/config/lexparse.c | 3 | ||||
-rw-r--r-- | src/include/tipidee/log.h | 1 | ||||
-rw-r--r-- | src/libtipidee/tipidee_log_request.c | 18 |
3 files changed, 19 insertions, 3 deletions
diff --git a/src/config/lexparse.c b/src/config/lexparse.c index 799b17f..99eeaa0 100644 --- a/src/config/lexparse.c +++ b/src/config/lexparse.c @@ -150,7 +150,8 @@ static inline void parse_log (char const *s, size_t const *word, size_t n, mdt c { .name = "request", .value = TIPIDEE_LOG_REQUEST }, { .name = "resource", .value = TIPIDEE_LOG_RESOURCE }, { .name = "start", .value = TIPIDEE_LOG_START }, - { .name = "user-agent", .value = TIPIDEE_LOG_UA } + { .name = "user-agent", .value = TIPIDEE_LOG_UA }, + { .name = "x-forwarded-for", .value = TIPIDEE_LOG_XFORWARDEDFOR } } ; uint32_t v = 0 ; char pack[4] ; diff --git a/src/include/tipidee/log.h b/src/include/tipidee/log.h index 93ee386..b8decc0 100644 --- a/src/include/tipidee/log.h +++ b/src/include/tipidee/log.h @@ -23,6 +23,7 @@ #define TIPIDEE_LOG_CLIENTIP 0x0080 #define TIPIDEE_LOG_CLIENTHOST 0x0100 #define TIPIDEE_LOG_HOSTASPREFIX 0x0200 +#define TIPIDEE_LOG_XFORWARDEDFOR 0x0400 #define TIPIDEE_LOG_DEBUG 0x8000 #define TIPIDEE_LOG_DEFAULT (TIPIDEE_LOG_REQUEST | TIPIDEE_LOG_ANSWER | TIPIDEE_LOG_SIZE) diff --git a/src/libtipidee/tipidee_log_request.c b/src/libtipidee/tipidee_log_request.c index 6543214..54755ec 100644 --- a/src/libtipidee/tipidee_log_request.c +++ b/src/libtipidee/tipidee_log_request.c @@ -12,10 +12,10 @@ void tipidee_log_request (uint32_t v, tipidee_rql const *rql, tipidee_headers const *hdr, stralloc *sa) { - char const *a[16] = { PROG, ": info:" } ; + char const *a[18] = { PROG, ": info:" } ; size_t m = 2 ; size_t start = sa->len ; /* assert: not zero */ - size_t refpos = 0, uapos = 0 ; + size_t refpos = 0, uapos = 0, xffpos = 0 ; if (!(v & TIPIDEE_LOG_REQUEST)) return ; if (!string_quotes(sa, rql->uri.path) || !stralloc_0(sa)) goto eerr ; if (v & TIPIDEE_LOG_REFERRER) @@ -36,6 +36,15 @@ void tipidee_log_request (uint32_t v, tipidee_rql const *rql, tipidee_headers co if (!string_quotes(sa, x) || !stralloc_0(sa)) goto err ; } } + if (v & TIPIDEE_LOG_XFORWARDEDFOR) + { + char const *x = tipidee_headers_search(hdr, "X-Forwarded-For") ; + if (x) + { + xffpos = sa->len ; + if (!string_quotes(sa, x) || !stralloc_0(sa)) goto err ; + } + } if (v & TIPIDEE_LOG_HOSTASPREFIX) { a[m++] = " host " ; @@ -67,6 +76,11 @@ void tipidee_log_request (uint32_t v, tipidee_rql const *rql, tipidee_headers co a[m++] = " user-agent " ; a[m++] = sa->s + uapos ; } + if (xffpos) + { + a[m++] = " x-forwarded-for " ; + a[m++] = sa->s + xffpos ; + } strerr_warnv(a, m) ; sa->len = start ; return ; |