]> git.ipfire.org Git - people/stevee/network.git/blob - src/functions/functions.hotplug
8fccae4e7c6ef9f645cf4ebf02b8a262e25d9d69
[people/stevee/network.git] / src / functions / functions.hotplug
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
22 hotplug_assert_in_hotplug_event() {
23 assert [ -n "${IN_HOTPLUG_EVENT}" ]
24 }
25
26 hotplug_action() {
27 hotplug_assert_in_hotplug_event
28
29 echo "${ACTION}"
30 }
31
32 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
53 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
73 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
82 hotplug_event_interface_is_slave_of_port() {
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}")"
92 list_match "${INTERFACE}" ${slaves}
93 }
94
95 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}
106 }
107
108 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 }