Skip to content

Commit

Permalink
dist/tools/ethos: add setup_network.sh script
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspar030 committed Jul 15, 2019
1 parent 827d2d9 commit f74e5e7
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
16 changes: 16 additions & 0 deletions dist/tools/ethos/README.md
Expand Up @@ -13,3 +13,19 @@ To use, add

to app Makefile, "make clean all flash", then run this tool as follows:
# sudo ./ethos <tap-device> <serial>

## setup_network.sh

This script sets up a tap device, configures a prefix and starts a uhcpd server
serving that prefix towards the tap device.
The tap device will be owned by the calling user, or if called with sudo, with
the user that uses sudo. That way, ethos can use it without being root / using
sudo.

E.g., use as follows:

$ sudo ./setup_network.sh riot0 2001:db8::0/64

Keep that running, then in another shell start ethos:

$ ethos riot0 <serial>
49 changes: 49 additions & 0 deletions dist/tools/ethos/setup_network.sh
@@ -0,0 +1,49 @@
#!/bin/sh

create_tap() {
ip tuntap add ${TAP} mode tap user ${_USER}
sysctl -w net.ipv6.conf.${TAP}.forwarding=1
sysctl -w net.ipv6.conf.${TAP}.accept_ra=0
ip link set ${TAP} up
ip a a fe80::1/64 dev ${TAP}
ip a a fd00:dead:beef::1/128 dev lo
ip route add ${PREFIX} via fe80::2 dev ${TAP}
}

remove_tap() {
ip tuntap del ${TAP} mode tap
}

cleanup() {
echo "Cleaning up..."
remove_tap
ip a d fd00:dead:beef::1/128 dev lo
trap "" INT QUIT TERM EXIT
}

start_uhcpd() {
${UHCPD} ${TAP} ${PREFIX}
}

TAP=$1
PREFIX=$2
_USER=$3
: ${UHCPD:="$(readlink -f $(dirname $0)"/../uhcpd/bin")/uhcpd"}

[ -z "${TAP}" -o -z "${PREFIX}" ] && {
echo "usage: $0 <tap-device> <prefix> [<user>]"
exit 1
}

if [ -z "$_USER" ]; then
if [ -n "$SUDO_USER" ] ; then
_USER=$SUDO_USER
else
_USER=$USER
fi
fi

trap "cleanup" INT QUIT TERM EXIT


create_tap && start_uhcpd

0 comments on commit f74e5e7

Please sign in to comment.