1
10
13
14
20
21
22
23
24
25
26
27
28
29
30
31
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
145
146
147
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
171
172
173
176
177
178
179
180
181
182
183
188
193
194
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
217
218
219
220
221
222
223
224
225
226
227
228
229
234
235
236
237
238
239
240
241
245
246
247
248
249
250
251
252
253
254
255
257
258
259
260
261
265
266
270
271
272
273
279
280
286
287
288
289
290
291
292
293
294
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_ip.h"
#ifdef NX_IPSEC_ENABLE
#include "nx_ipsec.h"
#include "nx_icmp.h"
/* ... */#endif
#ifdef FEATURE_NX_IPV6
#include "nx_ipv6.h"
#endif
...
...
UINT _nx_ip_max_payload_size_find(NX_IP *ip_ptr,
NXD_ADDRESS *dest_address,
UINT if_index,
UINT src_port,
UINT dest_port,
ULONG protocol,
ULONG *start_offset_ptr,
ULONG *payload_length_ptr)
{
ULONG payload_length = 0;
ULONG start_offset = 0;
#if defined(NX_IPSEC_ENABLE) || defined(TX_ENABLE_EVENT_TRACE)
NXD_ADDRESS src_address = {0};
#endif
#ifdef NX_IPSEC_ENABLE
UINT block_size;
NX_IPSEC_SA *sa = NX_NULL;
UINT ret;
ULONG data_offset;/* ... */
#endif
#ifdef TX_ENABLE_EVENT_TRACE
ULONG src_address_lsw = 0, dst_address_lsw = 0;
#endif
#ifndef NX_DISABLE_IPV4
if (dest_address -> nxd_ip_version == NX_IP_VERSION_V4)
{
start_offset = NX_IPv4_PACKET;
if ((if_index >= NX_MAX_PHYSICAL_INTERFACES) || (!ip_ptr -> nx_ip_interface[if_index].nx_interface_ip_address))
{
return(NX_INVALID_INTERFACE);
}if ((if_index >= NX_MAX_PHYSICAL_INTERFACES) || (!ip_ptr -> nx_ip_interface[if_index].nx_interface_ip_address)) { ... }
#if defined(NX_IPSEC_ENABLE) || defined(TX_ENABLE_EVENT_TRACE)
src_address.nxd_ip_address.v4 = ip_ptr -> nx_ip_interface[if_index].nx_interface_ip_address;
src_address.nxd_ip_version = NX_IP_VERSION_V4;/* ... */
#endif
payload_length = ip_ptr -> nx_ip_interface[if_index].nx_interface_ip_mtu_size + NX_PHYSICAL_HEADER;
}if (dest_address -> nxd_ip_version == NX_IP_VERSION_V4) { ... }
/* ... */#endif
#ifdef FEATURE_NX_IPV6
if (dest_address -> nxd_ip_version == NX_IP_VERSION_V6)
{
start_offset = NX_IPv6_PACKET;
if (if_index >= (NX_MAX_IPV6_ADDRESSES + NX_LOOPBACK_IPV6_ENABLED))
{
return(NX_IP_ADDRESS_ERROR);
}if (if_index >= (NX_MAX_IPV6_ADDRESSES + NX_LOOPBACK_IPV6_ENABLED)) { ... }
#if defined(NX_IPSEC_ENABLE) || defined(TX_ENABLE_EVENT_TRACE)
COPY_IPV6_ADDRESS(ip_ptr -> nx_ipv6_address[if_index].nxd_ipv6_address, src_address.nxd_ip_address.v6);
src_address.nxd_ip_version = NX_IP_VERSION_V6;/* ... */
#endif
payload_length = ip_ptr -> nx_ipv6_address[if_index].nxd_ipv6_address_attached -> nx_interface_ip_mtu_size + NX_PHYSICAL_HEADER;
}if (dest_address -> nxd_ip_version == NX_IP_VERSION_V6) { ... }
/* ... */#endif
if (protocol == NX_PROTOCOL_TCP)
{
start_offset += 20;
}if (protocol == NX_PROTOCOL_TCP) { ... }
else if (protocol == NX_PROTOCOL_UDP)
{
start_offset += 8;
}else if (protocol == NX_PROTOCOL_UDP) { ... }
/* ... */
payload_length -= start_offset;
#ifdef NX_IPSEC_ENABLE
ret = NX_IPSEC_TRAFFIC_BYPASS;
if (ip_ptr -> nx_ip_packet_egress_sa_lookup)
{
#ifdef FEATURE_NX_IPV6
if (src_address.nxd_ip_version == NX_IP_VERSION_V4)
{
#endif
ret = ip_ptr -> nx_ip_packet_egress_sa_lookup(ip_ptr, &src_address, dest_address,
(UCHAR)protocol, src_port, dest_port,
&data_offset, (VOID **)&sa, (NX_ICMP_ECHO_REQUEST_TYPE << 8));
#ifdef FEATURE_NX_IPV6
}if (src_address.nxd_ip_version == NX_IP_VERSION_V4) { ... }
else
{
ret = ip_ptr -> nx_ip_packet_egress_sa_lookup(ip_ptr, &src_address, dest_address,
(UCHAR)protocol, src_port, dest_port,
&data_offset, (VOID **)&sa, (NX_ICMPV6_ECHO_REQUEST_TYPE << 8));
}else { ... }
#endif
}if (ip_ptr -> nx_ip_packet_egress_sa_lookup) { ... }
if (ret == NX_IPSEC_TRAFFIC_PROTECT)
{
start_offset += sa -> nx_ipsec_sa_head_encap_size;
payload_length -= sa -> nx_ipsec_sa_head_encap_size;
if (sa -> nx_ipsec_sa_protocol == NX_PROTOCOL_NEXT_HEADER_ENCAP_SECURITY)
{
if (sa -> nx_ipsec_sa_integrity_method != NX_NULL)
{
block_size = sa -> nx_ipsec_sa_integrity_method -> nx_crypto_block_size_in_bytes;
payload_length -= block_size;
}if (sa -> nx_ipsec_sa_integrity_method != NX_NULL) { ... }
if ((sa -> nx_ipsec_sa_encryption_method != NX_NULL) &&
(sa -> nx_ipsec_sa_encryption_method -> nx_crypto_algorithm != NX_CRYPTO_NONE))
{
block_size = 4;
if (sa -> nx_ipsec_sa_encryption_method -> nx_crypto_algorithm != NX_CRYPTO_ENCRYPTION_NULL)
{
block_size = sa -> nx_ipsec_sa_encryption_method -> nx_crypto_block_size_in_bytes;
}if (sa -> nx_ipsec_sa_encryption_method -> nx_crypto_algorithm != NX_CRYPTO_ENCRYPTION_NULL) { ... }
payload_length = payload_length / block_size;
payload_length = payload_length * block_size;
payload_length -= NX_IPSEC_ESP_TRAIL_LEN;
}if ((sa -> nx_ipsec_sa_encryption_method != NX_NULL) && (sa -> nx_ipsec_sa_encryption_method -> nx_crypto_algorithm != NX_CRYPTO_NONE)) { ... }
}if (sa -> nx_ipsec_sa_protocol == NX_PROTOCOL_NEXT_HEADER_ENCAP_SECURITY) { ... }
}if (ret == NX_IPSEC_TRAFFIC_PROTECT) { ... }
/* ... */#else
NX_PARAMETER_NOT_USED(src_port);
NX_PARAMETER_NOT_USED(dest_port);/* ... */
#endif
if (payload_length_ptr)
{
*payload_length_ptr = payload_length;
}if (payload_length_ptr) { ... }
if (start_offset_ptr)
{
*start_offset_ptr = start_offset;
}if (start_offset_ptr) { ... }
#ifdef TX_ENABLE_EVENT_TRACE
#ifndef NX_DISABLE_IPV4
if (dest_address -> nxd_ip_version == NX_IP_VERSION_V4)
{
src_address_lsw = src_address.nxd_ip_address.v4;
dst_address_lsw = dest_address -> nxd_ip_address.v4;
}if (dest_address -> nxd_ip_version == NX_IP_VERSION_V4) { ... }
/* ... */#endif
#ifdef FEATURE_NX_IPV6
if (dest_address -> nxd_ip_version == NX_IP_VERSION_V6)
{
src_address_lsw = src_address.nxd_ip_address.v6[3];
dst_address_lsw = dest_address -> nxd_ip_address.v6[3];
}if (dest_address -> nxd_ip_version == NX_IP_VERSION_V6) { ... }
/* ... */#endif
NX_TRACE_IN_LINE_INSERT(NXD_TRACE_IP_MAX_PAYLOAD_SIZE_FIND, src_address_lsw, dst_address_lsw, payload_length, start_offset, NX_TRACE_PACKET_EVENTS, 0, 0);
/* ... */
#endif
return(NX_SUCCESS);
}{ ... }