Skip to content

Commit

Permalink
net: Avoid compiling native network stack parts w/o NET_NATIVE
Browse files Browse the repository at this point in the history
In case NET_NATIVE is disabled, certain network stack components do not
need to be compiled. Otherwise, they could throw errors if
--no-gc-sections compiler options is enabled.

Signed-off-by: Robert Lubos <[email protected]>
  • Loading branch information
rlubos committed Sep 30, 2024
1 parent 163083e commit 10e9e4d
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 21 deletions.
36 changes: 36 additions & 0 deletions include/zephyr/net/net_if.h
Original file line number Diff line number Diff line change
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
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
50 changes: 34 additions & 16 deletions subsys/net/ip/net_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ LOG_MODULE_REGISTER(net_core, CONFIG_NET_CORE_LOG_LEVEL);

#include "net_stats.h"

#if defined(CONFIG_NET_NATIVE)
static inline enum net_verdict process_data(struct net_pkt *pkt,
bool is_loopback)
{
Expand Down Expand Up @@ -188,22 +189,6 @@ static void net_post_init(void)
#endif
}

static void init_rx_queues(void)
{
/* Starting TX side. The ordering is important here and the TX
* can only be started when RX side is ready to receive packets.
*/
net_if_init();

net_tc_rx_init();

/* This will take the interface up and start everything. */
net_if_post_init();

/* Things to init after network interface is working */
net_post_init();
}

static inline void copy_ll_addr(struct net_pkt *pkt)
{
memcpy(net_pkt_lladdr_src(pkt), net_pkt_lladdr_if(pkt),
Expand Down Expand Up @@ -571,6 +556,39 @@ static inline void l3_init(void)

NET_DBG("Network L3 init done");
}
#else /* CONFIG_NET_NATIVE */
#define l3_init(...)
#define net_post_init(...)
int net_send_data(struct net_pkt *pkt)
{
ARG_UNUSED(pkt);

return -ENOTSUP;
}
int net_recv_data(struct net_if *iface, struct net_pkt *pkt)
{
ARG_UNUSED(iface);
ARG_UNUSED(pkt);

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

static void init_rx_queues(void)
{
/* Starting TX side. The ordering is important here and the TX
* can only be started when RX side is ready to receive packets.
*/
net_if_init();

net_tc_rx_init();

/* This will take the interface up and start everything. */
net_if_post_init();

/* Things to init after network interface is working */
net_post_init();
}

static inline int services_init(void)
{
Expand Down
4 changes: 4 additions & 0 deletions subsys/net/ip/net_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ struct net_if *z_vrfy_net_if_get_by_index(int index)
#include <zephyr/syscalls/net_if_get_by_index_mrsh.c>
#endif

#if defined(CONFIG_NET_NATIVE)
static inline void net_context_send_cb(struct net_context *context,
int status)
{
Expand Down Expand Up @@ -382,6 +383,7 @@ void net_if_queue_tx(struct net_if *iface, struct net_pkt *pkt)
;
}
}
#endif /* CONFIG_NET_NATIVE */

void net_if_stats_reset(struct net_if *iface)
{
Expand Down Expand Up @@ -445,6 +447,7 @@ static inline void init_iface(struct net_if *iface)
net_ipv6_pe_init(iface);
}

#if defined(CONFIG_NET_NATIVE)
enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt)
{
const struct net_l2 *l2;
Expand Down Expand Up @@ -551,6 +554,7 @@ enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt)

return verdict;
}
#endif /* CONFIG_NET_NATIVE */

int net_if_set_link_addr_locked(struct net_if *iface,
uint8_t *addr, uint8_t len,
Expand Down
6 changes: 3 additions & 3 deletions subsys/net/ip/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -634,7 +634,7 @@ static inline uint16_t pkt_calc_chksum(struct net_pkt *pkt, uint16_t sum)
return sum;
}

#if defined(CONFIG_NET_IP)
#if defined(CONFIG_NET_NATIVE_IP)
uint16_t net_calc_chksum(struct net_pkt *pkt, uint8_t proto)
{
size_t len = 0U;
Expand Down Expand Up @@ -684,7 +684,7 @@ uint16_t net_calc_chksum(struct net_pkt *pkt, uint8_t proto)
}
#endif

#if defined(CONFIG_NET_IPV4)
#if defined(CONFIG_NET_NATIVE_IPV4)
uint16_t net_calc_chksum_ipv4(struct net_pkt *pkt)
{
uint16_t sum;
Expand All @@ -697,7 +697,7 @@ uint16_t net_calc_chksum_ipv4(struct net_pkt *pkt)

return ~sum;
}
#endif /* CONFIG_NET_IPV4 */
#endif /* CONFIG_NET_NATIVE_IPV4 */

#if defined(CONFIG_NET_IPV4_IGMP)
uint16_t net_calc_chksum_igmp(struct net_pkt *pkt)
Expand Down

0 comments on commit 10e9e4d

Please sign in to comment.