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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [brstart-static.sh] - Blame information for rev 757

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 set up an Ethernet bridge that can be
10
# used with Or1ksim via the TUN/TAP 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: ./brstart-static.sh <username> <groupname> <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/are the persistent TAP interface(s)
34
 
35
# Check we have the right number of arguments
36
if [ "x$#" != "x5" ]
37
then
38
    echo "Usage: ./brstart-static.sh <username> <groupname> <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
username=$1
52
groupname=$2
53
br=$3
54
eth=$4
55
tap=$5
56
 
57
# Determine the IP address, netmask and broadcast of the current Ethernet
58
# interface. This is used if the bridge is set up manually, rather than using
59
# DHCP.
60
eth_ip=`ifconfig $eth | \
61
        grep "inet addr" | \
62
        head -1 | \
63
        sed -e 's/^.*inet addr:\([^ \t]*\).*$/\1/'`
64
eth_netmask=`ifconfig $eth | \
65
        grep "Mask" | \
66
        head -1 | \
67
        sed -e 's/^.*Mask:\([^ \t]*\).*$/\1/'`
68
eth_broadcast=`ifconfig $eth | \
69
        grep "Bcast" | \
70
        head -1 | \
71
        sed -e 's/^.*Bcast:\([^ \t]*\).*$/\1/'`
72
 
73
# Create the TAP interface
74
openvpn --mktun --dev ${tap} --user ${username} --group ${groupname}
75
 
76
if [ $? != 0 ]
77
then
78
    echo "Failed to create ${tap}"
79
    exit 1
80
fi
81
 
82
# Create the bridge
83
brctl addbr ${br}
84
 
85
if [ $? != 0 ]
86
then
87
    echo "Failed to create ${br}"
88
    exit 1
89
fi
90
 
91
# Add the host Ethernet and TAP interfaces, removing the IP addresses of the
92
# underlying interfaces.
93
for i in ${eth} ${tap}
94
do
95
    # Add the interface
96
    brctl addif ${br} ${i}
97
 
98
    if [ $? != 0 ]
99
    then
100
        echo "Failed to create ${i}"
101
        exit 1
102
    fi
103
 
104
    # Remove the IP address
105
    ifconfig ${i} 0.0.0.0 promisc up
106
 
107
    if [ $? != 0 ]
108
    then
109
        echo "Failed to remove IP interface of ${i}"
110
        exit 1
111
    fi
112
done
113
 
114
# Reconfigure the bridge to have the original IP address, netmask and
115
# broadcast mask
116
ifconfig ${br} ${eth_ip} netmask ${eth_netmask} broadcast ${eth_broadcast}
117
 
118
# Open up firewall to the tap and bridge. We have a generic reject at the end
119
# of the chain, so we insert these at the start.
120
iptables -I INPUT 1 -i ${tap} -j ACCEPT
121
iptables -I INPUT 1 -i ${br} -j ACCEPT
122
iptables -I FORWARD 1 -i ${br} -j ACCEPT

powered by: WebSVN 2.1.0

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