Page MenuHomeFreeBSD

D11635.id30898.diff
No OneTemporary

D11635.id30898.diff

Index: contrib/hyperv/tools/scripts/hyperv_vfattach
===================================================================
--- /dev/null
+++ contrib/hyperv/tools/scripts/hyperv_vfattach
@@ -0,0 +1,49 @@
+#!/bin/sh
+
+#
+# If transparent VF is enabled, don't do anything.
+#
+
+sysctl -n hw.hn.vf_transparent > /dev/null 2>&1
+if [ $? -ne 0 ]
+then
+ # Old kernel; no transparent VF.
+ vf_transparent=0
+else
+ vf_transparent=`sysctl -n hw.hn.vf_transparent`
+fi
+
+if [ $vf_transparent -ne 0 ]
+then
+ exit 0
+fi
+
+#
+# Check to see whether $1 is a VF or not.
+# If $1 is a VF, bring it up now.
+#
+
+sysctl -n hw.hn.vflist > /dev/null 2>&1
+if [ $? -ne 0 ]
+then
+ # Old kernel; nothing could be done properly.
+ exit 0
+fi
+
+iface=$1
+vf_list=`sysctl -n hw.hn.vflist`
+
+for vf in $vf_list
+do
+ if [ $vf = $iface ]
+ then
+ #
+ # Linger a little bit mainly to make sure
+ # that $iface is fully attached.
+ #
+ sleep 2
+
+ ifconfig $iface up
+ break
+ fi
+done
Index: contrib/hyperv/tools/scripts/hyperv_vfup
===================================================================
--- /dev/null
+++ contrib/hyperv/tools/scripts/hyperv_vfup
@@ -0,0 +1,119 @@
+#!/bin/sh
+
+. /etc/rc.subr
+. /etc/network.subr
+
+load_rc_config netif
+
+#
+# Customized per-interface setup, e.g. hyperv_vfup.hn1
+#
+# NOTE-CUSTOMIZE:
+# Comment this out, if this script is used as template
+# for the customized per-interface setup.
+#
+if [ -f /usr/libexec/hyperv/hyperv_vfup.$1 ]
+then
+ /usr/libexec/hyperv/hyperv_vfup.$1
+ exit $?
+fi
+
+# NOTE-CUSTOMIZE:
+#hn=${0##*.}
+hn=$1
+hn_unit=`echo $hn | sed 's/[^0-9]*//g'`
+
+vf=`sysctl -n dev.hn.$hn_unit.vf`
+if [ ! $vf ]
+then
+ # Race happened; VF was removed, before we ran.
+ echo "$hn: VF was detached"
+ exit 0
+fi
+
+#
+# Create laggX for hnX.
+# Add VF and hnX to laggX.
+#
+
+lagg=lagg$hn_unit
+
+ifconfig $lagg > /dev/null 2>&1
+if [ $? -ne 0 ]
+then
+ #
+ # No laggX, create it now.
+ #
+ ifconfig $lagg create > /dev/null 2>&1
+ if [ $? -ne 0 ]
+ then
+ echo "$lagg creation failed"
+ exit 1
+ fi
+
+ #
+ # Configure laggX (failover), add hnX and VF to it.
+ #
+ ifconfig $lagg laggproto failover laggport $hn laggport $vf
+ ifconfig $lagg inet6 no_dad
+
+ #
+ # Stop dhclient on hnX, if any.
+ #
+ pidfile=/var/run/dhclient.$hn.pid
+ if [ -f $pidfile ]
+ then
+ kill -TERM `cat $pidfile`
+ fi
+
+ #
+ # Remove all configured IPv4 addresses on hnX, e.g.
+ # configured by dhclient. laggX will take over the
+ # network operations.
+ #
+ while true
+ do
+ ifconfig $hn -alias > /dev/null 2>&1
+ if [ $? -ne 0 ]
+ then
+ break
+ fi
+ done
+
+ # TODO: Remove IPv6 addresses on hnX
+
+ #
+ # Use hnX's configuration for laggX
+ #
+ # NOTE-CUSTOMIZE:
+ # If this script is used as template for the customized
+ # per-interface setup, replace this with whatever you
+ # want to do with the laggX.
+ #
+ if dhcpif $hn;
+ then
+ ifconfig $lagg up
+ if syncdhcpif $hn;
+ then
+ dhclient $lagg
+ else
+ dhclient -b $lagg
+ fi
+ else
+ ifconfig_args=`ifconfig_getargs $hn`
+ if [ -n "$ifconfig_args" ]
+ then
+ ifconfig $lagg $ifconfig_args
+ fi
+ fi
+else
+ #
+ # laggX exists. Check whether VF was there or not.
+ # If VF was not added to laggX, add it now.
+ #
+ ifconfig $lagg | grep "laggport: $vf" > /dev/null 2>&1
+ if [ $? -ne 0 ]
+ then
+ ifconfig $lagg laggport $vf
+ fi
+fi
Index: etc/devd/hyperv.conf
===================================================================
--- etc/devd/hyperv.conf
+++ etc/devd/hyperv.conf
@@ -33,3 +33,15 @@
match "cdev" "hv_fsvss_dev";
action "pkill -x hv_vss_daemon";
};
+
+notify 10 {
+ match "system" "HYPERV_NIC_VF";
+ match "type" "VF_UP";
+ action "/usr/libexec/hyperv/hyperv_vfup $subsystem";
+};
+
+notify 10 {
+ match "system" "ETHERNET";
+ match "type" "IFATTACH";
+ action "/usr/libexec/hyperv/hyperv_vfattach $subsystem";
+};
Index: libexec/hyperv/Makefile
===================================================================
--- libexec/hyperv/Makefile
+++ libexec/hyperv/Makefile
@@ -5,5 +5,6 @@
BINDIR= ${LIBEXECDIR}/hyperv
SCRIPTS= hv_set_ifconfig hv_get_dns_info hv_get_dhcp_info
+SCRIPTS+= hyperv_vfattach hyperv_vfup
.include <bsd.prog.mk>

File Metadata

Mime Type
text/plain
Expires
Sat, May 16, 7:46 AM (18 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33122358
Default Alt Text
D11635.id30898.diff (4 KB)

Event Timeline