Hi guys.

This is my first ever post to an openbsd mailing list.
I apologize in advance if i'm doing something wrong.


So basically, I had just setup a relayd box in front of a
few httpd boxes behind a ipsec tunnel for fun.

btw, reyk and others, thank you so much for this fine software.

I noticed httpd(8) didn't have a way to log "true ips"

I went ahead and synced my source tree and wrote this:

disclaimer: I'm not a programmer. nor an expert.
idk if this is even an acceptable log format...

also, should something like this ( if it even belongs in the tree) be
tied to the "X-Forwarded-For" variable? is "HTTP_VIA" a better choice?
AFIAK it's arbitrary.

Also, was anyone planning on adding a 'customlog' feature?
Perhaps such a thing is going to be left out on purpose?

Sorry for bugging y'all. Just wanted to share my first practical diff.
-gwurr3


Index: usr.sbin/httpd/server_http.c
===================================================================
RCS file: /cvs/src/usr.sbin/httpd/server_http.c,v
retrieving revision 1.84
diff -u -p -r1.84 server_http.c
--- usr.sbin/httpd/server_http.c        23 Jun 2015 17:25:01 -0000      1.84
+++ usr.sbin/httpd/server_http.c        9 Jul 2015 08:40:43 -0000
@@ -1422,7 +1422,7 @@ server_log_http(struct client *clt, u_in
        static char              tstamp[64];
        static char              ip[INET6_ADDRSTRLEN];
        time_t                   t;
-       struct kv                key, *agent, *referrer;
+       struct kv                key, *agent, *referrer, *forwarded;
        struct tm               *tm;
        struct server_config    *srv_conf;
        struct http_descriptor  *desc;
@@ -1479,9 +1479,15 @@ server_log_http(struct client *clt, u_in
                    agent->kv_value == NULL)
                        agent = NULL;

+               key.kv_key = "X-Forwarded-For";
+               if ((forwarded = kv_find(&desc->http_headers, &key)) != NULL &&
+                   forwarded->kv_value == NULL)
+                       forwarded = NULL;
+
+
                if (evbuffer_add_printf(clt->clt_log,
                    "%s %s - %s [%s] \"%s %s%s%s%s%s\""
-                   " %03d %zu \"%s\" \"%s\"\n",
+                   " %03d %zu \"%s\" \"%s\" \"%s\"\n",
                    srv_conf->name, ip, clt->clt_remote_user == NULL ? "-" :
                    clt->clt_remote_user, tstamp,
                    server_httpmethod_byid(desc->http_method),
@@ -1492,7 +1498,8 @@ server_log_http(struct client *clt, u_in
                    desc->http_version == NULL ? "" : desc->http_version,
                    code, len,
                    referrer == NULL ? "" : referrer->kv_value,
-                   agent == NULL ? "" : agent->kv_value) == -1)
+                   agent == NULL ? "" : agent->kv_value,
+                   forwarded == NULL ? "" : forwarded->kv_value) == -1)
                        return (-1);
                break;

Reply via email to