Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dist/tools/ethos: add setup_network.sh script #11816

Merged
merged 1 commit into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions dist/tools/ethos/README.md
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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