Merge pull request #11889 from miri64/tapsetup/enh/sudo

tapsetup: require to be executed with sudo
This commit is contained in:
Francisco 2020-01-04 10:43:06 +01:00 committed by GitHub
commit f6f4469542
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 41 additions and 44 deletions

View File

@ -91,7 +91,7 @@ you can use to create a network of tap interfaces.
To create a bridge and two (or `count` at your option) tap interfaces: To create a bridge and two (or `count` at your option) tap interfaces:
./dist/tools/tapsetup/tapsetup [-c [<count>]] sudo ./dist/tools/tapsetup/tapsetup [-c [<count>]]
## CONTRIBUTE ## CONTRIBUTE

View File

@ -53,17 +53,17 @@ can use to create a network of tap interfaces.
Usage: Usage:
To create a bridge and two (or count at your option) tap interfaces: To create a bridge and two (or count at your option) tap interfaces:
../../dist/tools/tapsetup/tapsetup [-c [<count>]] sudo ../../dist/tools/tapsetup/tapsetup [-c [<count>]]
On OSX you need to start the RIOT instance at some point during the script's On OSX you need to start the RIOT instance at some point during the script's
execution. The script will instruct you when to do that. execution. The script will instruct you when to do that.
To delete the bridge and all tap interfaces: To delete the bridge and all tap interfaces:
../../dist/tools/tapsetup/tapsetup -d sudo ../../dist/tools/tapsetup/tapsetup -d
For OSX you **have** to run this after killing your RIOT instance and rerun For OSX you **have** to run this after killing your RIOT instance and rerun
`../../dist/tools/tapsetup [-c [<count>]]` before restarting. `sudo ../../dist/tools/tapsetup [-c [<count>]]` before restarting.
**Please note:** If you want to communicate between RIOT and your host **Please note:** If you want to communicate between RIOT and your host
operating system, you must not use the `tapsetup` script, but create and operating system, you must not use the `tapsetup` script, but create and

View File

