1 /* $Id: pcp_msg_struct.h,v 1.5 2014/09/06 08:15:37 nanard Exp $ */
3 * Website : http://miniupnp.free.fr/
4 * Author : Peter Tatrai
6 Copyright (c) 2013 by Cisco Systems, Inc.
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
37 #define PCP_OPCODE_SADSCP 3
40 /* Possible response codes sent by server, as a result of client request*/
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
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
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
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)
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,
133 PCP_OPTION_FLOW_PRIORITY
= 4, /*TODO: change it to correct value*/
139 #pragma warning (push)
140 #pragma warning (disable:4200)
143 #pragma pack(push, 1)
145 /* PCP common request header*/
146 typedef struct pcp_request
{
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];
156 /* PCP common response header*/
157 typedef struct pcp_response
{
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];
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]; /* */
178 /* same for both request and response */
179 typedef struct pcp_map_v2
{
181 uint8_t protocol
; /* 6 = TCP, 17 = UDP, 0 = 'all protocols' */
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];
190 /* same for both request and response */
191 typedef struct pcp_map_v1
{
196 struct in6_addr ext_ip
; /* ipv4 will be represented
197 by the ipv4 mapped ipv6 */
198 uint8_t next_data
[0];
201 /* same for both request and response */
202 typedef struct pcp_peer_v1
{
207 struct in6_addr ext_ip
; /* ipv4 will be represented
208 by the ipv4 mapped ipv6 */
211 struct in6_addr peer_ip
;
212 uint8_t next_data
[0];
215 /* same for both request and response */
216 typedef struct pcp_peer_v2
{
222 struct in6_addr ext_ip
; /* ipv4 will be represented
223 by the ipv4 mapped ipv6 */
226 struct in6_addr peer_ip
;
227 uint8_t next_data
[0];
231 typedef struct pcp_sadscp_req
{
233 uint8_t tolerance_fields
;
234 uint8_t app_name_length
;
238 typedef struct pcp_sadscp_resp
{
240 #define PCP_SADSCP_MASK ((1<<6)-1)
241 uint8_t a_r_dscp_value
;
246 typedef struct pcp_prefer_fail_option
{
250 uint8_t next_data
[0];
251 } pcp_prefer_fail_option_t
;
253 typedef struct pcp_3rd_party_option
{
258 uint8_t next_data
[0];
259 } pcp_3rd_party_option_t
;
262 typedef struct pcp_flow_priority_option
{
268 #define PCP_DSCP_MASK ((1<<6)-1)
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
;
276 typedef struct pcp_filter_option
{
283 struct in6_addr peer_ip
;
284 }pcp_filter_option_t
;
289 #pragma warning (pop)