]>
Commit | Line | Data |
---|---|---|
5b20e43a MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
1848564d | 5 | # Copyright (C) 2010 Michael Tremer & Christian Schmidt # |
5b20e43a MT |
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 | ||
98f4dae6 | 22 | INFO_SETTINGS="HOOK PORT_PARENTS PORT_CHILDREN" |
1848564d | 23 | |
2eaf16f3 MT |
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 | |
27 | # like that. | |
1c6a4e30 | 28 | hook_hotplug() { |
05365355 MT |
29 | # If the hook does not handle the hotplug event, it |
30 | # must return EXIT_NOT_HANDLED. | |
31 | exit ${EXIT_NOT_HANDLED} | |
2eaf16f3 MT |
32 | } |
33 | ||
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. | |
1c6a4e30 | 39 | hook_hotplug_rename() { |
2eaf16f3 | 40 | exit ${EXIT_FALSE} |
8895cf8f MT |
41 | } |
42 | ||
1c6a4e30 | 43 | hook_add() { |
c2441156 SS |
44 | cmd_not_implemented |
45 | } | |
46 | ||
a6fcc369 | 47 | hook_default_edit() { |
cd6d94b5 MT |
48 | local port=${1} |
49 | assert isset port | |
50 | shift | |
51 | ||
52 | port_settings_read "${port}" ${HOOK_SETTINGS} | |
53 | ||
54 | if ! hook_parse_cmdline $@; then | |
55 | return ${EXIT_ERROR} | |
56 | fi | |
57 | ||
58 | port_settings_write "${port}" ${HOOK_SETTINGS} | |
59 | ||
a6fcc369 MT |
60 | return ${EXIT_OK} |
61 | } | |
62 | ||
63 | hook_edit() { | |
64 | hook_default_edit $@ | |
cd6d94b5 MT |
65 | } |
66 | ||
7da8cf02 MT |
67 | # Returns a list of all children of this port |
68 | hook_children() { | |
69 | local port="${1}" | |
70 | ||
71 | if ! port_settings_read "${port}" ${HOOK_SETTINGS}; then | |
72 | log ERROR "Could not read port settings: ${port}" | |
73 | return ${EXIT_OK} | |
74 | fi | |
75 | ||
76 | print "${SLAVES}" | |
77 | } | |
78 | ||
1c6a4e30 | 79 | hook_status() { |
2181765d | 80 | local port="${1}" |
fe8e6d69 MT |
81 | assert isset port |
82 | ||
2181765d | 83 | cli_device_headline "${port}" --long |
fe8e6d69 MT |
84 | exit ${EXIT_OK} |
85 | } | |
1ba6a2bb MT |
86 | |
87 | # Create any virtual devices, but don't bring them up | |
88 | # Must tolerate that the device may already exist | |
1c6a4e30 | 89 | hook_create() { |
1ba6a2bb MT |
90 | cmd_not_implemented |
91 | } | |
92 | ||
93 | # Must tolerate that the device may not exist | |
1c6a4e30 | 94 | hook_remove() { |
1ba6a2bb MT |
95 | cmd_not_implemented |
96 | } | |
97 | ||
98 | # Just bring up the device | |
1c6a4e30 | 99 | hook_default_up() { |
1ba6a2bb MT |
100 | local port="${1}" |
101 | assert isset port | |
102 | ||
103 | if ! device_exists "${port}"; then | |
104 | log ERROR "Port '${port}' does not exist and cannot be brought up" | |
105 | exit ${EXIT_ERROR} | |
106 | fi | |
107 | ||
108 | # Bring up the port | |
109 | device_set_up "${port}" | |
110 | ||
111 | # Bring up all slaves if the port has any | |
112 | local slave | |
113 | for slave in $(port_get_slaves "${port}"); do | |
114 | port_up "${slave}" | |
115 | done | |
116 | } | |
117 | ||
1c6a4e30 | 118 | hook_up() { |
1ba6a2bb MT |
119 | hook_default_up $@ |
120 | } | |
121 | ||
1c6a4e30 | 122 | hook_default_down() { |
1ba6a2bb MT |
123 | local port="${1}" |
124 | assert isset port | |
125 | ||
126 | if device_exists "${port}"; then | |
127 | device_set_down "${port}" | |
128 | fi | |
129 | ||
130 | # Bring down all slaves if the port has any | |
131 | local slave | |
132 | for slave in $(port_get_slaves "${port}"); do | |
133 | port_down "${slave}" | |
134 | done | |
135 | } | |
136 | ||
1c6a4e30 | 137 | hook_down() { |
1ba6a2bb MT |
138 | hook_default_down $@ |
139 | } |