1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** NetX Component */
16 /** */
17 /** Internet Protocol (IP) */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define NX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "nx_api.h"
28 #include "nx_ip.h"
29 #include "nx_packet.h"
30
31
32 /* Bring in externs for caller checking code. */
33
34 NX_CALLER_CHECKING_EXTERNS
35
36
37 /**************************************************************************/
38 /* */
39 /* FUNCTION RELEASE */
40 /* */
41 /* _nxe_ip_raw_packet_send PORTABLE C */
42 /* 6.1 */
43 /* AUTHOR */
44 /* */
45 /* Yuxin Zhou, Microsoft Corporation */
46 /* */
47 /* DESCRIPTION */
48 /* */
49 /* This function checks for errors in the IP raw packet send */
50 /* function call. */
51 /* */
52 /* INPUT */
53 /* */
54 /* ip_ptr Pointer to IP control block */
55 /* packet_ptr Pointer to packet to send */
56 /* destination_ip Destination IP address */
57 /* type_of_service Type of service for packet */
58 /* */
59 /* OUTPUT */
60 /* */
61 /* status Completion status */
62 /* */
63 /* CALLS */
64 /* */
65 /* _nx_ip_raw_packet_send Actual IP raw packet send */
66 /* function */
67 /* */
68 /* CALLED BY */
69 /* */
70 /* Application */
71 /* */
72 /* RELEASE HISTORY */
73 /* */
74 /* DATE NAME DESCRIPTION */
75 /* */
76 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
77 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
78 /* resulting in version 6.1 */
79 /* */
80 /**************************************************************************/
_nxe_ip_raw_packet_send(NX_IP * ip_ptr,NX_PACKET ** packet_ptr_ptr,ULONG destination_ip,ULONG type_of_service)81 UINT _nxe_ip_raw_packet_send(NX_IP *ip_ptr, NX_PACKET **packet_ptr_ptr,
82 ULONG destination_ip, ULONG type_of_service)
83 {
84
85 #ifndef NX_DISABLE_IPV4
86 UINT status;
87 NX_PACKET *packet_ptr;
88
89
90 /* Setup packet pointer. */
91 packet_ptr = *packet_ptr_ptr;
92
93 /* Check for invalid input pointers. */
94 /*lint -e{923} suppress cast of ULONG to pointer. */
95 if ((ip_ptr == NX_NULL) || (ip_ptr -> nx_ip_id != NX_IP_ID) ||
96 (packet_ptr == NX_NULL) || (packet_ptr -> nx_packet_union_next.nx_packet_tcp_queue_next != ((NX_PACKET *)NX_PACKET_ALLOCATED)))
97 {
98 return(NX_PTR_ERROR);
99 }
100
101 /* Check to see if IP raw packet processing is enabled. */
102 if (!ip_ptr -> nx_ip_raw_ip_processing)
103 {
104 return(NX_NOT_ENABLED);
105 }
106
107 /* Check for invalid IP address. */
108 if (!destination_ip)
109 {
110 return(NX_IP_ADDRESS_ERROR);
111 }
112
113 /* Check for valid type of service. */
114 if (type_of_service & ~(NX_IP_TOS_MASK))
115 {
116 return(NX_OPTION_ERROR);
117 }
118
119 /* Check for an invalid packet prepend pointer. */
120 /*lint -e{946} suppress pointer subtraction, since it is necessary. */
121 if ((packet_ptr -> nx_packet_prepend_ptr - sizeof(NX_IPV4_HEADER)) < packet_ptr -> nx_packet_data_start)
122 {
123 return(NX_UNDERFLOW);
124 }
125
126 /* Check for an invalid packet append pointer. */
127 /*lint -e{946} suppress pointer subtraction, since it is necessary. */
128 if (packet_ptr -> nx_packet_append_ptr > packet_ptr -> nx_packet_data_end)
129 {
130 return(NX_OVERFLOW);
131 }
132
133 /* Check for appropriate caller. */
134 NX_THREADS_ONLY_CALLER_CHECKING
135
136 /* Call actual IP raw packet send function. */
137 status = _nx_ip_raw_packet_send(ip_ptr, packet_ptr, destination_ip, type_of_service);
138
139 /* Determine if the raw packet send was successful. */
140 if (status == NX_SUCCESS)
141 {
142
143 /* Yes, now clear the application's packet pointer so it can't be accidentally
144 used again by the application. This is only done when error checking is
145 enabled. */
146 *packet_ptr_ptr = NX_NULL;
147 }
148
149 /* Return completion status. */
150 return(status);
151 #else /* NX_DISABLE_IPV4 */
152 NX_PARAMETER_NOT_USED(ip_ptr);
153 NX_PARAMETER_NOT_USED(packet_ptr_ptr);
154 NX_PARAMETER_NOT_USED(destination_ip);
155 NX_PARAMETER_NOT_USED(type_of_service);
156
157 return(NX_NOT_SUPPORTED);
158 #endif /* !NX_DISABLE_IPV4 */
159 }
160
161