24_Vol2_ch.5_Interfaces_SLIP_and_Loopback

Download Report

Transcript 24_Vol2_ch.5_Interfaces_SLIP_and_Loopback

TCP/IP Illustrated Vol2
The Implementation
Interfaces : SLIP & Loopback
2005. 5. 30(월)
양우철
[email protected]
1
contents





Introduction
Code Introduction
SLIP Interface
Loopback Interface
Summary
2
Introduction


SLIP & Loopback Interface, ioctl commands
The TCP compression algorithm used by the
SLIP driver is described in section 29.13
3
Code Introduction (1/3)

The files containing code for SLIP and loopback
drivers are listed in Figure 5.2
4
Code Introduction (2/3)

Global Variables

The SLIP and loopback interface structures are
described in this chapter.

sl_softc is an array, since there can be many SLIP
interfaces.
loif is not an array, since there can be only one
loopback interface.

5
Code Introduction (3/3)

Statistics

One other variable (which is not in the ifnet structure)
collects statistic.
6
SLIP Interface (1/2)


A SLIP interface communicates with a remote
system across a asynchronous serial line.
As with Ethernet, SLIP defines a standard way to
IP packets as they are transmitted on the serial
line.
7
SLIP Interface (2/2)




Packets are separated by the SLIP END
character 0xc0.
END ->0xdb + 0xdc(Escaped END character)
0xdb : SLIP ESC character
ESC ->0xdb + 0xdd(Escaped ESC character)
No type field in SLIP frames, SLIP is suitable
only for carrying IP packets.
8
The SLIP Line Discipline : slipdisc (1/5)



In Net/3 the SLIP interface relies on an
asynchronous serial device driver to send and
receive the data.
TTYs(teletypes)
The Net3/TTY subsystem includes the notion of
a line discipline that acts as a filter between the
physical device and I/O system calls such as
read and write.
The kernel identifies line discipline by an integer
constant, which for SLIP is SLIPDISC.
9
The SLIP Line Discipline : slipdisc (2/5)
10
The SLIP Line Discipline : slipdisc (3/5)

A SLIP interface has two roles to play in the
kernel.


as a network interface
as a TTY line discipline
11
The SLIP Line Discipline : slipdisc (4/5)
12
The SLIP Line Discipline : slipdisc (5/5)

Figure 5.8 contains a lot of information





The network interface is represented by the sl_softc
structure and the TTY device by the tty structure.
Incoming bytes are stored in the cluster. when a
complete SLIP frame is received, the enclosed IP
packet is put on the ipintrq by slinput.
Outgoing packets are dequeued from if_snd or
sc_fastq, converted to SLIP frames, and passed to the
TTY device by slstart.
The TTY buffers outgoing bytes in the clist structure.
The t_oproc function drains and transmits the bytes
held in the clist structure.
13
SLIP Initialization : slopen and slinit

slopen : the line discipline’s open function




Establishes the association between a particular TTY
device and a particular SLIP interface.
Line specific open routine.
Attach the given tty to the first available sl unit.
Precautions



if the process does not have superuser privileges
if the TTY’s line discipline is set to SLIPDISC already
return immediately
14
SLIP Initialization : slopen and slinit
dev : a kernel device identifier
tp : a pointer to the tty structure
Discards any pending input
or output data in the TTY queues.
15
SLIP Initialization : slopen and slinit

slinit : allocates an mbuf cluster and attaches it
to the sl_softc structure with three pointers.



sc_buf : always points to the start of the packet in the
cluster
sc_mp : points to the location of the next byte to be
received
sc_ep : points to the end of the cluster
16
SLIP Initialization : slopen and slinit
sc_ep : points to the end of the cluster
sc_buf : points to the start of the packet in the cluster
sc_mp : points to the location of the next byte to be received
Maximum size of an uncompressed SLIP packet
-including a BPF header
Maximum size of a compressed SLIP packet stored in a cluster
17
SLIP Initialization : slopen and slinit
18
SLIP Input Processing : slinput

The TTY device driver delivers incoming
characters to the SLIP line discipline one at a
time by calling slinput.
Next input character
Contains control info.
Counts the incoming characters for all TTY devices
/*Frame End code (Figure 5.13)*/
When the cluster is full or
When an error is detected in the
end-of-frame processing
Cluster reset for new packet
19
SLIP Input Processing : slinput
20
SLIP Input Processing : slinput
21
SLIP Output Processing : sloutput



As with all network interfaces, output processing
begins when a network-level protocol calls the
interface’s if_output function.
For SLIP, the function is sloutput.
The four arguments to sloutput are:





ifp : a pointer to the SLIP ifnet structure (in this case
an sl_softc structure)
m : a pointer to be queued for output
dst : the next-hop destination for the packet
rtp : a pointer to a route entry
The SLIP interface maintains two queues of
outgoing packet.
22
SLIP Output Processing : sloutput
23
slstart Function


The TTY device driver calls slstart when it drains
its output queue and needs more bytes to
transmit.
The TTY subsystem manages its queues
through a clist structure.
24
slstart Function
25
slstart Function
26
slstart Function
27
slstart Function
28
slstart Function
Total number of octets sent
Packets sent on interface
29
SLIP Packet Loss




The SLIP interface provides a good example of a
best-effort service.
SLIP discards packets if the TTY is overloaded;
it truncate packets if resources are unavailable
after the packet transmission has started, and it
inserts extraneous null packets to detect and
discard line noise.
In each of these cases, no error message is
generated.
SLIP depends on IP and the transport layers to
detect damaged an missing packets.
30
SLIP Performance Considerations

The MTU of a SLIP frame (SLMTU), the clist
high-water mark (SLIP-HIWAT), and SLIP’s TOS
queueing strategies are all designed to minimize
the delay inherent in a slow serial link for
interactive traffic.
31
slclose Function

For completeness, we show the slclose function,
which is called when the slattach program closes
SLIP’s TTY device and terminates the
connection to the remote system.
32
sltioctl Function
33
Loopback Interface


Any packet sent to the loopback interface are
immediately queued for input.
looutput, the if_output function for the loopback
interface, places outgoing packets on the input
queue for the protocol specified by the packet’s
destination address.
34
Loopback Interface
35
Loopback Interface
36