]> git.ipfire.org Git - people/stevee/network.git/blob - src/hooks/zones/bridge.ports/ethernet
Use autotools.
[people/stevee/network.git] / src / hooks / zones / bridge.ports / ethernet
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 . /usr/lib/network/header-port
23
24 HOOK_SETTINGS="COST PRIORITY"
25
26 function hook_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 hook_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 hook_edit() {
68 hook_add $@
69 }
70
71 function hook_remove() {
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 hook_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 hook_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 hook_status() {
135 local zone=${1}
136 local port=${2}
137
138 # Do nothing for devices which are not up and running.
139 device_exists ${port} || exit ${EXIT_OK}
140
141 local status
142
143 # Check if the device is down.
144 if ! device_is_up ${port}; then
145 status=${MSG_DEVICE_STATUS_DOWN}
146
147 # Check if the device has no carrier.
148 elif ! device_has_carrier ${port}; then
149 status=${MSG_DEVICE_STATUS_NOCARRIER}
150
151 # Check for STP information.
152 elif stp_is_enabled ${zone}; then
153 local state=$(stp_port_get_state ${zone} ${port})
154 state="MSG_STP_${state}"
155 status="${!state}"
156
157 status="${status} - DSR: $(stp_port_get_designated_root ${zone} ${port})"
158 status="${status} - Cost: $(stp_port_get_cost ${zone} ${port})"
159 else
160 status=${MSG_DEVICE_STATUS_UP}
161 fi
162 cli_statusline 3 "${port}" "${status}"
163
164 exit ${EXIT_OK}
165 }