1 /*******************************************************************************
2 ################################################################################
3 # Copyright (c) [2017-2019] [Radisys] #
5 # Licensed under the Apache License, Version 2.0 (the "License"); #
6 # you may not use this file except in compliance with the License. #
7 # You may obtain a copy of the License at #
9 # http://www.apache.org/licenses/LICENSE-2.0 #
11 # Unless required by applicable law or agreed to in writing, software #
12 # distributed under the License is distributed on an "AS IS" BASIS, #
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
14 # See the License for the specific language governing permissions and #
15 # limitations under the License. #
16 ################################################################################
17 *******************************************************************************/
19 /********************************************************************20**
21 Name: common transport file
25 Desc: common file for transport related data structures
29 *********************************************************************21*/
38 /* network address table size */
39 #define CM_MAX_NET_ADDR 16
41 /* network address sizes */
43 #define CM_IPV4ADDR_SIZE CM_INET_IPV4ADDR_SIZE
44 #define CM_IPV6ADDR_SIZE CM_INET_IPV6ADDR_SIZE
46 /* network address sizes */
47 #define CM_IPV4PORT_SIZE CM_INET_IPV4PORT_SIZE
48 #define CM_IPV6PORT_SIZE CM_INET_IPV4PORT_SIZE
50 /* "type" in network address */
51 #define CM_NETADDR_NOTPRSNT 0
52 #define CM_NETADDR_IPV4 CM_INET_IPV4ADDR_TYPE
53 #define CM_NETADDR_IPV6 CM_INET_IPV6ADDR_TYPE
55 /* "type" in transport address */
56 #define CM_TPTADDR_NOTPRSNT 0
57 #define CM_TPTADDR_IPV4 CM_INET_IPV4ADDR_TYPE
58 #define CM_TPTADDR_IPV6 CM_INET_IPV6ADDR_TYPE
59 #define CM_TPTADDR_AAL 3
61 #define CM_MAX_SOCK_OPTS 8
63 /* "type" in transport parameters */
64 #define CM_TPTPARAM_NOTPRSNT 0
65 #define CM_TPTPARAM_SOCK 1
66 #define CM_TPTPARAM_AAL 2
67 #define CM_TPTPARAM_TLS 3
68 /*cm_tpt_h_001.main_14 Updated for TUCL 2.1 Release (Kernel SCTP Support) */
70 #define CM_TPTPARAM_SCTP 4
73 #define CM_INPORT_ANY 0
75 #ifdef __CMINETH__ /* Put cm_inet dependencies here */
77 /* "level" in Socket Options */
78 #define CM_SOCKOPT_LEVEL_SOCKET CM_INET_LEVEL_SOCKET
79 #define CM_SOCKOPT_LEVEL_IP CM_INET_LEVEL_IP
80 #define CM_SOCKOPT_LEVEL_TCP CM_INET_LEVEL_TCP
81 /*cm_tpt_h_001.main_14 Updated for TUCL 2.1 Release (Kernel SCTP Support) */
83 #define CM_SOCKOPT_LEVEL_SCTP CM_INET_LEVEL_SCTP
85 /* cm_tpt_h_001.main_16: Added new macro to support filter for ICMP messages */
86 #ifdef CM_ICMP_FILTER_SUPPORT
88 #define CM_SOCKOPT_LEVEL_RAW CM_INET_LEVEL_RAW
92 /* "option" in Socket Options */
93 #define CM_SOCKOPT_OPT_BLOCK CM_INET_OPT_BLOCK
94 #define CM_SOCKOPT_OPT_REUSEADDR CM_INET_OPT_REUSEADDR
95 #define CM_SOCKOPT_OPT_RX_BUF_SIZE CM_INET_OPT_RX_BUF_SIZE
96 #define CM_SOCKOPT_OPT_TX_BUF_SIZE CM_INET_OPT_TX_BUF_SIZE
97 #define CM_SOCKOPT_OPT_ADD_MCAST_MBR CM_INET_OPT_ADD_MCAST_MBR
98 #define CM_SOCKOPT_OPT_DRP_MCAST_MBR CM_INET_OPT_DRP_MCAST_MBR
99 #define CM_SOCKOPT_OPT_TCP_NODELAY CM_INET_OPT_TCP_NODELAY
100 #define CM_SOCKOPT_OPT_MCAST_LOOP CM_INET_OPT_MCAST_LOOP
101 #define CM_SOCKOPT_OPT_MCAST_IF CM_INET_OPT_MCAST_IF
102 #define CM_SOCKOPT_OPT_MCAST_TTL CM_INET_OPT_MCAST_TTL
103 #define CM_SOCKOPT_OPT_BROADCAST CM_INET_OPT_BROADCAST
104 /* added KEEPALIVE socket option for TCP socket */
105 #define CM_SOCKOPT_OPT_KEEPALIVE CM_INET_OPT_KEEPALIVE
107 #define CM_SOCKOPT_OPT_HDRINCLD CM_INET_OPT_HDR_INCLD
108 #define CM_SOCKOPT_OPT_DONTFRAGMENT CM_INET_OPT_DONTFRAGMENT
109 #define CM_SOCKOPT_OPT_TOS CM_INET_OPT_TOS
110 #define CM_SOCKOPT_OPT_TTL CM_INET_OPT_TTL
112 #ifdef IPV6_SUPPORTED
113 /* "level" in Socket Options */
114 #define CM_SOCKOPT_LEVEL_IPV6 CM_INET_LEVEL_IPV6
116 /* "option" in Socket Options */
117 #define CM_SOCKOPT_OPT_ADD_MCAST6_MBR CM_INET_OPT_ADD_MCAST6_MBR
118 #define CM_SOCKOPT_OPT_DRP_MCAST6_MBR CM_INET_OPT_DRP_MCAST6_MBR
119 #define CM_SOCKOPT_OPT_MCAST6_LOOP CM_INET_OPT_MCAST6_LOOP
120 #define CM_SOCKOPT_OPT_MCAST6_IF CM_INET_OPT_MCAST6_IF
121 #define CM_SOCKOPT_OPT_MCAST6_HOPS CM_INET_OPT_MCAST6_HOPS
122 #define CM_SOCKOPT_OPT_IPV6_TTL CM_INET_OPT_IPV6_TTL
124 /* added new IPv6 socket options for IPv6 extn hdrs */
125 #ifdef IPV6_OPTS_SUPPORTED
126 #define CM_SOCKOPT_OPT_RECVIPV6_HOPLIM CM_INET_OPT_RECVIPV6_HOPLIM
127 #define CM_SOCKOPT_OPT_RECVIPV6_HBHOPT CM_INET_OPT_RECVIPV6_HBHOPTS
128 #define CM_SOCKOPT_OPT_RECVIPV6_DSTOPTS CM_INET_OPT_RECVIPV6_DSTOPTS
129 #define CM_SOCKOPT_OPT_RECVIPV6_RTHDR CM_INET_OPT_RECVIPV6_RTHDR
130 #define CM_SOCKOPT_OPT_IP_ROUTER_ALERT6 CM_INET_OPT_IP_ROUTER_ALERT6
131 #endif /* IPV6_OPTS_SUPPORTED */
132 #define CM_SOCKOPT_OPT_IPV6_PKTINFO CM_INET_OPT_IPV6_PKTINFO
133 #endif /* IPV6_SUPPORTED */
135 /* added new IPv4 socket options for IPv4 IP options */
136 #ifdef IPV4_OPTS_SUPPORTED
137 #define CM_SOCKOPT_OPT_IP_OPTIONS CM_INET_OPT_IP_OPTIONS
138 #define CM_SOCKOPT_OPT_IPV4_PKTINFO CM_INET_OPT_IPV4_PKTINFO
139 #define CM_SOCKOPT_OPT_IP_ROUTER_ALERT CM_INET_OPT_IP_ROUTER_ALERT
140 #endif /* IPV4_OPTS_SUPPORTED */
142 /* sctp socket options */
143 /*cm_tpt_h_001.main_14 Updated for TUCL 2.1 Release (Kernel SCTP Support) */
145 #define CM_SOCKOPT_OPT_LINGER CM_INET_OPT_LINGER
146 #define CM_SOCKOPT_OPT_SCTP_EVENTS CM_INET_OPT_SCTP_EVENTS
147 #define CM_SOCKOPT_OPT_SCTP_PRIM_ADDR CM_INET_OPT_SCTP_PRIM_ADDR
148 #define CM_SOCKOPT_OPT_SCTP_PEERADDR_PARAMS CM_INET_OPT_SCTP_PEERADDR_PARAMS
149 #define CM_SOCKOPT_OPT_SCTP_GET_ASSOC_STA CM_INET_OPT_SCTP_GET_ASSOC_STA
150 #define CM_SOCKOPT_OPT_SCTP_GET_PADDR_INFO CM_INET_OPT_SCTP_GET_PADDR_INFO
151 /*cm_tpt_h_001.main_15 Updated for the support of configurable RTO parameters,
152 HBeat value Max retransmissions (Init, Path, Association)*/
153 #define CM_SOCKOPT_OPT_SCTP_ASSOC_PARAMS CM_INET_OPT_SCTP_ASSOC_PARAMS
154 #define CM_SOCKOPT_OPT_SCTP_RTO_INFO CM_INET_OPT_SCTP_RTO_INFO
155 #define CM_SOCKOPT_OPT_SCTP_INIT_MSG CM_INET_OPT_SCTP_INIT_MSG
158 /* IP header masks */
159 #define CM_DF_MASK 0x4000 /* Don't Fragment bit */
160 #define CM_MF_MASK 0x2000 /* More Fragment bit */
162 /* Protocol Values */
163 #define CM_PROTOCOL_IP CM_INET_PROTO_IP /* IP protocol */
164 #define CM_PROTOCOL_ICMP CM_INET_PROTO_ICMP /* ICMP protocol */
165 #define CM_PROTOCOL_TCP CM_INET_PROTO_TCP /* TCP protocol */
166 #define CM_PROTOCOL_UDP CM_INET_PROTO_UDP /* UDP protocol */
167 #define CM_PROTOCOL_RAW CM_INET_PROTO_RAW /* Raw protocol */
168 #define CM_PROTOCOL_SCTP CM_INET_PROTO_SCTP /* SCTP protocol */
169 /*cm_tpt_h_001.main_14 Updated for TUCL 2.1 Release (Kernel SCTP Support) */
171 #define CM_PROTOCOL_LKSCTP CM_INET_PROTO_SCTP /* SCTP protocol */
173 /* added new protocol */
174 #define CM_PROTOCOL_RSVP CM_INET_PROTO_RSVP /* RSVP protocol */
176 #ifdef IPV6_SUPPORTED
177 #define CM_PROTOCOL_IPV6 CM_INET_PROTO_IPV6 /* IPV6 protocol */
178 #define CM_PROTOCOL_ICMPV6 CM_INET_PROTO_ICMPV6 /* ICMP V6 protocol */
179 #endif /* IPV6_SUPPORTED */
182 #define CM_PROTOCOL_TLS CM_PROTOCOL_TCP /* TLS runs over TCP */
185 /* Type of service parameters */
186 #define CM_IPTOS_MIN_DELAY 0x10
187 #define CM_IPTOS_MAX_TPUT 0x08
188 #define CM_IPTOS_MAX_REL 0x04
190 /* Maximum Error Types */
191 #define CM_MAX_ICMP_ERROR 5
192 /* cm_tpt_h_001.main_16: Added new macro to support filter for ICMP messages */
193 #ifdef CM_ICMP_FILTER_SUPPORT
194 #ifndef CM_MAX_ICMP_SOCKET
195 #define CM_MAX_ICMP_SOCKET 5
197 #ifdef IPV6_SUPPORTED
198 #define CM_MAX_ICMPV6_MSGTYPE 140
202 /* ICMP Error Types */
203 #define CM_ICMP_ET_DEST_UNREACHBLE 3
204 #define CM_ICMP_ET_SRC_QUENCH 4
205 #define CM_ICMP_ET_REDRCT 5
206 #define CM_ICMP_ET_TIM_EXCEED 11
207 #define CM_ICMP_ET_PARAM_PROB 12
209 /* ICMPV6 Error Types */
210 #ifdef IPV6_SUPPORTED
211 #define CM_ICMP_ET_V6DEST_UNREACHABLE 1
212 #define CM_ICMP_ET_V6PACKET_TOO_BIG 2
213 #define CM_ICMP_ET_V6PACKET_TIME_EXCEEDED 3
214 #define CM_ICMP_ET_V6PACKET_PARAM_PROB 4
215 #endif /* IPV6_SUPPORTED */
217 /* ICMP Error Codes - destination unreachable */
218 #define CM_ICMP_EC_NWK_UNREACH 0
219 #define CM_ICMP_EC_HST_UNREACH 1
220 #define CM_ICMP_EC_PROTO_UNREACH 2
221 #define CM_ICMP_EC_PORT_UNREACH 3
222 #define CM_ICMP_EC_FRAG_REQ_DFSET 4
223 #define CM_ICMP_EC_SRC_RUT_FAIL 5
225 /* ICMP Error Codes - Source Quench */
226 #define CM_ICMP_EC_SRC_QUENCH 4
228 /* ICMP Error Codes - Redirect */
229 #define CM_ICMP_EC_RDRCT_NWK 0
230 #define CM_ICMP_EC_RDRCT_HST 1
231 #define CM_ICMP_EC_RDRCT_TOSNWK 2
232 #define CM_ICMP_EC_RDRCT_TOSHST 3
234 /* ICMP Error codes - Time exceeded */
235 #define CM_ICMP_EC_TTL_TRNST 0
236 #define CM_ICMP_EC_TTL_REASM 1
238 /* ICMP V6 Error codes */
239 #ifdef IPV6_SUPPORTED
240 /* Error codes - Destination unreachable */
241 #define CM_ICMPV6_EC_NO_RTTO_DEST 0
242 #define CM_ICMPV6_EC_ADMN_PROHIBIT 1
243 #define CM_ICMPV6_EC_NOT_NEIGHBOR 2
244 #define CM_ICMPV6_EC_ADDR_UNREACH 3
245 #define CM_ICMPV6_EC_PORT_UNREACH 4
247 /* Error codes - Time exceeded */
248 #define CM_ICMPV6_EC_HOPLIM_EXCD 0
249 #define CM_ICMPV6_EC_FRG_REASM_TM_EXCD 1
251 /* Error codes - Paramter problem */
252 #define CM_ICMPV6_EC_ERRHDR_FIELD 0
253 #define CM_ICMPV6_EC_UNKNOWN_NXT_HDR 1
254 #define CM_ICMPV6_EC_UNKNOWN_OPTION 2
256 #endif /* IPV6_SUPPORTED */
258 /* types of Filter parameter */
259 #define CM_ICMP_NO_FILTER 0
260 #define CM_ICMPVER4_FILTER CM_INET_IPV4ADDR_TYPE
261 #define CM_ICMPVER6_FILTER CM_INET_IPV6ADDR_TYPE
263 /* For all Error code in a particular Error type */
264 #define CM_ALL_CODES_MASK 0xFFFFFFFF
266 /* types of header parameter */
267 #define CM_HDRPARM_NOTPRSNT 0
268 #define CM_HDRPARM_IPV4 CM_INET_IPV4ADDR_TYPE
269 #define CM_HDRPARM_IPV6 CM_INET_IPV6ADDR_TYPE
270 /* added new define for ipHdrParm.type */
271 #define CM_HDRPARM_ICMP6 1
273 #define CM_IPV4_HDRLEN 20 /* Length of IP Header */
274 #define CM_IPV6_HDRLEN 40 /* Length of IP Header */
275 /* added new new define for IPv4 IP option */
276 #define CM_IPV4_OPTS_MAXLEN 44 /* Max length of IPv4 Options */
277 #endif /* CM_INET2 */
279 #define CM_INADDR_ANY CM_INET_INADDR_ANY
281 #define CM_SOCKOPT_ENABLE CM_INET_OPT_ENABLE
282 #define CM_SOCKOPT_DISABLE CM_INET_OPT_DISABLE
283 #endif /* __CMINETH__ */
285 /* packing/unpacking functions */
286 #define cmPkCmIpv4NetAddr(x, mBuf) SPkU32(x, mBuf)
287 /* Moved all packing functions to cm_tpt from
288 * cm_inet.c files. Hence no #defines are required */
289 #define cmUnpkCmIpv4NetAddr(x, mBuf) SUnpkU32(x, mBuf)
291 /* added macro to free memory allocated for IPv6
293 #ifdef IPV6_OPTS_SUPPORTED
294 #define CM_TPT_FREE_IPV6_HDRPARM(_region, _pool, _hdrParm) \
296 CmIpv6HdrParm *_hdrParmIpv6; \
298 if (_hdrParm->type == CM_HDRPARM_IPV6) \
300 _hdrParmIpv6 = &_hdrParm->u.hdrParmIpv6; \
301 if( _hdrParmIpv6->ipv6ExtHdr.hbhHdrPrsnt) \
303 for(numOpts = _hdrParmIpv6->ipv6ExtHdr.hbhOptsArr.numHBHOpts; \
304 numOpts > 0; numOpts--) \
306 SPutSBuf(_region, _pool, (Data *)_hdrParmIpv6->ipv6ExtHdr. \
307 hbhOptsArr.hbhOpts[numOpts - 1].value, (Size)(_hdrParmIpv6-> \
308 ipv6ExtHdr.hbhOptsArr.hbhOpts[numOpts - 1].length)); \
309 SPutSBuf(_region, _pool, (Data *)&_hdrParmIpv6->ipv6ExtHdr. \
310 hbhOptsArr.hbhOpts[numOpts - 1], \
311 (Size)sizeof(CmInetIpv6HBHHdr)); \
314 if(_hdrParmIpv6->ipv6ExtHdr.destOptsPrsnt) \
316 for(numOpts = _hdrParmIpv6->ipv6ExtHdr.destOptsArr.numDestOpts; \
317 numOpts > 0; numOpts--) \
319 SPutSBuf(_region, _pool, (Data *)_hdrParmIpv6->ipv6ExtHdr. \
320 destOptsArr.destOpts[numOpts - 1].value, (Size)(_hdrParmIpv6-> \
321 ipv6ExtHdr.destOptsArr.destOpts[numOpts - 1].length)); \
322 SPutSBuf(_region, _pool, (Data *)&_hdrParmIpv6->ipv6ExtHdr. \
323 destOptsArr.destOpts[numOpts - 1], \
324 (Size)sizeof(CmInetIpv6DestOptsHdr)); \
327 if( _hdrParmIpv6->ipv6ExtHdr.rtOptsPrsnt) \
329 SPutSBuf(_region, _pool, \
330 (Data *)_hdrParmIpv6->ipv6ExtHdr.rtOpts.ipv6Addrs, \
331 (Size)(_hdrParmIpv6->ipv6ExtHdr.rtOpts.numAddrs * 16)); \
335 #endif /* IPV6_OPTS_SUPPORTED */
336 #endif /* __CMTPTH__ */
339 /********************************************************************30**
341 *********************************************************************31*/