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