]>
Commit | Line | Data |
---|---|---|
1 | #!/bin/bash | |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2010 Michael Tremer & Christian Schmidt # | |
6 | # # | |
7 | # This program is free software: you can redistribute it and/or modify # | |
8 | # it under the terms of the GNU General Public License as published by # | |
9 | # the Free Software Foundation, either version 3 of the License, or # | |
10 | # (at your option) any later version. # | |
11 | # # | |
12 | # This program is distributed in the hope that it will be useful, # | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
15 | # GNU General Public License for more details. # | |
16 | # # | |
17 | # You should have received a copy of the GNU General Public License # | |
18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
19 | # # | |
20 | ############################################################################### | |
21 | ||
22 | . /lib/network/header-port | |
23 | ||
24 | HOOK_SETTINGS="COST PRIORITY" | |
25 | ||
26 | function _check() { | |
27 | local i | |
28 | for i in COST PRIORITY; do | |
29 | if isset ${i}; then | |
30 | assert isinteger ${i} | |
31 | fi | |
32 | done | |
33 | } | |
34 | ||
35 | function _add() { | |
36 | local zone=${1} | |
37 | local port=${2} | |
38 | shift 2 | |
39 | ||
40 | assert isset zone | |
41 | assert isset port | |
42 | ||
43 | if ! port_exists ${port}; then | |
44 | error "Port '${port}' does not exist." | |
45 | exit ${EXIT_ERROR} | |
46 | fi | |
47 | ||
48 | config_read $(zone_dir ${zone})/ports/${port} | |
49 | ||
50 | while [ $# -gt 0 ]; do | |
51 | case "${1}" in | |
52 | --priority=*) | |
53 | PRIORITY=${1#--priority=} | |
54 | ;; | |
55 | --cost=*) | |
56 | COST=${1#--cost=} | |
57 | ;; | |
58 | esac | |
59 | shift | |
60 | done | |
61 | ||
62 | config_write $(zone_dir ${zone})/ports/${port} ${HOOK_SETTINGS} | |
63 | ||
64 | exit ${EXIT_OK} | |
65 | } | |
66 | ||
67 | function _edit() { | |
68 | _add $@ | |
69 | } | |
70 | ||
71 | function _rem() { | |
72 | local zone=${1} | |
73 | local port=${2} | |
74 | ||
75 | assert isset zone | |
76 | assert isset port | |
77 | ||
78 | assert zone_exists ${zone} | |
79 | ||
80 | if ! listmatch ${port} $(zone_get_ports ${zone}); then | |
81 | error "Port '${port}' does not belong to '${zone}'." | |
82 | error "Won't remove anything." | |
83 | exit ${EXIT_ERROR} | |
84 | fi | |
85 | ||
86 | if port_exists ${port}; then | |
87 | ( _down ${zone} ${port} ) | |
88 | fi | |
89 | ||
90 | rm -f $(zone_dir ${zone})/ports/${port} | |
91 | ||
92 | exit ${EXIT_OK} | |
93 | } | |
94 | ||
95 | function _up() { | |
96 | local zone=${1} | |
97 | local port=${2} | |
98 | ||
99 | assert isset zone | |
100 | assert isset port | |
101 | ||
102 | assert zone_exists ${zone} | |
103 | assert port_exists ${port} | |
104 | ||
105 | port_up ${port} | |
106 | ||
107 | # Set same MTU to device that the bridge has got | |
108 | device_set_mtu ${port} $(device_get_mtu ${zone}) | |
109 | ||
110 | bridge_attach_device ${zone} ${port} | |
111 | ||
112 | # XXX must set cost and prio here | |
113 | ||
114 | exit ${EXIT_OK} | |
115 | } | |
116 | ||
117 | function _down() { | |
118 | local zone=${1} | |
119 | local port=${2} | |
120 | ||
121 | assert isset zone | |
122 | assert isset port | |
123 | ||
124 | assert zone_exists ${zone} | |
125 | assert port_exists ${port} | |
126 | ||
127 | bridge_detach_device ${zone} ${port} | |
128 | ||
129 | port_down ${port} | |
130 | ||
131 | exit ${EXIT_OK} | |
132 | } | |
133 | ||
134 | function _status() { | |
135 | local zone=${1} | |
136 | local port=${2} | |
137 | ||
138 | printf " %-10s - " "${port}" | |
139 | if ! device_is_up ${port}; then | |
140 | echo -ne "${COLOUR_DOWN} DOWN ${COLOUR_NORMAL}" | |
141 | else | |
142 | local state=$(stp_port_get_state ${zone} ${port}) | |
143 | local colour="COLOUR_STP_${state}" | |
144 | printf "${!colour}%10s${COLOUR_NORMAL}" ${state} | |
145 | ||
146 | echo -n " - DSR: $(stp_port_get_designated_root ${zone} ${port})" | |
147 | echo -n " - Cost: $(stp_port_get_cost ${zone} ${port})" | |
148 | fi | |
149 | ||
150 | echo | |
151 | ||
152 | exit ${EXIT_OK} | |
153 | } | |
154 | ||
155 | run $@ |