]>
Commit | Line | Data |
---|---|---|
a1a8f0f4 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 | # Setup logging. |
23 | LOG_FACILITY="network-hotplug-rename" | |
24 | LOG_DISABLE_STDOUT="true" | |
25 | ||
26 | . /usr/lib/network/functions | |
27 | ||
e9df08ad MT |
28 | # Read network settings |
29 | network_settings_read | |
df468241 | 30 | |
a1a8f0f4 MT |
31 | # Check if the INTERFACE variable is properly set. |
32 | assert isset INTERFACE | |
33 | ||
8c63fa13 | 34 | # Log what we are doing here. |
aa96e2b9 | 35 | log DEBUG "Called for INTERFACE='${INTERFACE}'" |
8c63fa13 | 36 | |
2eaf16f3 MT |
37 | # Check if the device is already in use and |
38 | # prevent the script to touch it in any way. | |
39 | if ! device_is_free ${INTERFACE}; then | |
aa96e2b9 | 40 | log ERROR "The device '${INTERFACE}' is in use" |
2eaf16f3 MT |
41 | exit ${EXIT_ERROR} |
42 | fi | |
43 | ||
aa96e2b9 MT |
44 | # Everything is wrapped into a function so that we can use locking on it |
45 | main() { | |
285bb232 MT |
46 | # Check if the device has a unique MAC address (which is |
47 | # what are using to uniquely identify an interface) | |
48 | local address="$(device_get_address "${INTERFACE}")" | |
49 | if isset address && [ "${address}" = "00:00:00:00:00:00" ]; then | |
50 | log DEBUG "Ignoring interface ${INTERFACE} with invalid MAC address ${address}" | |
51 | return ${EXIT_OK} | |
52 | fi | |
53 | ||
aa96e2b9 MT |
54 | # Determine the type of the device and then see what |
55 | # we need to do with it. | |
56 | local type="$(device_get_type "${INTERFACE}")" | |
2eaf16f3 | 57 | |
aa96e2b9 | 58 | log DEBUG "Interface '${INTERFACE}' is of type '${type}'" |
2eaf16f3 | 59 | |
aa96e2b9 MT |
60 | case "${type}" in |
61 | ethernet) | |
62 | # Search within all the port configurations | |
63 | # if this port has already been configured. | |
64 | local port | |
65 | for port in $(ports_get_all); do | |
66 | port_cmd hotplug_rename "${port}" "${INTERFACE}" &>/dev/null | |
67 | if [ $? -eq ${EXIT_TRUE} ]; then | |
ec87f5ce | 68 | print "${port}" |
aa96e2b9 MT |
69 | exit ${EXIT_OK} |
70 | fi | |
71 | done | |
2eaf16f3 | 72 | |
ec87f5ce MT |
73 | # Could not find a valid port configuration, creating a new one |
74 | port="$(port_find_free "${PORT_PATTERN}")" | |
75 | assert isset port | |
aa96e2b9 | 76 | |
ec87f5ce MT |
77 | # Create a new port configuration with the new name |
78 | if ! port_new "ethernet" "${port}" "${INTERFACE}"; then | |
79 | log ERROR "Could not create new port configuration for ${INTERFACE}" | |
80 | return ${EXIT_ERROR} | |
81 | fi | |
82 | ||
83 | print "${port}" | |
aa96e2b9 MT |
84 | ;; |
85 | esac | |
86 | ||
87 | return ${EXIT_OK} | |
88 | } | |
a1a8f0f4 | 89 | |
aa96e2b9 MT |
90 | # Run perform rename function exclusively |
91 | lock "${RUN_DIR}/.network-rename-lock" main || exit $? |