]> git.ipfire.org Git - people/ms/network.git/blame - src/udev/network-hotplug
wireless monitor: Use proper port name
[people/ms/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
8c63fa13
MT
22. /usr/lib/network/functions
23
e9df08ad
MT
24# Read network settings
25network_settings_read
b834a824 26
8c63fa13
MT
27# Setup logging.
28LOG_FACILITY="network-hotplug"
29
30log DEBUG "Called with ACTION='${ACTION}', INTERFACE='${INTERFACE}'."
3a7fef62 31
3a7fef62
MT
32# Check if the udev environment variables are properly set.
33assert isset ACTION
34assert isset INTERFACE
35
36# Check, if the device is a physical network interface and
37# if we can handle it.
8c63fa13 38if device_exists ${INTERFACE}; then
a23fdc0e
MT
39 # Skip wireless monitor devices
40 if device_is_wireless_monitor "${INTERFACE}"; then
41 exit ${EXIT_OK}
42 fi
43
e72eb5c8
MT
44 type="$(device_get_type "${INTERFACE}")"
45 case "${type}" in
46 # Remove automatically created bonding interface without any configuration
47 bonding)
48 port_exists "${INTERFACE}" || bonding_remove "${INTERFACE}"
49 exit ${EXIT_OK}
50 ;;
51 ethernet)
52 log DEBUG "Called for interface '${INTERFACE}' which is a virtual interface. Exiting."
53 exit ${EXIT_OK}
54 ;;
55 esac
3a7fef62
MT
56fi
57
58case "${ACTION}" in
59 add|register)
fb8c7c92
MT
60 # Handle hotplug events for zones.
61 if zone_exists "${INTERFACE}"; then
62 # TODO When e.g. a wireless device is plugged in,
63 # the right zone needs to be searched and started.
64 exit ${EXIT_OK}
65
66 # Check, if there is a port configuration for that device.
67 elif port_exists ${INTERFACE}; then
8c63fa13
MT
68 port=${INTERFACE}
69
70 # Create new configuration for _real_ network devices.
8c63fa13 71 else
9ea57fb8
MT
72 type=$(device_get_type ${INTERFACE})
73 case "${type}" in
74 # If the given device was not configured,
75 # we create an initial configuration.
76 ethernet|real)
77 port_create ethernet ${INTERFACE}
78 ;;
79
e6993835
MT
80 # Handle batman-adv and wireless devices.
81 batman-adv|batman-adv-port|wireless)
06a6f01e
MT
82 # Load regulatory domain for wireless devices
83 wireless_init_reg_domain
84
9ea57fb8
MT
85 # Save the phy of this device for later.
86 phy=$(phy_get ${INTERFACE})
87 assert isset phy
88
89 # Remove the unconfigured wireless device.
90 wireless_remove ${INTERFACE}
91
92 # Create configured child devices.
93 for port in $(ports_get_all); do
05365355
MT
94 port_cmd hotplug "${port}" "${phy}"
95 ret=$?
96
97 case "${ret}" in
98 ${EXIT_OK})
99 log DEBUG "phy '${phy}' was handled by port '${port}'"
100 break
101 ;;
102 ${EXIT_NOT_HANDLED})
103 log DEBUG "phy '${phy}' was not handled by port '${port}'"
104 ;;
105 *)
106 log WARNING "Unknown exit code for port '${port}': ${ret}"
107 ;;
108 esac
9ea57fb8
MT
109 done
110 ;;
111
112 # Do nothing for all the rest.
113 *)
114 log DEBUG "Don't create a port configuration for device '${INTERFACE}' of type '${type}'."
115 ;;
116 esac
117 exit ${EXIT_OK}
8c63fa13
MT
118 fi
119
3a7fef62
MT
120 # Check, if the device is configured in a zone.
121 # If not, there is nothing to do.
fb8c7c92
MT
122 zone=$(port_zone "${port}")
123 if isset zone; then
124 zone_hotplug_event "${zone}"
125 exit ${?}
3a7fef62
MT
126 fi
127 ;;
128
129 remove|unregister)
9ea57fb8
MT
130 # After the interface has been removed/unplugged,
131 # there are often daemons (like hostapd) which need
132 # to be stopped.
133 port_exists ${INTERFACE} && port_down ${INTERFACE}
3a7fef62
MT
134 ;;
135esac
136
137exit ${EXIT_OK}