]> git.ipfire.org Git - people/stevee/network.git/blob - hooks/zones/bridge.ports/ethernet
network: Magnificent changes on code.
[people/stevee/network.git] / 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 . /lib/network/header-port
23
24 HOOK_SETTINGS="HOOK DEVICE"
25
26 function _check() {
27 assert isset DEVICE_MAC
28 assert ismac DEVICE_MAC
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
56 assert isset zone
57 assert isset port
58
59 assert zone_exists ${zone}
60 assert port_exists ${port}
61
62 port_up ${port}
63
64 # Set same MTU to device that the bridge has got
65 device_set_mtu ${port} $(device_get_mtu ${zone})
66
67 bridge_attach_device ${zone} ${port}
68
69 exit ${EXIT_OK}
70 }
71
72 function _down() {
73 local zone=${1}
74 local port=${2}
75
76 assert isset zone
77 assert isset port
78
79 assert zone_exists ${zone}
80 assert port_exists ${port}
81
82 bridge_detach_device ${zone} ${port}
83
84 port_down ${port}
85
86 exit ${EXIT_OK}
87 }
88
89 function _status() {
90 local zone=${1}
91 local port=${2}
92
93 printf " %-10s - " "${port}"
94 if ! device_is_up ${port}; then
95 echo -ne "${COLOUR_DOWN} DOWN ${COLOUR_NORMAL}"
96 else
97 local state=$(stp_port_state ${zone} ${port})
98 local colour="COLOUR_STP_${state}"
99 printf "${!colour}%10s${COLOUR_NORMAL}" ${state}
100
101 echo -n " - DSR: $(stp_port_designated_root ${zone} ${port})"
102 echo -n " - Cost: $(stp_port_pathcost ${zone} ${port})"
103 fi
104
105 echo
106
107 exit ${EXIT_OK}
108 }
109
110 run $@