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 /**                                                                       */
15 /** NetX Component                                                        */
16 /**                                                                       */
17 /**   Internet Control Message Protocol (ICMP)                            */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define NX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 #include "nx_api.h"
27 #include "nx_ipv6.h"
28 #include "nx_icmpv6.h"
29 
30 #ifdef FEATURE_NX_IPV6
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*   _nx_icmpv6_destination_table_periodic_update         PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Yuxin Zhou, Microsoft Corporation                                   */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function is called from the IP thread task, and updates the    */
46 /*    MTU fields in the destination table, including handling MTU timer   */
47 /*    expiration and initiating a new path MTU probe.                     */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    ip_ptr                                IP instance pointer           */
52 /*                                                                        */
53 /*  OUTPUT                                                                */
54 /*                                                                        */
55 /*    NX_SUCCESS                           Search successfully completed  */
56 /*                                          regardless if match found or  */
57 /*                                          empty slot found for new entry*/
58 /*    NX_NOT_SUCCESSFUL                    Invalid input, search aborted  */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*    _nx_ipv6_perform_min_path_MTU_discovery                             */
63 /*                                         Service to query the existing  */
64 /*                                           minimum path MTU for changes */
65 /*                                                                        */
66 /*                                                                        */
67 /*  CALLED BY                                                             */
68 /*                                                                        */
69 /*    _nx_ip_thread_entry                  IP thread background task      */
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 /**************************************************************************/
80 
81 #ifdef NX_ENABLE_IPV6_PATH_MTU_DISCOVERY
82 
_nx_icmpv6_destination_table_periodic_update(NX_IP * ip_ptr)83 VOID _nx_icmpv6_destination_table_periodic_update(NX_IP *ip_ptr)
84 {
85 
86 UINT i, table_size;
87 
88     /* Set a local variable for convenience. */
89     table_size = ip_ptr -> nx_ipv6_destination_table_size;
90 
91     for (i = 0; table_size && (i < NX_IPV6_DESTINATION_TABLE_SIZE); i++)
92     {
93 
94         /* Ignore entries whose path MTU is already at the host MTU. */
95         if (ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_path_mtu &&
96             ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_nd_entry &&
97             (ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_path_mtu ==
98              ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_nd_entry -> nx_nd_cache_interface_ptr -> nx_interface_ip_mtu_size))
99         {
100             continue;
101         }
102 
103         /* Check for valid entries with a non infinite path MTU timeout. */
104         if (ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_valid &&
105             (ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_MTU_timer_tick != NX_WAIT_FOREVER))
106         {
107 
108             /* Keep track of valid entries we have checked. */
109             table_size--;
110 
111             /* Decrement the timer on table entry. */
112             if (ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_MTU_timer_tick <= NX_IP_PERIODIC_RATE)
113             {
114 
115                 /* Reset the path MTU to the IP instance MTU. */
116                 ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_path_mtu =
117                     ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_nd_entry -> nx_nd_cache_interface_ptr -> nx_interface_ip_mtu_size;
118 
119                 /* This is our optimal path MTU. So there is no need to age this table entry
120                    and attempt to increase the path MTU; ok set it to infinity. */
121                 ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_MTU_timer_tick = NX_WAIT_FOREVER;
122             }
123             else
124             {
125 
126                 ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_MTU_timer_tick -= (ULONG)NX_IP_PERIODIC_RATE;
127             }
128         }
129     }
130 
131     return;
132 }
133 #endif  /* NX_ENABLE_IPV6_PATH_MTU_DISCOVERY */
134 
135 #endif  /* FEATURE_NX_IPV6 */
136 
137