]>
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 | ||
54bae947 MT |
43 | hook_default_new() { |
44 | if ! hook_parse_cmdline "$@"; then | |
45 | return ${EXIT_ERROR} | |
46 | fi | |
47 | ||
48 | assert isset HOOK_PORT_PATTERN | |
49 | ||
50 | local port=$(port_find_free ${HOOK_PORT_PATTERN}) | |
51 | assert isset port | |
52 | ||
53 | port_settings_write "${port}" ${HOOK_SETTINGS} | |
54 | ||
55 | exit ${EXIT_OK} | |
56 | } | |
57 | ||
58 | hook_new() { | |
59 | hook_default_new "$@" | |
c2441156 SS |
60 | } |
61 | ||
a6fcc369 | 62 | hook_default_edit() { |
cd6d94b5 MT |
63 | local port=${1} |
64 | assert isset port | |
65 | shift | |
66 | ||
2e83362d MT |
67 | # Read settings |
68 | if ! port_settings_read "${port}" ${HOOK_SETTINGS}; then | |
69 | error "Could not read settings for port ${port}" | |
70 | return ${EXIT_ERROR} | |
71 | fi | |
cd6d94b5 | 72 | |
2e83362d | 73 | # Parse command line arguments |
2212045f | 74 | if ! hook_parse_cmdline "$@"; then |
cd6d94b5 MT |
75 | return ${EXIT_ERROR} |
76 | fi | |
77 | ||
2e83362d MT |
78 | # Save settings |
79 | if ! port_settings_write "${port}" ${HOOK_SETTINGS}; then | |
80 | error "Could not write settings for port ${port}" | |
81 | return ${EXIT_ERROR} | |
82 | fi | |
cd6d94b5 | 83 | |
79271f35 MT |
84 | # Apply settings |
85 | port_restart "${port}" | |
86 | ||
a6fcc369 MT |
87 | return ${EXIT_OK} |
88 | } | |
89 | ||
90 | hook_edit() { | |
2212045f | 91 | hook_default_edit "$@" |
cd6d94b5 MT |
92 | } |
93 | ||
7da8cf02 MT |
94 | # Returns a list of all children of this port |
95 | hook_children() { | |
96 | local port="${1}" | |
97 | ||
98 | if ! port_settings_read "${port}" ${HOOK_SETTINGS}; then | |
99 | log ERROR "Could not read port settings: ${port}" | |
100 | return ${EXIT_OK} | |
101 | fi | |
102 | ||
103 | print "${SLAVES}" | |
104 | } | |
105 | ||
1c6a4e30 | 106 | hook_status() { |
2181765d | 107 | local port="${1}" |
fe8e6d69 MT |
108 | assert isset port |
109 | ||
2181765d | 110 | cli_device_headline "${port}" --long |
fe8e6d69 MT |
111 | exit ${EXIT_OK} |
112 | } | |
1ba6a2bb MT |
113 | |
114 | # Create any virtual devices, but don't bring them up | |
115 | # Must tolerate that the device may already exist | |
1c6a4e30 | 116 | hook_create() { |
1ba6a2bb MT |
117 | cmd_not_implemented |
118 | } | |
119 | ||
120 | # Must tolerate that the device may not exist | |
1c6a4e30 | 121 | hook_remove() { |
1ba6a2bb MT |
122 | cmd_not_implemented |
123 | } | |
124 | ||
125 | # Just bring up the device | |
1c6a4e30 | 126 | hook_default_up() { |
1ba6a2bb MT |
127 | local port="${1}" |
128 | assert isset port | |
129 | ||
130 | if ! device_exists "${port}"; then | |
131 | log ERROR "Port '${port}' does not exist and cannot be brought up" | |
132 | exit ${EXIT_ERROR} | |
133 | fi | |
134 | ||
135 | # Bring up the port | |
136 | device_set_up "${port}" | |
137 | ||
138 | # Bring up all slaves if the port has any | |
139 | local slave | |
140 | for slave in $(port_get_slaves "${port}"); do | |
141 | port_up "${slave}" | |
142 | done | |
143 | } | |
144 | ||
54bae947 | 145 | # Depends on the port existing |
1c6a4e30 | 146 | hook_up() { |
2212045f | 147 | hook_default_up "$@" |
1ba6a2bb MT |
148 | } |
149 | ||
1c6a4e30 | 150 | hook_default_down() { |
1ba6a2bb MT |
151 | local port="${1}" |
152 | assert isset port | |
153 | ||
154 | if device_exists "${port}"; then | |
155 | device_set_down "${port}" | |
156 | fi | |
157 | ||
158 | # Bring down all slaves if the port has any | |
159 | local slave | |
160 | for slave in $(port_get_slaves "${port}"); do | |
161 | port_down "${slave}" | |
162 | done | |
163 | } | |
164 | ||
1c6a4e30 | 165 | hook_down() { |
2212045f | 166 | hook_default_down "$@" |
1ba6a2bb | 167 | } |