]> git.ipfire.org Git - people/arne_f/network.git/blame - hooks/zones/bridge.ports/ethernet
network: Updated stp framework.
[people/arne_f/network.git] / hooks / zones / bridge.ports / ethernet
CommitLineData
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 24HOOK_SETTINGS="COST PRIORITY"
1848564d
MT
25
26function _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 35function _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
67function _edit() {
68 _add $@
69}
70
c077c723
MT
71function _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
1848564d
MT
95function _up() {
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
117function _down() {
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
73c67755
MT
134function _status() {
135 local zone=${1}
136 local port=${2}
137
711ffac1
MT
138 printf " %-10s - " "${port}"
139 if ! device_is_up ${port}; then
73c67755
MT
140 echo -ne "${COLOUR_DOWN} DOWN ${COLOUR_NORMAL}"
141 else
feb76eaf 142 local state=$(stp_port_get_state ${zone} ${port})
73c67755
MT
143 local colour="COLOUR_STP_${state}"
144 printf "${!colour}%10s${COLOUR_NORMAL}" ${state}
711ffac1 145
feb76eaf
MT
146 echo -n " - DSR: $(stp_port_get_designated_root ${zone} ${port})"
147 echo -n " - Cost: $(stp_port_get_cost ${zone} ${port})"
73c67755 148 fi
711ffac1 149
73c67755
MT
150 echo
151
152 exit ${EXIT_OK}
153}
154
1848564d 155run $@