Miniupnpd: update from 1.8 (20140422) to 1.9 (20141209)
[tomato.git] / release / src / router / miniupnpd / pcp_msg_struct.h
blob2e795e8b0270d606a3d20452319013954a675ee7
1 /* $Id: pcp_msg_struct.h,v 1.5 2014/09/06 08:15:37 nanard Exp $ */
2 /* MiniUPnP project
3 * Website : http://miniupnp.free.fr/
4 * Author : Peter Tatrai
6 Copyright (c) 2013 by Cisco Systems, Inc.
7 All rights reserved.
9 Redistribution and use in source and binary forms, with or without
10 modification, are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice,
13 this list of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above copyright notice,
15 this list of conditions and the following disclaimer in the documentation
16 and/or other materials provided with the distribution.
17 * The name of the author may not be used to endorse or promote products
18 derived from this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
33 #define PCP_OPCODE_ANNOUNCE 0
34 #define PCP_OPCODE_MAP 1
35 #define PCP_OPCODE_PEER 2
36 #ifdef PCP_SADSCP
37 #define PCP_OPCODE_SADSCP 3
38 #endif
40 /* Possible response codes sent by server, as a result of client request*/
41 #define PCP_SUCCESS 0
43 #define PCP_ERR_UNSUPP_VERSION 1
44 /** The version number at the start of the PCP Request
45 * header is not recognized by this PCP server. This is a long
46 * lifetime error. This document describes PCP version 2.
49 #define PCP_ERR_NOT_AUTHORIZED 2
50 /**The requested operation is disabled for this PCP
51 * client, or the PCP client requested an operation that cannot be
52 * fulfilled by the PCP server's security policy. This is a long
53 * lifetime error.
56 #define PCP_ERR_MALFORMED_REQUEST 3
57 /**The request could not be successfully parsed.
58 * This is a long lifetime error.
61 #define PCP_ERR_UNSUPP_OPCODE 4
62 /** Unsupported Opcode. This is a long lifetime error.
65 #define PCP_ERR_UNSUPP_OPTION 5
66 /**Unsupported Option. This error only occurs if the
67 * Option is in the mandatory-to-process range. This is a long
68 * lifetime error.
71 #define PCP_ERR_MALFORMED_OPTION 6
72 /**Malformed Option (e.g., appears too many times,
73 * invalid length). This is a long lifetime error.
76 #define PCP_ERR_NETWORK_FAILURE 7
77 /**The PCP server or the device it controls are
78 * experiencing a network failure of some sort (e.g., has not
79 * obtained an External IP address). This is a short lifetime error.
82 #define PCP_ERR_NO_RESOURCES 8
83 /**Request is well-formed and valid, but the server has
84 * insufficient resources to complete the requested operation at this
85 * time. For example, the NAT device cannot create more mappings at
86 * this time, is short of CPU cycles or memory, or is unable to
87 * handle the request due to some other temporary condition. The
88 * same request may succeed in the future. This is a system-wide
89 * error, different from USER_EX_QUOTA. This can be used as a catch-
90 * all error, should no other error message be suitable. This is a
91 * short lifetime error.
94 #define PCP_ERR_UNSUPP_PROTOCOL 9
95 /**Unsupported transport protocol, e.g. SCTP in a
96 * NAT that handles only UDP and TCP. This is a long lifetime error.
99 #define PCP_ERR_USER_EX_QUOTA 10
100 /** This attempt to create a new mapping would exceed
101 * this subscriber's port quota. This is a short lifetime error.
104 #define PCP_ERR_CANNOT_PROVIDE_EXTERNAL 11
105 /** The suggested external port and/or
106 * external address cannot be provided. This error MUST only be
107 * returned for:
108 * * MAP requests that included the PREFER_FAILURE Option
109 * (normal MAP requests will return an available external port)
110 * * MAP requests for the SCTP protocol (PREFER_FAILURE is implied)
111 * * PEER requests
114 #define PCP_ERR_ADDRESS_MISMATCH 12
115 /** The source IP address of the request packet does
116 * not match the contents of the PCP Client's IP Address field, due
117 * to an unexpected NAT on the path between the PCP client and the
118 * PCP-controlled NAT or firewall. This is a long lifetime error.
121 #define PCP_ERR_EXCESSIVE_REMOTE_PEERS 13
122 /** The PCP server was not able to create the
123 * filters in this request. This result code MUST only be returned
124 * if the MAP request contained the FILTER Option. See Section 13.3
125 * for processing information. This is a long lifetime error.
128 typedef enum pcp_options {
129 PCP_OPTION_3RD_PARTY = 1,
130 PCP_OPTION_PREF_FAIL = 2,
131 PCP_OPTION_FILTER = 3,
132 #ifdef PCP_FLOWP
133 PCP_OPTION_FLOW_PRIORITY = 4, /*TODO: change it to correct value*/
134 #endif
135 } pcp_options_t;
138 #ifdef _WIN32
139 #pragma warning (push)
140 #pragma warning (disable:4200)
141 #endif /* _WIN32 */
143 #pragma pack(push, 1)
145 /* PCP common request header*/
146 typedef struct pcp_request {
147 uint8_t ver;
148 uint8_t r_opcode;
149 uint16_t reserved;
150 uint32_t req_lifetime;
151 struct in6_addr ip; /* ipv4 will be represented
152 by the ipv4 mapped ipv6 */
153 uint8_t next_data[0];
154 } pcp_request_t;
156 /* PCP common response header*/
157 typedef struct pcp_response {
158 uint8_t ver;
159 uint8_t r_opcode; /* R indicates Request (0) or Response (1)
160 Opcode is 7 bit value specifying operation MAP or PEER */
161 uint8_t reserved; /* reserved bits, must be 0 on transmission and must be ignored on reception */
162 uint8_t result_code; /* */
163 uint32_t lifetime; /* an unsigned 32-bit integer, in seconds {0, 2^32-1}*/
164 uint32_t epochtime; /* epoch indicates how long has PCP server had its current mappings
165 it increases by 1 every second */
166 uint32_t reserved1[3];/* For requests that were successfully parsed this must be sent as 0 */
167 uint8_t next_data[0];
168 } pcp_response_t;
171 typedef struct pcp_options_hdr {
172 uint8_t code; /* Most significant bit indicates if this option is mandatory (0) or optional (1) */
173 uint8_t reserved; /* MUST be set to 0 on transmission and MUST be ignored on reception */
174 uint16_t len; /* indicates the length of the enclosed data in octets (see RFC) */
175 uint8_t next_data[0]; /* */
176 } pcp_options_hdr_t;
178 /* same for both request and response */
179 typedef struct pcp_map_v2 {
180 uint32_t nonce[3];
181 uint8_t protocol; /* 6 = TCP, 17 = UDP, 0 = 'all protocols' */
182 uint8_t reserved[3];
183 uint16_t int_port; /* 0 indicates 'all ports' */
184 uint16_t ext_port; /* suggested external port */
185 struct in6_addr ext_ip; /* suggested external IP address
186 * ipv4 will be represented by the ipv4 mapped ipv6 */
187 uint8_t next_data[0];
188 } pcp_map_v2_t;
190 /* same for both request and response */
191 typedef struct pcp_map_v1 {
192 uint8_t protocol;
193 uint8_t reserved[3];
194 uint16_t int_port;
195 uint16_t ext_port;
196 struct in6_addr ext_ip; /* ipv4 will be represented
197 by the ipv4 mapped ipv6 */
198 uint8_t next_data[0];
199 } pcp_map_v1_t;
201 /* same for both request and response */
202 typedef struct pcp_peer_v1 {
203 uint8_t protocol;
204 uint8_t reserved[3];
205 uint16_t int_port;
206 uint16_t ext_port;
207 struct in6_addr ext_ip; /* ipv4 will be represented
208 by the ipv4 mapped ipv6 */
209 uint16_t peer_port;
210 uint16_t reserved1;
211 struct in6_addr peer_ip;
212 uint8_t next_data[0];
213 } pcp_peer_v1_t;
215 /* same for both request and response */
216 typedef struct pcp_peer_v2 {
217 uint32_t nonce[3];
218 uint8_t protocol;
219 uint8_t reserved[3];
220 uint16_t int_port;
221 uint16_t ext_port;
222 struct in6_addr ext_ip; /* ipv4 will be represented
223 by the ipv4 mapped ipv6 */
224 uint16_t peer_port;
225 uint16_t reserved1;
226 struct in6_addr peer_ip;
227 uint8_t next_data[0];
228 } pcp_peer_v2_t;
230 #ifdef PCP_SADSCP
231 typedef struct pcp_sadscp_req {
232 uint32_t nonce[3];
233 uint8_t tolerance_fields;
234 uint8_t app_name_length;
235 char app_name[0];
236 } pcp_sadscp_req_t;
238 typedef struct pcp_sadscp_resp {
239 uint32_t nonce[3];
240 #define PCP_SADSCP_MASK ((1<<6)-1)
241 uint8_t a_r_dscp_value;
242 uint8_t reserved[3];
243 } pcp_sadscp_resp_t;
244 #endif
246 typedef struct pcp_prefer_fail_option {
247 uint8_t option;
248 uint8_t reserved;
249 uint16_t len;
250 uint8_t next_data[0];
251 } pcp_prefer_fail_option_t;
253 typedef struct pcp_3rd_party_option{
254 uint8_t option;
255 uint8_t reserved;
256 uint16_t len;
257 struct in6_addr ip;
258 uint8_t next_data[0];
259 } pcp_3rd_party_option_t;
261 #ifdef PCP_FLOWP
262 typedef struct pcp_flow_priority_option{
263 uint8_t option;
264 uint8_t reserved;
265 uint16_t len;
266 uint8_t dscp_up;
267 uint8_t dscp_down;
268 #define PCP_DSCP_MASK ((1<<6)-1)
269 uint8_t reserved2;
270 /* most significant bit is used for response */
271 uint8_t response_bit;
272 uint8_t next_data[0];
273 } pcp_flow_priority_option_t;
274 #endif
276 typedef struct pcp_filter_option {
277 uint8_t option;
278 uint8_t reserved1;
279 uint16_t len;
280 uint8_t reserved2;
281 uint8_t prefix_len;
282 uint16_t peer_port;
283 struct in6_addr peer_ip;
284 }pcp_filter_option_t;
286 #pragma pack(pop)
288 #ifdef _WIN32
289 #pragma warning (pop)
290 #endif /* _WIN32 */