Skip to content

Commit a126a08

Browse files
IVandeVeirenashif
authored andcommitted
net: ip: igmp: Remove too strict length check
According to RFC2236 section 2.5, the IGMP message may be longer then 8 bytes. The rest of the bytes should be ignored. Signed-off-by: Ibe Van de Veire <[email protected]> (cherry picked from commit c646dd3)
1 parent ea219db commit a126a08

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

subsys/net/ip/igmp.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ LOG_MODULE_DECLARE(net_ipv4, CONFIG_NET_IPV4_LOG_LEVEL);
3535
#define IGMPV3_ALLOW_NEW_SOURCES 0x05
3636
#define IGMPV3_BLOCK_OLD_SOURCES 0x06
3737

38+
#define IGMPV2_PAYLOAD_MIN_LEN 8
39+
#define IGMPV3_PAYLOAD_MIN_LEN 12
40+
3841
static const struct in_addr all_systems = { { { 224, 0, 0, 1 } } };
3942
#if defined(CONFIG_NET_IPV4_IGMPV3)
4043
static const struct in_addr igmp_multicast_addr = { { { 224, 0, 0, 22 } } };
@@ -416,29 +419,29 @@ static int send_igmp_v3_report(struct net_if *iface, struct net_ipv4_igmp_v3_que
416419

417420
enum net_verdict net_ipv4_igmp_input(struct net_pkt *pkt, struct net_ipv4_hdr *ip_hdr)
418421
{
419-
#if defined(CONFIG_NET_IPV4_IGMPV3)
420-
NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(igmpv3_access, struct net_ipv4_igmp_v3_query);
421-
struct net_ipv4_igmp_v3_query *igmpv3_hdr;
422-
#endif
422+
int ret;
423423
NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(igmpv2_access, struct net_ipv4_igmp_v2_query);
424+
424425
struct net_ipv4_igmp_v2_query *igmpv2_hdr;
425-
enum igmp_version version;
426-
int ret;
427426
int igmp_buf_len =
428427
pkt->buffer->len - (net_pkt_ip_hdr_len(pkt) + net_pkt_ipv4_opts_len(pkt));
428+
#if defined(CONFIG_NET_IPV4_IGMPV3)
429+
struct net_ipv4_igmp_v3_query *igmpv3_hdr;
430+
enum igmp_version version;
431+
432+
NET_PKT_DATA_ACCESS_CONTIGUOUS_DEFINE(igmpv3_access, struct net_ipv4_igmp_v3_query);
429433

430434
/* Detect IGMP type (RFC 3376 ch 7.1) */
431-
if (igmp_buf_len == 8) {
435+
if (igmp_buf_len == IGMPV2_PAYLOAD_MIN_LEN) {
432436
/* IGMPv1/2 detected */
433437
version = IGMPV2;
434-
} else if (igmp_buf_len >= 12) {
438+
} else if (igmp_buf_len >= IGMPV3_PAYLOAD_MIN_LEN) {
435439
/* IGMPv3 detected */
436440
version = IGMPV3;
437-
#if !defined(CONFIG_NET_IPV4_IGMPV3)
438-
NET_DBG("DROP: %sv3 msg received but %s support is disabled", "IGMP", "IGMP");
439-
return NET_DROP;
440-
#endif
441441
} else {
442+
#else
443+
if (igmp_buf_len < IGMPV2_PAYLOAD_MIN_LEN) {
444+
#endif
442445
NET_DBG("DROP: unsupported payload length");
443446
return NET_DROP;
444447
}

0 commit comments

Comments
 (0)