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 23 /**************************************************************************/ 24 /* */ 25 /* COMPONENT DEFINITION RELEASE */ 26 /* */ 27 /* nx_ipv4.h PORTABLE C */ 28 /* 6.1.9 */ 29 /* AUTHOR */ 30 /* */ 31 /* Yuxin Zhou, Microsoft Corporation */ 32 /* */ 33 /* DESCRIPTION */ 34 /* */ 35 /* This file defines the NetX Internet Protocol component, */ 36 /* including all data types and external references. It is assumed */ 37 /* that nx_api.h and nx_port.h have already been included. */ 38 /* */ 39 /* RELEASE HISTORY */ 40 /* */ 41 /* DATE NAME DESCRIPTION */ 42 /* */ 43 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ 44 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 45 /* resulting in version 6.1 */ 46 /* 08-02-2021 Yuxin Zhou Modified comment(s), and */ 47 /* supported TCP/IP offload, */ 48 /* resulting in version 6.1.8 */ 49 /* 10-15-2021 Yuxin Zhou Modified comment(s), included */ 50 /* necessary header file, */ 51 /* resulting in version 6.1.9 */ 52 /* */ 53 /**************************************************************************/ 54 55 #ifndef NX_IPV4_H 56 #define NX_IPV4_H 57 58 #include "nx_api.h" 59 60 61 #ifndef NX_DISABLE_IPV4 62 #define NX_IP_VERSION 0x45000000UL /* Version 4, Length of 5 */ 63 64 #define NX_IP_NORMAL_LENGTH 5 /* Normal IP header length */ 65 #define NX_IP_HEADER_LENGTH_ENCODE_6 6 /* IP header length 6. */ 66 67 /* Define IP options. */ 68 69 #define NX_IP_OPTION_COPY_FLAG 0x80000000UL /* All fragments must carry the option. */ 70 #define NX_IP_OPTION_CLASS 0x00000000UL /* Control. */ 71 #define NX_IP_OPTION_ROUTER_ALERT_NUMBER 0x14000000UL 72 #define NX_IP_OPTION_ROUTER_ALERT_LENGTH 0x00040000UL 73 #define NX_IP_OPTION_ROUTER_ALERT_VALUE 0x00000000UL 74 75 76 /* Define IP option type. */ 77 #define NX_IP_OPTION_END 0 78 #define NX_IP_OPTION_NO_OPERATION 1 79 #define NX_IP_OPTION_INTERNET_TIMESTAMP 68 80 81 82 /* Define IP fragmenting information. */ 83 84 #ifdef NX_DONT_FRAGMENT 85 #define NX_IP_DONT_FRAGMENT NX_DONT_FRAGMENT 86 #else 87 #define NX_IP_DONT_FRAGMENT 0x00004000UL /* Don't fragment bit */ 88 #endif /* NX_DONT_FRAGMENT */ 89 #ifdef NX_MORE_FRAGMENTS 90 #define NX_IP_MORE_FRAGMENT NX_MORE_FRAGMENTS 91 #else 92 #define NX_IP_MORE_FRAGMENT 0x00002000UL /* More fragments */ 93 #endif /* NX_DONT_FRAGMENT */ 94 #define NX_IP_FRAGMENT_MASK 0x00003FFFUL /* Mask for fragment bits */ 95 #ifdef NX_FRAG_OFFSET_MASK 96 #define NX_IP_OFFSET_MASK NX_FRAG_OFFSET_MASK 97 #else 98 #define NX_IP_OFFSET_MASK 0x00001FFFUL /* Mask for fragment offset */ 99 #endif /* NX_FRAG_OFFSET_MASK */ 100 #define NX_IP_ALIGN_FRAGS 8 /* Fragment alignment */ 101 102 /* Define basic IP Header constant. */ 103 104 /* Define Basic Internet packet header data type. This will be used to 105 build new IP packets and to examine incoming packets into NetX. */ 106 107 typedef struct NX_IPV4_HEADER_STRUCT 108 { 109 /* Define the first 32-bit word of the IP header. This word contains 110 the following information: 111 112 bits 31-28 IP Version = 0x4 (IP Version4) 113 bits 27-24 IP Header Length of 32-bit words (5 if no options) 114 bits 23-16 IP Type of Service, where 0x00 -> Normal 115 0x10 -> Minimize Delay 116 0x08 -> Maximize Throughput 117 0x04 -> Maximize Reliability 118 0x02 -> Minimize Monetary Cost 119 bits 15-0 IP Datagram length in bytes 120 */ 121 ULONG nx_ip_header_word_0; 122 123 /* Define the second word of the IP header. This word contains 124 the following information: 125 126 bits 31-16 IP Packet Identification (just an incrementing number) 127 bits 15-0 IP Flags and Fragment Offset (used for IP fragmenting) 128 bit 15 Zero 129 bit 14 Don't Fragment 130 bit 13 More Fragments 131 bits 12-0 (Fragment offset)/8 132 */ 133 ULONG nx_ip_header_word_1; 134 135 /* Define the third word of the IP header. This word contains 136 the following information: 137 138 bits 31-24 IP Time-To-Live (maximum number of routers 139 packet can traverse before being 140 thrown away. Default values are typically 141 32 or 64) 142 bits 23-16 IP Protocol, where 0x01 -> ICMP Messages 143 0x02 -> IGMP Messages 144 0x06 -> TCP Messages 145 0x11 -> UDP Messages 146 bits 15-0 IP Checksum 147 */ 148 ULONG nx_ip_header_word_2; 149 150 /* Define the source IP address. */ 151 ULONG nx_ip_header_source_ip; 152 153 /* Define the destination IP address. */ 154 ULONG nx_ip_header_destination_ip; 155 } NX_IPV4_HEADER; 156 157 /* Define IPv4 internal function prototypes. */ 158 VOID _nx_ip_forward_packet_process(NX_IP *ip_ptr, NX_PACKET *packet_ptr); 159 VOID _nx_ip_fragment_forward_packet(NX_IP *ip_ptr, NX_PACKET *packet_ptr, ULONG destination_ip, ULONG fragment, ULONG next_hop_address); 160 void _nx_ip_packet_send(NX_IP *ip_ptr, NX_PACKET *packet_ptr, ULONG destination_ip, ULONG type_of_service, ULONG time_to_live, ULONG protocol, ULONG fragment, ULONG next_hop_address); 161 UINT _nx_ip_header_add(NX_IP *ip_ptr, NX_PACKET *packet_ptr, ULONG source_ip, ULONG destination_ip, 162 ULONG type_of_service, ULONG time_to_live, ULONG protocol, ULONG fragment); 163 VOID _nx_ip_driver_packet_send(NX_IP *ip_ptr, NX_PACKET *packet_ptr, ULONG destination_ip, ULONG fragment, ULONG next_hop_address); 164 ULONG _nx_ip_route_find(NX_IP *ip_ptr, ULONG destination_address, NX_INTERFACE **nx_ip_interface, ULONG *next_hop_address); 165 VOID _nx_ipv4_packet_receive(NX_IP *ip_ptr, NX_PACKET *packet_ptr); 166 UINT _nx_ipv4_option_process(NX_IP *ip_ptr, NX_PACKET *packet_ptr); 167 #endif /* NX_DISABLE_IPV4 */ 168 169 /* Define IPv4 function prototypes. */ 170 171 UINT _nx_ip_address_change_notify(NX_IP *ip_ptr, VOID (*ip_address_change_notify)(NX_IP *, VOID *), VOID *additional_info); 172 UINT _nx_ip_address_get(NX_IP *ip_ptr, ULONG *ip_address, ULONG *network_mask); 173 UINT _nx_ip_address_set(NX_IP *ip_ptr, ULONG ip_address, ULONG network_mask); 174 UINT _nx_ip_gateway_address_set(NX_IP *ip_ptr, ULONG ip_address); 175 UINT _nx_ip_gateway_address_get(NX_IP *ip_ptr, ULONG *ip_address); 176 UINT _nx_ip_gateway_address_clear(NX_IP *ip_ptr); 177 UINT _nx_ip_interface_address_get(NX_IP *ip_ptr, UINT interface_index, ULONG *ip_address, ULONG *network_mask); 178 UINT _nx_ip_interface_address_set(NX_IP *ip_ptr, UINT interface_index, ULONG ip_address, ULONG network_mask); 179 UINT _nx_ip_raw_packet_send(NX_IP *ip_ptr, NX_PACKET *packet_ptr, 180 ULONG destination_ip, ULONG type_of_service); 181 UINT _nx_ip_raw_packet_source_send(NX_IP *ip_ptr, NX_PACKET *packet_ptr, ULONG destination_ip, UINT address_index, ULONG type_of_service); 182 UINT _nx_ip_static_route_add(NX_IP *ip_ptr, ULONG network_address, 183 ULONG net_mask, ULONG next_hop); 184 UINT _nx_ip_static_route_delete(NX_IP *ip_ptr, ULONG network_address, ULONG net_mask); 185 UINT _nx_ipv4_multicast_interface_join(NX_IP *ip_ptr, ULONG group_address, UINT interface_index); 186 UINT _nx_ipv4_multicast_interface_leave(NX_IP *ip_ptr, ULONG group_address, UINT interface_index); 187 188 189 /* Define error checking shells for API services. These are only referenced by the 190 application. */ 191 192 UINT _nxe_ip_address_change_notify(NX_IP *ip_ptr, VOID (*ip_address_change_notify)(NX_IP *, VOID *), VOID *additional_info); 193 UINT _nxe_ip_address_get(NX_IP *ip_ptr, ULONG *ip_address, ULONG *network_mask); 194 UINT _nxe_ip_address_set(NX_IP *ip_ptr, ULONG ip_address, ULONG network_mask); 195 UINT _nxe_ip_interface_address_get(NX_IP *ip_ptr, UINT interface_index, ULONG *ip_address, ULONG *network_mask); 196 UINT _nxe_ip_interface_address_set(NX_IP *ip_ptr, UINT interface_index, ULONG ip_address, ULONG network_mask); 197 UINT _nxe_ip_gateway_address_set(NX_IP *ip_ptr, ULONG ip_address); 198 UINT _nxe_ip_gateway_address_get(NX_IP *ip_ptr, ULONG *ip_address); 199 UINT _nxe_ip_gateway_address_clear(NX_IP *ip_ptr); 200 UINT _nxe_ip_raw_packet_send(NX_IP *ip_ptr, NX_PACKET **packet_ptr_ptr, 201 ULONG destination_ip, ULONG type_of_service); 202 UINT _nxe_ip_raw_packet_source_send(NX_IP *ip_ptr, NX_PACKET **packet_ptr_ptr, 203 ULONG destination_ip, UINT address_index, ULONG type_of_service); 204 UINT _nxe_ip_static_route_add(NX_IP *ip_ptr, ULONG network_address, 205 ULONG net_mask, ULONG next_hop); 206 UINT _nxe_ip_static_route_delete(NX_IP *ip_ptr, ULONG network_address, ULONG net_mask); 207 UINT _nxe_ipv4_multicast_interface_join(NX_IP *ip_ptr, ULONG group_address, UINT interface_index); 208 UINT _nxe_ipv4_multicast_interface_leave(NX_IP *ip_ptr, ULONG group_address, UINT interface_index); 209 210 #ifndef FEATURE_NX_IPV6 211 #ifdef NX_IPSEC_ENABLE 212 #define AUTHENTICATION_HEADER 5 213 #define ENCAP_SECURITY_HEADER 6 214 #endif /* NX_IPSEC_ENABLE */ 215 #endif /* FEATURE_NX_IPV6 */ 216 #endif /* NX_IPV4_H */ 217 218