]> git.ipfire.org Git - people/ms/network.git/blame - src/header-port
wireless-ap: Allow to disable DFS in configuration
[people/ms/network.git] / src / header-port
CommitLineData
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 22INFO_SETTINGS="HOOK PORT_PARENTS PORT_CHILDREN"
1848564d 23
96088590
MT
24HOOK_PORT_PATTERN="${PORT_PATTERN}"
25
2eaf16f3
MT
26# This function is called after a device has been plugged
27# into the system and got its correct name.
28# The function is intended to create child ports and things
29# like that.
1c6a4e30 30hook_hotplug() {
05365355
MT
31 # If the hook does not handle the hotplug event, it
32 # must return EXIT_NOT_HANDLED.
33 exit ${EXIT_NOT_HANDLED}
2eaf16f3
MT
34}
35
36# This function gets called when a device is plugged in
37# to determine the right name.
38# The first argument is the port which should be tested
39# against the second argument which is the device that
40# has been plugged in.
1c6a4e30 41hook_hotplug_rename() {
2eaf16f3 42 exit ${EXIT_FALSE}
8895cf8f
MT
43}
44
54bae947 45hook_default_new() {
b7518acc 46 local ${HOOK_SETTINGS}
54bae947
MT
47 if ! hook_parse_cmdline "$@"; then
48 return ${EXIT_ERROR}
49 fi
50
51 assert isset HOOK_PORT_PATTERN
52
53 local port=$(port_find_free ${HOOK_PORT_PATTERN})
54 assert isset port
55
56 port_settings_write "${port}" ${HOOK_SETTINGS}
57
58 exit ${EXIT_OK}
59}
60
61hook_new() {
62 hook_default_new "$@"
c2441156
SS
63}
64
a6fcc369 65hook_default_edit() {
cd6d94b5
MT
66 local port=${1}
67 assert isset port
68 shift
69
2e83362d
MT
70 # Read settings
71 if ! port_settings_read "${port}" ${HOOK_SETTINGS}; then
72 error "Could not read settings for port ${port}"
73 return ${EXIT_ERROR}
74 fi
cd6d94b5 75
2e83362d 76 # Parse command line arguments
2212045f 77 if ! hook_parse_cmdline "$@"; then
cd6d94b5
MT
78 return ${EXIT_ERROR}
79 fi
80
2e83362d
MT
81 # Save settings
82 if ! port_settings_write "${port}" ${HOOK_SETTINGS}; then
83 error "Could not write settings for port ${port}"
84 return ${EXIT_ERROR}
85 fi
cd6d94b5 86
79271f35
MT
87 # Apply settings
88 port_restart "${port}"
89
a6fcc369
MT
90 return ${EXIT_OK}
91}
92
93hook_edit() {
2212045f 94 hook_default_edit "$@"
cd6d94b5
MT
95}
96
7da8cf02
MT
97# Returns a list of all children of this port
98hook_children() {
99 local port="${1}"
100
101 if ! port_settings_read "${port}" ${HOOK_SETTINGS}; then
102 log ERROR "Could not read port settings: ${port}"
103 return ${EXIT_OK}
104 fi
105
106 print "${SLAVES}"
107}
108
1c6a4e30 109hook_status() {
2181765d 110 local port="${1}"
fe8e6d69
MT
111 assert isset port
112
2181765d 113 cli_device_headline "${port}" --long
fe8e6d69
MT
114 exit ${EXIT_OK}
115}
1ba6a2bb
MT
116
117# Create any virtual devices, but don't bring them up
118# Must tolerate that the device may already exist
1c6a4e30 119hook_create() {
1ba6a2bb
MT
120 cmd_not_implemented
121}
122
123# Must tolerate that the device may not exist
1c6a4e30 124hook_remove() {
1ba6a2bb
MT
125 cmd_not_implemented
126}
127
128# Just bring up the device
1c6a4e30 129hook_default_up() {
1ba6a2bb
MT
130 local port="${1}"
131 assert isset port
132
133 if ! device_exists "${port}"; then
134 log ERROR "Port '${port}' does not exist and cannot be brought up"
135 exit ${EXIT_ERROR}
136 fi
137
138 # Bring up the port
139 device_set_up "${port}"
140
141 # Bring up all slaves if the port has any
142 local slave
143 for slave in $(port_get_slaves "${port}"); do
144 port_up "${slave}"
145 done
146}
147
54bae947 148# Depends on the port existing
1c6a4e30 149hook_up() {
2212045f 150 hook_default_up "$@"
1ba6a2bb
MT
151}
152
1c6a4e30 153hook_default_down() {
1ba6a2bb
MT
154 local port="${1}"
155 assert isset port
156
157 if device_exists "${port}"; then
158 device_set_down "${port}"
159 fi
160
161 # Bring down all slaves if the port has any
162 local slave
163 for slave in $(port_get_slaves "${port}"); do
164 port_down "${slave}"
165 done
166}
167
1c6a4e30 168hook_down() {
2212045f 169 hook_default_down "$@"
1ba6a2bb 170}