10Sstevel@tonic-gate#!/bin/sh 20Sstevel@tonic-gate# 30Sstevel@tonic-gate# CDDL HEADER START 40Sstevel@tonic-gate# 50Sstevel@tonic-gate# The contents of this file are subject to the terms of the 64121Samaguire# Common Development and Distribution License (the "License"). 74121Samaguire# You may not use this file except in compliance with the License. 80Sstevel@tonic-gate# 90Sstevel@tonic-gate# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 100Sstevel@tonic-gate# or http://www.opensolaris.org/os/licensing. 110Sstevel@tonic-gate# See the License for the specific language governing permissions 120Sstevel@tonic-gate# and limitations under the License. 130Sstevel@tonic-gate# 140Sstevel@tonic-gate# When distributing Covered Code, include this CDDL HEADER in each 150Sstevel@tonic-gate# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 160Sstevel@tonic-gate# If applicable, add the following below this CDDL HEADER, with the 170Sstevel@tonic-gate# fields enclosed by brackets "[]" replaced with your own identifying 180Sstevel@tonic-gate# information: Portions Copyright [yyyy] [name of copyright owner] 190Sstevel@tonic-gate# 200Sstevel@tonic-gate# CDDL HEADER END 210Sstevel@tonic-gate# 220Sstevel@tonic-gate# 238485SPeter.Memishian@Sun.COM# Copyright 2009 Sun Microsystems, Inc. All rights reserved. 240Sstevel@tonic-gate# Use is subject to license terms. 250Sstevel@tonic-gate# 260Sstevel@tonic-gate# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T. 270Sstevel@tonic-gate# All rights reserved. 280Sstevel@tonic-gate# 290Sstevel@tonic-gate 308485SPeter.Memishian@Sun.COM# Print warnings to console 318485SPeter.Memishian@Sun.COMwarn_failed_ifs() { 328485SPeter.Memishian@Sun.COM echo "Failed to $1 interface(s):$2" >/dev/msglog 338485SPeter.Memishian@Sun.COM} 348485SPeter.Memishian@Sun.COM 350Sstevel@tonic-gate# 360Sstevel@tonic-gate# shcat file 370Sstevel@tonic-gate# Simulates cat in sh so it doesn't need to be on the root filesystem. 380Sstevel@tonic-gate# 390Sstevel@tonic-gateshcat() { 400Sstevel@tonic-gate while [ $# -ge 1 ]; do 410Sstevel@tonic-gate while read i; do 420Sstevel@tonic-gate echo "$i" 430Sstevel@tonic-gate done < $1 440Sstevel@tonic-gate shift 450Sstevel@tonic-gate done 460Sstevel@tonic-gate} 470Sstevel@tonic-gate 480Sstevel@tonic-gate# 498485SPeter.Memishian@Sun.COM# inet_list list of IPv4 interfaces. 508485SPeter.Memishian@Sun.COM# inet6_list list of IPv6 interfaces. 518485SPeter.Memishian@Sun.COM# ipmp_list list of IPMP IPv4 interfaces. 528485SPeter.Memishian@Sun.COM# ipmp6_list list of IPMP IPv6 interfaces. 538485SPeter.Memishian@Sun.COM# inet_plumbed list of plumbed IPv4 interfaces. 548485SPeter.Memishian@Sun.COM# inet6_plumbed list of plumbed IPv6 interfaces. 558485SPeter.Memishian@Sun.COM# ipmp_created list of created IPMP IPv4 interfaces. 568485SPeter.Memishian@Sun.COM# ipmp6_created list of created IPMP IPv6 interfaces. 578485SPeter.Memishian@Sun.COM# inet_failed list of IPv4 interfaces that failed to plumb. 588485SPeter.Memishian@Sun.COM# inet6_failed list of IPv6 interfaces that failed to plumb. 598485SPeter.Memishian@Sun.COM# ipmp_failed list of IPMP IPv4 interfaces that failed to be created. 608485SPeter.Memishian@Sun.COM# ipmp6_failed list of IPMP IPv6 interfaces that failed to be created. 610Sstevel@tonic-gate# 620Sstevel@tonic-gateunset inet_list inet_plumbed inet_failed \ 638485SPeter.Memishian@Sun.COM inet6_list inet6_plumbed inet6_failed \ 648485SPeter.Memishian@Sun.COM ipmp_list ipmp_created ipmp_failed \ 658485SPeter.Memishian@Sun.COM ipmp6_list ipmp6_created ipmp6_failed 668485SPeter.Memishian@Sun.COM 670Sstevel@tonic-gate# 680Sstevel@tonic-gate# get_physical interface 690Sstevel@tonic-gate# 708485SPeter.Memishian@Sun.COM# Return physical interface corresponding to the given interface. 710Sstevel@tonic-gate# 720Sstevel@tonic-gateget_physical() 730Sstevel@tonic-gate{ 740Sstevel@tonic-gate ORIGIFS="$IFS" 750Sstevel@tonic-gate IFS="${IFS}:" 760Sstevel@tonic-gate set -- $1 770Sstevel@tonic-gate IFS="$ORIGIFS" 780Sstevel@tonic-gate 790Sstevel@tonic-gate echo $1 800Sstevel@tonic-gate} 810Sstevel@tonic-gate 820Sstevel@tonic-gate# 830Sstevel@tonic-gate# get_logical interface 840Sstevel@tonic-gate# 850Sstevel@tonic-gate# Return logical interface number. Zero will be returned 868485SPeter.Memishian@Sun.COM# if there is no explicit logical number. 870Sstevel@tonic-gate# 880Sstevel@tonic-gateget_logical() 890Sstevel@tonic-gate{ 900Sstevel@tonic-gate ORIGIFS="$IFS" 910Sstevel@tonic-gate IFS="${IFS}:" 920Sstevel@tonic-gate set -- $1 930Sstevel@tonic-gate IFS="$ORIGIFS" 940Sstevel@tonic-gate 950Sstevel@tonic-gate if [ -z "$2" ]; then 960Sstevel@tonic-gate echo 0 970Sstevel@tonic-gate else 980Sstevel@tonic-gate echo $2 990Sstevel@tonic-gate fi 1000Sstevel@tonic-gate} 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate# 1030Sstevel@tonic-gate# if_comp if1 if2 1040Sstevel@tonic-gate# 1058485SPeter.Memishian@Sun.COM# Compare interfaces. Do the physical interface names and logical interface 1060Sstevel@tonic-gate# numbers match? 1070Sstevel@tonic-gate# 1080Sstevel@tonic-gateif_comp() 1090Sstevel@tonic-gate{ 1108485SPeter.Memishian@Sun.COM physical_comp $1 $2 && [ `get_logical $1` -eq `get_logical $2` ] 1110Sstevel@tonic-gate} 1128485SPeter.Memishian@Sun.COM 1130Sstevel@tonic-gate# 1140Sstevel@tonic-gate# physical_comp if1 if2 1150Sstevel@tonic-gate# 1168485SPeter.Memishian@Sun.COM# Do the two interfaces share a physical interface? 1170Sstevel@tonic-gate# 1180Sstevel@tonic-gatephysical_comp() 1190Sstevel@tonic-gate{ 1200Sstevel@tonic-gate [ "`get_physical $1`" = "`get_physical $2`" ] 1210Sstevel@tonic-gate} 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate# 1240Sstevel@tonic-gate# in_list op item list 1250Sstevel@tonic-gate# 1260Sstevel@tonic-gate# Is "item" in the given list? Use "op" to do the test, applying it to 1270Sstevel@tonic-gate# "item" and each member of the list in turn until it returns success. 1280Sstevel@tonic-gate# 1290Sstevel@tonic-gatein_list() 1300Sstevel@tonic-gate{ 1310Sstevel@tonic-gate op=$1 1320Sstevel@tonic-gate item=$2 1330Sstevel@tonic-gate shift 2 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate while [ $# -gt 0 ]; do 1360Sstevel@tonic-gate $op $item $1 && return 0 1370Sstevel@tonic-gate shift 1380Sstevel@tonic-gate done 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate return 1 1410Sstevel@tonic-gate} 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate# 1448485SPeter.Memishian@Sun.COM# get_groupifname groupname 1458485SPeter.Memishian@Sun.COM# 1468485SPeter.Memishian@Sun.COM# Return the IPMP meta-interface name for the group, if it exists. 1470Sstevel@tonic-gate# 1488485SPeter.Memishian@Sun.COMget_groupifname() 1498485SPeter.Memishian@Sun.COM{ 1508485SPeter.Memishian@Sun.COM /sbin/ipmpstat -gP -o groupname,group | while IFS=: read name ifname; do 1518485SPeter.Memishian@Sun.COM if [ "$name" = "$1" ]; then 1528485SPeter.Memishian@Sun.COM echo "$ifname" 1538485SPeter.Memishian@Sun.COM return 1548485SPeter.Memishian@Sun.COM fi 1558485SPeter.Memishian@Sun.COM done 1568485SPeter.Memishian@Sun.COM} 1578485SPeter.Memishian@Sun.COM 1588485SPeter.Memishian@Sun.COM# 1598485SPeter.Memishian@Sun.COM# create_ipmp ifname groupname type 1608485SPeter.Memishian@Sun.COM# 1618485SPeter.Memishian@Sun.COM# Helper function for create_groupifname() that returns zero if it's able 1628485SPeter.Memishian@Sun.COM# to create an IPMP interface of the specified type and place it in the 1638485SPeter.Memishian@Sun.COM# specified group, or non-zero otherwise. 1648485SPeter.Memishian@Sun.COM# 1658485SPeter.Memishian@Sun.COMcreate_ipmp() 1668485SPeter.Memishian@Sun.COM{ 1678485SPeter.Memishian@Sun.COM /sbin/ifconfig $1 >/dev/null 2>&1 && return 1 1688485SPeter.Memishian@Sun.COM /sbin/ifconfig $1 inet6 >/dev/null 2>&1 && return 1 1698485SPeter.Memishian@Sun.COM /sbin/ifconfig $1 $3 ipmp group $2 2>/dev/null 1708485SPeter.Memishian@Sun.COM} 1718485SPeter.Memishian@Sun.COM 1728485SPeter.Memishian@Sun.COM# 1738485SPeter.Memishian@Sun.COM# create_groupifname groupname type 1748485SPeter.Memishian@Sun.COM# 1758485SPeter.Memishian@Sun.COM# Create an IPMP meta-interface name for the group. We only use this 1768485SPeter.Memishian@Sun.COM# function if all of the interfaces in the group failed at boot and there 1778485SPeter.Memishian@Sun.COM# were no /etc/hostname[6].<if> files for the IPMP meta-interface. 1788485SPeter.Memishian@Sun.COM# 1798485SPeter.Memishian@Sun.COMcreate_groupifname() 1808485SPeter.Memishian@Sun.COM{ 1818485SPeter.Memishian@Sun.COM # 1828485SPeter.Memishian@Sun.COM # This is a horrible way to count from 0 to 999, but in sh and 1838485SPeter.Memishian@Sun.COM # without necessarily having /usr mounted, what else can we do? 1848485SPeter.Memishian@Sun.COM # 1858485SPeter.Memishian@Sun.COM for a in "" 1 2 3 4 5 6 7 8 9; do 1868485SPeter.Memishian@Sun.COM for b in 0 1 2 3 4 5 6 7 8 9; do 1878485SPeter.Memishian@Sun.COM for c in 0 1 2 3 4 5 6 7 8 9; do 1888485SPeter.Memishian@Sun.COM # strip leading zeroes 1898485SPeter.Memishian@Sun.COM [ "$a" = "" ] && [ "$b" = 0 ] && b="" 1908485SPeter.Memishian@Sun.COM if create_ipmp ipmp$a$b$c $1 $2; then 1918485SPeter.Memishian@Sun.COM echo ipmp$a$b$c 1928485SPeter.Memishian@Sun.COM return 1938485SPeter.Memishian@Sun.COM fi 1948485SPeter.Memishian@Sun.COM done 1958485SPeter.Memishian@Sun.COM done 1968485SPeter.Memishian@Sun.COM done 1978485SPeter.Memishian@Sun.COM} 1988485SPeter.Memishian@Sun.COM 1998485SPeter.Memishian@Sun.COM# 2008485SPeter.Memishian@Sun.COM# get_hostname_ipmpinfo interface type 2018485SPeter.Memishian@Sun.COM# 2028485SPeter.Memishian@Sun.COM# Return all requested IPMP keywords from hostname file for a given interface. 2030Sstevel@tonic-gate# 2040Sstevel@tonic-gate# Example: 2058485SPeter.Memishian@Sun.COM# get_hostname_ipmpinfo hme0 inet keyword [ keyword ... ] 2060Sstevel@tonic-gate# 2078485SPeter.Memishian@Sun.COMget_hostname_ipmpinfo() 2080Sstevel@tonic-gate{ 2090Sstevel@tonic-gate case "$2" in 2108485SPeter.Memishian@Sun.COM inet) file=/etc/hostname.$1 2110Sstevel@tonic-gate ;; 2128485SPeter.Memishian@Sun.COM inet6) file=/etc/hostname6.$1 2130Sstevel@tonic-gate ;; 2140Sstevel@tonic-gate *) 2150Sstevel@tonic-gate return 2160Sstevel@tonic-gate ;; 2170Sstevel@tonic-gate esac 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate [ -r "$file" ] || return 2200Sstevel@tonic-gate 2218485SPeter.Memishian@Sun.COM type=$2 2228485SPeter.Memishian@Sun.COM shift 2 2238485SPeter.Memishian@Sun.COM 2240Sstevel@tonic-gate # 2258485SPeter.Memishian@Sun.COM # Read through the hostname file looking for the specified 2268485SPeter.Memishian@Sun.COM # keywords. Since there may be several keywords that cancel 2278485SPeter.Memishian@Sun.COM # each other out, the caller must post-process as appropriate. 2280Sstevel@tonic-gate # 2290Sstevel@tonic-gate while read line; do 2300Sstevel@tonic-gate [ -z "$line" ] && continue 2318485SPeter.Memishian@Sun.COM /sbin/ifparse -s "$type" $line 2328485SPeter.Memishian@Sun.COM done < "$file" | while read one two; do 2338485SPeter.Memishian@Sun.COM for keyword in "$@"; do 2348485SPeter.Memishian@Sun.COM [ "$one" = "$keyword" ] && echo "$one $two" 2358485SPeter.Memishian@Sun.COM done 2360Sstevel@tonic-gate done 2370Sstevel@tonic-gate} 2380Sstevel@tonic-gate 2390Sstevel@tonic-gate# 2400Sstevel@tonic-gate# get_group_for_type interface type list 2410Sstevel@tonic-gate# 2420Sstevel@tonic-gate# Look through the set of hostname files associated with the same physical 2430Sstevel@tonic-gate# interface as "interface", and determine which group they would configure. 2440Sstevel@tonic-gate# Only hostname files associated with the physical interface or logical 2450Sstevel@tonic-gate# interface zero are allowed to set the group. 2460Sstevel@tonic-gate# 2470Sstevel@tonic-gateget_group_for_type() 2480Sstevel@tonic-gate{ 2490Sstevel@tonic-gate physical=`get_physical $1` 2500Sstevel@tonic-gate type=$2 2510Sstevel@tonic-gate group="" 2520Sstevel@tonic-gate 2530Sstevel@tonic-gate # 2540Sstevel@tonic-gate # The last setting of the group is the one that counts, which is 2550Sstevel@tonic-gate # the reason for the second while loop. 2560Sstevel@tonic-gate # 2570Sstevel@tonic-gate shift 2 2588485SPeter.Memishian@Sun.COM for ifname in "$@"; do 2598485SPeter.Memishian@Sun.COM if if_comp "$physical" $ifname; then 2608485SPeter.Memishian@Sun.COM get_hostname_ipmpinfo $ifname $type group 2610Sstevel@tonic-gate fi 2620Sstevel@tonic-gate done | while :; do 2638485SPeter.Memishian@Sun.COM read keyword grname || { 2640Sstevel@tonic-gate echo "$group" 2650Sstevel@tonic-gate break 2660Sstevel@tonic-gate } 2678485SPeter.Memishian@Sun.COM group="$grname" 2680Sstevel@tonic-gate done 2690Sstevel@tonic-gate} 2700Sstevel@tonic-gate 2710Sstevel@tonic-gate# 2728485SPeter.Memishian@Sun.COM# get_group interface 2730Sstevel@tonic-gate# 2748485SPeter.Memishian@Sun.COM# If there is both an inet and inet6 version of an interface, the group 2758485SPeter.Memishian@Sun.COM# could be set in either set of hostname files. Since inet6 is configured 2768485SPeter.Memishian@Sun.COM# after inet, if there's a setting in both files, inet6 wins. 2770Sstevel@tonic-gate# 2788485SPeter.Memishian@Sun.COMget_group() 2790Sstevel@tonic-gate{ 2808485SPeter.Memishian@Sun.COM group=`get_group_for_type $1 inet6 $inet6_list` 2818485SPeter.Memishian@Sun.COM [ -z "$group" ] && group=`get_group_for_type $1 inet $inet_list` 2828485SPeter.Memishian@Sun.COM echo $group 2830Sstevel@tonic-gate} 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate# 2860Sstevel@tonic-gate# doDHCPhostname interface 2870Sstevel@tonic-gate# Pass to this function the name of an interface. It will return 2880Sstevel@tonic-gate# true if one should enable the use of DHCP client-side host name 2890Sstevel@tonic-gate# requests on the interface, and false otherwise. 2900Sstevel@tonic-gate# 2910Sstevel@tonic-gatedoDHCPhostname() 2920Sstevel@tonic-gate{ 2930Sstevel@tonic-gate if [ -f /etc/dhcp.$1 ] && [ -f /etc/hostname.$1 ]; then 2940Sstevel@tonic-gate set -- `shcat /etc/hostname.$1` 2950Sstevel@tonic-gate [ $# -eq 2 -a "$1" = "inet" ] 2960Sstevel@tonic-gate return $? 2970Sstevel@tonic-gate fi 2980Sstevel@tonic-gate return 1 2990Sstevel@tonic-gate} 3000Sstevel@tonic-gate 3010Sstevel@tonic-gate# 3020Sstevel@tonic-gate# inet_process_hostname processor [ args ] 3030Sstevel@tonic-gate# 3040Sstevel@tonic-gate# Process an inet hostname file. The contents of the file 3050Sstevel@tonic-gate# are taken from standard input. Each line is passed 3060Sstevel@tonic-gate# on the command line to the "processor" command. 3070Sstevel@tonic-gate# Command line arguments can be passed to the processor. 3080Sstevel@tonic-gate# 3090Sstevel@tonic-gate# Examples: 3100Sstevel@tonic-gate# inet_process_hostname /sbin/ifconfig hme0 < /etc/hostname.hme0 3110Sstevel@tonic-gate# 3120Sstevel@tonic-gate# inet_process_hostname /sbin/ifparse -f < /etc/hostname.hme0 3130Sstevel@tonic-gate# 3140Sstevel@tonic-gate# If there is only line in an hostname file we assume it contains 3150Sstevel@tonic-gate# the old style address which results in the interface being brought up 3168485SPeter.Memishian@Sun.COM# and the netmask and broadcast address being set ($inet_oneline_epilogue). 3170Sstevel@tonic-gate# 3180Sstevel@tonic-gate# If there are multiple lines we assume the file contains a list of 3190Sstevel@tonic-gate# commands to the processor with neither the implied bringing up of the 3200Sstevel@tonic-gate# interface nor the setting of the default netmask and broadcast address. 3210Sstevel@tonic-gate# 3220Sstevel@tonic-gate# Return non-zero if any command fails so that the caller may alert 3230Sstevel@tonic-gate# users to errors in the configuration. 3240Sstevel@tonic-gate# 3258485SPeter.Memishian@Sun.COMinet_oneline_epilogue="netmask + broadcast + up" 3268485SPeter.Memishian@Sun.COM 3270Sstevel@tonic-gateinet_process_hostname() 3280Sstevel@tonic-gate{ 3290Sstevel@tonic-gate if doDHCPhostname $2; then 3300Sstevel@tonic-gate : 3310Sstevel@tonic-gate else 3320Sstevel@tonic-gate # 3330Sstevel@tonic-gate # Redirecting input from a file results in a sub-shell being 3340Sstevel@tonic-gate # used, hence this outer loop surrounding the "multiple_lines" 3350Sstevel@tonic-gate # and "ifcmds" variables. 3360Sstevel@tonic-gate # 3370Sstevel@tonic-gate while :; do 3380Sstevel@tonic-gate multiple_lines=false 3390Sstevel@tonic-gate ifcmds="" 3400Sstevel@tonic-gate retval=0 3410Sstevel@tonic-gate 3428485SPeter.Memishian@Sun.COM while read one rest; do 3430Sstevel@tonic-gate if [ -n "$ifcmds" ]; then 3440Sstevel@tonic-gate # 3450Sstevel@tonic-gate # This handles the first N-1 3460Sstevel@tonic-gate # lines of a N-line hostname file. 3470Sstevel@tonic-gate # 3480Sstevel@tonic-gate $* $ifcmds || retval=$? 3490Sstevel@tonic-gate multiple_lines=true 3500Sstevel@tonic-gate fi 3518485SPeter.Memishian@Sun.COM 3528485SPeter.Memishian@Sun.COM # 3538485SPeter.Memishian@Sun.COM # Strip out the "ipmp" keyword if it's the 3548485SPeter.Memishian@Sun.COM # first token, since it's used to control 3558485SPeter.Memishian@Sun.COM # interface creation, not configuration. 3568485SPeter.Memishian@Sun.COM # 3578485SPeter.Memishian@Sun.COM [ "$one" = ipmp ] && one= 3588485SPeter.Memishian@Sun.COM ifcmds="$one $rest" 3590Sstevel@tonic-gate done 3600Sstevel@tonic-gate 3610Sstevel@tonic-gate # 3620Sstevel@tonic-gate # If the hostname file is empty or consists of only 3630Sstevel@tonic-gate # blank lines, break out of the outer loop without 3640Sstevel@tonic-gate # configuring the newly plumbed interface. 3650Sstevel@tonic-gate # 3660Sstevel@tonic-gate [ -z "$ifcmds" ] && return $retval 3670Sstevel@tonic-gate if [ $multiple_lines = false ]; then 3688485SPeter.Memishian@Sun.COM # The traditional one-line hostname file. 3698485SPeter.Memishian@Sun.COM ifcmds="$ifcmds $inet_oneline_epilogue" 3700Sstevel@tonic-gate fi 3710Sstevel@tonic-gate 3720Sstevel@tonic-gate # 3730Sstevel@tonic-gate # This handles either the single-line case or 3740Sstevel@tonic-gate # the last line of the N-line case. 3750Sstevel@tonic-gate # 3760Sstevel@tonic-gate $* $ifcmds || return $? 3770Sstevel@tonic-gate return $retval 3780Sstevel@tonic-gate done 3790Sstevel@tonic-gate fi 3800Sstevel@tonic-gate} 3810Sstevel@tonic-gate 3820Sstevel@tonic-gate# 3830Sstevel@tonic-gate# inet6_process_hostname processor [ args ] 3840Sstevel@tonic-gate# 3850Sstevel@tonic-gate# Process an inet6 hostname file. The contents of the file 3860Sstevel@tonic-gate# are taken from standard input. Each line is passed 3870Sstevel@tonic-gate# on the command line to the "processor" command. 3880Sstevel@tonic-gate# Command line arguments can be passed to the processor. 3890Sstevel@tonic-gate# 3900Sstevel@tonic-gate# Examples: 3910Sstevel@tonic-gate# inet6_process_hostname /sbin/ifconfig hme0 inet6 < /etc/hostname6.hme0 3920Sstevel@tonic-gate# 3930Sstevel@tonic-gate# inet6_process_hostname /sbin/ifparse -f inet6 < /etc/hostname6.hme0 3940Sstevel@tonic-gate# 3950Sstevel@tonic-gate# Return non-zero if any of the commands fail so that the caller may alert 3960Sstevel@tonic-gate# users to errors in the configuration. 3970Sstevel@tonic-gate# 3980Sstevel@tonic-gateinet6_process_hostname() 3990Sstevel@tonic-gate{ 4000Sstevel@tonic-gate retval=0 4018485SPeter.Memishian@Sun.COM while read one rest; do 4028485SPeter.Memishian@Sun.COM # 4038485SPeter.Memishian@Sun.COM # See comment in inet_process_hostname for details. 4048485SPeter.Memishian@Sun.COM # 4058485SPeter.Memishian@Sun.COM [ "$one" = ipmp ] && one= 4068485SPeter.Memishian@Sun.COM ifcmds="$one $rest" 4078485SPeter.Memishian@Sun.COM 4080Sstevel@tonic-gate if [ -n "$ifcmds" ]; then 4090Sstevel@tonic-gate $* $ifcmds || retval=$? 4100Sstevel@tonic-gate fi 4110Sstevel@tonic-gate done 4120Sstevel@tonic-gate return $retval 4130Sstevel@tonic-gate} 4140Sstevel@tonic-gate 4150Sstevel@tonic-gate# 4168485SPeter.Memishian@Sun.COM# Process interfaces that failed to plumb. Find the IPMP meta-interface 4178485SPeter.Memishian@Sun.COM# that should host the addresses. For IPv6, only static addresses defined 4188485SPeter.Memishian@Sun.COM# in hostname6 files are moved, autoconfigured addresses are not moved. 4190Sstevel@tonic-gate# 4200Sstevel@tonic-gate# Example: 4210Sstevel@tonic-gate# move_addresses inet6 4220Sstevel@tonic-gate# 4230Sstevel@tonic-gatemove_addresses() 4240Sstevel@tonic-gate{ 4250Sstevel@tonic-gate type="$1" 4260Sstevel@tonic-gate eval "failed=\"\$${type}_failed\"" 4270Sstevel@tonic-gate eval "list=\"\$${type}_list\"" 4288485SPeter.Memishian@Sun.COM process_func="${type}_process_hostname" 4290Sstevel@tonic-gate processed="" 4300Sstevel@tonic-gate 4310Sstevel@tonic-gate if [ "$type" = inet ]; then 4328485SPeter.Memishian@Sun.COM typedesc="IPv4" 4330Sstevel@tonic-gate zaddr="0.0.0.0" 4340Sstevel@tonic-gate hostpfx="/etc/hostname" 4350Sstevel@tonic-gate else 4368485SPeter.Memishian@Sun.COM typedesc="IPv6" 4370Sstevel@tonic-gate zaddr="::" 4380Sstevel@tonic-gate hostpfx="/etc/hostname6" 4390Sstevel@tonic-gate fi 4400Sstevel@tonic-gate 4418485SPeter.Memishian@Sun.COM echo "Moving addresses from missing ${typedesc} interface(s):\c" \ 4428485SPeter.Memishian@Sun.COM >/dev/msglog 4438485SPeter.Memishian@Sun.COM 4448485SPeter.Memishian@Sun.COM for ifname in $failed; do 4458485SPeter.Memishian@Sun.COM in_list if_comp $ifname $processed && continue 4460Sstevel@tonic-gate 4478485SPeter.Memishian@Sun.COM group=`get_group $ifname` 4488485SPeter.Memishian@Sun.COM if [ -z "$group" ]; then 4498485SPeter.Memishian@Sun.COM in_list physical_comp $ifname $processed || { 4508485SPeter.Memishian@Sun.COM echo " $ifname (not moved -- not" \ 4518485SPeter.Memishian@Sun.COM "in an IPMP group)\c" >/dev/msglog 4528485SPeter.Memishian@Sun.COM processed="$processed $ifname" 4530Sstevel@tonic-gate } 4540Sstevel@tonic-gate continue 4550Sstevel@tonic-gate fi 4568485SPeter.Memishian@Sun.COM 4578485SPeter.Memishian@Sun.COM # 4588485SPeter.Memishian@Sun.COM # Lookup the IPMP meta-interface name. If one doesn't exist, 4598485SPeter.Memishian@Sun.COM # create it. 4608485SPeter.Memishian@Sun.COM # 4618485SPeter.Memishian@Sun.COM grifname=`get_groupifname $group` 4628485SPeter.Memishian@Sun.COM [ -z "$grifname" ] && grifname=`create_groupifname $group $type` 4638485SPeter.Memishian@Sun.COM 4640Sstevel@tonic-gate # 4650Sstevel@tonic-gate # The hostname files are processed twice. In the first 466*10649SPeter.Memishian@Sun.COM # pass, we are looking for all commands that apply to the 467*10649SPeter.Memishian@Sun.COM # non-additional interface address. These may be 468*10649SPeter.Memishian@Sun.COM # scattered over several files. We won't know whether the 469*10649SPeter.Memishian@Sun.COM # address represents a failover address or not until we've 470*10649SPeter.Memishian@Sun.COM # read all the files associated with the interface. 4718485SPeter.Memishian@Sun.COM # 4720Sstevel@tonic-gate # In the first pass through the hostname files, all 473*10649SPeter.Memishian@Sun.COM # additional logical interface commands are removed. The 474*10649SPeter.Memishian@Sun.COM # remaining commands are concatenated together and passed 475*10649SPeter.Memishian@Sun.COM # to ifparse to determine whether the non-additional 476*10649SPeter.Memishian@Sun.COM # logical interface address is a failover address. If it 477*10649SPeter.Memishian@Sun.COM # as a failover address, the address may not be the first 478*10649SPeter.Memishian@Sun.COM # item on the line, so we can't just substitute "addif" 479*10649SPeter.Memishian@Sun.COM # for "set". We prepend an "addif $zaddr" command, and 480*10649SPeter.Memishian@Sun.COM # let the embedded "set" command set the address later. 4810Sstevel@tonic-gate # 4820Sstevel@tonic-gate /sbin/ifparse -f $type ` 4838485SPeter.Memishian@Sun.COM for item in $list; do 4848485SPeter.Memishian@Sun.COM if_comp $ifname $item && $process_func \ 4858485SPeter.Memishian@Sun.COM /sbin/ifparse $type < $hostpfx.$item 4868485SPeter.Memishian@Sun.COM done | while read three four; do 4878485SPeter.Memishian@Sun.COM [ "$three" != addif ] && echo "$three $four \c" 4888485SPeter.Memishian@Sun.COM done` | while read one two; do 4898485SPeter.Memishian@Sun.COM [ -z "$one" ] && continue 4908485SPeter.Memishian@Sun.COM [ "$one $two" = "$inet_oneline_epilogue" ] && \ 4918485SPeter.Memishian@Sun.COM continue 4928485SPeter.Memishian@Sun.COM line="addif $zaddr $one $two" 4938485SPeter.Memishian@Sun.COM /sbin/ifconfig $grifname $type $line >/dev/null 4948485SPeter.Memishian@Sun.COM done 4950Sstevel@tonic-gate 4960Sstevel@tonic-gate # 4970Sstevel@tonic-gate # In the second pass, look for the the "addif" commands 4980Sstevel@tonic-gate # that configure additional failover addresses. Addif 4990Sstevel@tonic-gate # commands are not valid in logical interface hostname 5000Sstevel@tonic-gate # files. 5010Sstevel@tonic-gate # 5028485SPeter.Memishian@Sun.COM if [ "$ifname" = "`get_physical $ifname`" ]; then 5038485SPeter.Memishian@Sun.COM $process_func /sbin/ifparse -f $type < $hostpfx.$ifname \ 5048485SPeter.Memishian@Sun.COM | while read one two; do 5058485SPeter.Memishian@Sun.COM [ "$one" = addif ] && \ 5068485SPeter.Memishian@Sun.COM /sbin/ifconfig $grifname $type \ 5078485SPeter.Memishian@Sun.COM addif $two >/dev/null 5080Sstevel@tonic-gate done 5090Sstevel@tonic-gate fi 5100Sstevel@tonic-gate 5118485SPeter.Memishian@Sun.COM in_list physical_comp $ifname $processed || { 5128485SPeter.Memishian@Sun.COM processed="$processed $ifname" 513*10649SPeter.Memishian@Sun.COM echo " $ifname (moved to $grifname)\c" > /dev/msglog 5140Sstevel@tonic-gate } 5158485SPeter.Memishian@Sun.COM done 5168485SPeter.Memishian@Sun.COM echo "." >/dev/msglog 5178485SPeter.Memishian@Sun.COM} 5188485SPeter.Memishian@Sun.COM 5198485SPeter.Memishian@Sun.COM# 5208485SPeter.Memishian@Sun.COM# if_configure type class interface_list 5218485SPeter.Memishian@Sun.COM# 5228485SPeter.Memishian@Sun.COM# Configure all of the interfaces of type `type' (e.g., "inet6") in 5238485SPeter.Memishian@Sun.COM# `interface_list' according to their /etc/hostname[6].* files. `class' 5248485SPeter.Memishian@Sun.COM# describes the class of interface (e.g., "IPMP"), as a diagnostic aid. 5258485SPeter.Memishian@Sun.COM# For inet6 interfaces, the interface is also brought up. 5268485SPeter.Memishian@Sun.COM# 5278485SPeter.Memishian@Sun.COMif_configure() 5288485SPeter.Memishian@Sun.COM{ 5298485SPeter.Memishian@Sun.COM fail= 5308485SPeter.Memishian@Sun.COM type=$1 5318485SPeter.Memishian@Sun.COM class=$2 5328485SPeter.Memishian@Sun.COM process_func=${type}_process_hostname 5338485SPeter.Memishian@Sun.COM shift 2 5348485SPeter.Memishian@Sun.COM 5358485SPeter.Memishian@Sun.COM if [ "$type" = inet ]; then 5368485SPeter.Memishian@Sun.COM desc="IPv4" 5378485SPeter.Memishian@Sun.COM hostpfx="/etc/hostname" 5388485SPeter.Memishian@Sun.COM else 5398485SPeter.Memishian@Sun.COM desc="IPv6" 5408485SPeter.Memishian@Sun.COM hostpfx="/etc/hostname6" 5418485SPeter.Memishian@Sun.COM fi 5428485SPeter.Memishian@Sun.COM [ -n "$class" ] && desc="$class $desc" 5438485SPeter.Memishian@Sun.COM 5448485SPeter.Memishian@Sun.COM echo "configuring $desc interfaces:\c" 5458485SPeter.Memishian@Sun.COM while [ $# -gt 0 ]; do 5468485SPeter.Memishian@Sun.COM $process_func /sbin/ifconfig $1 $type < $hostpfx.$1 >/dev/null 5478485SPeter.Memishian@Sun.COM if [ $? != 0 ]; then 5488485SPeter.Memishian@Sun.COM fail="$fail $1" 5498485SPeter.Memishian@Sun.COM elif [ "$type" = inet6 ]; then 5508485SPeter.Memishian@Sun.COM /sbin/ifconfig $1 inet6 up || fail="$fail $1" 5518485SPeter.Memishian@Sun.COM fi 5528485SPeter.Memishian@Sun.COM echo " $1\c" 5530Sstevel@tonic-gate shift 5540Sstevel@tonic-gate done 5550Sstevel@tonic-gate echo "." 5568485SPeter.Memishian@Sun.COM 5578485SPeter.Memishian@Sun.COM [ -n "$fail" ] && warn_failed_ifs "configure $desc" "$fail" 5580Sstevel@tonic-gate} 5595895Syz147064 5605895Syz147064# 5615895Syz147064# net_reconfigure is called from the network/physical service (by the 5625895Syz147064# net-physical and net-nwam method scripts) to perform tasks that only 5635895Syz147064# need to be done during a reconfigure boot. This needs to be 5645895Syz147064# isolated in a function since network/physical has two instances 5655895Syz147064# (default and nwam) that have distinct method scripts that each need 5665895Syz147064# to do these things. 5675895Syz147064# 5685895Syz147064net_reconfigure () 5695895Syz147064{ 5705895Syz147064 # 5715895Syz147064 # Is this a reconfigure boot? If not, then there's nothing 5725895Syz147064 # for us to do. 5735895Syz147064 # 5749682SCathy.Zhou@Sun.COM reconfig=`svcprop -c -p system/reconfigure \ 5759682SCathy.Zhou@Sun.COM system/svc/restarter:default 2>/dev/null` 5767645Sjames.d.carlson@sun.com if [ $? -ne 0 -o "$reconfig" = false ]; then 5775895Syz147064 return 0 5785895Syz147064 fi 5795895Syz147064 5805895Syz147064 # 5815895Syz147064 # Ensure that the datalink-management service is running since 5825895Syz147064 # manifest-import has not yet run for a first boot after 5835895Syz147064 # upgrade. We wouldn't need to do that if manifest-import ran 5845895Syz147064 # earlier in boot, since there is an explicit dependency 5855895Syz147064 # between datalink-management and network/physical. 5865895Syz147064 # 5875895Syz147064 svcadm enable -ts network/datalink-management:default 5885895Syz147064 5895895Syz147064 # 5905895Syz147064 # There is a bug in SMF which causes the svcadm command above 5915895Syz147064 # to exit prematurely (with an error code of 3) before having 5925895Syz147064 # waited for the service to come online after having enabled 5935895Syz147064 # it. Until that bug is fixed, we need to have the following 5945895Syz147064 # loop to explicitly wait for the service to come online. 5955895Syz147064 # 5965895Syz147064 i=0 5975895Syz147064 while [ $i -lt 30 ]; do 5985895Syz147064 i=`expr $i + 1` 5995895Syz147064 sleep 1 6005895Syz147064 state=`svcprop -p restarter/state \ 6015895Syz147064 network/datalink-management:default 2>/dev/null` 6025895Syz147064 if [ $? -ne 0 ]; then 6035895Syz147064 continue 6045895Syz147064 elif [ "$state" = "online" ]; then 6055895Syz147064 break 6065895Syz147064 fi 6075895Syz147064 done 6085895Syz147064 if [ "$state" != "online" ]; then 6095895Syz147064 echo "The network/datalink-management service \c" 6105895Syz147064 echo "did not come online." 6115895Syz147064 return 1 6125895Syz147064 fi 6135895Syz147064 6145895Syz147064 # 6155895Syz147064 # Initialize the set of physical links, and validate and 6165895Syz147064 # remove all the physical links which were removed during the 6175895Syz147064 # system shutdown. 6185895Syz147064 # 6195895Syz147064 /sbin/dladm init-phys 6205895Syz147064 return 0 6215895Syz147064} 62210491SRishi.Srivatsavai@Sun.COM 62310491SRishi.Srivatsavai@Sun.COM# 62410491SRishi.Srivatsavai@Sun.COM# Check for use of the default "Port VLAN Identifier" (PVID) -- VLAN 1. 62510491SRishi.Srivatsavai@Sun.COM# If there is one for a given interface, then warn the user and force the 62610491SRishi.Srivatsavai@Sun.COM# PVID to zero (if it's not already set). We do this by generating a list 62710491SRishi.Srivatsavai@Sun.COM# of interfaces with VLAN 1 in use first, and then parsing out the 62810491SRishi.Srivatsavai@Sun.COM# corresponding base datalink entries to check for ones without a 62910491SRishi.Srivatsavai@Sun.COM# "default_tag" property. 63010491SRishi.Srivatsavai@Sun.COM# 63110491SRishi.Srivatsavai@Sun.COMupdate_pvid() 63210491SRishi.Srivatsavai@Sun.COM{ 63310491SRishi.Srivatsavai@Sun.COM datalink=/etc/dladm/datalink.conf 63410491SRishi.Srivatsavai@Sun.COM 63510491SRishi.Srivatsavai@Sun.COM ( 63610491SRishi.Srivatsavai@Sun.COM # Find datalinks using VLAN 1 explicitly 63710491SRishi.Srivatsavai@Sun.COM # configured by dladm 63810491SRishi.Srivatsavai@Sun.COM /usr/bin/nawk ' 63910491SRishi.Srivatsavai@Sun.COM /^#/ || NF < 2 { next } 64010491SRishi.Srivatsavai@Sun.COM { linkdata[$1]=$2; } 64110491SRishi.Srivatsavai@Sun.COM /;vid=int,1;/ { 64210491SRishi.Srivatsavai@Sun.COM sub(/.*;linkover=int,/, "", $2); 64310491SRishi.Srivatsavai@Sun.COM sub(/;.*/, "", $2); 64410491SRishi.Srivatsavai@Sun.COM link=linkdata[$2]; 64510491SRishi.Srivatsavai@Sun.COM sub(/name=string,/, "", link); 64610491SRishi.Srivatsavai@Sun.COM sub(/;.*/, "", link); 64710491SRishi.Srivatsavai@Sun.COM print link; 64810491SRishi.Srivatsavai@Sun.COM }' $datalink 64910491SRishi.Srivatsavai@Sun.COM ) | ( /usr/bin/sort -u; echo END; cat $datalink ) | /usr/bin/nawk ' 65010491SRishi.Srivatsavai@Sun.COM /^END$/ { state=1; } 65110491SRishi.Srivatsavai@Sun.COM state == 0 { usingpvid[++nusingpvid]=$1; next; } 65210491SRishi.Srivatsavai@Sun.COM /^#/ || NF < 2 { next; } 65310491SRishi.Srivatsavai@Sun.COM { 65410491SRishi.Srivatsavai@Sun.COM # If it is already present and has a tag set, 65510491SRishi.Srivatsavai@Sun.COM # then believe it. 65610491SRishi.Srivatsavai@Sun.COM if (!match($2, /;default_tag=/)) 65710491SRishi.Srivatsavai@Sun.COM next; 65810491SRishi.Srivatsavai@Sun.COM sub(/name=string,/, "", $2); 65910491SRishi.Srivatsavai@Sun.COM sub(/;.*/, "", $2); 66010491SRishi.Srivatsavai@Sun.COM for (i = 1; i <= nusingpvid; i++) { 66110491SRishi.Srivatsavai@Sun.COM if (usingpvid[i] == $2) 66210491SRishi.Srivatsavai@Sun.COM usingpvid[i]=""; 66310491SRishi.Srivatsavai@Sun.COM } 66410491SRishi.Srivatsavai@Sun.COM } 66510491SRishi.Srivatsavai@Sun.COM END { 66610491SRishi.Srivatsavai@Sun.COM for (i = 1; i <= nusingpvid; i++) { 66710491SRishi.Srivatsavai@Sun.COM if (usingpvid[i] != "") { 66810491SRishi.Srivatsavai@Sun.COM printf("Warning: default VLAN tag set to 0" \ 66910491SRishi.Srivatsavai@Sun.COM " on %s\n", usingpvid[i]); 67010491SRishi.Srivatsavai@Sun.COM cmd=sprintf("dladm set-linkprop -p " \ 67110491SRishi.Srivatsavai@Sun.COM "default_tag=0 %s\n", usingpvid[i]); 67210491SRishi.Srivatsavai@Sun.COM system(cmd); 67310491SRishi.Srivatsavai@Sun.COM } 67410491SRishi.Srivatsavai@Sun.COM } 67510491SRishi.Srivatsavai@Sun.COM }' 67610491SRishi.Srivatsavai@Sun.COM} 677