Using dip

Now that was rather simple. Nevertheless, you might want to automate the steps previously described. It would be much better to have a simple command that performs all the steps necessary to open the serial device, cause the modem to dial the provider, log in, enable the SLIP line discipline, and configure the network interface. This is what the dip command is for.

dip means Dialup IP. It was written by Fred van Kempen and has been patched very heavily by a number of people. Today there is one strain that is used by almost everyone: Version dip337p- uri, which is included with most modern Linux distributions, or is available from the metalab.unc.edu FTP archive.

dip provides an interpreter for a simple scripting language that can handle the modem for you, convert the line to SLIP mode, and configure the interfaces. The script language is powerful enough to suit most configurations.

To be able to configure the SLIP interface, dip requires root privilege. It would now be tempting to make dip setuid to root so that all users can dial up some SLIP server without having to give them root access. This is very dangerous, though, because setting up bogus interfaces and default routes with dip may disrupt routing on your network. Even worse, this action would give your users power to connect to any SLIP server and launch dangerous attacks on your network. If you want to allow your users to fire up a SLIP connection, write small wrapper programs for each prospective SLIP server and have these wrappers invoke dip with the specific script that establishes the connection. Carefully written wrapper programs can then safely be made setuid to root.[44] An alternative, more flexible approach is to give trusted users root access to dip using a program like sudo.

A Sample Script

Assume that the host to which we make our SLIP connection is cowslip, and that we have written a script for dip to run called cowslip.dip that makes our connection. We invoke dip with the script name as argument:

# dip cowslip.dip

DIP: Dialup IP Protocol Driver version 3.3.7 (12/13/93)

Written by Fred N. van Kempen, MicroWalt Corporation.

connected to cowslip.moo.com with addr 192.168.5.74

#

The script itself is shown in Example 7.1.

Example 7.1: A Sample dip Script

# Sample dip script for dialing up cowslip

# Set local and remote name and address

 get $local vlager-slip

 get $remote cowslip

 port ttyS3 # choose a serial port speed

 38400 # set speed to max

 modem HAYES # set modem type

 reset # reset modem and tty

 flush # flush out modem response

# Prepare for dialing.

 send ATQ0V1E1X1

wait OK 2

 if $errlvl != 0 goto error

 dial 41988

 if $errlvl != 0 goto error

 wait CONNECT 60

 if $errlvl != 0 goto error

# Okay, we're connected now

 sleep 3

 send

 wait ogin: 10

 if $errlvl != 0 goto error

 send Svlager

 wait ssword: 5

 if $errlvl != 0 goto error

 send knockknock

 wait running 30

 if $errlvl != 0 goto error

# We have logged in, and the remote side is firing up SLIP.

 print Connected to $remote with address $rmtip

 default # Make this link our default route

 mode SLIP # We go to SLIP mode, too

# fall through in case of error

error:

 print SLIP to $remote failed.

After connecting to cowslip and enabling SLIP, dip will detach from the terminal and go to the background. You can then start using the normal networking services on the SLIP link. To terminate the connection, simply invoke dip with the -k option. This sends a hangup signal to dip, using the process ID dip records in /etc/dip.pid:

# dip -k

In dip 's scripting language, keywords prefixed with a dollar symbol denote variable names. dip has a predefined set of variables, which will be listed below. $remote and $local, for instance, contain the hostnames of the remote and local hosts involved in the SLIP link.

The first two statements in the sample script are get commands, which is dip 's way to set a variable. Here, the local and remote hostnames are set to vlager and cowslip, respectively.

The next five statements set up the terminal line and the modem. reset sends a reset string to the modem. The next statement flushes out the modem response so that the login chat in the next few lines works properly. This chat is pretty straightforward: it simply dials 41988, the phone number of cowslip, and logs in to the account Svlager using the password knockknock. The wait command makes dip wait for the string given as its first argument; the number given as its second argument makes the wait time out after that many seconds if no such string is received. The if commands interspersed in the login procedure check that no error occurred while executing the command.

The final commands executed after logging in are default, which makes the SLIP link the default route to all hosts, and mode, which enables SLIP mode on the line and configures the interface and routing table for you.

Добавить отзыв
ВСЕ ОТЗЫВЫ О КНИГЕ В ИЗБРАННОЕ

0

Вы можете отметить интересные вам фрагменты текста, которые будут доступны по уникальной ссылке в адресной строке браузера.

Отметить Добавить цитату