]>
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 | ||
24 | HOOK_SETTINGS="HOOK DEVICE" | |
25 | ||
26 | function _check() { | |
711ffac1 MT |
27 | assert isset DEVICE_MAC |
28 | assert ismac DEVICE_MAC | |
1848564d MT |
29 | } |
30 | ||
31 | function _create() { | |
32 | local zone=${1} | |
33 | local device=${2} | |
34 | shift 2 | |
35 | ||
36 | if [ -z "${device}" ]; then | |
37 | error "No device given." | |
38 | exit ${EXIT_ERROR} | |
39 | fi | |
40 | ||
41 | if ! device_exists ${device}; then | |
42 | warning "Device does not exist." | |
43 | fi | |
44 | ||
45 | DEVICE=$(macify ${device}) | |
46 | ||
47 | config_write $(zone_dir ${zone})/port.${HOOK}.$(device_hash ${device}) ${HOOK_SETTINGS} | |
48 | ||
49 | exit ${EXIT_OK} | |
50 | } | |
51 | ||
52 | function _up() { | |
53 | local zone=${1} | |
54 | local port=${2} | |
55 | ||
711ffac1 MT |
56 | assert isset zone |
57 | assert isset port | |
1848564d | 58 | |
711ffac1 MT |
59 | assert zone_exists ${zone} |
60 | assert port_exists ${port} | |
1848564d | 61 | |
711ffac1 | 62 | port_up ${port} |
1848564d MT |
63 | |
64 | # Set same MTU to device that the bridge has got | |
711ffac1 | 65 | device_set_mtu ${port} $(device_get_mtu ${zone}) |
1848564d | 66 | |
711ffac1 | 67 | bridge_attach_device ${zone} ${port} |
1848564d MT |
68 | |
69 | exit ${EXIT_OK} | |
70 | } | |
71 | ||
72 | function _down() { | |
73 | local zone=${1} | |
74 | local port=${2} | |
75 | ||
711ffac1 MT |
76 | assert isset zone |
77 | assert isset port | |
1848564d | 78 | |
711ffac1 MT |
79 | assert zone_exists ${zone} |
80 | assert port_exists ${port} | |
1848564d | 81 | |
711ffac1 | 82 | bridge_detach_device ${zone} ${port} |
1848564d | 83 | |
711ffac1 | 84 | port_down ${port} |
1848564d MT |
85 | |
86 | exit ${EXIT_OK} | |
87 | } | |
88 | ||
73c67755 MT |
89 | function _status() { |
90 | local zone=${1} | |
91 | local port=${2} | |
92 | ||
711ffac1 MT |
93 | printf " %-10s - " "${port}" |
94 | if ! device_is_up ${port}; then | |
73c67755 MT |
95 | echo -ne "${COLOUR_DOWN} DOWN ${COLOUR_NORMAL}" |
96 | else | |
711ffac1 | 97 | local state=$(stp_port_state ${zone} ${port}) |
73c67755 MT |
98 | local colour="COLOUR_STP_${state}" |
99 | printf "${!colour}%10s${COLOUR_NORMAL}" ${state} | |
711ffac1 MT |
100 | |
101 | echo -n " - DSR: $(stp_port_designated_root ${zone} ${port})" | |
102 | echo -n " - Cost: $(stp_port_pathcost ${zone} ${port})" | |
73c67755 | 103 | fi |
711ffac1 | 104 | |
73c67755 MT |
105 | echo |
106 | ||
107 | exit ${EXIT_OK} | |
108 | } | |
109 | ||
1848564d | 110 | run $@ |