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 /**                                                                       */
15 /** NetX Component                                                        */
16 /**                                                                       */
17 /**   Internet Control Message Protocol for IPv6 (ICMPv6)                 */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 #define NX_SOURCE_CODE
23 
24 /* Include necessary system files.  */
25 #include "nx_api.h"
26 #include "nx_icmp.h"
27 #include "nx_icmpv6.h"
28 
29 
30 /**************************************************************************/
31 /*                                                                        */
32 /*  FUNCTION                                               RELEASE        */
33 /*                                                                        */
34 /*    _nxd_icmp_enable                                    PORTABLE C      */
35 /*                                                           6.1          */
36 /*  AUTHOR                                                                */
37 /*                                                                        */
38 /*    Yuxin Zhou, Microsoft Corporation                                   */
39 /*                                                                        */
40 /*  DESCRIPTION                                                           */
41 /*                                                                        */
42 /*    This function enables the ICMPv4 and ICMPv6 services for the        */
43 /*    specified IP instance.                                              */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    ip_ptr                                IP instance pointer           */
48 /*                                                                        */
49 /*  OUTPUT                                                                */
50 /*                                                                        */
51 /*    status                                Completion status             */
52 /*                                                                        */
53 /*  CALLS                                                                 */
54 /*                                                                        */
55 /*    memset                                Set the memory                */
56 /*    tx_mutex_get                          Obtain protection mutex       */
57 /*    tx_mutex_put                          Release protection mutex      */
58 /*                                                                        */
59 /*  CALLED BY                                                             */
60 /*                                                                        */
61 /*    Application Code                                                    */
62 /*                                                                        */
63 /*  RELEASE HISTORY                                                       */
64 /*                                                                        */
65 /*    DATE              NAME                      DESCRIPTION             */
66 /*                                                                        */
67 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
68 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
69 /*                                            resulting in version 6.1    */
70 /*                                                                        */
71 /**************************************************************************/
_nxd_icmp_enable(NX_IP * ip_ptr)72 UINT _nxd_icmp_enable(NX_IP *ip_ptr)
73 {
74 
75 
76     /* If trace is enabled, insert this event into the trace buffer.  */
77     NX_TRACE_IN_LINE_INSERT(NXD_TRACE_ICMP_ENABLE, ip_ptr, 0, 0, 0, NX_TRACE_ICMP_EVENTS, 0, 0);
78 
79     tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
80 
81     /* Setup the ICMP packet receiving routine, thereby enabling ICMP traffic.  */
82     /* ICMPv4 and ICMPv6 share the same packet_receive routine.  */
83     ip_ptr -> nx_ip_icmp_packet_receive =  _nx_icmp_packet_receive;
84 
85 #ifndef NX_DISABLE_IPV4
86     /* Setup the ICMP packet queue processing routine.  */
87     ip_ptr -> nx_ip_icmp_queue_process =  _nx_icmp_queue_process;
88 
89     /* Start the ICMPv4 packet process routine */
90     ip_ptr -> nx_ip_icmpv4_packet_process = _nx_icmpv4_packet_process;
91 #endif
92 
93 #ifdef FEATURE_NX_IPV6
94     /* Setup the ICMPv6 packet process routine */
95     ip_ptr -> nx_ip_icmpv6_packet_process = _nx_icmpv6_packet_process;
96 
97     /* Setup the ND Cache periodic update routine */
98     ip_ptr -> nx_nd_cache_fast_periodic_update = _nx_nd_cache_fast_periodic_update;
99     ip_ptr -> nx_nd_cache_slow_periodic_update = _nx_nd_cache_slow_periodic_update;
100 
101     /* Initialize tables used in ICMPv6 protocols. */
102     /* Clear the ND Cache table. */
103     memset(&ip_ptr -> nx_ipv6_nd_cache[0], 0, sizeof(ND_CACHE_ENTRY) * NX_IPV6_NEIGHBOR_CACHE_SIZE);
104 
105     /* Clear the destination table. */
106     memset(&ip_ptr -> nx_ipv6_destination_table[0], 0, sizeof(NX_IPV6_DESTINATION_ENTRY) * NX_IPV6_DESTINATION_TABLE_SIZE);
107 
108     /* Set the initial size to zero. */
109     ip_ptr -> nx_ipv6_destination_table_size = 0;
110 
111 #ifdef NX_ENABLE_IPV6_PATH_MTU_DISCOVERY
112     /* Set up the MTU path discovery periodic update. */
113     ip_ptr -> nx_destination_table_periodic_update = _nx_icmpv6_destination_table_periodic_update;
114 #endif /* NX_ENABLE_IPV6_PATH_MTU_DISCOVERY  */
115 
116 #endif /* FEATURE_NX_IPV6 */
117 
118     tx_mutex_put(&(ip_ptr -> nx_ip_protection));
119 
120     /* Return a successful status!  */
121     return(NX_SUCCESS);
122 }
123 
124