-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathbridge-default-route
More file actions
executable file
·114 lines (109 loc) · 2.62 KB
/
bridge-default-route
File metadata and controls
executable file
·114 lines (109 loc) · 2.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/bash
# Script to create a bridge for the default route
# Copyright (C) 2014 docbill@gmail.com
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
METRIC=1
CTL=default
eval $(route -n |tr '\t' ' '|sed -n -e 's,^0\.0\.0\.0 *\([0-9.][0-9.]*\) *0\.0\.0\.0 *UG *\([0-9][0-9]*\) .* \([^ ]*\)$,XMETRIC=\2;GATEWAY=\1;INTERFACE=\3,p'|sort -n|head)
needUsage=0
BRIDGE="$1"
shift
while [ $# -gt 0 ]
do
option="$1"
case "$1" in
[Cc][Tt][Ll] )
shift
CTL="$1"
;;
[Gg][Aa][Tt]* )
shift
GATEWAY="$1"
;;
[Mm][Ee][Tt]* )
shift
METRIC="$1"
;;
[Dd][Ee][Vv]* )
shift
INTERFACE="$1"
;;
*)
needUsage=1
echo "Unrecognized option '$1'" 1>&2
;;
esac
shift
done
if [ $needUsage -eq 0 ]
then
if [ -z "$BRIDGE" ]
then
needUsage=1
echo "Unknown bridge" 1>&2
elif [ -z "$CTL" ]
then
needUsage=1
echo "Unknown ctl" 1>&2
elif [ -z "$GATEWAY" ]
then
needUsage=1
echo "Unknown gateway" 1>&2
elif [ -z "$METRIC" ]
then
needUsage=1
echo "Unknown metric" 1>&2
elif [ -z "$INTERFACE" ]
then
needUsage=1
echo "Unknown dev" 1>&2
fi
fi
if [ $needUsage -eq 1 ]
then
echo "Usage: "\""$0"\"" <BRIDGE> [ctl <brctl|ovs-vsctl>] [gateway <GATEWAY>] \\ " 1>&2
echo " [metric <METRIC>] [dev <INTEFACE>]" 1>&2
echo " " 1>&2
echo "Creates a new bridge and routes the network through that bridge." 1>&2
echo "e.g. " 1>&2
echo \""$0"\"" br0 ctl ovs-vsctl gateway 172.31.253.1 metric 1 dev em1" 1>&2
exit 1
fi
b0=${0#*/}
if [ "$CTL" = "default" ]
then
if ( ovs-vsctl list-br 2>>/dev/null 1>>/dev/null )
then
CTL=ovs-vsctl
else
CTL=brctl
fi
fi
if [ "$CTL" = "ovs-vsctl" ]
then
ovs-vsctl add-br "$BRIDGE"
else
brctl addbr "$BRIDGE"
fi
ifconfig "$BRIDGE" up
if [ "$CTL" = "ovs-vsctl" ]
then
ovs-vsctl add-port "$BRIDGE" "$INTERFACE"
else
brctl addif "$BRIDGE" "$INTERFACE"
fi
ifconfig "$INTERFACE" 0
dhclient -r "$INTERFACE"
dhclient "$BRIDGE"
route add -host $GATEWAY metric "$METRIC" dev "$BRIDGE"