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 #include "nx_api.h"
29 #include "nx_ip.h"
30 #include "nx_ipv6.h"
31
32 /* Bring in externs for caller checking code. */
33
34 NX_CALLER_CHECKING_EXTERNS
35
36 /**************************************************************************/
37 /* */
38 /* FUNCTION RELEASE */
39 /* */
40 /* _nxde_ip_raw_packet_source_send PORTABLE C */
41 /* 6.1 */
42 /* AUTHOR */
43 /* */
44 /* Yuxin Zhou, Microsoft Corporation */
45 /* */
46 /* DESCRIPTION */
47 /* */
48 /* This function does error checking for the raw IP packet send serivce*/
49 /* out the specified IP source. */
50 /* */
51 /* INPUT */
52 /* */
53 /* ip_ptr Pointer to IP control block */
54 /* packet_ptr Pointer to packet to send */
55 /* destination_ip Destination IP address */
56 /* address_index Index to the IPv6 address */
57 /* protocol Value for the protocol field */
58 /* ttl Value for ttl or hop limit */
59 /* tos Value for tos or traffic */
60 /* class and flow label */
61 /* */
62 /* OUTPUT */
63 /* */
64 /* NX_PTR_ERROR Invalid pointer input */
65 /* NX_NOT_ENABLED Raw packet send not enabled */
66 /* NX_IP_ADDRESS_ERROR Invalid input address */
67 /* NX_INVALID_INTERFACE Invalid interface input */
68 /* status Completion status */
69 /* */
70 /* CALLS */
71 /* */
72 /* nxd_ip_raw_packet_source_send Actual raw packet send service*/
73 /* */
74 /* CALLED BY */
75 /* */
76 /* Application */
77 /* */
78 /* RELEASE HISTORY */
79 /* */
80 /* DATE NAME DESCRIPTION */
81 /* */
82 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
83 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
84 /* resulting in version 6.1 */
85 /* */
86 /**************************************************************************/
_nxde_ip_raw_packet_source_send(NX_IP * ip_ptr,NX_PACKET * packet_ptr,NXD_ADDRESS * destination_ip,UINT address_index,ULONG protocol,UINT ttl,ULONG tos)87 UINT _nxde_ip_raw_packet_source_send(NX_IP *ip_ptr, NX_PACKET *packet_ptr,
88 NXD_ADDRESS *destination_ip, UINT address_index, ULONG protocol, UINT ttl, ULONG tos)
89 {
90
91 UINT status;
92
93 /* Check for invalid input pointers. */
94 if ((ip_ptr == NX_NULL) || (packet_ptr == NX_NULL) || (destination_ip == NX_NULL))
95 {
96 return(NX_PTR_ERROR);
97 }
98
99 /* Determine if raw IP packet sending/receiving is enabled. */
100 if (!ip_ptr -> nx_ip_raw_ip_processing)
101 {
102 return(NX_NOT_ENABLED);
103 }
104
105 /* Check that the destination address version is either IPv4 or IPv6. */
106 if ((destination_ip -> nxd_ip_version != NX_IP_VERSION_V4) &&
107 (destination_ip -> nxd_ip_version != NX_IP_VERSION_V6))
108 {
109 return(NX_IP_ADDRESS_ERROR);
110 }
111
112 #ifndef NX_DISABLE_IPV4
113 if (destination_ip -> nxd_ip_version == NX_IP_VERSION_V4)
114 {
115
116 if (destination_ip -> nxd_ip_address.v4 == 0)
117 {
118 return(NX_IP_ADDRESS_ERROR);
119 }
120
121 /* Check for valid interface. */
122 if (address_index >= NX_MAX_IP_INTERFACES)
123 {
124 return(NX_INVALID_INTERFACE);
125 }
126
127 /* Check for an invalid packet prepend pointer for IPv4 packet. */
128 /*lint -e{946} suppress pointer subtraction, since it is necessary. */
129 if ((packet_ptr -> nx_packet_prepend_ptr - sizeof(NX_IPV4_HEADER)) < packet_ptr -> nx_packet_data_start)
130 {
131 return(NX_UNDERFLOW);
132 }
133 }
134 #endif /* !NX_DISABLE_IPV4 */
135
136 #ifdef FEATURE_NX_IPV6
137 if (destination_ip -> nxd_ip_version == NX_IP_VERSION_V6)
138 {
139
140 /* destination_ip -> nxd_ip_version == NX_IP_VERSION_V6. */
141 /* Check for valid destination address. */
142 if (CHECK_UNSPECIFIED_ADDRESS(&destination_ip -> nxd_ip_address.v6[0]))
143 {
144 return(NX_IP_ADDRESS_ERROR);
145 }
146
147 /* Check for valid interface. */
148 if (address_index >= (NX_MAX_IPV6_ADDRESSES + NX_LOOPBACK_IPV6_ENABLED))
149 {
150 return(NX_IP_ADDRESS_ERROR);
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 }
160 #endif /* FEATURE_NX_IPV6 */
161
162 /* Check for an invalid packet append pointer. */
163 /*lint -e{946} suppress pointer subtraction, since it is necessary. */
164 if (packet_ptr -> nx_packet_append_ptr > packet_ptr -> nx_packet_data_end)
165 {
166 return(NX_OVERFLOW);
167 }
168
169 /* Check for appropriate caller. */
170 NX_THREADS_ONLY_CALLER_CHECKING
171
172 /* Call the actual service. */
173 status = _nxd_ip_raw_packet_source_send(ip_ptr, packet_ptr, destination_ip, address_index, protocol, ttl, tos);
174
175 /* Return completion status. */
176 return(status);
177 }
178
179