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 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _nxd_ipv6_default_router_table_init                 PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function initializes IPv6 routing table.  Note it is up to the */
45 /*    caller to obtain mutex protection before writing to the table.      */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    ip_ptr                                Pointer to IP control block   */
50 /*                                                                        */
51 /*  OUTPUT                                                                */
52 /*                                                                        */
53 /*    None                                                                */
54 /*                                                                        */
55 /*  CALLS                                                                 */
56 /*                                                                        */
57 /*    None                                                                */
58 /*                                                                        */
59 /*  CALLED BY                                                             */
60 /*                                                                        */
61 /*    nx_ipv6_enable                                                      */
62 /*                                                                        */
63 /*  NOTE                                                                  */
64 /*                                                                        */
65 /*    This function cannot be called from ISR.                            */
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_default_router_table_init(NX_IP * ip_ptr)76 VOID _nxd_ipv6_default_router_table_init(NX_IP *ip_ptr)
77 {
78 
79 ULONG i;
80 
81     /* Initialize each entry in the default router table to null. */
82     for (i = 0; i < NX_IPV6_DEFAULT_ROUTER_TABLE_SIZE; i++)
83     {
84 
85         ip_ptr -> nx_ipv6_default_router_table[i].nx_ipv6_default_router_entry_flag = 0;
86         ip_ptr -> nx_ipv6_default_router_table[i].nx_ipv6_default_router_entry_life_time = 0;
87         ip_ptr -> nx_ipv6_default_router_table[i].nx_ipv6_default_router_entry_neighbor_cache_ptr = NX_NULL;
88     }
89 
90     /* Set the initial size to zero. */
91     ip_ptr -> nx_ipv6_default_router_table_size = 0;
92 
93     /* Initialize the index for recruiting less "reachable" routers
94        when the current router cannot be reached. */
95     ip_ptr -> nx_ipv6_default_router_table_round_robin_index = 0;
96 
97     /* Initialize the start of the prefix table (linked list) to NULL. */
98     ip_ptr -> nx_ipv6_prefix_list_table[0].nx_ipv6_prefix_entry_prev = NX_NULL;
99     ip_ptr -> nx_ipv6_prefix_list_table[0].nx_ipv6_prefix_entry_next = &ip_ptr -> nx_ipv6_prefix_list_table[1];
100 
101     /* Link up the entries in the prefix table.  */
102     for (i = 1; i < NX_IPV6_PREFIX_LIST_TABLE_SIZE - 1; i++)
103     {
104 
105         ip_ptr -> nx_ipv6_prefix_list_table[i].nx_ipv6_prefix_entry_prev = &ip_ptr -> nx_ipv6_prefix_list_table[i - 1];
106         ip_ptr -> nx_ipv6_prefix_list_table[i].nx_ipv6_prefix_entry_next = &ip_ptr -> nx_ipv6_prefix_list_table[i + 1];
107     }
108 
109     /* Null terminate the end of the prefix table (linked list). */
110     ip_ptr -> nx_ipv6_prefix_list_table[i].nx_ipv6_prefix_entry_prev = &ip_ptr -> nx_ipv6_prefix_list_table[i - 1];
111     ip_ptr -> nx_ipv6_prefix_list_table[i].nx_ipv6_prefix_entry_next = NX_NULL;
112 
113     /* Set the free list pointer to the 1st entry. */
114     ip_ptr -> nx_ipv6_prefix_entry_free_list = &ip_ptr -> nx_ipv6_prefix_list_table[0];
115     ip_ptr -> nx_ipv6_prefix_list_ptr = NX_NULL;
116 
117     /* All done, return. */
118 }
119 
120 
121 #endif /* FEATURE_NX_IPV6 */
122 
123