2002-07-18 05:00:17 +00:00
|
|
|
#!/bin/sh -x
|
2000-10-08 19:20:36 +00:00
|
|
|
#
|
1999-08-27 23:37:10 +00:00
|
|
|
# $FreeBSD$
|
2000-10-08 19:20:36 +00:00
|
|
|
#
|
1997-04-27 03:59:19 +00:00
|
|
|
|
2002-07-18 05:00:17 +00:00
|
|
|
# PROVIDE: network1
|
|
|
|
# REQUIRE: atm1 ipfilter mountcritlocal pccard serial sppp sysctl tty
|
|
|
|
# KEYWORD: FreeBSD
|
1997-04-27 03:59:19 +00:00
|
|
|
|
2002-07-18 05:00:17 +00:00
|
|
|
. /etc/rc.subr
|
|
|
|
|
|
|
|
name="network1"
|
|
|
|
start_cmd="network_start"
|
|
|
|
stop_cmd="network_stop"
|
|
|
|
|
|
|
|
convert_host_conf()
|
|
|
|
{
|
|
|
|
host_conf=$1; shift;
|
|
|
|
nsswitch_conf=$1; shift;
|
|
|
|
awk ' \
|
|
|
|
/^[:blank:]*#/ { next } \
|
|
|
|
/(hosts|local|file)/ { nsswitch[c] = "files"; c++; next } \
|
|
|
|
/(dns|bind)/ { nsswitch[c] = "dns"; c++; next } \
|
|
|
|
/nis/ { nsswitch[c] = "nis"; c++; next } \
|
|
|
|
{ printf "Warning: unrecognized line [%s]", $0 > "/dev/stderr" } \
|
|
|
|
END { \
|
|
|
|
printf "hosts: "; \
|
|
|
|
for (i in nsswitch) printf "%s ", nsswitch[i]; \
|
|
|
|
printf "\n"; \
|
|
|
|
}' < $host_conf > $nsswitch_conf
|
|
|
|
}
|
|
|
|
|
|
|
|
generate_host_conf()
|
|
|
|
{
|
|
|
|
nsswitch_conf=$1; shift;
|
|
|
|
host_conf=$1; shift;
|
|
|
|
|
|
|
|
awk '
|
|
|
|
BEGIN {
|
|
|
|
xlat["files"] = "hosts";
|
|
|
|
xlat["dns"] = "bind";
|
|
|
|
xlat["nis"] = "nis";
|
|
|
|
cont = 0;
|
|
|
|
}
|
|
|
|
sub(/^[\t ]*hosts:/, "") || cont {
|
|
|
|
if (!cont)
|
|
|
|
srcs = ""
|
|
|
|
sub(/#.*/, "")
|
|
|
|
gsub(/[][]/, " & ")
|
|
|
|
cont = sub(/\\$/, "")
|
|
|
|
srcs = srcs " " $0
|
|
|
|
}
|
|
|
|
END {
|
|
|
|
print "# Auto-generated from nsswitch.conf, do not edit"
|
|
|
|
ns = split(srcs, s)
|
|
|
|
for (n = 1; n <= ns; ++n) {
|
|
|
|
if (s[n] in xlat)
|
|
|
|
print xlat[s[n]]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
' <$nsswitch_conf >$host_conf
|
|
|
|
}
|
|
|
|
|
|
|
|
network_start()
|
|
|
|
{
|
|
|
|
# set hostname, turn on network
|
|
|
|
#
|
|
|
|
echo -n "Doing initial network setup:"
|
1997-09-11 10:59:02 +00:00
|
|
|
|
2001-11-01 12:39:01 +00:00
|
|
|
# Generate host.conf for compatibility
|
|
|
|
#
|
|
|
|
if [ -f "/etc/nsswitch.conf" ]; then
|
2001-11-07 00:33:56 +00:00
|
|
|
echo -n ' host.conf'
|
2001-11-01 12:39:01 +00:00
|
|
|
generate_host_conf /etc/nsswitch.conf /etc/host.conf
|
|
|
|
fi
|
|
|
|
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
# Convert host.conf to nsswitch.conf if necessary
|
2001-11-01 12:39:01 +00:00
|
|
|
#
|
|
|
|
if [ -f "/etc/host.conf" -a ! -f "/etc/nsswitch.conf" ]; then
|
2000-12-17 08:16:06 +00:00
|
|
|
echo ''
|
|
|
|
echo 'Warning: /etc/host.conf is no longer used'
|
2001-11-01 12:39:01 +00:00
|
|
|
echo ' /etc/nsswitch.conf will be created for you'
|
|
|
|
convert_host_conf /etc/host.conf /etc/nsswitch.conf
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
fi
|
|
|
|
|
1999-09-13 15:44:20 +00:00
|
|
|
# Set the host name if it is not already set
|
|
|
|
#
|
|
|
|
if [ -z "`hostname -s`" ]; then
|
|
|
|
hostname ${hostname}
|
|
|
|
echo -n ' hostname'
|
1999-04-10 10:56:58 +00:00
|
|
|
fi
|
1999-09-13 15:44:20 +00:00
|
|
|
|
|
|
|
# Set the domainname if we're using NIS
|
|
|
|
#
|
2002-07-18 05:00:17 +00:00
|
|
|
if checkyesno nisdomainname ; then
|
1999-09-13 15:44:20 +00:00
|
|
|
domainname ${nisdomainname}
|
|
|
|
echo -n ' domain'
|
2002-07-18 05:00:17 +00:00
|
|
|
fi
|
1999-09-13 15:44:20 +00:00
|
|
|
|
2001-09-19 21:27:27 +00:00
|
|
|
# Attempt to create cloned interfaces.
|
|
|
|
for ifn in ${cloned_interfaces}; do
|
|
|
|
ifconfig ${ifn} create
|
|
|
|
done
|
|
|
|
|
1999-09-13 15:44:20 +00:00
|
|
|
# Set up all the network interfaces, calling startup scripts if needed
|
|
|
|
#
|
|
|
|
case ${network_interfaces} in
|
|
|
|
[Aa][Uu][Tt][Oo])
|
|
|
|
network_interfaces="`ifconfig -l`"
|
|
|
|
;;
|
2001-09-19 21:27:27 +00:00
|
|
|
*)
|
|
|
|
network_interfaces="${network_interfaces} ${cloned_interfaces}"
|
|
|
|
;;
|
1999-09-13 15:44:20 +00:00
|
|
|
esac
|
|
|
|
|
1999-12-12 01:58:30 +00:00
|
|
|
dhcp_interfaces=""
|
1999-09-13 15:44:20 +00:00
|
|
|
for ifn in ${network_interfaces}; do
|
|
|
|
if [ -r /etc/start_if.${ifn} ]; then
|
|
|
|
. /etc/start_if.${ifn}
|
1999-12-12 01:58:30 +00:00
|
|
|
eval showstat_$ifn=1
|
1999-03-24 10:28:49 +00:00
|
|
|
fi
|
1999-09-13 15:44:20 +00:00
|
|
|
|
|
|
|
# Do the primary ifconfig if specified
|
|
|
|
#
|
|
|
|
eval ifconfig_args=\$ifconfig_${ifn}
|
|
|
|
|
|
|
|
case ${ifconfig_args} in
|
|
|
|
'')
|
|
|
|
;;
|
|
|
|
[Dd][Hh][Cc][Pp])
|
1999-12-12 01:58:30 +00:00
|
|
|
# DHCP inits are done all in one go below
|
|
|
|
dhcp_interfaces="$dhcp_interfaces $ifn"
|
|
|
|
eval showstat_$ifn=1
|
1999-09-13 15:44:20 +00:00
|
|
|
;;
|
|
|
|
*)
|
|
|
|
ifconfig ${ifn} ${ifconfig_args}
|
1999-12-12 01:58:30 +00:00
|
|
|
eval showstat_$ifn=1
|
1999-09-13 15:44:20 +00:00
|
|
|
;;
|
|
|
|
esac
|
1999-12-12 01:58:30 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
if [ ! -z "${dhcp_interfaces}" ]; then
|
2002-07-18 05:00:17 +00:00
|
|
|
${dhcp_program:-/sbin/dhclient} ${dhcp_flags} ${dhcp_interfaces} fi
|
1999-09-13 15:44:20 +00:00
|
|
|
|
1999-12-12 01:58:30 +00:00
|
|
|
for ifn in ${network_interfaces}; do
|
1999-09-13 15:44:20 +00:00
|
|
|
# Check to see if aliases need to be added
|
|
|
|
#
|
|
|
|
alias=0
|
|
|
|
while : ; do
|
|
|
|
eval ifconfig_args=\$ifconfig_${ifn}_alias${alias}
|
|
|
|
if [ -n "${ifconfig_args}" ]; then
|
|
|
|
ifconfig ${ifn} ${ifconfig_args} alias
|
1999-12-12 01:58:30 +00:00
|
|
|
eval showstat_$ifn=1
|
2001-11-14 06:35:43 +00:00
|
|
|
alias=$((${alias} + 1))
|
1999-09-13 15:44:20 +00:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# Do ipx address if specified
|
|
|
|
#
|
|
|
|
eval ifconfig_args=\$ifconfig_${ifn}_ipx
|
|
|
|
if [ -n "${ifconfig_args}" ]; then
|
|
|
|
ifconfig ${ifn} ${ifconfig_args}
|
1999-12-12 01:58:30 +00:00
|
|
|
eval showstat_$ifn=1
|
1999-09-13 15:44:20 +00:00
|
|
|
fi
|
1999-12-12 01:58:30 +00:00
|
|
|
done
|
1999-09-13 15:44:20 +00:00
|
|
|
|
2002-07-18 05:00:17 +00:00
|
|
|
# catch-all for interfaces that haven't been 'ifconfig'ed so far
|
1999-12-12 01:58:30 +00:00
|
|
|
for ifn in ${network_interfaces}; do
|
|
|
|
eval showstat=\$showstat_${ifn}
|
|
|
|
if [ ! -z ${showstat} ]; then
|
1999-09-13 15:44:20 +00:00
|
|
|
ifconfig ${ifn}
|
1999-12-12 01:58:30 +00:00
|
|
|
fi
|
1999-09-13 15:44:20 +00:00
|
|
|
done
|
|
|
|
|
2002-07-18 05:00:17 +00:00
|
|
|
|
2000-02-06 16:33:54 +00:00
|
|
|
|
2002-07-18 05:00:17 +00:00
|
|
|
# Check $defaultroute, then /etc/mygate, for the name of my gateway
|
|
|
|
# host. That name must be in /etc/hosts.
|
1999-09-13 15:44:20 +00:00
|
|
|
#
|
2002-07-18 05:00:17 +00:00
|
|
|
if [ -z "$defaultroute" ] && [ -f /etc/mygate ]; then
|
|
|
|
defaultroute=`cat /etc/mygate`
|
|
|
|
fi
|
|
|
|
if [ -n "$defaultroute" ]; then
|
|
|
|
route add default $defaultroute
|
|
|
|
fi
|
1999-09-13 15:44:20 +00:00
|
|
|
|
2002-07-18 05:00:17 +00:00
|
|
|
# Check if each configured interface xxN has an $ifaliases_xxN variable
|
|
|
|
# associated, then configure additional IP addresses for that interface.
|
|
|
|
# The variable contains a list of "address netmask" pairs, with
|
|
|
|
# "netmask" set to "-" if the interface default netmask is to be used.
|
2001-10-20 04:46:32 +00:00
|
|
|
#
|
2002-07-18 05:00:17 +00:00
|
|
|
# Note that $ifaliases_xxN works only with certain configurations and
|
|
|
|
# considered not recommended. Use /etc/ifconfig.xxN if possible.
|
|
|
|
#
|
1999-09-13 15:44:20 +00:00
|
|
|
#
|
2002-07-18 05:00:17 +00:00
|
|
|
if [ -n "$configured_interfaces" ]; then
|
|
|
|
echo "Adding interface aliases:"
|
|
|
|
done_aliases_message=yes
|
1997-09-11 10:59:02 +00:00
|
|
|
fi
|
2002-07-18 05:00:17 +00:00
|
|
|
for int in $configured_interfaces; do
|
|
|
|
eval args=\$ifaliases_$int
|
|
|
|
if [ -n "$args" ]; then
|
|
|
|
set -- $args
|
|
|
|
while [ $# -ge 2 ]; do
|
|
|
|
addr=$1 ; net=$2 ; shift 2
|
|
|
|
if [ "$net" = "-" ]; then
|
|
|
|
# for compatibility only, obsolete
|
|
|
|
ifconfig $int inet alias $addr
|
|
|
|
else
|
|
|
|
ifconfig $int inet alias $addr \
|
|
|
|
netmask $net
|
|
|
|
fi
|
|
|
|
# Use loopback, not the wire
|
|
|
|
route add $addr 127.0.0.1
|
|
|
|
done
|
1999-09-13 15:44:20 +00:00
|
|
|
fi
|
2002-07-18 05:00:17 +00:00
|
|
|
done
|
1999-09-13 15:44:20 +00:00
|
|
|
|
2002-07-18 05:00:17 +00:00
|
|
|
# /etc/ifaliases, if it exists, contains the names of additional IP
|
|
|
|
# addresses for each interface. It is formatted as a series of lines
|
|
|
|
# that contain
|
|
|
|
# address interface netmask
|
1999-09-13 15:44:20 +00:00
|
|
|
#
|
2002-07-18 05:00:17 +00:00
|
|
|
# Note that /etc/ifaliases works only with certain cases only and its
|
|
|
|
# use is not recommended. Use /etc/ifconfig.xxN instead.
|
|
|
|
#
|
|
|
|
#
|
|
|
|
if [ -f /etc/ifaliases ]; then
|
|
|
|
if [ "$done_aliases_message" != yes ]; then
|
|
|
|
echo "Adding interface aliases:"
|
1999-09-13 15:44:20 +00:00
|
|
|
fi
|
2002-07-18 05:00:17 +00:00
|
|
|
while read addr int net; do
|
|
|
|
if [ -z "$net" ]; then
|
|
|
|
# for compatibility only, obsolete
|
|
|
|
ifconfig $int inet alias $addr
|
|
|
|
else
|
|
|
|
ifconfig $int inet alias $addr netmask $net
|
1999-09-13 15:44:20 +00:00
|
|
|
fi
|
2002-07-18 05:00:17 +00:00
|
|
|
# use loopback, not the wire
|
|
|
|
route add $addr 127.0.0.1
|
|
|
|
done < /etc/ifaliases
|
1999-09-13 15:44:20 +00:00
|
|
|
fi
|
|
|
|
|
2002-07-18 05:00:17 +00:00
|
|
|
# IPv6 interface autoconfiguration.
|
1999-09-13 15:44:20 +00:00
|
|
|
#
|
2002-07-18 05:00:17 +00:00
|
|
|
if ifconfig lo0 inet6 >/dev/null 2>&1; then
|
|
|
|
# wait till DAD is completed. always invoke it in case
|
|
|
|
# if are configured manually by ifconfig
|
|
|
|
#
|
|
|
|
dadcount=`sysctl -n net.inet6.ip6.dad_count 2>/dev/null`
|
|
|
|
sleep $dadcount
|
|
|
|
sleep 1
|
|
|
|
|
|
|
|
if checkyesno rtsol; then
|
|
|
|
if [ "$ip6mode" = "autohost" ]; then
|
|
|
|
echo 'Sending router solicitation...'
|
|
|
|
rtsol $rtsol_flags
|
|
|
|
else
|
|
|
|
echo
|
|
|
|
warn \
|
|
|
|
"ip6mode must be set to 'autohost' to use rtsol."
|
|
|
|
fi
|
1999-09-13 15:44:20 +00:00
|
|
|
|
2002-07-18 05:00:17 +00:00
|
|
|
# wait till DAD is completed, for global addresses
|
|
|
|
# configured by router advert message.
|
|
|
|
#
|
|
|
|
sleep $dadcount
|
|
|
|
sleep 1
|
2000-05-16 06:52:11 +00:00
|
|
|
fi
|
2002-07-18 05:00:17 +00:00
|
|
|
fi
|
1999-09-13 15:44:20 +00:00
|
|
|
|
2002-07-18 05:00:17 +00:00
|
|
|
# XXX this must die
|
|
|
|
if [ -s /etc/netstart.local ]; then
|
|
|
|
sh /etc/netstart.local start
|
|
|
|
fi
|
|
|
|
fi
|
1999-09-13 15:44:20 +00:00
|
|
|
echo '.'
|
|
|
|
|
2002-07-18 05:00:17 +00:00
|
|
|
# Resync ipfilter
|
|
|
|
/etc/rc.d/ipfilter resync
|
1997-04-27 03:59:19 +00:00
|
|
|
}
|
|
|
|
|
2002-07-18 05:00:17 +00:00
|
|
|
network_stop()
|
|
|
|
{
|
|
|
|
echo "Stopping network."
|
1999-09-13 15:44:20 +00:00
|
|
|
|
2002-07-18 05:00:17 +00:00
|
|
|
# XXX this must die
|
|
|
|
if [ -s /etc/netstart.local ]; then
|
|
|
|
sh /etc/netstart.local stop
|
1999-09-13 15:44:20 +00:00
|
|
|
fi
|
|
|
|
|
2002-07-18 05:00:17 +00:00
|
|
|
echo "Deleting aliases."
|
|
|
|
if [ -f /etc/ifaliases ]; then
|
|
|
|
while read addr int net; do
|
|
|
|
ifconfig $int inet delete $addr
|
|
|
|
done < /etc/ifaliases
|
|
|
|
fi
|
1999-09-13 15:44:20 +00:00
|
|
|
|
2002-07-18 05:00:17 +00:00
|
|
|
for int in `ifconfig -lu`; do
|
|
|
|
eval args=\$ifaliases_$int
|
|
|
|
if [ -n "$args" ]; then
|
|
|
|
set -- $args
|
|
|
|
while [ $# -ge 2 ]; do
|
|
|
|
addr=$1 ; net=$2 ; shift 2
|
|
|
|
ifconfig $int inet delete $addr
|
|
|
|
done
|
1999-09-13 15:44:20 +00:00
|
|
|
fi
|
2002-07-18 05:00:17 +00:00
|
|
|
done
|
1999-09-13 15:44:20 +00:00
|
|
|
|
2002-07-18 05:00:17 +00:00
|
|
|
# down interfaces
|
|
|
|
#
|
|
|
|
echo -n 'Downing network interfaces:'
|
|
|
|
if [ "$net_interfaces" != NO ]; then
|
|
|
|
if checkyesno auto_ifconfig; then
|
|
|
|
tmp=`ifconfig -l`
|
|
|
|
else
|
|
|
|
tmp="$net_interfaces"
|
1999-11-23 00:22:25 +00:00
|
|
|
fi
|
2002-07-18 05:00:17 +00:00
|
|
|
for int in $tmp; do
|
|
|
|
eval args=\$ifconfig_$int
|
|
|
|
if [ -n "$args" ] || [ -f /etc/ifconfig.$int ]; then
|
|
|
|
echo -n " $int"
|
|
|
|
ifconfig $int down
|
2002-03-19 03:45:02 +00:00
|
|
|
fi
|
2001-06-03 12:26:56 +00:00
|
|
|
done
|
2002-07-18 05:00:17 +00:00
|
|
|
echo "."
|
|
|
|
fi
|
2001-06-03 12:26:56 +00:00
|
|
|
|
2002-07-18 05:00:17 +00:00
|
|
|
# flush routes
|
|
|
|
#
|
|
|
|
route -n flush
|
Add nsswitch support. By creating an /etc/nsswitch.conf file, you can
configure FreeBSD so that various databases such as passwd and group can be
looked up using flat files, NIS, or Hesiod.
= Hesiod has been added to libc (see hesiod(3)).
= A library routine for parsing nsswitch.conf and invoking callback
functions as specified has been added to libc (see nsdispatch(3)).
= The following C library functions have been modified to use nsdispatch:
. getgrent, getgrnam, getgrgid
. getpwent, getpwnam, getpwuid
. getusershell
. getaddrinfo
. gethostbyname, gethostbyname2, gethostbyaddr
. getnetbyname, getnetbyaddr
. getipnodebyname, getipnodebyaddr, getnodebyname, getnodebyaddr
= host.conf has been removed from src/etc. rc.network has been modified
to warn that host.conf is no longer used at boot time. In addition, if
there is a host.conf but no nsswitch.conf, the latter is created at boot
time from the former.
Obtained from: NetBSD
2000-09-06 18:16:48 +00:00
|
|
|
|
2001-11-01 12:39:01 +00:00
|
|
|
}
|
2002-07-18 05:00:17 +00:00
|
|
|
|
|
|
|
load_rc_config $name
|
|
|
|
run_rc_command "$1"
|