]>
Commit | Line | Data |
---|---|---|
1848564d MT |
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 | ||
943e3f7e | 24 | HOOK_SETTINGS="COST PRIORITY" |
1848564d MT |
25 | |
26 | function _check() { | |
943e3f7e MT |
27 | local i |
28 | for i in COST PRIORITY; do | |
29 | if isset ${i}; then | |
30 | assert isinteger ${i} | |
31 | fi | |
32 | done | |
1848564d MT |
33 | } |
34 | ||
943e3f7e | 35 | function _add() { |
1848564d | 36 | local zone=${1} |
943e3f7e | 37 | local port=${2} |
1848564d MT |
38 | shift 2 |
39 | ||
943e3f7e MT |
40 | assert isset zone |
41 | assert isset port | |
42 | ||
43 | if ! port_exists ${port}; then | |
44 | error "Port '${port}' does not exist." | |
1848564d MT |
45 | exit ${EXIT_ERROR} |
46 | fi | |
47 | ||
943e3f7e | 48 | config_read $(zone_dir ${zone})/ports/${port} |
1848564d | 49 | |
943e3f7e MT |
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 | |
1848564d | 61 | |
943e3f7e | 62 | config_write $(zone_dir ${zone})/ports/${port} ${HOOK_SETTINGS} |
1848564d MT |
63 | |
64 | exit ${EXIT_OK} | |
65 | } | |
66 | ||
943e3f7e MT |
67 | function _edit() { |
68 | _add $@ | |
69 | } | |
70 | ||
1848564d MT |
71 | function _up() { |
72 | local zone=${1} | |
73 | local port=${2} | |
74 | ||
711ffac1 MT |
75 | assert isset zone |
76 | assert isset port | |
1848564d | 77 | |
711ffac1 MT |
78 | assert zone_exists ${zone} |
79 | assert port_exists ${port} | |
1848564d | 80 | |
711ffac1 | 81 | port_up ${port} |
1848564d MT |
82 | |
83 | # Set same MTU to device that the bridge has got | |
711ffac1 | 84 | device_set_mtu ${port} $(device_get_mtu ${zone}) |
1848564d | 85 | |
711ffac1 | 86 | bridge_attach_device ${zone} ${port} |
1848564d | 87 | |
943e3f7e MT |
88 | # XXX must set cost and prio here |
89 | ||
1848564d MT |
90 | exit ${EXIT_OK} |
91 | } | |
92 | ||
93 | function _down() { | |
94 | local zone=${1} | |
95 | local port=${2} | |
96 | ||
711ffac1 MT |
97 | assert isset zone |
98 | assert isset port | |
1848564d | 99 | |
711ffac1 MT |
100 | assert zone_exists ${zone} |
101 | assert port_exists ${port} | |
1848564d | 102 | |
711ffac1 | 103 | bridge_detach_device ${zone} ${port} |
1848564d | 104 | |
711ffac1 | 105 | port_down ${port} |
1848564d MT |
106 | |
107 | exit ${EXIT_OK} | |
108 | } | |
109 | ||
73c67755 MT |
110 | function _status() { |
111 | local zone=${1} | |
112 | local port=${2} | |
113 | ||
711ffac1 MT |
114 | printf " %-10s - " "${port}" |
115 | if ! device_is_up ${port}; then | |
73c67755 MT |
116 | echo -ne "${COLOUR_DOWN} DOWN ${COLOUR_NORMAL}" |
117 | else | |
711ffac1 | 118 | local state=$(stp_port_state ${zone} ${port}) |
73c67755 MT |
119 | local colour="COLOUR_STP_${state}" |
120 | printf "${!colour}%10s${COLOUR_NORMAL}" ${state} | |
711ffac1 MT |
121 | |
122 | echo -n " - DSR: $(stp_port_designated_root ${zone} ${port})" | |
123 | echo -n " - Cost: $(stp_port_pathcost ${zone} ${port})" | |
73c67755 | 124 | fi |
711ffac1 | 125 | |
73c67755 MT |
126 | echo |
127 | ||
128 | exit ${EXIT_OK} | |
129 | } | |
130 | ||
1848564d | 131 | run $@ |