Download presentation
Presentation is loading. Please wait.
1
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 1 TCP/IP Stack Introduction: Looking Under the Hood! Shiv Kalyanaraman Rensselaer Polytechnic Institute shivkuma@ecse.rpi.edu http://www.ecse.rpi.edu/Homepages/shivkuma Google: “SHIV RPI”
2
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 2 Example program q 1. Create UDP datagram socket; fill in server address q 2. Send datagram to a server q 3. Read datagram returned by server
3
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 3 Example Program: UDP Datagram 1. 2. 3.
4
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 4 Organization of Networking Code Protocol Independent Layer
5
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 5 Descriptor Kernel Data Structures
6
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 6 Descriptors q Socket: is like other UNIX descriptors q Can read(), write(), dup(), fcntl(), close(); shared between parent and child after fork() q Socket descriptor file{} socket{} q Fileops{}: convenient place for socket operations q Doubly linked list of protocol control blocks (PCBs) q Sendto: Access PCBs in top-down manner q Receive: PCBs searched for port-number; then socket{} accessed through inp_socket
7
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 7 Kernel Data Structures
8
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 8 Memory Buffers (mbufs) q Used for passing socket address structs, data etc q 128-bytes, with 20 byte mbuf header q Mbuf chain with mbuf packet header q m_next: links mbufs within a packet q m_nextpkt: links multiple pkts (queue of mbufs) q 2048-byte clusters used if data > 208 bytes
9
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 9 Example: mbuf chain with data q 150 bytes of data divided into 2 mbufs: 100 + 50 bytes q Note: pkthdr fields (and mflags = M_PKTHDR) only in first mbuf
10
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 10 Mbufs: header and data q Protocol (IP +UDP) headers prepended in another mbuf (avoid copies in future)! q Pkthdr fields moved to first mbuf in this new chain. q Headers are in the end of the first mbuf: allows space for ethernet header prepending q M_data points to appropriate location
11
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 11 TCP/IP Stack
12
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 12 Output Functions at Various Levels q UDP output routine fills in UDP header and as much of the IP header as possible (eg: IP chksum not filled; but destination address & UDP checksum filled) q 2 copy passes on 150 bytes of data so far: q A) to copy from process to kernel mbuf; q B) to compute UDP checksum q IP fills in remaining fields, determines outgoing interface, fragments IP datagram if necessary, and calls the interface output function q Ethernet output: converts IP addr to Ethernet address (ARP); prepend 14-byte Enet header; add mbuf chain to output queue for interface; “start” interface if not busy. q Interface copies data to transmit buffer (3 rd copy pass), initiates output & release mbuf chain
13
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 13 Input processing q Recvfrom(): input is asynchronous:interrupt driven & not system-call driven q Device interrupt => ethernet device driver scheduled q Ethernet driver reads data into an mbuf chain (in our case 54 bytes received: 26 byte payload, 28 bytes of UDP/IP headers) q Pkthdr.rcvif field in mbuf points to interface structure (used only for input) q Device driver passes mbuf to a general Ethernet input routine which does de-multiplexing based upon the type field. q Add to IP queue, and schedule a software interrupt for IP q IP input triggered by software interrupt. q IP processes each datagram in its input queue: verifies chksum, processes IP options, sanity checks. q Either forward pkt (if router), else demux it to the appropriate protocol (UDP) q UDP sanity checks, decides whether a process should receive dgram. q Goes thru UDP PCBs looking for inp_lport (local port) & append two mbufs to socket receive queue
14
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 14 Mbufs in Socket Receive Queue q 1 st mbuf: MT_SONAME q The length fields refer to the data only (just a quick pointer manipulation based upon fig 1.10)
15
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 15 Functions to block interrupts
16
Shivkumar Kalyanaraman Rensselaer Polytechnic Institute 16 Interrupt Priority Levels Device interrupt -> interface layer executes … Software interrupt -> protocol layer executes… then the socket code executes…
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.