]>
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 | ||
f41fa3d7 | 22 | . /usr/lib/network/header-port |
1848564d | 23 | |
943e3f7e | 24 | HOOK_SETTINGS="COST PRIORITY" |
1848564d | 25 | |
2181765d | 26 | function hook_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 | ||
2181765d | 35 | function hook_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 | ||
2181765d MT |
67 | function hook_edit() { |
68 | hook_add $@ | |
943e3f7e MT |
69 | } |
70 | ||
2181765d | 71 | function hook_remove() { |
c077c723 MT |
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 | ||
2181765d | 95 | function hook_up() { |
1848564d MT |
96 | local zone=${1} |
97 | local port=${2} | |
98 | ||
711ffac1 MT |
99 | assert isset zone |
100 | assert isset port | |
1848564d | 101 | |
711ffac1 MT |
102 | assert zone_exists ${zone} |
103 | assert port_exists ${port} | |
1848564d | 104 | |
711ffac1 | 105 | port_up ${port} |
1848564d MT |
106 | |
107 | # Set same MTU to device that the bridge has got | |
711ffac1 | 108 | device_set_mtu ${port} $(device_get_mtu ${zone}) |
1848564d | 109 | |
711ffac1 | 110 | bridge_attach_device ${zone} ${port} |
1848564d | 111 | |
943e3f7e MT |
112 | # XXX must set cost and prio here |
113 | ||
1848564d MT |
114 | exit ${EXIT_OK} |
115 | } | |
116 | ||
2181765d | 117 | function hook_down() { |
1848564d MT |
118 | local zone=${1} |
119 | local port=${2} | |
120 | ||
711ffac1 MT |
121 | assert isset zone |
122 | assert isset port | |
1848564d | 123 | |
711ffac1 MT |
124 | assert zone_exists ${zone} |
125 | assert port_exists ${port} | |
1848564d | 126 | |
711ffac1 | 127 | bridge_detach_device ${zone} ${port} |
1848564d | 128 | |
711ffac1 | 129 | port_down ${port} |
1848564d MT |
130 | |
131 | exit ${EXIT_OK} | |
132 | } | |
133 | ||
2181765d | 134 | function hook_status() { |
73c67755 MT |
135 | local zone=${1} |
136 | local port=${2} | |
137 | ||
48bc31eb MT |
138 | # Do nothing for devices which are not up and running. |
139 | device_exists ${port} || exit ${EXIT_OK} | |
140 | ||
8e3508ac | 141 | local status |
48bc31eb MT |
142 | |
143 | # Check if the device is down. | |
711ffac1 | 144 | if ! device_is_up ${port}; then |
48bc31eb MT |
145 | status=${MSG_DEVICE_STATUS_DOWN} |
146 | ||
147 | # Check if the device has no carrier. | |
7fdca094 | 148 | elif ! device_has_carrier ${port}; then |
8e3508ac | 149 | status=${MSG_DEVICE_STATUS_NOCARRIER} |
48bc31eb MT |
150 | |
151 | # Check for STP information. | |
152 | elif stp_is_enabled ${zone}; then | |
feb76eaf | 153 | local state=$(stp_port_get_state ${zone} ${port}) |
8e3508ac MT |
154 | state="MSG_STP_${state}" |
155 | status="${!state}" | |
711ffac1 | 156 | |
8e3508ac MT |
157 | status="${status} - DSR: $(stp_port_get_designated_root ${zone} ${port})" |
158 | status="${status} - Cost: $(stp_port_get_cost ${zone} ${port})" | |
36e3fd2f | 159 | else |
8e3508ac | 160 | status=${MSG_DEVICE_STATUS_UP} |
73c67755 | 161 | fi |
8e3508ac | 162 | cli_statusline 3 "${port}" "${status}" |
73c67755 MT |
163 | |
164 | exit ${EXIT_OK} | |
165 | } |