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 /**************************************************************************/
14 /**                                                                       */
15 /** NetX Component                                                        */
16 /**                                                                       */
17 /**   Internet Group Management Protocol (IGMP)                           */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 #define NX_SOURCE_CODE
22 
23 
24 /* Include necessary system files.  */
25 
26 #include "nx_api.h"
27 #include "nx_igmp.h"
28 
29 
30 /**************************************************************************/
31 /*                                                                        */
32 /*  FUNCTION                                               RELEASE        */
33 /*                                                                        */
34 /*    _nx_igmp_loopback_enable                            PORTABLE C      */
35 /*                                                           6.1          */
36 /*  AUTHOR                                                                */
37 /*                                                                        */
38 /*    Yuxin Zhou, Microsoft Corporation                                   */
39 /*                                                                        */
40 /*  DESCRIPTION                                                           */
41 /*                                                                        */
42 /*    This function enables loopback for all subsequent IGMP groups       */
43 /*    joined by the host.                                                 */
44 /*                                                                        */
45 /*  INPUT                                                                 */
46 /*                                                                        */
47 /*    ip_ptr                                IP instance pointer           */
48 /*                                                                        */
49 /*  OUTPUT                                                                */
50 /*                                                                        */
51 /*    status                                Completion status             */
52 /*                                                                        */
53 /*  CALLS                                                                 */
54 /*                                                                        */
55 /*   _tx_mutex_get                          Obtain the mutex              */
56 /*   _tx_mutex_put                          Release the mutex             */
57 /*                                                                        */
58 /*  CALLED BY                                                             */
59 /*                                                                        */
60 /*    Application Code                                                    */
61 /*                                                                        */
62 /*  RELEASE HISTORY                                                       */
63 /*                                                                        */
64 /*    DATE              NAME                      DESCRIPTION             */
65 /*                                                                        */
66 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
67 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
68 /*                                            resulting in version 6.1    */
69 /*                                                                        */
70 /**************************************************************************/
_nx_igmp_loopback_enable(NX_IP * ip_ptr)71 UINT  _nx_igmp_loopback_enable(NX_IP *ip_ptr)
72 {
73 
74 #ifndef NX_DISABLE_IPV4
75 
76 
77     /* If trace is enabled, insert this event into the trace buffer.  */
78     NX_TRACE_IN_LINE_INSERT(NX_TRACE_IGMP_LOOPBACK_ENABLE, ip_ptr, 0, 0, 0, NX_TRACE_IGMP_EVENTS, 0, 0);
79 
80     /* Obtain the IP mutex so we can search the multicast join list.  */
81     tx_mutex_get(&(ip_ptr -> nx_ip_protection), TX_WAIT_FOREVER);
82 
83     /* Set the global IGMP loopback flag.  All subsequent IGMP group join
84        requests will have loopback enabled.  */
85     ip_ptr -> nx_ip_igmp_global_loopback_enable =  NX_TRUE;
86 
87     /* Release the protection over the IP instance.  */
88     tx_mutex_put(&(ip_ptr -> nx_ip_protection));
89 
90     /* Return a successful status!  */
91     return(NX_SUCCESS);
92 #else /* NX_DISABLE_IPV4  */
93     NX_PARAMETER_NOT_USED(ip_ptr);
94 
95     return(NX_NOT_SUPPORTED);
96 #endif /* !NX_DISABLE_IPV4  */
97 }
98 
99