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 /** NetX Component */ 15 /** */ 16 /** Internet Control Message Protocol (ICMP) */ 17 /** */ 18 /**************************************************************************/ 19 /**************************************************************************/ 20 21 #define NX_SOURCE_CODE 22 23 24 /* Include necessary system files. */ 25 #include "nx_api.h" 26 #include "nx_ipv6.h" 27 #include "nx_icmpv6.h" 28 29 #ifdef FEATURE_NX_IPV6 30 31 /**************************************************************************/ 32 /* */ 33 /* FUNCTION RELEASE */ 34 /* */ 35 /* _nxd_ipv6_destination_table_find_next_hop PORTABLE C */ 36 /* 6.1 */ 37 /* AUTHOR */ 38 /* */ 39 /* Yuxin Zhou, Microsoft Corporation */ 40 /* */ 41 /* DESCRIPTION */ 42 /* */ 43 /* This is an internal function. It searches the destination table */ 44 /* (equivalent to IPv4 static routing table) for a possible match. */ 45 /* */ 46 /* INPUT */ 47 /* */ 48 /* ip_ptr Pointer to IP. */ 49 /* destination_ip IP address to search for. */ 50 /* next_hop Storage space for next hop */ 51 /* address. */ 52 /* */ 53 /* OUTPUT */ 54 /* */ 55 /* NX_SUCCESS Valid next hop returned */ 56 /* NX_NOT_SUCCESSFUL Invalid pointer input or no */ 57 /* match found; next hop not */ 58 /* returned */ 59 /* CALLS */ 60 /* */ 61 /* */ 62 /* CALLED BY */ 63 /* */ 64 /* _nx_icmpv6_process_redirect Process incoming redirect */ 65 /* message. */ 66 /* */ 67 /* RELEASE HISTORY */ 68 /* */ 69 /* DATE NAME DESCRIPTION */ 70 /* */ 71 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ 72 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 73 /* resulting in version 6.1 */ 74 /* */ 75 /**************************************************************************/ _nxd_ipv6_destination_table_find_next_hop(NX_IP * ip_ptr,ULONG * destination_ip,ULONG * next_hop)76UINT _nxd_ipv6_destination_table_find_next_hop(NX_IP *ip_ptr, ULONG *destination_ip, ULONG *next_hop) 77 { 78 79 UINT i, table_size; 80 UINT status; 81 82 83 status = NX_NOT_SUCCESSFUL; 84 85 /* Next hop storage must not be valid. */ 86 NX_ASSERT(next_hop != NX_NULL); 87 88 /* Set a local variable for convenience. */ 89 table_size = ip_ptr -> nx_ipv6_destination_table_size; 90 91 /* Check the num of destination. */ 92 if (table_size == 0) 93 { 94 return(NX_NOT_SUCCESSFUL); 95 } 96 97 /* Loop through all entries. */ 98 for (i = 0; table_size && (i < NX_IPV6_DESTINATION_TABLE_SIZE); i++) 99 { 100 101 /* Skip invalid entries. */ 102 if (!ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_valid) 103 { 104 continue; 105 } 106 107 /* Keep track of valid entries we have checked. */ 108 table_size--; 109 110 /* Check whether or not the address is the same. */ 111 if (CHECK_IPV6_ADDRESSES_SAME(ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_destination_address, destination_ip)) 112 { 113 114 /* Copy next hop address to user-supplied storage. */ 115 COPY_IPV6_ADDRESS(ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_next_hop, next_hop); 116 117 status = NX_SUCCESS; 118 119 /* break out of the for loop */ 120 break; 121 } 122 } 123 124 125 return(status); 126 } 127 128 129 #endif /* FEATURE_NX_IPV6 */ 130 131