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