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.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) diff --git a/examples/gnrc_border_router/Makefile.native.conf b/examples/gnrc_border_router/Makefile.native.conf index a649b88aa6..47785a3447 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 @@ -30,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) diff --git a/examples/gnrc_border_router/README.md b/examples/gnrc_border_router/README.md index bc82beecda..18cac784ae 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.