]> git.ipfire.org Git - people/ms/network.git/blob - src/header-port
dummy: Cleanup hook
[people/ms/network.git] / src / header-port
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
22 INFO_SETTINGS="HOOK PORT_PARENTS PORT_CHILDREN"
23
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.
28 hook_hotplug() {
29 # If the hook does not handle the hotplug event, it
30 # must return EXIT_NOT_HANDLED.
31 exit ${EXIT_NOT_HANDLED}
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.
39 hook_hotplug_rename() {
40 exit ${EXIT_FALSE}
41 }
42
43 hook_add() {
44 cmd_not_implemented
45 }
46
47 hook_edit() {
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
60 exit ${EXIT_OK}
61 }
62
63 hook_info() {
64 local port="${1}"
65 assert isset port
66 shift
67
68 settings_read "$(port_file ${port})"
69
70 local key val
71 for key in PORT_PARENTS PORT_CHILDREN; do
72 val="${key}_VAR"
73 val=${!val}
74
75 assign "${key}" "${!val}"
76 done
77
78 for key in ${INFO_SETTINGS}; do
79 echo "${key}=\"${!key}\""
80 done
81
82 exit ${ERROR_OK}
83 }
84
85 hook_status() {
86 local port="${1}"
87 assert isset port
88
89 cli_device_headline "${port}" --long
90 exit ${EXIT_OK}
91 }
92
93 # Create any virtual devices, but don't bring them up
94 # Must tolerate that the device may already exist
95 hook_create() {
96 cmd_not_implemented
97 }
98
99 # Must tolerate that the device may not exist
100 hook_remove() {
101 cmd_not_implemented
102 }
103
104 # Just bring up the device
105 hook_default_up() {
106 local port="${1}"
107 assert isset port
108
109 if ! device_exists "${port}"; then
110 log ERROR "Port '${port}' does not exist and cannot be brought up"
111 exit ${EXIT_ERROR}
112 fi
113
114 # Bring up the port
115 device_set_up "${port}"
116
117 # Bring up all slaves if the port has any
118 local slave
119 for slave in $(port_get_slaves "${port}"); do
120 port_up "${slave}"
121 done
122 }
123
124 hook_up() {
125 hook_default_up $@
126 }
127
128 hook_default_down() {
129 local port="${1}"
130 assert isset port
131
132 if device_exists "${port}"; then
133 device_set_down "${port}"
134 fi
135
136 # Bring down all slaves if the port has any
137 local slave
138 for slave in $(port_get_slaves "${port}"); do
139 port_down "${slave}"
140 done
141 }
142
143 hook_down() {
144 hook_default_down $@
145 }