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