summaryrefslogtreecommitdiff
path: root/common/src/nxd_icmp_enable.c
blob: e60ef75d597bcc4ebefc680bcf2d3abc66f1fccb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/***************************************************************************
 * Copyright (c) 2024 Microsoft Corporation
 * Copyright (c) 2025-present Eclipse ThreadX Contributors
 *
 * This program and the accompanying materials are made available under the
 * terms of the MIT License which is available at
 * https://opensource.org/licenses/MIT.
 *
 * SPDX-License-Identifier: MIT
 **************************************************************************/


/**************************************************************************/
/**************************************************************************/
/**                                                                       */
/** NetX Component                                                        */
/**                                                                       */
/**   Internet Control Message Protocol for IPv6 (ICMPv6)                 */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/

#define NX_SOURCE_CODE

/* Include necessary system files.  */
#include "nx_api.h"
#include "nx_icmp.h"
#include "nx_icmpv6.h"


/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _nxd_icmp_enable                                    PORTABLE C      */
/*                                                           6.4.3        */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Yuxin Zhou, Microsoft Corporation                                   */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function enables the ICMPv4 and ICMPv6 services for the        */
/*    specified IP instance.                                              */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    ip_ptr                                IP instance pointer           */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    status                                Completion status             */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*    memset                                Set the memory                */
/*    tx_mutex_get                          Obtain protection mutex       */
/*    tx_mutex_put                          Release protection mutex      */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    Application Code                                                    */
/*                                                                        */
/**************************************************************************/
UINT _nxd_icmp_enable(NX_IP *ip_ptr)
{


    /* If trace is enabled, insert this event into the trace buffer.  */
    NX_TRACE_IN_LINE_INSERT(NXD_TRACE_ICMP_ENABLE, ip_ptr, 0, 0, 0, NX_TRACE_ICMP_EVENTS, 0, 0);

    tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);

    /* Setup the ICMP packet receiving routine, thereby enabling ICMP traffic.  */
    /* ICMPv4 and ICMPv6 share the same packet_receive routine.  */
    ip_ptr -> nx_ip_icmp_packet_receive =  _nx_icmp_packet_receive;

#ifndef NX_DISABLE_IPV4
    /* Setup the ICMP packet queue processing routine.  */
    ip_ptr -> nx_ip_icmp_queue_process =  _nx_icmp_queue_process;

    /* Start the ICMPv4 packet process routine */
    ip_ptr -> nx_ip_icmpv4_packet_process = _nx_icmpv4_packet_process;
#endif

#ifdef FEATURE_NX_IPV6
    /* Setup the ICMPv6 packet process routine */
    ip_ptr -> nx_ip_icmpv6_packet_process = _nx_icmpv6_packet_process;

    /* Setup the ND Cache periodic update routine */
    ip_ptr -> nx_nd_cache_fast_periodic_update = _nx_nd_cache_fast_periodic_update;
    ip_ptr -> nx_nd_cache_slow_periodic_update = _nx_nd_cache_slow_periodic_update;

    /* Initialize tables used in ICMPv6 protocols. */
    /* Clear the ND Cache table. */
    memset(&ip_ptr -> nx_ipv6_nd_cache[0], 0, sizeof(ND_CACHE_ENTRY) * NX_IPV6_NEIGHBOR_CACHE_SIZE);

    /* Clear the destination table. */
    memset(&ip_ptr -> nx_ipv6_destination_table[0], 0, sizeof(NX_IPV6_DESTINATION_ENTRY) * NX_IPV6_DESTINATION_TABLE_SIZE);

    /* Set the initial size to zero. */
    ip_ptr -> nx_ipv6_destination_table_size = 0;

#ifdef NX_ENABLE_IPV6_PATH_MTU_DISCOVERY
    /* Set up the MTU path discovery periodic update. */
    ip_ptr -> nx_destination_table_periodic_update = _nx_icmpv6_destination_table_periodic_update;
#endif /* NX_ENABLE_IPV6_PATH_MTU_DISCOVERY  */

#endif /* FEATURE_NX_IPV6 */

    tx_mutex_put(&(ip_ptr -> nx_ip_protection));

    /* Return a successful status!  */
    return(NX_SUCCESS);
}