Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 18 Oct 1995 17:53:31 -0400 (EDT)
From:      rhh@ct.picker.com (Randall Hopper)
To:        crosswjo@hp-pcd.cv.hp.com
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Dynamic IP with SLIP...
Message-ID:  <9510182153.AA25363@elmer.ct.picker.com>
In-Reply-To: <9510032233.AA11979@hpcvusd.cv.hp.com> from "John Crosswhite" at Oct 3, 95 03:33:31 pm

next in thread | previous in thread | raw e-mail | index | archive | help
> After searching through the mailing list archives and reading the SLIP FAQS,
> I can see that there is no information on the configuration of SLIP for
> dynamic allocation of IP's.
> 
> Unfortunately, my provider (school) does not support ppp.  SO...SLIP is the
> only way to go as far as a dialup solution is concerned.  Could somebody find
> it within their hearts to point me to a source of relevant information on the
> subject?

Here are some script's I've modified to do SLIP on FreeBSD.  However, they
currently are set up to deal with a staticly assigned IP number.  Because of
this, they assume you've already added necessary routes to your routing table
as well as ifconfiged your slip interface for the appropriate IP before running
slip-on script.

To handle a dynamic IP, you'll need to stick a "read a_line" command after the
chat command (or between a few chat commands) to yank the IP number printed by
the dial-in server off into a variable.  Once you have this, you can then
ifconfig your slip interface and add your routes appropriately before kicking
off slattach.

Hope this helps.

							Randall Hopper
							rhh@ct.picker.com


-----------------------------------------------------------------------------
                                  slip-on
-----------------------------------------------------------------------------

#!/bin/sh
#
#===============================================
#       slip-on
#
#       Set up a SLIP link (FreeBSD 2.0.5) 
#===============================================

PATH=/usr/bin:/bin:/sbin:$PATH

#INITSTRING="AT&F1&B1S11=35"            # USR Sportster 28.8 FAX
INITSTRING="AT&C1&D2&Q6N1S11=50M0"      # ZOOM 14.4 FAX (no protocol)

DIALSTRING="ATDT1231234"
SERVER_PASSWORD=xxx
IP_ADDRESS=123.456.123.456
BAUD_RATE=57600

INTERFACE=sl0
DEVICE=cuaa1
DEVICE_INITIAL=`echo $DEVICE | sed 's/cua\(.*\)/cuai\1/'`
DEVICE_LOCKED=`echo $DEVICE | sed 's/cua\(.*\)/cual\1/'`
LOCKFILE=/var/spool/lock/LCK..$DEVICE



#------------------
#  Parse cmd line
#------------------
DO_VERBOSE=y
DO_REDIAL=y

while [ -n "$*" ]; do
   case $1 in
      -quiet)
	      DO_VERBOSE=n
	      ;;
      -noredial)
	      DO_REDIAL=n
	      ;;
   esac
   shift
   done

#--------------------------------
#  Get full path to this script
#--------------------------------

NEW_0=$0
case "$NEW_0" in
   /*)
       ;;
   *)
       NEW_0=`which $0`
       if [ -n "$NEW_0" ]; then
          case "$NEW_0" in
             /*)
                 ;;
             *)
                 NEW_0=`pwd`/"$NEW_0"
		 ;;
	  esac
       fi
       ;;
esac
if [ $DO_REDIAL = y -a \( -z "$NEW_0" -o ! -x "$NEW_0" \) ]; then
   echo "WARNING:  Couldn't find location of this script -- redial disabled"
   DO_REDIAL=n
fi


#------------------
#  Sanity Checks
#------------------
if [ `whoami` != root ]; then
    echo "ERROR:  Must be root"      # needed for ifconfig & TIOCSETD
    exit 1
fi

if [ -f $LOCKFILE ]; then
    echo "ERROR: /dev/$DEVICE is locked ($LOCKFILE exists)"
    exit 1
fi
#if [ -f $PIDFILE ]; then
#    echo "ERROR: slattach looks like it's running on /dev/$DEVICE"
#    echo "       ($PIDFILE exists)"
#    exit 1
#fi


#-------------------------------------------
#  Set up and connect to modem serial port
#-------------------------------------------
stty -f /dev/$DEVICE_INITIAL speed $BAUD_RATE crtscts > /dev/null

exec 0< /dev/$DEVICE
exec 1> /dev/$DEVICE


#--------------------------------------------------------------------------
#  Clear out the serial driver's receive buffer -- may be "NO CARRIER" or
#    something left in there that'll cause the next chat to bottom out
#    (NOTE: Use -v option for debugging)
#--------------------------------------------------------------------------
if chat -v "" AT OK AT OK; then
    echo > /dev/null
else
    if [ $DO_VERBOSE = y ]; then echo "ERROR: CHAT call 1 failed" >&2; fi
    exit 2
fi
 

#------------------------------------------------------------
#  Log-in through the dial-in server and get into SLIP mode
#    (NOTE: Use -v option for debugging)
#------------------------------------------------------------

if chat -v \
     ABORT "NO CARRIER" ABORT BUSY ABORT "NO DIAL TONE" \
     ""                         "$INITSTRING"      \
     "OK"                       "$DIALSTRING"      \
     "Login:"                   "slip"             \
     "Password:"                "$SERVER_PASSWORD" \
     "IP address or hostname:"  "$IP_ADDRESS"
then

    #-----------------------------------------------------------------------
    #  Start SLIP process  (if not already started -- e.g. in a reconnect)
    #-----------------------------------------------------------------------

    PIDFILE=/var/run/slattach.$DEVICE.pid

    if [ ! -f $PIDFILE ]; then
       if [ $DO_VERBOSE = y ]; then echo "Starting SLIP..." >&2; fi
       if [ $DO_REDIAL = y ]; then
          slattach -h -c -s $BAUD_RATE -r "$NEW_0 $*" /dev/${DEVICE} > /dev/null 2>&1 &
       else
          slattach -h -c -s $BAUD_RATE /dev/${DEVICE} > /dev/null 2>&1 &
       fi
       ifconfig $INTERFACE up
       sleep 3
       exit 0
    else 
       #  Reconnected - return control to parent slattach process
       exit 0
    fi
else
   if [ $DO_VERBOSE = y ]; then echo "ERROR: Chat call 2 failed" >&2; fi
   exit 2
fi

-----------------------------------------------------------------------------
                                  slip-off
-----------------------------------------------------------------------------

#!/bin/sh
#
#===============================================
#       slip-off
#
#       Take down a SLIP link (FreeBSD 2.0.5) 
#===============================================

PATH=/usr/bin:/bin:/sbin:$PATH

DEVICE=cuaa1
INTERFACE=sl1

PIDFILE=/var/run/slattach.$DEVICE.pid

if [ `whoami` != root ]; then
   echo "ERROR:  Must be root"      # needed for ifconfig & killing root proc
   exit 1
fi

if [ ! -f $PIDFILE ]; then
   echo "ERROR:  Can't find PID file for slattach process"
   exit 1
fi

#------------------------------------------------------------------------
# 1. Kill slattach process
# 2. Bring down the interface
# 3. Open/Close the device (in case slattach didn't) to hang up modem
#------------------------------------------------------------------------

kill -INT `cat /var/run/slattach.$DEVICE.pid`
ifconfig $INTERFACE down
sleep 2
echo "" > /dev/$DEVICE

exit 0



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?9510182153.AA25363>