]>
Commit | Line | Data |
---|---|---|
ab5a37b4 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 | # | |
22 | # XXX This hook is rather unusable because the parent device cannot be used | |
23 | # anymore in a bridge. | |
24 | # | |
25 | ||
26 | . /usr/lib/network/header-port | |
27 | ||
28 | HOOK_SETTINGS="HOOK ADDRESS PARENT" | |
29 | ||
2181765d | 30 | function hook_check() { |
ab5a37b4 MT |
31 | assert isset PARENT |
32 | assert ismac ADDRESS | |
33 | } | |
34 | ||
2181765d | 35 | function hook_create() { |
ab5a37b4 MT |
36 | while [ $# -gt 0 ]; do |
37 | case "${1}" in | |
38 | --parent-device=*) | |
39 | PARENT=$(cli_get_val ${1}) | |
40 | ;; | |
41 | --address=*) | |
42 | ADDRESS=$(cli_get_val ${1}) | |
43 | ;; | |
44 | *) | |
45 | warning "Unknown argument '${1}'" | |
46 | ;; | |
47 | esac | |
48 | shift | |
49 | done | |
50 | ||
51 | local port=$(port_find_free "${PARENT}${MACVLAN_PORT_INTERFIX}N") | |
52 | assert isset port | |
53 | ||
e9df08ad | 54 | if port_settings_write "${port}" ${HOOK_SETTINGS}; then |
ab5a37b4 MT |
55 | log INFO "New macvlan port '${port}' has been created." |
56 | fi | |
57 | ||
58 | exit ${EXIT_OK} | |
59 | } | |
60 | ||
2181765d | 61 | function hook_edit() { |
ab5a37b4 MT |
62 | local port=${1} |
63 | assert isset port | |
64 | shift | |
65 | ||
e9df08ad | 66 | port_settings_read "${port}" ${HOOK_SETTINGS} |
ab5a37b4 MT |
67 | |
68 | while [ $# -gt 0 ]; do | |
69 | case "${1}" in | |
70 | --address=*) | |
71 | ADDRESS=$(cli_get_val ${1}) | |
72 | ;; | |
73 | *) | |
74 | warning "Unknown argument '${1}'" | |
75 | ;; | |
76 | esac | |
77 | shift | |
78 | done | |
79 | ||
e9df08ad | 80 | port_settings_write "${port}" ${HOOK_SETTINGS} |
ab5a37b4 MT |
81 | |
82 | exit ${EXIT_OK} | |
83 | } | |
84 | ||
2181765d | 85 | function hook_up() { |
ab5a37b4 MT |
86 | local port=${1} |
87 | assert isset port | |
88 | ||
e9df08ad | 89 | port_settings_read "${port}" ${HOOK_SETTINGS} |
ab5a37b4 MT |
90 | |
91 | # Create device if not already exists. | |
92 | if ! device_exists ${port}; then | |
93 | macvlan_create "${port}" "${PARENT}" "${ADDRESS}" | |
94 | fi | |
95 | ||
96 | exit ${EXIT_OK} | |
97 | } | |
98 | ||
2181765d | 99 | function hook_down() { |
ab5a37b4 MT |
100 | local port=${1} |
101 | ||
102 | assert isset port | |
103 | ||
e9df08ad | 104 | port_settings_read "${port}" ${HOOK_SETTINGS} |
ab5a37b4 MT |
105 | |
106 | if ! device_exists ${port}; then | |
107 | exit ${EXIT_OK} | |
108 | fi | |
109 | ||
110 | macvlan_remove ${port} | |
111 | ||
112 | exit ${EXIT_OK} | |
113 | } |