diff --git a/dist/tools/ethos/start_network.sh b/dist/tools/ethos/start_network.sh index fe0cb28d19..6d9a458340 100755 --- a/dist/tools/ethos/start_network.sh +++ b/dist/tools/ethos/start_network.sh @@ -9,7 +9,6 @@ create_tap() { ip link set ${TAP} up ip a a fe80::1/64 dev ${TAP} ip a a fd00:dead:beef::1/128 dev lo - ip route add ${PREFIX} via fe80::2 dev ${TAP} } remove_tap() { @@ -31,15 +30,25 @@ cleanup() { } start_uhcpd() { + ip route add "${PREFIX}" via fe80::2 dev "${TAP}" ${UHCPD} ${TAP} ${PREFIX} > /dev/null & UHCPD_PID=$! } start_dhcpd() { + ip route add "${PREFIX}" via fe80::2 dev "${TAP}" DHCPD_PIDFILE=$(mktemp) ${DHCPD} -d -p ${DHCPD_PIDFILE} ${TAP} ${PREFIX} 2> /dev/null } +start_radvd() { + ADDR=$(echo "${PREFIX}" | sed -e 's/::\//::1\//') + ip a a "${ADDR}" dev "${TAP}" + sysctl net.ipv6.conf."${TAP}".accept_ra=2 + sysctl net.ipv6.conf."${TAP}".accept_ra_rt_info_max_plen=64 + ${RADVD} -c "${TAP}" "${PREFIX}" +} + if [ "$1" = "-d" ] || [ "$1" = "--use-dhcpv6" ]; then USE_DHCPV6=1 shift 1 @@ -47,6 +56,13 @@ else USE_DHCPV6=0 fi +if [ "$1" = "-r" ] || [ "$1" = "--use-radvd" ]; then + USE_RADVD=1 + shift 1 +else + USE_RADVD=0 +fi + if [ "$1" = "-e" ] || [ "$1" = "--ethos-only" ]; then ETHOS_ONLY=1 shift 1 @@ -61,7 +77,7 @@ BAUDRATE=115200 START_ETHOS=1 [ -z "${PORT}" -o -z "${TAP}" -o -z "${PREFIX}" ] && { - echo "usage: $0 [-d|--use-dhcp] [-e|--ethos-only] " \ + echo "usage: $0 [-d|--use-dhcp] [-e|--ethos-only] [-r|--use-radvd]" \ " " \ "[baudrate]" exit 1 @@ -80,6 +96,10 @@ if [ ${ETHOS_ONLY} -ne 1 ]; then DHCPD="$(readlink -f "${ETHOS_DIR}/../dhcpv6-pd_ia/")/dhcpv6-pd_ia.py" start_dhcpd START_ETHOS=$? + elif [ ${USE_RADVD} -eq 1 ]; then + RADVD="$(readlink -f "${ETHOS_DIR}/../radvd/")/radvd.sh" + start_radvd + START_ETHOS=$? else UHCPD="$(readlink -f "${ETHOS_DIR}/../uhcpd/bin")/uhcpd" start_uhcpd diff --git a/dist/tools/sliptty/start_network.sh b/dist/tools/sliptty/start_network.sh index fe685821e3..6621472f92 100755 --- a/dist/tools/sliptty/start_network.sh +++ b/dist/tools/sliptty/start_network.sh @@ -3,6 +3,7 @@ SLIPTTY_DIR="$(cd "$(dirname "$0")" && pwd -P)" UHCPD="$(cd "${SLIPTTY_DIR}/../uhcpd/bin" && pwd -P)/uhcpd" DHCPD="$(cd "${SLIPTTY_DIR}/../dhcpv6-pd_ia/" && pwd -P)/dhcpv6-pd_ia.py" +RADVD="$(cd "${SLIPTTY_DIR}/../radvd/" && pwd -P)/radvd.sh" TUN=sl0 TUN_GLB="fdea:dbee:f::1/64" UHCPD_PID= @@ -40,6 +41,7 @@ create_tun() { echo " ${SUDO} sysctl -w net.ipv6.conf.all.forwarding=0" >&2 echo "when not desired without this script" >&2 ${SUDO} sysctl -w net.ipv6.conf.${TUN}.accept_ra=2 + ${SUDO} sysctl -w net.ipv6.conf."${TUN}".accept_ra_rt_info_max_plen=64 ${SUDO} ip link set ${TUN} up || exit 1 ${SUDO} ip address add fe80::1/64 dev ${TUN} ${SUDO} ip address add ${TUN_GLB} dev ${TUN} @@ -111,20 +113,26 @@ start_dhcpd() { ${DHCPD} -d -p ${DHCPD_PIDFILE} ${TUN} ${PREFIX} 2> /dev/null } +start_radvd() { + "${RADVD}" -c "${TUN}" "${PREFIX}" +} + usage() { - echo "usage: $1 [-I ] [-d] [-e] [-g /] serial [baudrate]" - echo "usage: $1 [-I ] [-d] [-e] [-g /] tcp:host [port]" + echo "usage: $1 [-I ] [-d] [-r] [-e] [-g /] serial [baudrate]" + echo "usage: $1 [-I ] [-d] [-r] [-e] [-g /] tcp:host [port]" } trap "cleanup" INT QUIT TERM EXIT SLIP_ONLY=0 USE_DHCPV6=0 +USE_RADVD=0 -while getopts dehI: opt; do +while getopts dehIr: opt; do case ${opt} in d) USE_DHCPV6=1; shift 1;; e) SLIP_ONLY=1; shift 1;; + r) USE_RADVD=1; shift 1;; I) TUN=${OPTARG}; shift 2;; g) TUN_GLB=${OPTARG}; shift 2;; h) usage $0; exit 0;; @@ -143,6 +151,9 @@ if [ ${SLIP_ONLY} -ne 1 ]; then if [ ${USE_DHCPV6} -eq 1 ]; then start_dhcpd START_SLIP=$? + elif [ ${USE_RADVD} -eq 1 ]; then + start_radvd + START_SLIP=$? else start_uhcpd START_SLIP=$? diff --git a/dist/tools/usb-cdc-ecm/start_network.sh b/dist/tools/usb-cdc-ecm/start_network.sh index 0684c61758..cf72f07b60 100755 --- a/dist/tools/usb-cdc-ecm/start_network.sh +++ b/dist/tools/usb-cdc-ecm/start_network.sh @@ -34,7 +34,6 @@ setup_interface() { ip link set "${INTERFACE}" up ip a a fe80::1/64 dev "${INTERFACE}" ip a a fd00:dead:beef::1/128 dev lo - ip route add "${PREFIX}" via fe80::2 dev "${INTERFACE}" } cleanup_interface() { @@ -57,15 +56,25 @@ cleanup() { } start_uhcpd() { + ip route add "${PREFIX}" via fe80::2 dev "${INTERFACE}" ${UHCPD} "${INTERFACE}" "${PREFIX}" > /dev/null & UHCPD_PID=$! } start_dhcpd() { + ip route add "${PREFIX}" via fe80::2 dev "${INTERFACE}" DHCPD_PIDFILE=$(mktemp) ${DHCPD} -d -p "${DHCPD_PIDFILE}" "${INTERFACE}" "${PREFIX}" 2> /dev/null } +start_radvd() { + ADDR=$(echo "${PREFIX}" | sed -e 's/::\//::1\//') + ip a a "${ADDR}" dev "${INTERFACE}" + sysctl net.ipv6.conf."${INTERFACE}".accept_ra=2 + sysctl net.ipv6.conf."${INTERFACE}".accept_ra_rt_info_max_plen=64 + ${RADVD} -c "${INTERFACE}" "${PREFIX}" +} + if [ "$1" = "-d" ] || [ "$1" = "--use-dhcpv6" ]; then USE_DHCPV6=1 shift 1 @@ -73,9 +82,16 @@ else USE_DHCPV6=0 fi +if [ "$1" = "-r" ] || [ "$1" = "--use-radvd" ]; then + USE_RADVD=1 + shift 1 +else + USE_RADVD=0 +fi + PREFIX=$1 [ -z "${PREFIX}" ] && { - echo "usage: $0 [-d|--use-dhcpv6] []" + echo "usage: $0 [-d|--use-dhcpv6] [-r|--use-radvd ] []" exit 1 } @@ -90,6 +106,9 @@ setup_interface if [ ${USE_DHCPV6} -eq 1 ]; then DHCPD="$(readlink -f "${USB_CDC_ECM_DIR}/../dhcpv6-pd_ia/")/dhcpv6-pd_ia.py" start_dhcpd +elif [ ${USE_RADVD} -eq 1 ]; then + RADVD="$(readlink -f "${USB_CDC_ECM_DIR}/../radvd/")/radvd.sh" + start_radvd else UHCPD="$(readlink -f "${USB_CDC_ECM_DIR}/../uhcpd/bin")/uhcpd" start_uhcpd diff --git a/dist/tools/zep_dispatch/start_network.sh b/dist/tools/zep_dispatch/start_network.sh index f98cd93b87..8e7f4ee33d 100755 --- a/dist/tools/zep_dispatch/start_network.sh +++ b/dist/tools/zep_dispatch/start_network.sh @@ -3,6 +3,7 @@ ZEP_DISPATCH_DIR="$(cd "$(dirname "$0")" && pwd -P)" UHCPD="$(cd "${ZEP_DISPATCH_DIR}/../uhcpd/bin" && pwd -P)/uhcpd" DHCPD="$(cd "${ZEP_DISPATCH_DIR}/../dhcpv6-pd_ia/" && pwd -P)/dhcpv6-pd_ia.py" +RADVD="$(cd "${ZEP_DISPATCH_DIR}/../radvd/" && pwd -P)/radvd.sh" ZEP_DISPATCH="${ZEP_DISPATCH_DIR}/bin/zep_dispatch" TAP_GLB="fdea:dbee:f::1/64" @@ -16,7 +17,6 @@ create_tap() { ip link set "${TAP}" up ip a a fe80::1/64 dev "${TAP}" ip a a ${TAP_GLB} dev "${TAP}" - ip route add "${PREFIX}" via fe80::2 dev "${TAP}" } remove_tap() { @@ -40,15 +40,25 @@ cleanup() { } start_uhcpd() { + ip route add "${PREFIX}" via fe80::2 dev "${TAP}" ${UHCPD} "${TAP}" "${PREFIX}" > /dev/null & UHCPD_PID=$! } start_dhcpd() { + ip route add "${PREFIX}" via fe80::2 dev "${TAP}" DHCPD_PIDFILE=$(mktemp) ${DHCPD} -d -p "${DHCPD_PIDFILE}" "${TAP}" "${PREFIX}" 2> /dev/null } +start_radvd() { + ADDR=$(echo "${PREFIX}" | sed -e 's/::\//::1\//') + ip a a "${ADDR}" dev "${TAP}" + sysctl net.ipv6.conf."${TAP}".accept_ra=2 + sysctl net.ipv6.conf."${TAP}".accept_ra_rt_info_max_plen=64 + ${RADVD} -c "${TAP}" "${PREFIX}" +} + start_zep_dispatch() { ${ZEP_DISPATCH} :: "${ZEP_PORT_BASE}" > /dev/null & ZEP_DISPATCH_PID=$! @@ -61,6 +71,13 @@ else USE_DHCPV6=0 fi +if [ "$1" = "-r" ] || [ "$1" = "--use-radvd" ]; then + USE_RADVD=1 + shift 1 +else + USE_RADVD=0 +fi + if [ "$1" = "-z" ] || [ "$1" = "--use-zep-dispatch" ]; then USE_ZEP_DISPATCH=1 ZEP_PORT_BASE=$2 @@ -77,7 +94,7 @@ shift 2 for TAP in "$@"; do :; done [[ -z "${ELFFILE}" || -z "${PREFIX}" || -z "${TAP}" ]] && { - echo "usage: $0 [-d|--use-dhcp] [-z|--use-zep ] " \ + echo "usage: $0 [-d|--use-dhcp] [-r|--use-radvd] [-z|--use-zep ] " \ " [elf args]" exit 1 } @@ -92,6 +109,8 @@ fi if [ ${USE_DHCPV6} -eq 1 ]; then start_dhcpd +elif [ ${USE_RADVD} -eq 1 ]; then + start_radvd else start_uhcpd fi diff --git a/examples/gnrc_border_router/Makefile b/examples/gnrc_border_router/Makefile index 8771de9ae8..bd73d1c6b2 100644 --- a/examples/gnrc_border_router/Makefile +++ b/examples/gnrc_border_router/Makefile @@ -44,17 +44,24 @@ USEMODULE += ps # When using a regular network uplink we should use DHCPv6 ifneq (,$(filter cdc-ecm wifi ethernet,$(UPLINK))) - USE_DHCPV6 ?= 1 + PREFIX_CONF ?= dhcpv6 else - USE_DHCPV6 ?= 0 + PREFIX_CONF ?= uhcp endif -ifeq (1,$(USE_DHCPV6)) +# Check if the selected method for prefix configuration is valid +ifeq (,$(filter dhcpv6 uhcp auto_subnets,$(PREFIX_CONF))) + $(error Supported methods for prefix configuration are `dhcpv6`, `uhcp` and `auto_subnets`) +endif + +ifeq (dhcpv6,$(PREFIX_CONF)) # include DHCPv6 client for 6LoWPAN border router USEMODULE += gnrc_dhcpv6_client_6lbr -else +else ifeq (uhcp,$(PREFIX_CONF)) # include UHCP client USEMODULE += gnrc_uhcpc +else ifeq (auto_subnets,$(PREFIX_CONF)) + USEMODULE += gnrc_ipv6_auto_subnets_simple endif # Comment this out to disable code in RIOT that does safety checking @@ -67,7 +74,7 @@ QUIET ?= 1 # Ethos/native TAP interface and UHCP prefix can be configured from make command TAP ?= tap0 -ifeq (1,$(USE_DHCPV6)) +ifneq (,$(filter dhcpv6 auto_subnets,$(PREFIX_CONF))) # with DHCPv6 the 64-bit delegated prefixes are generated from a shorter # configured prefix. IPV6_PREFIX ?= 2001:db8::/32 @@ -110,7 +117,7 @@ include $(RIOTBASE)/Makefile.include # Compile-time configuration for DHCPv6 client (needs to come after # Makefile.include as this might come from Kconfig) -ifeq (1,$(USE_DHCPV6)) +ifeq (dhcpv6,$(PREFIX_CONF)) ifndef CONFIG_GNRC_DHCPV6_CLIENT_6LBR_STATIC_ROUTE ifeq (1,$(STATIC_ROUTES)) CFLAGS += -DCONFIG_GNRC_DHCPV6_CLIENT_6LBR_STATIC_ROUTE=1 @@ -129,7 +136,7 @@ host-tools: # define native specific targets to only run UHCP daemon when required ifneq (,$(filter native,$(BOARD))) -ifneq (1,$(USE_DHCPV6)) +ifeq (uhcp,$(PREFIX_CONF)) .PHONY: uhcpd-daemon uhcpd-daemon: host-tools diff --git a/examples/gnrc_border_router/Makefile.cdc-ecm.conf b/examples/gnrc_border_router/Makefile.cdc-ecm.conf index 679b931c5f..8c86a6afbc 100644 --- a/examples/gnrc_border_router/Makefile.cdc-ecm.conf +++ b/examples/gnrc_border_router/Makefile.cdc-ecm.conf @@ -2,11 +2,13 @@ USEMODULE += auto_init_usbus USEMODULE += usbus_cdc_ecm -ifeq (1,$(USE_DHCPV6)) +ifeq (dhcpv6,$(PREFIX_CONF)) FLAGS_EXTRAS += --use-dhcpv6 +else ifeq (auto_subnets,$(PREFIX_CONF)) + FLAGS_EXTRAS += --use-radvd endif # Configure terminal parameters for UHCP TERMDEPS += host-tools TERMPROG ?= sudo sh $(RIOTTOOLS)/usb-cdc-ecm/start_network.sh -TERMFLAGS ?= $(FLAGS_EXTRAS) $(IPV6_PREFIX) $(PORT) \ No newline at end of file +TERMFLAGS ?= $(FLAGS_EXTRAS) $(IPV6_PREFIX) $(PORT) diff --git a/examples/gnrc_border_router/Makefile.ethos.conf b/examples/gnrc_border_router/Makefile.ethos.conf index 9a7d1484cd..abce83ffd0 100644 --- a/examples/gnrc_border_router/Makefile.ethos.conf +++ b/examples/gnrc_border_router/Makefile.ethos.conf @@ -2,8 +2,10 @@ CFLAGS += -DETHOS_BAUDRATE=$(ETHOS_BAUDRATE) STATIC_ROUTES ?= 1 -ifeq (1,$(USE_DHCPV6)) +ifeq (dhcpv6,$(PREFIX_CONF)) FLAGS_EXTRAS=--use-dhcpv6 +else ifeq (auto_subnets,$(PREFIX_CONF)) + FLAGS_EXTRAS=--use-radvd endif # Configure terminal parameters diff --git a/examples/gnrc_border_router/Makefile.native.conf b/examples/gnrc_border_router/Makefile.native.conf index d6dcab5c9f..a649b88aa6 100644 --- a/examples/gnrc_border_router/Makefile.native.conf +++ b/examples/gnrc_border_router/Makefile.native.conf @@ -9,8 +9,10 @@ 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 (1,$(USE_DHCPV6)) +ifeq (dhcpv6,$(PREFIX_CONF)) FLAGS_EXTRAS += --use-dhcpv6 +else ifeq (auto_subnets,$(PREFIX_CONF)) + FLAGS_EXTRAS += --use-radvd endif # enable the ZEP dispatcher diff --git a/examples/gnrc_border_router/Makefile.slip.conf b/examples/gnrc_border_router/Makefile.slip.conf index d0c51b92be..bf36fdb80d 100644 --- a/examples/gnrc_border_router/Makefile.slip.conf +++ b/examples/gnrc_border_router/Makefile.slip.conf @@ -4,8 +4,11 @@ CFLAGS += -DSLIPDEV_PARAM_BAUDRATE=$(SLIP_BAUDRATE) STATIC_ROUTES ?= 1 -ifeq (1,$(USE_DHCPV6)) +ifeq (dhcpv6,$(PREFIX_CONF)) FLAGS_EXTRAS=-d +else ifeq (auto_subnets,$(PREFIX_CONF)) + FLAGS_EXTRAS=-r + USEMODULE += slipdev_l2addr endif # Configure terminal parameters diff --git a/examples/gnrc_border_router/README.md b/examples/gnrc_border_router/README.md index 9a0e6e50ea..e6c339c600 100644 --- a/examples/gnrc_border_router/README.md +++ b/examples/gnrc_border_router/README.md @@ -36,7 +36,7 @@ router, stdio is multiplexed over the same line. The `wifi` uplink will connect to an existing WiFi (IEEE 802.11) network. The network must provide a DHCPv6 server that supports prefix delegation (IA_PD) when -`USE_DHCPV6=1` is set (default). +`PREFIX_CONF=dhcpv6` is set (default). Use `WIFI_SSID="SSID" WIFI_PASS="password"` in your `make` command to set your WiFi's credentials. You can alternatively edit the `Makefile`. @@ -85,10 +85,10 @@ make clean all flash ``` If you want to use DHCPv6 instead of UHCP compile with the environment variable -`USE_DHCPV6` set to 1 +`PREFIX_CONF` set to dhcpv6 ```bash -USE_DHCPV6=1 make clean all flash +PREFIX_CONF=dhcpv6 make clean all flash ``` ## Usage