#!/usr/sbin/sh # # Copyright (c) 1999, 2014, Oracle and/or its affiliates. All rights reserved. # This script configures IP routing. . /lib/svc/share/smf_include.sh . /lib/svc/share/net_include.sh # # In a shared-IP zone we need this service to be up, but all of the work # it tries to do is irrelevant (and will actually lead to the service # failing if we try to do it), so just bail out. # In the global zone and exclusive-IP zones we proceed. # smf_configure_ip || exit $SMF_EXIT_OK case "$1" in 'start') # fall through -- rest of script is startup code ;; 'stop') # # Removal of static routes destroys iSCSI connectivity. ZFS file # systems built on iSCSI need to be accessible during shutdown, so # we skip removal of static routes when iSCSI targets are present. # if iscsi_is_active ; then exit $SMF_EXIT_OK fi static_file=`$SVCPROP -p $SRTS_FILE_PROP $SMF_FMRI 2>/dev/null` walk_static_routes delete "$static_file" exit $SMF_EXIT_OK ;; 'refresh') # # For refresh, simply add the static routes. If a route has already # been added, it won't be added again. # static_file=`$SVCPROP -p $SRTS_FILE_PROP $SMF_FMRI 2>/dev/null` walk_static_routes add "$static_file" exit $SMF_EXIT_OK ;; *) echo "Usage: $0 start | stop | refresh" exit 1 ;; esac # # If routing.conf file is in place, and has not already been read in # by previous invokation of routeadm, legacy configuration is upgraded # by this call to "routeadm -u". This call is also needed when # a /var/svc/profile/upgrade file is found, as it may contain routeadm commands # which need to be applied. Finally, routeadm starts in.ndpd by # enabling the ndp service (in.ndpd), which is required for IPv6 address # autoconfiguration. It would be nice if we could do this in # network/loopback, but since the SMF backend is read-only at that # point in boot, we cannot. Further, here we have to apply the routing # configuration alone as the forwarding configuration would have already been # applied by the `ipmgmtd' daemon early in the boot. The boot time execution # of routeadm is indicated by the project-private -b option and this informs # routeadm to apply only routing configuration. # /usr/sbin/routeadm -b -u # # Are we routing dynamically? routeadm(1M) reports this in the # "current" values of ipv4/6-routing - if either are true, we are running # routing daemons (or at least they are enabled to run). # dynamic_routing_test=`/usr/sbin/routeadm -p | \ $NAWK '/^ipv[46]-routing [.]*/ { print $2 }' | $GREP "current=enabled"` if [ -n "$dynamic_routing_test" ]; then dynamic_routing="true" fi # # Configure default IPv4 routers using the local "/etc/defaultrouter" # configuration file. The file can contain the hostnames or IP # addresses of one or more default routers. If hostnames are used, # each hostname must also be listed in the local "/etc/hosts" file # because NIS is not running at the time that this script is # run. Each router name or address is listed on a single line by # itself in the file. Anything else on that line after the router's # name or address is ignored. Lines that begin with "#" are # considered comments and ignored. # # Note that the default router file is ignored if we received routes # from a DHCP server. Our policy is to always trust DHCP over local # administration. # smf_netstrategy if [ "$_INIT_NET_STRATEGY" = "dhcp" ] && \ [ -n "`/usr/sbin/dhcpinfo Router`" ]; then defrouters=`/usr/sbin/dhcpinfo Router` elif [ -f /etc/defaultrouter ]; then defrouters=`$GREP -v \^\# /etc/defaultrouter | /usr/bin/awk '{print $1}'` if [ -n "$defrouters" ]; then for router in $defrouters; do /usr/sbin/route -n add default -gateway \ $router >/dev/null done fi else defrouters= fi # # Identify the appropriate static_routes file, based on the currently # active NCP. # ncp=`get_active_ncp` STATIC_ROUTES="/etc/inet/static_routes-$ncp" # # Read the ncp-specific /etc/inet/static_routes and add each route. # walk_static_routes add $STATIC_ROUTES # # Use routeadm(1M) to configure forwarding and launch routing daemons # for IPv4 and IPv6 based on preset values. These settings only apply # to the global zone. For IPv4 dynamic routing, the system will default # to disabled if a default route was previously added via BOOTP, DHCP, # or the /etc/defaultrouter file. routeadm also starts in.ndpd. # if [ "$dynamic_routing" != "true" ] && [ -z "$defrouters" ]; then # # No default routes were setup by "route" command above # from DHCP or the /etc/defaultrouter file. Check the # kernel routing table for any other default routes (some # might have been set via the static_routes file). # $NETSTAT -rn -f inet | $GREP default >/dev/null 2>&1 && defrouters=yes fi # # The routeadm/ipv4-routing-set property is true if the administrator # has run "routeadm -e/-d ipv4-routing". If not, we revert to the # appropriate defaults. We no longer run "routeadm -u" on every boot # however, as persistent daemon state is now controlled by SMF. # ipv4_routing_set=`$SVCPROP -p routeadm/ipv4-routing-set $SMF_FMRI` if [ -z "$defrouters" ]; then # # Set default value for ipv4-routing to enabled. If routeadm -e/-d # has not yet been run by the administrator, we apply this default. # The -b option is project-private and informs routeadm not # to treat the enable as administrator-driven. # $SVCCFG -s $SMF_FMRI setprop routeadm/default-ipv4-routing = true if [ "$ipv4_routing_set" = "false" ]; then /usr/sbin/routeadm -b -e ipv4-routing -u fi else # # Default router(s) have been found, so ipv4-routing default value # should be disabled. If routaedm -e/d has not yet been run by # the administrator, we apply this default. The -b option is # project-private and informs routeadm not to treat the disable as # administrator-driven. # $SVCCFG -s $SMF_FMRI setprop routeadm/default-ipv4-routing = false if [ "$ipv4_routing_set" = "false" ]; then /usr/sbin/routeadm -b -d ipv4-routing -u fi fi # Clear exit status. exit $SMF_EXIT_OK