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 # This function is called after a device has been plugged
25 # into the system and got its correct name.
26 # The function is intended to create child ports and things
29 # If the hook does not handle the hotplug event, it
30 # must return EXIT_NOT_HANDLED.
31 exit ${EXIT_NOT_HANDLED}
34 # This function gets called when a device is plugged in
35 # to determine the right name.
36 # The first argument is the port which should be tested
37 # against the second argument which is the device that
38 # has been plugged in.
39 hook_hotplug_rename
() {
44 if ! hook_parse_cmdline
"$@"; then
48 assert isset HOOK_PORT_PATTERN
50 local port
=$
(port_find_free
${HOOK_PORT_PATTERN})
53 port_settings_write
"${port}" ${HOOK_SETTINGS}
67 port_settings_read
"${port}" ${HOOK_SETTINGS}
69 if ! hook_parse_cmdline $@
; then
73 port_settings_write
"${port}" ${HOOK_SETTINGS}
82 # Returns a list of all children of this port
86 if ! port_settings_read
"${port}" ${HOOK_SETTINGS}; then
87 log ERROR
"Could not read port settings: ${port}"
98 cli_device_headline
"${port}" --long
102 # Create any virtual devices, but don't bring them up
103 # Must tolerate that the device may already exist
108 # Must tolerate that the device may not exist
113 # Just bring up the device
118 if ! device_exists
"${port}"; then
119 log ERROR
"Port '${port}' does not exist and cannot be brought up"
124 device_set_up
"${port}"
126 # Bring up all slaves if the port has any
128 for slave
in $
(port_get_slaves
"${port}"); do
133 # Depends on the port existing
138 hook_default_down
() {
142 if device_exists
"${port}"; then
143 device_set_down
"${port}"
146 # Bring down all slaves if the port has any
148 for slave
in $
(port_get_slaves
"${port}"); do