#!/bin/bash # # Copyright (c) 2017, 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 manipulates DHCPv6-PD configuration. # # # Currently solution was verified only on raspbian. # if [ "$PLATFORM" = "ubuntu" ]; then WAN_INTERFACE="enp0s3" else WAN_INTERFACE="eth0" fi WLAN_INTERFACE="wlan0" WPAN_INTERFACE="wpan0" DHCPCD_CONF="/etc/dhcpcd.conf" DHCPCD_CONF_BACKUP="$DHCPCD_CONF.orig" NCP_STATE_NOTIFIER="/usr/sbin/ncp_state_notifier" NCP_STATE_DISPATCHER="/etc/ncp_state_notifier/dispatcher.d" NCP_STATE_NOTIFIER_SERVICE_NAME="ncp_state_notifier.service" NCP_STATE_NOTIFIER_SERVICE="/etc/systemd/system/${NCP_STATE_NOTIFIER_SERVICE_NAME}" DHCPCD_RELOADER="${NCP_STATE_DISPATCHER}/dhcpcd_reloader" without DHCPV6_PD || test "$PLATFORM" = beagleboneblack || test "$PLATFORM" = raspbian || test "$PLATFORM" = ubuntu || die "DHCPv6-PD is not tested under $PLATFORM." create_dhcpcd_conf_with_dhcpv6_pd() { sudo tee ${DHCPCD_CONF} < "/tmp/\${NAME}.pid" if [ -z \${IFACE} ]; then IFACE=${WPAN_INTERFACE} fi OTBR_PATH="/io/openthread/BorderRouter/\${IFACE}" WATCH1="type='signal', interface=org.freedesktop.DBus.Properties, path=\${OTBR_PATH}, member='PropertiesChanged'" notify_about_state() { logger -t "\${NAME}[\${PID}]" "Notifying about change state to: \${1} on the interface: \${2}" for SCRIPT in \`find \${DISPATCHER_PATH} -type f\`; do logger -t "\${NAME}[\${PID}]" "Running script: \${SCRIPT}" .\${SCRIPT} \${1} \${2} done } process_output() { local NEXT_LINE_IS_STATE=0 while read -r LINE; do if echo \${LINE} | grep -q "NCP:State"; then NEXT_LINE_IS_STATE=1 continue fi if [ \${NEXT_LINE_IS_STATE} -eq 1 ]; then NEXT_LINE_IS_STATE=1 STATE=\`echo \${LINE} | cut -d'"' -f2\` notify_about_state \${STATE} \${IFACE} fi done } dbus-monitor --system "\${WATCH1}" | process_output EOF } create_dhcpcd_reloader_script() { sudo tee ${DHCPCD_RELOADER} <