Telecommunications and Multimedia Unit
Download
1 / 46

Agostinho L S Castro - PowerPoint PPT Presentation


  • 115 Views
  • Uploaded on

Telecommunications and Multimedia Unit. BSD TCP/IP Protocol Suite An Overview of the Implementation. Agostinho L S Castro. [email protected] BSD TCP/IP Protocol Suite – The Implementation. Network Implementation. 4.4 BSD supports 4 distinct communication protocol families. TCP/IP.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Agostinho L S Castro' - rafer


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

Telecommunications and Multimedia Unit

BSD TCP/IP Protocol Suite

An Overview of the Implementation

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • Network Implementation

4.4 BSD supports 4 distinct communication protocol

families

  • TCP/IP

  • XNS (Xerox Network Systems)

  • OSI protocols

  • Unix domain protocols

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • The TCP/IP protocol suite allows computers of all sizes, from different computer vendor, running totally different

  • operating systems, to communicate with each other.

  • TCP/IP is normally considered to be a 4 layer system

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • General organization of networking code in 4.4 BSD

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


sys/mbuf.h

mbuf structure, mbuff macros and definitions

kern/uipc_mbuf.c

linux/include/linux/skbuff.h

mbuf.h functions

BSD TCP/IP Protocol Suite – The Implementation

  • Mbufs (Memory Buffers)

A fundamental concept in the design of the Berkeley

Networking is the memory buffer, called an mbuf, used

throughout the networking code to hold various pieces

of information.

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

mbuf.h

/* header at beginning of each mbuf */

struct m_hdr {

struct mbuf *mh_next ; /* next buffer in chain */

struct mbuf *mh_nextpkt; /* next chain in queue record */

……………………………………………………………………………………

short mh_type; /* type of data */

short mh_flags; /* flags */

………………………………………..…………………………………………..

#define m_next m.hdr.mh_next

#define m_len m.hdr.mh_len

……………………………………………………………………..……………..

};

mbuf structures

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • Remarks on mbuf

  • The size of the mbuf structure is always 128 bytes

  • In each of the mbuf we show the m_data member

  • pointing to the beginning of the corresponding buffer.

  • (this pointer can point anywhere in the corresponding

  • buff – not necessarily in the front)

  • The m_next pointer links together the mbuf forming a

  • single packet into an mbuf chain

  • The m_next pointer links multiple packets together to

  • form a queue of mbuf

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

Linked list of mbuf chains with head pointer

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • Interface layer

4.4 BSD interface layer attempts to provide a hardware-

independent programming interface between the network

protocols and the drivers for the network devices

connected to a system

The interface layer supports provides for all devices

  • A well-defined set of interface functions

  • A standard set of statistics and control flags

  • A device-independent method of storing protocol

  • address

  • A standard queueing method for outgoing packets

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


sys/socket.h  address structure definitions

net/if.h  interface structure definitions

net/if_dl.h  link-level structure definitions

linux/init/main.c  system and interface initialisations

drivers/net/skeleton.c  generic interface code

drivers/net/loopback.c  loopback device driver

BSD TCP/IP Protocol Suite – The Implementation

net/init_main.c  system and interface initialisations

net/if.c  generic interface code

net/if_loop.c  loopback device driver

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • Interface layer

  • Ifnet struture

  • Ifaddr struture

  • sockaddr struture

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • ifnet structure

  • It contains information common to all interfaces.

  • During system initialization, a separate ifnet structure is

  • allocated for each network device.

  • Every ifnet structure has a list of one or more protocol

  • address associated with it.

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • ifnet description

    • Implementation information

      • List construction

      • Common interface information (name, such as: eth0, sl0,...)

    • Flags (if_flags specifies the operational state and

      • properties of the interface)

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • ifnet description

    • Interface timer

    • BSD packet filter

      • Through BPF, a process can receive copies of

      • packets transmitted or received by interface

    • Hardware information

      • Interface characteristics (hardware address type

      • supported by the interface – Ethernet , SLIP,

      • loopback interface)

      • mtu, metric, baudrate

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • ifnet description

    • Interfaces statistics

    • Functions pointers (interface procedures)

  • It contains pointers to the standard interface-layer

  • functions which isolate device-specific details from

  • network layer

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • ifnet description

    • Output queue

      • Each interface has its own ifnet structure and

      • therefore it own output queue

  • ifaddr structure

    • Each interface maintains a linked list of ifaddr structures

    • because some data links, such as Ethernet, support

    • more then one protocol

    • A separate ifaddr structure describes each address assigned to the interface, usually one address per protocol

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

if.h

struct ifaddr {

struct ifaddr *ifa_next;/*next address for interface */

struct ifnet *ifa_ifp; /*back-pointer to interface */

……………………………………………………………..…..

};

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • sockaddr structure

    • Addressing information for an interface consists of

    • more then single host address. 4.4 BSD maintains

    • host, broadcast and network mask in structures

    • derived from generic sockaddr structure

socket.h

struct sockaddr {

u_char sa_len; /* total length */

u_char sa_family; /* address family*/

.......................................................................

};

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

sa_family constants

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • Ifnet and ifaddr specialization

  • The ifnet and ifaddr structures contain general information

  • applicable to all network interface and protocol address.

  • To accommodate additional device and protocol-specific information, each driver defines and each protocol

  • allocates a specialized version of the ifnet and ifaddr structures.

  • Arpcom structure is common to all Ethernet drivers and contains information for the Address Resolution Protocol (ARP)

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

Arragement of ifnet structure within

