Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 84 additions & 0 deletions include/zephyr/net/mld.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*
* Copyright (c) 2016 Intel Corporation
* Copyright (c) 2024 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/

/** @file
* @brief Multicast Listener Discovery API
*/

#ifndef ZEPHYR_INCLUDE_NET_MLD_H_
#define ZEPHYR_INCLUDE_NET_MLD_H_

/**
* @brief MLD (Multicast Listener Discovery)
* @defgroup mld Multicast Listener Discovery API
* @since 1.8
* @version 0.8.0
* @ingroup networking
* @{
*/

#include <errno.h>

#include <zephyr/net/net_if.h>
#include <zephyr/net/net_ip.h>
#include <zephyr/toolchain.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 0 if joining was done, <0 otherwise.
*/
#if defined(CONFIG_NET_IPV6_MLD)
int net_ipv6_mld_join(struct net_if *iface, const struct in6_addr *addr);
#else
static inline int
net_ipv6_mld_join(struct net_if *iface, const struct in6_addr *addr)
{
ARG_UNUSED(addr);
ARG_UNUSED(iface);

return -ENOTSUP;
}
#endif /* CONFIG_NET_IPV6_MLD */

/**
* @brief Leave a given multicast group.
*
* @param iface Network interface where leave message is sent
* @param addr Multicast group to leave
*
* @return 0 if leaving is done, <0 otherwise.
*/
#if defined(CONFIG_NET_IPV6_MLD)
int net_ipv6_mld_leave(struct net_if *iface, const struct in6_addr *addr);
#else
static inline int
net_ipv6_mld_leave(struct net_if *iface, const struct in6_addr *addr)
{
ARG_UNUSED(iface);
ARG_UNUSED(addr);

return -ENOTSUP;
}
#endif /* CONFIG_NET_IPV6_MLD */

#ifdef __cplusplus
}
#endif

/**
* @}
*/

#endif /* ZEPHYR_INCLUDE_NET_MLD_H_ */
54 changes: 45 additions & 9 deletions include/zephyr/net/net_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ struct net_offload;
#endif /* CONFIG_NET_OFFLOAD */

