]> git.ipfire.org Git - people/stevee/network.git/blame - hooks/zones/bridge.ports/ethernet
network: Make two groups of hooks, again.
[people/stevee/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
24HOOK_SETTINGS="HOOK DEVICE"
25
26function _check() {
27 assert isset DEVICE
28 assert ismac DEVICE
29}
30
31function _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
52function _up() {
53 local zone=${1}
54 local port=${2}
55
56 config_read $(zone_dir ${zone})/${port}
57
58 local device=$(devicify ${DEVICE})
59
60 if ! device_exists ${device}; then
61 warning "Device '${DEVICE}' does not exist."
62 exit ${EXIT_ERROR}
63 fi
64
65 # Set same MTU to device that the bridge has got
66 device_set_mtu ${device} $(device_get_mtu ${zone})
67
68 device_set_up ${device}
69
70 bridge_attach_device ${zone} ${device}
71
72 exit ${EXIT_OK}
73}
74
75function _down() {
76 local zone=${1}
77 local port=${2}
78
79 config_read $(zone_dir ${zone})/${port}
80
81 local device=$(devicify ${DEVICE})
82
83 if ! device_exists ${device}; then
84 warning "Device '${DEVICE}' does not exist."
85 exit ${EXIT_ERROR}
86 fi
87
88 bridge_detach_device ${zone} ${device}
89
90 device_set_down ${device}
91
92 exit ${EXIT_OK}
93}
94
73c67755
MT
95function _status() {
96 local zone=${1}
97 local port=${2}
98
99 config_read $(zone_dir ${zone})/${port}
100
101 local device=$(devicify ${DEVICE})
102
103 printf " %-10s - " "${device}"
104 if ! device_is_up ${device}; then
105 echo -ne "${COLOUR_DOWN} DOWN ${COLOUR_NORMAL}"
106 else
107 local state=$(stp_port_state ${zone} ${device})
108 local colour="COLOUR_STP_${state}"
109 printf "${!colour}%10s${COLOUR_NORMAL}" ${state}
110 fi
111
112 echo -n " - DSR: $(stp_port_designated_root ${zone} ${device})"
113 echo -n " - Cost: $(stp_port_pathcost ${zone} ${device})"
114 echo
115
116 exit ${EXIT_OK}
117}
118
1848564d 119run $@