1
0
mirror of https://github.com/wfjm/w11.git synced 2026-01-16 16:48:03 +00:00
wfjm.w11/tools/bin/ip_create_tap
Walter F.J. Mueller f5aa586d20 tools for setting up ethernet bridge and tap
- add ip_create_br: create bride and convert default ethernet interface
  - add ip_create_tap: create use-mode tap device
  - add ip_inspect: helper script
2017-05-07 18:23:35 +02:00

52 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
# $Id: ip_create_tap 873 2017-04-14 11:56:29Z mueller $
#
# Copyright 2017- by Walter F.J. Mueller <W.F.J.Mueller@gsi.de>
# License disclaimer see License.txt in $RETROBASE directory
#
# Revision History:
# Date Rev Version Comment
# 2017-04-14 873 1.0 Initial version
# 2017-03-04 858 0.5 First draft
#
tap=${1:-tap0}
if ifconfig | grep -q "${tap}\s*Link"
then
echo "tap ${tap} already exists"
exit 1
fi
ifconfig | grep -q "br0\s*Link"
if [ $? != 0 ]
then
echo "ip_create_tap-I: create bridge br0"
ip_create_br
fi
# sanitize PATH, use what sudo has
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
which_ifconfig=$(which ifconfig)
which_tunctl=$(which tunctl)
which_brctl=$(which brctl)
if [[ -z "$which_ifconfig" || -z "$which_tunctl" || -z "$which_brctl" ]]
then
echo "ip_create_br-E: ifconfig, brctl, or route not in PATH"
exit 1
fi
# print info so that sudo password prompt is expected
if [[ $(id -u) -ne 0 ]] ; then echo "ip_create_br-I: requires sudo" ; fi
sudo $which_tunctl -t ${tap} -u $USER
sudo $which_ifconfig ${tap} up
# bridge in the tap device
sudo $which_brctl addif br0 ${tap}
sudo $which_ifconfig ${tap} 0.0.0.0
#
$which_ifconfig ${tap}