Skip to content

Commit 135cf0e

Browse files
committed
[nrf fromtree] net: Avoid compiling native network stack parts w/o NET_NATIVE
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]> (cherry picked from commit 2e1d896)
1 parent d7ac5b1 commit 135cf0e

File tree

5 files changed

+79
-21
lines changed

5 files changed

+79
-21
lines changed

include/zephyr/net/net_if.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1827,15 +1827,33 @@ bool net_if_ipv6_router_rm(struct net_if_router *router);
18271827
*
18281828
* @return Hop limit
18291829
*/
1830+
#if defined(CONFIG_NET_NATIVE_IPV6)
18301831
uint8_t net_if_ipv6_get_hop_limit(struct net_if *iface);
1832+
#else
1833+
static inline uint8_t net_if_ipv6_get_hop_limit(struct net_if *iface)
1834+
{
1835+
ARG_UNUSED(iface);
1836+
1837+
return 0;
1838+
}
1839+
#endif /* CONFIG_NET_NATIVE_IPV6 */
18311840

18321841
/**
18331842
* @brief Set the default IPv6 hop limit of a given interface.
18341843
*
18351844
* @param iface Network interface
18361845
* @param hop_limit New hop limit
18371846
*/
1847+
#if defined(CONFIG_NET_NATIVE_IPV6)
18381848
void net_if_ipv6_set_hop_limit(struct net_if *iface, uint8_t hop_limit);
1849+
#else
1850+
static inline void net_if_ipv6_set_hop_limit(struct net_if *iface,
1851+
uint8_t hop_limit)
1852+
{
1853+
ARG_UNUSED(iface);
1854+
ARG_UNUSED(hop_limit);
1855+
}
1856+
#endif /* CONFIG_NET_NATIVE_IPV6 */
18391857

18401858
/** @cond INTERNAL_HIDDEN */
18411859

