1#!/bin/sh 2# 3# Copyright (c) 2016 Intel Corporation 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16 17# Run radvd in a loop. This way we can restart qemu and do not need 18# to manually restart radvd process. 19 20PID_DIR=/var/run/radvd 21PID_FILE=$PID_DIR/radvd.pid 22 23ip link | grep tap0 > /dev/null 2>&1 24if [ $? -eq 0 ]; then 25 CONF_FILE=radvd_slip.conf 26else 27 ip link | grep zeth > /dev/null 2>&1 28 if [ $? -eq 0 ]; then 29 CONF_FILE=radvd_native_posix.conf 30 else 31 echo "Cannot find suitable network interface to run radvd" 32 exit 3 33 fi 34fi 35 36if [ ! -f $CONF_FILE ]; then 37 if [ ! -f $ZEPHYR_BASE/../net-tools/$CONF_FILE ]; then 38 echo "Cannot find $CONF_FILE file." 39 exit 1 40 fi 41 DIR=$ZEPHYR_BASE/../net-tools 42else 43 DIR=. 44fi 45 46if [ ! -f $DIR/$CONF_FILE ] ;then 47 echo "No such config file $DIR/$CONF_FILE found." 48 exit 4 49fi 50 51if [ ! -s $DIR/$CONF_FILE ]; then 52 echo "Config file $DIR/$CONF_FILE is empty." 53 exit 4 54fi 55 56if [ `id -u` != 0 ]; then 57 echo "Run this script as a root user!" 58 exit 2 59fi 60 61STOPPED=0 62trap ctrl_c INT TERM 63 64ctrl_c() { 65 STOPPED=1 66 kill `cat $PID_FILE` 67} 68 69mkdir -p $PID_DIR 70 71while [ $STOPPED -eq 0 ]; do 72 radvd -n -C $DIR/$CONF_FILE -m stderr -p $PID_FILE -u root 73done 74