# Call a script that will create all virtual devices for a parent device
# that has just come up.
ACTION=="add", SUBSYSTEM=="net", RUN+="/lib/udev/network-hotplug-vlan"
+
+# Call a script that will set up macvtap interfaces
+ACTION=="add", SUBSYSTEM=="net", RUN+="/lib/udev/network-hotplug-macvtap"
--- /dev/null
+#!/bin/bash
+############################################################################
+# #
+# This file is part of the IPFire Firewall. #
+# #
+# IPFire is free software; you can redistribute it and/or modify #
+# it under the terms of the GNU General Public License as published by #
+# the Free Software Foundation; either version 2 of the License, or #
+# (at your option) any later version. #
+# #
+# IPFire is distributed in the hope that it will be useful, #
+# but WITHOUT ANY WARRANTY; without even the implied warranty of #
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
+# GNU General Public License for more details. #
+# #
+# You should have received a copy of the GNU General Public License #
+# along with IPFire; if not, write to the Free Software #
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA #
+# #
+# Copyright (C) 2016 IPFire Team <info@ipfire.org> #
+# #
+############################################################################
+
+[ -n "${INTERFACE}" ] || exit 2
+
+PHYSICAL_INTERFACE="${INTERFACE}"
+VIRTUAL_INTERFACE="${INTERFACE%phys}"
+#VIRTUAL_INTERFACE="${VIRTUAL_INTERFACE}0"
+
+# Do nothing if the physical interface does not end with "phys"
+case "${PHYSICAL_INTERFACE}" in
+ *phys)
+ ;;
+ *)
+ exit 0
+ ;;
+esac
+
+ADDRESS="$(</sys/class/net/${PHYSICAL_INTERFACE}/address)"
+rand="$(</proc/sys/kernel/random/uuid)"
+rand="${rand//-/}"
+GENERATED_ADDRESS=$(echo "02:${rand:0:2}:${rand:2:2}:${rand:4:2}:${rand:6:2}:${rand:8:2}")
+
+ip link add link "${PHYSICAL_INTERFACE}" "${VIRTUAL_INTERFACE}" address "${ADDRESS}" type macvlan mode bridge
+ip link set "${PHYSICAL_INTERFACE}" address "${GENERATED_ADDRESS}"
+ip link set "${PHYSICAL_INTERFACE}" up
for zone in ${ZONES}; do
address="${zone}_MACADDR"
device="${zone}_DEV"
+ mode="${zone}_MODE"
# Skip if address or device is unset
[ -n "${!address}" -a -n "${!device}" ] || continue
+ # Compare MAC addresses
+ [ "${ADDRESS}" = "${!address}" ] || continue
+
# If a matching interface has been found we will
# print the name to which udev will rename it.
- if [ "${ADDRESS}" = "${!address}" ]; then
+ if [ "${!mode}" = "macvtap" ]; then
+ echo "${!device}phys"
+ else
echo "${!device}"
- exit 0
fi
+
+ exit 0
done
# If we get here we have not found a matching device,
/lib/udev/network-hotplug-rename
install -v -m 755 $(DIR_SRC)/config/udev/network-hotplug-vlan \
/lib/udev/network-hotplug-vlan
+ install -v -m 755 $(DIR_SRC)/config/udev/network-hotplug-macvtap \
+ /lib/udev/network-hotplug-macvtap
install -v -m 644 $(DIR_SRC)/config/udev/60-net.rules \
/lib/udev/rules.d