Skip to content

Commit 7d5e943

Browse files
authored
Merge pull request #21855 from Lukas-Luger/pr/legacy-tx_sync
sys/net/gnrc/netif: hold packets after tx_sync split
2 parents 0a2e164 + bae016a commit 7d5e943

File tree

4 files changed

+115
-5
lines changed

4 files changed

+115
-5
lines changed

sys/net/gnrc/netif/gnrc_netif.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1922,11 +1922,6 @@ static void _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt, bool push_back)
19221922
/* try to send anyway */
19231923
}
19241924
}
1925-
/* hold in case device was busy to not having to rewrite *all* the link
1926-
* layer implementations in case `gnrc_netif_pktq` is included */
1927-
if (gnrc_netif_netdev_legacy_api(netif)) {
1928-
gnrc_pktbuf_hold(pkt, 1);
1929-
}
19301925
#endif /* IS_USED(MODULE_GNRC_NETIF_PKTQ) */
19311926

19321927
/* Record send in neighbor statistics if destination is unicast */
@@ -1947,6 +1942,13 @@ static void _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt, bool push_back)
19471942
/* Split off the TX sync snip */
19481943
gnrc_pktsnip_t *tx_sync = IS_USED(MODULE_GNRC_TX_SYNC)
19491944
? gnrc_tx_sync_split(pkt) : NULL;
1945+
#if IS_USED(MODULE_GNRC_NETIF_PKTQ)
1946+
/* hold in case device was busy to not having to rewrite *all* the link
1947+
* layer implementations in case `gnrc_netif_pktq` is included */
1948+
if (gnrc_netif_netdev_legacy_api(netif)) {
1949+
gnrc_pktbuf_hold(pkt, 1);
1950+
}
1951+
#endif /* IS_USED(MODULE_GNRC_NETIF_PKTQ) */
19501952
int res = netif->ops->send(netif, pkt);
19511953

19521954
/* For legacy netdevs (no confirm_send) TX is blocking, thus it is always
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
include ../Makefile.net_common
2+
3+
USEMODULE += netdev_default
4+
USEMODULE += auto_init_gnrc_netif
5+
USEMODULE += gnrc_tx_sync
6+
USEMODULE += gnrc_netif_pktq
7+
USEMODULE += nrfmin
8+
USEMODULE += ztimer_sec
9+
10+
include $(RIOTBASE)/Makefile.include
11+
12+
CFLAGS += -DDEBUG_ASSERT_VERBOSE=1
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright (C) 2025 Technische Universität Dresden
3+
*
4+
* This file is subject to the terms and conditions of the GNU Lesser
5+
* General Public License v2.1. See the file LICENSE in the top level
6+
* directory for more details.
7+
*/
8+
9+
/**
10+
* @{
11+
*
12+
* @file
13+
* @brief Text application for gnrc_legacy_tx_sync
14+
*
15+
* @author Lukas Luger <[email protected]>
16+
*
17+
* @}
18+
*/
19+
20+
#include <stdio.h>
21+
22+
#include "net/af.h"
23+
#include "net/gnrc/pktbuf.h"
24+
#include "net/gnrc/tx_sync.h"
25+
#include "net/gnrc.h"
26+
#include "ztimer.h"
27+
#include "thread.h"
28+
29+
static const char test_msg[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTU"
30+
"VWXYZ0123456789.,:;!?@#$%^&*()[]{}-_=+/<>`~\'\""
31+
"\\";
32+
33+
void print_failed(void *arg)
34+
{
35+
(void)arg;
36+
puts("TEST FAILED");
37+
}
38+
39+
int main(void)
40+
{
41+
puts(
42+
"Test application for gnrc_legacy_tx_sync\n"
43+
"========================================\n"
44+
"\n"
45+
"This application sends a single message over the nrfmin netdev.\n"
46+
"Other legacy netdevs can be used by changing the board and using\n"
47+
"a different driver. Note: RIOT will sometimes choose the\n"
48+
"netdev_ieee802154_submac as default driver which is not legacy.\n"
49+
"tx_sync will only fail if gnrc_netif_pktq is used with a legacy driver.\n"
50+
"If tx_sync does not finish in one second, the test will fail.\n"
51+
);
52+
53+
/* Preparing the gnrc message */
54+
gnrc_netif_t *netif = gnrc_netif_iter(NULL);
55+
gnrc_pktsnip_t *pkt = gnrc_pktbuf_add(NULL, test_msg, sizeof(test_msg),
56+
GNRC_NETTYPE_UNDEF);
57+
gnrc_tx_sync_t tx_sync;
58+
gnrc_tx_sync_append(pkt, &tx_sync);
59+
60+
/* Set timeout message in case tx sync fails */
61+
ztimer_t timer = {
62+
.callback = print_failed,
63+
.arg = NULL,
64+
};
65+
ztimer_set(ZTIMER_SEC, &timer, 1);
66+
67+
/* Sending and waiting */
68+
gnrc_netapi_send(netif->pid, pkt);
69+
gnrc_tx_sync(&tx_sync);
70+
71+
/* Cancel error message and print success message */
72+
ztimer_remove(ZTIMER_SEC, &timer);
73+
puts("TEST PASSED");
74+
75+
return 0;
76+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env python3
2+
3+
# Copyright (C) 2025 Technische Universität Dresden
4+
#
5+
# This file is subject to the terms and conditions of the GNU Lesser
6+
# General Public License v2.1. See the file LICENSE in the top level
7+
# directory for more details.
8+
9+
# @author Lukas Luger <[email protected]>
10+
11+
import sys
12+
from testrunner import run
13+
14+
15+
def testfunc(child):
16+
child.expect("TEST PASSED", timeout=2)
17+
18+
19+
if __name__ == "__main__":
20+
sys.exit(run(testfunc))

0 commit comments

Comments
 (0)