From 5260c18ae6e27d5f9fb7853a48ca10f3b9057a6d Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 2 Nov 2022 21:09:42 +0100 Subject: [PATCH 1/3] examples/gnrc_border_router: add option to re-use existing TAP interface --- dist/tools/zep_dispatch/start_network.sh | 15 +++++++++++++-- examples/gnrc_border_router/Makefile | 2 +- examples/gnrc_border_router/Makefile.native.conf | 12 ++++++++---- examples/gnrc_border_router/README.md | 15 +++++++++++++++ 4 files changed, 37 insertions(+), 7 deletions(-) diff --git a/dist/tools/zep_dispatch/start_network.sh b/dist/tools/zep_dispatch/start_network.sh index 8e7f4ee33d..fb9a1a90de 100755 --- a/dist/tools/zep_dispatch/start_network.sh +++ b/dist/tools/zep_dispatch/start_network.sh @@ -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 @@ -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 @@ -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 diff --git a/examples/gnrc_border_router/Makefile b/examples/gnrc_border_router/Makefile index 8ed6bbc4e4..05f2538774 100644 --- a/examples/gnrc_border_router/Makefile +++ b/examples/gnrc_border_router/Makefile @@ -43,7 +43,7 @@ USEMODULE += ps #USEMODULE += gnrc_ipv6_nib_dns # include RDNSS option handling # When using a regular network uplink we should use DHCPv6 -ifneq (,$(filter cdc-ecm wifi ethernet,$(UPLINK))) +ifneq (,$(filter cdc-ecm wifi ethernet,$(UPLINK)) $(REUSE_TAP)) PREFIX_CONF ?= dhcpv6 else PREFIX_CONF ?= uhcp diff --git a/examples/gnrc_border_router/Makefile.native.conf b/examples/gnrc_border_router/Makefile.native.conf index a649b88aa6..72a5a0d194 100644 --- a/examples/gnrc_border_router/Makefile.native.conf +++ b/examples/gnrc_border_router/Makefile.native.conf @@ -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 (1, $(REUSE_TAP)) + 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 diff --git a/examples/gnrc_border_router/README.md b/examples/gnrc_border_router/README.md index 957c68edf2..7cf1f2ecfd 100644 --- a/examples/gnrc_border_router/README.md +++ b/examples/gnrc_border_router/README.md @@ -44,6 +44,21 @@ credentials. You can alternatively edit the `Makefile`. Currently, `wifi` requires an esp8266 or esp32 for the border router and will default to using `esp_now` for the downstream interface. +### Connection sharing with host + +If the host (Linux) computer has an IPv6 uplink that can be shard with the RIOT border +router to provide it with an uplink. + +This requires the host network to be bridged with the TAP network by connecting it to +the TAP bridge: + + sudo dist/tools/tapsetup/tapsetup -u eno1 + +where `eno1` is the host's uplink interface. + +Then specify `REUSE_TAP=1` when building / running the border router application. +This works with both `native` and the `ethos` uplink. + ## Requirements This functionality works only on Linux machines. macOS support will be added in the future (lack of native `tap` interface). From a61a0262d7c984106a30cb17992307d12df1c4c9 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 8 Nov 2022 14:57:51 +0100 Subject: [PATCH 2/3] examples/gnrc_border_router: allow to re-use tap interface with ethos --- examples/gnrc_border_router/Makefile.ethos.conf | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/examples/gnrc_border_router/Makefile.ethos.conf b/examples/gnrc_border_router/Makefile.ethos.conf index abce83ffd0..51f59239d3 100644 --- a/examples/gnrc_border_router/Makefile.ethos.conf +++ b/examples/gnrc_border_router/Makefile.ethos.conf @@ -1,14 +1,21 @@ CFLAGS += -DETHOS_BAUDRATE=$(ETHOS_BAUDRATE) -STATIC_ROUTES ?= 1 - ifeq (dhcpv6,$(PREFIX_CONF)) FLAGS_EXTRAS=--use-dhcpv6 else ifeq (auto_subnets,$(PREFIX_CONF)) FLAGS_EXTRAS=--use-radvd endif -# Configure terminal parameters +ifeq (1, $(REUSE_TAP)) + # Use ethos directly + TERMPROG ?= $(RIOTTOOLS)/ethos/ethos + TERMFLAGS ?= $(TAP) $(PORT) $(ETHOS_BAUDRATE) +else + STATIC_ROUTES ?= 1 + + # Set up network, ethos started by start_network.sh + TERMPROG ?= sudo sh $(RIOTTOOLS)/ethos/start_network.sh + TERMFLAGS ?= $(FLAGS_EXTRAS) $(PORT) $(TAP) $(IPV6_PREFIX) $(ETHOS_BAUDRATE) +endif + TERMDEPS += host-tools -TERMPROG ?= sudo sh $(RIOTTOOLS)/ethos/start_network.sh -TERMFLAGS ?= $(FLAGS_EXTRAS) $(PORT) $(TAP) $(IPV6_PREFIX) $(ETHOS_BAUDRATE) From 299b5ac5a5a4ad838cb007aba0a9a35c0092471a Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Tue, 8 Nov 2022 15:13:45 +0100 Subject: [PATCH 3/3] examples/gnrc_border_router: honor $TAP setting --- examples/gnrc_border_router/Makefile.native.conf | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/gnrc_border_router/Makefile.native.conf b/examples/gnrc_border_router/Makefile.native.conf index 72a5a0d194..47785a3447 100644 --- a/examples/gnrc_border_router/Makefile.native.conf +++ b/examples/gnrc_border_router/Makefile.native.conf @@ -34,3 +34,6 @@ TERMFLAGS ?= $(patsubst %,-z [::1]:%, $(shell seq $(ZEP_PORT_BASE) $(ZEP_PORT_MA ifneq (,$(ZEP_MAC)) TERMFLAGS += --eui64=$(ZEP_MAC) endif + +# native uses $PORT to specify the TAP interface +PORT ?= $(TAP)