1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** NetX Component */
17 /** */
18 /** Internet Protocol (IP) */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define NX_SOURCE_CODE
24
25
26 /* Include necessary system files. */
27
28
29 #include "nx_api.h"
30 #include "nx_ip.h"
31 #include "nx_ipv6.h"
32 #include "nx_packet.h"
33
34 /* Bring in externs for caller checking code. */
35
36
37 NX_CALLER_CHECKING_EXTERNS
38
39 /**************************************************************************/
40 /* */
41 /* FUNCTION RELEASE */
42 /* */
43 /* _nxde_ip_raw_packet_send PORTABLE C */
44 /* 6.1 */
45 /* AUTHOR */
46 /* */
47 /* Yuxin Zhou, Microsoft Corporation */
48 /* */
49 /* DESCRIPTION */
50 /* */
51 /* This function sends a raw IP packet through the specified IPv6 */
52 /* interface. */
53 /* */
54 /* INPUT */
55 /* */
56 /* ip_ptr Pointer to IP control block */
57 /* packet_ptr Pointer to packet to send */
58 /* destination_ip Destination IP address */
59 /* protocol Value for the protocol field */
60 /* ttl Value for ttl or hop limit */
61 /* tos Value for tos or traffic */
62 /* class and flow label */
63 /* */
64 /* OUTPUT */
65 /* */
66 /* status Actual completion status */
67 /* NX_PTR_ERROR Invalid pointer input */
68 /* NX_NOT_ENABLED Raw IP not enabled */
69 /* NX_IP_ADDRESS_ERROR Invalid address version */
70 /* NX_INVALID_PARAMETERS Invalid protocol specified */
71 /* NX_UNDERFLOW Invalid packet header */
72 /* */
73 /* CALLS */
74 /* */
75 /* _nxd_ip_raw_packet_source_send Actual raw packet send */
76 /* function. */
77 /* */
78 /* CALLED BY */
79 /* */
80 /* Application */
81 /* */
82 /* RELEASE HISTORY */
83 /* */
84 /* DATE NAME DESCRIPTION */
85 /* */
86 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
87 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
88 /* resulting in version 6.1 */
89 /* */
90 /**************************************************************************/
_nxde_ip_raw_packet_send(NX_IP * ip_ptr,NX_PACKET ** packet_ptr_ptr,NXD_ADDRESS * destination_ip,ULONG protocol,UINT ttl,ULONG tos)91 UINT _nxde_ip_raw_packet_send(NX_IP *ip_ptr, NX_PACKET **packet_ptr_ptr,
92 NXD_ADDRESS *destination_ip, ULONG protocol, UINT ttl, ULONG tos)
93 {
94
95
96 NX_PACKET *packet_ptr;
97
98
99 /* Setup packet pointer. */
100 packet_ptr = *packet_ptr_ptr;
101
102 /* Check for invalid input pointers. */
103 /* Cast the ULONG into a packet pointer. Since this is exactly what we wish to do, disable the lint warning with the following comment: */
104 /*lint -e{923} suppress cast of ULONG to pointer. */
105 if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID) || (packet_ptr == NX_NULL) ||
106 (packet_ptr -> nx_packet_union_next.nx_packet_tcp_queue_next != ((NX_PACKET *)NX_PACKET_ALLOCATED)))
107 {
108
109 return(NX_PTR_ERROR);
110 }
111
112 /* Check to see if IP raw packet processing is enabled. */
113 if (!ip_ptr -> nx_ip_raw_ip_processing)
114 {
115 return(NX_NOT_ENABLED);
116 }
117
118 /* Check for invalid IP address. */
119 if (!destination_ip || ((destination_ip -> nxd_ip_version != NX_IP_VERSION_V6) &&
120 (destination_ip -> nxd_ip_version != NX_IP_VERSION_V4)))
121 {
122
123 return(NX_IP_ADDRESS_ERROR);
124 }
125
126 /* Check for valid protocol. */
127 if ((protocol & 0x000000FF) != protocol)
128 {
129 return(NX_INVALID_PARAMETERS);
130 }
131
132 #ifndef NX_DISABLE_IPV4
133 if (destination_ip -> nxd_ip_version == NX_IP_VERSION_V4)
134 {
135
136 /* Check for an invalid packet prepend pointer for IPv4 packet. */
137 /*lint -e{946} suppress pointer subtraction, since it is necessary. */
138 if ((packet_ptr -> nx_packet_prepend_ptr - sizeof(NX_IPV4_HEADER)) < packet_ptr -> nx_packet_data_start)
139 {
140 return(NX_UNDERFLOW);
141 }
142 if (destination_ip -> nxd_ip_address.v4 == 0)
143 {
144 return(NX_IP_ADDRESS_ERROR);
145 }
146 }
147 #endif /* !NX_DISABLE_IPV4 */
148
149 #ifdef FEATURE_NX_IPV6
150 if (destination_ip -> nxd_ip_version == NX_IP_VERSION_V6)
151 {
152
153 /* Check for an invalid packet prepend pointer for IPv6 packet. */
154 /*lint -e{946} suppress pointer subtraction, since it is necessary. */
155 if ((packet_ptr -> nx_packet_prepend_ptr - sizeof(NX_IPV6_HEADER)) < packet_ptr -> nx_packet_data_start)
156 {
157 return(NX_UNDERFLOW);
158 }
159 if (CHECK_UNSPECIFIED_ADDRESS(&destination_ip -> nxd_ip_address.v6[0]))
160 {
161 return(NX_IP_ADDRESS_ERROR);
162 }
163 }
164 #endif /* FEATURE_NX_IPV6 */
165
166
167 /* Check for an invalid packet append pointer. */
168 /*lint -e{946} suppress pointer subtraction, since it is necessary. */
169 if (packet_ptr -> nx_packet_append_ptr > packet_ptr -> nx_packet_data_end)
170 {
171 return(NX_OVERFLOW);
172 }
173
174 /* Check for appropriate caller. */
175 NX_THREADS_ONLY_CALLER_CHECKING
176
177 _nxd_ip_raw_packet_source_send(ip_ptr, packet_ptr, destination_ip, 0, protocol, ttl, tos);
178
179 /* Now clear the application's packet pointer so it can't be accidentally
180 used again by the application. This is only done when error checking is
181 enabled. */
182 *packet_ptr_ptr = NX_NULL;
183
184 /* Return completion status. */
185 return(NX_SUCCESS);
186 }
187
188