@@ -32,6 +32,7 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_IPV4_LOG_LEVEL);
3232#include <zephyr/random/random.h>
3333
3434#include "ipv4.h"
35+ #include "igmp.h"
3536
3637#define THREAD_SLEEP 50 /* ms */
3738
@@ -98,37 +99,87 @@ static void net_test_iface_init(struct net_if *iface)
9899 NET_LINK_ETHERNET );
99100}
100101
102+ #if defined(CONFIG_NET_IPV4_IGMPV3 )
103+ static struct net_ipv4_igmp_v3_report * get_igmp_hdr (struct net_pkt * pkt )
104+ #else
101105static struct net_ipv4_igmp_v2_query * get_igmp_hdr (struct net_pkt * pkt )
106+ #endif
102107{
103108 net_pkt_cursor_init (pkt );
104109
105110 net_pkt_skip (pkt , net_pkt_ip_hdr_len (pkt ) +
106111 net_pkt_ipv4_opts_len (pkt ));
107112
113+ #if defined(CONFIG_NET_IPV4_IGMPV3 )
114+ return (struct net_ipv4_igmp_v3_report * )net_pkt_cursor_get_pos (pkt );
115+ #else
108116 return (struct net_ipv4_igmp_v2_query * )net_pkt_cursor_get_pos (pkt );
117+ #endif
109118}
110119
120+ #if defined(CONFIG_NET_IPV4_IGMPV3 )
121+ static struct net_ipv4_igmp_v3_group_record * get_igmp_group_record (struct net_pkt * pkt )
122+ {
123+ net_pkt_cursor_init (pkt );
124+
125+ net_pkt_skip (pkt , net_pkt_ip_hdr_len (pkt ) + net_pkt_ipv4_opts_len (pkt ));
126+ net_pkt_skip (pkt , sizeof (struct net_ipv4_igmp_v3_report ));
127+
128+ return (struct net_ipv4_igmp_v3_group_record * )net_pkt_cursor_get_pos (pkt );
129+ }
130+ #endif
131+
111132static int tester_send (const struct device * dev , struct net_pkt * pkt )
112133{
113- struct net_ipv4_igmp_v2_query * igmp ;
134+ #if defined(CONFIG_NET_IPV4_IGMPV3 )
135+ struct net_ipv4_igmp_v3_report * igmp_header ;
136+ struct net_ipv4_igmp_v3_group_record * igmp_group_record ;
137+ #else
138+ struct net_ipv4_igmp_v2_query * igmp_header ;
139+ #endif
114140
115141 if (!pkt -> buffer ) {
116142 TC_ERROR ("No data to send!\n" );
117143 return - ENODATA ;
118144 }
119145
120- igmp = get_igmp_hdr (pkt );
146+ igmp_header = get_igmp_hdr (pkt );
121147
122- if (igmp -> type == NET_IPV4_IGMP_QUERY ) {
148+ if (igmp_header -> type == NET_IPV4_IGMP_QUERY ) {
123149 NET_DBG ("Received query...." );
124150 is_query_received = true;
125151 k_sem_give (& wait_data );
126- } else if (igmp -> type == NET_IPV4_IGMP_REPORT_V2 ) {
152+ } else if (igmp_header -> type == NET_IPV4_IGMP_REPORT_V2 ) {
127153 NET_DBG ("Received v2 report...." );
154+ zassert_false (IS_ENABLED (CONFIG_NET_IPV4_IGMPV3 ),
155+ "Wrong IGMP report received (IGMPv2)" );
128156 is_join_msg_ok = true;
129157 is_report_sent = true;
130158 k_sem_give (& wait_data );
131- } else if (igmp -> type == NET_IPV4_IGMP_LEAVE ) {
159+ } else if (igmp_header -> type == NET_IPV4_IGMP_REPORT_V3 ) {
160+ NET_DBG ("Received v3 report...." );
161+ zassert_true (IS_ENABLED (CONFIG_NET_IPV4_IGMPV3 ),
162+ "Wrong IGMP report received (IGMPv3)" );
163+
164+ #if defined(CONFIG_NET_IPV4_IGMPV3 )
165+ zassert_true (ntohs (igmp_header -> groups_len ) == 1 ,
166+ "Invalid group length of IGMPv3 report (%d)" , igmp_header -> groups_len );
167+
168+ igmp_group_record = get_igmp_group_record (pkt );
169+ zassert_true (igmp_group_record -> sources_len == 0 ,
170+ "Invalid sources length of IGMPv3 group record" );
171+
172+ if (igmp_group_record -> type == IGMPV3_CHANGE_TO_EXCLUDE_MODE ) {
173+ is_join_msg_ok = true;
174+ } else if (igmp_group_record -> type == IGMPV3_CHANGE_TO_INCLUDE_MODE ) {
175+ is_leave_msg_ok = true;
176+ }
177+ #else
178+ is_join_msg_ok = true;
179+ #endif
180+ is_report_sent = true;
181+ k_sem_give (& wait_data );
182+ } else if (igmp_header -> type == NET_IPV4_IGMP_LEAVE ) {
132183 NET_DBG ("Received leave...." );
133184 is_leave_msg_ok = true;
134185 k_sem_give (& wait_data );
0 commit comments