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 /** NetX Component */ 15 /** */ 16 /** Internet Protocol version 6 Default Router Table (IPv6 router) */ 17 /** */ 18 /**************************************************************************/ 19 /**************************************************************************/ 20 #define NX_SOURCE_CODE 21 22 23 /* Include necessary system files. */ 24 25 #include "nx_api.h" 26 #include "nx_ipv6.h" 27 #include "nx_nd_cache.h" 28 29 30 #ifdef FEATURE_NX_IPV6 31 /**************************************************************************/ 32 /* */ 33 /* FUNCTION RELEASE */ 34 /* */ 35 /* _nxd_ipv6_find_default_router_from_address PORTABLE C */ 36 /* 6.1 */ 37 /* AUTHOR */ 38 /* */ 39 /* Yuxin Zhou, Microsoft Corporation */ 40 /* */ 41 /* DESCRIPTION */ 42 /* */ 43 /* This function finds the specific IPv6 default router. */ 44 /* */ 45 /* INPUT */ 46 /* */ 47 /* ip_ptr IP instance pointer */ 48 /* router_address The specific gateway address */ 49 /* to search for. */ 50 /* */ 51 /* OUTPUT */ 52 /* */ 53 /* default router entry Pointer to the default router */ 54 /* entry. */ 55 /* CALLS */ 56 /* */ 57 /* tx_mutex_get Obtain IP protection mutex */ 58 /* tx_mutex_put Release IP protection mutex */ 59 /* */ 60 /* CALLED BY */ 61 /* */ 62 /* _nxd_icmpv6_process_na */ 63 /* */ 64 /* NOTE */ 65 /* */ 66 /* This function acquires the nx_ipv6_protection mutex. */ 67 /* Make sure the mutex is not locked before entering this function. */ 68 /* */ 69 /* This function cannot be called from ISR. */ 70 /* */ 71 /* RELEASE HISTORY */ 72 /* */ 73 /* DATE NAME DESCRIPTION */ 74 /* */ 75 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ 76 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 77 /* resulting in version 6.1 */ 78 /* */ 79 /**************************************************************************/ _nxd_ipv6_find_default_router_from_address(NX_IP * ip_ptr,ULONG * router_address)80NX_IPV6_DEFAULT_ROUTER_ENTRY *_nxd_ipv6_find_default_router_from_address(NX_IP *ip_ptr, ULONG *router_address) 81 { 82 83 INT i; 84 NX_IPV6_DEFAULT_ROUTER_ENTRY *rt_entry; 85 86 87 /* Get exclusive access to the IP task lock. */ 88 tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER); 89 90 /* Start the search at the top of the list...*/ 91 i = 0; 92 93 /* And go through the entire table or until a match is found. */ 94 while (i < NX_IPV6_DEFAULT_ROUTER_TABLE_SIZE) 95 { 96 97 /* Local pointer to table entry. */ 98 rt_entry = &ip_ptr -> nx_ipv6_default_router_table[i]; 99 100 /* Does this slot contain a valid router? */ 101 if (rt_entry -> nx_ipv6_default_router_entry_flag) 102 { 103 104 /* Yes, check if it matches the specified router address. */ 105 if (CHECK_IPV6_ADDRESSES_SAME(router_address, rt_entry -> nx_ipv6_default_router_entry_router_address)) 106 { 107 108 109 /* Yes it does, we can release the IP protection. */ 110 tx_mutex_put(&(ip_ptr -> nx_ip_protection)); 111 112 /* Return the pointer to this router entry. */ 113 return(rt_entry); 114 } 115 } 116 117 i++; 118 } 119 120 /* Release the lock. */ 121 tx_mutex_put(&(ip_ptr -> nx_ip_protection)); 122 123 /* Return a null pointer indicating no matching router found. */ 124 return(NX_NULL); 125 } 126 127 #endif /* FEATURE_NX_IPV6 */ 128 129