Initial commit of vpp code.
[vpp.git] / vnet / vnet / vcgn / cnat_v4_pptp_alg.h
1 /*
2  *------------------------------------------------------------------
3  * cnat_v4_pptp_alg.h
4  *
5  * Copyright (c) 2009-2013 Cisco and/or its affiliates.
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at:
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *------------------------------------------------------------------
18  */
19
20 #ifndef __CNAT_V4_PPTP_ALG_H__
21 #define __CNAT_V4_PPTP_ALG_H__
22
23 /* Debug utils of PPTP */
24 #define PPTP_DBG(debug, ...)  \
25             if(PREDICT_FALSE(cnat_pptp_debug_flag >= debug)) { \
26                     PLATFORM_DEBUG_PRINT("%s:%s:%d - ", \
27                            __FILE__, __FUNCTION__, __LINE__);\
28                     PLATFORM_DEBUG_PRINT(__VA_ARGS__);\
29                     PLATFORM_DEBUG_PRINT("\n"); \
30             } 
31
32 #define PPTP_DUMP_PACKET(ip, len) pptp_hex_dump(ip, len)
33
34
35 #define PPTP_DISABLED  0 
36 #define PPTP_ENABLED   1
37
38 #define PPTP_GRE_TIMEOUT  60 /*sec */
39
40 #define TCP_PPTP_PORT 1723
41
42 #define PPTP_PAC 0 
43 #define PPTP_PNS 1
44
45 /* PPTP MSG TYPE */
46
47 #define PPTP_MSG_TYPE_CONTROL  1
48 #define PPTP_MSG_TYPE_MGMT     2 
49
50 /* PPTP control messages */
51
52 /* control connection mgmt */ 
53 #define PPTP_START_CC_RQ           1 
54 #define PPTP_START_CC_RP           2 
55 #define PPTP_STOP_CC_RQ            3 
56 #define PPTP_STOP_CC_RP            4 
57 #define PPTP_ECHO_RQ               5 
58 #define PPTP_ECHO_RP               6 
59
60 /* call mgmt */
61 #define PPTP_OBOUND_CALL_RQ        7 
62 #define PPTP_OBOUND_CALL_RP        8 
63 #define PPTP_IBOUND_CALL_RQ        9 
64 #define PPTP_IBOUND_CALL_RP        10 
65 #define PPTP_IBOUND_CALL_CN        11 
66 #define PPTP_CALL_CLEAR_RQ         12 
67 #define PPTP_CALL_DISCON_NT        13 
68
69 /* other */
70
71 #define PPTP_WAN_ERR_NT            14
72 #define PPTP_SET_LINK_INF          15
73
74 #define PPTP_MIN_HDR_LEN           8
75
76 /* Byte offsets from start of TCP Data(PPTP header) */ 
77
78 #define PPTP_CTRL_MGMT_TYPE_OFFSET   0x02 
79 #define PPTP_CC_TYPE_OFFSET          0x08
80 #define PPTP_HDR_CALL_ID_OFFSET      0x0c 
81 #define PPTP_HDR_PEER_CALL_ID_OFFSET 0x0e 
82
83 #define PPTP_HDR_RESULT_CODE_OFFSET_STCCRP 0x0e 
84 #define PPTP_HDR_RESULT_CODE_OFFSET        0x10 
85
86
87 /* Offset of control/mgmt msg types 
88             from start of TCP header */ 
89
90 #define TCP_HEADER_SIZE(tcp)   \
91                   ((tcp->hdr_len>>4) << 2)
92
93   
94 #define PPTP_MSG_START_OFFSET(tcp)    \
95                   ((u8*)tcp + TCP_HEADER_SIZE(tcp))
96
97
98 #define PPTP_CC_MSG_TYPE_OFFSET(tcp) \
99                   (PPTP_MSG_START_OFFSET(tcp) + \
100                   PPTP_CC_TYPE_OFFSET )
101
102 #define PPTP_MGMT_MSG_TYPE_OFFSET(tcp) \
103                   ( PPTP_MSG_START_OFFSET(tcp) + \
104                   PPTP_CTRL_MGMT_TYPE_OFFSET )
105
106 #define PPTP_CALL_ID_OFFSET(tcp) \
107                    ( PPTP_MSG_START_OFFSET(tcp) + \
108                    PPTP_HDR_CALL_ID_OFFSET )
109
110 #define PPTP_PEER_CALL_ID_OFFSET(tcp) \
111                    ( PPTP_MSG_START_OFFSET(tcp) + \
112                    PPTP_HDR_PEER_CALL_ID_OFFSET )
113
114 #define PPTP_RESULT_CODE_OFFSET(tcp) \
115                    ( PPTP_MSG_START_OFFSET(tcp) + \
116                    PPTP_HDR_RESULT_CODE_OFFSET )
117
118 #define PPTP_RESULT_CODE_OFFSET_STCCRP(tcp) \
119                    ( PPTP_MSG_START_OFFSET(tcp) + \
120                    PPTP_HDR_RESULT_CODE_OFFSET_STCCRP)
121
122 /* values */
123 #define PPTP_CC_MSG_TYPE(tcp) \
124               (u16*)PPTP_CC_MSG_TYPE_OFFSET(tcp)
125
126 #define PPTP_MGMT_MSG_TYPE(tcp) \
127               (u16*)PPTP_MGMT_MSG_TYPE_OFFSET(tcp)
128
129 #define PPTP_CALL_ID(tcp) \
130               (u16*)PPTP_CALL_ID_OFFSET(tcp)
131
132 #define PPTP_PEER_CALL_ID(tcp) \
133               (u16*)PPTP_PEER_CALL_ID_OFFSET(tcp)
134
135 #define PPTP_RESULT_CODE(tcp) \
136               *(u8*)PPTP_RESULT_CODE_OFFSET(tcp);
137               
138 #define PPTP_RESULT_CODE_STCCRP(tcp) \
139               *(u8*)PPTP_RESULT_CODE_OFFSET_STCCRP(tcp);
140
141
142 /* other code */
143 #define PPTP_CHAN_SUCCESS   1
144
145
146 /* Data structures */
147
148 extern u32 cnat_pptp_debug_flag;
149
150 #endif /* __CNAT_V4_PPTP_ALG_H__ */