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