]>
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 | ||
8c63fa13 | 22 | . /usr/lib/network/header-port |
711ffac1 | 23 | |
64b7bffd MT |
24 | # DEVICE equals the actual MAC address of the device. |
25 | # If ADDRESS is set, the device will get ADDRESS set for its MAC address. | |
26 | ||
27 | HOOK_SETTINGS="HOOK ADDRESS DEVICE" | |
711ffac1 | 28 | |
2181765d | 29 | function hook_check() { |
64b7bffd MT |
30 | assert ismac DEVICE |
31 | ||
32 | if isset ADDRESS; then | |
33 | assert ismac ADDRESS | |
34 | fi | |
711ffac1 MT |
35 | } |
36 | ||
2181765d | 37 | function hook_create() { |
711ffac1 | 38 | local port=${1} |
711ffac1 | 39 | assert isset port |
64b7bffd | 40 | shift |
711ffac1 | 41 | |
64b7bffd MT |
42 | ADDRESS="" |
43 | DEVICE=$(device_get_address ${port}) | |
711ffac1 | 44 | |
e9df08ad | 45 | port_settings_write "${port}" ${HOOK_SETTINGS} |
711ffac1 MT |
46 | |
47 | exit ${EXIT_OK} | |
48 | } | |
49 | ||
2181765d | 50 | function hook_up() { |
711ffac1 | 51 | local port=${1} |
711ffac1 MT |
52 | assert isset port |
53 | ||
3ee5ccb1 MT |
54 | if ! device_exists "${port}"; then |
55 | log WARNING "Cannot bring up port '${port}' which does not exist" | |
56 | exit ${EXIT_OK} | |
57 | fi | |
58 | ||
64b7bffd | 59 | # Read in the confguration file. |
e9df08ad | 60 | port_settings_read "${port}" ${HOOK_SETTINGS} |
64b7bffd MT |
61 | |
62 | # Check if the MAC address is the right one. | |
63 | if isset ADDRESS; then | |
64 | device_set_address "${device}" "${ADDRESS}" | |
65 | fi | |
66 | ||
67 | # Bring up the device. | |
3ee5ccb1 | 68 | device_set_up "${port}" |
711ffac1 MT |
69 | |
70 | exit ${EXIT_OK} | |
71 | } | |
72 | ||
2181765d | 73 | function hook_down() { |
711ffac1 | 74 | local port=${1} |
711ffac1 MT |
75 | assert isset port |
76 | ||
64b7bffd | 77 | # Set down the device. |
711ffac1 MT |
78 | device_set_down ${port} |
79 | ||
80 | exit ${EXIT_OK} | |
81 | } | |
82 | ||
2181765d | 83 | function hook_hotplug_rename() { |
8895cf8f | 84 | local port=${1} |
8895cf8f | 85 | assert isset port |
64b7bffd MT |
86 | |
87 | local device=${2} | |
8895cf8f MT |
88 | assert isset device |
89 | ||
64b7bffd | 90 | # Read in the conifguration file. |
e9df08ad | 91 | port_settings_read "${port}" ${HOOK_SETTINGS} |
64b7bffd MT |
92 | |
93 | # Get the current MAC address of the device. | |
94 | local address=$(device_get_address ${device}) | |
95 | assert isset address | |
8895cf8f | 96 | |
64b7bffd MT |
97 | # Check if the address matches with the configuration. |
98 | if list_match "${address}" ${DEVICE} ${ADDRESS}; then | |
8c63fa13 | 99 | log DEBUG "Device '${device}' equals port '${port}'." |
64b7bffd MT |
100 | |
101 | # Change the MAC address, if needed. | |
102 | if isset ADDRESS; then | |
103 | device_set_address "${device}" "${ADDRESS}" | |
104 | fi | |
105 | ||
106 | # Everything is done. | |
8895cf8f MT |
107 | exit ${EXIT_OK} |
108 | fi | |
109 | ||
8c63fa13 | 110 | log DEBUG "Device '${device}' does not equal port '${port}'." |
8895cf8f MT |
111 | exit ${EXIT_ERROR} |
112 | } |