net_include.sh revision 7c478bd95313f5f23a4c958a745db2134aa03244
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License"). You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#ident "%Z%%M% %I% %E% SMI"
#
# Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T.
# All rights reserved.
#
#
# shcat file
# Simulates cat in sh so it doesn't need to be on the root filesystem.
#
while [ $# -ge 1 ]; do
while read i; do
echo "$i"
done < $1
shift
done
}
#
# Inet_list, list of IPv4 interfaces.
# Inet_plumbed, list of plumbed IPv4 interfaces.
# Inet_failed, list of IPv4 interfaces that failed to plumb.
# Inet6_list, list of IPv6 interfaces.
# Inet6_plumbed, list of plumbed IPv6 interfaces.
# Inet6_failed, list of IPv6 interfaces that failed to plumb.
#
#
# get_physical interface
#
# Return physical interface corresponding to the given logical
# interface.
#
{
IFS="${IFS}:"
set -- $1
echo $1
}
#
# get_logical interface
#
# Return logical interface number. Zero will be returned
# if there is no explicit logical device number.
#
{
IFS="${IFS}:"
set -- $1
if [ -z "$2" ]; then
echo 0
else
echo $2
fi
}
#
# if_comp if1 if2
#
# Compare Interfaces. Do the physical interface names and logical interface
# numbers match?
#
if_comp()
{
}
#
# physical_comp if1 if2
#
# Do the two devices share a physical interface?
#
{
}
#
# in_list op item list
#
# Is "item" in the given list? Use "op" to do the test, applying it to
# "item" and each member of the list in turn until it returns success.
#
in_list()
{
op=$1
item=$2
shift 2
while [ $# -gt 0 ]; do
shift
done
return 1
}
#
# get_group_from_hostname interface type
#
# Return all group settings from hostname file for a given interface.
#
# Example:
# get_group_from_hostname hme0 inet
#
{
;;
;;
*)
return
;;
esac
#
# Read through the hostname file looking for group settings
# There may be several group settings in the file. It is up
# to the caller to pick the right one (i.e. the last one).
#
while read line; do
done
}
#
# get_group_for_type interface type list
#
# Look through the set of hostname files associated with the same physical
# interface as "interface", and determine which group they would configure.
# Only hostname files associated with the physical interface or logical
# interface zero are allowed to set the group.
#
{
physical=`get_physical $1`
type=$2
group=""
#
# The last setting of the group is the one that counts, which is
# the reason for the second while loop.
#
shift 2
while [ $# -gt 0 ]; do
fi
shift
done | while :; do
read next || {
echo "$group"
break
}
done
}
#
# get_group interface [ configured | failed ]
#
# If there is both an inet and inet6 version of an interface, the group
# could be set in either set of hostname files.
#
# Inet6 is configured after inet, so if the group is set in both
# sets of hostname files, the inet6 file wins.
#
# The "configured" argument should be used to get the group for
# an interface that has been plumbed into the stack and configured. Use
# the "failed" argument to get the group for an interface that failed to
# plumb.
#
{
group=""
;;
;;
*)
return
;;
esac
else
fi
fi
echo $group
}
#
# get_standby_from_hostname interface type
#
# Return any "standby" or "-standby" flags in the hostname file.
#
# Example:
# get_standby_from_hostname hme0 inet6
#
#
{
;;
;;
*)
return
;;
esac
#
# There may be several instances of the "standby" and
# "-standby" flags in the hostname file. It is up to
# the caller to pick the correct one.
#
while read line; do
&& echo "$one"
done
}
#
# get_standby_for_type interface type plumbed_list
#
# Look through the set of hostname files associated with the same physical
# interface as "interface", and determine whether they would configure
# the interface as a standby interface.
#
{
physical=`get_physical $1`
type=$2
final=""
#
# The last "standby" or "-standby" flag is the one that counts,
# which is the reason for the second while loop.
#
shift 2
while [ $# -gt 0 ]; do
fi
shift
done | while :; do
read next || {
echo "$final"
break
}
done
}
#
# is_standby interface
#
# Determine whether a configured interface is a standby interface.
#
# Both the inet and inet6 hostname file sets must be checked.
# If "standby" or "-standby" is set in the inet6 hostname file set,
# don't bother looking at the inet set.
#
{
fi
# The return value is the value of the following test.
}
#
# get_alternate interface plumbed_list
#
# Look for a plumbed interface in the same group as "interface".
# A standby interface is preferred over a non-standby interface.
#
# Example:
# get_alternate hme0 $inet_plumbed
#
{
maybe=""
shift
while [ $# -gt 0 ]; do
group=`get_group $1 configured`
if is_standby $1; then
get_physical $1
return
else
fi
fi
shift
done
}
#
# doDHCPhostname interface
# Pass to this function the name of an interface. It will return
# true if one should enable the use of DHCP client-side host name
# requests on the interface, and false otherwise.
#
{
return $?
fi
return 1
}
#
# inet_process_hostname processor [ args ]
#
# Process an inet hostname file. The contents of the file
# are taken from standard input. Each line is passed
# on the command line to the "processor" command.
# Command line arguments can be passed to the processor.
#
# Examples:
# inet_process_hostname /sbin/ifconfig hme0 < /etc/hostname.hme0
#
# inet_process_hostname /sbin/ifparse -f < /etc/hostname.hme0
#
# If there is only line in an hostname file we assume it contains
# the old style address which results in the interface being brought up
# and the netmask and broadcast address being set.
#
# If there are multiple lines we assume the file contains a list of
# commands to the processor with neither the implied bringing up of the
# interface nor the setting of the default netmask and broadcast address.
#
# Return non-zero if any command fails so that the caller may alert
# users to errors in the configuration.
#
{
if doDHCPhostname $2; then
:
else
#
# Redirecting input from a file results in a sub-shell being
# used, hence this outer loop surrounding the "multiple_lines"
# and "ifcmds" variables.
#
while :; do
multiple_lines=false
ifcmds=""
retval=0
while read line; do
#
# This handles the first N-1
# lines of a N-line hostname file.
#
multiple_lines=true
fi
done
#
# If the hostname file is empty or consists of only
# blank lines, break out of the outer loop without
# configuring the newly plumbed interface.
#
if [ $multiple_lines = false ]; then
# The traditional single-line hostname file.
fi
#
# This handles either the single-line case or
# the last line of the N-line case.
#
$* $ifcmds || return $?
return $retval
done
fi
}
#
# inet6_process_hostname processor [ args ]
#
# Process an inet6 hostname file. The contents of the file
# are taken from standard input. Each line is passed
# on the command line to the "processor" command.
# Command line arguments can be passed to the processor.
#
# Examples:
# inet6_process_hostname /sbin/ifconfig hme0 inet6 < /etc/hostname6.hme0
#
# inet6_process_hostname /sbin/ifparse -f inet6 < /etc/hostname6.hme0
#
# Return non-zero if any of the commands fail so that the caller may alert
# users to errors in the configuration.
#
{
retval=0
while read ifcmds; do
fi
done
return $retval
}
#
# Process interfaces that failed to plumb. Find an alternative
# interface to host the addresses. For IPv6, only static addresses
# defined in hostname6 files are moved, autoconfigured addresses are
# not moved.
#
# Example:
# move_addresses inet6
#
{
type="$1"
eval "failed=\"\$${type}_failed\""
eval "plumbed=\"\$${type}_plumbed\""
eval "list=\"\$${type}_list\""
process_hostname="${type}_process_hostname"
processed=""
echo "moving addresses from failed IPv4 interfaces:\c"
zaddr="0.0.0.0"
else
echo "moving addresses from failed IPv6 interfaces:\c"
zaddr="::"
fi
set -- $failed
while [ $# -gt 0 ]; do
in_list if_comp $1 $processed && { shift; continue; }
in_list physical_comp $1 $processed || {
echo " $1 (couldn't move, no" \
"alternative interface)\c"
processed="$processed $1"
}
shift
continue
fi
#
# The hostname files are processed twice. In the first
# pass, we are looking for all commands that apply
# to the non-additional interface address. These may be
# scattered over several files. We won't know
# whether the address represents a failover address
# or not until we've read all the files associated with the
# interface.
# In the first pass through the hostname files, all
# additional logical interface commands are removed.
# The remaining commands are concatenated together and
# passed to ifparse to determine whether the
# non-additional logical interface address is a failover
# address. If it as a failover address, the
# address may not be the first item on the line,
# so we can't just substitute "addif" for "set".
# We prepend an "addif $zaddr" command, and let
# the embedded "set" command set the address later.
#
done
#
# In the second pass, look for the the "addif" commands
# that configure additional failover addresses. Addif
# commands are not valid in logical interface hostname
# files.
#
$process_hostname /sbin/ifparse -f $type \
done
fi
in_list physical_comp $1 $processed || {
echo " $1 (moved to $alternate)\c"
processed="$processed $1"
}
shift
done
echo "."
}