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 /** NetX Component */ 14 /** */ 15 /** Internet Protocol version 6 Default Router Table (IPv6 router) */ 16 /** */ 17 /**************************************************************************/ 18 /**************************************************************************/ 19 #define NX_SOURCE_CODE 20 21 22 /* Include necessary system files. */ 23 24 #include "nx_api.h" 25 #include "nx_ipv6.h" 26 #include "nx_nd_cache.h" 27 28 29 #ifdef FEATURE_NX_IPV6 30 31 /**************************************************************************/ 32 /* */ 33 /* FUNCTION RELEASE */ 34 /* */ 35 /* _nxd_ipv6_default_router_table_init PORTABLE C */ 36 /* 6.1 */ 37 /* AUTHOR */ 38 /* */ 39 /* Yuxin Zhou, Microsoft Corporation */ 40 /* */ 41 /* DESCRIPTION */ 42 /* */ 43 /* This function initializes IPv6 routing table. Note it is up to the */ 44 /* caller to obtain mutex protection before writing to the table. */ 45 /* */ 46 /* INPUT */ 47 /* */ 48 /* ip_ptr Pointer to IP control block */ 49 /* */ 50 /* OUTPUT */ 51 /* */ 52 /* None */ 53 /* */ 54 /* CALLS */ 55 /* */ 56 /* None */ 57 /* */ 58 /* CALLED BY */ 59 /* */ 60 /* nx_ipv6_enable */ 61 /* */ 62 /* NOTE */ 63 /* */ 64 /* This function cannot be called from ISR. */ 65 /* */ 66 /* RELEASE HISTORY */ 67 /* */ 68 /* DATE NAME DESCRIPTION */ 69 /* */ 70 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */ 71 /* 09-30-2020 Yuxin Zhou Modified comment(s), */ 72 /* resulting in version 6.1 */ 73 /* */ 74 /**************************************************************************/ _nxd_ipv6_default_router_table_init(NX_IP * ip_ptr)75VOID _nxd_ipv6_default_router_table_init(NX_IP *ip_ptr) 76 { 77 78 ULONG i; 79 80 /* Initialize each entry in the default router table to null. */ 81 for (i = 0; i < NX_IPV6_DEFAULT_ROUTER_TABLE_SIZE; i++) 82 { 83 84 ip_ptr -> nx_ipv6_default_router_table[i].nx_ipv6_default_router_entry_flag = 0; 85 ip_ptr -> nx_ipv6_default_router_table[i].nx_ipv6_default_router_entry_life_time = 0; 86 ip_ptr -> nx_ipv6_default_router_table[i].nx_ipv6_default_router_entry_neighbor_cache_ptr = NX_NULL; 87 } 88 89 /* Set the initial size to zero. */ 90 ip_ptr -> nx_ipv6_default_router_table_size = 0; 91 92 /* Initialize the index for recruiting less "reachable" routers 93 when the current router cannot be reached. */ 94 ip_ptr -> nx_ipv6_default_router_table_round_robin_index = 0; 95 96 /* Initialize the start of the prefix table (linked list) to NULL. */ 97 ip_ptr -> nx_ipv6_prefix_list_table[0].nx_ipv6_prefix_entry_prev = NX_NULL; 98 ip_ptr -> nx_ipv6_prefix_list_table[0].nx_ipv6_prefix_entry_next = &ip_ptr -> nx_ipv6_prefix_list_table[1]; 99 100 /* Link up the entries in the prefix table. */ 101 for (i = 1; i < NX_IPV6_PREFIX_LIST_TABLE_SIZE - 1; i++) 102 { 103 104 ip_ptr -> nx_ipv6_prefix_list_table[i].nx_ipv6_prefix_entry_prev = &ip_ptr -> nx_ipv6_prefix_list_table[i - 1]; 105 ip_ptr -> nx_ipv6_prefix_list_table[i].nx_ipv6_prefix_entry_next = &ip_ptr -> nx_ipv6_prefix_list_table[i + 1]; 106 } 107 108 /* Null terminate the end of the prefix table (linked list). */ 109 ip_ptr -> nx_ipv6_prefix_list_table[i].nx_ipv6_prefix_entry_prev = &ip_ptr -> nx_ipv6_prefix_list_table[i - 1]; 110 ip_ptr -> nx_ipv6_prefix_list_table[i].nx_ipv6_prefix_entry_next = NX_NULL; 111 112 /* Set the free list pointer to the 1st entry. */ 113 ip_ptr -> nx_ipv6_prefix_entry_free_list = &ip_ptr -> nx_ipv6_prefix_list_table[0]; 114 ip_ptr -> nx_ipv6_prefix_list_ptr = NX_NULL; 115 116 /* All done, return. */ 117 } 118 119 120 #endif /* FEATURE_NX_IPV6 */ 121 122