2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2010 Michael Tremer & Christian Schmidt #
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. #
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. #
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/>. #
20 ###############################################################################
22 INFO_SETTINGS
="HOOK PORT_PARENTS PORT_CHILDREN"
24 HOOK_PORT_PATTERN
="${PORT_PATTERN}"
26 # This function is called after a device has been plugged
27 # into the system and got its correct name.
28 # The function is intended to create child ports and things
31 # If the hook does not handle the hotplug event, it
32 # must return EXIT_NOT_HANDLED.
33 exit ${EXIT_NOT_HANDLED}
36 # This function gets called when a device is plugged in
37 # to determine the right name.
38 # The first argument is the port which should be tested
39 # against the second argument which is the device that
40 # has been plugged in.
41 hook_hotplug_rename
() {
45 hook_hotplug_rename_by_address
() {
52 # Read in the conifguration file.
53 if ! port_settings_read
"${port}"; then
57 # Get the current MAC address of the device.
58 local address
="$(device_get_address "${device}")"
61 # Check if the address matches with the configuration.
62 if list_match
"${address}" "${ADDRESS}" "${DEVICE}"; then
63 log DEBUG
"Device '${device}' is port '${port}'"
67 log DEBUG
"Device '${device}' is not port '${port}'"
71 # Returns the suggested name of the port
72 hook_find_port_name
() {
73 assert isset HOOK_PORT_PATTERN
74 port_find_free
"${HOOK_PORT_PATTERN}"
78 local ${HOOK_SETTINGS[*]}
80 # Import all default variables
83 if ! hook_parse_cmdline
"$@"; then
87 # Determine a name for this port
88 local port
="$(hook_find_port_name)"
92 if ! port_settings_write
"${port}" ${HOOK_SETTINGS[*]}; then
100 hook_default_new
"$@"
103 hook_default_edit
() {
109 if ! port_settings_read
"${port}" ${HOOK_SETTINGS[*]}; then
110 error
"Could not read settings for port ${port}"
114 # Parse command line arguments
115 if ! hook_parse_cmdline
"$@"; then
120 if ! port_settings_write
"${port}" ${HOOK_SETTINGS[*]}; then
121 error
"Could not write settings for port ${port}"
126 port_restart
"${port}"
132 hook_default_edit
"$@"
135 # Returns a list of all children of this port
139 if ! port_settings_read
"${port}" ${HOOK_SETTINGS[*]}; then
140 log ERROR
"Could not read port settings: ${port}"
151 cli_device_headline
"${port}" --long
155 # Create any virtual devices, but don't bring them up
156 # Must tolerate that the device may already exist
161 # Must tolerate that the device may not exist
166 # Just bring up the device
171 if ! device_exists
"${port}"; then
172 log ERROR
"Port '${port}' does not exist and cannot be brought up"
177 device_set_up
"${port}"
179 # Bring up all slaves if the port has any
181 for slave
in $
(port_get_slaves
"${port}"); do
186 # Depends on the port existing
191 hook_default_down
() {
195 if device_exists
"${port}"; then
196 device_set_down
"${port}"
199 # Bring down all slaves if the port has any
201 for slave
in $
(port_get_slaves
"${port}"); do
207 hook_default_down
"$@"