summaryrefslogtreecommitdiff
path: root/common/src/nx_icmpv6_dest_table_find.c
blob: 5385ff91ec90955e220ea7d1be224592e004f99b (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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/***************************************************************************
 * 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 (ICMP)                            */
/**                                                                       */
/**************************************************************************/
/**************************************************************************/

#define NX_SOURCE_CODE


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

#ifdef FEATURE_NX_IPV6


/**************************************************************************/
/*                                                                        */
/*  FUNCTION                                               RELEASE        */
/*                                                                        */
/*    _nx_icmpv6_dest_table_find                          PORTABLE C      */
/*                                                           6.4.3        */
/*  AUTHOR                                                                */
/*                                                                        */
/*    Yuxin Zhou, Microsoft Corporation                                   */
/*                                                                        */
/*  DESCRIPTION                                                           */
/*                                                                        */
/*    This function finds a destination table entry based on destination  */
/*    address.  If no match is found, a the destination entry pointer is  */
/*    set to NULL, but a successful search status returned.               */
/*                                                                        */
/*  INPUT                                                                 */
/*                                                                        */
/*    ip_ptr                               Pointer to IP                  */
/*    destination_address                  Destination IP address.        */
/*    dest_entry_ptr                       Pointer to location of matching*/
/*                                             table entry, if any.       */
/*    path_mtu                             Optional path mtu update.      */
/*                                           Note: caller shall make sure */
/*                                           MTU does not exceed physical */
/*                                           link MTU size.               */
/*    mtu_timeout                          Optional entry timeout update  */
/*                                                                        */
/*  OUTPUT                                                                */
/*                                                                        */
/*    NX_SUCCESS                            Search successfully completed */
/*                                             regardless if match found  */
/*    NX_NOT_SUCCESSFUL                     Invalid input; search aborted */
/*                                                                        */
/*  CALLS                                                                 */
/*                                                                        */
/*                                                                        */
/*  CALLED BY                                                             */
/*                                                                        */
/*    nx_icmpv6_send_queued_packets         Send queued ICMPv6 packets    */
/*    nx_ipv6_send_packet                   Send specified IPv6 packet    */
/*                                                                        */
/**************************************************************************/
UINT _nx_icmpv6_dest_table_find(NX_IP *ip_ptr, ULONG *destination_address, NX_IPV6_DESTINATION_ENTRY **dest_entry_ptr,
                                ULONG path_mtu, ULONG mtu_timeout)
{

UINT i, table_size;

    /* Destination address must be valid. */
    NX_ASSERT((destination_address != NX_NULL) && (dest_entry_ptr != NULL));

    /* Set a local variable for convenience. */
    table_size = ip_ptr -> nx_ipv6_destination_table_size;

    /* Check the destination num. */
    if (table_size == 0)
    {
        return(NX_NOT_SUCCESSFUL);
    }

    /* Initialize the return value. */
    *dest_entry_ptr = NX_NULL;

    /* Loop through all entries. */
    for (i = 0; table_size && (i < NX_IPV6_DESTINATION_TABLE_SIZE); i++)
    {

        /* Skip invalid entries. */
        if (!ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_valid)
        {
            continue;
        }

        /* Keep track of valid entries we have checked. */
        table_size--;

        /* Check whether or not the address is the same. */
        if (CHECK_IPV6_ADDRESSES_SAME(&ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_destination_address[0], destination_address))
        {

#ifdef NX_ENABLE_IPV6_PATH_MTU_DISCOVERY

            /* Update the table entry if the supplied path MTU is non zero and
               does not exceed our IP instance MTU. */
            if (path_mtu > 0)
            {

                /* Do we have a valid timeout e.g. did this information come from an RA packet?
                   Or is a packet too big message indicating we need to decrease our path MTU? */
                if ((mtu_timeout > 0) || (ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_path_mtu > path_mtu))
                {

                    /* OK to change the path MTU. */
                    ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_path_mtu = path_mtu;

                    /* Was a valid timeout supplied? */
                    if (mtu_timeout > 0)
                    {

                        /* Yes;  Ok to update table entry with the specified timeout. */
                        ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_MTU_timer_tick = mtu_timeout;
                    }
                    else
                    {
                        /* No; the path MTU changed in response to a packet too big error
                           message.  Set the table entry timeout to the required wait
                           interval.  We cannot attempt to restore (increase) the path MTU
                           before this time out expires. */
                        ip_ptr -> nx_ipv6_destination_table[i].nx_ipv6_destination_entry_MTU_timer_tick = NX_PATH_MTU_INCREASE_WAIT_INTERVAL_TICKS;
                    }
                }

                /* Else this information presumably comes a Packet too Big message.
                   RFC 1981 disallows increasing a path MTU based on a PTB message
                   (decreasing is allowed and required). */
            }
#else
            NX_PARAMETER_NOT_USED(path_mtu);
            NX_PARAMETER_NOT_USED(mtu_timeout);
#endif /* NX_ENABLE_IPV6_PATH_MTU_DISCOVERY */

            *dest_entry_ptr = &ip_ptr -> nx_ipv6_destination_table[i];

            return(NX_SUCCESS);
        }
    }

    return(NX_NOT_SUCCESSFUL);
}

#endif  /* FEATURE_NX_IPV6 */