]> git.ipfire.org Git - network.git/blame - src/udev/network-hotplug
ibnetwork: Add command to show available VHT capabilities of phys
[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
b8026986
MT
47 # Propagate the hotplug event to all configured port hooks
48 hotplug_propagate_all_ports || exit ${EXIT_ERROR}
49 ;;
50
51 net)
52 assert isset INTERFACE
3a7fef62 53
b8026986 54 # Don't do anything for zones
fb8c7c92 55 if zone_exists "${INTERFACE}"; then
fb8c7c92 56 exit ${EXIT_OK}
47e2688a
MT
57
58 # Stop processing rules for the loopback device
59 elif device_is_loopback ${INTERFACE}; then
60 exit ${EXIT_OK}
61
82fac748
MT
62 # Stop processing rules for IPsec devices
63 elif device_is_ipsec ${INTERFACE}; then
64 exit ${EXIT_OK}
65
47e2688a
MT
66 # Stop processing rules for wireless monitoring devices
67 elif device_is_wireless_monitor ${INTERFACE}; then
68 exit ${EXIT_OK}
b8026986 69 fi
fb8c7c92 70
b8026986
MT
71 # Get the internal type of the device for later processing
72 TYPE="$(device_get_type "${INTERFACE}")"
8c63fa13 73
b8026986
MT
74 log DEBUG " INTERFACE='${INTERFACE}', TYPE='${TYPE}'"
75
b8026986
MT
76 # Handle special cases like removing automatically created
77 # devices that we don't want
78 case "${ACTION},${TYPE}" in
79 # Bonding
80 add,bonding)
81 # Remove bonding devices without configuration
82 if ! port_exists "${INTERFACE}"; then
83 bonding_remove "${INTERFACE}"
84 exit ${EXIT_OK}
85 fi
86 ;;
87
0067696a
MT
88 # dummy
89 add,dummy)
90 # Remove the by default created dummy device
91 if [ "${INTERFACE}" = "dummy0" ]; then
92 dummy_remove "${INTERFACE}"
93 exit ${EXIT_OK}
94 fi
95 ;;
96
b8026986
MT
97 # Ethernet
98 add,ethernet)
99 # Create a default port for all ethernet devices
100 if ! port_exists "${INTERFACE}"; then
1ba6a2bb 101 port_new "ethernet" "${INTERFACE}"
b8026986
MT
102 fi
103 ;;
104
105 # Wireless devices
106 add,wireless)
107 # Remove wireless devices without configuration
108 if ! port_exists "${INTERFACE}"; then
109 wireless_remove "${INTERFACE}"
110 exit ${EXIT_OK}
111 fi
112
113 # Load regulatory domain for wireless devices
114 wireless_init_reg_domain
115 ;;
116
117 # Don't propagate removal events for ports that don't exist
118 remove,*)
119 if ! port_exists "${INTERFACE}"; then
120 exit ${EXIT_OK}
121 fi
122 ;;
123 esac
124
125 if ! port_exists "${INTERFACE}"; then
126 log ERROR "Got to hotplug event for a port which does not exist: ${INTERFACE}"
127 exit ${EXIT_ERROR}
3a7fef62 128 fi
b8026986
MT
129
130 # Propagate the hotplug event to all configured port hooks
131 hotplug_propagate_all_ports || exit ${EXIT_ERROR}
132
2a969c27
MT
133 # Propagate the hotplug event to all configured zones
134 hotplug_propagate_all_zones || exit ${EXIT_ERROR}
b8026986
MT
135
136 exit ${EXIT_OK}
3a7fef62
MT
137 ;;
138
b8026986
MT
139 *)
140 log ERROR "Called for an unsupported subsystem: ${SUBSYSTEM}"
141 exit ${EXIT_ERROR}
3a7fef62
MT
142 ;;
143esac
144
b8026986 145exit ${EXIT_NOT_HANDLED}