summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Brown <jbrown@easypost.com>2016-03-11 15:36:47 -0800
committerJames Brown <jbrown@easypost.com>2017-01-31 10:18:02 -0800
commitcecfe60b1a8b099cea76e05082adbd933341bf14 (patch)
tree32eb804535e2004384173af875698d43b29e8953
parent2d76dfe9fe2015183b6fb838d223a1fb4d9815f5 (diff)
downloaduwsgi-cecfe60b1a8b099cea76e05082adbd933341bf14.tar.gz
correctly handle IPv6 sources in proto/http
-rw-r--r--proto/http.c41
-rwxr-xr-xuwsgi.h7
2 files changed, 36 insertions, 12 deletions
diff --git a/proto/http.c b/proto/http.c
index fa1e0ebc..c797ee02 100644
--- a/proto/http.c
+++ b/proto/http.c
@@ -207,8 +207,8 @@ static int http_parse(struct wsgi_request *wsgi_req, char *watermark) {
char *ptr = wsgi_req->proto_parser_buf;
char *base = ptr;
char *query_string = NULL;
- char ip[INET_ADDRSTRLEN+1];
- struct sockaddr_in *http_sin = (struct sockaddr_in *) &wsgi_req->c_addr;
+ char ip[INET6_ADDRSTRLEN+1];
+ struct sockaddr *http_sa = (struct sockaddr *) &wsgi_req->c_addr;
char *proxy_src = NULL;
char *proxy_dst = NULL;
char *proxy_src_port = NULL;
@@ -328,14 +328,35 @@ static int http_parse(struct wsgi_request *wsgi_req, char *watermark) {
}
}
else {
- // TODO add ipv6 support
- memset(ip, 0, INET_ADDRSTRLEN+1);
- if (inet_ntop(AF_INET, (void *) &http_sin->sin_addr.s_addr, ip, INET_ADDRSTRLEN)) {
- wsgi_req->len += proto_base_add_uwsgi_var(wsgi_req, "REMOTE_ADDR", 11, ip, strlen(ip));
- }
- else {
- uwsgi_error("inet_ntop()");
- return -1;
+ // TODO log something useful for AF_UNIX sockets
+ switch (http_sa->sa_family) {
+ case AF_INET6:
+ {
+ memset(ip, 0, INET6_ADDRSTRLEN+1);
+ struct sockaddr_in6* http_sin = (struct sockaddr_in6*)http_sa;
+ if (inet_ntop(AF_INET6, (void *) &http_sin->sin6_addr, ip, INET6_ADDRSTRLEN)) {
+ wsgi_req->len += proto_base_add_uwsgi_var(wsgi_req, "REMOTE_ADDR", 11, ip, strlen(ip));
+ }
+ else {
+ uwsgi_error("inet_ntop()");
+ return -1;
+ }
+ }
+ break;
+ case AF_INET:
+ default:
+ {
+ struct sockaddr_in* http_sin = (struct sockaddr_in*)http_sa;
+ memset(ip, 0, INET_ADDRSTRLEN+1);
+ if (inet_ntop(AF_INET, (void *) &http_sin->sin_addr, ip, INET_ADDRSTRLEN)) {
+ wsgi_req->len += proto_base_add_uwsgi_var(wsgi_req, "REMOTE_ADDR", 11, ip, strlen(ip));
+ }
+ else {
+ uwsgi_error("inet_ntop()");
+ return -1;
+ }
+ }
+ break;
}
}
diff --git a/uwsgi.h b/uwsgi.h
index 37b1e0f4..2df7e5c4 100755
--- a/uwsgi.h
+++ b/uwsgi.h
@@ -1375,8 +1375,11 @@ struct wsgi_request {
char *appid;
uint16_t appid_len;
- //this is big enough to contain sockaddr_in
- struct sockaddr_un c_addr;
+ union address {
+ struct sockaddr_in sin;
+ struct sockaddr_in6 sin6;
+ struct sockaddr_un sun;
+ } c_addr;
int c_len;
//iovec