1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-12-24 22:13:52 +01:00

Merge pull request #13668 from benpicco/tools/radvd

tools/radvd: Add script to run radvd on a tun interface
This commit is contained in:
benpicco 2020-07-01 16:06:24 +02:00 committed by GitHub
commit adc0a3cb8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 115 additions and 0 deletions

9
dist/tools/radvd/radvd.conf vendored Normal file
View File

@ -0,0 +1,9 @@
interface ${TAP}
{
AdvSendAdvert on;
prefix ${PREFIX}
{
AdvOnLink on;
AdvAutonomous on;
};
};

106
dist/tools/radvd/radvd.sh vendored Executable file
View File

@ -0,0 +1,106 @@
#!/bin/sh
CURRENT_DIR="$(dirname $(readlink -f $0))"
PIDFILE="/tmp/radvd-${SUDO_USER}.pid"
stop_radvd() {
if [ -f "${PIDFILE}" ]; then
PID=$(cat ${PIDFILE})
fi
if [ -n "${PID}" ]; then
kill ${PID}
rm ${PIDFILE}
echo "radvd stopped"
fi
}
start_radvd() {
export TAP
export PREFIX
cat ${CURRENT_DIR}/radvd.conf | envsubst | radvd -C /dev/stdin -u ${SUDO_USER} -p ${PIDFILE}
if [ $? -ne 0 ]; then
echo "radvd failed to start on ${TAP} with prefix ${PREFIX}"
exit 1
else
echo "radvd running on ${TAP}"
fi
}
usage() {
echo "usage: $0 [options]" >&2
echo "Options:" >&2
echo " -c <tap-device> <prefix>: Start radvd on <tap-device>, advertising <prefix>" >&2
echo " -d, --delete: Stop radvd" >&2
}
if ! command -v radvd > /dev/null; then
echo "Router Advertisement Daemon 'radvd' not found." >&2
echo "Please install 'radvd' on your operating system." >&2
exit 1
fi
while true ; do
case "$1" in
-c|--create)
if [ -n "${COMMAND}" ]; then
usage
exit 2
fi
COMMAND="create"
shift
case "$1" in
"")
usage
exit 2 ;;
*)
TAP="$1"
shift 1 ;;
esac
case "$1" in
"")
usage
exit 2 ;;
*)
PREFIX="$1"
shift 1 ;;
esac ;;
-d|--delete)
if [ -n "${COMMAND}" ]; then
usage
exit 2
fi
COMMAND="delete"
shift ;;
-h|--help)
usage
exit ;;
"")
break ;;
*) usage
exit 2 ;;
esac
done
if [ -z "${SUDO_USER}" ]; then
echo 'Environment variable $SUDO_USER required; Please run with `sudo`'
exit 1
fi
if [ -z "${COMMAND}" ]; then
COMMAND="create"
fi
if [ "${COMMAND}" = 'create' ]; then
[ -z "${TAP}" -o -z "${PREFIX}" ] && {
usage
exit 1
}
stop_radvd
start_radvd || exit 1
elif [ "${COMMAND}" = 'delete' ]; then
stop_radvd || exit 1
else
echo 'unknown command'
exit 1
fi