Skip to content

Commit

Permalink
net: Add CONFIG_NET_NATIVE option for selecting native IP
Browse files Browse the repository at this point in the history
Allow user to disable native IP stack and use offloaded IP
stack instead. It is also possible to enable both at the same
time if needed.

Fixes zephyrproject-rtos#18105

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
  • Loading branch information
jukkar committed Sep 10, 2019
1 parent 466f91a commit 5398673
Show file tree
Hide file tree
Showing 26 changed files with 560 additions and 188 deletions.
5 changes: 4 additions & 1 deletion drivers/net/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# SPDX-License-Identifier: Apache-2.0

zephyr_sources_ifdef(CONFIG_SLIP slip.c)
zephyr_sources_ifdef(CONFIG_NET_LOOPBACK loopback.c)

if(CONFIG_NET_NATIVE)
zephyr_sources_ifdef(CONFIG_SLIP slip.c)
zephyr_sources_ifdef(CONFIG_NET_PPP ppp.c)
endif()
2 changes: 2 additions & 0 deletions drivers/net/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
menuconfig NET_PPP
bool "Point-to-point (PPP) UART based driver"
depends on NET_L2_PPP
depends on NET_NATIVE
select UART_PIPE
select UART_INTERRUPT_DRIVEN

Expand Down Expand Up @@ -73,6 +74,7 @@ endif # NET_PPP
menuconfig SLIP
bool "SLIP driver"
depends on (!QEMU_TARGET || NET_QEMU_SLIP)
depends on NET_NATIVE
select UART_PIPE
select UART_INTERRUPT_DRIVEN

Expand Down
98 changes: 70 additions & 28 deletions include/net/net_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
#include <net/net_stats.h>
#include <net/net_timeout.h>

#if defined(CONFIG_NET_DHCPV4)
#if defined(CONFIG_NET_DHCPV4) && defined(CONFIG_NET_NATIVE_IPV4)
#include <net/dhcpv4.h>
#endif
#if defined(CONFIG_NET_IPV4_AUTO)
#if defined(CONFIG_NET_IPV4_AUTO) && defined(CONFIG_NET_NATIVE_IPV4)
#include <net/ipv4_autoconf.h>
#endif

