]>
Commit | Line | Data |
---|---|---|
600b99fb MT |
1 | #!/bin/bash |
2 | ############################################################################### | |
3 | # # | |
4 | # IPFire.org - A linux based firewall # | |
5 | # Copyright (C) 2015 IPFire Team <info@ipfire.org> # | |
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 | ||
22 | # Check if all appropriate variables are set | |
23 | [ -n "${INTERFACE}" ] || exit 2 | |
24 | ||
25 | # Ignore virtual interfaces, etc. | |
26 | case "${INTERFACE}" in | |
27 | lo) | |
28 | exit 0 | |
29 | ;; | |
30 | tun*) | |
31 | exit 0 | |
32 | ;; | |
33 | ppp*) | |
34 | exit 0 | |
35 | ;; | |
36 | esac | |
37 | ||
38 | # Check if INTERFACE actually exists | |
39 | [ -d "/sys/class/net/${INTERFACE}" ] || exit 1 | |
40 | ||
41 | # If the network configuration is not readable, | |
42 | # we cannot go on. | |
43 | if [ ! -r "/var/ipfire/ethernet/settings" ]; then | |
44 | exit 1 | |
45 | fi | |
46 | ||
47 | # Read network settings | |
48 | eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) | |
49 | ||
50 | # Standard zones | |
51 | ZONES="RED GREEN ORANGE BLUE" | |
52 | ||
53 | # Determine the address of INTERFACE | |
54 | ADDRESS="$(</sys/class/net/${INTERFACE}/address)" | |
55 | ||
56 | # Walk through all zones and find the matching interface | |
57 | for zone in ${ZONES}; do | |
58 | address="${zone}_MACADDR" | |
59 | device="${zone}_DEV" | |
7b616db4 | 60 | mode="${zone}_MODE" |
087a2001 | 61 | slaves="${zone}_SLAVES" |
600b99fb | 62 | |
087a2001 DW |
63 | # Return DEV when the address matches |
64 | if [ "${!address,,}" = "${ADDRESS,,}" ]; then | |
65 | echo "${!device}" | |
66 | exit 0 | |
67 | fi | |
7b616db4 | 68 | |
600b99fb MT |
69 | # If a matching interface has been found we will |
70 | # print the name to which udev will rename it. | |
1857244e | 71 | case "${!mode}" in |
4aef53d5 | 72 | bridge) |
087a2001 DW |
73 | counter=0 |
74 | for slave in ${!slaves}; do | |
75 | if [ "${slave,,}" = "${ADDRESS,,}" ]; then | |
76 | echo "${!device}p${counter}" | |
77 | fi | |
78 | (( counter += 1 )) | |
79 | done | |
4aef53d5 | 80 | ;; |
1857244e | 81 | esac |
600b99fb MT |
82 | done |
83 | ||
84 | # If we get here we have not found a matching device, | |
85 | # but we won't return an error any way. The new device | |
86 | # will remain with the previous name. | |
87 | exit 0 |