]>
Commit | Line | Data |
---|---|---|
bd86d39f 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 | . /usr/lib/network/header-port | |
23 | ||
d389e96b MT |
24 | HOOK_SETTINGS=( |
25 | "ADDRESS" | |
26 | ) | |
bd86d39f | 27 | |
1c6a4e30 | 28 | hook_check_settings() { |
bd86d39f MT |
29 | assert ismac ADDRESS |
30 | } | |
31 | ||
cd6d94b5 | 32 | hook_parse_cmdline() { |
bd86d39f MT |
33 | while [ $# -gt 0 ]; do |
34 | case "${1}" in | |
35 | --address=*) | |
2212045f | 36 | ADDRESS=$(cli_get_val "${1}") |
bd86d39f MT |
37 | ;; |
38 | *) | |
39 | warning "Unknown argument '${1}'" | |
40 | ;; | |
41 | esac | |
42 | shift | |
43 | done | |
44 | ||
cd6d94b5 MT |
45 | if isset ADDRESS; then |
46 | if ! ismac ADDRESS; then | |
47 | error "Invalid MAC address given: ${ADDRESS}" | |
48 | return ${EXIT_ERROR} | |
49 | fi | |
50 | ||
51 | # Generate a random but static MAC address if none was set | |
52 | else | |
bd86d39f MT |
53 | ADDRESS=$(mac_generate) |
54 | fi | |
cd6d94b5 MT |
55 | } |
56 | ||
57 | hook_new() { | |
2212045f | 58 | if ! hook_parse_cmdline "$@"; then |
cd6d94b5 MT |
59 | return ${EXIT_ERROR} |
60 | fi | |
bd86d39f MT |
61 | |
62 | local port=$(port_find_free ${DUMMY_PORT_PATTERN}) | |
63 | assert isset port | |
64 | ||
eba9fa9c | 65 | if port_settings_write "${port}"; then |
bd86d39f MT |
66 | log INFO "New dummy port '${port}' has been created" |
67 | fi | |
68 | ||
69 | exit ${EXIT_OK} | |
70 | } | |
71 | ||
1c6a4e30 | 72 | hook_create() { |
1ba6a2bb | 73 | local port="${1}" |
bd86d39f MT |
74 | assert isset port |
75 | ||
1ba6a2bb | 76 | # Read configuration |
eba9fa9c | 77 | port_settings_read "${port}" |
bd86d39f | 78 | |
1ba6a2bb MT |
79 | # Create the dummy device |
80 | dummy_create "${port}" "${ADDRESS}" | |
81 | ||
82 | exit ${EXIT_OK} | |
83 | } | |
84 | ||
1c6a4e30 | 85 | hook_remove() { |
1ba6a2bb MT |
86 | local port="${1}" |
87 | assert isset port | |
88 | ||
89 | # Remove the dummy device | |
90 | dummy_remove "${port}" | |
91 | } | |
92 | ||
1c6a4e30 | 93 | hook_hotplug_rename() { |
12f9c8d2 | 94 | hook_hotplug_rename_by_address "$@" |
bd86d39f | 95 | } |