@ -35,15 +35,15 @@ create_bridge() {
case "${PLATFORM}" in case "${PLATFORM}" in
FreeBSD) FreeBSD)
sudo kldload if_bridge kldload if_bridge
sudo ifconfig ${BRNAME} create || exit 1 ;; ifconfig ${BRNAME} create || exit 1 ;;
Linux) Linux)
sudo ip link add name ${BRNAME} type bridge || exit 1 ip link add name ${BRNAME} type bridge || exit 1
if [ -n "${DEACTIVATE_IPV6}" ]; then if [ -n "${DEACTIVATE_IPV6}" ]; then
sudo -s sh -c "echo 1 > /proc/sys/net/ipv6/conf/${BRNAME}/disable_ipv6" || exit 1 echo 1 > /proc/sys/net/ipv6/conf/${BRNAME}/disable_ipv6 || exit 1
fi ;; fi ;;
OSX) OSX)
sudo ifconfig ${BRNAME} create || exit 1 ;; ifconfig ${BRNAME} create || exit 1 ;;
*) *)
;; ;;
esac esac
@ -52,9 +52,9 @@ create_bridge() {
up_bridge() { up_bridge() {
case "${PLATFORM}" in case "${PLATFORM}" in
FreeBSD|OSX) FreeBSD|OSX)
sudo ifconfig ${BRNAME} up || exit 1 ;; ifconfig ${BRNAME} up || exit 1 ;;
Linux) Linux)
sudo ip link set ${BRNAME} up || exit 1 ;; ip link set ${BRNAME} up || exit 1 ;;
*) *)
;; ;;
esac esac
@ -65,17 +65,17 @@ delete_bridge() {
case "${PLATFORM}" in case "${PLATFORM}" in
FreeBSD) FreeBSD)
sudo sysctl net.link.tap.user_open=0 sysctl net.link.tap.user_open=0
sudo kldunload if_tap || exit 1 kldunload if_tap || exit 1
sudo kldunload if_bridge || exit 1 ;; kldunload if_bridge || exit 1 ;;
Linux) Linux)
for IF in $(ls /sys/class/net/${BRNAME}/brif); do for IF in $(ls /sys/class/net/${BRNAME}/brif); do
sudo ip link delete "${IF}" ip link delete "${IF}"
done done
sudo ip link delete ${BRNAME} || exit 1 ;; ip link delete ${BRNAME} || exit 1 ;;
OSX) OSX)
sudo ifconfig ${BRNAME} destroy || exit 1 ;; ifconfig ${BRNAME} destroy || exit 1 ;;
*) *)
;; ;;
esac esac
@ -84,8 +84,8 @@ delete_bridge() {
begin_tap() { begin_tap() {
case "${PLATFORM}" in case "${PLATFORM}" in
FreeBSD) FreeBSD)
sudo kldload if_tap || exit 1 kldload if_tap || exit 1
sudo sysctl net.link.tap.user_open=1 ;; sysctl net.link.tap.user_open=1 ;;
*) *)
;; ;;
esac esac
@ -95,24 +95,24 @@ create_tap() {
case "${PLATFORM}" in case "${PLATFORM}" in
FreeBSD) FreeBSD)
echo "creating ${TAPNAME}${N}" || exit 1 echo "creating ${TAPNAME}${N}" || exit 1
sudo ifconfig tap${N} create || exit 1 ifconfig tap${N} create || exit 1
sudo chown ${USER} /dev/tap${N} || exit 1 chown ${SUDO_USER} /dev/tap${N} || exit 1
sudo ifconfig ${BRNAME} addm tap${N} || exit 1 ifconfig ${BRNAME} addm tap${N} || exit 1
sudo ifconfig tap${N} up || exit 1 ;; ifconfig tap${N} up || exit 1 ;;
Linux) Linux)
echo "creating ${TAPNAME}${N}" echo "creating ${TAPNAME}${N}"
sudo ip tuntap add dev ${TAPNAME}${N} mode tap user ${USER} || exit 1 ip tuntap add dev ${TAPNAME}${N} mode tap user ${SUDO_USER} || exit 1
if [ -n "${DEACTIVATE_IPV6}" ]; then if [ -n "${DEACTIVATE_IPV6}" ]; then
sudo -s sh -c "echo 1 > /proc/sys/net/ipv6/conf/${TAPNAME}${N}/disable_ipv6" || exit 1 echo 1 > /proc/sys/net/ipv6/conf/${TAPNAME}${N}/disable_ipv6 || exit 1
fi fi
sudo ip link set dev ${TAPNAME}${N} master ${BRNAME} || exit 1 ip link set dev ${TAPNAME}${N} master ${BRNAME} || exit 1
sudo ip link set ${TAPNAME}${N} up || exit 1 ;; ip link set ${TAPNAME}${N} up || exit 1 ;;
OSX) OSX)
sudo chown ${USER} /dev/tap${N} || exit 1 chown ${SUDO_USER} /dev/tap${N} || exit 1
echo "start RIOT instance for tap${N} now and hit enter" echo "start RIOT instance for tap${N} now and hit enter"
read read
sudo ifconfig ${BRNAME} addm tap${N} || exit 1 ifconfig ${BRNAME} addm tap${N} || exit 1
sudo ifconfig tap${N} up || exit 1 ;; ifconfig tap${N} up || exit 1 ;;
*) *)
;; ;;
esac esac
@ -174,13 +174,10 @@ while true ; do
esac esac
done done
if [ -z "${USER}" ]; then if [ -z "${SUDO_USER}" ]; then
export USER=$(id -un) echo 'Environment variable $SUDO_USER required; Please run with `sudo`'
if [ -z "${USER}" ]; then
echo 'need to export $USER'
exit 1 exit 1
fi fi
fi
if [ -z "${COMMAND}" ]; then if [ -z "${COMMAND}" ]; then
COMMAND="create" COMMAND="create"
fi fi

View File

