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

Subversion Repositories openrisc

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

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 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 461 jeremybenn
# Usage: ./brstart.sh <username> <groupname> <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
# - <tap> is/are the persistent TAP interface(s)
34
 
35 461 jeremybenn
# Check we have the right number of arguments
36
if [ "x$#" != "x5" ]
37
then
38
    echo "Usage: ./brstart.sh <username> <groupname> <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
username=$1
52
groupname=$2
53
br=$3
54
eth=$4
55
tap=$5
56 440 jeremybenn
 
57 461 jeremybenn
# 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 440 jeremybenn
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 461 jeremybenn
# Create the TAP interface
74
openvpn --mktun --dev ${tap} --user ${username} --group ${groupname}
75 440 jeremybenn
 
76 461 jeremybenn
if [ $? != 0 ]
77
then
78
    echo "Failed to create ${tap}"
79
    exit 1
80
fi
81 440 jeremybenn
 
82
# Create the bridge
83 461 jeremybenn
brctl addbr ${br}
84 440 jeremybenn
 
85 461 jeremybenn
if [ $? != 0 ]
86
then
87
    echo "Failed to create ${br}"
88
    exit 1
89
fi
90 440 jeremybenn
 
91 461 jeremybenn
# 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 440 jeremybenn
 
98 461 jeremybenn
    if [ $? != 0 ]
99
    then
100
        echo "Failed to create ${i}"
101
        exit 1
102
    fi
103 440 jeremybenn
 
104 461 jeremybenn
    # 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 440 jeremybenn
done
113
 
114 461 jeremybenn
# Reconfigure the bridge to have the appropriate Ethernet address. This uses
115
# dhclient to get the information from DHCP, but we could instead use
116
# ifconfig and the data about the original IP address, netmask and broadcast
117
# mask as follows:
118
#   ifconfig ${br} ${eth_ip} netmask ${eth_netmask} broadcast ${eth_broadcast}
119
dhclient ${br}
120
 
121
# Open up firewall to the tap and bridge. We have a generic reject at the end
122
# of the chain, so we insert these at the start.
123
iptables -I INPUT 1 -i ${tap} -j ACCEPT
124
iptables -I INPUT 1 -i ${br} -j ACCEPT
125
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.