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 /** Neighbor Discovery Cache */ 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_ipv6.h" 29 #include "nx_nd_cache.h" 30 31 #ifdef FEATURE_NX_IPV6 32 33 34 /**************************************************************************/ 35 /* */ 36 /* FUNCTION RELEASE */ 37 /* */ 38 /* nx_nd_cache_find_entry PORTABLE C */ 39 /* 6.1 */ 40 /* AUTHOR */ 41 /* */ 42 /* Yuxin Zhou, Microsoft Corporation */ 43 /* */ 44 /* DESCRIPTION */ 45 /* */ 46 /* This internal function finds an entry in the ND cache that is */ 47 /* mapped to the specified IPv6 address. */ 48 /* */ 49 /* INPUT */ 50 /* */ 51 /* ip_ptr IP instance pointer */ 52 /* dest_ip The IP address to match */ 53 /* nd_cache_entry User specified storage space of pointer to */ 54 /* the corresponding ND cache. */ 55 /* */ 56 /* OUTPUT */ 57 /* */ 58 /* status NX_SUCCESS: The ND cache entry is located. */ 59 /* nd_cache_entry contains valid value. */ 60 /* NX_NOT_SUCCESSFUL: The ND cache entry */ 61 /* cannot be found, or nd_cache_entry is */ 62 /* NULL. */ 63 /* */ 64 /* CALLS */ 65 /* */ 66 /* None */ 67 /* */ 68 /* CALLED BY */ 69 /* */ 70 /* Application Code */ 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 /**************************************************************************/ _nx_nd_cache_find_entry(NX_IP * ip_ptr,ULONG * dest_ip,ND_CACHE_ENTRY ** nd_cache_entry)81UINT _nx_nd_cache_find_entry(NX_IP *ip_ptr, 82 ULONG *dest_ip, ND_CACHE_ENTRY **nd_cache_entry) 83 { 84 UINT i; 85 UINT index; 86 87 /* Initialize the return value. */ 88 *nd_cache_entry = NX_NULL; 89 90 /* Compute a simple hash based on the dest_ip */ 91 index = (UINT)((dest_ip[0] + dest_ip[1] + dest_ip[2] + dest_ip[3]) % 92 (NX_IPV6_NEIGHBOR_CACHE_SIZE)); 93 94 for (i = 0; i < NX_IPV6_NEIGHBOR_CACHE_SIZE; i++) 95 { 96 97 if ((ip_ptr -> nx_ipv6_nd_cache[index].nx_nd_cache_nd_status != ND_CACHE_STATE_INVALID) && 98 (ip_ptr -> nx_ipv6_nd_cache[index].nx_nd_cache_interface_ptr) && 99 (CHECK_IPV6_ADDRESSES_SAME(&ip_ptr -> nx_ipv6_nd_cache[index].nx_nd_cache_dest_ip[0], dest_ip))) 100 { 101 102 /* find the entry */ 103 *nd_cache_entry = &ip_ptr -> nx_ipv6_nd_cache[index]; 104 105 return(NX_SUCCESS); 106 } 107 108 index++; 109 110 /* Check for overflow */ 111 if (index == NX_IPV6_NEIGHBOR_CACHE_SIZE) 112 { 113 index = 0; 114 } 115 } 116 117 return(NX_NOT_SUCCESSFUL); 118 } 119 120 #endif /* FEATURE_NX_IPV6 */ 121 122