forked from Tencent/phxsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproxy_protocol.h
More file actions
60 lines (49 loc) · 1.79 KB
/
Copy pathproxy_protocol.h
File metadata and controls
60 lines (49 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/*
Copyright (c) 2016 Tencent. See the AUTHORS file for names
of contributors.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the
Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#pragma once
namespace phxsqlproxy {
typedef struct tagProxyHdrV1 {
char line[108];
} ProxyHdrV1_t;
typedef struct tagProxyHdrV2 {
uint8_t sig[12];
uint8_t ver_cmd;
uint8_t fam;
uint16_t len;
union {
struct { // for TCP/UDP over IPv4, len = 12
uint32_t src_addr;
uint32_t dst_addr;
uint16_t src_port;
uint16_t dst_port;
} __attribute__((packed)) ip4;
struct { // for TCP/UDP over IPv6, len = 36
uint8_t src_addr[16];
uint8_t dst_addr[16];
uint16_t src_port;
uint16_t dst_port;
} __attribute__((packed)) ip6;
} addr;
} __attribute__((packed)) ProxyHdrV2_t;
const uint32_t PP2_VERSION = 0x20;
const uint32_t PP2_CMD_LOCAL = 0x00;
const uint32_t PP2_CMD_PROXY = 0x01;
const uint32_t PP2_FAM_UNSPEC = 0x00;
const uint32_t PP2_FAM_TCP4 = 0x11;
const uint32_t PP2_FAM_TCP6 = 0x21;
const char * const PP2_SIGNATURE = "\x0D\x0A\x0D\x0A\x00\x0D\x0A\x51\x55\x49\x54\x0A";
}