Skip to content

Commit

Permalink
net: Fix build issues with arm-clang
Browse files Browse the repository at this point in the history
The arm-clang compiler/linker does not optimize away unused function
symbols and thus will error if symbols that are referenced are not
defined.  To fix this add needed ifdef'ry.

Build various network samples that utilize ethernet but don't have
CONFIG_NET_PROMISCUOUS_MODE will get a link error for:

	Error: L6218E: Undefined symbol
	net_mgmt_NET_REQUEST_ETHERNET_SET_PROMISC_MODE
	(referred from ethernet.o).

Fix by adding ifdef protection around promisc code.

Signed-off-by: Kumar Gala <[email protected]>
  • Loading branch information
galak authored and carlescufi committed Apr 25, 2023
1 parent a01d40f commit 0090ad7
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
25 changes: 25 additions & 0 deletions include/zephyr/net/net_if.h
Original file line number Diff line number Diff line change
Expand Up @@ -2348,14 +2348,30 @@ void net_if_add_tx_timestamp(struct net_pkt *pkt);
*
* @return 0 on success, <0 if error
*/
#if defined(CONFIG_NET_PROMISCUOUS_MODE)
int net_if_set_promisc(struct net_if *iface);
#else
static inline int net_if_set_promisc(struct net_if *iface)
{
ARG_UNUSED(iface);

return -ENOTSUP;
}
#endif

/**
* @brief Set network interface into normal mode
*
* @param iface Pointer to network interface
*/
#if defined(CONFIG_NET_PROMISCUOUS_MODE)
void net_if_unset_promisc(struct net_if *iface);
#else
static inline void net_if_unset_promisc(struct net_if *iface)
{
ARG_UNUSED(iface);
}
#endif

/**
* @brief Check if promiscuous mode is set or not.
Expand All @@ -2365,7 +2381,16 @@ void net_if_unset_promisc(struct net_if *iface);
* @return True if interface is in promisc mode,
* False if interface is not in in promiscuous mode.
*/
#if defined(CONFIG_NET_PROMISCUOUS_MODE)
bool net_if_is_promisc(struct net_if *iface);
#else
static inline bool net_if_is_promisc(struct net_if *iface)
{
ARG_UNUSED(iface);

return false;
}
#endif

/**
* @brief Check if there are any pending TX network data for a given network
Expand Down
2 changes: 2 additions & 0 deletions subsys/net/ip/net_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -4316,6 +4316,7 @@ void net_if_dormant_off(struct net_if *iface)
k_mutex_unlock(&lock);
}

#if defined(CONFIG_NET_PROMISCUOUS_MODE)
static int promisc_mode_set(struct net_if *iface, bool enable)
{
enum net_l2_flags l2_flags = 0;
Expand Down Expand Up @@ -4390,6 +4391,7 @@ bool net_if_is_promisc(struct net_if *iface)

return net_if_flag_is_set(iface, NET_IF_PROMISC);
}
#endif /* CONFIG_NET_PROMISCUOUS_MODE */

#ifdef CONFIG_NET_POWER_MANAGEMENT

Expand Down
2 changes: 2 additions & 0 deletions subsys/net/l2/ethernet/ethernet.c
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,7 @@ void net_eth_set_ptp_port(struct net_if *iface, int port)
}
#endif /* CONFIG_NET_L2_PTP */

#if defined(CONFIG_NET_PROMISCUOUS_MODE)
int net_eth_promisc_mode(struct net_if *iface, bool enable)
{
struct ethernet_req_params params;
Expand All @@ -1191,6 +1192,7 @@ int net_eth_promisc_mode(struct net_if *iface, bool enable)
return net_mgmt(NET_REQUEST_ETHERNET_SET_PROMISC_MODE, iface,
&params, sizeof(struct ethernet_req_params));
}
#endif/* CONFIG_NET_PROMISCUOUS_MODE */

void ethernet_init(struct net_if *iface)
{
Expand Down
1 change: 1 addition & 0 deletions tests/net/iface/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ CONFIG_NET_MAX_CONTEXTS=4
CONFIG_NET_L2_DUMMY=y
CONFIG_NET_L2_ETHERNET=y
CONFIG_NET_L2_ETHERNET_MGMT=y
CONFIG_NET_PROMISCUOUS_MODE=y
CONFIG_NET_LOG=y
CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y
Expand Down

0 comments on commit 0090ad7

Please sign in to comment.