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