]> git.ipfire.org Git - people/stevee/network.git/blame - src/functions/functions.hotplug
Add hotplugging for zones (and ports of those)
[people/stevee/network.git] / src / functions / functions.hotplug
CommitLineData
b8026986
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2014 IPFire Network Development Team #
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
22function hotplug_assert_in_hotplug_event() {
23 assert [ -n "${IN_HOTPLUG_EVENT}" ]
24}
25
26function hotplug_action() {
27 hotplug_assert_in_hotplug_event
28
29 echo "${ACTION}"
30}
31
32function hotplug_propagate_all_ports() {
33 hotplug_assert_in_hotplug_event
34
35 # Create configured child devices.
36 local port
37 for port in $(ports_get_all); do
38 port_hotplug_event "${port}"
39 local ret="${?}"
40
41 # Log warning for crashed hooks
42 case "${ret}" in
43 ${EXIT_OK}|${EXIT_NOT_HANDLED})
44 : # do nothing
45 ;;
46 *)
47 log WARNING "Unknown exit code for port '${port}': ${ret}"
48 ;;
49 esac
50 done
51}
52
2a969c27
MT
53function hotplug_propagate_all_zones() {
54 hotplug_assert_in_hotplug_event
55
56 local zone
57 for zone in $(zones_get_all); do
58 zone_hotplug_event "${zone}"
59 local ret="${?}"
60
61 # Log warning for crashed hooks
62 case "${ret}" in
63 ${EXIT_OK}|${EXIT_NOT_HANDLED})
64 : # do nothing
65 ;;
66 *)
67 log WARNING "Unknown exit code for zone '${zone}': ${ret}"
68 ;;
69 esac
70 done
71}
72
b8026986
MT
73function hotplug_event_port_is_interface() {
74 hotplug_assert_in_hotplug_event
75
76 local port="${1}"
77 assert isset port
78
79 [ "${port}" = "${INTERFACE}" ]
80}
81
2a969c27 82function hotplug_event_interface_is_slave_of_port() {
b8026986
MT
83 hotplug_assert_in_hotplug_event
84
85 local port="${1}"
86 assert isset port
87
88 # Return false if INTERFACE is not set
89 isset INTERFACE || return ${EXIT_FALSE}
90
91 local slaves="$(port_get_slaves "${port}")"
2a969c27
MT
92 list_match "${INTERFACE}" ${slaves}
93}
94
95function hotplug_event_interface_is_port_of_zone() {
96 hotplug_assert_in_hotplug_event
97
98 local zone="${1}"
99 assert isset zone
100
101 # Return false if INTERFACE is not set
102 isset INTERFACE || return ${EXIT_FALSE}
103
104 local ports="$(zone_get_ports "${zone}")"
105 list_match "${INTERFACE}" ${ports}
b8026986
MT
106}
107
108function hotplug_event_port_uses_phy() {
109 hotplug_assert_in_hotplug_event
110
111 local port="${1}"
112 assert isset port
113
114 # Return false if PHY is not set
115 isset PHY || return ${EXIT_FALSE}
116
117 # Returns true if port uses PHY
118 port_uses_phy "${port}" "${PHY}"
119}