]> git.ipfire.org Git - people/ms/network.git/blame - src/udev/network-hotplug
hotplug: Continue running through script for ipsec devices
[people/ms/network.git] / src / udev / network-hotplug
CommitLineData
3a7fef62
MT
1#!/bin/bash
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2011 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
b8026986
MT
22IN_HOTPLUG_EVENT=1
23
24# Setup logging.
25LOG_FACILITY="network-hotplug"
26
8c63fa13
MT
27. /usr/lib/network/functions
28
e9df08ad
MT
29# Read network settings
30network_settings_read
b834a824 31
b8026986 32log DEBUG "Called with SUBSYSTEM='${SUBSYSTEM}', ACTION='${ACTION}'"
3a7fef62 33
3a7fef62
MT
34# Check if the udev environment variables are properly set.
35assert isset ACTION
3a7fef62 36
b8026986
MT
37case "${SUBSYSTEM}" in
38 ieee80211)
39 PHY="$(basename "${DEVPATH}")"
40 if phy_exists "${PHY}"; then
41 PHY_ADDRESS="$(phy_get_address "${PHY}")"
42 log DEBUG " PHY='${PHY}', PHY_ADDRESS='${PHY_ADDRESS}'"
43 else
44 PHY=""
45 fi
a23fdc0e 46
208f7452
MT
47 # Configure LEDs
48 [ "${ACTION}" = "add" ] && phy_leds_autoconf "${PHY}"
49
b8026986
MT
50 # Propagate the hotplug event to all configured port hooks
51 hotplug_propagate_all_ports || exit ${EXIT_ERROR}
52 ;;
53
54 net)
55 assert isset INTERFACE
3a7fef62 56
b8026986 57 # Don't do anything for zones
fb8c7c92 58 if zone_exists "${INTERFACE}"; then
fb8c7c92 59 exit ${EXIT_OK}
47e2688a
MT
60
61 # Stop processing rules for the loopback device
62 elif device_is_loopback ${INTERFACE}; then
63 exit ${EXIT_OK}
64
65 # Stop processing rules for wireless monitoring devices
66 elif device_is_wireless_monitor ${INTERFACE}; then
67 exit ${EXIT_OK}
b8026986 68 fi
fb8c7c92 69
b8026986
MT
70 # Get the internal type of the device for later processing
71 TYPE="$(device_get_type "${INTERFACE}")"
8c63fa13 72
b8026986
MT
73 log DEBUG " INTERFACE='${INTERFACE}', TYPE='${TYPE}'"
74
b8026986
MT
75 # Handle special cases like removing automatically created
76 # devices that we don't want
77 case "${ACTION},${TYPE}" in
78 # Bonding
79 add,bonding)
80 # Remove bonding devices without configuration
81 if ! port_exists "${INTERFACE}"; then
82 bonding_remove "${INTERFACE}"
83 exit ${EXIT_OK}
84 fi
85 ;;
86
0067696a
MT
87 # dummy
88 add,dummy)
89 # Remove the by default created dummy device
90 if [ "${INTERFACE}" = "dummy0" ]; then
91 dummy_remove "${INTERFACE}"
92 exit ${EXIT_OK}
93 fi
94 ;;
95
b8026986
MT
96 # Ethernet
97 add,ethernet)
98 # Create a default port for all ethernet devices
99 if ! port_exists "${INTERFACE}"; then
1ba6a2bb 100 port_new "ethernet" "${INTERFACE}"
b8026986
MT
101 fi
102 ;;
103
104 # Wireless devices
105 add,wireless)
106 # Remove wireless devices without configuration
107 if ! port_exists "${INTERFACE}"; then
108 wireless_remove "${INTERFACE}"
109 exit ${EXIT_OK}
110 fi
111
112 # Load regulatory domain for wireless devices
113 wireless_init_reg_domain
114 ;;
115
116 # Don't propagate removal events for ports that don't exist
117 remove,*)
118 if ! port_exists "${INTERFACE}"; then
119 exit ${EXIT_OK}
120 fi
121 ;;
122 esac
123
124 if ! port_exists "${INTERFACE}"; then
125 log ERROR "Got to hotplug event for a port which does not exist: ${INTERFACE}"
126 exit ${EXIT_ERROR}
3a7fef62 127 fi
b8026986
MT
128
129 # Propagate the hotplug event to all configured port hooks
130 hotplug_propagate_all_ports || exit ${EXIT_ERROR}
131
2a969c27
MT
132 # Propagate the hotplug event to all configured zones
133 hotplug_propagate_all_zones || exit ${EXIT_ERROR}
b8026986
MT
134
135 exit ${EXIT_OK}
3a7fef62
MT
136 ;;
137
b8026986
MT
138 *)
139 log ERROR "Called for an unsupported subsystem: ${SUBSYSTEM}"
140 exit ${EXIT_ERROR}
3a7fef62
MT
141 ;;
142esac
143
b8026986 144exit ${EXIT_NOT_HANDLED}