]> git.ipfire.org Git - people/stevee/network.git/blame - src/udev/network-hotplug
Rename all "config" to "settings"
[people/stevee/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
ec63256a 39 if ! device_is_ethernet ${INTERFACE}; then
8c63fa13
MT
40 log DEBUG "Called for interface '${INTERFACE}' which is a virtual interface. Exiting."
41 exit ${EXIT_OK}
42 fi
3a7fef62
MT
43fi
44
45case "${ACTION}" in
46 add|register)
8c63fa13
MT
47 # Check, if there is a configuration for that device.
48 if port_exists ${INTERFACE}; then
49 port=${INTERFACE}
50
51 # Create new configuration for _real_ network devices.
8c63fa13 52 else
9ea57fb8
MT
53 type=$(device_get_type ${INTERFACE})
54 case "${type}" in
55 # If the given device was not configured,
56 # we create an initial configuration.
57 ethernet|real)
58 port_create ethernet ${INTERFACE}
59 ;;
60
e6993835
MT
61 # Handle batman-adv and wireless devices.
62 batman-adv|batman-adv-port|wireless)
06a6f01e
MT
63 # Load regulatory domain for wireless devices
64 wireless_init_reg_domain
65
9ea57fb8
MT
66 # Save the phy of this device for later.
67 phy=$(phy_get ${INTERFACE})
68 assert isset phy
69
70 # Remove the unconfigured wireless device.
71 wireless_remove ${INTERFACE}
72
73 # Create configured child devices.
74 for port in $(ports_get_all); do
75 port_cmd hotplug ${port} ${phy}
76 done
77 ;;
78
79 # Do nothing for all the rest.
80 *)
81 log DEBUG "Don't create a port configuration for device '${INTERFACE}' of type '${type}'."
82 ;;
83 esac
84 exit ${EXIT_OK}
8c63fa13
MT
85 fi
86
3a7fef62
MT
87 zone=$(port_zone ${port})
88
89 # Check, if the device is configured in a zone.
90 # If not, there is nothing to do.
91 isset zone || exit ${EXIT_OK}
92
9ea57fb8
MT
93 # If the zone is already up, we add the device
94 # to the zone.
95 if zone_is_up ${zone}; then
3a7fef62
MT
96 zone_up ${zone}
97 fi
98 ;;
99
100 remove|unregister)
9ea57fb8
MT
101 # After the interface has been removed/unplugged,
102 # there are often daemons (like hostapd) which need
103 # to be stopped.
104 port_exists ${INTERFACE} && port_down ${INTERFACE}
3a7fef62
MT
105 ;;
106esac
107
108exit ${EXIT_OK}