diff --git a/reg-tests/http-rules/forwarded-header-7239.vtc b/reg-tests/http-rules/forwarded-header-7239.vtc index a894113e78..dd2c6e3fd0 100644 --- a/reg-tests/http-rules/forwarded-header-7239.vtc +++ b/reg-tests/http-rules/forwarded-header-7239.vtc @@ -151,6 +151,12 @@ client c1 -connect ${h1_fe1_sock} { expect resp.status == 200 expect resp.http.nodename == "::1" expect resp.http.nodeport == "_id" + + txreq -req GET -url /req4 \ + -hdr "forwarded: for=127.9.0.1" + rxresp + expect resp.status == 200 + expect resp.http.nodename == "127.9.0.1" } -run client c2 -connect ${h2_fe1h2_sock} { diff --git a/src/http_ext.c b/src/http_ext.c index 269a97f5e3..3367e3884c 100644 --- a/src/http_ext.c +++ b/src/http_ext.c @@ -114,8 +114,12 @@ static inline int http_7239_extract_ipv4(struct ist *input, struct in_addr *ip) { char ip4[INET_ADDRSTRLEN]; unsigned char buf[sizeof(struct in_addr)]; + void *dst = buf; int it = 0; + if (ip) + dst = ip; + /* extract ipv4 addr */ while (it < istlen(*input) && it < (sizeof(ip4) - 1)) { if (!isdigit((unsigned char)istptr(*input)[it]) && @@ -125,11 +129,9 @@ static inline int http_7239_extract_ipv4(struct ist *input, struct in_addr *ip) it += 1; } ip4[it] = 0; - if (inet_pton(AF_INET, ip4, buf) != 1) + if (inet_pton(AF_INET, ip4, dst) != 1) return 0; /* invalid ip4 addr */ /* ok */ - if (ip) - memcpy(ip, buf, sizeof(buf)); *input = istadv(*input, it); return 1; } @@ -146,8 +148,12 @@ static inline int http_7239_extract_ipv6(struct ist *input, struct in6_addr *ip) { char ip6[INET6_ADDRSTRLEN]; unsigned char buf[sizeof(struct in6_addr)]; + void *dst = buf; int it = 0; + if (ip) + dst = ip; + *input = istnext(*input); /* skip '[' leading char */ /* extract ipv6 addr */ while (it < istlen(*input) && @@ -162,11 +168,9 @@ static inline int http_7239_extract_ipv6(struct ist *input, struct in6_addr *ip) if ((istlen(*input)-it) < 1 || istptr(*input)[it] != ']') return 0; /* missing ending "]" char */ it += 1; - if (inet_pton(AF_INET6, ip6, buf) != 1) + if (inet_pton(AF_INET6, ip6, dst) != 1) return 0; /* invalid ip6 addr */ /* ok */ - if (ip) - memcpy(ip, buf, sizeof(buf)); *input = istadv(*input, it); return 1; }