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 version 6 (IPv6) */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 24 /**************************************************************************/ 25 /* */ 26 /* COMPONENT DEFINITION RELEASE */ 27 /* */ 28 /* nx_ipv6.h PORTABLE C */ 29 /* 6.1.9 */ 30 /* AUTHOR */ 31 /* */ 32 /* Yuxin Zhou, Microsoft Corporation */ 33 /* */ 34 /* DESCRIPTION */ 35 /* */ 36 /* This file defines the NetX Internet Protocol component, */ 37 /* including all data types and external references. It is assumed */ 38 /* that nx_api.h and nx_port.h have already been included. */ 39 /* */ 40 /* This header file is for NetX Duo internal use only. Application */ 41 /* shall not include this file directly. */ 42 /* */ 43 /* RELEASE HISTORY */ 44 /* */ 45 /* DATE NAME DESCRIPTION */ 46 /* */ 47 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ 48 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 49 /* resulting in version 6.1 */ 50 /* 10-15-2021 Yuxin Zhou Modified comment(s), included */ 51 /* necessary header file, */ 52 /* resulting in version 6.1.9 */ 53 /* */ 54 /**************************************************************************/ 55 56 #ifndef NX_IPV6_H 57 #define NX_IPV6_H 58 59 #include "nx_api.h" 60 #ifdef FEATURE_NX_IPV6 61 62 /* Define basic IP Header constant. */ 63 64 /* Define Basic Internet packet header data type. This will be used to 65 build new IP packets and to examine incoming packets into NetX. */ 66 67 typedef struct NX_IPV6_HEADER_STRUCT 68 { 69 /* 70 Define the first 32-bit word of the IP header. This word contains 71 the following information: 72 73 bits 31-28 IP Version = 0x6 (IP Version6) 74 bits 27-20 Traffic Class 75 bits 19-00 Flow Lable 76 */ 77 ULONG nx_ip_header_word_0; 78 79 /* 80 Define the second word of the IP header. This word contains 81 the following information: 82 83 bits 31-16 Payload Length 84 bits 15-8 Next Header; 85 bits 7-0 Hop limit 86 */ 87 ULONG nx_ip_header_word_1; 88 89 /* Sender IP address. */ 90 ULONG nx_ip_header_source_ip[4]; 91 92 /* Define the destination IP address. */ 93 ULONG nx_ip_header_destination_ip[4]; 94 } NX_IPV6_HEADER; 95 96 97 /* Define the data structure of the IPv6 optional field used in 98 hop-by-hop option and destination option headers. */ 99 typedef struct NX_IPV6_HEADER_OPTION_STRUCT 100 { 101 102 /* A hint to the protocol that follows. */ 103 UCHAR nx_ipv6_header_option_next_header; 104 105 /* Size of this option field.*/ 106 UCHAR nx_ipv6_header_option_ext_length; 107 108 /* ICMPv6 Option header type. */ 109 /*lint -esym(768,NX_IPV6_HEADER_OPTION_STRUCT::nx_ipv6_header_option_type) suppress member not referenced. It is not used as a host. */ 110 UCHAR nx_ipv6_header_option_type; 111 112 /* ICMPv6 Option-specific area. */ 113 /*lint -esym(768,NX_IPV6_HEADER_OPTION_STRUCT::nx_ipv6_header_option_data) suppress member not referenced. It is not used as a host. */ 114 UCHAR nx_ipv6_header_option_data; 115 } NX_IPV6_HEADER_OPTION; 116 117 118 /* Hop by hop header optoin. */ 119 typedef struct NX_IPV6_HOP_BY_HOP_OPTION_STRUCT 120 { 121 /* Option type. */ 122 UCHAR nx_ipv6_hop_by_hop_option_type; 123 124 /* Size of this option field.*/ 125 UCHAR nx_ipv6_hop_by_hop_length; 126 127 /* Start point of the option data. */ 128 /*lint -esym(768,NX_IPV6_HOP_BY_HOP_OPTION_STRUCT::nx_ipv6_hop_by_hop_data) suppress member not referenced. It is not used as a host. */ 129 USHORT nx_ipv6_hop_by_hop_data; 130 } NX_IPV6_HOP_BY_HOP_OPTION; 131 132 133 /* Routing header option. */ 134 typedef struct NX_IPV6_HEADER_ROUTING_OPTION_STRUCT 135 { 136 137 /* A hint to the protocol that follows. */ 138 /*lint -esym(768,NX_IPV6_HEADER_ROUTING_OPTION_STRUCT::nx_ipv6_header_routing_option_next_header) suppress member not referenced. It is not used as a host. */ 139 UCHAR nx_ipv6_header_routing_option_next_header; 140 141 /* Header length. */ 142 /*lint -esym(768,NX_IPV6_HEADER_ROUTING_OPTION_STRUCT::nx_ipv6_header_routing_option_hdr_ext_len) suppress member not referenced. It is not used as a host. */ 143 UCHAR nx_ipv6_header_routing_option_hdr_ext_len; 144 145 /* Router type. */ 146 /*lint -esym(768,NX_IPV6_HEADER_ROUTING_OPTION_STRUCT::nx_ipv6_header_routing_option_routing_type) suppress member not referenced. It is not used as a host. */ 147 UCHAR nx_ipv6_header_routing_option_routing_type; 148 149 /* Segments left. */ 150 UCHAR nx_ipv6_header_routing_option_segments_left; 151 152 /* Data. */ 153 /*lint -esym(768,NX_IPV6_HEADER_ROUTING_OPTION_STRUCT::nx_ipv6_header_routing_option_data) suppress member not referenced. It is not used as a host. */ 154 ULONG *nx_ipv6_header_routing_option_data; 155 } NX_IPV6_HEADER_ROUTING_OPTION; 156 157 /* Fragment header option. */ 158 typedef struct NX_IPV6_HEADER_FRAGMENT_OPTION_STRUCT 159 { 160 /* A hint to the protocol that follows. */ 161 UCHAR nx_ipv6_header_fragment_option_next_header; 162 163 /* Unused field. */ 164 UCHAR nx_ipv6_header_fragment_option_reserved; 165 166 /* Fragment offset. Last 3 bits are used as flags. */ 167 USHORT nx_ipv6_header_fragment_option_offset_flag; 168 169 /* ID field. */ 170 ULONG nx_ipv6_header_fragment_option_packet_id; 171 } NX_IPV6_HEADER_FRAGMENT_OPTION; 172 173 /* Unicast address type. Note that site local address types have been 174 deprectated in RFC 4291 and are treated as global address types. */ 175 #define IPV6_ADDRESS_LINKLOCAL 0x00000001 176 /* 177 #define IPV6_ADDRESS_SITELOCAL 0x00000002 178 */ 179 #define IPV6_ADDRESS_GLOBAL 0x00000004 180 181 /* Multicast address type */ 182 #define IPV6_ALL_NODE_MCAST 0x00000010 183 #define IPV6_ALL_ROUTER_MCAST 0x00000020 184 #define IPV6_SOLICITED_NODE_MCAST 0x00000040 185 186 #define IPV6_ADDRESS_UNICAST 0x80000000 187 #define IPV6_ADDRESS_MULTICAST 0x40000000 188 #define IPV6_ADDRESS_UNSPECIFIED 0x20000000 189 #define IPV6_ADDRESS_LOOPBACK 0x10000000 190 191 192 193 /* 194 The following symbols define the order of the IPv6 optional 195 headers. Each value represents a state during the parse of the 196 optional headers. An error occurs when the parser encounters 197 an optional header when it is not expecting the header, i.e. 198 the header is out of order. . 199 200 201 IPv6 defines the order of the optional headers: (RFC2460 section 4.1) 202 * IPv6 Header 203 * Hop-by-Hop Options header 204 * Destination Options header 205 * Routnig header 206 * Fragment header 207 * Authentication header 208 * Encapsulating Security Payload header 209 * Destination Options header 210 * Upper-layer header 211 */ 212 enum NX_IPV6_OPTION_STATE 213 { 214 IPV6_BASE_HEADER, /* 0 */ 215 HOP_BY_HOP_HEADER, /* 1 */ 216 DESTINATION_HEADER_1, /* 2 */ 217 ROUTING_HEADER, /* 3 */ 218 FRAGMENT_HEADER, /* 4 */ 219 #ifdef NX_IPSEC_ENABLE 220 AUTHENTICATION_HEADER, /* 5 */ 221 ENCAP_SECURITY_HEADER, /* 6 */ 222 #endif /* NX_IPSEC_ENABLE */ 223 DESTINATION_HEADER_2 /* 7 */ 224 }; 225 226 227 228 /* Define IPv6 internal functions. */ 229 230 UINT _nxd_ipv6_default_router_add_internal(NX_IP *ip_ptr, ULONG *router_addr, ULONG router_lifetime, NX_INTERFACE *if_ptr, INT router_type, NX_IPV6_DEFAULT_ROUTER_ENTRY **_new_entry); 231 VOID _nxd_ipv6_default_router_table_init(NX_IP *ip_ptr); 232 UINT _nxd_ipv6_find_max_prefix_length(ULONG *addr1, ULONG *addr, UINT max_length); 233 VOID _nx_ipv6_fragment_process(struct NX_IP_DRIVER_STRUCT *driver_req_ptr, UINT mtu); 234 UINT _nx_ipv6_header_add(NX_IP *ip_ptr, NX_PACKET **packet_pptr, 235 ULONG protocol, ULONG payload_size, ULONG hop_limit, 236 ULONG *src_address, ULONG *dest_address, ULONG *fragment); 237 UINT _nx_ipv6_packet_copy(NX_PACKET *source_pkt_head, NX_PACKET *dest_pkt_head, UINT size); 238 UINT _nx_ipv6_multicast_join(NX_IP *, ULONG *, NX_INTERFACE *); 239 UINT _nx_ipv6_multicast_leave(NX_IP *, ULONG *, NX_INTERFACE *); 240 UINT _nx_ipv6_option_error(NX_IP *ip_ptr, NX_PACKET *packet_ptr, UCHAR option_type, UINT offset); 241 VOID _nx_ipv6_packet_receive(NX_IP *ip_ptr, NX_PACKET *packet_ptr); 242 VOID _nx_ipv6_packet_send(NX_IP *ip_ptr, NX_PACKET *packet_ptr, ULONG protocol, ULONG payload_size, ULONG hop_limit, ULONG *src_address, ULONG *dest_address); 243 UINT _nx_ipv6_prefix_list_add_entry(NX_IP *ip_ptr, ULONG *prefix, ULONG prefix_length, ULONG valid_lifetime); 244 VOID _nx_ipv6_prefix_list_delete(NX_IP *ip_ptr, ULONG *prefix, INT prefix_length); 245 VOID _nx_ipv6_prefix_list_delete_entry(NX_IP *ip_ptr, NX_IPV6_PREFIX_ENTRY *entry); 246 UINT _nx_ipv6_process_hop_by_hop_option(NX_IP *ip_ptr, NX_PACKET *packet_ptr); 247 UINT _nx_ipv6_process_routing_option(NX_IP *ip_ptr, NX_PACKET *packet_ptr); 248 UINT _nx_ipv6_process_fragment_option(NX_IP *ip_ptr, NX_PACKET *packet_ptr); 249 250 UINT _nxd_ipv6_interface_find(NX_IP *ip_ptr, ULONG *dest_address, 251 NXD_IPV6_ADDRESS **ipv6_addr, NX_INTERFACE *if_ptr); 252 UINT _nxd_ipv6_router_lookup(NX_IP *ip_ptr, NX_INTERFACE *if_ptr, ULONG *router_address, void **nd_cache_entry); 253 VOID _nxd_ipv6_router_solicitation_check(NX_IP *ip_ptr); 254 UINT _nxd_ipv6_raw_packet_send_internal(NX_IP *ip_ptr, NX_PACKET *packet_ptr, NXD_ADDRESS *destination_ip, ULONG protocol); 255 VOID _nxd_ipv6_prefix_router_timer_tick(NX_IP *ip_ptr); 256 NX_IPV6_DEFAULT_ROUTER_ENTRY* _nxd_ipv6_find_default_router_from_address(NX_IP *ip_ptr, ULONG *ip_addr); 257 INT _nxd_ipv6_search_onlink(NX_IP *ip_ptr, ULONG *dest_addr); 258 259 #endif /* FEATURE_NX_IPV6 */ 260 261 262 263 /* 264 If NX_IPV6_UTIL_INLINE is defined, the functions are compiled as inline functions. 265 Inline functions improve execution speed. However it also increases code size. 266 Applications concerning more about code size should have the symbol undefeind 267 when building NetX Duo library and the application. 268 */ 269 #ifndef NX_IPV6_UTIL_INLINE 270 271 #ifdef NX_IPSEC_ENABLE 272 INT CHECK_IPV6_ADDRESS_RANGE(ULONG *ip_addr_start, ULONG *ip_addr_end, ULONG *ip_addr); 273 #endif /* NX_IPSEC_ENABLE */ 274 INT CHECK_IPV6_ADDRESSES_SAME(ULONG *ip_dest, ULONG *myip); 275 INT CHECK_UNSPECIFIED_ADDRESS(ULONG *ip_addr); 276 void SET_UNSPECIFIED_ADDRESS(ULONG *ip_addr); 277 void COPY_IPV6_ADDRESS(ULONG *copy_from, ULONG *copy_to); 278 void COPY_NXD_ADDRESS(NXD_ADDRESS *copy_from, NXD_ADDRESS *copy_to); 279 void SET_SOLICITED_NODE_MULTICAST_ADDRESS(ULONG *address, ULONG *unicast_address); 280 INT CHECK_ALL_ROUTER_MCAST_ADDRESS(ULONG *address); 281 VOID _nx_ipv6_address_change_endian(ULONG *address); 282 283 #endif /* NX_IPV6_UTIL_INLINE */ 284 INT CHECK_IP_ADDRESSES_BY_PREFIX(ULONG *ip_addr1, ULONG *ip_addr2, ULONG prefix_len); 285 INT CHECK_IPV6_SOLICITED_NODE_MCAST_ADDRESS(ULONG *dest_ip, ULONG *myip); 286 ULONG IPv6_Address_Type(ULONG *ip_address); 287 288 /* Define IPv6 API function prototype. */ 289 UINT _nxd_ipv6_enable(NX_IP *ip_ptr); 290 UINT _nxd_ipv6_disable(NX_IP *ip_ptr); 291 UINT _nxd_ipv6_address_get(NX_IP *ip_ptr, UINT address_index, NXD_ADDRESS *ip_address, ULONG *prefix_length, UINT *interface_index); 292 UINT _nxd_ipv6_address_set(NX_IP *ip_ptr, UINT interface_index, NXD_ADDRESS *ip_address, ULONG prefix_length, UINT *address_index); 293 UINT _nxd_ipv6_address_delete(NX_IP *ip_ptr, UINT address_index); 294 UINT _nxd_ipv6_address_change_notify(NX_IP *ip_ptr, VOID (*ipv6_address_change_notfiy)(NX_IP *ip_ptr, UINT status, UINT interface_index, UINT address_index, ULONG *ip_address)); 295 UINT _nxd_ipv6_default_router_add(NX_IP *ip_ptr, NXD_ADDRESS *router_addr, ULONG router_lifetime, UINT interface_index); 296 UINT _nxd_ipv6_default_router_delete(NX_IP *ip_ptr, NXD_ADDRESS *router_address); 297 UINT _nxd_ipv6_default_router_get(NX_IP *ip_ptr, UINT interface_index, NXD_ADDRESS *router_addr, ULONG *router_lifetime, ULONG *prefix_length); 298 UINT _nxd_ipv6_default_router_entry_get(NX_IP *ip_ptr, UINT interface_index, UINT entry_index, NXD_ADDRESS *router_addr, ULONG *router_lifetime, ULONG *prefix_length, ULONG *configuration_method); 299 UINT _nxd_ipv6_default_router_number_of_entries_get(NX_IP *ip_ptr, UINT interface_index, UINT *num_entries); 300 UINT _nxd_ipv6_multicast_interface_join(NX_IP *ip_ptr, NXD_ADDRESS *group_address, UINT interface_index); 301 UINT _nxd_ipv6_multicast_interface_leave(NX_IP *ip_ptr, NXD_ADDRESS *group_address, UINT interface_index); 302 UINT _nxd_ipv6_stateless_address_autoconfig_disable(NX_IP *ip_ptr, UINT interface_index); 303 UINT _nxd_ipv6_stateless_address_autoconfig_enable(NX_IP *ip_ptr, UINT interface_index); 304 305 /* Define error checking shells for API services. These are only referenced by the application. */ 306 UINT _nxde_ipv6_enable(NX_IP *ip_ptr); 307 UINT _nxde_ipv6_disable(NX_IP *ip_ptr); 308 UINT _nxde_ipv6_stateless_address_autoconfig_disable(NX_IP *ip_ptr, UINT interface_index); 309 UINT _nxde_ipv6_stateless_address_autoconfig_enable(NX_IP *ip_ptr, UINT interface_index); 310 UINT _nxde_ipv6_address_get(NX_IP *ip_ptr, UINT address_index, NXD_ADDRESS *ip_address, ULONG *prefix_length, UINT *interface_index); 311 UINT _nxde_ipv6_address_set(NX_IP *ip_ptr, UINT interface_index, NXD_ADDRESS *ip_address, ULONG prefix_length, UINT *address_index); 312 UINT _nxde_ipv6_address_delete(NX_IP *ip_ptr, UINT address_index); 313 UINT _nxde_ipv6_address_change_notify(NX_IP *ip_ptr, VOID (*ipv6_address_change_notfiy)(NX_IP *ip_ptr, UINT status, UINT interface_index, UINT address_index, ULONG *ip_address)); 314 UINT _nxde_ipv6_default_router_add(NX_IP *ip_ptr, NXD_ADDRESS *router_addr, ULONG router_lifetime, UINT interface_index); 315 UINT _nxde_ipv6_default_router_delete(NX_IP *ip_ptr, NXD_ADDRESS *router_address); 316 UINT _nxde_ipv6_default_router_get(NX_IP *ip_ptr, UINT interface_index, NXD_ADDRESS *router_addr, ULONG *router_lifetime, ULONG *prefix_length); 317 UINT _nxde_ipv6_default_router_entry_get(NX_IP *ip_ptr, UINT interface_index, UINT entry_index, NXD_ADDRESS *router_addr, ULONG *router_lifetime, ULONG *prefix_length, ULONG *configuration_method); 318 UINT _nxde_ipv6_default_router_number_of_entries_get(NX_IP *ip_ptr, UINT interface_index, UINT *num_entries); 319 UINT _nxde_ip_raw_packet_send(NX_IP *ip_ptr, NX_PACKET **packet_ptr_ptr, 320 NXD_ADDRESS *destination_ip, ULONG protocol, UINT ttl, ULONG tos); 321 UINT _nxde_ipv6_multicast_interface_join(NX_IP *ip_ptr, NXD_ADDRESS *group_address, UINT interface_index); 322 UINT _nxde_ipv6_multicast_interface_leave(NX_IP *ip_ptr, NXD_ADDRESS *group_address, UINT interface_index); 323 324 #endif /* NX_IPV6_H */ 325 326