Select one of the symbols to view example projects that use it.
 
Outline
...
...
...
#define NX_SOURCE_CODE
#include "nx_api.h"
#include "nx_ip.h"
#include "nx_packet.h"
#include "nx_ipv6.h"
#include "nx_icmpv6.h"
...
Files
loading...
SourceVuSTM32 Libraries and Samplesnetxduocommon/src/nx_ipv6_packet_receive.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/**************************************************************************/ /* */ /* Copyright (c) Microsoft Corporation. All rights reserved. */ /* */ /* This software is licensed under the Microsoft Software License */ /* Terms for Microsoft Azure RTOS. Full text of the license can be */ /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ /* and in the root directory of this software. */ /* */... /**************************************************************************/ ... /**************************************************************************/ /**************************************************************************/ /** */ /** NetX Component */ /** */ /** Internet Protocol (IP) */ /** */... /**************************************************************************/ /**************************************************************************/ #define NX_SOURCE_CODE /* Include necessary system files. */ #include "nx_api.h" #include "nx_ip.h" #include "nx_packet.h" #include "nx_ipv6.h" #include "nx_icmpv6.h" 5 includes #ifdef FEATURE_NX_IPV6 /**************************************************************************/ /* */ /* FUNCTION RELEASE */ /* */ /* _nx_ipv6_packet_receive PORTABLE C */ /* 6.1 */ /* AUTHOR */ /* */ /* Yuxin Zhou, Microsoft Corporation */ /* */ /* DESCRIPTION */ /* */ /* This function receives IPv6 packets from the nx_ip_packet_receive. */ /* The packet is either processed here or placed it in a deferred */ /* processing queue, depending on the complexity of the packet. */ /* */ /* INPUT */ /* */ /* ip_ptr Pointer to IP control block */ /* packet_ptr Pointer to packet received */ /* */ /* OUTPUT */ /* */ /* None */ /* */ /* CALLS */ /* */ /* _nx_packet_release Packet release function */ /* _nx_ip_dispatch_process The routine that examines */ /* other optional headers and */ /* upper layer protocols. */ /* */ /* CALLED BY */ /* */ /* Application I/O Driver */ /* */ /* RELEASE HISTORY */ /* */ /* DATE NAME DESCRIPTION */ /* */ /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ /* 09-30-2020 Yuxin Zhou Modified comment(s), */ /* resulting in version 6.1 */ /* */... /**************************************************************************/ VOID _nx_ipv6_packet_receive(NX_IP *ip_ptr, NX_PACKET *packet_ptr) { UINT error; ULONG delta; UINT pkt_length; UCHAR next_header_type; NX_IPV6_HEADER *ip_header_ptr; NXD_IPV6_ADDRESS *interface_ipv6_address_next; NXD_IPV6_ADDRESS *incoming_address = NX_NULL; #ifndef NX_DISABLE_PACKET_CHAIN NX_PACKET *before_last_packet; NX_PACKET *last_packet;/* ... */ #endif /* NX_DISABLE_PACKET_CHAIN */ #ifdef NX_ENABLE_IPV6_MULTICAST INT i = 0; #endif /* NX_ENABLE_IPV6_MULTICAST */ /* Add debug information. */ NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr); /* Points to the base of IPv6 header. */ /*lint -e{927} -e{826} suppress cast of pointer to pointer, since it is necessary */ ip_header_ptr = (NX_IPV6_HEADER *)packet_ptr -> nx_packet_prepend_ptr; /* Byte swap WORD 1 to obtain IPv6 payload length. */ NX_CHANGE_ULONG_ENDIAN(ip_header_ptr -> nx_ip_header_word_1); pkt_length = (UINT)((ip_header_ptr -> nx_ip_header_word_1 >> 16) + sizeof(NX_IPV6_HEADER)); /* Make sure the packet length field matches the payload length field in the IPv6 header. */ if (packet_ptr -> nx_packet_length != (ULONG)pkt_length) { /* Determine if the packet length is less than the size reported in the IP header. */ if (packet_ptr -> nx_packet_length < (ULONG)pkt_length) { /* The incoming packet has a wrong payload size. */ #ifndef NX_DISABLE_IP_INFO /* Increment the IP invalid packet error. */ ip_ptr -> nx_ip_invalid_packets++; /* Increment the IP receive packets dropped count. */ ip_ptr -> nx_ip_receive_packets_dropped++;/* ... */ #endif /* Release the packet! */ _nx_packet_release(packet_ptr); /* In all cases, receive processing is finished. Return to caller. */ return; }if (packet_ptr -> nx_packet_length < (ULONG)pkt_length) { ... } /* Calculate the difference in the length. */ delta = packet_ptr -> nx_packet_length - pkt_length; /* Adjust the packet length. */ packet_ptr -> nx_packet_length = packet_ptr -> nx_packet_length - delta; /* Adjust the append pointer. */ #ifndef NX_DISABLE_PACKET_CHAIN /* Loop to process adjustment that spans multiple packets. */ while (delta) { /* Determine if the packet is chained (or still chained after the adjustment). */ if (packet_ptr -> nx_packet_last == NX_NULL) { /* No, packet is not chained, simply adjust the append pointer in the packet. */ packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_append_ptr - delta; /* Break out of the loop, since the adjustment is complete. */ break; }if (packet_ptr -> nx_packet_last == NX_NULL) { ... } /* Pickup the pointer to the last packet. */ last_packet = packet_ptr -> nx_packet_last; /* Determine if the amount to adjust is less than the payload in the last packet. */ /*lint -e{946} -e{947} suppress pointer subtraction, since it is necessary. */ if (((ULONG)(last_packet -> nx_packet_append_ptr - last_packet -> nx_packet_prepend_ptr)) > delta) { /* Yes, simply adjust the append pointer of the last packet in the chain. */ /*lint -e{946} -e{947} suppress pointer subtraction, since it is necessary. */ last_packet -> nx_packet_append_ptr = last_packet -> nx_packet_append_ptr - delta; /* Get out of the loop, since the adjustment is complete. */ break; }if (((ULONG)(last_packet -> nx_packet_append_ptr - last_packet -> nx_packet_prepend_ptr)) > delta) { ... } else { /* Adjust the delta by the amount in the last packet. */ delta = delta - ((ULONG)(last_packet -> nx_packet_append_ptr - last_packet -> nx_packet_prepend_ptr)); /* Find the packet before the last packet. */ before_last_packet = packet_ptr; while (before_last_packet -> nx_packet_next != last_packet) { /* Move to the next packet in the chain. */ before_last_packet = before_last_packet -> nx_packet_next; }while (before_last_packet -> nx_packet_next != last_packet) { ... } /* At this point, we need to release the last packet and adjust the other packet pointers. *//* ... */ /* Ensure the next packet pointer is NULL in what is now the last packet. */ before_last_packet -> nx_packet_next = NX_NULL; /* Determine if the packet is still chained. */ if (packet_ptr != before_last_packet) { /* Yes, the packet is still chained, setup the last packet pointer. */ packet_ptr -> nx_packet_last = before_last_packet; }if (packet_ptr != before_last_packet) { ... } else { /* The packet is no longer chained, set the last packet pointer to NULL. */ packet_ptr -> nx_packet_last = NX_NULL; }else { ... } /* Release the last packet. */ _nx_packet_release(last_packet); }else { ... } }while (delta) { ... } /* ... */#else /* Simply adjust the append pointer in the packet. */ packet_ptr -> nx_packet_append_ptr = packet_ptr -> nx_packet_append_ptr - delta;/* ... */ #endif /* NX_DISABLE_PACKET_CHAIN */ }if (packet_ptr -> nx_packet_length != (ULONG)pkt_length) { ... } /* Byte swap the rest of the IPv6 header fields. */ NX_CHANGE_ULONG_ENDIAN(ip_header_ptr -> nx_ip_header_word_0); NX_IPV6_ADDRESS_CHANGE_ENDIAN(ip_header_ptr -> nx_ip_header_destination_ip); NX_IPV6_ADDRESS_CHANGE_ENDIAN(ip_header_ptr -> nx_ip_header_source_ip); /* Get a pointer to the first address in the address list for this interface (e.g. the interface the packet was received on). *//* ... */ interface_ipv6_address_next = packet_ptr -> nx_packet_address.nx_packet_interface_ptr -> nxd_interface_ipv6_address_list_head; /* Check if this packet is intended for this host by looping through all the addresses in the IP interface table for a match. */ while (interface_ipv6_address_next) { /* Ignore invalid addresses. */ if (interface_ipv6_address_next -> nxd_ipv6_address_state != NX_IPV6_ADDR_STATE_UNKNOWN) { /* Does the incoming packet match one of the IP interfaces? */ if (CHECK_IPV6_ADDRESSES_SAME(ip_header_ptr -> nx_ip_header_destination_ip, interface_ipv6_address_next -> nxd_ipv6_address)) { /* Yes, we found a match! */ incoming_address = interface_ipv6_address_next; break; }if (CHECK_IPV6_ADDRESSES_SAME(ip_header_ptr -> nx_ip_header_destination_ip, interface_ipv6_address_next -> nxd_ipv6_address)) { ... } /* Check for multicast address. */ else if (CHECK_IPV6_SOLICITED_NODE_MCAST_ADDRESS(ip_header_ptr -> nx_ip_header_destination_ip, interface_ipv6_address_next -> nxd_ipv6_address)) { /* Yes, this is a multicast address. */ incoming_address = interface_ipv6_address_next; break; }else if (CHECK_IPV6_SOLICITED_NODE_MCAST_ADDRESS(ip_header_ptr -> nx_ip_header_destination_ip, interface_ipv6_address_next -> nxd_ipv6_address)) { ... } }if (interface_ipv6_address_next -> nxd_ipv6_address_state != NX_IPV6_ADDR_STATE_UNKNOWN) { ... } /* No match yet, get the next address. */ interface_ipv6_address_next = interface_ipv6_address_next -> nxd_ipv6_address_next; }while (interface_ipv6_address_next) { ... } #ifdef NX_ENABLE_IPV6_MULTICAST if ((incoming_address == NX_NULL) && ((ip_header_ptr -> nx_ip_header_destination_ip[0] & 0xFF000000) == 0xFF000000)) { /* Search the address whether match our multicast join list. */ for (i = 0; i < NX_MAX_MULTICAST_GROUPS; i++) { /* Match the destination address with the multicast list */ if ((ip_ptr -> nx_ipv6_multicast_entry[i].nx_ip_mld_join_interface_list == packet_ptr -> nx_packet_address.nx_packet_interface_ptr) && (CHECK_IPV6_ADDRESSES_SAME(ip_header_ptr -> nx_ip_header_destination_ip, (ip_ptr -> nx_ipv6_multicast_entry[i].nx_ip_mld_join_list)))) { incoming_address = ip_ptr -> nx_ipv6_multicast_entry[i].nx_ip_mld_join_interface_list -> nxd_interface_ipv6_address_list_head; break; }if ((ip_ptr -> nx_ipv6_multicast_entry[i].nx_ip_mld_join_interface_list == packet_ptr -> nx_packet_address.nx_packet_interface_ptr) && (CHECK_IPV6_ADDRESSES_SAME(ip_header_ptr -> nx_ip_header_destination_ip, (ip_ptr -> nx_ipv6_multicast_entry[i].nx_ip_mld_join_list)))) { ... } }for (i = 0; i < NX_MAX_MULTICAST_GROUPS; i++) { ... } }if ((incoming_address == NX_NULL) && ((ip_header_ptr -> nx_ip_header_destination_ip[0] & 0xFF000000) == 0xFF000000)) { ... } /* ... */#endif /* NX_ENABLE_IPV6_MULTICAST */ /* Check for valid interface. */ if (incoming_address == NX_NULL) { /* The incoming packet has a destination address that does not match any of the local interface addresses so its not for me. *//* ... */ #ifndef NX_DISABLE_IP_INFO /* Increment the IP receive packets dropped count. */ ip_ptr -> nx_ip_receive_packets_dropped++;/* ... */ #endif /* Release the packet. */ _nx_packet_release(packet_ptr); /* In all cases, receive processing is finished. Return to caller. */ return; }if (incoming_address == NX_NULL) { ... } /* Set the matching address to the packet address. */ packet_ptr -> nx_packet_address.nx_packet_ipv6_address_ptr = incoming_address; /* Update the IP header pointer, packet length and packet prepend pointer to point to the next header (either IP option header or upper layer protocol header. *//* ... */ packet_ptr -> nx_packet_prepend_ptr += sizeof(NX_IPV6_HEADER); packet_ptr -> nx_packet_length -= (ULONG)sizeof(NX_IPV6_HEADER); packet_ptr -> nx_packet_option_offset = 6; next_header_type = (UCHAR)((ip_header_ptr -> nx_ip_header_word_1 >> 8) & 0xFF); /* Search all the extension headers, terminate after upper layer protocols (such as UDP, TCP, ICMP). Also check the order of the optional headers. Once an out-of-order option field is detected, the search is terminated and an ICMPv6 error message is generated. *//* ... */ /* Initialize start of search for just passed the IP header. */ packet_ptr -> nx_packet_option_state = (UCHAR)IPV6_BASE_HEADER; packet_ptr -> nx_packet_destination_header = 0; #ifndef NX_DISABLE_IP_INFO /* Increment the number of packets delivered. */ ip_ptr -> nx_ip_total_packets_delivered++; /* Increment the IP packet bytes received (not including the header). */ ip_ptr -> nx_ip_total_bytes_received += packet_ptr -> nx_packet_length;/* ... */ #endif error = _nx_ip_dispatch_process(ip_ptr, packet_ptr, next_header_type); if (error) { _nx_packet_release(packet_ptr); }if (error) { ... } return; }_nx_ipv6_packet_receive (NX_IP *ip_ptr, NX_PACKET *packet_ptr) { ... } /* ... */ #endif /* FEATURE_NX_IPV6 */
Details
Show:
from
Types: Columns:
This file uses the notable symbols shown below. Click anywhere in the file to view more details.