1#!/bin/sh 2 3. /etc/rc.subr 4. /etc/network.subr 5 6load_rc_config netif 7 8# 9# Customized per-interface setup, e.g. hyperv_vfup.hn1 10# 11# NOTE-CUSTOMIZE: 12# Comment this out, if this script is used as template 13# for the customized per-interface setup. 14# 15if [ -f /usr/libexec/hyperv/hyperv_vfup.$1 ] 16then 17 /usr/libexec/hyperv/hyperv_vfup.$1 18 exit $? 19fi 20 21# NOTE-CUSTOMIZE: 22#hn=${0##*.} 23hn=$1 24hn_unit=`echo $hn | sed 's/[^0-9]*//g'` 25 26vf=`sysctl -n dev.hn.$hn_unit.vf` 27if [ ! $vf ] 28then 29 # Race happened; VF was removed, before we ran. 30 echo "$hn: VF was detached" 31 exit 0 32fi 33 34# 35# Create laggX for hnX. 36# Add VF and hnX to laggX. 37# 38 39lagg=lagg$hn_unit 40 41ifconfig $lagg > /dev/null 2>&1 42if [ $? -ne 0 ] 43then 44 # 45 # No laggX, create it now. 46 # 47 ifconfig $lagg create > /dev/null 2>&1 48 if [ $? -ne 0 ] 49 then 50 echo "$lagg creation failed" 51 exit 1 52 fi 53 54 # 55 # Configure laggX (failover), add hnX and VF to it. 56 # 57 ifconfig $lagg laggproto failover laggport $hn laggport $vf 58 ifconfig $lagg inet6 no_dad 59 60 # 61 # Stop dhclient on hnX, if any. 62 # 63 pidfile=/var/run/dhclient.$hn.pid 64 if [ -f $pidfile ] 65 then 66 kill -TERM `cat $pidfile` 67 fi 68 69 # 70 # Remove all configured IPv4 addresses on hnX, e.g. 71 # configured by dhclient. laggX will take over the 72 # network operations. 73 # 74 while true 75 do 76 ifconfig $hn -alias > /dev/null 2>&1 77 if [ $? -ne 0 ] 78 then 79 break 80 fi 81 done 82 83 # TODO: Remove IPv6 addresses on hnX 84 85 # 86 # Use hnX's configuration for laggX 87 # 88 # NOTE-CUSTOMIZE: 89 # If this script is used as template for the customized 90 # per-interface setup, replace this with whatever you 91 # want to do with the laggX. 92 # 93 if dhcpif $hn; 94 then 95 ifconfig $lagg up 96 if syncdhcpif $hn; 97 then 98 dhclient $lagg 99 else 100 dhclient -b $lagg 101 fi 102 else 103 ifconfig_args=`ifconfig_getargs $hn` 104 if [ -n "$ifconfig_args" ] 105 then 106 ifconfig $lagg $ifconfig_args 107 fi 108 fi 109else 110 # 111 # laggX exists. Check whether VF was there or not. 112 # If VF was not added to laggX, add it now. 113 # 114 ifconfig $lagg | grep "laggport: $vf" > /dev/null 2>&1 115 if [ $? -ne 0 ] 116 then 117 ifconfig $lagg laggport $vf 118 fi 119fi 120