110616SSebastien.Roy@Sun.COM#!/sbin/sh 210616SSebastien.Roy@Sun.COM# 310616SSebastien.Roy@Sun.COM# CDDL HEADER START 410616SSebastien.Roy@Sun.COM# 510616SSebastien.Roy@Sun.COM# The contents of this file are subject to the terms of the 610616SSebastien.Roy@Sun.COM# Common Development and Distribution License (the "License"). 710616SSebastien.Roy@Sun.COM# You may not use this file except in compliance with the License. 810616SSebastien.Roy@Sun.COM# 910616SSebastien.Roy@Sun.COM# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 1010616SSebastien.Roy@Sun.COM# or http://www.opensolaris.org/os/licensing. 1110616SSebastien.Roy@Sun.COM# See the License for the specific language governing permissions 1210616SSebastien.Roy@Sun.COM# and limitations under the License. 1310616SSebastien.Roy@Sun.COM# 1410616SSebastien.Roy@Sun.COM# When distributing Covered Code, include this CDDL HEADER in each 1510616SSebastien.Roy@Sun.COM# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1610616SSebastien.Roy@Sun.COM# If applicable, add the following below this CDDL HEADER, with the 1710616SSebastien.Roy@Sun.COM# fields enclosed by brackets "[]" replaced with your own identifying 1810616SSebastien.Roy@Sun.COM# information: Portions Copyright [yyyy] [name of copyright owner] 1910616SSebastien.Roy@Sun.COM# 2010616SSebastien.Roy@Sun.COM# CDDL HEADER END 2110616SSebastien.Roy@Sun.COM# 2210616SSebastien.Roy@Sun.COM# 23*12016SGirish.Moodalbail@Sun.COM# Copyright 2010 Sun Microsystems, Inc. All rights reserved. 2410616SSebastien.Roy@Sun.COM# Use is subject to license terms. 2510616SSebastien.Roy@Sun.COM# 2610616SSebastien.Roy@Sun.COM# This service configures IP tunnel links and IP interfaces over IP 2710616SSebastien.Roy@Sun.COM# tunnels. 2810616SSebastien.Roy@Sun.COM# 2910616SSebastien.Roy@Sun.COM 3010616SSebastien.Roy@Sun.COM. /lib/svc/share/smf_include.sh 3110616SSebastien.Roy@Sun.COM 3210616SSebastien.Roy@Sun.COM# 3310616SSebastien.Roy@Sun.COM# Configure tunnels which were deferred by /lib/svc/method/net-physical (the 3410616SSebastien.Roy@Sun.COM# svc:/network/physical service) since it depends on the tunnel source 3510616SSebastien.Roy@Sun.COM# addresses being available. 3610616SSebastien.Roy@Sun.COM# 3710616SSebastien.Roy@Sun.COM# WARNING: you may wish to turn OFF forwarding if you haven't already, because 3810616SSebastien.Roy@Sun.COM# of various possible security vulnerabilities when configuring tunnels for 3910616SSebastien.Roy@Sun.COM# Virtual Private Network (VPN) construction. 4010616SSebastien.Roy@Sun.COM# 4110616SSebastien.Roy@Sun.COM# Also, if names are used in the /etc/hostname*.* files, those names have to 4210616SSebastien.Roy@Sun.COM# be in either DNS (and DNS is used) or in /etc/hosts, because this file is 4311262SRajagopal.Andra@Sun.COM# executed before NIS is started. 4410616SSebastien.Roy@Sun.COM# 4510616SSebastien.Roy@Sun.COM 4610616SSebastien.Roy@Sun.COM# 4710616SSebastien.Roy@Sun.COM# get_tunnel_links: print the names of the tunnel links currently configured 4810616SSebastien.Roy@Sun.COM# on the running system. 4910616SSebastien.Roy@Sun.COM# 5010616SSebastien.Roy@Sun.COMget_tunnel_links () 5110616SSebastien.Roy@Sun.COM{ 5210616SSebastien.Roy@Sun.COM /sbin/dladm show-iptun -p -o link 5310616SSebastien.Roy@Sun.COM} 5410616SSebastien.Roy@Sun.COM 5510616SSebastien.Roy@Sun.COM# plumb_tunnel <intf_name> <net_type> <intf_file> 5610616SSebastien.Roy@Sun.COMplumb_tunnel () 5710616SSebastien.Roy@Sun.COM{ 5810616SSebastien.Roy@Sun.COM /sbin/ifconfig $1 $2 plumb 5910616SSebastien.Roy@Sun.COM while read ifcmds; do 6010616SSebastien.Roy@Sun.COM if [ -n "$ifcmds" ]; then 6110616SSebastien.Roy@Sun.COM /sbin/ifconfig $1 $2 $ifcmds 6210616SSebastien.Roy@Sun.COM fi 6310616SSebastien.Roy@Sun.COM done < $3 > /dev/null 6410616SSebastien.Roy@Sun.COM /sbin/ifconfig $1 $2 up 6510616SSebastien.Roy@Sun.COM} 6610616SSebastien.Roy@Sun.COM 6710616SSebastien.Roy@Sun.COMcase "$1" in 6810616SSebastien.Roy@Sun.COMstart) 6910616SSebastien.Roy@Sun.COM # First, bring up tunnel links 7010616SSebastien.Roy@Sun.COM /sbin/dladm up-iptun 7110616SSebastien.Roy@Sun.COM 7210616SSebastien.Roy@Sun.COM # 7310616SSebastien.Roy@Sun.COM # Get the list of IP tunnel interfaces we'll need to configure. These 7410616SSebastien.Roy@Sun.COM # are comprised of IP interfaces over the tunnels we've just brought 7510616SSebastien.Roy@Sun.COM # up in the above dladm command, and the implicit tunnels named "ip.*" 7610616SSebastien.Roy@Sun.COM # that we'll also create for backward compatibility. When we build 7710616SSebastien.Roy@Sun.COM # the list of implicit tunnels, we have to make sure that they're not 7810616SSebastien.Roy@Sun.COM # different kinds of links that are simply named "ip.*". 7910616SSebastien.Roy@Sun.COM # 8010616SSebastien.Roy@Sun.COM tunnel_links=`get_tunnel_links` 8110616SSebastien.Roy@Sun.COM implicit_tunnel_names=`/usr/bin/ls -1 /etc/hostname.ip*.*[0-9] \ 8210616SSebastien.Roy@Sun.COM /etc/hostname6.ip*.*[0-9] 2> /dev/null | /usr/bin/cut -f2- -d. | \ 8310616SSebastien.Roy@Sun.COM /usr/bin/sort -u` 8410616SSebastien.Roy@Sun.COM for intf_name in $implicit_tunnel_names; do 8510616SSebastien.Roy@Sun.COM /sbin/dladm show-link -pP $intf_name > /dev/null 2>&1 8610616SSebastien.Roy@Sun.COM if [ $? -ne 0 ]; then 8710616SSebastien.Roy@Sun.COM implicit_tunnels="$implicit_tunnels $intf_name" 8810616SSebastien.Roy@Sun.COM fi 8910616SSebastien.Roy@Sun.COM done 9010616SSebastien.Roy@Sun.COM tunnel_interfaces=`for intf in $tunnel_links $implicit_tunnels; do \ 9110616SSebastien.Roy@Sun.COM echo $intf; done | /usr/bin/sort -u` 9210616SSebastien.Roy@Sun.COM 9310616SSebastien.Roy@Sun.COM for intf_name in $tunnel_interfaces; do 9410616SSebastien.Roy@Sun.COM if [ -f /etc/hostname.$intf_name ]; then 9510616SSebastien.Roy@Sun.COM plumb_tunnel $intf_name inet /etc/hostname.$intf_name 9610616SSebastien.Roy@Sun.COM fi 9710616SSebastien.Roy@Sun.COM if [ -f /etc/hostname6.$intf_name ]; then 9810616SSebastien.Roy@Sun.COM plumb_tunnel $intf_name inet6 /etc/hostname6.$intf_name 9910616SSebastien.Roy@Sun.COM fi 100*12016SGirish.Moodalbail@Sun.COM # 101*12016SGirish.Moodalbail@Sun.COM # Configure IP tunnel interfaces set up using ipadm 102*12016SGirish.Moodalbail@Sun.COM # 103*12016SGirish.Moodalbail@Sun.COM state=`/sbin/ipadm show-if -p -o state $intf_name` 104*12016SGirish.Moodalbail@Sun.COM if [ $? -ne 0 ] || [ "$state" != "disabled" ]; then 105*12016SGirish.Moodalbail@Sun.COM # 106*12016SGirish.Moodalbail@Sun.COM # skip if not managed my ipadm or if not a persistent 107*12016SGirish.Moodalbail@Sun.COM # interface 108*12016SGirish.Moodalbail@Sun.COM # 109*12016SGirish.Moodalbail@Sun.COM continue; 110*12016SGirish.Moodalbail@Sun.COM elif [ -f /etc/hostname.$intf_name ] ||\ 111*12016SGirish.Moodalbail@Sun.COM [ -f /etc/hostname6.$intf_name ]; then 112*12016SGirish.Moodalbail@Sun.COM echo "found /etc/hostname.$intf_name or "\ 113*12016SGirish.Moodalbail@Sun.COM "/etc/hostname6.$intfi_name, ignoring ipadm "\ 114*12016SGirish.Moodalbail@Sun.COM "configuration" > /dev/msglog 115*12016SGirish.Moodalbail@Sun.COM continue; 116*12016SGirish.Moodalbail@Sun.COM else 117*12016SGirish.Moodalbail@Sun.COM # Enable the interface managed by ipadm 118*12016SGirish.Moodalbail@Sun.COM /sbin/ipadm enable-if -t $intf_name 119*12016SGirish.Moodalbail@Sun.COM fi 12010616SSebastien.Roy@Sun.COM done 12110616SSebastien.Roy@Sun.COM 12210616SSebastien.Roy@Sun.COM # 12310616SSebastien.Roy@Sun.COM # Set 6to4 Relay Router communication support policy and, if 12410616SSebastien.Roy@Sun.COM # applicable, the destination Relay Router IPv4 address. See 12510616SSebastien.Roy@Sun.COM # /etc/default/inetinit for setting and further info on 12610616SSebastien.Roy@Sun.COM # ACCEPT6TO4RELAY and RELAY6TO4ADDR. If ACCEPT6TO4RELAY=NO, the 12710616SSebastien.Roy@Sun.COM # default value in the kernel will be used. 12810616SSebastien.Roy@Sun.COM # 12910616SSebastien.Roy@Sun.COM [ -f /etc/default/inetinit ] && . /etc/default/inetinit 13010616SSebastien.Roy@Sun.COM ACCEPT6TO4RELAY=`echo "$ACCEPT6TO4RELAY" | /usr/bin/tr '[A-Z]' '[a-z]'` 13110616SSebastien.Roy@Sun.COM if [ "$ACCEPT6TO4RELAY" = yes ]; then 13210616SSebastien.Roy@Sun.COM if [ "$RELAY6TO4ADDR" ]; then 13310616SSebastien.Roy@Sun.COM /usr/sbin/6to4relay -e -a $RELAY6TO4ADDR 13410616SSebastien.Roy@Sun.COM else 13510616SSebastien.Roy@Sun.COM /usr/sbin/6to4relay -e 13610616SSebastien.Roy@Sun.COM fi 13710616SSebastien.Roy@Sun.COM fi 13810616SSebastien.Roy@Sun.COM ;; 13910616SSebastien.Roy@Sun.COM 14010616SSebastien.Roy@Sun.COMstop) 14110616SSebastien.Roy@Sun.COM tunnel_links=`get_tunnel_links` 14210616SSebastien.Roy@Sun.COM 14310616SSebastien.Roy@Sun.COM # Unplumb IP interfaces 14410616SSebastien.Roy@Sun.COM for tun in $tunnel_links; do 14510616SSebastien.Roy@Sun.COM /sbin/ifconfig $tun unplumb > /dev/null 2>&1 14610616SSebastien.Roy@Sun.COM /sbin/ifconfig $tun inet6 unplumb > /dev/null 2>&1 147*12016SGirish.Moodalbail@Sun.COM /sbin/ipadm disable-if -t $tun > /dev/null 2>&1 14810616SSebastien.Roy@Sun.COM done 14910616SSebastien.Roy@Sun.COM 15010616SSebastien.Roy@Sun.COM # Take down the IP tunnel links 15110616SSebastien.Roy@Sun.COM /sbin/dladm down-iptun 15210616SSebastien.Roy@Sun.COM ;; 15310616SSebastien.Roy@Sun.COM 15410616SSebastien.Roy@Sun.COM*) 15510616SSebastien.Roy@Sun.COM echo "Usage: $0 { start | stop }" 15610616SSebastien.Roy@Sun.COM exit 1 15710616SSebastien.Roy@Sun.COM ;; 15810616SSebastien.Roy@Sun.COMesac 15910616SSebastien.Roy@Sun.COM 16010616SSebastien.Roy@Sun.COMexit $SMF_EXIT_OK 161