12b24ab6bSSebastien Roy#!/sbin/sh 22b24ab6bSSebastien Roy# 32b24ab6bSSebastien Roy# CDDL HEADER START 42b24ab6bSSebastien Roy# 52b24ab6bSSebastien Roy# The contents of this file are subject to the terms of the 62b24ab6bSSebastien Roy# Common Development and Distribution License (the "License"). 72b24ab6bSSebastien Roy# You may not use this file except in compliance with the License. 82b24ab6bSSebastien Roy# 92b24ab6bSSebastien Roy# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 102b24ab6bSSebastien Roy# or http://www.opensolaris.org/os/licensing. 112b24ab6bSSebastien Roy# See the License for the specific language governing permissions 122b24ab6bSSebastien Roy# and limitations under the License. 132b24ab6bSSebastien Roy# 142b24ab6bSSebastien Roy# When distributing Covered Code, include this CDDL HEADER in each 152b24ab6bSSebastien Roy# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 162b24ab6bSSebastien Roy# If applicable, add the following below this CDDL HEADER, with the 172b24ab6bSSebastien Roy# fields enclosed by brackets "[]" replaced with your own identifying 182b24ab6bSSebastien Roy# information: Portions Copyright [yyyy] [name of copyright owner] 192b24ab6bSSebastien Roy# 202b24ab6bSSebastien Roy# CDDL HEADER END 212b24ab6bSSebastien Roy# 222b24ab6bSSebastien Roy# 23*6e91bba0SGirish Moodalbail# Copyright 2010 Sun Microsystems, Inc. All rights reserved. 242b24ab6bSSebastien Roy# Use is subject to license terms. 252b24ab6bSSebastien Roy# 262b24ab6bSSebastien Roy# This service configures IP tunnel links and IP interfaces over IP 272b24ab6bSSebastien Roy# tunnels. 282b24ab6bSSebastien Roy# 292b24ab6bSSebastien Roy 302b24ab6bSSebastien Roy. /lib/svc/share/smf_include.sh 312b24ab6bSSebastien Roy 322b24ab6bSSebastien Roy# 332b24ab6bSSebastien Roy# Configure tunnels which were deferred by /lib/svc/method/net-physical (the 342b24ab6bSSebastien Roy# svc:/network/physical service) since it depends on the tunnel source 352b24ab6bSSebastien Roy# addresses being available. 362b24ab6bSSebastien Roy# 372b24ab6bSSebastien Roy# WARNING: you may wish to turn OFF forwarding if you haven't already, because 382b24ab6bSSebastien Roy# of various possible security vulnerabilities when configuring tunnels for 392b24ab6bSSebastien Roy# Virtual Private Network (VPN) construction. 402b24ab6bSSebastien Roy# 412b24ab6bSSebastien Roy# Also, if names are used in the /etc/hostname*.* files, those names have to 422b24ab6bSSebastien Roy# be in either DNS (and DNS is used) or in /etc/hosts, because this file is 4336e852a1SRaja Andra# executed before NIS is started. 442b24ab6bSSebastien Roy# 452b24ab6bSSebastien Roy 462b24ab6bSSebastien Roy# 472b24ab6bSSebastien Roy# get_tunnel_links: print the names of the tunnel links currently configured 482b24ab6bSSebastien Roy# on the running system. 492b24ab6bSSebastien Roy# 502b24ab6bSSebastien Royget_tunnel_links () 512b24ab6bSSebastien Roy{ 522b24ab6bSSebastien Roy /sbin/dladm show-iptun -p -o link 532b24ab6bSSebastien Roy} 542b24ab6bSSebastien Roy 552b24ab6bSSebastien Roy# plumb_tunnel <intf_name> <net_type> <intf_file> 562b24ab6bSSebastien Royplumb_tunnel () 572b24ab6bSSebastien Roy{ 582b24ab6bSSebastien Roy /sbin/ifconfig $1 $2 plumb 592b24ab6bSSebastien Roy while read ifcmds; do 602b24ab6bSSebastien Roy if [ -n "$ifcmds" ]; then 612b24ab6bSSebastien Roy /sbin/ifconfig $1 $2 $ifcmds 622b24ab6bSSebastien Roy fi 632b24ab6bSSebastien Roy done < $3 > /dev/null 642b24ab6bSSebastien Roy /sbin/ifconfig $1 $2 up 652b24ab6bSSebastien Roy} 662b24ab6bSSebastien Roy 672b24ab6bSSebastien Roycase "$1" in 682b24ab6bSSebastien Roystart) 692b24ab6bSSebastien Roy # First, bring up tunnel links 702b24ab6bSSebastien Roy /sbin/dladm up-iptun 712b24ab6bSSebastien Roy 722b24ab6bSSebastien Roy # 732b24ab6bSSebastien Roy # Get the list of IP tunnel interfaces we'll need to configure. These 742b24ab6bSSebastien Roy # are comprised of IP interfaces over the tunnels we've just brought 752b24ab6bSSebastien Roy # up in the above dladm command, and the implicit tunnels named "ip.*" 762b24ab6bSSebastien Roy # that we'll also create for backward compatibility. When we build 772b24ab6bSSebastien Roy # the list of implicit tunnels, we have to make sure that they're not 782b24ab6bSSebastien Roy # different kinds of links that are simply named "ip.*". 792b24ab6bSSebastien Roy # 802b24ab6bSSebastien Roy tunnel_links=`get_tunnel_links` 812b24ab6bSSebastien Roy implicit_tunnel_names=`/usr/bin/ls -1 /etc/hostname.ip*.*[0-9] \ 822b24ab6bSSebastien Roy /etc/hostname6.ip*.*[0-9] 2> /dev/null | /usr/bin/cut -f2- -d. | \ 832b24ab6bSSebastien Roy /usr/bin/sort -u` 842b24ab6bSSebastien Roy for intf_name in $implicit_tunnel_names; do 852b24ab6bSSebastien Roy /sbin/dladm show-link -pP $intf_name > /dev/null 2>&1 862b24ab6bSSebastien Roy if [ $? -ne 0 ]; then 872b24ab6bSSebastien Roy implicit_tunnels="$implicit_tunnels $intf_name" 882b24ab6bSSebastien Roy fi 892b24ab6bSSebastien Roy done 902b24ab6bSSebastien Roy tunnel_interfaces=`for intf in $tunnel_links $implicit_tunnels; do \ 912b24ab6bSSebastien Roy echo $intf; done | /usr/bin/sort -u` 922b24ab6bSSebastien Roy 932b24ab6bSSebastien Roy for intf_name in $tunnel_interfaces; do 942b24ab6bSSebastien Roy if [ -f /etc/hostname.$intf_name ]; then 952b24ab6bSSebastien Roy plumb_tunnel $intf_name inet /etc/hostname.$intf_name 962b24ab6bSSebastien Roy fi 972b24ab6bSSebastien Roy if [ -f /etc/hostname6.$intf_name ]; then 982b24ab6bSSebastien Roy plumb_tunnel $intf_name inet6 /etc/hostname6.$intf_name 992b24ab6bSSebastien Roy fi 100*6e91bba0SGirish Moodalbail # 101*6e91bba0SGirish Moodalbail # Configure IP tunnel interfaces set up using ipadm 102*6e91bba0SGirish Moodalbail # 103*6e91bba0SGirish Moodalbail state=`/sbin/ipadm show-if -p -o state $intf_name` 104*6e91bba0SGirish Moodalbail if [ $? -ne 0 ] || [ "$state" != "disabled" ]; then 105*6e91bba0SGirish Moodalbail # 106*6e91bba0SGirish Moodalbail # skip if not managed my ipadm or if not a persistent 107*6e91bba0SGirish Moodalbail # interface 108*6e91bba0SGirish Moodalbail # 109*6e91bba0SGirish Moodalbail continue; 110*6e91bba0SGirish Moodalbail elif [ -f /etc/hostname.$intf_name ] ||\ 111*6e91bba0SGirish Moodalbail [ -f /etc/hostname6.$intf_name ]; then 112*6e91bba0SGirish Moodalbail echo "found /etc/hostname.$intf_name or "\ 113*6e91bba0SGirish Moodalbail "/etc/hostname6.$intfi_name, ignoring ipadm "\ 114*6e91bba0SGirish Moodalbail "configuration" > /dev/msglog 115*6e91bba0SGirish Moodalbail continue; 116*6e91bba0SGirish Moodalbail else 117*6e91bba0SGirish Moodalbail # Enable the interface managed by ipadm 118*6e91bba0SGirish Moodalbail /sbin/ipadm enable-if -t $intf_name 119*6e91bba0SGirish Moodalbail fi 1202b24ab6bSSebastien Roy done 1212b24ab6bSSebastien Roy 1222b24ab6bSSebastien Roy # 1232b24ab6bSSebastien Roy # Set 6to4 Relay Router communication support policy and, if 1242b24ab6bSSebastien Roy # applicable, the destination Relay Router IPv4 address. See 1252b24ab6bSSebastien Roy # /etc/default/inetinit for setting and further info on 1262b24ab6bSSebastien Roy # ACCEPT6TO4RELAY and RELAY6TO4ADDR. If ACCEPT6TO4RELAY=NO, the 1272b24ab6bSSebastien Roy # default value in the kernel will be used. 1282b24ab6bSSebastien Roy # 1292b24ab6bSSebastien Roy [ -f /etc/default/inetinit ] && . /etc/default/inetinit 1302b24ab6bSSebastien Roy ACCEPT6TO4RELAY=`echo "$ACCEPT6TO4RELAY" | /usr/bin/tr '[A-Z]' '[a-z]'` 1312b24ab6bSSebastien Roy if [ "$ACCEPT6TO4RELAY" = yes ]; then 1322b24ab6bSSebastien Roy if [ "$RELAY6TO4ADDR" ]; then 1332b24ab6bSSebastien Roy /usr/sbin/6to4relay -e -a $RELAY6TO4ADDR 1342b24ab6bSSebastien Roy else 1352b24ab6bSSebastien Roy /usr/sbin/6to4relay -e 1362b24ab6bSSebastien Roy fi 1372b24ab6bSSebastien Roy fi 1382b24ab6bSSebastien Roy ;; 1392b24ab6bSSebastien Roy 1402b24ab6bSSebastien Roystop) 1412b24ab6bSSebastien Roy tunnel_links=`get_tunnel_links` 1422b24ab6bSSebastien Roy 1432b24ab6bSSebastien Roy # Unplumb IP interfaces 1442b24ab6bSSebastien Roy for tun in $tunnel_links; do 1452b24ab6bSSebastien Roy /sbin/ifconfig $tun unplumb > /dev/null 2>&1 1462b24ab6bSSebastien Roy /sbin/ifconfig $tun inet6 unplumb > /dev/null 2>&1 147*6e91bba0SGirish Moodalbail /sbin/ipadm disable-if -t $tun > /dev/null 2>&1 1482b24ab6bSSebastien Roy done 1492b24ab6bSSebastien Roy 1502b24ab6bSSebastien Roy # Take down the IP tunnel links 1512b24ab6bSSebastien Roy /sbin/dladm down-iptun 1522b24ab6bSSebastien Roy ;; 1532b24ab6bSSebastien Roy 1542b24ab6bSSebastien Roy*) 1552b24ab6bSSebastien Roy echo "Usage: $0 { start | stop }" 1562b24ab6bSSebastien Roy exit 1 1572b24ab6bSSebastien Roy ;; 1582b24ab6bSSebastien Royesac 1592b24ab6bSSebastien Roy 1602b24ab6bSSebastien Royexit $SMF_EXIT_OK 161