From 26647c7ba95dfe679923ecdf91ba99ac6d5b8acd Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 13 Nov 2024 13:40:13 +0100 Subject: [PATCH 1/3] gnrc_netif: fix packet leak with gnrc_netif_pktq & netdev_new_api (cherry picked from commit b9b8c4a68f2b119f7d49deb5a955ee2f341a57fa) --- sys/net/gnrc/netif/gnrc_netif.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sys/net/gnrc/netif/gnrc_netif.c b/sys/net/gnrc/netif/gnrc_netif.c index 66e317a0a059..eacc79b6762e 100644 --- a/sys/net/gnrc/netif/gnrc_netif.c +++ b/sys/net/gnrc/netif/gnrc_netif.c @@ -1810,7 +1810,7 @@ static void _tx_done(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt, } return; } - else { + else if (gnrc_netif_netdev_legacy_api(netif)) { /* remove previously held packet */ gnrc_pktbuf_release(pkt); return; @@ -1882,7 +1882,9 @@ static void _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt, bool push_back) } /* hold in case device was busy to not having to rewrite *all* the link * layer implementations in case `gnrc_netif_pktq` is included */ - gnrc_pktbuf_hold(pkt, 1); + if (gnrc_netif_netdev_legacy_api(netif)) { + gnrc_pktbuf_hold(pkt, 1); + } #endif /* IS_USED(MODULE_GNRC_NETIF_PKTQ) */ /* Record send in neighbor statistics if destination is unicast */ From 985cb2e593af58e66efedab397aa0723a00d29ce Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 13 Nov 2024 15:40:36 +0100 Subject: [PATCH 2/3] sys/net/gnrc/netif: don't release snip with netdev_new_api (cherry picked from commit 8eef1c117086170d7d227c3818ee9f16db0a653e) --- sys/net/gnrc/netif/gnrc_netif_raw.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/sys/net/gnrc/netif/gnrc_netif_raw.c b/sys/net/gnrc/netif/gnrc_netif_raw.c index 0ba358fd177b..f8a475be0054 100644 --- a/sys/net/gnrc/netif/gnrc_netif_raw.c +++ b/sys/net/gnrc/netif/gnrc_netif_raw.c @@ -104,13 +104,24 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif) return pkt; } +static gnrc_pktsnip_t *_skip_pkt_head(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt) +{ + if (gnrc_netif_netdev_legacy_api(netif)) { + /* we don't need the netif snip: remove it */ + return gnrc_pktbuf_remove_snip(pkt, pkt); + } + else { + /* _tx_done() will free the entire list */ + return pkt->next; + } +} + static int _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt) { int res = -ENOBUFS; if (pkt->type == GNRC_NETTYPE_NETIF) { - /* we don't need the netif snip: remove it */ - pkt = gnrc_pktbuf_remove_snip(pkt, pkt); + pkt = _skip_pkt_head(netif, pkt); } netdev_t *dev = netif->dev; From c19334547628776559c0153603cbc17c3384afaf Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 13 Nov 2024 18:55:50 +0100 Subject: [PATCH 3/3] drivers/at86rf215: properly implement netdev_new (cherry picked from commit 1629a6aa411fbc22847b8aa8ad32f77420b2d3ff) --- drivers/at86rf215/at86rf215_netdev.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/at86rf215/at86rf215_netdev.c b/drivers/at86rf215/at86rf215_netdev.c index 72d2d5127b9d..dddbb8280d6c 100644 --- a/drivers/at86rf215/at86rf215_netdev.c +++ b/drivers/at86rf215/at86rf215_netdev.c @@ -176,9 +176,11 @@ static int _send(netdev_t *netdev, const iolist_t *iolist) at86rf215_tx_exec(dev); } - /* return the number of bytes that were actually loaded into the frame - * buffer/send out */ - return (int)len; + /* store successfully sent number of bytes */ + dev->tx_frame_len = len; + + /* netdev_new just returns 0 on success */ + return 0; } static int _confirm_send(netdev_t *netdev, void *info)