@ -62,7 +62,7 @@ call this the `native` port). Try it right now in your terminal window:
git clone git://github.com/RIOT-OS/RIOT.git # assumption: git is pre-installed git clone git://github.com/RIOT-OS/RIOT.git # assumption: git is pre-installed
cd RIOT cd RIOT
git checkout <LATEST_RELEASE> git checkout <LATEST_RELEASE>
./dist/tools/tapsetup/tapsetup # create virtual Ethernet sudo ./dist/tools/tapsetup/tapsetup # create virtual Ethernet
# interfaces to connect multiple # interfaces to connect multiple
# RIOT instances # RIOT instances
cd examples/default/ cd examples/default/

View File

@ -39,7 +39,7 @@ RIOT provides three shell to interact with the CCN-Lite stack:
An example usage of this application could be setup like this: An example usage of this application could be setup like this:
1. Open a terminal window, navigate to the RIOT directory, and enter 1. Open a terminal window, navigate to the RIOT directory, and enter
`dist/tools/tapsetup/tapsetup -c`. `sudo dist/tools/tapsetup/tapsetup -c`.
2. Open a second terminal window and navigate to this directory in both of 2. Open a second terminal window and navigate to this directory in both of
windows. windows.
3. Call `make -B clean all term` in the first terminal and `PORT=tap1 make 3. Call `make -B clean all term` in the first terminal and `PORT=tap1 make

View File

@ -12,7 +12,7 @@ Linux version of TinyDTLS. However, this is not tested yet.
Preparing the logical interfaces: Preparing the logical interfaces:
./../../dist/tools/tapsetup/tapsetup --create 2 sudo ./../../dist/tools/tapsetup/tapsetup --create 2
For the server instance: For the server instance:

View File

@ -58,7 +58,7 @@ single RIOT native instance, we can do the following:
1. Setup `tap` and `tapbr` devices using RIOT's `tapsetup` script: 1. Setup `tap` and `tapbr` devices using RIOT's `tapsetup` script:
``` ```
./RIOTDIR/dist/tools/tapsetup/tapsetup sudo ./RIOTDIR/dist/tools/tapsetup/tapsetup
``` ```
2. Assign a site-global prefix to the `tapbr0` interface (the name could be 2. Assign a site-global prefix to the `tapbr0` interface (the name could be

View File

@ -104,7 +104,7 @@ you first need to set up two tap devices and a bridge that connects
them. This constitutes a virtual network that the RIOT instances can them. This constitutes a virtual network that the RIOT instances can
use to communicate. use to communicate.
./../../dist/tools/tapsetup/tapsetup --create 2 sudo ./../../dist/tools/tapsetup/tapsetup --create 2
Then, make sure you've compiled the application by calling `make` and Then, make sure you've compiled the application by calling `make` and
start the first RIOT instance by invoking `make term`. In the RIOT start the first RIOT instance by invoking `make term`. In the RIOT

View File

@ -12,7 +12,7 @@ however show up in Wireshark, which can be confusing). So be sure to adjust your
First, create a tap interface (to which RIOT will connect) and a bridge (to which Linux will connect) from the RIOT main directory run: First, create a tap interface (to which RIOT will connect) and a bridge (to which Linux will connect) from the RIOT main directory run:
./dist/tools/tapsetup/tapsetup -c 1 sudo ./dist/tools/tapsetup/tapsetup -c 1
Now you can start the `gnrc_tftp` example by invoking `make term`. This should automatically connect to the `tap0` interface. If Now you can start the `gnrc_tftp` example by invoking `make term`. This should automatically connect to the `tap0` interface. If
this doesn't work for some reason, run `make` without any arguments, and then run the binary manually like so (assuming you are in the `examples/gnrc_tftp` directory): this doesn't work for some reason, run `make` without any arguments, and then run the binary manually like so (assuming you are in the `examples/gnrc_tftp` directory):

View File

@ -8,7 +8,7 @@ Any board with a default netdev can be used to run this example.
Create `tap` and `tapbr` devices using RIOT's `tapsetup` script before stating the application: Create `tap` and `tapbr` devices using RIOT's `tapsetup` script before stating the application:
```bash ```bash
./RIOTDIR/dist/tools/tapsetup/tapsetup sudo ./RIOTDIR/dist/tools/tapsetup/tapsetup
``` ```
Then run the application on 2 different terminals : Then run the application on 2 different terminals :