Expand All @@ -50,11 +50,11 @@ struct net_if_addr {
/** IP address */
struct net_addr address;

#if defined(CONFIG_NET_IPV6)
#if defined(CONFIG_NET_NATIVE_IPV6)
struct net_timeout lifetime;
#endif

#if defined(CONFIG_NET_IPV6_DAD)
#if defined(CONFIG_NET_IPV6_DAD) && defined(CONFIG_NET_NATIVE_IPV6)
/** Duplicate address detection (DAD) timer */
sys_snode_t dad_node;
u32_t dad_start;
Expand All @@ -65,7 +65,7 @@ struct net_if_addr {
/** What is the current state of the address */
enum net_addr_state addr_state;

#if defined(CONFIG_NET_IPV6_DAD)
#if defined(CONFIG_NET_IPV6_DAD) && defined(CONFIG_NET_NATIVE_IPV6)
/** How many times we have done DAD */
u8_t dad_count;
#endif
Expand Down Expand Up @@ -205,7 +205,7 @@ struct net_offload;
#endif /* CONFIG_NET_OFFLOAD */

/** @cond INTERNAL_HIDDEN */
#if defined(CONFIG_NET_IPV6)
#if defined(CONFIG_NET_NATIVE_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 @@ -234,7 +234,7 @@ struct net_if_ipv6 {

/** Retransmit timer (RFC 4861, page 52) */
u32_t retrans_timer;
#if defined(CONFIG_NET_IPV6_ND)
#if defined(CONFIG_NET_IPV6_ND) && defined(CONFIG_NET_NATIVE_IPV6)
/** Router solicitation timer node */
sys_snode_t rs_node;

Expand All @@ -250,7 +250,7 @@ struct net_if_ipv6 {
};

/** @cond INTERNAL_HIDDEN */
#if defined(CONFIG_NET_IPV4)
#if defined(CONFIG_NET_NATIVE_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 All @@ -276,7 +276,7 @@ struct net_if_ipv4 {
u8_t ttl;
};

#if defined(CONFIG_NET_DHCPV4)
#if defined(CONFIG_NET_DHCPV4) && defined(CONFIG_NET_NATIVE_IPV4)
struct net_if_dhcpv4 {
/** Used for timer lists */
sys_snode_t node;
Expand Down Expand Up @@ -315,7 +315,7 @@ struct net_if_dhcpv4 {
};
#endif /* CONFIG_NET_DHCPV4 */

#if defined(CONFIG_NET_IPV4_AUTO)
#if defined(CONFIG_NET_IPV4_AUTO) && defined(CONFIG_NET_NATIVE_IPV4)
struct net_if_ipv4_autoconf {
/** Used for timer lists */
sys_snode_t node;
Expand Down Expand Up @@ -359,11 +359,11 @@ struct net_if_ipv4_autoconf {
* @brief Network interface IP address configuration.
*/
struct net_if_ip {
#if defined(CONFIG_NET_IPV6)
#if defined(CONFIG_NET_NATIVE_IPV6)
struct net_if_ipv6 *ipv6;
#endif /* CONFIG_NET_IPV6 */

#if defined(CONFIG_NET_IPV4)
#if defined(CONFIG_NET_NATIVE_IPV4)
struct net_if_ipv4 *ipv4;
#endif /* CONFIG_NET_IPV4 */
};
Expand All @@ -375,11 +375,11 @@ struct net_if_config {
/** IP address configuration setting */
struct net_if_ip ip;

#if defined(CONFIG_NET_DHCPV4)
#if defined(CONFIG_NET_DHCPV4) && defined(CONFIG_NET_NATIVE_IPV4)
struct net_if_dhcpv4 dhcpv4;
#endif /* CONFIG_NET_DHCPV4 */

#if defined(CONFIG_NET_IPV4_AUTO)
#if defined(CONFIG_NET_IPV4_AUTO) && defined(CONFIG_NET_NATIVE_IPV4)
struct net_if_ipv4_autoconf ipv4auto;
#endif /* CONFIG_NET_IPV4_AUTO */
};
Expand Down Expand Up @@ -653,7 +653,7 @@ static inline struct net_if_config *net_if_get_config(struct net_if *iface)
*
* @param iface Pointer to a network interface structure
*/
#if defined(CONFIG_NET_IPV6_DAD)
#if defined(CONFIG_NET_IPV6_DAD) && defined(CONFIG_NET_NATIVE_IPV6)
void net_if_start_dad(struct net_if *iface);
#else
static inline void net_if_start_dad(struct net_if *iface)
Expand All @@ -675,7 +675,7 @@ void net_if_start_rs(struct net_if *iface);
*
* @param iface Pointer to a network interface structure
*/
#if defined(CONFIG_NET_IPV6_ND)
#if defined(CONFIG_NET_IPV6_ND) && defined(CONFIG_NET_NATIVE_IPV6)
void net_if_stop_rs(struct net_if *iface);
#else
static inline void net_if_stop_rs(struct net_if *iface)
Expand Down Expand Up @@ -1166,7 +1166,7 @@ bool net_if_ipv6_addr_onlink(struct net_if **iface, struct in6_addr *addr);
*
* @return pointer to the IPv6 address, or NULL if none
*/
#if defined(CONFIG_NET_IPV6)
#if defined(CONFIG_NET_NATIVE_IPV6)
static inline struct in6_addr *net_if_router_ipv6(struct net_if_router *router)
{
return &router->address.in6_addr;
Expand Down Expand Up @@ -1247,7 +1247,7 @@ bool net_if_ipv6_router_rm(struct net_if_router *router);
*/
static inline u8_t net_if_ipv6_get_hop_limit(struct net_if *iface)
{
#if defined(CONFIG_NET_IPV6)
#if defined(CONFIG_NET_NATIVE_IPV6)
if (!iface->config.ip.ipv6) {
return 0;
}
Expand All @@ -1267,7 +1267,7 @@ static inline u8_t net_if_ipv6_get_hop_limit(struct net_if *iface)
static inline void net_ipv6_set_hop_limit(struct net_if *iface,
u8_t hop_limit)
{
#if defined(CONFIG_NET_IPV6)
#if defined(CONFIG_NET_NATIVE_IPV6)
if (!iface->config.ip.ipv6) {
return;
}
Expand All @@ -1285,7 +1285,7 @@ static inline void net_ipv6_set_hop_limit(struct net_if *iface,
static inline void net_if_ipv6_set_base_reachable_time(struct net_if *iface,
u32_t reachable_time)
{
#if defined(CONFIG_NET_IPV6)
#if defined(CONFIG_NET_NATIVE_IPV6)
if (!iface->config.ip.ipv6) {
return;
}
Expand All @@ -1303,7 +1303,7 @@ static inline void net_if_ipv6_set_base_reachable_time(struct net_if *iface,
*/
static inline u32_t net_if_ipv6_get_reachable_time(struct net_if *iface)
{
#if defined(CONFIG_NET_IPV6)
#if defined(CONFIG_NET_NATIVE_IPV6)
if (!iface->config.ip.ipv6) {
return 0;
}
Expand Down Expand Up @@ -1331,7 +1331,7 @@ u32_t net_if_ipv6_calc_reachable_time(struct net_if_ipv6 *ipv6);
*/
static inline void net_if_ipv6_set_reachable_time(struct net_if_ipv6 *ipv6)
{
#if defined(CONFIG_NET_IPV6)
#if defined(CONFIG_NET_NATIVE_IPV6)
ipv6->reachable_time = net_if_ipv6_calc_reachable_time(ipv6);
#endif
}
Expand All @@ -1345,7 +1345,7 @@ static inline void net_if_ipv6_set_reachable_time(struct net_if_ipv6 *ipv6)
static inline void net_if_ipv6_set_retrans_timer(struct net_if *iface,
u32_t retrans_timer)
{
#if defined(CONFIG_NET_IPV6)
#if defined(CONFIG_NET_NATIVE_IPV6)
if (!iface->config.ip.ipv6) {
return;
}
Expand All @@ -1363,7 +1363,7 @@ static inline void net_if_ipv6_set_retrans_timer(struct net_if *iface,
*/
static inline u32_t net_if_ipv6_get_retrans_timer(struct net_if *iface)
{
#if defined(CONFIG_NET_IPV6)
#if defined(CONFIG_NET_NATIVE_IPV6)
if (!iface->config.ip.ipv6) {
return 0;
}
Expand All @@ -1385,8 +1385,19 @@ static inline u32_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)
const struct in6_addr *net_if_ipv6_select_src_addr(struct net_if *iface,
const struct in6_addr *dst);
#else
static inline const struct in6_addr *net_if_ipv6_select_src_addr(
struct net_if *iface, const struct in6_addr *dst)
{
ARG_UNUSED(iface);
ARG_UNUSED(dst);

return NULL;
}
#endif

/**
* @brief Get a network interface that should be used when sending
Expand All @@ -1397,7 +1408,17 @@ const struct in6_addr *net_if_ipv6_select_src_addr(struct net_if *iface,
* @return Pointer to network interface to use, NULL if no suitable interface
* could be found.
*/
#if defined(CONFIG_NET_NATIVE_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(
const struct in6_addr *dst)
{
ARG_UNUSED(dst);

return NULL;
}
#endif

/**
* @brief Get a IPv6 link local address in a given state.
Expand Down Expand Up @@ -1477,7 +1498,7 @@ int net_if_config_ipv4_put(struct net_if *iface);
*/
static inline u8_t net_if_ipv4_get_ttl(struct net_if *iface)
{
#if defined(CONFIG_NET_IPV4)
#if defined(CONFIG_NET_NATIVE_IPV4)
if (!iface->config.ip.ipv4) {
return 0;
}
Expand Down Expand Up @@ -1600,7 +1621,7 @@ struct net_if_mcast_addr *net_if_ipv4_maddr_lookup(const struct in_addr *addr,
*
* @return pointer to the IPv4 address, or NULL if none
*/
#if defined(CONFIG_NET_IPV4)
#if defined(CONFIG_NET_NATIVE_IPV4)
static inline struct in_addr *net_if_router_ipv4(struct net_if_router *router)
{
return &router->address.in_addr;
Expand Down Expand Up @@ -1694,7 +1715,17 @@ 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)
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(
const struct in_addr *dst)
{
ARG_UNUSED(dst);

return NULL;
}
#endif

/**
* @brief Get a IPv4 source address that should be used when sending
Expand All @@ -1707,8 +1738,19 @@ struct net_if *net_if_ipv4_select_src_iface(const struct in_addr *dst);
* @return Pointer to IPv4 address to use, NULL if no IPv4 address
* could be found.
*/
#if defined(CONFIG_NET_NATIVE_IPV4)
const struct in_addr *net_if_ipv4_select_src_addr(struct net_if *iface,
const struct in_addr *dst);
#else
static inline const struct in_addr *net_if_ipv4_select_src_addr(
struct net_if *iface, const struct in_addr *dst)
{
ARG_UNUSED(iface);
ARG_UNUSED(dst);

return NULL;
}
#endif

/**
* @brief Get a IPv4 link local address in a given state.
Expand Down Expand Up @@ -1931,7 +1973,7 @@ static inline bool net_if_is_up(struct net_if *iface)
*/
int net_if_down(struct net_if *iface);

#if defined(CONFIG_NET_PKT_TIMESTAMP)
#if defined(CONFIG_NET_PKT_TIMESTAMP) && defined(CONFIG_NET_NATIVE)
/**
* @typedef net_if_timestamp_callback_t
* @brief Define callback that is called after a network packet
Expand Down Expand Up @@ -2037,7 +2079,7 @@ struct net_if_api {
void (*init)(struct net_if *iface);
};

#if defined(CONFIG_NET_DHCPV4)
#if defined(CONFIG_NET_DHCPV4) && defined(CONFIG_NET_NATIVE_IPV4)
#define NET_IF_DHCPV4_INIT .dhcpv4.state = NET_DHCPV4_DISABLED,
#else
#define NET_IF_DHCPV4_INIT
Expand Down
11 changes: 11 additions & 0 deletions include/net/net_ip.h
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,7 @@ extern bool net_if_ipv4_is_addr_bcast(struct net_if *iface,
*
* @return True if address is a broadcast address, false otherwise.
*/
#if defined(CONFIG_NET_NATIVE_IPV4)
static inline bool net_ipv4_is_addr_bcast(struct net_if *iface,
const struct in_addr *addr)
{
Expand All @@ -809,6 +810,16 @@ static inline bool net_ipv4_is_addr_bcast(struct net_if *iface,

return net_if_ipv4_is_addr_bcast(iface, addr);
}
#else
static inline bool net_ipv4_is_addr_bcast(struct net_if *iface,
const struct in_addr *addr)
{
ARG_UNUSED(iface);
ARG_UNUSED(addr);

return false;
}
#endif

extern struct net_if_addr *net_if_ipv4_addr_lookup(const struct in_addr *addr,
struct net_if **iface);
Expand Down
Loading

0 comments on commit 5398673

Please sign in to comment.