Merge pull request #11401 from miri64/tests/enh/i11398-testcase
tests: provide test case for malformed IEEE 802.15.4 packets
This commit is contained in:
commit
ac9e80cfd0
15
tests/gnrc_netif_ieee802154/Makefile
Normal file
15
tests/gnrc_netif_ieee802154/Makefile
Normal file
@ -0,0 +1,15 @@
|
||||
BOARD_WHITELIST = native
|
||||
|
||||
include ../Makefile.tests_common
|
||||
|
||||
TERMFLAGS ?= -z "0.0.0.0:17755,localhost:17754"
|
||||
|
||||
USEMODULE += socket_zep
|
||||
USEMODULE += auto_init_gnrc_netif
|
||||
USEMODULE += gnrc
|
||||
USEMODULE += gnrc_netif_ieee802154
|
||||
USEMODULE += gnrc_pktdump
|
||||
|
||||
TEST_ON_CI_WHITELIST += native
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
11
tests/gnrc_netif_ieee802154/README.md
Normal file
11
tests/gnrc_netif_ieee802154/README.md
Normal file
@ -0,0 +1,11 @@
|
||||
Tests for `gnrc_netif_ieee802154`
|
||||
=================================
|
||||
|
||||
Motivation for this test was a reproducible test case for issue [#11398].
|
||||
Just run `make all test` for `native` to do run it.
|
||||
|
||||
The test may be extended with other test cases for the `gnrc_netif_ieee802154`
|
||||
module in the future.
|
||||
|
||||
|
||||
[#11398]: https://github.com/RIOT-OS/RIOT/issues/11398
|
||||
38
tests/gnrc_netif_ieee802154/main.c
Normal file
38
tests/gnrc_netif_ieee802154/main.c
Normal file
@ -0,0 +1,38 @@
|
||||
/*
|
||||
* Copyright (C) 2019 Freie Universität Berlin
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @author Martine Lenders <m.lenders@fu-berlin.de>
|
||||
*/
|
||||
|
||||
#include "net/gnrc.h"
|
||||
#include "net/gnrc/netif.h"
|
||||
#include "net/gnrc/pktdump.h"
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
char addr_str[GNRC_NETIF_L2ADDR_MAXLEN * 3];
|
||||
gnrc_netif_t *netif = gnrc_netif_iter(NULL);
|
||||
|
||||
printf("l2_addr: %s\n", gnrc_netif_addr_to_str(netif->l2addr,
|
||||
netif->l2addr_len,
|
||||
addr_str));
|
||||
|
||||
gnrc_netreg_entry_t dump = GNRC_NETREG_ENTRY_INIT_PID(
|
||||
GNRC_NETREG_DEMUX_CTX_ALL,
|
||||
gnrc_pktdump_pid
|
||||
);
|
||||
gnrc_netreg_register(GNRC_NETTYPE_UNDEF, &dump);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
60
tests/gnrc_netif_ieee802154/tests/01-run.py
Executable file
60
tests/gnrc_netif_ieee802154/tests/01-run.py
Executable file
@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2019 Freie Universität Berlin
|
||||
#
|
||||
# This file is subject to the terms and conditions of the GNU Lesser
|
||||
# General Public License v2.1. See the file LICENSE in the top level
|
||||
# directory for more details.
|
||||
|
||||
import sys
|
||||
import socket
|
||||
from testrunner import run
|
||||
from pexpect import EOF, TIMEOUT
|
||||
from scapy.all import ZEP2, Dot15d4Data, Dot15d4FCS, raw
|
||||
|
||||
ZEP_V2_VERSION = 2
|
||||
ZEP_V2_TYPE_DATA = 1
|
||||
|
||||
|
||||
def testfunc(child):
|
||||
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
|
||||
s.bind(("", 17754))
|
||||
child.expect("l2_addr: ([0-9A-F:]+)")
|
||||
dst = int(child.match.group(1).replace(':', ''), base=16)
|
||||
|
||||
# first send valid packet to check if communication is set up correctly
|
||||
# generated with udp send <link-local> 61616 0 in tests/gnrc_udp
|
||||
payload = b"\x7e\x33\xf3\x00"
|
||||
payload = (
|
||||
Dot15d4FCS(fcf_srcaddrmode=2, fcf_panidcompress=True,
|
||||
fcf_frametype="Data") /
|
||||
Dot15d4Data(dest_addr=dst, dest_panid=0x23, src_addr=dst-1) /
|
||||
payload
|
||||
)
|
||||
packet = raw(
|
||||
ZEP2(ver=ZEP_V2_VERSION, type=ZEP_V2_TYPE_DATA, channel=26,
|
||||
length=len(payload)) / payload
|
||||
)
|
||||
s.sendto(packet, ("localhost", 17755))
|
||||
child.expect("PKTDUMP: data received:")
|
||||
child.expect("00000000 7E 33 F3 00")
|
||||
child.expect("~~ PKT - 2 snips, total size: 16 byte")
|
||||
payload = (
|
||||
Dot15d4FCS(fcf_srcaddrmode=2, fcf_panidcompress=True,
|
||||
fcf_frametype="Data") /
|
||||
# just append destination PAN ID and address
|
||||
bytes([0x23, 0x00, dst & 0xff, dst >> 8])
|
||||
)
|
||||
packet = raw(
|
||||
ZEP2(ver=ZEP_V2_VERSION, type=ZEP_V2_TYPE_DATA, channel=26,
|
||||
length=len(payload)) / payload
|
||||
)
|
||||
s.sendto(packet, ("localhost", 17755))
|
||||
res = child.expect([TIMEOUT, EOF, "PKTDUMP: data received:"])
|
||||
# we actually want the timeout here. The application either
|
||||
# receives a bogus packet or crashes in an error case case
|
||||
assert res == 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(run(testfunc, timeout=1))
|
||||
Loading…
x
Reference in New Issue
Block a user