1 /*
2  * Copyright (c) 2018 Antmicro Ltd
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_SUBSYS_NET_LIB_SOCKS_SOCKS_INTERNAL_H_
8 #define ZEPHYR_SUBSYS_NET_LIB_SOCKS_SOCKS_INTERNAL_H_
9 
10 #define SOCKS5_PKT_MAGIC			0x05
11 #define SOCKS5_PKT_RSV				0x00
12 
13 #define SOCKS5_AUTH_METHOD_NOAUTH		0x00
14 #define SOCKS5_AUTH_METHOD_GSSAPI		0x01
15 #define SOCKS5_AUTH_METHOD_USERPASS		0x02
16 #define SOCKS5_AUTH_METHOD_NONEG		0xFF
17 
18 #define SOCKS5_CMD_CONNECT			0x01
19 #define SOCKS5_CMD_BIND				0x02
20 #define SOCKS5_CMD_UDP_ASSOCIATE		0x03
21 
22 #define SOCKS5_ATYP_IPV4			0x01
23 #define SOCKS5_ATYP_DOMAINNAME			0x03
24 #define SOCKS5_ATYP_IPV6			0x04
25 
26 #define SOCKS5_CMD_RESP_SUCCESS			0x00
27 #define SOCKS5_CMD_RESP_FAILURE			0x01
28 #define SOCKS5_CMD_RESP_NOT_ALLOWED		0x02
29 #define SOCKS5_CMD_RESP_NET_UNREACHABLE		0x03
30 #define SOCKS5_CMD_RESP_HOST_UNREACHABLE	0x04
31 #define SOCKS5_CMD_RESP_REFUSED			0x05
32 #define SOCKS5_CMD_RESP_TTL_EXPIRED		0x06
33 #define SOCKS5_CMD_RESP_CMD_NOT_SUPPORTED	0x07
34 #define SOCKS5_CMD_RESP_ATYP_NOT_SUPPORTED	0x08
35 
36 struct socks5_method_request_common {
37 	uint8_t ver;
38 	uint8_t nmethods;
39 } __packed;
40 
41 struct socks5_method_request {
42 	struct socks5_method_request_common r;
43 	uint8_t methods[255];
44 } __packed;
45 
46 struct socks5_method_response {
47 	uint8_t ver;
48 	uint8_t method;
49 } __packed;
50 
51 struct socks5_ipv4_addr {
52 	uint8_t addr[4];
53 	uint16_t port;
54 } __packed;
55 
56 struct socks5_ipv6_addr {
57 	uint8_t addr[16];
58 	uint16_t port;
59 } __packed;
60 
61 struct socks5_command_request_common {
62 	uint8_t ver;
63 	uint8_t cmd;
64 	uint8_t rsv;
65 	uint8_t atyp;
66 } __packed;
67 
68 struct socks5_command_request {
69 	struct socks5_command_request_common r;
70 	union {
71 		struct socks5_ipv4_addr ipv4_addr;
72 		struct socks5_ipv6_addr ipv6_addr;
73 	};
74 } __packed;
75 
76 struct socks5_command_response_common {
77 	uint8_t ver;
78 	uint8_t rep;
79 	uint8_t rsv;
80 	uint8_t atyp;
81 } __packed;
82 
83 struct socks5_command_response {
84 	struct socks5_command_response_common r;
85 	union {
86 		struct socks5_ipv4_addr ipv4_addr;
87 		struct socks5_ipv6_addr ipv6_addr;
88 	};
89 } __packed;
90 
91 #endif /* ZEPHYR_SUBSYS_NET_LIB_SOCKS_SOCKS_INTERNAL_H_ */
92