net: iface: Make sure we access valid ll address

It is possible that net_pkt will disappear while we are sending
it, so save link address if we need that information.

Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
Jukka Rissanen 2020-03-11 17:19:02 +02:00
commit 907dede475

View file

@ -147,7 +147,10 @@ static inline void net_context_send_cb(struct net_context *context,
static bool net_if_tx(struct net_if *iface, struct net_pkt *pkt)
{
struct net_linkaddr *dst;
struct net_linkaddr ll_dst = {
.addr = NULL
};
struct net_linkaddr_storage ll_dst_storage;
struct net_context *context;
int status;
@ -164,7 +167,20 @@ static bool net_if_tx(struct net_if *iface, struct net_pkt *pkt)
debug_check_packet(pkt);
dst = net_pkt_lladdr_dst(pkt);
/* If there're any link callbacks, with such a callback receiving
* a destination address, copy that address out of packet, just in
* case packet is freed before callback is called.
*/
if (!sys_slist_is_empty(&link_callbacks)) {
if (net_linkaddr_set(&ll_dst_storage,
net_pkt_lladdr_dst(pkt)->addr,
net_pkt_lladdr_dst(pkt)->len) == 0) {
ll_dst.addr = ll_dst_storage.addr;
ll_dst.len = ll_dst_storage.len;
ll_dst.type = net_pkt_lladdr_dst(pkt)->type;
}
}
context = net_pkt_context(pkt);
if (net_if_flag_is_set(iface, NET_IF_UP)) {
@ -235,8 +251,8 @@ static bool net_if_tx(struct net_if *iface, struct net_pkt *pkt)
}
}
if (dst->addr) {
net_if_call_link_cb(iface, dst, status);
if (ll_dst.addr) {
net_if_call_link_cb(iface, &ll_dst, status);
}
return true;