1#!/bin/sh 2 3. /etc/rc.subr 4. /etc/network.subr 5 6load_rc_config netif 7 8# Configure IPv6 on the lagg using the synthetic interface's rc.conf values. 9# Keep the variable remapping local to this subshell. 10ipv6_lagg_up() 11( 12 local var value suffix ifconfig_args 13 14 afexists inet6 || return 0 15 if ! ipv6if $hn && ! checkyesno ipv6_activate_all_interfaces 16 then 17 return 0 18 fi 19 20 for var in `list_vars "ifconfig_${hn}_*"` 21 do 22 suffix=${var#ifconfig_${hn}_} 23 case $suffix in 24 ipv6|alias*) 25 eval value=\"\$$var\" 26 setvar "ifconfig_${lagg}_${suffix}" "$value" 27 ;; 28 esac 29 done 30 value=`get_if_var $hn ipv6_prefix_IF` 31 setvar "ipv6_prefix_${lagg}" "$value" 32 for var in `list_vars "ipv6_ifconfig_${hn}"` \ 33 `list_vars "ipv6_ifconfig_${hn}_alias*"` 34 do 35 suffix=${var#ipv6_ifconfig_${hn}} 36 eval value=\"\$$var\" 37 setvar "ipv6_ifconfig_${lagg}${suffix}" "$value" 38 done 39 ipv6_network_interfaces="$ipv6_network_interfaces $lagg" 40 41 ifconfig $lagg inet6 -ifdisabled up || return 1 42 for ifconfig_args in "`ifconfig_getargs $lagg ipv6`" \ 43 "`get_if_var $lagg ipv6_ifconfig_IF`" 44 do 45 [ -n "$ifconfig_args" ] || continue 46 # Accept legacy values without the address-family keyword. 47 case $ifconfig_args in 48 inet6|inet6[[:space:]]*) ;; 49 *) ifconfig_args="inet6 $ifconfig_args" ;; 50 esac 51 ifconfig $lagg $ifconfig_args || return 1 52 done 53 ipv6_up $lagg 54 ipv6_accept_rtadv_up $lagg 55 return 0 56) 57 58# 59# Customized per-interface setup, e.g. hyperv_vfup.hn1 60# 61# NOTE-CUSTOMIZE: 62# Comment this out, if this script is used as template 63# for the customized per-interface setup. 64# 65if [ -f /usr/libexec/hyperv/hyperv_vfup.$1 ] 66then 67 /usr/libexec/hyperv/hyperv_vfup.$1 68 exit $? 69fi 70 71# NOTE-CUSTOMIZE: 72#hn=${0##*.} 73hn=$1 74hn_unit=`echo $hn | sed 's/[^0-9]*//g'` 75 76vf=`sysctl -n dev.hn.$hn_unit.vf` 77if [ ! $vf ] 78then 79 # Race happened; VF was removed, before we ran. 80 echo "$hn: VF was detached" 81 exit 0 82fi 83 84# 85# Create laggX for hnX. 86# Add VF and hnX to laggX. 87# 88 89lagg=lagg$hn_unit 90 91ifconfig $lagg > /dev/null 2>&1 92if [ $? -ne 0 ] 93then 94 # 95 # No laggX, create it now. 96 # 97 ifconfig $lagg create > /dev/null 2>&1 98 if [ $? -ne 0 ] 99 then 100 echo "$lagg creation failed" 101 exit 1 102 fi 103 104 # 105 # Stop accepting advertisements on hnX. Leave IPv6 enabled and its 106 # link-local address in place until lagg has purged the member's 107 # IPv6 addresses, prefixes, and default routers. 108 # 109 if afexists inet6 110 then 111 ifconfig $hn inet6 -accept_rtadv || exit 1 112 fi 113 114 # Configure laggX (failover), add hnX and VF to it. 115 ifconfig $lagg laggproto failover laggport $hn laggport $vf || exit 1 116 if afexists inet6 117 then 118 # lagg does not purge an IPv6-disabled member or one without a 119 # link-local address. Disable IPv6 and remove any addresses left. 120 # SLAAC addresses are relearned on lagg, not copied as permanent. 121 ifconfig $hn inet6 ifdisabled || exit 1 122 inet6_status=`ifconfig $hn inet6` || exit 1 123 for addr in `printf '%s\n' "$inet6_status" | \ 124 awk '$1 == "inet6" { print $2 }'` 125 do 126 ifconfig $hn inet6 "$addr" -alias || exit 1 127 done 128 ifconfig $lagg inet6 no_dad 129 fi 130 131 # 132 # Stop dhclient on hnX, if any. 133 # 134 pidfile=/var/run/dhclient.$hn.pid 135 if [ -f $pidfile ] 136 then 137 kill -TERM `cat $pidfile` 138 fi 139 140 # 141 # Remove all configured IPv4 addresses on hnX, e.g. 142 # configured by dhclient. laggX will take over the 143 # network operations. 144 # 145 # Enumerate addresses; an empty ifconfig -alias may return success. 146 ipv4_down $hn 147 148 # 149 # Use hnX's configuration for laggX 150 # 151 # NOTE-CUSTOMIZE: 152 # If this script is used as template for the customized 153 # per-interface setup, replace this with whatever you 154 # want to do with the laggX. 155 # 156 if dhcpif $hn; 157 then 158 ifconfig $lagg up 159 if syncdhcpif $hn; 160 then 161 dhclient $lagg 162 else 163 dhclient -b $lagg 164 fi 165 else 166 ifconfig_args=`ifconfig_getargs $hn` 167 if [ -n "$ifconfig_args" ] 168 then 169 ifconfig $lagg $ifconfig_args 170 fi 171 fi 172 ipv6_lagg_up || exit 1 173else 174 # 175 # laggX exists. Check whether VF was there or not. 176 # If VF was not added to laggX, add it now. 177 # 178 ifconfig $lagg | grep "laggport: $vf" > /dev/null 2>&1 179 if [ $? -ne 0 ] 180 then 181 ifconfig $lagg laggport $vf 182 fi 183fi 184