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 /** NetX Component */
14 /** */
15 /** Internet Protocol version 6 Default Router Table (IPv6 router) */
16 /** */
17 /**************************************************************************/
18 /**************************************************************************/
19 #define NX_SOURCE_CODE
20
21
22 /* Include necessary system files. */
23
24 #include "nx_api.h"
25 #include "nx_ipv6.h"
26 #ifdef FEATURE_NX_IPV6
27 #include "nx_nd_cache.h"
28 #include "nx_icmpv6.h"
29 #endif /* FEATURE_NX_IPV6 */
30
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _nxd_ipv6_default_router_delete PORTABLE C */
38 /* 6.1 */
39 /* AUTHOR */
40 /* */
41 /* Yuxin Zhou, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function deletes an IPv6 routing table entry. */
46 /* */
47 /* INPUT */
48 /* */
49 /* ip_ptr Pointer to IP control block */
50 /* router_addr Pointer to router address to */
51 /* delete */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* NX_SUCCESS Successful completion status */
56 /* */
57 /* CALLS */
58 /* */
59 /* tx_mutex_get Obtain protection mutex */
60 /* tx_mutex_put Release protection mutex */
61 /* */
62 /* CALLED BY */
63 /* */
64 /* Application Code */
65 /* */
66 /* RELEASE HISTORY */
67 /* */
68 /* DATE NAME DESCRIPTION */
69 /* */
70 /* 05-19-2020 Yuxin Zhou Initial Version 6.0 */
71 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
72 /* resulting in version 6.1 */
73 /* */
74 /**************************************************************************/
_nxd_ipv6_default_router_delete(NX_IP * ip_ptr,NXD_ADDRESS * router_address)75 UINT _nxd_ipv6_default_router_delete(NX_IP *ip_ptr, NXD_ADDRESS *router_address)
76 {
77 #ifdef FEATURE_NX_IPV6
78
79 INT i;
80 NX_IPV6_DEFAULT_ROUTER_ENTRY *rt_entry;
81
82
83 NX_TRACE_IN_LINE_INSERT(NXD_TRACE_IPV6_DEFAULT_ROUTER_DELETE,
84 ip_ptr, router_address -> nxd_ip_address.v6[3], 0, 0, NX_TRACE_IP_EVENTS, 0, 0);
85
86 /* Obtain protection on this IP instance for access into the default router table. */
87 tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
88
89 /* If our default route table is empty, just return */
90 if (ip_ptr -> nx_ipv6_default_router_table_size == 0)
91 {
92
93 /* Release the mutex. */
94 tx_mutex_put(&(ip_ptr -> nx_ip_protection));
95
96 return(NX_SUCCESS);
97 }
98
99 /* Search the entire table for a matching entry. */
100 for (i = 0; i < NX_IPV6_DEFAULT_ROUTER_TABLE_SIZE; i++)
101 {
102
103 /*Set local pointer for convenience. */
104 rt_entry = &ip_ptr -> nx_ipv6_default_router_table[i];
105
106 /* Does this slot contain a router? */
107 if (rt_entry -> nx_ipv6_default_router_entry_flag & NX_IPV6_ROUTE_TYPE_VALID)
108 {
109
110 /* Does it match the router address to search for? */
111 if (CHECK_IPV6_ADDRESSES_SAME(router_address -> nxd_ip_address.v6,
112 rt_entry -> nx_ipv6_default_router_entry_router_address))
113 {
114
115 /* Yes, does it have a pointer into the cache table? */
116 if (rt_entry -> nx_ipv6_default_router_entry_neighbor_cache_ptr)
117 {
118
119 /* Clear the router status. This will enable the entry
120 to time out eventually. */
121 rt_entry -> nx_ipv6_default_router_entry_neighbor_cache_ptr -> nx_nd_cache_is_router = NX_NULL;
122 }
123
124 /* Clean any entries in the destination table for this router. */
125 _nx_invalidate_destination_entry(ip_ptr, rt_entry -> nx_ipv6_default_router_entry_router_address);
126
127 /* Mark the entry as empty. */
128 rt_entry -> nx_ipv6_default_router_entry_flag = 0;
129
130 /* Clear the interface pointer .*/
131 rt_entry -> nx_ipv6_default_router_entry_interface_ptr = NX_NULL;
132
133 /* Decrease the count of available routers. */
134 ip_ptr -> nx_ipv6_default_router_table_size--;
135
136 /* Release the mutex. */
137 tx_mutex_put(&(ip_ptr -> nx_ip_protection));
138
139 return(NX_SUCCESS);
140 }
141 }
142 }
143
144 /* Release the mutex. */
145 tx_mutex_put(&(ip_ptr -> nx_ip_protection));
146
147 return(NX_NOT_FOUND);
148
149 #else /* !FEATURE_NX_IPV6 */
150 NX_PARAMETER_NOT_USED(ip_ptr);
151 NX_PARAMETER_NOT_USED(router_address);
152
153 return(NX_NOT_SUPPORTED);
154
155 #endif /* FEATURE_NX_IPV6 */
156 }
157
158