Mercurial > hg > nginx
comparison src/core/ngx_proxy_protocol.c @ 6184:fa663739e115
Stream: client-side PROXY protocol.
The new directive "proxy_protocol" toggles sending out PROXY protocol header
to upstream once connection is established.
author | Roman Arutyunyan <arut@nginx.com> |
---|---|
date | Tue, 16 Jun 2015 13:45:16 +0300 |
parents | 3a72b1805c52 |
children | a420cb1c170b |
comparison
equal
deleted
inserted
replaced
6183:4dcffe43a7ea | 6184:fa663739e115 |
---|---|
87 ngx_log_error(NGX_LOG_ERR, c->log, 0, | 87 ngx_log_error(NGX_LOG_ERR, c->log, 0, |
88 "broken header: \"%*s\"", (size_t) (last - buf), buf); | 88 "broken header: \"%*s\"", (size_t) (last - buf), buf); |
89 | 89 |
90 return NULL; | 90 return NULL; |
91 } | 91 } |
92 | |
93 | |
94 u_char * | |
95 ngx_proxy_protocol_write(ngx_connection_t *c, u_char *buf, u_char *last) | |
96 { | |
97 ngx_uint_t port, lport; | |
98 | |
99 if (last - buf < NGX_PROXY_PROTOCOL_MAX_HEADER) { | |
100 return NULL; | |
101 } | |
102 | |
103 if (ngx_connection_local_sockaddr(c, NULL, 0) != NGX_OK) { | |
104 return NULL; | |
105 } | |
106 | |
107 switch (c->sockaddr->sa_family) { | |
108 | |
109 case AF_INET: | |
110 buf = ngx_cpymem(buf, "PROXY TCP4 ", sizeof("PROXY TCP4 ") - 1); | |
111 | |
112 port = ntohs(((struct sockaddr_in *) c->sockaddr)->sin_port); | |
113 lport = ntohs(((struct sockaddr_in *) c->local_sockaddr)->sin_port); | |
114 | |
115 break; | |
116 | |
117 #if (NGX_HAVE_INET6) | |
118 case AF_INET6: | |
119 buf = ngx_cpymem(buf, "PROXY TCP6 ", sizeof("PROXY TCP6 ") - 1); | |
120 | |
121 port = ntohs(((struct sockaddr_in6 *) c->sockaddr)->sin6_port); | |
122 lport = ntohs(((struct sockaddr_in6 *) c->local_sockaddr)->sin6_port); | |
123 | |
124 break; | |
125 #endif | |
126 | |
127 default: | |
128 return ngx_cpymem(buf, "PROXY UNKNOWN" CRLF, | |
129 sizeof("PROXY UNKNOWN" CRLF) - 1); | |
130 } | |
131 | |
132 buf += ngx_sock_ntop(c->sockaddr, c->socklen, buf, last - buf, 0); | |
133 | |
134 *buf++ = ' '; | |
135 | |
136 buf += ngx_sock_ntop(c->local_sockaddr, c->local_socklen, buf, last - buf, | |
137 0); | |
138 | |
139 return ngx_slprintf(buf, last, " %ui %ui" CRLF, port, lport); | |
140 } |