Agostinho L S Castro [email protected] Telecommunications and Multimedia Unit BSD TCP/IP...
-
date post
18-Dec-2015 -
Category
Documents
-
view
214 -
download
0
Transcript of Agostinho L S Castro [email protected] Telecommunications and Multimedia Unit BSD TCP/IP...
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
BSD TCP/IP Protocol SuiteAn Overview of the Implementation
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
•Network Implementation
4.4 BSD supports 4 distinct communication protocol families
1. TCP/IP
2. XNS (Xerox Network Systems)
3. OSI protocols
4. Unix domain protocols
•The TCP/IP protocol suite allows computers of all sizes, from different computer vendor, running totally different operating systems, to communicate with each other.
Application Telnet, FTP, e-mail, etc.
Transport TCP, UDP
Network IP, ICMP, IGMP
Link Device driver and Interface card
•TCP/IP is normally considered to be a 4 layer system
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
•General organization of networking code in 4.4 BSD
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
•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.
mbuf structure, mbuff macros and definitionssys/mbuf.h
kern/uipc_mbuf.cmbuf.h functions
linux/include/linux/skbuff.h
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
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 structuresm_flags Description
M_BROADCAST
sent/receive as link level broadcast
m_type Description
MT_data Dynamic data allocation
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
•Remarks on mbuf
1. The size of the mbuf structure is always 128 bytes
2. 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)
3. The m_next pointer links together the mbuf forming a single packet into an mbuf chain
4. The m_next pointer links multiple packets together to form a queue of mbuf
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
Linked list of mbuf chains with head pointer
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
•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
i. A well-defined set of interface functionsii. A standard set of statistics and control flagsiii. A device-independent method of storing protocol addressi. A standard queueing method for outgoing packets
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
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
net/init_main.c system and interface initialisations
drivers/net/skeleton.c generic interface code
net/if.c generic interface code
drivers/net/loopback.c loopback device driver
net/if_loop.c loopback device driver
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
•Interface layer
•Ifnet struture
•Ifaddr struture
•sockaddr struture
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
•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.
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
ifnet description•Implementation information
List constructionCommon interface information (name, such as: eth0, sl0,...)
•Flags (if_flags specifies the operational state and
properties of the interface)If_flags Kernel
OnlyDescriptions
IFF_BROADCAST x The interface is for a broadcast network
IFF_MULTICAST x The interface supports multicasting
IFF_PROMISC The interface receives all network packets
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
ifnet description•Interface timer•BSD packet filter
Through BPF, a process can receive copies of packets transmitted or received by interface
•Hardware informationInterface characteristics (hardware address type supported by the interface – Ethernet , SLIP, loopback interface)mtu, metric, baudrate
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
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 Function
Description
if_init Initialize the inteface
if_output
Queue outgoing packets for transmission
if_start Initiate transmission of packets
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
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
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
if.hstruct ifaddr { struct ifaddr *ifa_next; /*next address for interface */ struct ifnet *ifa_ifp; /*back-pointer to interface */……………………………………………………………..…..};
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
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 structuresocket.h
struct sockaddr { u_char sa_len; /* total length */ u_char sa_family; /* address family*/.......................................................................};
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
sa_family Protocol
AF_INET Internet
AF_ISO, AF_OSI OSI
AF_UNIX Unix
AF_ROUTE Rpouting table
AF_LINK Data link
sa_family constants
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
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)
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
Arragement of ifnet structure within device-dependent structures
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
Ethernet Initialization•cpu_start (init_main.c)
the kernel locates any attached network devicesle,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
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
•Interface: Ethernet
File Description
net/if_ether.h Ethernet structures
net/if.h Ioctl command definitions
net/if_ethersubr.c
Generic Ethernet frames
dev/if_le.c Ethernet driver (LANCE)
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
if_le.cleintr 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
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
ether_input Function•ether_input function 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
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
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
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
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
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
•IP: Internet Protocol
File Description
net/route.h Route entries
netinet/ip.h IP Header
netinet/ip_input.c IP Processing
netinet/ip_output.c
IP output Processing
Netinet/in_cksum.c
Internet Checksum algorithm
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
IP datagram, including ip structure namesip structure - ip.h file
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
input processingipintr Function – ip_input.c
•verification of incoming packetsdequeueing packets from ipintrqverifies their contentsdamaged or erroneous packets are silently discardedIP version (ip_v = 4)IP checksumByte orderingPacket length
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
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.
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
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
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
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 protocolsIP header constructionPacket already including header (for a forward packet)
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
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 fragmentationThe final section of ip_output ensure that the IP header has a valid source address and the interface associated with the route
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
•TCP: Transmission Control Protocol
File Description
netinet/tcp.h tcphdr structure definition
netinet/tcp_input.c
tcp_input
netinet/tcp_output tcp_outputtcp_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
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
TCP Headertcp.h file
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
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
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
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 sendBuild MSS (maximum segment size) option Build window scale optionBuild timestamp optionCheck if options have overflowed segmentUpdate statisticsAllocate an mbuf for IP and TCP headersCopy data into mbuf
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
tcp_output descriptionSet PSH (push flag) flagUpdate statisticsGet mbuf for IP and TCP headersCopy IP and TCP header templates into mbufSet sequence number filed of segmentSet acknowledgment field of segmentSet header length if option presentDon´t advertise less than one full-size segment
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
tcp_output descriptionObserve upper limit for advertised window on thisconnectionDo not shrink windowSet urgent offsetSet retransmission timerPersist stateAdd trace record for socket debuggingSet IP length, TTL, and TOSPass datagram to IP
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
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.
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
TCP Input – tcp_input.c
Preliminary processingGet IP and TCP in first mbufVerify TCP checksumVerify TCP offset fieldGet headers plus option into first mbufProcess timestamp option quicklySave input flags and convert fields to host byte orderLocate Internet PCB (protocol control block)
BSD TCP/IP Protocol Suite – The Implementation
Agostinho L S [email protected]
Telecommunications and Multimedia Unit
Preliminary processingDrop segment and generate RSTSilently drop segmentUnscale advertised windowSave connection state and TCP/IP headers if socket debug option enabledCreate new socket if segment arrives for listening socketComputer window scale factorReset idle time and keep alive timerProcess TCP options if not in LISTEN state
TCP Input – tcp_input.c
Telecommunications and Multimedia Unit
Bibliography
1. Wright, G. R., Stevens, W. R.,"TCP/IP Illustrated – The Implementaion",Volume 2.,Addison-Wesley, 1995 .
2. Wright, G. R., Stevens, W. R.,"TCP/IP Illustrated – The Protocol",Volume 1.,Addison-Wesley, 1994 .
3. Rubini, A., “LINUX Device Drivers”, O´Reilly& Associates, Inc.,1998.
4. Rusling, David A., “The Linux Kernel”, LDP – www.linuxdoc.org