Index: udev-147/extras/net-sriov-names/76-net-sriov-names.rules
===================================================================
--- /dev/null
+++ udev-147/extras/net-sriov-names/76-net-sriov-names.rules
@@ -0,0 +1,14 @@
+# do not edit this file, it will be overwritten on update
+#
+# rename SRIOV virtual function interfaces
+
+ACTION=="remove", GOTO="net-sriov-names_end"
+
+SUBSYSTEM=="net", SUBSYSTEMS=="pci", ACTION=="add", NAME=="?*", ENV{INTERFACE_NEW}="$name"
+SUBSYSTEM=="net", SUBSYSTEMS=="pci", ACTION=="add", IMPORT{program}="net-set-sriov-names"
+
+# rename interface if needed
+ENV{INTERFACE_NEW}=="?*", NAME="$env{INTERFACE_NEW}"
+ENV{INTERFACE_NEW}=="", DRIVERS=="cxgb4vf|igbvf|ixgbevf", NAME="vf$attr{ifindex}"
+
+LABEL="net-sriov-names_end"
Index: udev-147/extras/net-sriov-names/net-set-sriov-names
===================================================================
--- /dev/null
+++ udev-147/extras/net-sriov-names/net-set-sriov-names
@@ -0,0 +1,79 @@
+#!/bin/bash -e
+#
+# This script is run to rename virtual interfaces
+#
+
+if [ -n "$UDEV_LOG" ]; then
+	if [ "$UDEV_LOG" -ge 7 ]; then
+		set -x
+	fi
+fi
+
+# according to dev_new_index(), ifindex is within [1, INT_MAX]
+int_max=$(/usr/bin/getconf INT_MAX)
+ifindex_before() {
+	a=$1
+	b=$2
+
+	((0 < (b - a) && (b - a) < int_max / 2 ||
+		-1 * int_max < (b - a) && (b - a) < -1 * int_max / 2))
+}
+
+rename_interface() {
+	local src_net=$1
+	local dest_net=$2
+	local err=0
+
+	/sbin/ip link set dev $src_net down
+	/sbin/ip link set dev $src_net name $dest_net
+}
+
+if [ -z "$INTERFACE" ]; then
+	echo "missing \$INTERFACE" >&2
+	exit 1
+fi
+
+if [ -e "/sys/class/net/$INTERFACE/device/physfn" ]; then
+	pf=$(ls -1 "/sys/class/net/$INTERFACE/device/physfn/net")
+	if [ $(echo "$pf" | wc -l) -ne 1 ]; then
+		echo "too many pf's" >&2
+		exit 1
+	fi
+	read vfindex < "/sys/class/net/$INTERFACE/ifindex"
+	read pfindex < "/sys/class/net/$pf/ifindex"
+	if ifindex_before $pfindex $vfindex; then
+		bus_info=$(basename $(readlink "/sys/class/net/$INTERFACE/device"))
+		for virtfn in "/sys/class/net/$pf/device/"virtfn*; do
+			if [ "$(basename $(readlink "$virtfn"))" = "$bus_info" ]; then
+				vfnum=$(basename "$virtfn")
+				vfnum=${vfnum#virtfn}
+				echo "INTERFACE_NEW=$pf.vf$vfnum"
+				exit 0
+			fi
+		done
+	fi
+fi
+
+read pfindex < "/sys/class/net/$INTERFACE/ifindex"
+shopt -s nullglob
+for virtfn in "/sys/class/net/$INTERFACE/device/"virtfn*; do
+	vf=$(ls -1 "$virtfn/net")
+	if [ $(echo "$vf" | wc -l) -ne 1 ]; then
+		echo "too many vf's" >&2
+		exit 1
+	fi
+	read vfindex < "/sys/class/net/$vf/ifindex"
+	if ifindex_before $vfindex $pfindex; then
+		vfnum=$(basename "$virtfn")
+		vfnum=${vfnum#virtfn}
+		if [ "$INTERFACE_NEW" ]; then
+			new_name=$INTERFACE_NEW
+		else
+			new_name=$INTERFACE
+		fi
+		new_name="$new_name.vf$vfnum"
+		if [ "$vf" != "$new_name" ]; then
+			rename_interface "$vf" "$new_name"
+		fi
+	fi
+done
Index: udev-147/Makefile.am
===================================================================
--- udev-147.orig/Makefile.am
+++ udev-147/Makefile.am
@@ -191,6 +191,12 @@ dist_udevrules_DATA += extras/firmware/5
 dist_udevrules_DATA += extras/hotplug_mem_cpu/80-hotplug_mem_cpu.rules
 
 # ------------------------------------------------------------------------------
+# Virtual function interface renaming
+# ------------------------------------------------------------------------------
+dist_udevrules_DATA += extras/net-sriov-names/76-net-sriov-names.rules
+dist_libexec_SCRIPTS += extras/net-sriov-names/net-set-sriov-names
+
+# ------------------------------------------------------------------------------
 # rule_generator - persistent network and optical device rule generator
 # ------------------------------------------------------------------------------
 dist_libexec_SCRIPTS += \
Index: udev-147/Makefile.in
===================================================================
--- udev-147.orig/Makefile.in
+++ udev-147/Makefile.in
@@ -320,6 +320,7 @@ udev_udevd_DEPENDENCIES = libudev/libude
 am__dist_libexec_SCRIPTS_DIST = extras/firmware/firmware.sh \
 	extras/rule_generator/write_cd_rules \
 	extras/rule_generator/write_net_rules \
+	extras/net-sriov-names/net-set-sriov-names \
 	extras/keymap/findkeyboards
 SCRIPTS = $(dist_libexec_SCRIPTS)
 DEFAULT_INCLUDES = -I.@am__isrc@
@@ -467,6 +468,7 @@ am__dist_udevrules_DATA_DIST = rules/rul
 	extras/modem-modeswitch/61-option-modem-modeswitch.rules \
 	extras/modem-modeswitch/61-mobile-action.rules \
 	extras/hotplug_mem_cpu/80-hotplug_mem_cpu.rules \
+	extras/net-sriov-names/76-net-sriov-names.rules \
 	extras/keymap/95-keymap.rules
 DATA = $(dist_doc_DATA) $(dist_udevconf_DATA) $(dist_udevhome_DATA) \
 	$(dist_udevkeymap_DATA) $(dist_udevrules_DATA) \
@@ -786,7 +788,8 @@ udev_test_udev_LDADD = libudev/libudev-p
 # ------------------------------------------------------------------------------
 dist_libexec_SCRIPTS = extras/firmware/firmware.sh \
 	extras/rule_generator/write_cd_rules \
-	extras/rule_generator/write_net_rules $(am__append_10)
+	extras/rule_generator/write_net_rules \
+	extras/net-sriov-names/net-set-sriov-names $(am__append_10)
 udevhomedir = $(libexecdir)
 dist_udevhome_DATA = extras/rule_generator/rule_generator.functions
 
