]> git.ipfire.org Git - people/jschlag/network.git/blob - src/header-port
ca1b0917356de8460cb5ce953baa5fb17c445f5c
[people/jschlag/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_default_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 return ${EXIT_OK}
61 }
62
63 hook_edit() {
64 hook_default_edit $@
65 }
66
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
79 hook_info() {
80 local port="${1}"
81 assert isset port
82 shift
83
84 settings_read "$(port_file ${port})"
85
86 local key val
87 for key in PORT_PARENTS PORT_CHILDREN; do
88 val="${key}_VAR"
89 val=${!val}
90
91 assign "${key}" "${!val}"
92 done
93
94 for key in ${INFO_SETTINGS}; do
95 echo "${key}=\"${!key}\""
96 done
97
98 exit ${ERROR_OK}
99 }
100
101 hook_status() {
102 local port="${1}"
103 assert isset port
104
105 cli_device_headline "${port}" --long
106 exit ${EXIT_OK}
107 }
108
109 # Create any virtual devices, but don't bring them up
110 # Must tolerate that the device may already exist
111 hook_create() {
112 cmd_not_implemented
113 }
114
115 # Must tolerate that the device may not exist
116 hook_remove() {
117 cmd_not_implemented
118 }
119
120 # Just bring up the device
121 hook_default_up() {
122 local port="${1}"
123 assert isset port
124
125 if ! device_exists "${port}"; then
126 log ERROR "Port '${port}' does not exist and cannot be brought up"
127 exit ${EXIT_ERROR}
128 fi
129
130 # Bring up the port
131 device_set_up "${port}"
132
133 # Bring up all slaves if the port has any
134 local slave
135 for slave in $(port_get_slaves "${port}"); do
136 port_up "${slave}"
137 done
138 }
139
140 hook_up() {
141 hook_default_up $@
142 }
143
144 hook_default_down() {
145 local port="${1}"
146 assert isset port
147
148 if device_exists "${port}"; then
149 device_set_down "${port}"
150 fi
151
152 # Bring down all slaves if the port has any
153 local slave
154 for slave in $(port_get_slaves "${port}"); do
155 port_down "${slave}"
156 done
157 }
158
159 hook_down() {
160 hook_default_down $@
161 }