Hallo, dies ist ein Test.
PWD: /www/data-lst1/unixsoft/unixsoft/kaempfer/.public_html
Running in File Mode
Relative path: ./../../../../../././../lib/svc/method/net-physical
Real path: /lib/svc/method/net-physical
Zurück
#!/usr/sbin/sh # # Copyright (c) 1999, 2020, Oracle and/or its affiliates. All rights reserved. # # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T. # All rights reserved. # . /lib/svc/share/smf_include.sh . /lib/svc/share/net_include.sh # # Version history: # # There are two version properties in svc:/network/physical:default. # upgrade/version is defined as 1 in the manifest and when /etc/hostname.* is # obsoleted, it is changed to 2. upgrade/nwamd_version is migrated from # nwamd/version of the nwam instance and is the one currently used to track # version. # # NB: upgrade/nwamd_version property is used to track the current version. # # Also, note that NET_PHYSICAL_VERSION in # usr/src/cmd/cmd-inet/lib/nwamd/util.h must be updated to use this same value. # # v0: NWAM Phase 0/0.5 # - no version property # v1: NWAM Phase 1 # - nwamd/version = 1 in nwam instance # v2: Hostname obsoleted # - upgrade/version = 2 in default instance # v3: defaultrouter(5) EOF # - upgrade/version = 3 in default instance # v2: Instances merge (nwam instance obsoleted) # - upgrade/nwamd_version = 2 in default instance # - nwaminst/upgraded = true in nwam instance # v3: Highlander (merged repo, nwam instance removed) # - upgrade/nwamd_version = 3 # v4: No NWAM (NCP and locations removed, one config file) # - upgrade/nwamd_version = 4 # NET_PHYSICAL_HIGHLANDER_VERSION=3 NET_PHYSICAL_NO_NWAM_VERSION=4 NET_PHYSICAL_VERSION=$NET_PHYSICAL_NO_NWAM_VERSION DEFRTR_EOF_VERSION=3 DEFRTR=/etc/defaultrouter # Make sure that the libraries essential to this stage of booting can be found. LD_LIBRARY_PATH=/lib; export LD_LIBRARY_PATH VOL_NETCFG_PATH=$SMF_SYSVOL_FS/netcfg NET_INSTALL_FMRI="svc:/network/install:default" NP_DEFAULT_FMRI="svc:/network/physical:default" STATIC_ROUTES_FILE="/etc/inet/static_routes" # # Convert a device-based nic name to a physical link name. # nic2phys () { /usr/sbin/dladm show-phys -p -odevice,link | while IFS=':' read device phys; do if [[ $device == $1 ]]; then print $phys return fi done print $1 } # # Network configuration for network installs is obtained manually (via the # PROM or CLI during boot) or via DHCP. In the case of DHCP, enable # svc:/network/dhcp/client:default so that dhcpagent can adopt the already # configured interface. In the case of a manual configuration, the # configuration should be retrieved using netbootinfo and the interface and, # optionally, a default route should be configured using the proper CLIs. # # Note that iSCSI is a special case since it needs to configure its interface # itself in the kernel. # config_netinstall () { # # netbootinfo returns an error in the non-network boot case. So, # just return. # strategy=`$NETBOOTINFO net-config-strategy 2>/dev/null` if [ $? -ne 0 -o -z "$strategy" -o "$strategy" = "none" ]; then return fi echo "Configuring network using boot properties." nic=`$NETBOOTINFO interface-name 2>/dev/null` phys=`nic2phys $nic` if [ $? -ne 0 -o -z "$phys" -o "$phys" = "none" ]; then echo "Failed to obtain network interface used to" \ "boot from the network.\nConfiguration bypassed." return fi # # It is possible that the kernel has already plumbed and # configured the interface (e.g., iSCSI boot). If so, # just return. # state=`$IPADM show-if -p -o state $phys 2>/dev/null` if [ $? -eq 0 -a "$state" = "ok" ] ; then # # If netbooting with iSCSI boot, then continue to enable # svc:/network/dhcp/client:default # if [ "$strategy" = "dhcp" ] ; then echo "$phys has been configured, but needs to" \ "be adopted." else echo "$phys has already been configured. No" \ "need to reconfigure.\nConfiguration bypassed." return fi fi # # If a vlan was specified, configure it here and reassign phys to it # vlan=`$NETBOOTINFO vlan 2>/dev/null` if [ "$vlan" -ne "none" ]; then vphys=${phys}vlan${vlan} dladm create-vlan -l $phys -v $vlan $vphys if [ $? -ne 0 ]; then echo "Failed to configure vlan $vlan" return else echo "Configured vlan $vlan" fi phys=$vphys fi case "$strategy" in "dhcp") # # If vlan was set, just configure a new DHCP interface on it # if [ "$vlan" -ne "none" ]; then ipadm create-ip -t $phys ipadm create-addr -t -T dhcp $phys/netboot if [ $? -ne 0 ]; then echo "Failed to configure network over vlan" return else echo "Configured DHCP over VLAN $vlan" fi else # # Enable svc:/network/dhcp/client:default to adopt # $SVCADM enable -st svc:/network/dhcp/client:default echo "Adopted DHCP configured interface, $phys." fi ;; "manual") ip=`$NETBOOTINFO host-ip 2>/dev/null` if [ $? -ne 0 -o -z "$ip" -o "$ip" = "none" ]; then echo "Failed to obtain IP address for manual" \ "configuration.\nConfiguration bypassed." return fi mask=`$NETBOOTINFO subnet-mask 2>/dev/null` if [ $? -ne 0 -o -z "$mask" -o "$mask" = "none" ]; then echo "Failed to obtain netmask for manual" \ "configuration.\nConfiguration bypassed." return fi # # ipadm requires CIDR prefixlen so convert # mask to plen. # plen=`netmask2plen $mask` if [ $? -ne 0 -o -z "$plen" ]; then echo "Failed to configure network using" \ "boot parameters." echo "Could not convert $mask to CIDR prefixlen." return fi # # Configure the interface. No need for it to be # persistent. # $IPADM show-if $phys >/dev/null 2>&1 if [ $? -ne 0 ]; then $IPADM create-ip -t $phys if [ $? -ne 0 ]; then warn_failed_ifs "create IPv4" "$phys" return fi fi $IPADM create-addr -t -T static -a \ local=$ip/$plen $phys/netboot >/dev/null 2>&1 if [ $? -ne 0 ]; then echo "Failed to configure address $ip/$plen on $phys" warn_failed_ifs "plumb IPv4" "$phys" return fi echo "Configured $phys using boot parameters." router=`$NETBOOTINFO router-ip 2>/dev/null` if [ $? -ne 0 -o -z "$router" -o "$router" = "none" ]; then return fi $ROUTE add default $router -ifp $phys >/dev/null 2>&1 $ROUTE get default $router -ifp $phys >/dev/null 2>&1 if [ $? -ne 0 ]; then echo "Failed to configure default route using" \ "boot parameter:\nrouter-ip=$router" return fi echo "Added default route using boot parameters." ;; esac } # # configure_dhcp # # Configure DHCP addresses on all interfaces in the system. Use a wait of 0 # so that libipadm does not wait. We will wait here for at least one address # to be configured or 120 seconds have elapsed. # configure_dhcp() { media=$(/usr/bin/svcs -Ho STATE svc:/system/filesystem/root-assembly:media \ 2>/dev/null) dhcpstarted= for if in $($DLADM show-link -po LINK 2>/dev/null); do # If booted with media and the link has "allowed-ips", skip if [[ $media != disabled ]]; then ips=$($DLADM show-linkprop -co VALUE -p allowed-ips $if \ 2>/dev/null) [[ -n $ips ]] && continue fi $IPADM delete-ip $if 2>/dev/null $IPADM create-ip -t $if 2>/dev/null $IPADM create-addr -t -T dhcp -w 0 $if/v4 2>/dev/null dhcpstarted=yes done # If we did not configure DHCP, no need to wait [[ -z $dhcpstarted ]] && return maxwait=120 # seconds (default dhcp timeout) cnt=0 while (( cnt < maxwait )); do $IPADM show-addr -po addrobj,addr,state 2>/dev/null | \ while IFS=':' read aobj addr state; do # skip loopback addresses [[ $aobj == lo0* ]] && continue # skip disabled addresses [[ $state == disabled ]] && continue # if any addr has : or ., then it has address if [[ $addr == *[.:]* ]]; then echo "$aobj is configured with $addr" break 2 # break out of both while-loops fi done # loop (( cnt++ )) sleep 1 done } # # upgrade_static_routes_file # # Add any default routes specified in the /etc/defaultrouter file to the # /etc/inet/static_routes. # # Note that if there is an error upgrading the file, we print a warning # message and march on. # upgrade_static_routes_file() { typeset TMPSTATICRTS=/system/volatile/static_routes.$$ typeset RT if [ -f $STATIC_ROUTES_FILE ]; then $CP -p $STATIC_ROUTES_FILE $TMPSTATICRTS else echo "#" > $TMPSTATICRTS echo "# File generated by Solaris upgrade - do not edit." \ >> $TMPSTATICRTS echo "#" >> $TMPSTATICRTS fi if [ $? != 0 ]; then echo "Failed to upgrade default route(s)" return fi $GREP -v "^#" $DEFRTR | while read RT; do echo default $RT >> $TMPSTATICRTS done $MV -f $TMPSTATICRTS $STATIC_ROUTES_FILE 2>/dev/null if [ $? != 0 ]; then $RM $TMPSTATICRTS echo "Failed to rename $TMPSTATICRTS file" return fi } # # upgrade_defaultrouter # # defaultrouter(5) is no longer supported. As we transition to not supporting # it any longer, apply any existing default routes to /etc/inet/static_route # file. If the defaultrouter file was being used, then add a comment to file # to make sure the administrator knows that the file is no longer supported. # # Additionally, once we have transitioned to no longer supporting the file, # give the administrator a message if they configure it. # upgrade_defaultrouter() { typeset NROUTES=0 typeset SVCVER=`$SVCCFG -s $SMF_FMRI listprop -o value upgrade/version 2>/dev/null` [ $? -eq 1 ] && SVCVER=0 [ -f $DEFRTR ] && NROUTES=`$GREP -cv "^#" $DEFRTR` if [ "$SVCVER" -ge "$DEFRTR_EOF_VERSION" ]; then # # If someone has configured defaultrouter give them a slap # up side the head. # if [ $NROUTES -ne 0 ]; then msg="defaultrouter(5) is not supported on this " msg=$msg"version of Solaris.\n" msg=$msg"Use route(8) to configure persistent routes." echo "$msg" | smf_console echo $msg fi # # Move the defaultrouter file aside if it exists to avoid # problems with future sysconfig configure/reconfigure # operations. # [ -f $DEFRTR ] && $MV -f $DEFRTR ${DEFRTR}.obsolete return fi # # Before ending the feature, process the file. This means applying the # default route(s) to the /etc/inet/static_routes file. # if [ $NROUTES -ne 0 ]; then upgrade_static_routes_file fi # # If the defrouter file exists, then update it to mention the end of # the feature and move the file aside to avoid future problems. # if [ -f $DEFRTR ]; then echo "#" >$DEFRTR echo "# This file is no longer supported in this version of" \ "Oracle Solaris." >>$DEFRTR echo "#" >>$DEFRTR echo "# To configure persistent default routes, use the" \ "route(8) command" >>$DEFRTR echo "# with the '-p' option." >>$DEFRTR echo "#" >>$DEFRTR $MV -f $DEFRTR ${DEFRTR}.obsolete fi # # This upgrade is a one shot deal. # $SVCCFG -s $SMF_FMRI setprop \ upgrade/version = integer: $DEFRTR_EOF_VERSION } # # move_static_routes <profile> # # Removal of NWAM profiles. The data from the active profile is moved to # /etc/inet/static_routes. Move profile-specific static_routes files to # *.obsolete. # move_static_routes() { typeset profile=$1 tmpfile=$STATIC_ROUTES_FILE.tmp if [ -f $STATIC_ROUTES_FILE-${profile} ]; then $CP -p $STATIC_ROUTES_FILE-${profile} $tmpfile $MV -f $tmpfile $STATIC_ROUTES_FILE fi for file in ${STATIC_ROUTES_FILE}-*; do ext="${file##*.}" if [ $ext != "obsolete" -a -f $file ]; then $MV -f ${file} ${file}.obsolete 2>/dev/null fi done } # # move_ncp_default_routes <profile> # # Some NCPs may have {ipv4,ipv6}-default-route specified. Move such routes to # /etc/inet/static_routes file. # move_ncp_default_routes() { typeset profile=$1 file=/etc/ipadm/ipadm-${profile}.conf # cannot use netcfg(8) command to get the properties, script it. # Also, cannot use route(8) command because the interfaces aren't # created yet. Append to the static_routes file directly. # ipv4-default-route # _ifname=net0; [...]ipv4-default-route=string,x.x.x.x;[...] $GREP ipv4-default-route $file 2>/dev/null | \ /usr/bin/sed -e 's/^_ifname=\([a-zA-Z0-9]*\);.*ipv4-default-route=string,\([0-9\.]*\);.*$/\1 \2/' | \ while read if dest; do \ echo "default $dest -ifp $if" >> $STATIC_ROUTES_FILE; \ done # ipv6-default-route # _ifname=net0; [...]ipv6-default-route=string,x:x:x::x;[...] $GREP ipv6-default-route $file 2>/dev/null | \ /usr/bin/sed -e 's/^_ifname=\([a-zA-Z0-9]*\);.*ipv6-default-route=string,\([a-zA-Z0-9:]*\);.*$/\1 \2/' | \ while read if dest; do \ echo "-inet6 default $dest -ifp $if" >> $STATIC_ROUTES_FILE; \ done } # # Remove the IP configuration. Also, disconnect wireless connections and # remove secure objects. # net_unconfigure () { # flush the forwarding table, including persistent entries $ROUTE -p flush # # It is not possible to release the DHCP leases with "ipadm # delete-addr -r" because when this function is called, the interfaces # are disabled. This means that because active addresses are not # found, the '-r' is ignored. Thus, explicitly remove the lease files # and the DUID and IAID files from /var/dhcp (and also the old # /etc/dhcp) directory. # $RM -f /var/dhcp/*.dhc /var/dhcp/*.dh6 /var/dhcp/duid /var/dhcp/iaid $RM -f /etc/dhcp/*.dhc /etc/dhcp/*.dh6 /etc/dhcp/duid /etc/dhcp/iaid # delete all non-loopback IP interfaces. for intf in $($IPADM show-if -p -o ifname,class); do echo $intf | IFS=':' read ifname ifclass case $ifclass in 'ip' ) $IPADM delete-ip $ifname ;; 'ipmp' ) $IPADM delete-ipmp --force $ifname ;; 'vni' ) $IPADM delete-vni $ifname ;; esac if [ $? -ne 0 ]; then return 1 fi done if smf_is_globalzone; then # disconnect from any connected WiFi links for wifi in $($DLADM show-wifi -p -o link,status); do echo $wifi | IFS=':' read linkname wifistatus if [ "$wifistatus" == "connected" ]; then $DLADM disconnect-wifi $linkname if [ $? -ne 0 ]; then return 1 fi fi done # delete security objects for secobj in $($DLADM show-secobj -p -o object); do $DLADM delete-secobj $secobj || return 1 done fi return 0 } # # Script entry point # # Arguments to net-physical are # method ( start | refresh | stop | upgrade | unconfigure ) # # # Ensure directory for libnetcfg doors etc exists and is owned by netadm/netadm # if [ ! -d $VOL_NETCFG_PATH ]; then /usr/bin/mkdir -m 0755 $VOL_NETCFG_PATH /usr/bin/chown netadm:netadm $VOL_NETCFG_PATH fi case "$1" in 'start') # # This service doesn't do anything in a shared-stack zone; but it # needs to be online to meet dependencies. We use this return # value to notify the smf infrastructure that there are no running # processes associated with this online, non-transient service. # smf_configure_ip if [ $? -eq 1 ]; then smf_method_exit $SMF_EXIT_TEMP_TRANSIENT shared_stack \ "$SMF_FMRI does nothing in a shared-stack zone" fi # remainder of script is start action ;; 'unconfigure') # Unconfigure interfaces first net_unconfigure || exit $SMF_EXIT_ERR_CONFIG # # Revert property customizations. We revert back to the profile that # was set by the install manifest. # $SVCCFG -s $SMF_FMRI delcust general/enabled || \ exit $SMF_EXIT_ERR_CONFIG $SVCCFG -s $SMF_FMRI delcust nwamd || exit $SMF_EXIT_ERR_CONFIG $SVCADM refresh $SMF_FMRI $SVCCFG -s $NET_INSTALL_FMRI delcust || exit $SMF_EXIT_ERR_CONFIG $SVCADM refresh $NET_INSTALL_FMRI exit $SMF_EXIT_OK ;; 'refresh') /usr/bin/pkill -HUP -z `smf_zonename` nwamd exit $SMF_EXIT_OK ;; 'stop') # Nothing to do in a shared stack zone. smf_configure_ip [ $? -eq 1 ] && exit $SMF_EXIT_OK /usr/bin/pkill -z `smf_zonename` nwamd # Kill any processes left in service contract. For example, # the dhcpagent in the DHCP netinstall case. smf_kill_contract $2 TERM 1 [ $? -ne 0 ] && exit $SMF_EXIT_ERR_CONFIG exit $SMF_EXIT_OK ;; 'upgrade') version=`$SVCPROP -cp upgrade/nwamd_version $NP_DEFAULT_FMRI` profile=`$SVCPROP -cp netcfg/active_ncp $NP_DEFAULT_FMRI 2>/dev/null` /lib/inet/nwamd -u case $? in '-1') exit $SMF_EXIT_ERR_FATAL ;; '1') # # Return value of 1 indicates upgrade was required and # completed successfully # if [ "$version" -lt "$NET_PHYSICAL_NO_NWAM_VERSION" ]; then # No NWAM - only one static routes file move_static_routes "$profile" # If there are any default routes in the NCP, make it # a persistent static route move_ncp_default_routes "$profile" fi ;; esac exit $SMF_EXIT_OK ;; *) echo "Usage: $0 { start | stop | refresh | unconfigure | upgrade }" exit 1 ;; esac # # Remainder of 'start' script # if smf_is_globalzone; then # # Only applicable for Kernel Zones. # Returns after all the Implicit DLMPs have been created # if smf_is_kernelzone; then $DLADM init-idlmp fi # Initialize device properties $DLADM init-devprop $DLADM init-secobj # # Upgrade handling. The upgrade file consists of a series of dladm(8) # commands. # upgrade_script=/var/svc/profile/upgrade_datalink if [ -f "${upgrade_script}" ]; then . "${upgrade_script}" # # Rename the upgrade script file so that on subsequent reboots # we do not end up applying the same configuration. # $MV -f "${upgrade_script}" \ "${upgrade_script}".app.`/usr/bin/date +\%Y\%m\%d\%H\%M\%S` fi # # If the global zone is running as a kernel zone guest, then # IP interface configuration can come from the host through # zonecfg's allowed-address and defrouter properties. # if smf_is_kernelzone; then # # See below. # $IPADM create-ip -z fi else # # In non-global zones, IP interface configuration for normal anets # and EVS anets can come from the global zone via zonecfg's # allowed-address and configure-allowed-address properties. Before we # enable addresses configured in this manner, we need to create # persistent IP interface configuration if it doesn't already # exist. # $IPADM create-ip -z # # Create flows via flowadm # /usr/sbin/flowadm init-flow fi # # Check for netboot info to direct us. # if smf_is_globalzone; then config_netinstall fi # # If the private nwamd/dhcp SMF property is set, configure all interfaces with # non-persistent DHCP addresses. Wait until at least one DHCP address is # configured or 120 seconds has elapsed. # dhcp=`$SVCPROP -cp nwamd/dhcp $NP_DEFAULT_FMRI 2>/dev/null` if [ "$dhcp" = "true" ]; then configure_dhcp fi # # Start nwamd in foreground; it will daemonize itself # /lib/inet/nwamd || exit $SMF_EXIT_ERR_FATAL # # See if static routes were created by install. If so, they were created # under $SMF_SYSVOL_FS. Copy them into their proper place. # SYSVOL_STATIC_ROUTES="${SMF_SYSVOL_FS}/${STATIC_ROUTES_FILE}" if [ -f $SYSVOL_STATIC_ROUTES ]; then echo "Installing persistent routes" if [ -f $STATIC_ROUTES_FILE ]; then $CAT $SYSVOL_STATIC_ROUTES | $GREP -v '^#' \ >> $STATIC_ROUTES_FILE $RM -f $SYSVOL_STATIC_ROUTES else $MV -f $SYSVOL_STATIC_ROUTES $STATIC_ROUTES_FILE fi fi # # defaultrouter(5) is no longer supported. # upgrade_defaultrouter # # Upgrade persistent static routes in /etc/inet/static_routes to SMF # if [ -f $STATIC_ROUTES_FILE ]; then /usr/bin/egrep -v "^(#|$)" $STATIC_ROUTES_FILE \ | while read line; do $ROUTE upgrade-smf $line done $MV -f $STATIC_ROUTES_FILE ${STATIC_ROUTES_FILE}.obsolete fi # # Add the persistent static routes, so that the next stage of booting will # have access to NFS. This is done here as well as in network/routing-setup # for that reason. # $ROUTE add -a exit $SMF_EXIT_OK