]>
Commit | Line | Data |
---|---|---|
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 | 24 | HOOK_SETTINGS="HOOK ADDRESS MIIMON MODE SLAVES" |
711ffac1 | 25 | |
d1e71061 MT |
26 | ADDRESS=$(mac_generate) |
27 | SLAVES="" | |
711ffac1 MT |
28 | MIIMON=100 |
29 | ||
2181765d | 30 | function hook_check() { |
d1e71061 MT |
31 | assert isset ADDRESS |
32 | assert ismac ADDRESS | |
711ffac1 MT |
33 | |
34 | #assert isset SLAVES | |
35 | assert isinteger MIIMON | |
36 | } | |
37 | ||
2181765d | 38 | function hook_create() { |
711ffac1 MT |
39 | _edit $@ |
40 | } | |
41 | ||
2181765d | 42 | function hook_edit() { |
711ffac1 | 43 | local port=${1} |
d1e71061 | 44 | assert isset port |
711ffac1 MT |
45 | shift |
46 | ||
47 | while [ $# -gt 0 ]; do | |
48 | case "${1}" in | |
d1e71061 MT |
49 | --address=*) |
50 | ADDRESS=$(cli_get_val ${1}) | |
711ffac1 MT |
51 | ;; |
52 | --miimon=*) | |
d1e71061 | 53 | MIIMON=$(cli_get_val ${1}) |
711ffac1 MT |
54 | ;; |
55 | --mode=*) | |
d1e71061 | 56 | MODE=$(cli_get_val ${1}) |
711ffac1 MT |
57 | ;; |
58 | --slave=*) | |
d1e71061 MT |
59 | slave=$(cli_get_val ${1}) |
60 | SLAVES="${SLAVES} ${slave}" | |
711ffac1 MT |
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 | |
d1e71061 MT |
83 | for slave in $(unquote ${SLAVES}); do |
84 | if ! device_is_ethernet ${slave}; then | |
711ffac1 MT |
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 | ||
d1e71061 | 93 | port_config_write ${port} ${HOOK_SETTINGS} |
711ffac1 MT |
94 | |
95 | exit ${EXIT_OK} | |
96 | } | |
97 | ||
2181765d | 98 | function hook_up() { |
711ffac1 | 99 | local device=${1} |
d1e71061 | 100 | assert isset device |
711ffac1 | 101 | |
d1e71061 | 102 | port_config_read ${device} |
711ffac1 MT |
103 | |
104 | if device_exists ${device}; then | |
105 | log DEBUG "Bonding device '${device}' does already exist." | |
106 | ||
d1e71061 | 107 | device_set_address ${device} ${ADDRESS} |
711ffac1 MT |
108 | device_set_up ${device} |
109 | ||
110 | exit ${EXIT_OK} | |
111 | fi | |
112 | ||
d1e71061 MT |
113 | bonding_create ${device} --address="${ADDRESS}" --mode="${MODE}" |
114 | local ret=$? | |
711ffac1 | 115 | |
d1e71061 | 116 | [ ${ret} -eq ${EXIT_OK} ] || exit ${EXIT_ERROR} |
711ffac1 MT |
117 | |
118 | bonding_set_miimon ${device} ${MIIMON} | |
b8c614b2 | 119 | device_set_up ${device} |
711ffac1 MT |
120 | |
121 | local slave | |
d1e71061 MT |
122 | for slave in $(unquote ${SLAVES}); do |
123 | if ! device_exists ${slave}; then | |
711ffac1 MT |
124 | warning_log "${device}: configured slave '${slave}' is not available." |
125 | continue | |
126 | fi | |
711ffac1 MT |
127 | |
128 | bonding_enslave_device ${device} ${slave} | |
129 | done | |
130 | ||
d1e71061 MT |
131 | # Bring up the device. |
132 | device_set_up ${device} | |
133 | ||
711ffac1 MT |
134 | exit ${EXIT_OK} |
135 | } | |
136 | ||
2181765d | 137 | function hook_down() { |
711ffac1 MT |
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 | } |