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

Subversion Repositories openrisc

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

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

Line No. Rev Author Line
1 440 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 461 jeremybenn
# Usage: ./brend.sh <bridge> <eth> <tap>
30 440 jeremybenn
 
31
# - <bridge> is the bridge interface to use, e.g. br0
32
# - <eth> is the hardware ethernet interface to use, e.g. eth0
33 461 jeremybenn
# - <tap> is the tap interface to use, e.g. tap0
34 440 jeremybenn
 
35 461 jeremybenn
# Check we have the right number of arguments
36
if [ "x$#" != "x3" ]
37
then
38
    echo "Usage: ./brend.sh <bridge> <eth> <tap>"
39
    exit 1
40
fi
41 440 jeremybenn
 
42 461 jeremybenn
# 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 440 jeremybenn
 
50 461 jeremybenn
# Break out the arguments
51 440 jeremybenn
br=$1
52 461 jeremybenn
eth=$2
53
tap=$3
54 440 jeremybenn
 
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 461 jeremybenn
# 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 440 jeremybenn
 
74 461 jeremybenn
# Take down the bridge and delete it
75
ifconfig ${br} down
76 440 jeremybenn
 
77 461 jeremybenn
if [ $? != 0 ]
78
then
79
    echo "Failed to take down ${br}"
80
    exit 1
81
fi
82 440 jeremybenn
 
83 461 jeremybenn
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. We could use ifconfig with the IP address,
104 508 jeremybenn
# netmask and broadcast mask from earlier, but this does not work in a DHCP
105
# world (the MAC has changed). Instead we use a single shot dhcp
106
# configuration. In future the extant eth0 dhclient will refresh the lease.
107 461 jeremybenn
dhclient -1 -d ${eth0}
108
 
109
if [ $? != 0 ]
110
then
111
    echo "Failed to get lease for ${eth}"
112
    exit 1
113
fi
114
 
115
# Kill the outstanding br0 DHCL client
116
kill `ps ax | grep "dhclient.*${br}" | grep -v "grep" | cut -c 1-5`

powered by: WebSVN 2.1.0

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