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
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _nx_ip_raw_packet_source_send PORTABLE C */
36 /* 6.1 */
37 /* AUTHOR */
38 /* */
39 /* Yuxin Zhou, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function sends a raw IP packet through the specified IP */
44 /* source. */
45 /* */
46 /* INPUT */
47 /* */
48 /* ip_ptr Pointer to IP control block */
49 /* packet_ptr Pointer to packet to send */
50 /* destination_ip Destination IP address */
51 /* address_index Index to the IPv6 address */
52 /* type_of_service Type of service for packet */
53 /* */
54 /* OUTPUT */
55 /* */
56 /* status Completion status */
57 /* */
58 /* CALLS */
59 /* */
60 /* nx_ip_packet_send Core IP packet send service */
61 /* nx_ip_route_find Find a suitable outgoing */
62 /* interface. */
63 /* tx_mutex_get Get protection mutex */
64 /* tx_mutex_put Put protection mutex */
65 /* */
66 /* CALLED BY */
67 /* */
68 /* Application */
69 /* */
70 /* RELEASE HISTORY */
71 /* */
72 /* DATE NAME DESCRIPTION */
73 /* */
74 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
75 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
76 /* resulting in version 6.1 */
77 /* */
78 /**************************************************************************/
_nx_ip_raw_packet_source_send(NX_IP * ip_ptr,NX_PACKET * packet_ptr,ULONG destination_ip,UINT address_index,ULONG type_of_service)79 UINT _nx_ip_raw_packet_source_send(NX_IP *ip_ptr, NX_PACKET *packet_ptr,
80 ULONG destination_ip, UINT address_index, ULONG type_of_service)
81 {
82
83 #ifndef NX_DISABLE_IPV4
84 ULONG next_hop_address;
85
86 /* Add debug information. */
87 NX_PACKET_DEBUG(__FILE__, __LINE__, packet_ptr);
88
89 /* Store interface information into the packet structure. */
90 packet_ptr -> nx_packet_address.nx_packet_interface_ptr = &(ip_ptr -> nx_ip_interface[address_index]);
91
92 /* Get mutex protection. */
93 tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
94
95 /* Figure out a suitable outgoing interface. */
96 _nx_ip_route_find(ip_ptr, destination_ip, &packet_ptr -> nx_packet_address.nx_packet_interface_ptr, &next_hop_address);
97
98 /* If trace is enabled, insert this event into the trace buffer. */
99 NX_TRACE_IN_LINE_INSERT(NX_TRACE_IP_RAW_PACKET_SEND, ip_ptr, packet_ptr, destination_ip, type_of_service, NX_TRACE_IP_EVENTS, 0, 0);
100
101 /* Yes, raw packet sending and receiving is enabled send packet! */
102 /*lint -e{644} suppress variable might not be initialized, since "next_hop_address" was initialized in _nx_ip_route_find. */
103 _nx_ip_packet_send(ip_ptr, packet_ptr, destination_ip, type_of_service, NX_IP_TIME_TO_LIVE, NX_IP_RAW, NX_FRAGMENT_OKAY, next_hop_address);
104
105 /* Release mutex protection. */
106 tx_mutex_put(&(ip_ptr -> nx_ip_protection));
107
108 /* Return a successful status! */
109 return(NX_SUCCESS);
110 #else /* NX_DISABLE_IPV4 */
111 NX_PARAMETER_NOT_USED(ip_ptr);
112 NX_PARAMETER_NOT_USED(packet_ptr);
113 NX_PARAMETER_NOT_USED(destination_ip);
114 NX_PARAMETER_NOT_USED(address_index);
115 NX_PARAMETER_NOT_USED(type_of_service);
116
117 return(NX_NOT_SUPPORTED);
118 #endif /* !NX_DISABLE_IPV4 */
119 }
120
121