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