]> git.ipfire.org Git - network.git/blob - src/udev/network-hotplug
42bf319605d2c5395f384dceaa1db310ac99c730
[network.git] / src / udev / network-hotplug
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
22 IN_HOTPLUG_EVENT=1
23
24 # Setup logging.
25 LOG_FACILITY="network-hotplug"
26
27 . /usr/lib/network/functions
28
29 # Read network settings
30 network_settings_read
31
32 log DEBUG "Called with SUBSYSTEM='${SUBSYSTEM}', ACTION='${ACTION}', INTERFACE='${INTERFACE}', DEVPATH='${DEVPATH}'"
33
34 # Check if the udev environment variables are properly set.
35 assert isset ACTION
36
37 case "${SUBSYSTEM}" in
38 ieee80211)
39 PHY="$(basename "${DEVPATH}")"
40
41 # Check if the PHY exists
42 if ! phy_exists "${PHY}"; then
43 exit ${EXIT_OK}
44 fi
45
46 case "${ACTION}" in
47 add)
48 # Load regulatory domain for wireless devices
49 wireless_init_reg_domain
50
51 # Configure LEDs
52 phy_leds_autoconf "${PHY}"
53 ;;
54 esac
55
56 # Propagate the hotplug event to all configured port hooks
57 hotplug_propagate_all_ports || exit ${EXIT_ERROR}
58
59 # Everything went fine
60 exit ${EXIT_OK}
61 ;;
62
63 net)
64 assert isset INTERFACE
65
66 # Stop processing rules for the loopback device
67 if device_is_loopback ${INTERFACE}; then
68 exit ${EXIT_OK}
69
70 # Skip all pppN interfaces (for pppoe-server)
71 elif device_is_ppp "${INTERFACE}" && [[ ${INTERFACE} =~ ^ppp[0-9]+$ ]]; then
72 log DEBUG "Ignoring PPP device"
73 exit ${EXIT_OK}
74
75 # Stop processing rules for wireless monitoring devices
76 elif device_is_wireless_monitor ${INTERFACE}; then
77 exit ${EXIT_OK}
78 fi
79
80 # Did we get called for a non-existing interface?
81 if ! zone_exists "${INTERFACE}" && ! port_exists "${INTERFACE}"; then
82 case "${ACTION}" in
83 add)
84 log WARNING "Got to hotplug event for a port which does not exist: ${INTERFACE}"
85
86 # Try to remove the device again
87
88 # GRE6
89 if device_is_gre6 "${INTERFACE}" && [ "${INTERFACE}" = "ip6gre0" ]; then
90 log DEBUG "ip6gre0 cannot be removed"
91 exit ${EXIT_OK}
92
93 # GRE
94 elif device_is_gre "${INTERFACE}" && [ "${INTERFACE}" = "gre0" ]; then
95 log DEBUG "gre0 cannot be removed"
96 exit ${EXIT_OK}
97
98 # VTI
99 elif device_is_vti "${INTERFACE}" && [ "${INTERFACE}" = "ip_vti0" ]; then
100 log DEBUG "ip_vti0 cannot be removed"
101 exit ${EXIT_OK}
102 fi
103
104 TYPE="$(device_get_type "${INTERFACE}")"
105 case "${TYPE}" in
106 bonding)
107 bonding_remove "${INTERFACE}"
108 ;;
109 dummy)
110 dummy_remove "${INTERFACE}"
111 ;;
112 wireless)
113 wireless_remove "${INTERFACE}"
114 ;;
115 *)
116 device_delete "${INTERFACE}"
117 esac
118
119 exit ${EXIT_OK}
120 ;;
121
122 remove)
123 # Don't propagate removal events for ports that don't exist
124 exit ${EXIT_OK}
125 ;;
126 esac
127 fi
128
129 # Propagate the hotplug event to all configured port hooks
130 hotplug_propagate_all_ports || exit ${EXIT_ERROR}
131
132 # Propagate the hotplug event to all configured zones
133 hotplug_propagate_all_zones || exit ${EXIT_ERROR}
134
135 exit ${EXIT_OK}
136 ;;
137
138 *)
139 log ERROR "Called for an unsupported subsystem: ${SUBSYSTEM}"
140 exit ${EXIT_ERROR}
141 ;;
142 esac
143
144 exit ${EXIT_NOT_HANDLED}