[PATCH] Make Nginx Parse URL to IPv6

Speed First speedfirst at gmail.com
Wed Mar 2 11:55:53 MSK 2011


This is a new implementation according to your comments.

Here is my comments to this patch

1. ngx_inet_sock_addr is removed. You are right, ngx_parse_url can do that
job. So no need to change ngx_inet.h

2. the old "gethostbyname" implementation will be used if "--with-ipv6" is
not set; when "--with-ipv6" is set, "getaddrinfo" will be used

3. now when "ngx_inet_parse_url" find u->host might be a hostname, it will
invoke new added function "ngx_inet_resolve_hostname".

4. seems there is a bug in old file's line 829. Only when uri is NULL, len =
last - port.

5. now "ngx_inet6_parse_url" will finally invoke new added
"ngx_inet6_resolve_host", just like what "ngx_inet_parse_url" does. I think
it should be done but the old code doesn't do that. Please confirm this is
valid.

6. I try to remove duplicated code as much as possible, so the
"ngx_inet_resolve_host" is almost rewritten. Now, it will first handle the
u->host as it's an IP; if not, it will try to resolve them.

7. In "ngx_inet_parse_url", it firstly assume it's AF_INET and allocate the
memory. I think it's not suitable in the new implementation, but I didn't
touch this part of code.

8. All the fix are tested as before (with and without "--with-ipv6"), all
test are passed.

9. I make this implementation based on 0.9.3. I compare the ngx_inet.c in
official 0.9.3 and 0.9.5, and find there is a difference:

-        for (i = 0; i < u->naddrs; i++) {
+        for (i = 0; h->h_addr_list[i] != NULL; i++) {

Since my implementation use "getaddrinfo", h_addr_list[i] will be invalid
when "--with-ipv6" is set.

Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://nginx.org/pipermail/nginx-devel/attachments/20110302/e2d8263c/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ngx_inet.c.diff
Type: text/x-patch
Size: 14162 bytes
Desc: not available
URL: <http://nginx.org/pipermail/nginx-devel/attachments/20110302/e2d8263c/attachment.bin>


More information about the nginx-devel mailing list