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