From 15ab9bbdcda705c1c4bb10bd49ffd49907a96754 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Fri, 15 Oct 2021 17:37:40 +0200 Subject: [PATCH] tools/usb-cdc-ecm: add support for radvd / auto_subnets --- dist/tools/usb-cdc-ecm/start_network.sh | 23 +++++++++++++++++-- .../gnrc_border_router/Makefile.cdc-ecm.conf | 4 +++- 2 files changed, 24 insertions(+), 3 deletions(-) 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/examples/gnrc_border_router/Makefile.cdc-ecm.conf b/examples/gnrc_border_router/Makefile.cdc-ecm.conf index 0f46566bc9..8c86a6afbc 100644 --- a/examples/gnrc_border_router/Makefile.cdc-ecm.conf +++ b/examples/gnrc_border_router/Makefile.cdc-ecm.conf @@ -2,8 +2,10 @@ USEMODULE += auto_init_usbus USEMODULE += usbus_cdc_ecm -ifeq (dhcpv6, $(PREFIX_CONF)) +ifeq (dhcpv6,$(PREFIX_CONF)) FLAGS_EXTRAS += --use-dhcpv6 +else ifeq (auto_subnets,$(PREFIX_CONF)) + FLAGS_EXTRAS += --use-radvd endif # Configure terminal parameters for UHCP