net: ipv4: Add IGMPv2 support

Add Internet Group Management Protocol v2 support, see RFC 2236
for details.

Fixes #2336

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2021-04-26 20:03:35 +03:00 committed by Jukka Rissanen
commit a1c4952dfd
10 changed files with 456 additions and 1 deletions

66
include/net/igmp.h Normal file
View file

@ -0,0 +1,66 @@
/*
* Copyright (c) 2021 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
/** @file
* @brief IGMP API
*/
#ifndef ZEPHYR_INCLUDE_NET_IGMP_H_
#define ZEPHYR_INCLUDE_NET_IGMP_H_
/**
* @brief IGMP (Internet Group Management Protocol)
* @defgroup igmp IGMP API
* @ingroup networking
* @{
*/
#include <zephyr/types.h>
#include <net/net_if.h>
#include <net/net_ip.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Join a given multicast group.
*
* @param iface Network interface where join message is sent
* @param addr Multicast group to join
*
* @return Return 0 if joining was done, <0 otherwise.
*/
#if defined(CONFIG_NET_IPV4_IGMP)
int net_ipv4_igmp_join(struct net_if *iface, const struct in_addr *addr);
#else
#define net_ipv4_igmp_join(iface, addr) -ENOSYS
#endif
/**
* @brief Leave a given multicast group.
*
* @param iface Network interface where leave message is sent
* @param addr Multicast group to leave
*
* @return Return 0 if leaving is done, <0 otherwise.
*/
#if defined(CONFIG_NET_IPV4_IGMP)
int net_ipv4_igmp_leave(struct net_if *iface, const struct in_addr *addr);
#else
#define net_ipv4_igmp_leave(iface, addr) -ENOSYS
#endif
#ifdef __cplusplus
}
#endif
/**
* @}
*/
#endif /* ZEPHYR_INCLUDE_NET_IGMP_H_ */

View file

@ -135,6 +135,8 @@ enum net_event_ipv4_cmd {
NET_EVENT_IPV4_CMD_DHCP_START,
NET_EVENT_IPV4_CMD_DHCP_BOUND,
NET_EVENT_IPV4_CMD_DHCP_STOP,
NET_EVENT_IPV4_CMD_MCAST_JOIN,
NET_EVENT_IPV4_CMD_MCAST_LEAVE,
};
#define NET_EVENT_IPV4_ADDR_ADD \
@ -158,6 +160,12 @@ enum net_event_ipv4_cmd {
#define NET_EVENT_IPV4_DHCP_STOP \
(_NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_DHCP_STOP)
#define NET_EVENT_IPV4_MCAST_JOIN \
(_NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_MCAST_JOIN)
#define NET_EVENT_IPV4_MCAST_LEAVE \
(_NET_EVENT_IPV4_BASE | NET_EVENT_IPV4_CMD_MCAST_LEAVE)
/* L4 network events */
#define _NET_L4_LAYER NET_MGMT_LAYER_L4

View file

@ -62,6 +62,7 @@ extern "C" {
enum net_ip_protocol {
IPPROTO_IP = 0, /**< IP protocol (pseudo-val for setsockopt() */
IPPROTO_ICMP = 1, /**< ICMP protocol */
IPPROTO_IGMP = 2, /**< IGMP protocol */
IPPROTO_IPIP = 4, /**< IPIP tunnels */
IPPROTO_TCP = 6, /**< TCP protocol */
IPPROTO_UDP = 17, /**< UDP protocol */