0%

Book Description

TCP/IP Illustrated, an ongoing series covering the many facets of TCP/IP, brings a highly-effective visual approach to learning about this networking protocol suite.

TCP/IP Illustrated, Volume 2 contains a thorough explanation of how TCP/IP protocols are implemented. There isn't a more practical or up-to-date bookothis volume is the only one to cover the de facto standard implementation from the 4.4BSD-Lite release, the foundation for TCP/IP implementations run daily on hundreds of thousands of systems worldwide.

Combining 500 illustrations with 15,000 lines of real, working code, TCP/IP Illustrated, Volume 2 uses a teach-by-example approach to help you master TCP/IP implementation. You will learn about such topics as the relationship between the sockets API and the protocol suite, and the differences between a host implementation and a router. In addition, the book covers the newest features of the 4.4BSD-Lite release, including multicasting, long fat pipe support, window scale, timestamp options, and protection against wrapped sequence numbers, and many other topics.

Comprehensive in scope, based on a working standard, and thoroughly illustrated, this book is an indispensable resource for anyone working with TCP/IP.

Table of Contents

  1. TCP/IP Illustrated, Volume 2
    1. Addison-Wesley Professional Computing Series
    2. Preface
      1. Introduction
      2. Organization of the Book
      3. Intended Audience
      4. Source Code Copyright
    3. Acknowledgments
    4. Structure Definitions
    5. Function and Macro Definitions
    6. 1. Introduction
      1. 1.1. Introduction
        1. 1.1. Introduction
        2. 1.2. Source Code Presentation
          1. Set congestion window to one segment
          2. Typographical Conventions
        3. 1.3. History
        4. 1.4. Application Programming Interfaces
        5. 1.5. Example Program
          1. Create a datagram socket
          2. Fill in sockaddr_in structure with server’s address
          3. Send datagram to server
          4. Read datagram returned by server
        6. 1.6. System Calls and Library Functions
        7. 1.7. Network Implementation Overview
        8. 1.8. Descriptors
        9. 1.9. Mbufs (Memory Buffers) and Output Processing
          1. Mbuf Containing Socket Address Structure
          2. Mbuf Containing Data
          3. Prepending IP and UDP Headers
          4. IP Output
          5. Ethernet Output
          6. Summary of UDP Output
        10. 1.10. Input Processing
          1. Ethernet Input
          2. IP Input
          3. UDP Input
          4. Process Input
        11. 1.11. Network Implementation Overview Revisited
        12. 1.12. Interrupt Levels and Concurrency
        13. 1.13. Source Code Organization
        14. 1.14. Test Network
      2. 1.15. Summary
        1. 1.15. Summary
        2. Exercises
    7. 2. Mbufs: Memory Buffers
      1. 2.1. Introduction
        1. 2.1. Introduction
        2. 2.2. Code Introduction
          1. Global Variables
          2. Statistics
          3. Kernel Statistics
        3. 2.3. Mbuf Definitions
        4. 2.4. mbuf Structure
        5. 2.5. Simple Mbuf Macros and Functions
          1. m_get Function
          2. MGET Macro
          3. m_retry Function
          4. Mbuf Locking
        6. 2.6. m_devget and m_pullup Functions
          1. m_devget Function
          2. mtod and dtom Macros
          3. m_pullup Function and Contiguous Protocol Headers
          4. m_pullup and IP Fragmentation and Reassembly
          5. Avoidance of m_pullup by TCP Reassembly
          6. Summary of m_pullup Usage
        7. 2.7. Summary of Mbuf Macros and Functions
        8. 2.8. Summary of Net/3 Networking Data Structures
        9. 2.9. m_copy and Cluster Reference Counts
        10. 2.10. Alternatives
      2. 2.11. Summary
        1. 2.11. Summary
        2. Exercises
    8. 3. Interface Layer
      1. 3.1. Introduction
        1. 3.1. Introduction
        2. 3.2. Code Introduction
          1. Global Variables
          2. SNMP Variables
        3. 3.3. ifnet Structure
          1. Common interface information
          2. Interface timer
          3. BSD Packet Filter
          4. Interface characteristics
          5. Interface statistics
          6. Change timestamp
          7. Interface functions
        4. 3.4. ifaddr Structure
        5. 3.5. sockaddr Structure
          1. sockaddr structure
          2. osockaddr structure
        6. 3.6. ifnet and ifaddr Specialization
        7. 3.7. Network Initialization Overview
        8. 3.8. Ethernet Initialization
          1. le_softc structure
          2. arpcom structure
          3. Copy the hardware address from the device
          4. Initialize the ifnet structure
        9. 3.9. SLIP Initialization
        10. 3.10. Loopback Initialization
        11. 3.11. if_attach Function
          1. Resize ifnet_addrs array if necessary
          2. Create link-level name and compute size of link-level address
          3. The address
          4. The mask
          5. ether_ifattach function
        12. 3.12. ifinit Function
      2. 3.13. Summary
        1. 3.13. Summary
        2. Exercises
    9. 4. Interfaces: Ethernet
      1. 4.1. Introduction
        1. 4.1. Introduction
        2. 4.2. Code Introduction
          1. Global Variables
          2. Statistics
          3. SNMP Variables
        3. 4.3. Ethernet Interface
          1. leintr Function
          2. leread Function
          3. ether_input Function
          4. Broadcast and multicast recognition
          5. Link-level demultiplexing
          6. Queue the packet
          7. ether_output Function
          8. Host route
          9. Gateway route
          10. Avoid ARP flooding
          11. IP output
          12. Explicit Ethernet output
          13. Unrecognized address families
          14. Ethernet header
          15. lestart Function
          16. Interface must be initialized
          17. Dequeue frame from output queue
          18. Transmit frame and pass to BPF
          19. Repeat if device is ready for more frames
          20. Mark device as busy
        4. 4.4. ioctl System Call
          1. ifioctl Function
          2. ifconf Function
          3. Example
          4. Generic Interface ioctl commands
          5. SIOCGIFFLAGS and SIOCGIFMETRIC
          6. SIOCSIFFLAGS
          7. Ignore IFF_CANTCHANGE flags
          8. SIOCSIFMETRIC
          9. if_down and if_up Functions
          10. Ethernet, SLIP, and Loopback
      2. 4.5. Summary
        1. 4.5. Summary
        2. Exercises
    10. 5. Interfaces: SLIP and Loopback
      1. 5.1. Introduction
        1. 5.1. Introduction
        2. 5.2. Code Introduction
          1. Global Variables
          2. Statistics
        3. 5.3. SLIP Interface
          1. The SLIP Line Discipline: SLIPDISC
          2. SLIP Initialization: slopen and slinit
          3. SLIP Input Processing: slinput
          4. SLIP Output Processing: sloutput
          5. slstart Function
          6. SLIP Packet Loss
          7. SLIP Performance Considerations
          8. slclose Function
          9. sltioctl Function
        4. 5.4. Loopback Interface
      2. 5.5. Summary
        1. 5.5. Summary
        2. Exercises
    11. 6. IP Addressing
      1. 6.1. Introduction
        1. 6.1. Introduction
          1. IP Addresses
          2. Typographical Conventions for IP Addresses
          3. Hosts and Routers
        2. 6.2. Code Introduction
          1. Global Variables
        3. 6.3. Interface and Address Summary
        4. 6.4. sockaddr_in Structure
        5. 6.5. in_ifaddr Structure
        6. 6.6. Address Assignment
          1. ifioctl Function
          2. in_control Function
          3. Preconditions: SIOCSIFADDR, SIOCSIFNETMASK, and SIOCSIFDSTADDR
          4. Superuser only
          5. Allocate structure
          6. Initialize structure
          7. Address Assignment: SIOCSIFADDR
          8. in_ifinit Function
          9. Assign address and notify hardware
          10. Ethernet configuration
          11. Discard previous routes
          12. Construct network mask and default subnetmask
          13. Construct network and subnetwork numbers
          14. Establish route for host or network
          15. Join all-hosts group
          16. Network Mask Assignment: SIOCSIFNETMASK
          17. Destination Address Assignment: SIOCSIFDSTADDR
          18. Retrieving Interface Information
          19. Multiple IP Addresses per Interface
          20. Additional IP Addresses: SIOCAIFADDR
          21. Deleting IP Addresses: SIOCDIFADDR
        7. 6.7. Interface ioctl Processing
          1. leioctl Function
          2. Unrecognized commands
          3. slioctl Function
          4. Unrecognized commands
          5. loioctl Function
          6. Unrecognized commands
        8. 6.8. Internet Utility Functions
        9. 6.9. ifnet Utility Functions
      2. 6.10. Summary
        1. 6.10. Summary
        2. Exercises
    12. 7. Domains and Protocols
      1. 7.1. Introduction
        1. 7.1. Introduction
        2. 7.2. Code Introduction
          1. Global Variables
          2. Statistics
        3. 7.3. domain Structure
        4. 7.4. protosw Structure
        5. 7.5. IP domain and protosw Structures
          1. domaininit Function
        6. 7.6. pffindproto and pffindtype Functions
          1. Example
        7. 7.7. pfctlinput Function
        8. 7.8. IP Initialization
          1. Internet Transport Demultiplexing
          2. ip_init Function
        9. 7.9. sysctl System Call
          1. net_sysctl Function
      2. 7.10. Summary
        1. 7.10. Summary
        2. Exercises
    13. 8. IP: Internet Protocol
      1. 8.1. Introduction
        1. 8.1. Introduction
        2. 8.2. Code Introduction
          1. Global Variables
          2. Statistics
          3. SNMP Variables
        3. 8.3. IP Packets
        4. 8.4. Input Processing: ipintr Function
          1. ipintr Overview
          2. Verification
          3. IP version
          4. IP checksum
          5. Byte ordering
          6. Packet length
          7. To Forward or Not To Forward?
          8. Option processing
          9. Final destination?
          10. Forwarding
          11. Reassembly and Demultiplexing
          12. Transport demultiplexing
        5. 8.5. Forwarding: ip_forward Function
          1. Is packet eligible for forwarding?
          2. Decrement TTL
          3. Locate next hop
          4. Redirect Messages
          5. Leaving on receiving interface?
          6. Send redirect?
          7. Select appropriate router
          8. Forward packet
          9. Send ICMP error?
        6. 8.6. Output Processing: ip_output Function
          1. Header Initialization
          2. Construct IP header
          3. Packet already includes header
          4. Route Selection
          5. Verify cached route
          6. Bypass routing
          7. Locate route
          8. Source Address Selection and Fragmentation
          9. Select source address
          10. Send packet
          11. Fragment packet
          12. Cleanup
        7. 8.7. Internet Checksum: in_cksum Function
          1. Loop unrolling
          2. More Optimizations
        8. 8.8. setsockopt and getsockopt System Calls
          1. PRCO_SETOPT Processing
          2. PRCO_GETOPT Processing
        9. 8.9. ip_sysctl Function
      2. 8.10. Summary
        1. 8.10. Summary
        2. Exercises
    14. 9. IP Option Processing
      1. 9.1. Introduction
        1. 9.1. Introduction
        2. 9.2. Code Introduction
          1. Global Variables
          2. Statistics
        3. 9.3. Option Format
        4. 9.4. ip_dooptions Function
          1. EOL and NOP processing
          2. Source route forwarding
          3. Error handling
        5. 9.5. Record Route Option
          1. Record address
          2. ip_rtaddr Function
          3. Check IP forwarding cache
          4. Locate route
          5. Return route information
        6. 9.6. Source and Record Route Options
          1. End of source route
          2. Update packet for next hop
          3. Multicast destinations
          4. save_rte Function
          5. ip_srcroute Function
          6. Allocate mbuf for source route
        7. 9.7. Timestamp Option
          1. Timestamp only
          2. Timestamp and address
          3. Timestamp at prespecified addresses
          4. Insert timestamp
          5. iptime Function
        8. 9.8. ip_insertoptions Function
        9. 9.9. ip_pcbopts Function
          1. Discard previous options
          2. Make room for first-hop destination
          3. Scan option list
          4. Rearrange LSRR or SSRR option
          5. Cleanup
        10. 9.10. Limitations
      2. 9.11. Summary
        1. 9.11. Summary
        2. Exercises
    15. 10. IP Fragmentation and Reassembly
      1. 10.1. Introduction
        1. 10.1. Introduction
        2. 10.2. Code Introduction
          1. Global Variables
          2. Statistics
        3. 10.3. Fragmentation
        4. 10.4. ip_optcopy Function
        5. 10.5. Reassembly
        6. 10.6. ip_reass Function
          1. Create reassembly list
          2. Reassembly timeout
          3. Datagram identifiers
          4. Reconstruct datagram header
          5. Compute packet length
        7. 10.7. ip_slowtimo Function
          1. ip_drain Function
      2. 10.8. Summary
        1. 10.8. Summary
        2. Exercises
    16. 11. ICMP: Internet Control Message Protocol
      1. 11.1. Introduction
        1. 11.1. Introduction
        2. 11.2. Code Introduction
          1. Global Variables
          2. Statistics
          3. SNMP Variables
        3. 11.3. icmp Structure
        4. 11.4. ICMP protosw Structure
        5. 11.5. Input Processing: icmp_input Function
          1. Static structures
          2. Validate message
          3. Verify checksum
          4. Verify type
          5. Raw ICMP input
        6. 11.6. Error Processing
        7. 11.7. Request Processing
          1. Echo Query: ICMP_ECHO and ICMP_ECHOREPLY
          2. Timestamp Query: ICMP_TSTAMP and ICMP_TSTAMPREPLY
          3. Address Mask Query: ICMP_MASKREQ and ICMP_MASKREPLY
          4. Select subnet mask
          5. Convert to reply
          6. Select destination address
          7. Information Query: ICMP_IREQ and ICMP_IREQREPLY
          8. Router Discovery: icmp_routeradvert and icmp_routersolicit
        8. 11.8. Redirect Processing
          1. Validate
          2. Update routes
        9. 11.9. Reply Processing
        10. 11.10. Output Processing
        11. 11.11. icmp_error Function
        12. 11.12. icmp_reflect Function
          1. Set destination address
          2. Select source address
          3. Get reversed source route
          4. Add record route and timestamp options
          5. Remove original options
          6. Send message and cleanup
        13. 11.13. icmp_send Function
        14. 11.14. icmp_sysctl Function
      2. 11.15. Summary
        1. 11.15. Summary
        2. Exercises
    17. 12. IP Multicasting
      1. 12.1. Introduction
        1. 12.1. Introduction
          1. Well-Known IP Multicast Groups
        2. 12.2. Code Introduction
          1. Global Variables
          2. Statistics
        3. 12.3. Ethernet Multicast Addresses
          1. IP to Ethernet Multicast Address Mapping
          2. IP to Ethernet multicast mapping
        4. 12.4. ether_multi Structure
          1. Ethernet multicast addresses
          2. Ethernet multicast lookups
        5. 12.5. Ethernet Multicast Reception
        6. 12.6. in_multi Structure
          1. IP multicast addresses
          2. IP multicast lookups
        7. 12.7. ip_moptions Structure
          1. Multicast options
        8. 12.8. Multicast Socket Options
        9. 12.9. Multicast TTL Values
          1. The MBONE
          2. Expanding-Ring Search
        10. 12.10. ip_setmoptions Function
          1. Construct the defaults
          2. Process options
          3. Discard structure if defaults are OK
          4. Selecting an Explicit Multicast Interface: IP_MULTICAST_IF
          5. Validation
          6. Select the default interface
          7. Selecting an Explicit Multicast TTL: IP_MULTICAST_TTL
          8. Validate and select the default TTL
          9. Selecting Multicast Loopbacks: IP_MULTICAST_LOOP
          10. Validate and select the loopback policy
        11. 12.11. Joining an IP Multicast Group
          1. Validation
          2. Locate the interface
          3. Already a member?
          4. Join the group
          5. in_addmulti Function
          6. Already a member
          7. Update the in_multi list
          8. Update the interface and announce the change
          9. slioctl and loioctl Functions: SIOCADDMULTI and SIOCDELMULTI
          10. leioctl Function: SIOCADDMULTI and SIOCDELMULTI
          11. ether_addmulti Function
          12. Initialize address range
          13. Already receiving
          14. Update ether_multi list
        12. 12.12. Leaving an IP Multicast Group
          1. Validation
          2. Delete membership references
          3. in_delmulti Function
          4. Update in_multi structure
          5. ether_delmulti Function
          6. Locate ether_multi structure
          7. Delete ether_multi structure
        13. 12.13. ip_getmoptions Function
          1. Copy the option data and return
        14. 12.14. Multicast Input Processing: ipintr Function
          1. Forward packets if configured as multicast router
        15. 12.15. Multicast Output Processing: ip_output Function
          1. Establish defaults
          2. Select source address
          3. Loopback or not?
          4. Forward or not?
          5. Transmit or not?
          6. Send packet
          7. ip_mloopback Function
          8. Duplicate and queue packet
        16. 12.16. Performance Considerations
      2. 12.17. Summary
        1. 12.17. Summary
        2. Exercises
    18. 13. IGMP: Internet Group Management Protocol
      1. 13.1. Introduction
        1. 13.1. Introduction
        2. 13.2. Code Introduction
          1. Global Variables
          2. Statistics
          3. SNMP Variables
        3. 13.3. igmp Structure
        4. 13.4. IGMP protosw Structure
        5. 13.5. Joining a Group: igmp_joingroup Function
        6. 13.6. igmp_fasttimo Function
          1. igmp_sendreport Function
        7. 13.7. Input Processing: igmp_input Function
          1. Validate IGMP message
          2. Pass IGMP messages to raw IP
          3. Membership Query: IGMP_HOST_MEMBERSHIP_QUERY
          4. Membership Report: IGMP_HOST_MEMBERSHIP_REPORT
        8. 13.8. Leaving a Group: igmp_leavegroup Function
      2. 13.9. Summary
        1. 13.9. Summary
        2. Exercises
    19. 14. IP Multicast Routing
      1. 14.1. Introduction
        1. 14.1. Introduction
        2. 14.2. Code Introduction
          1. Global Variables
          2. Statistics
          3. SNMP Variables
        3. 14.3. Multicast Output Processing Revisited
        4. 14.4. mrouted Daemon
        5. 14.5. Virtual Interfaces
          1. Virtual Interface Table
          2. add_vif Function
          3. Validate index
          4. Locate physical interface
          5. Configure tunnel interface
          6. Configure physical interface
          7. Save multicast information
          8. del_vif Function
          9. Validate index
          10. Delete interface
          11. Adjust interface count
        6. 14.6. IGMP Revisited
          1. add_lgrp Function
          2. Validate add request
          3. If needed, expand group array
          4. Add new group
          5. del_lgrp Function
          6. Validate interface index
          7. Update lookup cache
          8. Delete group
          9. grplst_member Function
          10. Check the cache
          11. Search the membership array
        7. 14.7. Multicast Routing
          1. Multicast Routing Table
          2. del_mrt Function
          3. Find route entry
          4. Delete route entry
          5. add_mrt Function
          6. Update existing route
          7. Allocate new route
          8. mrtfind Function
          9. Check route lookup cache
          10. Check the hash table
        8. 14.8. Multicast Forwarding: ip_mforward Function
          1. Arrival on physical interface
          2. Arrival on a tunnel
          3. Delete tunnel options
          4. Expired TTL or local multicast
          5. No route available
          6. Arrived on unexpected interface
          7. phyint_send Function
          8. tunnel_send Function
          9. Will the tunnel options fit?
          10. Duplicate the datagram and allocate mbuf for new header and tunnel options
          11. Modify IP header
          12. Construct tunnel options
          13. Send the tunneled datagram
        9. 14.9. Cleanup: ip_mrouter_done Function
      2. 14.10. Summary
        1. 14.10. Summary
        2. Exercises
    20. 15. Socket Layer
      1. 15.1. Introduction
        1. 15.1. Introduction
          1. splnet Processing
        2. 15.2. Code Introduction
          1. Global Variables
        3. 15.3. socket Structure
          1. SS_NBIO and SS_ASYNC Flags
        4. 15.4. System Calls
          1. Example
          2. System Call Summary
        5. 15.5. Processes, Descriptors, and Sockets
        6. 15.6. socket System Call
          1. socreate Function
          2. Find protocol switch table
          3. Allocate and initialize socket structure
          4. PRU_ATTACH request
          5. Cleanup and return
          6. Superuser Privileges
        7. 15.7. getsock and sockargs Functions
        8. 15.8. bind System Call
          1. sobind Function
        9. 15.9. listen System Call
          1. solisten Function
        10. 15.10. tsleep and wakeup Functions
          1. Example
        11. 15.11. accept System Call
          1. Validate arguments
          2. Wait for a connection
          3. Asynchronous errors
          4. Associate socket with descriptor
          5. Protocol processing
          6. soaccept Function
        12. 15.12. sonewconn and soisconnected Functions
          1. Limit incoming connections
          2. Allocate new socket
          3. Queue connection
          4. Protocol processing
          5. Wakeup processes
          6. Queue incomplete connections
          7. Wakeup processes waiting for new connection
        13. 15.13. connect System call
          1. Start connection processing
          2. Wait for connection establishment
          3. soconnect Function
          4. Breaking a Connectionless Association
        14. 15.14. shutdown System Call
          1. soshutdown and sorflush
          2. Release control mbufs
        15. 15.15. close System Call
          1. soo_close Function
          2. soclose Function
          3. Discard pending connections
          4. Break established connection or association
          5. Release data structures
          6. Return if socket still in use
          7. Remove from connection queues
          8. Discard send and receive queues
      2. 15.16. Summary
        1. 15.16. Summary
        2. Exercises
    21. 16. Socket I/O
      1. 16.1. Introduction
        1. 16.1. Introduction
        2. 16.2. Code Introduction
          1. Global Variables
        3. 16.3. Socket Buffers
          1. Socket Macros and Functions
        4. 16.4. write, writev, sendto, and sendmsg System Calls
          1. Example
        5. 16.5. sendmsg System Call
          1. Copy iov array
          2. sendit and cleanup
        6. 16.6. sendit Function
          1. uiomove Function
          2. Example
          3. sendit Code
          4. Initialize auio
          5. Copy address and control information from the process
          6. Send data and cleanup
        7. 16.7. sosend Function
          1. Reliable Protocol Buffering
          2. Unreliable Protocol Buffering
          3. sosend Code
          4. Lock send buffer
          5. Check for space
          6. Use data from top
          7. Copy data from process
          8. Pass data to the protocol
          9. Cleanup
          10. Compute transfer size and semantics
          11. If requested, disable routing
          12. Compute available space
          13. Enforce message size limit
          14. Wait for more space?
          15. Wait for space
          16. Allocate packet header or standard mbuf
          17. If possible, use a cluster
          18. Prepare the mbuf
          19. Get data from the process
          20. Fill another buffer?
          21. sosend Summary
          22. Performance Considerations
        8. 16.8. read, readv, recvfrom, and recvmsg System Calls
        9. 16.9. recvmsg System Call
          1. Copy iov array
          2. recvit and cleanup
        10. 16.10. recvit Function
          1. Call soreceive
          2. Copy address and control information to the process
          3. Cleanup
        11. 16.11. soreceive Function
          1. Out-of-Band Data
          2. Example
          3. Other Receive Options
          4. Receive Buffer Organization: Message Boundaries
          5. Receive Buffer Organization: No Message Boundaries
          6. Control Information and Out-of-band Data
        12. 16.12. soreceive Code
          1. If necessary, wait for data
          2. Process address and control information
          3. Setup data transfer
          4. Mbuf data transfer loop
          5. Cleanup
          6. Receive OOB data
          7. Connection confirmation
          8. Can the call be satisfied now?
          9. Wait for more data?
          10. Yes, wait for more data
          11. dontblock
          12. Return address information
          13. Return control information
          14. Prepare to transfer data
          15. Check for transition between OOB and regular data
          16. Update OOB mark
          17. Finished with mbuf?
          18. More data to process
          19. Update OOB mark
          20. End of logical record
          21. MSG_WAITALL
          22. Error or no more data will arrive
          23. Wait for data to arrive
          24. Synchronize m and nextrecord with receive buffer
          25. Process next mbuf
          26. Truncated message
          27. End of record processing
          28. Nothing transferred
          29. Analysis
        13. 16.13. select System Call
          1. Validation and setup
          2. Copy file descriptor sets from process
          3. Setup timeout value
          4. Scan file descriptors
          5. Error or some descriptors are ready
          6. Timeout expired?
          7. Status changed during selscan
          8. Wait for buffer changes
          9. Ready to return
          10. selscan Function
          11. Locate descriptors to be monitored
          12. Poll descriptor
          13. Descriptor is ready
          14. soo_select Function
          15. Is socket readable?
          16. Is socket writeable?
          17. Are there any exceptional conditions pending?
          18. selrecord Function
          19. Already selecting on this descriptor
          20. Select collision with another process?
          21. No collision
          22. selwakeup Function
          23. Wake all processes during a collision
      2. 16.14. Summary
        1. 16.14. Summary
        2. Exercises
    22. 17. Socket Options
      1. 17.1. Introduction
        1. 17.1. Introduction
        2. 17.2. Code Introduction
          1. Global Variables and Statistics
        3. 17.3. setsockopt System Call
          1. sosetopt Function
        4. 17.4. getsockopt System Call
          1. sogetopt Function
        5. 17.5. fcntl and ioctl System Calls
          1. fcntl Code
          2. ioctl Code
        6. 17.6. getsockname System Call
        7. 17.7. getpeername System Call
      2. 17.8. Summary
        1. 17.8. Summary
        2. Exercises
    23. 18. Radix Tree Routing Tables
      1. 18.1. Introduction
        1. 18.1. Introduction
        2. 18.2. Routing Table Structure
          1. Example—Host Match
          2. Example—Host Match
          3. Example—Network Match
          4. Example—Default Match
          5. Example—Network Match with Backtracking
          6. Example—Backtracking Multiple Levels
          7. Example—Host Match with Backtracking and Cloning
          8. The Big Picture
        3. 18.3. Routing Sockets
        4. 18.4. Code Introduction
          1. Global Variables
          2. Statistics
          3. SNMP Variables
        5. 18.5. Radix Node Data Structures
        6. 18.6. Routing Structures
        7. 18.7. Initialization: route_init and rtable_init Functions
        8. 18.8. Initialization: rn_init and rn_inithead Functions
          1. Determine max_keylen
          2. Allocate and initialize rn_zeros, rn_ones, and maskedKey
          3. Initialize tree of masks
        9. 18.9. Duplicate Keys and Mask Lists
        10. 18.10. rn_match Function
          1. Go down the tree to the corresponding leaf
          2. Check for exact match
          3. Explicit check for default
        11. 18.11. rn_search Function
      2. 18.12. Summary
        1. 18.12. Summary
        2. Exercises
    24. 19. Routing Requests and Routing Messages
      1. 19.1. Introduction
        1. 19.1. Introduction
        2. 19.2. rtalloc and rtalloc1 Functions
          1. Call rn_match
          2. Search fails
          3. Create clone entries
          4. Clone creation fails
          5. Check for external resolution
          6. Increment reference count for normal successful search
        3. 19.3. RTFREE Macro and rtfree Function
          1. Release interface reference
          2. Release routing memory
          3. Routing Table Reference Counts
        4. 19.4. rtrequest Function
          1. Delete from routing tree
          2. Remove reference to gateway routing table entry
          3. Call interface request function
          4. Return pointer or release reference
          5. Locate corresponding interface
          6. Allocate memory for routing table entry
          7. Allocate and copy gateway address
          8. Copy destination address
          9. Add entry to routing tree
          10. Store interface pointers
          11. Copy metrics for newly cloned route
          12. Call interface request function
          13. Return pointer and increment reference count
          14. Example: Cloned Routes with Network Masks
        5. 19.5. rt_setgate Function
          1. Set lengths from socket address structures
          2. Allocate memory
          3. Use memory already allocated for key and gateway
          4. Copy new gateway
          5. Copy key from old memory to new memory
          6. Release gateway routing pointer
          7. Locate and store new gateway routing pointer
        6. 19.6. rtinit Function
          1. Get destination address for route
          2. Mask network address with network mask
          3. Search for routing table entry
          4. Process request
          5. Generate routing message on successful delete
          6. Successful add
          7. Incorrect interface
          8. Generate routing message
        7. 19.7. rtredirect Function
          1. New gateway must be directly connected
          2. Locate routing table entry for destination and validate redirect
          3. Must create a new route
          4. Create new host route
          5. Create route
          6. Modify existing host route
          7. Ignore if destination is directly connected
          8. Return pointer and increment statistic
          9. Generate routing message
        8. 19.8. Routing Message Structures
        9. 19.9. rt_missmsg Function
          1. Build message in mbuf chain
          2. Finish building message
          3. Set protocol of message, call raw_input
        10. 19.10. rt_ifmsg Function
          1. Build message in mbuf chain
          2. Finish building message
          3. Set protocol of message, call raw_input
        11. 19.11. rt_newaddrmsg Function
          1. Generate two routing messages
          2. Generate message with up to four addresses
          3. Finish building message
          4. Build message
          5. Set protocol of message, call raw_input
        12. 19.12. rt_msg1 Function
          1. Get mbuf and determine fixed size of message
          2. Verify structure fits in mbuf
          3. Initialize mbuf packet header and zero structure
          4. Copy socket address structures into mbuf chain
          5. Store length, version, and type
        13. 19.13. rt_msg2 Function
          1. Determine size of structure
          2. Copy socket address structures
          3. Check if data to be stored
          4. Allocate buffer first time or if message length increases
          5. Go around again and store result
          6. Store length, version, and type
        14. 19.14. sysctl_rtable Function
          1. Validate arguments
          2. Initialize walkarg structure
          3. Dump routing table
          4. Return interface list
          5. Release buffer
          6. Update w_needed
          7. Return actual size of message
          8. Return estimated size of message
        15. 19.15. sysctl_dumpentry Function
          1. Check flags of routing table entry
          2. Form routing message
          3. Copy message back to process
        16. 19.16. sysctl_iflist Function
          1. Check interface index
          2. Build routing message
          3. Copy message back to process
          4. Iterate through address structures, check address family
          5. Build routing message
          6. Copy message back to process
      2. 19.17. Summary
        1. 19.17. Summary
        2. Exercises
    25. 20. Routing Sockets
      1. 20.1. Introduction
        1. 20.1. Introduction
        2. 20.2. routedomain and protosw Structures
        3. 20.3. Routing Control Blocks
        4. 20.4. raw_init Function
        5. 20.5. route_output Function
          1. Check mbuf for validity
          2. Allocate buffer
          3. Check version number
          4. Destination address required
          5. Handle optional genmask
          6. Locate existing entry
          7. Do not allow network match
          8. Use network mask to find correct entry
          9. Return destination, gateway, and masks
          10. Return interface information
          11. Construct reply
          12. Change gateway
          13. Locate new interface
          14. Check if interface changed
          15. Update metrics
          16. Call interface request function
          17. Store clone generation mask
          18. Update bitmask of locked metrics
          19. Return error or OK
          20. Release held route
          21. No process to receive message
          22. Other listeners but no loopback copy
          23. Convert buffer into mbuf chain
          24. Avoid loopback copy
          25. Set address family of routing message
        6. 20.6. rt_xaddrs Function
        7. 20.7. rt_setmetrics Function
        8. 20.8. raw_input Function
          1. Compare address family and protocol
          2. Compare local and foreign addresses
          3. Append message to socket receive buffer
        9. 20.9. route_usrreq Function
          1. PRU_ATTACH: allocate control block
          2. PRU_DETACH: decrement counters
          3. Process request
          4. Increment counters
          5. Connect socket
          6. Enable SO_USELOOPBACK by default
        10. 20.10. raw_usrreq Function
          1. PRU_CONTROL requests invalid
          2. Control information invalid
          3. Socket must have a control block
        11. 20.11. raw_attach, raw_detach, and raw_disconnect Functions
      2. 20.12. Summary
        1. 20.12. Summary
        2. Exercises
    26. 21. ARP: Address Resolution Protocol
      1. 21.1. Introduction
        1. 21.1. Introduction
        2. 21.2. ARP and the Routing Table
        3. 21.3. Code Introduction
          1. Global Variables
          2. Statistics
          3. SNMP Variables
        4. 21.4. ARP Structures
        5. 21.5. arpwhohas Function
        6. 21.6. arprequest Function
          1. Allocate and initialize mbuf
          2. Initialize pointers
          3. Fill in Ethernet header
          4. Fill in ARP fields
          5. Fill in sockaddr and call interface output function
        7. 21.7. arpintr Function
        8. 21.8. in_arpinput Function
          1. Look for matching interface and IP address
          2. Validate sender’s hardware address
          3. Check sender’s IP address
          4. Search routing table for match with sender’s IP address
          5. Update existing entry or fill in new entry
          6. Check if sender’s hardware addresses changed
          7. Record sender’s hardware address
          8. Update newly resolved ARP entry
          9. Finished with ARP reply packets
          10. This host is the target
          11. Check if this host is a proxy server for target
          12. Form proxy reply
          13. Complete construction of ARP reply packet
          14. Fill in sockaddr with Ethernet header
        9. 21.9. ARP Timer Functions
          1. arptimer Function
          2. Set next timeout
          3. Check all ARP entries
          4. arptfree Function
          5. Invalidate (don’t delete) entries in use
          6. Delete unreferenced entries
        10. 21.10. arpresolve Function
          1. Handle broadcast and multicast destinations
          2. Get pointer to llinfo_arp structure
          3. Check ARP entry for validity
          4. Hold only most recent IP datagram
          5. Send ARP request but avoid ARP flooding
        11. 21.11. arplookup Function
          1. Initialize sockaddr_inarp to look up
          2. Look up entry in routing table
          3. Decrement routing table reference count
        12. 21.12. Proxy ARP
        13. 21.13. arp_rtrequest Function
          1. Initialize ARP timeout function
          2. Ignore indirect routes
          3. RTM_ADD command
          4. Backward compatibility
          5. Initialize entry for network route to interface
          6. Send gratuitous ARP request
          7. Verify sockaddr_dl Structure
          8. Handle route changes
          9. Initialize llinfo_arp structure
          10. Handle local host specially
          11. Make entry permanent and set Ethernet address
          12. Set interface pointer to loopback interface
          13. Verify la pointer
          14. Delete llinfo_arp structure
        14. 21.14. ARP and Multicasting
      2. 21.15. Summary
        1. 21.15. Summary
        2. Exercises
    27. 22. Protocol Control Blocks
      1. 22.1. Introduction
        1. 22.1. Introduction
        2. 22.2. Code Introduction
          1. Global Variables
          2. Statistics
        3. 22.3. inpcb Structure
        4. 22.4. in_pcballoc and in_pcbdetach Functions
          1. Allocate PCB and initialize to zero
          2. Link structures together
        5. 22.5. Binding, Connecting, and Demultiplexing
          1. Binding of Local IP Address and Port Number
          2. Connecting a UDP Socket
          3. Demultiplexing of Received IP Datagrams by TCP
          4. Demultiplexing of Received IP Datagrams by UDP
        6. 22.6. in_pcblookup Function
          1. Compare local port number
          2. Compare local address
          3. Compare foreign address and foreign port number
          4. Check if wildcard match allowed
          5. Remember best match, return if exact match found
          6. Example—Demultiplexing of Received TCP Segment
        7. 22.7. in_pcbbind Function
          1. so_reuseaddr Examples
          2. SO_REUSEPORT Socket Option
        8. 22.8. in_pcbconnect Function
          1. Validate argument
          2. Handle connection to 0.0.0.0 and 255.255.255.255 specially
          3. Release route if no longer valid
          4. Acquire route
          5. Determine outgoing interface
          6. Verify that socket pair is unique
          7. Implicit bind and assignment of ephemeral port
          8. Store foreign address and foreign port in PCB
          9. IP Source Address Versus Outgoing Interface Address
        9. 22.9. in_pcbdisconnect Function
        10. 22.10. in_setsockaddr and in_setpeeraddr Functions
        11. 22.11. in_pcbnotify, in_rtchange, and in_losing Functions
          1. Verify arguments
          2. Handle redirects specially
          3. Call notify function for selected PCBs
          4. in_rtchange Function
          5. Redirects and Raw Sockets
          6. ICMP Errors and UDP Sockets
          7. in_losing Function
          8. Generate routing message
          9. Delete or release route
        12. 22.12. Implementation Refinements
      2. 22.13. Summary
        1. 22.13. Summary
        2. Exercises
    28. 23. UDP: User Datagram Protocol
      1. 23.1. Introduction
        1. 23.1. Introduction
        2. 23.2. Code Introduction
          1. Global Variables
          2. Statistics
          3. SNMP Variables
        3. 23.3. UDP protosw Structure
        4. 23.4. UDP Header
        5. 23.5. udp_init Function
        6. 23.6. udp_output Function
          1. Discard optional control information
          2. Temporarily connect an unconnected socket
          3. Prepend IP and UDP headers
          4. Prepending IP/UDP Headers and Mbuf Clusters
          5. UDP Checksum Calculation and Pseudo-Header
          6. Prepare pseudo-header for checksum computation
          7. Calculate checksum
          8. Fill in UDP length, TTL, and TOS
          9. Send datagram
          10. Disconnect temporarily connected socket
        7. 23.7. udp_input Function
          1. General Validation of Received UDP Datagram
          2. Discard IP options
          3. Verify UDP length
          4. Save copy of IP header and verify UDP checksum
          5. Demultiplexing Unicast Datagrams
          6. Check one-behind cache
          7. Search all UDP PCBs
          8. Generate ICMP port unreachable error
          9. Return source IP address and source port
          10. IP_RECVDSTADDR socket option
          11. Unimplemented socket options
          12. Append data to socket’s receive queue
          13. Error return
          14. Demultiplexing Multicast and Broadcast Datagrams
          15. Connected UDP Sockets and Multihomed Hosts
        8. 23.8. udp_saveopt Function
        9. 23.9. udp_ctlinput Function
          1. udp_notify Function
        10. 23.10. udp_usrreq Function
        11. 23.11. udp_sysctl Function
        12. 23.12. Implementation Refinements
          1. UDP PCB Cache
          2. UDP Checksum
      2. 23.13. Summary
        1. 23.13. Summary
        2. Exercises
    29. 24. TCP: Transmission Control Protocol
      1. 24.1. Introduction
        1. 24.1. Introduction
        2. 24.2. Code Introduction
          1. Global Variables
          2. Statistics
          3. SNMP Variables
        3. 24.3. TCP protosw Structure
        4. 24.4. TCP Header
        5. 24.5. TCP Control Block
        6. 24.6. TCP State Transition Diagram
          1. Half-Close
        7. 24.7. TCP Sequence Numbers
          1. Modular Arithmetic with Sequence Numbers
          2. Example—Sequence Number Comparisons
        8. 24.8. tcp_init Function
          1. Set initial send sequence number (ISS)
          2. Initialize linked list of TCP Internet PCBs
          3. Calculate maximum protocol header length
          4. MSL and Quiet Time Concept
      2. 24.9. Summary
        1. 24.9. Summary
        2. Exercises
    30. 25. TCP Timers
      1. 25.1. Introduction
        1. 25.1. Introduction
        2. 25.2. Code Introduction
        3. 25.3. tcp_canceltimers Function
        4. 25.4. tcp_fasttimo Function
        5. 25.5. tcp_slowtimo Function
          1. Check each timer counter in all TCP control blocks
          2. Check if TCP control block has been deleted
          3. Count idle time
          4. Increment RTT counter
          5. Increment initial send sequence number
          6. Increment RFC 1323 timestamp value
        6. 25.6. tcp_timers Function
          1. FIN_WAIT_2 and 2MSL Timers
          2. 2MSL timer
          3. FIN_WAIT_2 timer
          4. Persist Timer
          5. Force window probe segment
          6. Connection Establishment and Keepalive Timers
          7. Connection-establishment timer expires after 75 seconds
          8. Keepalive timer expires after 2 hours of idle time
          9. Drop connection when no response
          10. Send a keepalive probe
          11. Reset keepalive timer
        7. 25.7. Retransmission Timer Calculations
        8. 25.8. tcp_newtcpcb Function
        9. 25.9. tcp_setpersist Function
          1. Check retransmission timer not enabled
          2. Calculate RTO
          3. Apply exponential backoff
        10. 25.10. tcp_xmit_timer Function
          1. Update smoothed estimators
          2. Initialize smoothed estimators on first RTT measurement
          3. Clear soft error variable
        11. 25.11. Retransmission Timeout: tcp_timers Function
          1. Increment shift count
          2. Drop connection
          3. Calculate new RTO
          4. Ask IP to find a new route
          5. Clear estimators
          6. Force retransmission of oldest unacknowledged data
          7. Karn’s algorithm
          8. Slow Start and Congestion Avoidance
          9. Accuracy
        12. 25.12. An RTT Example
      2. 25.13. Summary
        1. 25.13. Summary
        2. Exercises
    31. 26. TCP Output
      1. 26.1. Introduction
        1. 26.1. Introduction
        2. 26.2. tcp_output Overview
          1. Is an ACK expected from the other end?
          2. Go back to slow start
          3. Send more than one segment
        3. 26.3. Determine if a Segment Should be Sent
          1. Calculate amount of data to send
          2. Check for window shrink
          3. Enter persist state
          4. Send one segment at a time
          5. Turn off FIN flag if send buffer not emptied
          6. Calculate window advertisement
          7. Sender silly window avoidance
          8. Example
          9. Example
        4. 26.4. TCP Options
        5. 26.5. Window Scale Option
        6. 26.6. Timestamp Option
          1. Which Timestamp to Echo, RFC 1323 Algorithm
          2. Which Timestamp to Echo, Corrected Algorithm
          3. Timestamps and Delayed ACKs
        7. 26.7. Send a Segment
          1. Build MSS option
          2. Should window scale option be sent?
          3. Build window scale option
          4. Should timestamp option be sent?
          5. Build timestamp option
          6. Check if options have overflowed segment
          7. Update statistics
          8. Allocate an mbuf for IP and TCP headers
          9. Copy data into mbuf
          10. Set PSH flag
          11. Update statistics
          12. Get mbuf for IP and TCP headers
          13. Copy IP and TCP header templates into mbuf
          14. Decrement snd_nxt if FIN is being retransmitted
          15. Set sequence number field of segment
          16. Set acknowledgment field of segment
          17. Set header length if options present
          18. Don’t advertise less than one full-sized segment
          19. Observe upper limit for advertised window on this connection
          20. Do not shrink window
          21. Set urgent offset
          22. Remember starting sequence number
          23. Increment snd_nxt
          24. Update snd_max
          25. Set retransmission timer
          26. Persist state
          27. Add trace record for socket debugging
          28. Set IP length, TTL, and TOS
          29. Pass datagram to IP
          30. Update rcv_adv and last_ack_sent
          31. More data to send?
        8. 26.8. tcp_template Function
          1. Allocate mbuf
          2. Initialize header fields
          3. Pseudo-header for TCP checksum computation
        9. 26.9. tcp_respond Function
          1. Send keepalive probe when keepalive timer expires
          2. Send RST segment in response to received segment
      2. 26.10. Summary
        1. 26.10. Summary
        2. Exercises
    32. 27. TCP Functions
      1. 27.1. Introduction
        1. 27.1. Introduction
        2. 27.2. tcp_drain Function
        3. 27.3. tcp_drop Function
        4. 27.4. tcp_close Function
          1. Route Characteristics
          2. Check if enough data sent to update statistics
          3. Update RTT
          4. Update mean deviation
          5. Resource Release
          6. Release any mbufs on reassembly queue
          7. Release header template and TCP control block
          8. Release PCB
        5. 27.5. tcp_mss Function
          1. Acquire a route if necessary
          2. Initialize smoothed RTT estimator
          3. Initialize smoothed mean deviation estimator
          4. Calculate initial RTO
          5. Use MSS from routing table MTU
          6. Round MSS down to multiple of MCLBYTES
          7. Check if destination local or nonlocal
          8. Other end’s MSS is upper bound
          9. Round buffer sizes to multiple of MSS
          10. Initialize congestion window and slow start threshold
          11. Example
        6. 27.6. tcp_ctlinput Function
        7. 27.7. tcp_notify Function
        8. 27.8. tcp_quench Function
        9. 27.9. TCP_REASS Macro and tcp_reass Function
          1. TCP_REASS Macro
          2. tcp_reass Function
        10. 27.10. tcp_trace Function
          1. Sample Output
      2. 27.11. Summary
        1. 27.11. Summary
        2. Exercises
    33. 28. TCP Input
      1. 28.1. Introduction
        1. 28.1. Introduction
        2. 28.2. Preliminary Processing
          1. Get IP and TCP headers in first mbuf
          2. Verify TCP checksum
          3. Verify TCP offset field
          4. Get headers plus option into first mbuf
          5. Process timestamp option quickly
          6. Save input flags and convert fields to host byte order
          7. Locate Internet PCB
          8. Drop segment and generate RST
          9. Silently drop segment
          10. Unscale advertised window
          11. Save connection state and IP/TCP headers if socket debug option enabled
          12. Create new socket if segment arrives for listening socket
          13. Compute window scale factor
          14. Reset idle time and keepalive timer
          15. Process TCP options if not in LISTEN state
        3. 28.3. tcp_dooptions Function
          1. Fetch option type and length
          2. MSS option
          3. Window scale option
          4. Timestamp option
        4. 28.4. Header Prediction
          1. Check if segment is the next expected
          2. Update ts_recent from received timestamp
          3. Test for pure ACK
          4. Update RTT estimators
          5. Delete acknowledged bytes from send buffer
          6. Stop retransmit timer
          7. Awaken waiting processes
          8. Generate more output
          9. Test for next in-sequence data segment
          10. Complete processing of received data
          11. Statistics
        5. 28.5. TCP Input: Slow Path Processing
          1. Drop IP and TCP headers, including TCP options
          2. Calculate receive window
        6. 28.6. Initiation of Passive Open, Completion of Active Open
          1. Initiation of Passive Open
          2. Drop if RST, ACK, or no SYN
          3. Drop if broadcast or multicast
          4. Get mbuf for client’s IP address and port
          5. Set local address in PCB
          6. Connect PCB to peer
          7. Allocate and initialize IP and TCP header template
          8. Process any TCP options
          9. Initialize ISS
          10. Initialize sequence number variables in control block
          11. ACK the SYN and change state
          12. Completion of Active Open
          13. Verify received ACK
          14. Process and drop RST segment
          15. Verify SYN flag set
          16. Process ACK
          17. Turn off retransmission timer
          18. Initialize receive sequence numbers
          19. Connection is established
          20. Check for window scale option
          21. Pass any queued data to process
          22. Update RTT estimators
          23. Simultaneous open
          24. Drop any received data that follows receive window
          25. Force update of window variables
        7. 28.7. PAWS: Protection Against Wrapped Sequence Numbers
          1. Basic PAWS test
          2. Check for outdated timestamp
          3. Drop duplicate segment
        8. 28.8. Trim Segment so Data is Within Window
          1. Check if any duplicate data at front of segment
          2. Remove duplicate SYN
          3. Check for entire duplicate packet
          4. Check for duplicate FIN
          5. Generate duplicate ACK
          6. Handle simultaneous open or self-connect
          7. Update statistics for partial duplicate segments
          8. Remove duplicate data and update urgent offset
          9. Calculate number of bytes beyond right edge of window
          10. Check for new incarnation of a connection in the TIME_WAIT state
          11. Check for probe of closed window
          12. Drop other segments that are completely outside window
          13. Handle segments that contain some valid data
          14. When to Drop an ACK
        9. 28.9. Self-Connects and Simultaneous Opens
        10. 28.10. Record Timestamp
        11. 28.11. RST Processing
          1. SYN_RCVD state
          2. Other states
      2. 28.12. Summary
        1. 28.12. Summary
        2. Exercises
    34. 29. TCP Input
      1. 29.1. Introduction
        1. 29.1. Introduction
        2. 29.2. ACK Processing Overview
        3. 29.3. Completion of Passive Opens and Simultaneous Opens
          1. Verify received ACK
          2. Check for window scale option
          3. Pass queued data to process
        4. 29.4. Fast Retransmit and Fast Recovery Algorithms
          1. Number of consecutive duplicate ACKs reaches threshold of 3
          2. Turn off retransmission timer
          3. Retransmit missing segment
          4. Set congestion window
          5. Set snd_nxt
          6. Number of consecutive duplicate ACKs exceeds threshold of 3
          7. Skip remainder of ACK processing
        5. 29.5. ACK Processing
          1. Adjust congestion window
          2. Check for out-of-range ACK
          3. Calculate number of bytes acknowledged
          4. Update RTT estimators
          5. Check if all outstanding data has been acknowledged
          6. Unacknowledged data outstanding
          7. Karn’s Algorithm and Timestamps
          8. Update congestion window
          9. Remove acknowledged bytes from the send buffer
          10. Wakeup processes waiting on send buffer
          11. Receipt of ACK in FIN_WAIT_1 state
          12. Set FIN_WAIT_2 timer
          13. Receipt of ACK in CLOSING state
          14. Receipt of ACK in LAST_ACK state
          15. Receipt of ACK in TIME WAIT state
        6. 29.6. Update Window Information
          1. Check if send window should be updated
          2. Update variables
        7. 29.7. Urgent Mode Processing
          1. Check if URG flag should be processed
          2. Ignore bogus urgent offsets
          3. Calculate receive urgent pointer
          4. Notify process of TCP’s urgent mode
          5. Pull out-of-band byte out of normal data stream
          6. Adjust receive urgent pointer if not urgent mode
        8. 29.8. tcp_pulloutofband Function
          1. Skip to next mbuf in chain
        9. 29.9. Processing of Received Data
          1. Guess size of other end’s send buffer
        10. 29.10. FIN Processing
          1. Process first FIN received on connection
          2. SYN_RCVD or ESTABLISHED states
          3. FIN_WAIT_1 state
          4. FIN_WAIT_2 state
          5. Start TIME_WAIT timer
          6. TIME_WAIT state
        11. 29.11. Final Processing
          1. SO_DEBUG socket option
          2. Call tcp_output
          3. dropafterack
          4. dropwithreset
          5. Sequence number and acknowledgment number of RST segment
          6. Rejecting connections
          7. Destroy temporarily created socket
          8. Drop (without ACK or RST)
        12. 29.12. Implementation Refinements
        13. 29.13. Header Compression
          1. Introduction
          2. Compression of Header Fields
          3. Special Cases
          4. Examples
          5. Configuration
      2. 29.14. Summary
        1. 29.14. Summary
        2. Exercises
    35. 30. TCP User Requests
      1. 30.1. Introduction
        1. 30.1. Introduction
        2. 30.2. tcp_usrreq Function
          1. in_control processes ioctl requests
          2. Control information is invalid
          3. PRU_ATTACH request
          4. PRU_DETACH request
          5. Assign ephemeral port
          6. Connect PCB
          7. Initialize IP and TCP headers
          8. Calculate window scale factor
          9. Set socket and connection state
          10. Initialize sequence numbers
          11. Send initial SYN
          12. PRU_SHUTDOWN request
          13. PRU_RCVD request
          14. PRU_SEND request
          15. PRU_ABORT request
          16. PRU_SENSE request
          17. Verify that reading out-of-band data is appropriate
          18. Check that out-of-band byte has arrived
          19. Return out-of-band byte
          20. Flip flags
          21. Check for room and append to send buffer
          22. Calculate urgent pointer
          23. Force TCP output
        3. 30.3. tcp_attach Function
          1. Allocate space for send buffer and receive buffer
          2. Allocate Internet PCB and TCP control block
        4. 30.4. tcp_disconnect Function
          1. Connection not yet synchronized
          2. Hard disconnect
          3. Graceful disconnect
          4. Discard pending receive data
          5. Change connection state
        5. 30.5. tcp_usrclosed Function
          1. Simple close when SYN not received
          2. Move to FIN_WAIT_1 state
          3. Move to LAST_ACK state
        6. 30.6. tcp_ctloutput Function
          1. TCP_NODELAY option
          2. TCP_MAXSEG option
          3. Release mbuf
      2. 30.7. Summary
        1. 30.7. Summary
        2. Exercises
    36. 31. BPF: BSD Packet Filter
      1. 31.1. Introduction
        1. 31.1. Introduction
        2. 31.2. Code Introduction
          1. Global Variables
          2. Statistics
        3. 31.3. bpf_if Structure
          1. Initialize bpf_if structure
          2. Compute BPF header size
          3. Initialize bpf_dtab table
          4. Print console message
        4. 31.4. bpf_d Structure
          1. Packet buffers
          2. bpfopen Function
          3. Allocate bpf_d structure
          4. bpfioctl Function
          5. bpf_setif Function
          6. Locate matching ifnet structure
          7. Attach bpf_d structure
          8. bpf_attachd Function
        5. 31.5. BPF Input
          1. bpf_tap Function
          2. Pass packet to one or more BPF devices
          3. catchpacket Function
          4. Will the packet fit?
          5. Immediate mode processing
          6. Append BPF header
          7. bpfread Function
          8. Wait for data
          9. Immediate mode
          10. No packets available
          11. Check hold buffer
          12. Check store buffer
          13. Packets are available
        6. 31.6. BPF Output
          1. bpfwrite Function
          2. Check device number
          3. Copy data into mbuf chain
          4. Queue packet
      2. 31.7. Summary
        1. 31.7. Summary
        2. Exercises
    37. 32. Raw IP
      1. 32.1. Introduction
        1. 32.1. Introduction
        2. 32.2. Code Introduction
          1. Global Variables
          2. Statistics
        3. 32.3. Raw IP protosw Structure
        4. 32.4. rip_init Function
        5. 32.5. rip_input Function
          1. Save source IP address
          2. Search all raw IP PCBs for one or more matching entries
          3. Compare protocols
          4. Compare local and foreign IP addresses
          5. Pass copy of received datagram to processes
          6. Undeliverable datagram
        6. 32.6. rip_output Function
          1. Kernel fills in IP header
          2. Caller fills in IP header: IP_HDRINCL socket option
        7. 32.7. rip_usrreq Function
          1. Verify superuser
          2. Create Internet PCB and reserve buffer space
        8. 32.8. rip_ctloutput Function
      2. 32.9. Summary
        1. 32.9. Summary
        2. Exercises
    38. Epilogue
    39. A. Solutions to Selected Exercises
      1. Chapter 1
        1. Chapter 1
        2. Chapter 2
        3. Chapter 3
        4. Chapter 4
        5. Chapter 5
        6. Chapter 6
        7. Chapter 7
        8. Chapter 8
        9. Chapter 9
        10. Chapter 10
        11. Chapter 11
        12. Chapter 12
        13. Chapter 13
        14. Chapter 14
        15. Chapter 15
        16. Chapter 16
        17. Chapter 17
        18. Chapter 18
        19. Chapter 19
        20. Chapter 20
        21. Chapter 21
        22. Chapter 22
        23. Chapter 23
        24. Chapter 24
        25. Chapter 25
        26. Chapter 26
        27. Chapter 27
        28. Chapter 28
        29. Chapter 29
        30. Chapter 30
        31. Chapter 31
        32. Chapter 32
    40. B. Source Code Availability
      1. URLs: Uniform Resource Locators
        1. URLs: Uniform Resource Locators
        2. 4.4BSD-Lite
        3. Operating Systems that Run the 4.4BSD-Lite Networking Software
        4. RFCs
        5. GNU Software
        6. PPP Software
        7. mrouted Software
        8. ISODE Software
    41. C. RFC 1122 Compliance
      1. C.1. Link-Layer Requirements
        1. C.1. Link-Layer Requirements
        2. C.2. IP Requirements
          1. Multihoming
          2. Broadcast
          3. IP Interface
        3. C.3. IP Options Requirements
          1. Source Route Forwarding
        4. C.4. IP Fragmentation and Reassembly Requirements
        5. C.5. ICMP Requirements
        6. C.6. Multicasting Requirements
        7. C.7. IGMP Requirements
        8. C.8. Routing Requirements
        9. C.9. ARP Requirements
        10. C.10. UDP Requirements
        11. C.11. TCP Requirements
          1. PSH Flag
          2. Window
          3. Urgent Data
          4. TCP Options
          5. TCP Checksums
          6. Initial Sequence Number Selection
          7. Opening Connections
          8. Closing Connections
          9. Retransmissions
          10. Generating ACKs
          11. Sending Data
          12. Connection Failures
          13. Keepalive Packets
          14. IP Options
          15. Receiving ICMP Messages from IP
          16. Application Programming Interface
    42. Bibliography
3.145.16.90