Core: named PP v2 address-family and TLV-type constants.

Define NGX_PROXY_PROTOCOL_AF_* and NGX_PROXY_PROTOCOL_V2_TYPE_* /
SUBTYPE_* constants in ngx_proxy_protocol.h, replacing the raw hex
literals used in ngx_proxy_protocol_v2_write() for the family_transport
byte.  The local AF_INET/AF_INET6 defines in ngx_proxy_protocol.c are
removed; the read path's existing NGX_PROXY_PROTOCOL_AF_INET/INET6
references now bind to the header definitions.
This commit is contained in:
Vadim Zhestikov 2026-05-12 09:37:30 -07:00
parent fb7594b2e1
commit 4e27cff7cf
2 changed files with 22 additions and 8 deletions

View file

@ -9,10 +9,6 @@
#include <ngx_core.h>
#define NGX_PROXY_PROTOCOL_AF_INET 1
#define NGX_PROXY_PROTOCOL_AF_INET6 2
#define ngx_proxy_protocol_parse_uint16(p) \
( ((uint16_t) (p)[0] << 8) \
+ ( (p)[1]) )
@ -361,7 +357,7 @@ ngx_proxy_protocol_v2_write(ngx_connection_t *c, u_char *buf, u_char *last)
case AF_INET:
header->family_transport = 0x10 | transport; /* AF_INET */
header->family_transport = (NGX_PROXY_PROTOCOL_AF_INET << 4) | transport;
header->len[0] = 0;
header->len[1] = sizeof(ngx_proxy_protocol_inet_addrs_t);
@ -396,7 +392,7 @@ ngx_proxy_protocol_v2_write(ngx_connection_t *c, u_char *buf, u_char *last)
if (IN6_IS_ADDR_V4MAPPED(src6)) {
header->family_transport = 0x10 | transport; /* AF_INET */
header->family_transport = (NGX_PROXY_PROTOCOL_AF_INET << 4) | transport;
header->len[0] = 0;
header->len[1] = sizeof(ngx_proxy_protocol_inet_addrs_t);
@ -414,7 +410,7 @@ ngx_proxy_protocol_v2_write(ngx_connection_t *c, u_char *buf, u_char *last)
} else {
header->family_transport = 0x20 | transport; /* AF_INET6 */
header->family_transport = (NGX_PROXY_PROTOCOL_AF_INET6 << 4) | transport;
header->len[0] = 0;
header->len[1] = sizeof(ngx_proxy_protocol_inet6_addrs_t);
@ -437,7 +433,7 @@ ngx_proxy_protocol_v2_write(ngx_connection_t *c, u_char *buf, u_char *last)
default:
header->family_transport = 0x00; /* UNSPEC */
header->family_transport = NGX_PROXY_PROTOCOL_AF_UNSPEC << 4;
header->len[0] = 0;
header->len[1] = 0;

View file

@ -17,6 +17,24 @@
#define NGX_PROXY_PROTOCOL_V2_MAX_HEADER 52
#define NGX_PROXY_PROTOCOL_MAX_HEADER 4096
#define NGX_PROXY_PROTOCOL_AF_UNSPEC 0
#define NGX_PROXY_PROTOCOL_AF_INET 1
#define NGX_PROXY_PROTOCOL_AF_INET6 2
#define NGX_PROXY_PROTOCOL_AF_UNIX 3
#define NGX_PROXY_PROTOCOL_V2_TYPE_ALPN 0x01
#define NGX_PROXY_PROTOCOL_V2_TYPE_AUTHORITY 0x02
#define NGX_PROXY_PROTOCOL_V2_TYPE_CRC32C 0x03
#define NGX_PROXY_PROTOCOL_V2_TYPE_NOOP 0x04
#define NGX_PROXY_PROTOCOL_V2_TYPE_UNIQUE_ID 0x05
#define NGX_PROXY_PROTOCOL_V2_TYPE_SSL 0x20
#define NGX_PROXY_PROTOCOL_V2_SUBTYPE_SSL_VERSION 0x21
#define NGX_PROXY_PROTOCOL_V2_SUBTYPE_SSL_CN 0x22
#define NGX_PROXY_PROTOCOL_V2_SUBTYPE_SSL_CIPHER 0x23
#define NGX_PROXY_PROTOCOL_V2_SUBTYPE_SSL_SIG_ALG 0x24
#define NGX_PROXY_PROTOCOL_V2_SUBTYPE_SSL_KEY_ALG 0x25
#define NGX_PROXY_PROTOCOL_V2_TYPE_NETNS 0x30
struct ngx_proxy_protocol_s {
ngx_str_t src_addr;