Skip to content

[Backport v3.7-branch] net: net_if: fix net_if_send_data for offloaded ifaces #76716

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 6, 2024
Merged
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
23 changes: 19 additions & 4 deletions subsys/net/ip/net_if.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ static inline void init_iface(struct net_if *iface)

enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt)
{
const struct net_l2 *l2;
struct net_context *context = net_pkt_context(pkt);
struct net_linkaddr *dst = net_pkt_lladdr_dst(pkt);
enum net_verdict verdict = NET_OK;
Expand All @@ -455,10 +456,24 @@ enum net_verdict net_if_send_data(struct net_if *iface, struct net_pkt *pkt)
goto done;
}

if (IS_ENABLED(CONFIG_NET_OFFLOAD) && !net_if_l2(iface)) {
NET_WARN("no l2 for iface %p, discard pkt", iface);
verdict = NET_DROP;
goto done;
/* The check for CONFIG_NET_*_OFFLOAD here is an optimization;
* This is currently the only way for net_if_l2 to be NULL or missing send().
*/
if (IS_ENABLED(CONFIG_NET_OFFLOAD) || IS_ENABLED(CONFIG_NET_SOCKETS_OFFLOAD)) {
l2 = net_if_l2(iface);
if (l2 == NULL) {
/* Offloaded ifaces may choose not to use an L2 at all. */
NET_WARN("no l2 for iface %p, discard pkt", iface);
verdict = NET_DROP;
goto done;
} else if (l2->send == NULL) {
/* Or, their chosen L2 (for example, OFFLOADED_NETDEV_L2)
* might simply not implement send.
*/
NET_WARN("l2 for iface %p cannot send, discard pkt", iface);
verdict = NET_DROP;
goto done;
}
}

/* If the ll address is not set at all, then we must set
Expand Down