summaryrefslogtreecommitdiffhomepage
path: root/src/core/ngx_inet.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2024-11-26Realip: allowed square brackets with portless IPv6 address.Roman Arutyunyan1-1/+5
When client address is received, IPv6 address could be specified without square brackets and without port, as well as both with the brackets and port. The change allows IPv6 in square brackets and no port, which was previously considered an error. This format conforms to RFC 3986. The change also affects proxy_bind and friends.
2024-03-18Fixed undefined behaviour with IPv4-mapped IPv6 addresses.Sergey Kandaurov1-1/+1
Previously, it could result when left-shifting signed integer due to implicit integer promotion, such that the most significant bit appeared on the sign bit. In practice, though, this results in the same left value as with an explicit cast, at least on known compilers, such as GCC and Clang. The reason is that in_addr_t, which is equivalent to uint32_t and same as "unsigned int" in ILP32 and LP64 data type models, has the same type width as the intermediate after integer promotion, so there's no side effects such as sign-extension. This explains why adding an explicit cast does not change object files in practice. Found with UndefinedBehaviorSanitizer (shift). Based on a patch by Piotr Sikora.
2019-03-06Listen port ranges.Roman Arutyunyan1-29/+118
A range is specified with a dash. For each port in a range a separate listen socket is created. Examples: listen 8080-9000; listen example.com:80-88;
2019-03-20Removed sorting of getaddrinfo() results.Roman Arutyunyan1-14/+5
Previously the ngx_inet_resolve_host() function sorted addresses in a way that IPv4 addresses came before IPv6 addresses. This was implemented in eaf95350d75c (1.3.10) along with the introduction of getaddrinfo() which could resolve host names to IPv6 addresses. Since the "listen" directive only used the first address, sorting allowed to preserve "listen" compatibility with the previous behavior and with the behavior of nginx built without IPv6 support. Now "listen" uses all resolved addresses which makes sorting pointless.
2019-03-15Multiple addresses in "listen".Roman Arutyunyan1-211/+129
Previously only one address was used by the listen directive handler even if host name resolved to multiple addresses. Now a separate listening socket is created for each address.
2017-10-05Fixed build without IPv6, broken by 874171c3c71a.Maxim Dounin1-1/+3
2017-10-04Fixed handling of non-null-terminated unix sockets.Maxim Dounin1-1/+3
At least FreeBSD, macOS, NetBSD, and OpenBSD can return unix sockets with non-null-terminated sun_path. Additionally, the address may become non-null-terminated if it does not fit into the buffer provided and was truncated (may happen on macOS, NetBSD, and Solaris, which allow unix socket addresess larger than struct sockaddr_un). As such, ngx_sock_ntop() might overread the sockaddr provided, as it used "%s" format and thus assumed null-terminated string. To fix this, the ngx_strnlen() function was introduced, and it is now used to calculate correct length of sun_path.
2016-10-10Core: sockaddr lengths now respected by ngx_cmp_sockaddr().Maxim Dounin1-6/+13
Linux can return AF_UNIX sockaddrs with partially filled sun_path, resulting in spurious comparison failures and failed binary upgrades. Added proper checking of the lengths provided. Reported by Jan Seda, http://mailman.nginx.org/pipermail/nginx-devel/2016-September/008832.html.
2016-09-07Core: introduced ngx_cidr_match() function.Dmitry Volyntsev1-0/+87
2016-06-20Fixed build on MSVC.Roman Arutyunyan1-1/+1
2016-06-20Introduced ngx_inet_get_port() and ngx_inet_set_port() functions.Roman Arutyunyan1-21/+62
2016-05-24Fixed build on MSVC.Maxim Dounin1-2/+2
2016-05-23Realip: port support in X-Real-IP and X-Forwarded-For.Dmitry Volyntsev1-0/+79
Now, the module extracts optional port which may accompany an IP address. This custom extension is introduced, among other things, in order to facilitate logging of original client ports. Addresses with ports are expected to be in the RFC 3986 format, that is, with IPv6 addresses in square brackets. E.g., "X-Real-IP: [2001:0db8::1]:12345" sets client port ($remote_port) to 12345.
2016-05-23Introduced the ngx_sockaddr_t type.Ruslan Ermilov1-3/+3
It's properly aligned and can hold any supported sockaddr.
2016-05-11Removed a surplus condition from ngx_parse_inet6_url().Ruslan Ermilov1-33/+30
No functional changes, since the condition was always true.
2016-05-11Core: fixed port handling in ngx_parse_inet6_url().Valentin Bartenev1-1/+6
This fixes buffer over-read when no port is specified in cases similar to 5df5d7d771f6, and catches missing port separator.
2016-04-08Removed redundant "u" format specifier.Ruslan Ermilov1-1/+1
It is implied for "x" and "X".
2016-03-31Fixed format specifiers in ngx_sprintf().Sergey Kandaurov1-1/+1
2016-03-30Style.Ruslan Ermilov1-10/+10
2016-02-26Core: allow strings without null-termination in ngx_parse_url().Piotr Sikora1-2/+4
This fixes buffer over-read while using variables in the "proxy_pass", "fastcgi_pass", "scgi_pass", and "uwsgi_pass" directives, where result of string evaluation isn't null-terminated. Found with MemorySanitizer. Signed-off-by: Piotr Sikora <piotrsikora@google.com>
2015-04-28Fixed overflow detection in ngx_inet_addr().Valentin Bartenev1-5/+5
Overflow detection of the last octet might not work. Reported by Sergey Polovko.
2015-03-17Overflow detection in ngx_inet_addr().Ruslan Ermilov1-2/+6
2013-12-06Core: externalized ngx_cmp_sockaddr().Ruslan Ermilov1-0/+73
It's also extended with the "cmp_port" argument to indicate whether ports should be compared as well, or only addresses.
2013-08-05Core: guard use of AI_ADDRCONFIG.Ruslan Ermilov1-0/+2
Some systems (notably NetBSD and OpenBSD) lack AI_ADDRCONFIG support. Reported by Piotr Sikora.
2013-08-05Fixed build with signed socklen_t and unix sockets.Maxim Dounin1-1/+1
This seems to be the case at least under Cygwin, where build was broken by 05ba5bce31e0 (1.5.3). Reported by Kevin Worthington, http://mailman.nginx.org/pipermail/nginx/2013-August/040028.html.
2013-08-05Core: only resolve address families configured on the local system.Ruslan Ermilov1-0/+1
This is done by passing AI_ADDRCONFIG to getaddrinfo(). On Linux, setting net.ipv6.conf.all.disable_ipv6 to 1 will now be respected. On FreeBSD, AI_ADDRCONFIG filtering is currently implemented by attempting to create a datagram socket for the corresponding family, which succeeds even if the system doesn't in fact have any addresses of that family configured. That is, if the system with IPv6 support in the kernel doesn't have IPv6 addresses configured, AI_ADDRCONFIG will filter out IPv6 only inside a jail without IPv6 addresses or with IPv6 disabled.
2013-07-11Core: extended ngx_sock_ntop() with socklen parameter.Vladimir Homutov1-5/+17
On Linux, sockaddr length is required to process unix socket addresses properly due to unnamed sockets (which don't have sun_path set at all) and abstract namespace sockets.
2013-01-10Fixed "proxy_pass" with IP address and no port (ticket #276).Ruslan Ermilov1-10/+4
Upstreams created by "proxy_pass" with IP address and no port were broken in 1.3.10, by not initializing port in u->sockaddr. API change: ngx_parse_url() was modified to always initialize port (in u->sockaddr and in u->port), even for the u->no_resolve case; ngx_http_upstream() and ngx_http_upstream_add() were adopted.
2012-12-22Properly initialize "struct in6_addr" with zeroes.Ruslan Ermilov1-1/+1
2012-12-17Implemented IPv6 support for URLs specified using domain names.Ruslan Ermilov1-29/+210
This includes "debug_connection", upstreams, "proxy_pass", etc. (ticket #92) To preserve compatibility, "listen" specified with a domain name selects the first IPv4 address, if available. If not available, the first IPv6 address will be used (ticket #186).
2012-12-17Fixed URL parsing code.Ruslan Ermilov1-5/+5
The URL parsing code is not expected to initialize port from default port when in "no_resolve" mode. This got broken in r4671 for the case of IPv6 literals.
2012-12-17Simplified URL parsing code.Ruslan Ermilov1-30/+26
Except for the "listen" directive, "*" specified as a hostname is no longer treated specially.
2012-06-04Support for IPv6 literals in proxy_pass and so on.Maxim Dounin1-7/+30
2012-06-01Code reduction (no functional changes).Ruslan Ermilov1-19/+2
2012-05-21Removed historical and now redundant syntax pre-checks in ngx_parse_url().Ruslan Ermilov1-5/+0
2012-04-12Reduced the number of lines of code in ngx_inet_addr().Ruslan Ermilov1-5/+1
2012-04-11Improved readability of the code that produces bitmask from prefix.Ruslan Ermilov1-2/+2
In collaboration with Maxim Dounin.
2012-04-03In ngx_ptocidr(), check that the supplied prefix length is withinRuslan Ermilov1-0/+7
the allowed range.
2012-04-03Fixed spelling in multiline C comments.Ruslan Ermilov1-1/+1
2012-01-18Copyright updated.Maxim Konovalov1-0/+1
2011-10-25Fixed port range checking.Ruslan Ermilov1-3/+3
2011-04-15fix segfault in IPv6 parsing while processing invalid IPv4 address X.YYYY.ZIgor Sysoev1-1/+1
patch by Maxim Dounin
2011-02-17fix u->one_addr handling in ngx_inet_resolve_host()Igor Sysoev1-1/+1
patch by Maxim Dounin
2009-12-07fix double free(), introduced in r3268Igor Sysoev1-1/+0
2009-11-03ngx_ptocidr() supports IPv6Igor Sysoev1-26/+66
2009-11-03make ngx_inet6_ntop() non-staticIgor Sysoev1-4/+1
2009-11-02change ngx_parse_addr() interfaceIgor Sysoev1-22/+13
2009-11-02ngx_parse_addr()Igor Sysoev1-0/+63
2009-11-02rename ngx_peer_addr_t to ngx_addr_tIgor Sysoev1-3/+3
2009-11-02use sin6_addr.s6_addr instead of "(u_char *) & .sin6_addr"Igor Sysoev1-2/+2