@@ -1860,15 +1878,33 @@ static inline void net_ipv6_set_hop_limit(struct net_if *iface,
18601878
*
18611879
* @return Hop limit
18621880
*/
1881+
#if defined(CONFIG_NET_NATIVE_IPV6)
18631882
uint8_t net_if_ipv6_get_mcast_hop_limit(struct net_if *iface);
1883+
#else
1884+
static inline uint8_t net_if_ipv6_get_mcast_hop_limit(struct net_if *iface)
1885+
{
1886+
ARG_UNUSED(iface);
1887+
1888+
return 0;
1889+
}
1890+
#endif /* CONFIG_NET_NATIVE_IPV6 */
18641891

18651892
/**
18661893
* @brief Set the default IPv6 multicast hop limit of a given interface.
18671894
*
18681895
* @param iface Network interface
18691896
* @param hop_limit New hop limit
18701897
*/
1898+
#if defined(CONFIG_NET_NATIVE_IPV6)
18711899
void net_if_ipv6_set_mcast_hop_limit(struct net_if *iface, uint8_t hop_limit);
1900+
#else
1901+
static inline void net_if_ipv6_set_mcast_hop_limit(struct net_if *iface,
1902+
uint8_t hop_limit)
1903+
{
1904+
ARG_UNUSED(iface);
1905+
ARG_UNUSED(hop_limit);
1906+
}
1907+
#endif /* CONFIG_NET_NATIVE_IPV6 */
18721908

18731909
/**
18741910
* @brief Set IPv6 reachable time for a given interface

subsys/net/ip/net_context.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,7 +2456,7 @@ enum net_verdict net_context_packet_received(struct net_conn *conn,
24562456
return verdict;
24572457
}
24582458

2459-
#if defined(CONFIG_NET_UDP)
2459+
#if defined(CONFIG_NET_NATIVE_UDP)
24602460
static int recv_udp(struct net_context *context,
24612461
net_context_recv_cb_t cb,
24622462
k_timeout_t timeout,
@@ -2538,7 +2538,7 @@ static int recv_udp(struct net_context *context,
25382538
}
25392539
#else
25402540
#define recv_udp(...) 0
2541-
#endif /* CONFIG_NET_UDP */
2541+
#endif /* CONFIG_NET_NATIVE_UDP */
25422542

25432543
static enum net_verdict net_context_raw_packet_received(
25442544
struct net_conn *conn,

subsys/net/ip/net_core.c

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ LOG_MODULE_REGISTER(net_core, CONFIG_NET_CORE_LOG_LEVEL);
6060

6161
#include "net_stats.h"
6262

63+
#if defined(CONFIG_NET_NATIVE)
6364
static inline enum net_verdict process_data(struct net_pkt *pkt,
6465
bool is_loopback)
6566
{
@@ -188,22 +189,6 @@ static void net_post_init(void)
188189
#endif
189190
}
190191

191-
static void init_rx_queues(void)
192-
{
193-
/* Starting TX side. The ordering is important here and the TX
194-
* can only be started when RX side is ready to receive packets.
195-
*/
196-
net_if_init();
197-
198-
net_tc_rx_init();
199-
200-
/* This will take the interface up and start everything. */
201-
net_if_post_init();
202-
203-
/* Things to init after network interface is working */
204-
net_post_init();
205-
}
206-
207192
static inline void copy_ll_addr(struct net_pkt *pkt)
208193
{
209194
memcpy(net_pkt_lladdr_src(pkt), net_pkt_lladdr_if(pkt),
@@ -571,6 +556,39 @@ static inline void l3_init(void)
571556

572557
NET_DBG("Network L3 init done");
573558
}
559+
#else /* CONFIG_NET_NATIVE */
560+
#define l3_init(...)
561+
#define net_post_init(...)
562+
int net_send_data(struct net_pkt *pkt)
563+
{
564+
ARG_UNUSED(pkt);
565+
566+
return -ENOTSUP;
567+
}
568+
int net_recv_data(struct net_if *iface, struct net_pkt *pkt)
569+
{
570+
ARG_UNUSED(iface);
571+
ARG_UNUSED(pkt);
572+
573+
return -ENOTSUP;
574+
}
575+
#endif /* CONFIG_NET_NATIVE */
576+
577+
static void init_rx_queues(void)
578+
{
579+
/* Starting TX side. The ordering is important here and the TX
580+
* can only be started when RX side is ready to receive packets.
581+
*/
582+
net_if_init();
583+
584+
net_tc_rx_init();
585+
586+
/* This will take the interface up and start everything. */
587+
net_if_post_init();
588+
589+
/* Things to init after network interface is working */
590+
net_post_init();
591+
}
574592

575593
static inline int services_init(void)
576594
{

subsys/net/ip/net_if.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ struct net_if *z_vrfy_net_if_get_by_index(int index)
174174
#include <zephyr/syscalls/net_if_get_by_index_mrsh.c>
175175
#endif
176176

177+
#if defined(CONFIG_NET_NATIVE)
177178
static inline void net_context_send_cb(struct net_context *context,
178179
int status)
179180
{
@@ -382,6 +383,7 @@ void net_if_queue_tx(struct net_if *iface, struct net_pkt *pkt)
382383
;
383384
}
384385
}
386+
#endif /* CONFIG_NET_NATIVE */
385387

386388
void net_if_stats_reset(struct net_if *iface)
387389
{
@@ -445,6 +447,7 @@ static inline void init_iface(struct net_if *iface)
445447
net_ipv6_pe_init(iface);
446448
}
447449

450+
#if defined(CONFIG_NET_NATIVE)
448451
enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt)
449452
{
450453
const struct net_l2 *l2;
@@ -551,6 +554,7 @@ enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt)
551554

552555
return verdict;
553556
}
557+
#endif /* CONFIG_NET_NATIVE */
554558

555559
int net_if_set_link_addr_locked(struct net_if *iface,
556560
uint8_t *addr, uint8_t len,

subsys/net/ip/utils.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ static inline uint16_t pkt_calc_chksum(struct net_pkt *pkt, uint16_t sum)
634634
return sum;
635635
}
636636

637-
#if defined(CONFIG_NET_IP)
637+
#if defined(CONFIG_NET_NATIVE_IP)
638638
uint16_t net_calc_chksum(struct net_pkt *pkt, uint8_t proto)
639639
{
640640
size_t len = 0U;
@@ -684,7 +684,7 @@ uint16_t net_calc_chksum(struct net_pkt *pkt, uint8_t proto)
684684
}
685685
#endif
686686

687-
#if defined(CONFIG_NET_IPV4)
687+
#if defined(CONFIG_NET_NATIVE_IPV4)
688688
uint16_t net_calc_chksum_ipv4(struct net_pkt *pkt)
689689
{
690690
uint16_t sum;
@@ -697,7 +697,7 @@ uint16_t net_calc_chksum_ipv4(struct net_pkt *pkt)
697697

698698
return ~sum;
699699
}
700-
#endif /* CONFIG_NET_IPV4 */
700+
#endif /* CONFIG_NET_NATIVE_IPV4 */
701701

702702
#if defined(CONFIG_NET_IPV4_IGMP)
703703
uint16_t net_calc_chksum_igmp(struct net_pkt *pkt)

0 commit comments

Comments
 (0)