device-dependent structures

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • Ethernet Initialization

    • cpu_start (init_main.c)

      • the kernel locates any attached network devices

      • le,sl,loop xxxattach – initialization function

    • each device driver for a network interface initialize a

    • specialized ifnet structure

    • if_attach function completes the initialization and

    • inserts the structure into linked list the interface (ifnet structure specialized, arpcom structure)

  • After this initialization, the interfaces are configured only

  • with link-level address

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • Interface: Ethernet

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • if_le.c

  • leintr Function

    • leintr Function examines the hardware and if a frame

    • has arrived. Calls lread function to transfer the frame

    • from the interface to a chain of mbufs

  • leread Function

    • ether_header construction

    • chain of mbufs construction

    • it passes the incoming frames to BPF

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • ether_input Function

    • ether_inputfunction examines the ether_header

    • structure to determine the type of data has been

    • received and then queues the received packet for processing

    • broadcast and multicast recognition

    • link-level demultiplexing

    • queue the packet

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • ether_output Function

    • output frames of Ethernet frames

    • network-level protocol (IP) call if_output function

    • (ifnet structure)

    • if_output ~ ether_output (accept and queue frame for begin transmission of frame

    • - verification

  • - protocol-specific processing

  • - frame construction

  • - interface queueing

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • lestart Function

    • interface must be initialized

    • dequeue frame from output queue

    • transmit frame and pass to BPF

    • repeat if device is ready for more frames

    • mark device as busy

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • IP: Internet Protocol

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

IP datagram, including ip structure names

ip structure - ip.h file

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • input processing

  • ipintr Function – ip_input.c

    • verification of incoming packets

      • dequeueing packets from ipintrq

      • verifies their contents

      • damaged or erroneous packets are silently discarded

      • IP version (ip_v = 4)

      • IP checksum

      • Byte ordering

      • Packet length

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • ipintr Function – ip_input.c

    • Determines whether or not the packet has reached its final destination

      • NO – forward (if systems is configured as a router)

      • YES – transport-level protocol

    • Reassembly and demultipexing

    • The protocol specified in the datagram is mapped by ip_p.

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

ip_forward Function

A packet arriving at a system other than its final destination needs to be forward. ipintr calls the function ip_forward which implements the forwarding algorithm

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • ip_output Function – ip_output.c

  • two sources: ip_forward and the transport protocols

    • Header initialization

    • The first section of ip_output merge options into the

      outgoing packets and completes the IP header for packets that passed from the transport protocols

    • IP header construction

    • Packet already including header (for a forward packet)

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • ip_output Function – ip_output.c

    • Route selection

      • After completing the IP header, the next task for

      • ip_output is to locate a route to the destination

    • Source address selection and fragmentation

      • The final section of ip_output ensure that the IP

      • header has a valid source address and the interface associated with the route

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • TCP: Transmission Control Protocol

tcp_debug.h, tcp_seq.h, tcp_timer.h, tcp_var.h, tcp_tcpip.h

tcp_debug.c, tcp_subr.c, tcp_timer.c, tcp_usrreq.c

28 functions and almost 4,500 lines of C code

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

TCP Header

tcp.h file

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

TCP Output – tcp_output.c

tcp_output is called whenever a segment to be sent on

a connection

tcp_output determines whether a segment can be sent,

and if so, what values to set all the TCP header fields

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • tcp_output description

    • Send a segment

    • it fills in all the fields in the TCP header and passes the segment to IP for output

    • Calculate amount of data to send

    • Build MSS (maximum segment size) option

    • Build window scale option

    • Build timestamp option

    • Check if options have overflowed segment

    • Update statistics

    • Allocate an mbuf for IP and TCP headers

    • Copy data into mbuf

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • tcp_output description

    • Set PSH (push flag) flag

    • Update statistics

    • Get mbuf for IP and TCP headers

    • Copy IP and TCP header templates into mbuf

    • Set sequence number filed of segment

    • Set acknowledgment field of segment

    • Set header length if option present

    • Don´t advertise less than one full-size segment

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

  • tcp_output description

    • Observe upper limit for advertised window on this

      connection

    • Do not shrink window

    • Set urgent offset

    • Set retransmission timer

    • Persist state

    • Add trace record for socket debugging

    • Set IP length, TTL, and TOS

    • Pass datagram to IP

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

TCP Input – tcp_input.c

  • The function tcp_input is about 1100 lines code.

  • The function tcp_input is called by ipintr when a datagram

  • is received with a protocol field of TCP.

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

TCP Input – tcp_input.c

  • Preliminary processing

    • Get IP and TCP in first mbuf

    • Verify TCP checksum

    • Verify TCP offset field

    • Get headers plus option into first mbuf

    • Process timestamp option quickly

    • Save input flags and convert fields to host byte order

    • Locate Internet PCB (protocol control block)

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


BSD TCP/IP Protocol Suite – The Implementation

TCP Input – tcp_input.c

  • Preliminary processing

    • Drop segment and generate RST

    • Silently drop segment

    • Unscale advertised window

    • Save connection state and TCP/IP headers if socket debug option enabled

    • Create new socket if segment arrives for listening

      socket

    • Computer window scale factor

    • Reset idle time and keep alive timer

    • Process TCP options if not in LISTEN state

Telecommunications and Multimedia Unit

Agostinho L S Castro

[email protected]


Telecommunications and Multimedia Unit

Bibliography

  • Wright, G. R., Stevens, W. R.,"TCP/IP Illustrated – The Implementaion",Volume 2.,Addison-Wesley, 1995 .

  • Wright, G. R., Stevens, W. R.,"TCP/IP Illustrated – The Protocol",Volume 1.,Addison-Wesley, 1994 .

  • Rubini, A., “LINUX Device Drivers”, O´Reilly& Associates, Inc.,1998.

  • Rusling, David A., “The Linux Kernel”, LDP – www.linuxdoc.org


ad