]> git.ipfire.org Git - people/stevee/network.git/blob - hooks/zones/bridge.ports/bonding
network: Make two groups of hooks, again.
[people/stevee/network.git] / hooks / zones / bridge.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 . /lib/network/header-port
23
24 HOOK_SETTINGS="HOOK DEVICE_MAC DEVICE_NAME MODE SLAVES"
25
26 DEVICE_NAME="bond0" # XXX DEVICE_NAME must be unique
27 DEVICE_MAC=$(mac_generate)
28
29 function _check() {
30 assert isset DEVICE_MAC
31 assert ismac DEVICE_MAC
32 assert isset DEVICE_NAME
33
34 assert isset SLAVES
35 }
36
37 function _create() {
38 local zone=${1}
39 shift
40
41 local
42
43 while [ $# -gt 0 ]; do
44 case "${1}" in
45 --mac=*)
46 DEVICE_MAC=${1#--mac=}
47 ;;
48 --mode=*)
49 MODE=${1#--mode=}
50 ;;
51 --slave=*)
52 slave=${1#--slave=}
53 SLAVES="${SLAVES} $(macify ${slave})"
54 ;;
55 *)
56 warning "Unknown argument '${1}'"
57 ;;
58 esac
59 shift
60 done
61
62 # Remove any whitespace
63 SLAVES=$(echo ${SLAVES})
64
65 _check
66
67 config_write $(zone_dir ${zone})/port.${HOOK}.$(device_hash ${DEVICE_MAC}) ${HOOK_SETTINGS}
68
69 exit ${EXIT_OK}
70 }
71
72 function _up() {
73 local zone=${1}
74 local port=${2}
75
76 config_read $(zone_dir ${zone})/${port}
77
78 if ! device_exists $(devicify ${DEVICE_MAC}); then
79 device_virtual_create ${DEVICE} ${DEVICE_VID} ${DEVICE_MAC}
80 fi
81
82 local device=$(devicify ${DEVICE_MAC})
83
84 # Set same MTU to device that the bridge has got
85 device_set_mtu ${device} $(device_get_mtu ${zone})
86
87 bridge_attach_device ${zone} ${device}
88
89 exit ${EXIT_OK}
90 }
91
92 run $@