]>
Commit | Line | Data |
---|---|---|
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 |
22 | IN_HOTPLUG_EVENT=1 |
23 | ||
24 | # Setup logging. | |
25 | LOG_FACILITY="network-hotplug" | |
26 | ||
8c63fa13 MT |
27 | . /usr/lib/network/functions |
28 | ||
e9df08ad MT |
29 | # Read network settings |
30 | network_settings_read | |
b834a824 | 31 | |
46457a8e | 32 | log DEBUG "Called with SUBSYSTEM='${SUBSYSTEM}', ACTION='${ACTION}', INTERFACE='${INTERFACE}', DEVPATH='${DEVPATH}'" |
3a7fef62 | 33 | |
3a7fef62 MT |
34 | # Check if the udev environment variables are properly set. |
35 | assert isset ACTION | |
3a7fef62 | 36 | |
b8026986 MT |
37 | case "${SUBSYSTEM}" in |
38 | ieee80211) | |
39 | PHY="$(basename "${DEVPATH}")" | |
46457a8e MT |
40 | |
41 | # Check if the PHY exists | |
42 | if ! phy_exists "${PHY}"; then | |
43 | exit ${EXIT_OK} | |
b8026986 | 44 | fi |
a23fdc0e | 45 | |
46457a8e MT |
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 | |
208f7452 | 55 | |
b8026986 MT |
56 | # Propagate the hotplug event to all configured port hooks |
57 | hotplug_propagate_all_ports || exit ${EXIT_ERROR} | |
46457a8e MT |
58 | |
59 | # Everything went fine | |
60 | exit ${EXIT_OK} | |
b8026986 MT |
61 | ;; |
62 | ||
63 | net) | |
64 | assert isset INTERFACE | |
3a7fef62 | 65 | |
47e2688a | 66 | # Stop processing rules for the loopback device |
9b47451e | 67 | if device_is_loopback ${INTERFACE}; then |
47e2688a MT |
68 | exit ${EXIT_OK} |
69 | ||
fbdd77c2 MT |
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 | ||
47e2688a MT |
75 | # Stop processing rules for wireless monitoring devices |
76 | elif device_is_wireless_monitor ${INTERFACE}; then | |
77 | exit ${EXIT_OK} | |
b8026986 | 78 | fi |
fb8c7c92 | 79 | |
46457a8e | 80 | # Did we get called for a non-existing interface? |
9b47451e | 81 | if ! zone_exists "${INTERFACE}" && ! port_exists "${INTERFACE}"; then |
46457a8e MT |
82 | case "${ACTION}" in |
83 | add) | |
0de04f89 MT |
84 | # Ignore this for some special devices |
85 | case "${INTERFACE}" in | |
86 | gre0|ip6gre0|ip6tnl0|ip6_vti0|ip_vti0) | |
87 | log DEBUG "Ignoring special device ${INTERFACE}" | |
88 | ;; | |
89 | esac | |
90 | ||
46457a8e MT |
91 | log WARNING "Got to hotplug event for a port which does not exist: ${INTERFACE}" |
92 | ||
93 | # Try to remove the device again | |
e54199b6 | 94 | |
ec87f5ce | 95 | TYPE="$(device_get_type "${INTERFACE}")" |
46457a8e MT |
96 | case "${TYPE}" in |
97 | bonding) | |
98 | bonding_remove "${INTERFACE}" | |
99 | ;; | |
100 | dummy) | |
101 | dummy_remove "${INTERFACE}" | |
102 | ;; | |
103 | wireless) | |
104 | wireless_remove "${INTERFACE}" | |
105 | ;; | |
106 | *) | |
107 | device_delete "${INTERFACE}" | |
108 | esac | |
b8026986 | 109 | |
b8026986 | 110 | exit ${EXIT_OK} |
46457a8e | 111 | ;; |
b8026986 | 112 | |
46457a8e MT |
113 | remove) |
114 | # Don't propagate removal events for ports that don't exist | |
b8026986 | 115 | exit ${EXIT_OK} |
46457a8e MT |
116 | ;; |
117 | esac | |
3a7fef62 | 118 | fi |
b8026986 MT |
119 | |
120 | # Propagate the hotplug event to all configured port hooks | |
121 | hotplug_propagate_all_ports || exit ${EXIT_ERROR} | |
122 | ||
2a969c27 MT |
123 | # Propagate the hotplug event to all configured zones |
124 | hotplug_propagate_all_zones || exit ${EXIT_ERROR} | |
b8026986 MT |
125 | |
126 | exit ${EXIT_OK} | |
3a7fef62 MT |
127 | ;; |
128 | ||
b8026986 MT |
129 | *) |
130 | log ERROR "Called for an unsupported subsystem: ${SUBSYSTEM}" | |
131 | exit ${EXIT_ERROR} | |
3a7fef62 MT |
132 | ;; |
133 | esac | |
134 | ||
b8026986 | 135 | exit ${EXIT_NOT_HANDLED} |