Mercurial > hg > nginx-quic
comparison src/core/ngx_proxy_protocol.c @ 7252:7bdab16c55f1
Core: style.
author | Vladimir Homutov <vl@nginx.com> |
---|---|
date | Tue, 27 Mar 2018 18:39:38 +0300 |
parents | 416953ef0428 |
children | 63e91f263a49 |
comparison
equal
deleted
inserted
replaced
7251:416953ef0428 | 7252:7bdab16c55f1 |
---|---|
16 #define NGX_PP_V2_AF_UNSPEC 0 | 16 #define NGX_PP_V2_AF_UNSPEC 0 |
17 #define NGX_PP_V2_AF_INET 1 | 17 #define NGX_PP_V2_AF_INET 1 |
18 #define NGX_PP_V2_AF_INET6 2 | 18 #define NGX_PP_V2_AF_INET6 2 |
19 | 19 |
20 | 20 |
21 #define ngx_pp_v2_get_u16(p) \ | 21 #define ngx_pp_v2_get_u16(p) ((p)[0] << 8 | (p)[1]) |
22 ( ((uint16_t) ((u_char *) (p))[0] << 8) \ | |
23 + ( ((u_char *) (p))[1]) ) | |
24 | 22 |
25 | 23 |
26 typedef struct { | 24 typedef struct { |
27 u_char signature[NGX_PP_V2_SIGLEN]; | 25 u_char signature[NGX_PP_V2_SIGLEN]; |
28 u_char ver_cmd; | 26 u_char ver_cmd; |
29 u_char fam_transp; | 27 u_char family_transport; |
30 u_char len[2]; | 28 u_char len[2]; |
31 } ngx_pp_v2_header_t; | 29 } ngx_pp_v2_header_t; |
32 | 30 |
33 | 31 |
34 typedef struct { | 32 typedef struct { |
55 | 53 |
56 static u_char *ngx_proxy_protocol_v2_read(ngx_connection_t *c, u_char *buf, | 54 static u_char *ngx_proxy_protocol_v2_read(ngx_connection_t *c, u_char *buf, |
57 u_char *last); | 55 u_char *last); |
58 | 56 |
59 static const u_char ngx_pp_v2_signature[NGX_PP_V2_SIGLEN] = | 57 static const u_char ngx_pp_v2_signature[NGX_PP_V2_SIGLEN] = |
60 { 0x0D, 0x0A, 0x0D, 0x0A, 0x00, 0x0D, 0x0A, 0x51, 0x55, 0x49, 0x54, 0x0A }; | 58 { 0x0d, 0x0a, 0x0d, 0x0a, 0x00, 0x0d, 0x0a, 0x51, 0x55, 0x49, 0x54, 0x0a }; |
61 | 59 |
62 | 60 |
63 u_char * | 61 u_char * |
64 ngx_proxy_protocol_read(ngx_connection_t *c, u_char *buf, u_char *last) | 62 ngx_proxy_protocol_read(ngx_connection_t *c, u_char *buf, u_char *last) |
65 { | 63 { |
160 } | 158 } |
161 | 159 |
162 c->proxy_protocol_port = (in_port_t) n; | 160 c->proxy_protocol_port = (in_port_t) n; |
163 | 161 |
164 ngx_log_debug2(NGX_LOG_DEBUG_CORE, c->log, 0, | 162 ngx_log_debug2(NGX_LOG_DEBUG_CORE, c->log, 0, |
165 "PROXY protocol address: %V %i", &c->proxy_protocol_addr, n); | 163 "PROXY protocol address: %V %d", &c->proxy_protocol_addr, |
164 c->proxy_protocol_port); | |
166 | 165 |
167 skip: | 166 skip: |
168 | 167 |
169 for ( /* void */ ; p < last - 1; p++) { | 168 for ( /* void */ ; p < last - 1; p++) { |
170 if (p[0] == CR && p[1] == LF) { | 169 if (p[0] == CR && p[1] == LF) { |
256 return NULL; | 255 return NULL; |
257 } | 256 } |
258 | 257 |
259 end = buf + len; | 258 end = buf + len; |
260 | 259 |
261 cmd = hdr->ver_cmd & 0x0F; | 260 cmd = hdr->ver_cmd & 0x0f; |
262 | 261 |
263 if (cmd != NGX_PP_V2_CMD_PROXY) { | 262 if (cmd != NGX_PP_V2_CMD_PROXY) { |
264 ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0, | 263 ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0, |
265 "PROXY protocol v2 unsupported cmd 0x%xi", cmd); | 264 "PROXY protocol v2 unsupported command 0x%xi", cmd); |
266 return end; | 265 return end; |
267 } | 266 } |
268 | 267 |
269 transport = hdr->fam_transp & 0x0F; | 268 transport = hdr->family_transport & 0x0f; |
270 | 269 |
271 if (transport != NGX_PP_V2_STREAM) { | 270 if (transport != NGX_PP_V2_STREAM) { |
272 ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0, | 271 ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0, |
273 "PROXY protocol v2 unsupported transport 0x%xi", | 272 "PROXY protocol v2 unsupported transport 0x%xi", |
274 transport); | 273 transport); |
275 return end; | 274 return end; |
276 } | 275 } |
277 | 276 |
278 family = hdr->fam_transp >> 4; | 277 family = hdr->family_transport >> 4; |
279 | 278 |
280 addrs = (ngx_pp_v2_addrs_t *) buf; | 279 addrs = (ngx_pp_v2_addrs_t *) buf; |
281 | 280 |
282 switch (family) { | 281 switch (family) { |
283 | 282 |
306 | 305 |
307 #if (NGX_HAVE_INET6) | 306 #if (NGX_HAVE_INET6) |
308 | 307 |
309 case NGX_PP_V2_AF_INET6: | 308 case NGX_PP_V2_AF_INET6: |
310 | 309 |
311 if ((size_t) (end - buf) < sizeof(ngx_pp_v2_inet6_addrs_t)) { | 310 if ((size_t) (end - buf) < sizeof(ngx_pp_v2_inet6_addrs_t)) { |
312 return NULL; | 311 return NULL; |
313 } | 312 } |
314 | 313 |
315 sockaddr.sockaddr_in6.sin6_family = AF_INET6; | 314 sockaddr.sockaddr_in6.sin6_family = AF_INET6; |
316 sockaddr.sockaddr_in6.sin6_port = 0; | 315 sockaddr.sockaddr_in6.sin6_port = 0; |
327 #endif | 326 #endif |
328 | 327 |
329 default: | 328 default: |
330 | 329 |
331 ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0, | 330 ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0, |
332 "PROXY_protocol v2 unsupported address family " | 331 "PROXY protocol v2 unsupported address family 0x%xi", |
333 "0x%xi", family); | 332 family); |
334 return end; | 333 return end; |
335 } | 334 } |
336 | 335 |
337 name = &c->proxy_protocol_addr; | 336 name = &c->proxy_protocol_addr; |
338 | 337 |
346 if (name->len == 0) { | 345 if (name->len == 0) { |
347 return NULL; | 346 return NULL; |
348 } | 347 } |
349 | 348 |
350 ngx_log_debug2(NGX_LOG_DEBUG_CORE, c->log, 0, | 349 ngx_log_debug2(NGX_LOG_DEBUG_CORE, c->log, 0, |
351 "PROXY protocol v2 address: %V %i", name, | 350 "PROXY protocol v2 address: %V %d", name, |
352 (ngx_int_t) c->proxy_protocol_port); | 351 c->proxy_protocol_port); |
353 | 352 |
354 if (buf < end) { | 353 if (buf < end) { |
355 ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0, | 354 ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0, |
356 "PROXY protocol v2 %z bytes tlv ignored", end - buf); | 355 "PROXY protocol v2 %z bytes tlv ignored", end - buf); |
357 } | 356 } |