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 #include "nx_icmpv6.h"
29
30
31 #ifdef FEATURE_NX_IPV6
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _nxd_ipv6_prefix_router_timer_tick PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* Yuxin Zhou, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* At every time tick, this function checks for time out expiration on */
45 /* both the default router list and the prefix list tables bound to the*/
46 /* supplied IP instance. */
47 /* */
48 /* INPUT */
49 /* */
50 /* ip_ptr IP instance pointer */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* None */
55 /* */
56 /* CALLS */
57 /* */
58 /* _nx_invalidate_destination_entry Invalidate the entry in the */
59 /* destination */
60 /* */
61 /* CALLED BY */
62 /* */
63 /* _nx_ip_thread_entry */
64 /* */
65 /* NOTE */
66 /* */
67 /* The nx_ip_protection mutex must be obtained before calling this */
68 /* function. */
69 /* */
70 /* This function cannot be called from ISR. */
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 /**************************************************************************/
_nxd_ipv6_prefix_router_timer_tick(NX_IP * ip_ptr)81 VOID _nxd_ipv6_prefix_router_timer_tick(NX_IP *ip_ptr)
82 {
83
84 UINT i, table_size;
85 NX_IPV6_PREFIX_ENTRY *tmp, *prefix_entry;
86 NX_IPV6_DEFAULT_ROUTER_ENTRY *rt_entry;
87
88
89 /* Set a local variable for convenience. */
90 table_size = ip_ptr -> nx_ipv6_default_router_table_size;
91
92 /* Check each entry in the default router table. */
93 for (i = 0; table_size && (i < NX_IPV6_DEFAULT_ROUTER_TABLE_SIZE); i++)
94 {
95
96 /* Set a local variable for convenience. */
97 rt_entry = &ip_ptr -> nx_ipv6_default_router_table[i];
98
99 /* Skip invalid or empty slots. */
100 if ((rt_entry -> nx_ipv6_default_router_entry_flag & NX_IPV6_ROUTE_TYPE_VALID) == 0)
101 {
102 continue;
103 }
104
105 /* Keep track of valid entries we've checked. */
106 table_size--;
107
108 /* Has the entry on the current table entry expired? */
109 if (rt_entry -> nx_ipv6_default_router_entry_life_time == 0)
110 {
111
112 /* Yes, the router has timed out. */
113 /* Does this router have an entry in the ND cache table? */
114 if (rt_entry -> nx_ipv6_default_router_entry_neighbor_cache_ptr)
115 {
116
117 /* Yes, clear out that entry, we are invalidating this entry. */
118 rt_entry -> nx_ipv6_default_router_entry_neighbor_cache_ptr -> nx_nd_cache_is_router = NX_NULL;
119 }
120
121 /* Clean any entries in the destination table for this router. */
122 _nx_invalidate_destination_entry(ip_ptr, rt_entry -> nx_ipv6_default_router_entry_router_address);
123
124 /* Invalidate the entry in the router table. */
125 rt_entry -> nx_ipv6_default_router_entry_flag = 0;
126
127 /* Clear the interface pointer .*/
128 rt_entry -> nx_ipv6_default_router_entry_interface_ptr = NX_NULL;
129
130 /* Decrease the IP instance default router count. */
131 ip_ptr -> nx_ipv6_default_router_table_size--;
132 }
133 else
134 {
135 /* Is this a static router (infinite timeout)? */
136 if (rt_entry -> nx_ipv6_default_router_entry_life_time != 0xFFFF)
137 {
138
139 /* No, so decrement the lifetime by one tick.*/
140 rt_entry -> nx_ipv6_default_router_entry_life_time--;
141 }
142 }
143 }
144
145 /* Set a pointer to the first prefix entry in the IP prefix list. */
146 prefix_entry = ip_ptr -> nx_ipv6_prefix_list_ptr;
147
148 /* Loop through the entire list. */
149 while (prefix_entry)
150 {
151
152 /* Set a placemarker at the current prefix. */
153 tmp = prefix_entry;
154
155 /* Get a pointer to the next prefix. */
156 prefix_entry = prefix_entry -> nx_ipv6_prefix_entry_next;
157
158 /* Skip the static entries. */
159 if (tmp -> nx_ipv6_prefix_entry_valid_lifetime != (UINT)0xFFFFFFFF)
160 {
161
162 /* Has the prefix entry timeout expired? */
163 if (tmp -> nx_ipv6_prefix_entry_valid_lifetime == 0)
164 {
165
166 /* Yes, so delete it from the list. */
167 _nx_ipv6_prefix_list_delete_entry(ip_ptr, tmp);
168 }
169 else
170 {
171
172 /* Just decrement the time remaining. */
173 tmp -> nx_ipv6_prefix_entry_valid_lifetime--;
174 }
175 }
176 }
177
178 return;
179 }
180
181 #endif /* FEATURE_NX_IPV6 */
182
183