1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

Merge pull request #16993 from benpicco/examples/gnrc_border_router-auto_subnets

examples/gnrc_border_router: allow to use gnrc_ipv6_auto_subnets for prefix configuration
This commit is contained in:
benpicco 2022-07-12 11:02:09 +02:00 committed by GitHub
commit b68c17188f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 109 additions and 24 deletions

View File

@ -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]" \
"<serial-port> <tap-device> <prefix> " \
"[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

View File

@ -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 <sl0>] [-d] [-e] [-g <addr>/<prefix_len>] <prefix> serial [baudrate]"
echo "usage: $1 [-I <sl0>] [-d] [-e] [-g <addr>/<prefix_len>] <prefix> tcp:host [port]"
echo "usage: $1 [-I <sl0>] [-d] [-r] [-e] [-g <addr>/<prefix_len>] <prefix> serial [baudrate]"
echo "usage: $1 [-I <sl0>] [-d] [-r] [-e] [-g <addr>/<prefix_len>] <prefix> 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=$?

View File

@ -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] <prefix> [<serial-port>]"
echo "usage: $0 [-d|--use-dhcpv6] [-r|--use-radvd ] <prefix> [<serial-port>]"
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

View File

@ -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 <port>] " \
echo "usage: $0 [-d|--use-dhcp] [-r|--use-radvd] [-z|--use-zep <port>] " \
"<elffile> <prefix> [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

View File

@ -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

View File

@ -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)
TERMFLAGS ?= $(FLAGS_EXTRAS) $(IPV6_PREFIX) $(PORT)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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