OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [brend-static.sh] - Blame information for rev 760

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 508 jeremybenn
#!/bin/bash
2
 
3
# Copyright (C) 2010 ORSoC AB
4
# Copyright (C) 2010 Embecosm Limited
5
 
6
# Contributor Julius Baxter <julius.baxter@orsoc.se>
7
# Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
8
 
9
# This file is a superuser script to close down an Ethernet bridge and restore
10
# the simple Ethernet interface.
11
 
12
# This program is free software; you can redistribute it and/or modify it
13
# under the terms of the GNU General Public License as published by the Free
14
# Software Foundation; either version 3 of the License, or (at your option)
15
# any later version.
16
 
17
# This program is distributed in the hope that it will be useful, but WITHOUT
18
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
19
# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
20
# more details.
21
 
22
# You should have received a copy of the GNU General Public License along
23
# with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 
25
# ------------------------------------------------------------------------------
26
 
27
# Pre-requisites: bridge-utils must be installed.
28
 
29
# Usage: ./brend-static.sh <bridge> <eth> <tap>
30
 
31
# - <bridge> is the bridge interface to use, e.g. br0
32
# - <eth> is the hardware ethernet interface to use, e.g. eth0
33
# - <tap> is the tap interface to use, e.g. tap0
34
 
35
# Check we have the right number of arguments
36
if [ "x$#" != "x3" ]
37
then
38
    echo "Usage: ./brend-static.sh <bridge> <eth> <tap>"
39
    exit 1
40
fi
41
 
42
# Check we are root
43
euid=`id -un`
44
if [ "x${euid}" != "xroot" ]
45
then
46
    echo "Must run as root"
47
    exit 1
48
fi
49
 
50
# Break out the arguments
51
br=$1
52
eth=$2
53
tap=$3
54
 
55
# Determine the IP address, netmask and broadcast of the bridge.
56
eth_ip=`ifconfig $br | \
57
        grep "inet addr" | \
58
        head -1 | \
59
        sed -e 's/^.*inet addr:\([^ \t]*\).*$/\1/'`
60
eth_netmask=`ifconfig $br | \
61
        grep "Mask" | \
62
        head -1 | \
63
        sed -e 's/^.*Mask:\([^ \t]*\).*$/\1/'`
64
eth_broadcast=`ifconfig $br | \
65
        grep "Bcast" | \
66
        head -1 | \
67
        sed -e 's/^.*Bcast:\([^ \t]*\).*$/\1/'`
68
 
69
# Close the firewall to the tap and bridge
70
iptables -D INPUT -i ${tap} -j ACCEPT
71
iptables -D INPUT -i ${br} -j ACCEPT
72
iptables -D FORWARD -i ${br} -j ACCEPT
73
 
74
# Take down the bridge and delete it
75
ifconfig ${br} down
76
 
77
if [ $? != 0 ]
78
then
79
    echo "Failed to take down ${br}"
80
    exit 1
81
fi
82
 
83
brctl delbr ${br}
84
 
85
if [ $? != 0 ]
86
then
87
    echo "Failed to take delete ${br}"
88
    exit 1
89
fi
90
 
91
# Delete the TAP interface. Note we mustn't have anything using it. It's
92
# rather harsh, but we use fuser to ensure this (it will take out all users of
93
# any TAP/TUN interface).
94
fuser -k /dev/net/tun
95
openvpn --rmtun --dev ${tap}
96
 
97
if [ $? != 0 ]
98
then
99
    echo "Failed to remove ${tap}"
100
    exit 1
101
fi
102
 
103
# Restore the Ethernet interface, using the IP address, netmask and broadcast
104
# mask from earlier.
105
ifconfig ${eth} ${eth_ip} netmask ${eth_netmask} broadcast ${eth_broadcast}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.