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 
22 #define NX_SOURCE_CODE
23 
24 
25 /* Include necessary system files.  */
26 
27 #include "nx_api.h"
28 #include "nx_igmp.h"
29 
30 
31 #ifndef NX_DISABLE_IPV4
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _nx_igmp_multicast_check                            PORTABLE C      */
37 /*                                                           6.1          */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Yuxin Zhou, Microsoft Corporation                                   */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function checks the list of joined multicast addresses to see  */
45 /*    if the incoming address matches.  If the specified group is         */
46 /*    "all hosts" or if a match is found, NX_TRUE is returned to the      */
47 /*    caller.                                                             */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    ip_ptr                                IP instance pointer           */
52 /*    group                                 Multicast group IP address    */
53 /*    nx_interface                          Pointer to interface          */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    NX_TRUE                               If a match is found           */
58 /*    NX_FALSE                              Otherwise                     */
59 /*                                                                        */
60 /*  CALLS                                                                 */
61 /*                                                                        */
62 /*    None                                                                */
63 /*                                                                        */
64 /*  CALLED BY                                                             */
65 /*                                                                        */
66 /*    _nx_ipv4_packet_receive               Raw IP packet receive         */
67 /*                                                                        */
68 /*  RELEASE HISTORY                                                       */
69 /*                                                                        */
70 /*    DATE              NAME                      DESCRIPTION             */
71 /*                                                                        */
72 /*  05-19-2020     Yuxin Zhou               Initial Version 6.0           */
73 /*  09-30-2020     Yuxin Zhou               Modified comment(s),          */
74 /*                                            resulting in version 6.1    */
75 /*                                                                        */
76 /**************************************************************************/
_nx_igmp_multicast_check(NX_IP * ip_ptr,ULONG group,NX_INTERFACE * nx_interface)77 UINT  _nx_igmp_multicast_check(NX_IP *ip_ptr, ULONG group, NX_INTERFACE *nx_interface)
78 {
79 
80 UINT i;
81 
82     /* Check for "all hosts" group.  We always assume all hosts membership.  */
83     /*lint -e{835} -e{845} suppress operating on zero. */
84     if (group ==  NX_ALL_HOSTS_ADDRESS)
85     {
86         return(NX_TRUE);
87     }
88 
89     /* Loop through the IP multicast join list to find the matching group that is being
90        responded to by another host on this same network.  */
91 
92     for (i = 0; i < NX_MAX_MULTICAST_GROUPS; i++)
93     {
94 
95         /* Check for a match.  */
96         if ((ip_ptr -> nx_ipv4_multicast_entry[i].nx_ipv4_multicast_join_list == group) &&
97             (nx_interface == ip_ptr -> nx_ipv4_multicast_entry[i].nx_ipv4_multicast_join_interface_list))
98         {
99             return(NX_TRUE);
100         }
101     }
102 
103     /* Otherwise, we have searched the entire list, return false.  */
104     return(NX_FALSE);
105 }
106 #endif /* !NX_DISABLE_IPV4  */
107 
108