c9e1bbfb91
o use ifn rather than interface in rc.network o merge into rc.d/network1 Approved by: (re blanket)
232 lines
4.6 KiB
Bash
232 lines
4.6 KiB
Bash
#!/bin/sh -x
|
|
#
|
|
# $FreeBSD$
|
|
#
|
|
|
|
# PROVIDE: network1
|
|
# REQUIRE: atm1 ipfilter mountcritlocal pccard serial sppp sysctl tty
|
|
# KEYWORD: FreeBSD
|
|
|
|
. /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_gif_setup() {
|
|
case ${gif_interfaces} in
|
|
[Nn][Oo] | '')
|
|
;;
|
|
*)
|
|
for i in ${gif_interfaces}; do
|
|
eval peers=\$gifconfig_$i
|
|
case ${peers} in
|
|
'')
|
|
continue
|
|
;;
|
|
*)
|
|
ifconfig $i create >/dev/null 2>&1
|
|
ifconfig $i tunnel ${peers}
|
|
ifconfig $i up
|
|
;;
|
|
esac
|
|
done
|
|
;;
|
|
esac
|
|
}
|
|
|
|
network_start()
|
|
{
|
|
# set hostname, turn on network
|
|
#
|
|
echo -n "Doing initial network setup:"
|
|
|
|
# Generate host.conf for compatibility
|
|
#
|
|
if [ -f "/etc/nsswitch.conf" ]; then
|
|
echo -n ' host.conf'
|
|
generate_host_conf /etc/nsswitch.conf /etc/host.conf
|
|
fi
|
|
|
|
# Convert host.conf to nsswitch.conf if necessary
|
|
#
|
|
if [ -f "/etc/host.conf" -a ! -f "/etc/nsswitch.conf" ]; then
|
|
echo ''
|
|
echo 'Warning: /etc/host.conf is no longer used'
|
|
echo ' /etc/nsswitch.conf will be created for you'
|
|
convert_host_conf /etc/host.conf /etc/nsswitch.conf
|
|
fi
|
|
|
|
# Set the host name if it is not already set
|
|
#
|
|
if [ -z "`hostname -s`" ]; then
|
|
hostname ${hostname}
|
|
echo -n ' hostname'
|
|
fi
|
|
|
|
# Set the domainname if we're using NIS
|
|
#
|
|
case ${nisdomainname} in
|
|
[Nn][Oo]|'')
|
|
;;
|
|
*)
|
|
domainname ${nisdomainname}
|
|
echo -n ' domain'
|
|
;;
|
|
esac
|
|
|
|
echo '.'
|
|
|
|
# Attempt to create cloned interfaces.
|
|
for ifn in ${cloned_interfaces}; do
|
|
ifconfig ${ifn} create
|
|
done
|
|
|
|
# gifconfig
|
|
network_gif_setup
|
|
|
|
# Set up all the network interfaces, calling startup scripts if needed
|
|
#
|
|
case ${network_interfaces} in
|
|
[Aa][Uu][Tt][Oo])
|
|
network_interfaces="`ifconfig -l`"
|
|
;;
|
|
*)
|
|
network_interfaces="${network_interfaces} ${cloned_interfaces}"
|
|
;;
|
|
esac
|
|
|
|
dhcp_interfaces=""
|
|
for ifn in ${network_interfaces}; do
|
|
if ifconfig ${ifn} | grep -s UP, > /dev/null 2>&1; then
|
|
# Interface is already up, so ignore it.
|
|
continue;
|
|
fi
|
|
|
|
if [ -r /etc/start_if.${ifn} ]; then
|
|
. /etc/start_if.${ifn}
|
|
eval showstat_$ifn=1
|
|
fi
|
|
|
|
# Do the primary ifconfig if specified
|
|
#
|
|
eval ifconfig_args=\$ifconfig_${ifn}
|
|
|
|
case ${ifconfig_args} in
|
|
'')
|
|
;;
|
|
[Dd][Hh][Cc][Pp])
|
|
# DHCP inits are done all in one go below
|
|
dhcp_interfaces="$dhcp_interfaces $ifn"
|
|
eval showstat_$ifn=1
|
|
;;
|
|
*)
|
|
ifconfig ${ifn} ${ifconfig_args}
|
|
eval showstat_$ifn=1
|
|
;;
|
|
esac
|
|
done
|
|
|
|
if [ ! -z "${dhcp_interfaces}" ]; then
|
|
${dhcp_program:-/sbin/dhclient} ${dhcp_flags} ${dhcp_interfaces}
|
|
fi
|
|
|
|
for ifn in ${network_interfaces}; do
|
|
# 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
|
|
eval showstat_$ifn=1
|
|
alias=$((${alias} + 1))
|
|
else
|
|
break;
|
|
fi
|
|
done
|
|
|
|
# Do ipx address if specified
|
|
#
|
|
eval ifconfig_args=\$ifconfig_${ifn}_ipx
|
|
if [ -n "${ifconfig_args}" ]; then
|
|
ifconfig ${ifn} ${ifconfig_args}
|
|
eval showstat_$ifn=1
|
|
fi
|
|
done
|
|
|
|
# Display ifconfiged interfaces
|
|
for ifn in ${network_interfaces}; do
|
|
eval showstat=\$showstat_${ifn}
|
|
if [ ! -z ${showstat} ]; then
|
|
ifconfig ${ifn}
|
|
fi
|
|
done
|
|
|
|
# Resync ipfilter
|
|
/etc/rc.d/ipfilter resync
|
|
}
|
|
|
|
network_stop()
|
|
{
|
|
echo -n "Stopping network:"
|
|
|
|
# flush routes
|
|
#
|
|
echo -n " flush routes"
|
|
route -n flush
|
|
|
|
echo '.'
|
|
}
|
|
|
|
load_rc_config $name
|
|
run_rc_command "$1"
|