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 #endif /* FEATURE_NX_IPV6 */
29 
30 
31 /**************************************************************************/
32 /*                                                                        */
33 /*  FUNCTION                                               RELEASE        */
34 /*                                                                        */
35 /*    _nxd_ipv6_default_router_add                         PORTABLE C     */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Yuxin Zhou, Microsoft Corporation                                   */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function adds a router to the default IPv6 routing table.      */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    ip_ptr                                IP instance pointer           */
48 /*    router_addr                           Destination Network addr      */
49 /*    router_lifetime                       Life time information         */
50 /*    interface_index                       Index to the interface        */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    status                                Completion status             */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*    tx_mutex_get                          Obtain protection mutex       */
59 /*    tx_mutex_put                          Release protection mutex      */
60 /*    _nxd_ipv6_default_router_add_internal                               */
61 /*                                          Actual function that adds     */
62 /*                                          an entry to the router table  */
63 /*                                                                        */
64 /*  CALLED BY                                                             */
65 /*                                                                        */
66 /*    Application code                                                    */
67 /*                                                                        */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
74 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
75 /*                                            resulting in version 6.1    */
76 /*                                                                        */
77 /**************************************************************************/
_nxd_ipv6_default_router_add(NX_IP * ip_ptr,NXD_ADDRESS * router_addr,ULONG router_lifetime,UINT interface_index)78 UINT  _nxd_ipv6_default_router_add(NX_IP *ip_ptr,
79                                    NXD_ADDRESS *router_addr,
80                                    ULONG router_lifetime,
81                                    UINT interface_index)
82 {
83 #ifdef FEATURE_NX_IPV6
84 
85 UINT status;
86 
87 
88     NX_TRACE_IN_LINE_INSERT(NXD_TRACE_IPV6_DEFAULT_ROUTER_ADD, ip_ptr, router_addr -> nxd_ip_address.v6[3], router_lifetime, 0, NX_TRACE_IP_EVENTS, 0, 0);
89 
90     /* Obtain protection on this IP instance for access into the default router table. */
91     tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
92 
93     status = _nxd_ipv6_default_router_add_internal(ip_ptr,
94                                                    router_addr -> nxd_ip_address.v6,
95                                                    router_lifetime,
96                                                    &ip_ptr -> nx_ip_interface[interface_index],
97                                                    NX_IPV6_ROUTE_TYPE_STATIC,
98                                                    NX_NULL);
99 
100     /* Release the mutex.  */
101     tx_mutex_put(&(ip_ptr -> nx_ip_protection));
102 
103     return(status);
104 
105 #else /* !FEATURE_NX_IPV6 */
106     NX_PARAMETER_NOT_USED(ip_ptr);
107     NX_PARAMETER_NOT_USED(router_addr);
108     NX_PARAMETER_NOT_USED(router_lifetime);
109     NX_PARAMETER_NOT_USED(interface_index);
110 
111     return(NX_NOT_SUPPORTED);
112 
113 #endif /* FEATURE_NX_IPV6 */
114 }
115 
116