From 702d7684d3738eb810e55ac25f5fc1b53117c8bd Mon Sep 17 00:00:00 2001 From: Shery Sheng Date: Thu, 13 Jun 2024 16:08:08 +0800 Subject: [PATCH 01/10] semi-automated PD on raspbian scripts --- examples/platforms/raspbian/default | 1 + script/_dhcpv6_pd_ref | 76 +++++++++++++++++++++++ script/bootstrap | 14 +++++ script/reference-device/dhcpcd.enter-hook | 59 ++++++++++++++++++ script/reference-device/dhcpcd.exit-hook | 48 ++++++++++++++ script/setup | 3 + 6 files changed, 201 insertions(+) create mode 100644 script/_dhcpv6_pd_ref create mode 100644 script/reference-device/dhcpcd.enter-hook create mode 100644 script/reference-device/dhcpcd.exit-hook diff --git a/examples/platforms/raspbian/default b/examples/platforms/raspbian/default index f5bb3f07449..3ed3e5a1150 100644 --- a/examples/platforms/raspbian/default +++ b/examples/platforms/raspbian/default @@ -31,6 +31,7 @@ NAT64=1 DNS64=0 DHCPV6_PD=0 +DHCPV6_PD_REF=1 NETWORK_MANAGER=0 BACKBONE_ROUTER=1 BORDER_ROUTING=1 diff --git a/script/_dhcpv6_pd_ref b/script/_dhcpv6_pd_ref new file mode 100644 index 00000000000..4ca98f9e4e0 --- /dev/null +++ b/script/_dhcpv6_pd_ref @@ -0,0 +1,76 @@ +#!/bin/bash + +customise_dhcpcd_conf() +{ +sudo tee /etc/dhcpcd.conf > /dev/null < /dev/null < /dev/null < /dev/null < /dev/null < /dev/null < Date: Thu, 26 Sep 2024 06:59:06 +0000 Subject: [PATCH 02/10] semi-automated PD on raspbian scripts: fix the issue where 'mv' command permanently removes the hook files --- script/_dhcpv6_pd_ref | 17 +++++++---------- script/bootstrap | 10 +++++----- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/script/_dhcpv6_pd_ref b/script/_dhcpv6_pd_ref index 4ca98f9e4e0..f118bae4a93 100644 --- a/script/_dhcpv6_pd_ref +++ b/script/_dhcpv6_pd_ref @@ -2,7 +2,7 @@ customise_dhcpcd_conf() { -sudo tee /etc/dhcpcd.conf > /dev/null </dev/null < /dev/null </dev/null < Date: Fri, 27 Sep 2024 02:47:55 +0000 Subject: [PATCH 03/10] semi-automated PD on raspbian scripts: remove redundant comments --- script/_dhcpv6_pd_ref | 12 ------------ script/reference-device/dhcpcd.enter-hook | 12 ------------ 2 files changed, 24 deletions(-) diff --git a/script/_dhcpv6_pd_ref b/script/_dhcpv6_pd_ref index f118bae4a93..8e84521a095 100644 --- a/script/_dhcpv6_pd_ref +++ b/script/_dhcpv6_pd_ref @@ -38,18 +38,6 @@ interface eth0 EOF } -# customise_dhcpcd_hooks90 -# { -# #dhcpcd.enter-hook -# sudo tee /etc/dhcpcd.enter-hook > /dev/null < /dev/null < Date: Wed, 9 Oct 2024 04:05:16 +0000 Subject: [PATCH 04/10] semi-automated PD on raspbian scripts: support of debian platform for latest Raspi OS --- examples/platforms/debian/default | 1 + script/_border_routing | 1 - script/_dhcpv6_pd_ref | 5 +++++ script/_otbr | 6 ++++++ script/bootstrap | 2 +- script/reference-device/dhcpcd.enter-hook | 6 ++++-- script/reference-device/dhcpcd.exit-hook | 7 ++++--- 7 files changed, 21 insertions(+), 7 deletions(-) diff --git a/examples/platforms/debian/default b/examples/platforms/debian/default index c76b5423e6c..054a032bf86 100644 --- a/examples/platforms/debian/default +++ b/examples/platforms/debian/default @@ -31,6 +31,7 @@ NAT64=0 DNS64=0 DHCPV6_PD=0 +DHCPV6_PD_REF=1 NETWORK_MANAGER=0 BACKBONE_ROUTER=1 BORDER_ROUTING=1 diff --git a/script/_border_routing b/script/_border_routing index f17c8fe6900..9af4cf46490 100644 --- a/script/_border_routing +++ b/script/_border_routing @@ -81,7 +81,6 @@ dhcpcd_disable_ipv6() if [ -f $DHCPCD_CONF_FILE ]; then sudo cp $DHCPCD_CONF_FILE $DHCPCD_CONF_BACKUP_FILE sudo tee -a $DHCPCD_CONF_FILE </dev/null; then sudo apt-get install --no-install-recommends -y dhcpcd sudo mkdir -p /etc/systemd/system/dhcpcd.service.d # allow edit system config file eg. /etc/radvd.conf diff --git a/script/reference-device/dhcpcd.enter-hook b/script/reference-device/dhcpcd.enter-hook index fb9e041cb8f..113d2da3538 100644 --- a/script/reference-device/dhcpcd.enter-hook +++ b/script/reference-device/dhcpcd.enter-hook @@ -1,14 +1,16 @@ #!/bin/bash WAN_INTERFACE="eth0" +WLAN_INTERFACE="wlan0" WPAN_INTERFACE="wpan0" + RADVD_CONF="/etc/radvd.conf" LOG_TAG="dhcpcd.enter.hook:" config_ra() { - logger -t "$LOG_TAG $reason start config radvd" + logger "$LOG_TAG $reason start config radvd" sudo tee "${RADVD_CONF}" > /dev/null < /dev/null < Date: Sat, 12 Oct 2024 07:31:05 +0000 Subject: [PATCH 05/10] semi-automated PD on raspbian scripts: bug fix --- script/_border_routing | 17 +++++++---- script/_dhcpv6_pd_ref | 36 +++++------------------ script/reference-device/dhcpcd.enter-hook | 1 - script/setup | 4 +-- 4 files changed, 20 insertions(+), 38 deletions(-) diff --git a/script/_border_routing b/script/_border_routing index 9af4cf46490..71bb3d807ad 100644 --- a/script/_border_routing +++ b/script/_border_routing @@ -68,13 +68,18 @@ accept_ra_enable() fi } -# This function disables IPv6 support in dhcpcd. +# This function disables IPv6 Router Solicitation (RS) in dhcpcd. # -# dhcpcd on raspberry Pi enables IPv6 support by default. The problem with -# dhcpcd is that it does't support Route Information Option (RIO), so we need -# to rely on the kernel implementation. dhcpcd will force set accept_ra to 0 -# for all interfaces it is currently running on, if IPv6 is enabled. This -# conflicts with our accept_ra* configurations. +# dhcpcd on Raspberry Pi enables IPv6 support by default, including Router +# Solicitations (RS). While we want to use dhcpcd for IPv6 address management, +# dhcpcd's handling of RS can conflict with the kernel's IPv6 configuration, +# specifically the 'accept_ra' setting. +# +# By disabling RS in dhcpcd with 'noipv6rs', we prevent dhcpcd from interfering +# with the kernel's 'accept_ra' setting, allowing us to manage IPv6 routing and +# other aspects of IPv6 configuration at the kernel level. This approach ensures +# that we can leverage dhcpcd for IPv6 address assignment while maintaining +# control over 'accept_ra'. # dhcpcd_disable_ipv6() { diff --git a/script/_dhcpv6_pd_ref b/script/_dhcpv6_pd_ref index 6b59542139b..4d4e13fea06 100644 --- a/script/_dhcpv6_pd_ref +++ b/script/_dhcpv6_pd_ref @@ -3,34 +3,8 @@ customise_dhcpcd_conf() { sudo tee /etc/dhcpcd.conf >/dev/null < Date: Mon, 14 Oct 2024 06:29:16 +0000 Subject: [PATCH 06/10] semi-automated PD on raspbian scripts: bug fix --- script/_dhcpv6_pd_ref | 11 +++-------- script/bootstrap | 6 +++--- script/reference-device/dhcpcd.enter-hook | 6 +++--- script/reference-device/dhcpcd.exit-hook | 7 ++++--- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/script/_dhcpv6_pd_ref b/script/_dhcpv6_pd_ref index 4d4e13fea06..d6d74eeab14 100644 --- a/script/_dhcpv6_pd_ref +++ b/script/_dhcpv6_pd_ref @@ -2,18 +2,14 @@ customise_dhcpcd_conf() { + # This has to be run after script/_border_routing, and this will + # invalidate all changes to dhcpcd.conf made by script/_border_routing. sudo tee /etc/dhcpcd.conf >/dev/null </dev/null; then + # dhcpv6-pd + without DHCPV6_PD_REF || { sudo apt-get install --no-install-recommends -y dhcpcd sudo mkdir -p /etc/systemd/system/dhcpcd.service.d # allow edit system config file eg. /etc/radvd.conf @@ -118,7 +118,7 @@ EOF # reload dhcpcd daemon to activate the custom.conf sudo systemctl daemon-reload sudo apt-get install --no-install-recommends -y radvd - fi + } # network-manager without NETWORK_MANAGER || sudo apt-get install --no-install-recommends -y dnsmasq network-manager diff --git a/script/reference-device/dhcpcd.enter-hook b/script/reference-device/dhcpcd.enter-hook index 99566b33b36..bd02ccc65e2 100644 --- a/script/reference-device/dhcpcd.enter-hook +++ b/script/reference-device/dhcpcd.enter-hook @@ -1,7 +1,6 @@ #!/bin/bash -WAN_INTERFACE="eth0" -WLAN_INTERFACE="wlan0" +UPSTREAM_INTERFACE="eth0" WPAN_INTERFACE="wpan0" RADVD_CONF="/etc/radvd.conf" @@ -29,7 +28,8 @@ EOF } -if [ "${interface}" = "eth0" ] || [ “${interface}” = “wlan0” ]; then +# TODO: set the upstream interface according to the environment variables of `script/setup`. +if [ "${interface}" = ${UPSTREAM_INTERFACE} ]; then for var in $(env); do # Split the variable into name and value diff --git a/script/reference-device/dhcpcd.exit-hook b/script/reference-device/dhcpcd.exit-hook index 8aba12527d5..ce79b9385cd 100644 --- a/script/reference-device/dhcpcd.exit-hook +++ b/script/reference-device/dhcpcd.exit-hook @@ -2,8 +2,7 @@ #dhcpcd.exit-hook -WAN_INTERFACE="eth0" -WLAN_INTERFACE="wlan0" +UPSTREAM_INTERFACE="eth0" WPAN_INTERFACE="wpan0" RADVD_CONF="/etc/radvd.conf" @@ -29,7 +28,9 @@ interface ${WPAN_INTERFACE} EOF } -if [ “${interface}” = “eth0” ] || [ “${interface}” = “wlan0” ]; then + +# TODO: set the upstream interface according to the environment variables of `script/setup`. +if [ “${interface}” = ${UPSTREAM_INTERFACE} ]; then for var in $(env); do # Split the variable into name and value From 519386b0dc7fd31bb6e30d75320ba7913ed11c3a Mon Sep 17 00:00:00 2001 From: Yang Song Date: Tue, 15 Oct 2024 05:36:08 +0000 Subject: [PATCH 07/10] semi-automated PD on raspbian scripts: bug fix --- script/_border_routing | 15 +++------ script/_dhcpv6_pd_ref | 33 ++++++++++++++++++-- script/reference-device/dhcpcd.enter-hook | 34 +++++++++++++++++++-- script/reference-device/dhcpcd.exit-hook | 37 ++++++++++++++++++++--- 4 files changed, 100 insertions(+), 19 deletions(-) diff --git a/script/_border_routing b/script/_border_routing index 71bb3d807ad..88febb1ba06 100644 --- a/script/_border_routing +++ b/script/_border_routing @@ -70,16 +70,11 @@ accept_ra_enable() # This function disables IPv6 Router Solicitation (RS) in dhcpcd. # -# dhcpcd on Raspberry Pi enables IPv6 support by default, including Router -# Solicitations (RS). While we want to use dhcpcd for IPv6 address management, -# dhcpcd's handling of RS can conflict with the kernel's IPv6 configuration, -# specifically the 'accept_ra' setting. -# -# By disabling RS in dhcpcd with 'noipv6rs', we prevent dhcpcd from interfering -# with the kernel's 'accept_ra' setting, allowing us to manage IPv6 routing and -# other aspects of IPv6 configuration at the kernel level. This approach ensures -# that we can leverage dhcpcd for IPv6 address assignment while maintaining -# control over 'accept_ra'. +# dhcpcd on raspberry Pi enables IPv6 support by default. The problem with +# dhcpcd is that it does't support Route Information Option (RIO), so we need +# to rely on the kernel implementation. dhcpcd will force set accept_ra to 0 +# for all interfaces it is currently running on, if IPv6 RS is enabled. This +# conflicts with our accept_ra* configurations. # dhcpcd_disable_ipv6() { diff --git a/script/_dhcpv6_pd_ref b/script/_dhcpv6_pd_ref index d6d74eeab14..008170fc2f5 100644 --- a/script/_dhcpv6_pd_ref +++ b/script/_dhcpv6_pd_ref @@ -1,12 +1,41 @@ #!/bin/bash +# +# Copyright (c) 2024, The OpenThread Authors. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# 3. Neither the name of the copyright holder nor the +# names of its contributors may be used to endorse or promote products +# derived from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# +# Description: +# This script sets up border routing configurations. +# customise_dhcpcd_conf() { # This has to be run after script/_border_routing, and this will # invalidate all changes to dhcpcd.conf made by script/_border_routing. sudo tee /etc/dhcpcd.conf >/dev/null < Date: Tue, 15 Oct 2024 05:50:30 +0000 Subject: [PATCH 08/10] semi-automated PD on raspbian scripts: comment and naming update --- script/_border_routing | 4 ++-- script/_dhcpv6_pd_ref | 2 +- script/reference-device/dhcpcd.enter-hook | 3 --- script/reference-device/dhcpcd.exit-hook | 3 --- 4 files changed, 3 insertions(+), 9 deletions(-) diff --git a/script/_border_routing b/script/_border_routing index 88febb1ba06..712de6d6160 100644 --- a/script/_border_routing +++ b/script/_border_routing @@ -76,7 +76,7 @@ accept_ra_enable() # for all interfaces it is currently running on, if IPv6 RS is enabled. This # conflicts with our accept_ra* configurations. # -dhcpcd_disable_ipv6() +dhcpcd_disable_ipv6rs() { if [ -f $DHCPCD_CONF_FILE ]; then sudo cp $DHCPCD_CONF_FILE $DHCPCD_CONF_BACKUP_FILE @@ -106,7 +106,7 @@ border_routing_install() { with BORDER_ROUTING || return 0 - dhcpcd_disable_ipv6 + dhcpcd_disable_ipv6rs accept_ra_install # /proc/sys/net/ipv6/conf/* files are read-only in docker diff --git a/script/_dhcpv6_pd_ref b/script/_dhcpv6_pd_ref index 008170fc2f5..b431ce625da 100644 --- a/script/_dhcpv6_pd_ref +++ b/script/_dhcpv6_pd_ref @@ -27,7 +27,7 @@ # POSSIBILITY OF SUCH DAMAGE. # # Description: -# This script sets up border routing configurations. +# This script manipulates DHCPv6-PD-REF configuration. # customise_dhcpcd_conf() diff --git a/script/reference-device/dhcpcd.enter-hook b/script/reference-device/dhcpcd.enter-hook index bd565188adc..7a9fd98b108 100644 --- a/script/reference-device/dhcpcd.enter-hook +++ b/script/reference-device/dhcpcd.enter-hook @@ -26,9 +26,6 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # -# Description: -# This script sets up border routing configurations. -# # TODO: set the upstream interface according to the environment variables of `script/setup`. UPSTREAM_INTERFACE="eth0" diff --git a/script/reference-device/dhcpcd.exit-hook b/script/reference-device/dhcpcd.exit-hook index 8708addd43b..e11259f90cf 100644 --- a/script/reference-device/dhcpcd.exit-hook +++ b/script/reference-device/dhcpcd.exit-hook @@ -26,9 +26,6 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. # -# Description: -# This script sets up border routing configurations. -# # TODO: set the upstream interface according to the environment variables of `script/setup`. UPSTREAM_INTERFACE="eth0" From b1ed4819f0aba05e13c5c7bc2351efe1d29d38bb Mon Sep 17 00:00:00 2001 From: Yang Song Date: Tue, 15 Oct 2024 05:55:19 +0000 Subject: [PATCH 09/10] semi-automated PD on raspbian scripts: comment and naming update --- script/_border_routing | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/script/_border_routing b/script/_border_routing index 712de6d6160..e9b79c76932 100644 --- a/script/_border_routing +++ b/script/_border_routing @@ -86,8 +86,8 @@ EOF fi } -# This function enables IPv6 support in dhcpcd. -dhcpcd_enable_ipv6() +# This function enables IPv6 Router Solicitation (RS) in dhcpcd. +dhcpcd_enable_ipv6rs() { if [ -f $DHCPCD_CONF_BACKUP_FILE ]; then sudo cp $DHCPCD_CONF_BACKUP_FILE $DHCPCD_CONF_FILE @@ -99,7 +99,7 @@ border_routing_uninstall() with BORDER_ROUTING || return 0 accept_ra_uninstall - dhcpcd_enable_ipv6 + dhcpcd_enable_ipv6rs } border_routing_install() From d0c2b487120ecc9d423cf3fed5a4e4cc6374af78 Mon Sep 17 00:00:00 2001 From: Yang Song Date: Tue, 15 Oct 2024 09:09:43 +0000 Subject: [PATCH 10/10] semi-automated PD on raspbian scripts: reload radvd to keep current settings --- script/reference-device/dhcpcd.enter-hook | 2 +- script/reference-device/dhcpcd.exit-hook | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/script/reference-device/dhcpcd.enter-hook b/script/reference-device/dhcpcd.enter-hook index 7a9fd98b108..cfa62800502 100644 --- a/script/reference-device/dhcpcd.enter-hook +++ b/script/reference-device/dhcpcd.enter-hook @@ -69,7 +69,7 @@ if [ ${interface} = ${UPSTREAM_INTERFACE} ]; then DELEGATED6 | REBIND6 | RENEW6 | BOUND6 ) logger "$LOG_TAG prefix is $new_dhcp6_ia_pd1_prefix1 length is $new_dhcp6_ia_pd1_prefix1_length pltime is $new_dhcp6_ia_pd1_prefix1_pltime vltime is $new_dhcp6_ia_pd1_prefix1_vltime" config_ra $new_dhcp6_ia_pd1_prefix1 $new_dhcp6_ia_pd1_prefix1_length $new_dhcp6_ia_pd1_prefix1_pltime $new_dhcp6_ia_pd1_prefix1_vltime - sudo systemctl restart radvd || logger "$LOG_TAG Failed to restart radvd" + sudo systemctl reload radvd || logger "$LOG_TAG Failed to reload radvd" ;; esac fi diff --git a/script/reference-device/dhcpcd.exit-hook b/script/reference-device/dhcpcd.exit-hook index e11259f90cf..faed780ade0 100644 --- a/script/reference-device/dhcpcd.exit-hook +++ b/script/reference-device/dhcpcd.exit-hook @@ -67,7 +67,7 @@ if [ ${interface} = ${UPSTREAM_INTERFACE} ]; then case $reason in EXPIRE6 | STOP6) config_ra $old_dhcp6_ia_pd1_prefix1 $old_dhcp6_ia_pd1_prefix1_length 0 0 - sudo systemctl restart radvd + sudo systemctl reload radvd ;; esac fi