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