]>
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 | ||
30 | function _check() { | |
31 | assert isset PARENT | |
32 | assert ismac ADDRESS | |
33 | } | |
34 | ||
35 | function _create() { | |
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 | ||
54 | if config_write $(port_file ${port}) ${HOOK_SETTINGS}; then | |
55 | log INFO "New macvlan port '${port}' has been created." | |
56 | fi | |
57 | ||
58 | exit ${EXIT_OK} | |
59 | } | |
60 | ||
61 | function _edit() { | |
62 | local port=${1} | |
63 | assert isset port | |
64 | shift | |
65 | ||
66 | config_read $(port_file ${port}) | |
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 | ||
80 | config_write $(port_file ${port}) ${HOOK_SETTINGS} | |
81 | ||
82 | exit ${EXIT_OK} | |
83 | } | |
84 | ||
85 | function _up() { | |
86 | local port=${1} | |
87 | assert isset port | |
88 | ||
89 | config_read $(port_file ${port}) | |
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 | ||
99 | function _down() { | |
100 | local port=${1} | |
101 | ||
102 | assert isset port | |
103 | ||
104 | config_read $(port_file ${port}) | |
105 | ||
106 | if ! device_exists ${port}; then | |
107 | exit ${EXIT_OK} | |
108 | fi | |
109 | ||
110 | macvlan_remove ${port} | |
111 | ||
112 | exit ${EXIT_OK} | |
113 | } |