Skip to content

Commit

Permalink
examples/gnrc_border_router: add option to re-use existing TAP interface
Browse files Browse the repository at this point in the history
  • Loading branch information
benpicco committed Nov 2, 2022
1 parent e802203 commit cc2acd9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
15 changes: 13 additions & 2 deletions dist/tools/zep_dispatch/start_network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ remove_tap() {

cleanup() {
echo "Cleaning up..."
remove_tap
if [ "${CREATE_TAP}" -eq 1 ]; then
remove_tap
fi
if [ -n "${UHCPD_PID}" ]; then
kill "${UHCPD_PID}"
fi
Expand Down Expand Up @@ -64,6 +66,13 @@ start_zep_dispatch() {
ZEP_DISPATCH_PID=$!
}

if [ "$1" = "-c" ] || [ "$1" = "--create-tap" ]; then
CREATE_TAP=1
shift 1
else
CREATE_TAP=0
fi

if [ "$1" = "-d" ] || [ "$1" = "--use-dhcpv6" ]; then
USE_DHCPV6=1
shift 1
Expand Down Expand Up @@ -101,7 +110,9 @@ for TAP in "$@"; do :; done

trap "cleanup" INT QUIT TERM EXIT

create_tap
if [ ${CREATE_TAP} -eq 1 ]; then
create_tap
fi

if [ ${USE_ZEP_DISPATCH} -eq 1 ]; then
start_zep_dispatch
Expand Down
4 changes: 2 additions & 2 deletions examples/gnrc_border_router/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ RIOTBASE ?= $(CURDIR)/../..
UPLINK ?= ethos

# Check if the selected Uplink is valid
ifeq (,$(filter ethos slip cdc-ecm wifi ethernet,$(UPLINK)))
$(error Supported uplinks are `ethos`, `slip`, `cdc-ecm`, `ethernet` and `wifi`)
ifeq (,$(filter ethos slip cdc-ecm wifi ethernet tap,$(UPLINK)))
$(error Supported uplinks are `ethos`, `tap`, `slip`, `cdc-ecm`, `ethernet` and `wifi`)
endif

# Set the SSID and password of your WiFi network here
Expand Down
12 changes: 8 additions & 4 deletions examples/gnrc_border_router/Makefile.native.conf
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ CFLAGS += -DASYNC_READ_NUMOF=$(shell expr $(ZEP_DEVICES) + 1)
# Set CFLAGS if not being set via Kconfig
CFLAGS += $(if $(CONFIG_KCONFIG_MODULE_DHCPV6),,-DCONFIG_DHCPV6_CLIENT_PFX_LEASE_MAX=$(ZEP_DEVICES))

ifeq (dhcpv6,$(PREFIX_CONF))
FLAGS_EXTRAS += --use-dhcpv6
else ifeq (auto_subnets,$(PREFIX_CONF))
FLAGS_EXTRAS += --use-radvd
# create a new TAP interface if not re-using an existing one
ifneq (tap,$(UPLINK))
FLAGS_EXTRAS += --create-tap
ifeq (dhcpv6,$(PREFIX_CONF))
FLAGS_EXTRAS += --use-dhcpv6
else ifeq (auto_subnets,$(PREFIX_CONF))
FLAGS_EXTRAS += --use-radvd
endif
endif

# enable the ZEP dispatcher
Expand Down
1 change: 1 addition & 0 deletions examples/gnrc_border_router/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ For `native` the host-facing [`netdev_tap`](https://doc.riot-os.org/netdev__tap_
is configured, providing connectivity via a TAP interface to the RIOT instance.
On the node-facing side [`socket_zep`](https://doc.riot-os.org/group__drivers__socket__zep.html)
is used to simulate a IEEE 802.15.4 network.
Set `UPLINK=tap` to re-use an existing TAP interface instead of creating a new one.

To select an uplink, set the UPLINK environment variable. For instance, use `UPLINK=slip`
for a SLIP uplink.
Expand Down

0 comments on commit cc2acd9

Please sign in to comment.