]> git.ipfire.org Git - people/ms/network.git/blob - src/hooks/ports/bonding
hostapd: Enable WMM by default.
[people/ms/network.git] / src / hooks / ports / bonding
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="HOOK ADDRESS MIIMON MODE SLAVES"
25
26 ADDRESS=$(mac_generate)
27 SLAVES=""
28 MIIMON=100
29
30 function hook_check() {
31 assert isset ADDRESS
32 assert ismac ADDRESS
33
34 #assert isset SLAVES
35 assert isinteger MIIMON
36 }
37
38 function hook_create() {
39 _edit $@
40 }
41
42 function hook_edit() {
43 local port=${1}
44 assert isset port
45 shift
46
47 while [ $# -gt 0 ]; do
48 case "${1}" in
49 --address=*)
50 ADDRESS=$(cli_get_val ${1})
51 ;;
52 --miimon=*)
53 MIIMON=$(cli_get_val ${1})
54 ;;
55 --mode=*)
56 MODE=$(cli_get_val ${1})
57 ;;
58 --slave=*)
59 slave=$(cli_get_val ${1})
60 SLAVES="${SLAVES} ${slave}"
61 ;;
62 *)
63 warning "Unknown argument '${1}'"
64 ;;
65 esac
66 shift
67 done
68
69 DEVICE=${port}
70
71 # XXX think this must move to _check()
72 if ! isset DEVICE; then
73 error "You must set a device name."
74 exit ${EXIT_ERROR}
75 fi
76
77 if ! isset SLAVES; then
78 error "You need to specify at least one slave port (e.g. --slave=port0)."
79 exit ${EXIT_ERROR}
80 fi
81
82 local slave
83 for slave in $(unquote ${SLAVES}); do
84 if ! device_is_ethernet ${slave}; then
85 error "Slave device '${slave}' is not an ethernet device."
86 exit ${EXIT_ERROR}
87 fi
88 done
89
90 # Remove any whitespace
91 SLAVES=$(echo ${SLAVES})
92
93 port_config_write ${port} ${HOOK_SETTINGS}
94
95 exit ${EXIT_OK}
96 }
97
98 function hook_up() {
99 local device=${1}
100 assert isset device
101
102 port_config_read ${device}
103
104 if device_exists ${device}; then
105 log DEBUG "Bonding device '${device}' does already exist."
106
107 device_set_address ${device} ${ADDRESS}
108 device_set_up ${device}
109
110 exit ${EXIT_OK}
111 fi
112
113 bonding_create ${device} --address="${ADDRESS}" --mode="${MODE}"
114 local ret=$?
115
116 [ ${ret} -eq ${EXIT_OK} ] || exit ${EXIT_ERROR}
117
118 bonding_set_miimon ${device} ${MIIMON}
119 device_set_up ${device}
120
121 local slave
122 for slave in $(unquote ${SLAVES}); do
123 if ! device_exists ${slave}; then
124 warning_log "${device}: configured slave '${slave}' is not available."
125 continue
126 fi
127
128 bonding_enslave_device ${device} ${slave}
129 done
130
131 # Bring up the device.
132 device_set_up ${device}
133
134 exit ${EXIT_OK}
135 }
136
137 function hook_down() {
138 local device=${1}
139
140 bonding_remove ${device}
141
142 local slave
143 for slave in ${SLAVES}; do
144 device_set_down ${slave}
145 done
146
147 exit ${EXIT_OK}
148 }