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 /**                                                                       */
16 /** NetX Component                                                        */
17 /**                                                                       */
18 /**   Internet Control Message Protocol (ICMP)                            */
19 /**                                                                       */
20 /**************************************************************************/
21 /**************************************************************************/
22 
23 #define NX_SOURCE_CODE
24 
25 
26 /* Include necessary system files.  */
27 
28 #include "nx_api.h"
29 #include "nx_ipv6.h"
30 #include "nx_icmpv6.h"
31 
32 #ifdef NX_IPSEC_ENABLE
33 #include "nx_ipsec.h"
34 #endif /* NX_IPSEC_ENABLE */
35 
36 
37 #ifdef FEATURE_NX_IPV6
38 
39 
40 /**************************************************************************/
41 /*                                                                        */
42 /*  FUNCTION                                               RELEASE        */
43 /*                                                                        */
44 /*    _nx_icmpv6_DAD_failure                              PORTABLE C      */
45 /*                                                           6.1          */
46 /*  AUTHOR                                                                */
47 /*                                                                        */
48 /*    Yuxin Zhou, Microsoft Corporation                                   */
49 /*                                                                        */
50 /*  DESCRIPTION                                                           */
51 /*                                                                        */
52 /*    This function is called when the DAD process determines that a      */
53 /*    duplicate address is present on the local network.  The interface   */
54 /*    is set to an invalid state.                                         */
55 /*                                                                        */
56 /*  INPUT                                                                 */
57 /*                                                                        */
58 /*    ip_ptr                                IP stack instance             */
59 /*    ipv6_address                          The local IPv6 interface      */
60 /*                                            that detects the failure.   */
61 /*                                                                        */
62 /*  OUTPUT                                                                */
63 /*                                                                        */
64 /*    None                                                                */
65 /*                                                                        */
66 /*  CALLS                                                                 */
67 /*                                                                        */
68 /*    [ipv6_address_change_notify]         User callback function         */
69 /*                                                                        */
70 /*  CALLED BY                                                             */
71 /*                                                                        */
72 /*    _nx_icmpv6_process_na                                               */
73 /*                                                                        */
74 /*  RELEASE HISTORY                                                       */
75 /*                                                                        */
76 /*    DATE              NAME                      DESCRIPTION             */
77 /*                                                                        */
78 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
79 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
80 /*                                            resulting in version 6.1    */
81 /*                                                                        */
82 /**************************************************************************/
83 
84 #ifndef NX_DISABLE_IPV6_DAD
_nx_icmpv6_DAD_failure(NX_IP * ip_ptr,NXD_IPV6_ADDRESS * ipv6_address)85 VOID _nx_icmpv6_DAD_failure(NX_IP *ip_ptr, NXD_IPV6_ADDRESS *ipv6_address)
86 {
87 #ifdef NX_ENABLE_IPV6_ADDRESS_CHANGE_NOTIFY
88 UINT              interface_index;
89 UINT              ipv6_addr_index;
90 #endif /* NX_ENABLE_IPV6_ADDRESS_CHANGE_NOTIFY */
91 NXD_IPV6_ADDRESS *address_ptr;
92 
93     /* Set the interface to an invalid state. */
94     ipv6_address -> nxd_ipv6_address_state = NX_IPV6_ADDR_STATE_UNKNOWN;
95     ipv6_address -> nxd_ipv6_address_valid = NX_FALSE;
96 
97     /* Indicate the DAD process is disabled. */
98     ipv6_address -> nxd_ipv6_address_DupAddrDetectTransmit = 0;
99 #ifdef NX_ENABLE_IPV6_ADDRESS_CHANGE_NOTIFY
100     if (ip_ptr -> nx_ipv6_address_change_notify)
101     {
102         ipv6_addr_index = (ULONG)ipv6_address -> nxd_ipv6_address_index;
103         interface_index = (ULONG)ipv6_address -> nxd_ipv6_address_attached -> nx_interface_index;
104         ip_ptr -> nx_ipv6_address_change_notify(ip_ptr, NX_IPV6_ADDRESS_DAD_FAILURE, interface_index, ipv6_addr_index, &ipv6_address -> nxd_ipv6_address[0]);
105     }
106 #else
107     NX_PARAMETER_NOT_USED(ip_ptr);
108 #endif /* NX_ENABLE_IPV6_ADDRESS_CHANGE_NOTIFY */
109 
110     /* Remove address from interface. */
111     if (ipv6_address == ipv6_address -> nxd_ipv6_address_attached -> nxd_interface_ipv6_address_list_head)
112     {
113         ipv6_address -> nxd_ipv6_address_attached -> nxd_interface_ipv6_address_list_head = ipv6_address -> nxd_ipv6_address_next;
114     }
115     else
116     {
117 
118         for (address_ptr = ipv6_address -> nxd_ipv6_address_attached -> nxd_interface_ipv6_address_list_head;
119              address_ptr != NX_NULL;
120              address_ptr = address_ptr -> nxd_ipv6_address_next)
121         {
122             if (address_ptr -> nxd_ipv6_address_next == ipv6_address)
123             {
124                 address_ptr -> nxd_ipv6_address_next = ipv6_address -> nxd_ipv6_address_next;
125             }
126         }
127     }
128 }
129 
130 #endif  /* NX_DISABLE_IPV6_DAD */
131 #endif  /* FEATURE_NX_IPV6 */
132 
133