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