#!/bin/ksh # # CDDL HEADER START # # The contents of this file are subject to the terms of the # Common Development and Distribution License, (the "License"). # You may not use this file except in compliance with the License. # # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE # or http://www.opensolaris.org/os/licensing. # See the License for the specific language governing permissions # and limitations under the License. # # When distributing Covered Code, include this CDDL HEADER in each # file and include the License file at usr/src/OPENSOLARIS.LICENSE. # If applicable, add the following below this CDDL HEADER, with the # fields enclosed by brackets "[]" replaced with your own identifying # information: Portions Copyright [yyyy] [name of copyright owner] # # CDDL HEADER END # # Copyright 2006 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. title="Labeled Interface Manager" getAttrs() { zone=global type=ignore for j in `ifconfig $nic` do case $j in inet) type=$j;; zone) type=$j;; all-zones) zone=all-zones;; flags*) flags=$j;; *) case $type in inet) ipaddr=$j ;; zone) zone=$j ;; *) continue ;; esac;\ type=ignore;; esac done if [ $ipaddr != 0.0.0.0 ]; then template=`tninfo -h $ipaddr|grep Template| cut -d" " -f3` else template="..." ipaddr="..." fi } updateTnrhdb() { tnctl -h ${ipaddr}:$template x=`grep "^${ipaddr}[^0-9]" /etc/security/tsol/tnrhdb` if [ $? = 0 ]; then sed s/$x/${ipaddr}:$template/g /etc/security/tsol/tnrhdb \ > /tmp/txnetmgr.$$ mv /tmp/txnetmgr.$$ /etc/security/tsol/tnrhdb else echo ${ipaddr}:$template >> /etc/security/tsol/tnrhdb fi } getIPaddr() { hostname=$(zenity --entry \ --title="$title" \ --text="$nic: Enter hostname: ") if [ $? != 0 ]; then return; fi ipaddr=`getent hosts $hostname|cut -f1` if [[ -z $ipaddr ]]; then ipaddr=$(zenity --entry \ --title="$title" \ --text="$nic: Enter IP address: " \ --entry-text a.b.c.d) if [ $? != 0 ]; then return; fi fi # Update hosts and ipnodes grep "^${ipaddr}[^0-9]" /etc/inet/hosts >/dev/null if [ $? -eq 1 ]; then echo "$ipaddr\t$hostname" >> /etc/inet/hosts fi grep "^${ipaddr}[^0-9]" /etc/inet/ipnodes >/dev/null if [ $? -eq 1 ]; then echo "$ipaddr\t$hostname" >> /etc/inet/ipnodes fi template=cipso updateTnrhdb ifconfig $nic $ipaddr netmask + broadcast + echo $hostname > /etc/hostname.$nic } getTemplate() { templates=$(cat /etc/security/tsol/tnrhtp|\ grep "^[A-z]"|grep "type=cipso"|cut -f1 -d":") while [ 1 -gt 0 ]; do t_cmd=$(zenity --list \ --title="$title" \ --height=300 \ --column="Network Templates" \ $templates) if [ $? != 0 ]; then break; fi t_label=$(tninfo -t $t_cmd | grep sl|zenity --list \ --title="$title" \ --height=300 \ --width=450 \ --column="Click OK to associate $t_cmd template with $ipaddr" ) if [ $? != 0 ]; then continue fi template=$t_cmd updateTnrhdb break done } createInterface() { msg=`ifconfig $nic addif 0.0.0.0` $(zenity --info \ --title="$title" \ --text="$msg" ) } shareInterface() { ifconfig $nic all-zones;\ if_file=/etc/hostname.$nic sed q | sed -e "s/$/ all-zones/" < $if_file >/tmp/txnetmgr.$$ mv /tmp/txnetmgr.$$ $if_file } # # Always display vni0 since it is useful for cross-zone networking # ifconfig vni0 > /dev/null if [ $? != 0 ]; then ifconfig vni0 plumb fi while [ 1 -gt 0 ]; do attrs= for i in `ifconfig -au4|grep "^[a-z].*:" |grep -v LOOPBACK` do echo $i |grep "^[a-z].*:" >/dev/null 2>&1 if [ $? -eq 1 ]; then continue fi nic=${i%:} # Remove colon after interface name getAttrs attrs="$nic $zone $ipaddr $template Up $attrs" done for i in `ifconfig -ad4 |grep "^[a-z].*:" |grep -v LOOPBACK` do echo $i |grep "^[a-z].*:" >/dev/null 2>&1 if [ $? -eq 1 ]; then continue fi nic=${i%:} # Remove colon after interface name getAttrs attrs="$nic $zone $ipaddr $template Down $attrs" done nic=$(zenity --list \ --title="$title" \ --height=300 \ --width=450 \ --column="Interface" \ --column="Zone Name" \ --column="IP Address" \ --column="Template" \ --column="State" \ $attrs) if [[ -z $nic ]]; then exit fi getAttrs # Clear list of commands share= setipaddr= settemplate= newlogical= unplumb= bringup= bringdown= # Check for physical interface hascolon=`echo $nic |grep :` if [ $? != 0 ]; then newlogical="Create Logical Interface\n"; else up=`echo $flags|grep "UP,"` if [ $? != 0 ]; then unplumb="Remove Logical Interface\n" if [ $ipaddr != "..." ]; then bringup="Bring Up\n" fi else bringdown="Bring Down\n" fi fi if [ $ipaddr = "..." ]; then setipaddr="Set IP address...\n"; else settemplate="View Templates...\n" if [ $zone = global ]; then share="Share\n" fi fi command=$(echo ""\ $share \ $setipaddr \ $settemplate \ $newlogical \ $unplumb \ $bringup \ $bringdown \ | zenity --list \ --title="$title" \ --height=300 \ --column "Interface: $nic" ) case $command in " Create Logical Interface")\ createInterface;; " Set IP address...")\ getIPaddr;; " Share")\ shareInterface;; " View Templates...")\ getTemplate;; " Remove Logical Interface")\ ifconfig $nic unplumb;\ rm -f /etc/hostname.$nic;; " Bring Up")\ ifconfig $nic up;; " Bring Down")\ ifconfig $nic down;; *) continue;; esac done