/** @cond INTERNAL_HIDDEN */
#if defined(CONFIG_NET_NATIVE_IPV6)
#if defined(CONFIG_NET_IPV6)
#define NET_IF_MAX_IPV6_ADDR CONFIG_NET_IF_UNICAST_IPV6_ADDR_COUNT
#define NET_IF_MAX_IPV6_MADDR CONFIG_NET_IF_MCAST_IPV6_ADDR_COUNT
#define NET_IF_MAX_IPV6_PREFIX CONFIG_NET_IF_IPV6_PREFIX_COUNT
Expand Down Expand Up @@ -422,7 +422,7 @@ struct net_if_dhcpv6 {
#endif /* defined(CONFIG_NET_DHCPV6) && defined(CONFIG_NET_NATIVE_IPV6) */

/** @cond INTERNAL_HIDDEN */
#if defined(CONFIG_NET_NATIVE_IPV4)
#if defined(CONFIG_NET_IPV4)
#define NET_IF_MAX_IPV4_ADDR CONFIG_NET_IF_UNICAST_IPV4_ADDR_COUNT
#define NET_IF_MAX_IPV4_MADDR CONFIG_NET_IF_MCAST_IPV4_ADDR_COUNT
#else
Expand Down Expand Up @@ -542,11 +542,11 @@ struct net_if_ipv4_autoconf {
* @brief Network interface IP address configuration.
*/
struct net_if_ip {
#if defined(CONFIG_NET_NATIVE_IPV6)
#if defined(CONFIG_NET_IPV6)
struct net_if_ipv6 *ipv6;
#endif /* CONFIG_NET_IPV6 */

#if defined(CONFIG_NET_NATIVE_IPV4)
#if defined(CONFIG_NET_IPV4)
struct net_if_ipv4 *ipv4;
#endif /* CONFIG_NET_IPV4 */
};
Expand Down Expand Up @@ -1827,15 +1827,33 @@ bool net_if_ipv6_router_rm(struct net_if_router *router);
*
* @return Hop limit
*/
#if defined(CONFIG_NET_NATIVE_IPV6)
uint8_t net_if_ipv6_get_hop_limit(struct net_if *iface);
#else
static inline uint8_t net_if_ipv6_get_hop_limit(struct net_if *iface)
{
ARG_UNUSED(iface);

return 0;
}
#endif /* CONFIG_NET_NATIVE_IPV6 */

/**
* @brief Set the default IPv6 hop limit of a given interface.
*
* @param iface Network interface
* @param hop_limit New hop limit
*/
#if defined(CONFIG_NET_NATIVE_IPV6)
void net_if_ipv6_set_hop_limit(struct net_if *iface, uint8_t hop_limit);
#else
static inline void net_if_ipv6_set_hop_limit(struct net_if *iface,
uint8_t hop_limit)
{
ARG_UNUSED(iface);
ARG_UNUSED(hop_limit);
}
#endif /* CONFIG_NET_NATIVE_IPV6 */

/** @cond INTERNAL_HIDDEN */

Expand All @@ -1860,15 +1878,33 @@ static inline void net_ipv6_set_hop_limit(struct net_if *iface,
*
* @return Hop limit
*/
#if defined(CONFIG_NET_NATIVE_IPV6)
uint8_t net_if_ipv6_get_mcast_hop_limit(struct net_if *iface);
#else
static inline uint8_t net_if_ipv6_get_mcast_hop_limit(struct net_if *iface)
{
ARG_UNUSED(iface);

return 0;
}
#endif /* CONFIG_NET_NATIVE_IPV6 */

/**
* @brief Set the default IPv6 multicast hop limit of a given interface.
*
* @param iface Network interface
* @param hop_limit New hop limit
*/
#if defined(CONFIG_NET_NATIVE_IPV6)
void net_if_ipv6_set_mcast_hop_limit(struct net_if *iface, uint8_t hop_limit);
#else
static inline void net_if_ipv6_set_mcast_hop_limit(struct net_if *iface,
uint8_t hop_limit)
{
ARG_UNUSED(iface);
ARG_UNUSED(hop_limit);
}
#endif /* CONFIG_NET_NATIVE_IPV6 */

/**
* @brief Set IPv6 reachable time for a given interface
Expand Down Expand Up @@ -2002,7 +2038,7 @@ static inline uint32_t net_if_ipv6_get_retrans_timer(struct net_if *iface)
* @return Pointer to IPv6 address to use, NULL if no IPv6 address
* could be found.
*/
#if defined(CONFIG_NET_NATIVE_IPV6)
#if defined(CONFIG_NET_IPV6)
const struct in6_addr *net_if_ipv6_select_src_addr(struct net_if *iface,
const struct in6_addr *dst);
#else
Expand All @@ -2029,7 +2065,7 @@ static inline const struct in6_addr *net_if_ipv6_select_src_addr(
* @return Pointer to IPv6 address to use, NULL if no IPv6 address
* could be found.
*/
#if defined(CONFIG_NET_NATIVE_IPV6)
#if defined(CONFIG_NET_IPV6)
const struct in6_addr *net_if_ipv6_select_src_addr_hint(struct net_if *iface,
const struct in6_addr *dst,
int flags);
Expand All @@ -2054,7 +2090,7 @@ static inline const struct in6_addr *net_if_ipv6_select_src_addr_hint(
* @return Pointer to network interface to use, NULL if no suitable interface
* could be found.
*/
#if defined(CONFIG_NET_NATIVE_IPV6)
#if defined(CONFIG_NET_IPV6)
struct net_if *net_if_ipv6_select_src_iface(const struct in6_addr *dst);
#else
static inline struct net_if *net_if_ipv6_select_src_iface(
Expand Down Expand Up @@ -2431,7 +2467,7 @@ bool net_if_ipv4_is_addr_bcast(struct net_if *iface,
* @return Pointer to network interface to use, NULL if no suitable interface
* could be found.
*/
#if defined(CONFIG_NET_NATIVE_IPV4)
#if defined(CONFIG_NET_IPV4)
struct net_if *net_if_ipv4_select_src_iface(const struct in_addr *dst);
#else
static inline struct net_if *net_if_ipv4_select_src_iface(
Expand All @@ -2454,7 +2490,7 @@ static inline struct net_if *net_if_ipv4_select_src_iface(
* @return Pointer to IPv4 address to use, NULL if no IPv4 address
* could be found.
*/
#if defined(CONFIG_NET_NATIVE_IPV4)
#if defined(CONFIG_NET_IPV4)
const struct in_addr *net_if_ipv4_select_src_addr(struct net_if *iface,
const struct in_addr *dst);
#else
Expand Down
1 change: 1 addition & 0 deletions samples/net/sockets/coap_server/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
LOG_MODULE_REGISTER(net_coap_service_sample, LOG_LEVEL_DBG);

#include <zephyr/net/coap_service.h>
#include <zephyr/net/mld.h>

#ifdef CONFIG_NET_IPV6
#include "net_private.h"
Expand Down
2 changes: 1 addition & 1 deletion subsys/net/ip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ zephyr_library_sources(
)

if(CONFIG_NET_OFFLOAD)
zephyr_library_sources(net_context.c net_pkt.c net_tc.c)
zephyr_library_sources(net_context.c net_pkt.c)
endif()

zephyr_library_sources_ifdef(CONFIG_NET_MGMT_EVENT net_mgmt.c)
Expand Down
2 changes: 1 addition & 1 deletion subsys/net/ip/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ config NET_IPV4_MAPPING_TO_IPV6
config NET_SHELL
bool "Network shell utilities"
select SHELL
select NET_IPV4_IGMP if NET_IPV4
select NET_IPV4_IGMP if NET_NATIVE_IPV4
select REQUIRES_FLOAT_PRINTF
help
Activate shell module that provides network commands like
Expand Down
43 changes: 23 additions & 20 deletions subsys/net/ip/Kconfig.ipv4
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ menuconfig NET_IPV4

if NET_IPV4

config NET_IF_MAX_IPV4_COUNT
int "Max number of IPv4 network interfaces in the system"
default NET_VLAN_COUNT if NET_VLAN
default 2 if NET_LOOPBACK
default 1
help
This tells how many network interfaces there will be in the system
that will have IPv4 enabled.

config NET_IF_UNICAST_IPV4_ADDR_COUNT
int "Max number of unicast IPv4 addresses per network interface"
default 2 if NET_IPV4_AUTO
default 2 if NET_LOOPBACK
default 1

config NET_IF_MCAST_IPV4_ADDR_COUNT
int "Max number of multicast IPv4 addresses per network interface"
default 2 if NET_IPV4_IGMP
default 1

if NET_NATIVE_IPV4

config NET_INITIAL_TTL
int "Initial IPv4 time to live value for unicast packets"
default 64
Expand All @@ -34,26 +56,6 @@ config NET_INITIAL_MCAST_TTL
don't leave the local network unless the application explicitly
requests it.

config NET_IF_MAX_IPV4_COUNT
int "Max number of IPv4 network interfaces in the system"
default NET_VLAN_COUNT if NET_VLAN
default 2 if NET_LOOPBACK
default 1
help
This tells how many network interfaces there will be in the system
that will have IPv4 enabled.

config NET_IF_UNICAST_IPV4_ADDR_COUNT
int "Max number of unicast IPv4 addresses per network interface"
default 2 if NET_IPV4_AUTO
default 2 if NET_LOOPBACK
default 1

config NET_IF_MCAST_IPV4_ADDR_COUNT
int "Max number of multicast IPv4 addresses per network interface"
default 2 if NET_IPV4_IGMP
default 1

config NET_IF_MCAST_IPV4_SOURCE_COUNT
int "Max number of IPv4 sources per mcast address to be included or excluded"
default 1
Expand Down Expand Up @@ -177,4 +179,5 @@ module-help = Enable debug diagnostic from IPv4 autoconf client.
source "subsys/net/Kconfig.template.log_config.net"
endif # NET_IPV4_AUTO

endif # NET_NATIVE_IPV4
endif # NET_IPV4
42 changes: 0 additions & 42 deletions subsys/net/ip/ipv6.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,48 +198,6 @@ static inline int net_ipv6_finalize(struct net_pkt *pkt,
}
#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_IPV6_MLD)
int net_ipv6_mld_join(struct net_if *iface, const struct in6_addr *addr);
#else
static inline int
net_ipv6_mld_join(struct net_if *iface, const struct in6_addr *addr)
{
ARG_UNUSED(iface);
ARG_UNUSED(addr);

return -ENOTSUP;
}
#endif /* CONFIG_NET_IPV6_MLD */

/**
* @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_IPV6_MLD)
int net_ipv6_mld_leave(struct net_if *iface, const struct in6_addr *addr);
#else
static inline int
net_ipv6_mld_leave(struct net_if *iface, const struct in6_addr *addr)
{
ARG_UNUSED(iface);
ARG_UNUSED(addr);

return -ENOTSUP;
}
#endif /* CONFIG_NET_IPV6_MLD */

/**
* @brief Send MLDv2 report message with a single entry.
*
Expand Down
1 change: 1 addition & 0 deletions subsys/net/ip/ipv6_mld.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
LOG_MODULE_DECLARE(net_ipv6, CONFIG_NET_IPV6_LOG_LEVEL);

#include <errno.h>
#include <zephyr/net/mld.h>
#include <zephyr/net/net_core.h>
#include <zephyr/net/net_pkt.h>
#include <zephyr/net/net_stats.h>
Expand Down
4 changes: 2 additions & 2 deletions subsys/net/ip/net_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -2456,7 +2456,7 @@ enum net_verdict net_context_packet_received(struct net_conn *conn,
return verdict;
}

#if defined(CONFIG_NET_UDP)
#if defined(CONFIG_NET_NATIVE_UDP)
static int recv_udp(struct net_context *context,
net_context_recv_cb_t cb,
k_timeout_t timeout,
Expand Down Expand Up @@ -2538,7 +2538,7 @@ static int recv_udp(struct net_context *context,
}
#else
#define recv_udp(...) 0
#endif /* CONFIG_NET_UDP */
#endif /* CONFIG_NET_NATIVE_UDP */

static enum net_verdict net_context_raw_packet_received(
struct net_conn *conn,
Expand Down
Loading