]> git.ipfire.org Git - people/stevee/network.git/blob - src/header-port
80ff69400a74b2045c589ace7bc9f17bad699480
[people/stevee/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 function 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 function hook_hotplug_rename() {
40 exit ${EXIT_FALSE}
41 }
42
43 function hook_add() {
44 cmd_not_implemented
45 }
46
47 function hook_info() {
48 local port="${1}"
49 assert isset port
50 shift
51
52 settings_read "$(port_file ${port})"
53
54 local key val
55 for key in PORT_PARENTS PORT_CHILDREN; do
56 val="${key}_VAR"
57 val=${!val}
58 eval "${key}=\"${!val}\""
59 done
60
61 for key in ${INFO_SETTINGS}; do
62 echo "${key}=\"${!key}\""
63 done
64
65 exit ${ERROR_OK}
66 }
67
68 function hook_status() {
69 local port="${1}"
70 assert isset port
71
72 cli_device_headline "${port}" --long
73 exit ${EXIT_OK}
74 }
75
76 # Create any virtual devices, but don't bring them up
77 # Must tolerate that the device may already exist
78 function hook_create() {
79 cmd_not_implemented
80 }
81
82 # Must tolerate that the device may not exist
83 function hook_remove() {
84 cmd_not_implemented
85 }
86
87 # Just bring up the device
88 function hook_default_up() {
89 local port="${1}"
90 assert isset port
91
92 if ! device_exists "${port}"; then
93 log ERROR "Port '${port}' does not exist and cannot be brought up"
94 exit ${EXIT_ERROR}
95 fi
96
97 # Bring up the port
98 device_set_up "${port}"
99
100 # Bring up all slaves if the port has any
101 local slave
102 for slave in $(port_get_slaves "${port}"); do
103 port_up "${slave}"
104 done
105 }
106
107 function hook_up() {
108 hook_default_up $@
109 }
110
111 function hook_default_down() {
112 local port="${1}"
113 assert isset port
114
115 if device_exists "${port}"; then
116 device_set_down "${port}"
117 fi
118
119 # Bring down all slaves if the port has any
120 local slave
121 for slave in $(port_get_slaves "${port}"); do
122 port_down "${slave}"
123 done
124 }
125
126 function hook_down() {
127 hook_default_down $@
128 }