]> git.ipfire.org Git - people/stevee/network.git/blob - src/udev/network-hotplug
Split port hooks in to (create|remove|up|down) actions
[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 # 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
53
54 # Don't do anything for zones
55 if zone_exists "${INTERFACE}"; then
56 exit ${EXIT_OK}
57 fi
58
59 # Get the internal type of the device for later processing
60 TYPE="$(device_get_type "${INTERFACE}")"
61
62 log DEBUG " INTERFACE='${INTERFACE}', TYPE='${TYPE}'"
63
64 # Stop processing rules for wireless monitoring devices
65 if device_is_wireless_monitor "${INTERFACE}"; then
66 exit ${EXIT_OK}
67 fi
68
69 # Handle special cases like removing automatically created
70 # devices that we don't want
71 case "${ACTION},${TYPE}" in
72 # Bonding
73 add,bonding)
74 # Remove bonding devices without configuration
75 if ! port_exists "${INTERFACE}"; then
76 bonding_remove "${INTERFACE}"
77 exit ${EXIT_OK}
78 fi
79 ;;
80
81 # Ethernet
82 add,ethernet)
83 # Create a default port for all ethernet devices
84 if ! port_exists "${INTERFACE}"; then
85 port_new "ethernet" "${INTERFACE}"
86 exit ${EXIT_OK}
87 fi
88 ;;
89
90 # Wireless devices
91 add,wireless)
92 # Remove wireless devices without configuration
93 if ! port_exists "${INTERFACE}"; then
94 wireless_remove "${INTERFACE}"
95 exit ${EXIT_OK}
96 fi
97
98 # Load regulatory domain for wireless devices
99 wireless_init_reg_domain
100 ;;
101
102 # Don't propagate removal events for ports that don't exist
103 remove,*)
104 if ! port_exists "${INTERFACE}"; then
105 exit ${EXIT_OK}
106 fi
107 ;;
108 esac
109
110 if ! port_exists "${INTERFACE}"; then
111 log ERROR "Got to hotplug event for a port which does not exist: ${INTERFACE}"
112 exit ${EXIT_ERROR}
113 fi
114
115 # Propagate the hotplug event to all configured port hooks
116 hotplug_propagate_all_ports || exit ${EXIT_ERROR}
117
118 # Propagate the hotplug event to all configured zones
119 hotplug_propagate_all_zones || exit ${EXIT_ERROR}
120
121 exit ${EXIT_OK}
122 ;;
123
124 *)
125 log ERROR "Called for an unsupported subsystem: ${SUBSYSTEM}"
126 exit ${EXIT_ERROR}
127 ;;
128 esac
129
130 exit ${EXIT_NOT_HANDLED}