Tải bản đầy đủ (.pdf) (2,852 trang)

Addison wesley TCPIP illustrated volume 2 the implementation feb 1995 ISBN 020163354x

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (48.14 MB, 2,852 trang )

TCP/IPIllustrated,Volume2:The
Implementation
ByGaryR.Wright,W.RichardStevens

Publisher :AddisonWesley
PubDate :January12,1995
ISBN :0-201-63354-X
Pages :1200

TCP/IPIllustrated,Volume2
containsathoroughexplanation
ofhowTCP/IPprotocolsare
implemented.Thereisn'tamore
practicalorup-to-datebookothis
volumeistheonlyonetocover
thedefactostandard
implementationfromthe4.4BSDLiterelease,thefoundationfor
TCP/IPimplementationsrundaily
onhundredsofthousandsof
systemsworldwide.
Combining500illustrationswith
15,000linesofreal,working
code,TCP/IPIllustrated,Volume

2usesateach-by-example

approachtohelpyoumaster
Tableof

Contents TCP/IPimplementation.Youwill
learnaboutsuchtopicsasthe






relationshipbetweenthesockets
APIandtheprotocolsuite,and
thedifferencesbetweenahost
implementationandarouter.In
addition,thebookcoversthe
newestfeaturesofthe4.4BSDLiterelease,including
multicasting,longfatpipe
support,windowscale,timestamp
options,andprotectionagainst
wrappedsequencenumbers,and
manyothertopics.
Comprehensiveinscope,based
onaworkingstandard,and
thoroughlyillustrated,thisbookis
anindispensableresourcefor
anyoneworkingwithTCP/IP.




TCP/IPIllustrated,Volume2:The
Implementation
ByGaryR.Wright,W.RichardStevens

Publisher :AddisonWesley


PubDate :January12,1995
ISBN :0-201-63354-X
Tableof

Pages
:1200
Contents



Copyright



Preface



Introduction



OrganizationoftheBook



IntendedAudience




SourceCodeCopyright



Acknowledgments



Chapter1.Introduction



Section1.1.Introduction



Section1.2.SourceCodePresentation



Section1.3.History



Section1.4.ApplicationProgrammingInterfaces



Section1.5.ExampleProgram




Section1.6.SystemCallsandLibraryFunctions



Section1.7.NetworkImplementationOverview



Section1.8.Descriptors



Section1.9.Mbufs(MemoryBuffers)andOutputProcessing



Section1.10.InputProcessing



Section1.11.NetworkImplementationOverviewRevisited



Section1.12.InterruptLevelsandConcurrency




Section1.13.SourceCodeOrganization



Section1.14.TestNetwork



Section1.15.Summary



Chapter2.Mbufs:MemoryBuffers



Section2.1.Introduction



Section2.2.CodeIntroduction



Section2.3.MbufDefinitions



Section2.4.mbufStructure




Section2.5.SimpleMbufMacrosandFunctions



Section2.6.m_devgetandm_pullupFunctions



Section2.7.SummaryofMbufMacrosandFunctions




Section2.8.SummaryofNet/3NetworkingDataStructures



Section2.9.m_copyandClusterReferenceCounts



Section2.10.Alternatives



Section2.11.Summary




Chapter3.InterfaceLayer



Section3.1.Introduction



Section3.2.CodeIntroduction



Section3.3.ifnetStructure



Section3.4.ifaddrStructure



Section3.5.sockaddrStructure



Section3.6.ifnetandifaddrSpecialization



Section3.7.NetworkInitializationOverview




Section3.8.EthernetInitialization



Section3.9.SLIPInitialization



Section3.10.LoopbackInitialization



Section3.11.if_attachFunction



Section3.12.ifinitFunction



3.13Summary



Chapter4.Interfaces:Ethernet




Section4.1.Introduction



Section4.2.CodeIntroduction



Section4.3.EthernetInterface



Section4.4.ioctlSystemCall



Section4.5.Summary



Chapter5.Interfaces:SLIPandLoopback



Section5.1.Introduction



Section5.2.CodeIntroduction




Section5.3.SLIPInterface



Section5.4.LoopbackInterface



Section5.5.Summary



Chapter6.IPAddressing



Section6.1.Introduction



Section6.2.CodeIntroduction



Section6.3.InterfaceandAddressSummary




Section6.4.sockaddr_inStructure



Section6.5.in_ifaddrStructure



Section6.6.AddressAssignment



Section6.7.InterfaceioctlProcessing



Section6.8.InternetUtilityFunctions



Section6.9.ifnetUtilityFunctions



Section6.10.Summary





Chapter7.DomainsandProtocols
Section7.1.Introduction




Section7.2.CodeIntroduction



Section7.3.domainStructure



Section7.4.protoswStructure



Section7.5.IPdomainandprotoswStructures



Section7.6.pffindprotoandpffindtypeFunctions



Section7.7.pfctlinputFunction




Section7.8.IPInitialization



Section7.9.sysctlSystemCall



Section7.10.Summary



Chapter8.IP:InternetProtocol



Section8.1.Introduction



Section8.2.CodeIntroduction



Section8.3.IPPackets



Section8.4.InputProcessing:ipintrFunction




Section8.5.Forwarding:ip_forwardFunction



Section8.6.OutputProcessing:ip_outputFunction



Section8.7.InternetChecksum:in_cksumFunction



Section8.8.setsockoptandgetsockoptSystemCalls



Section8.9.ip_sysctlFunction



Section8.10.Summary



Chapter9.IPOptionProcessing




Section9.1.Introduction



Section9.2.CodeIntroduction



Section9.3.OptionFormat



Section9.4.ip_dooptionsFunction



Section9.5.RecordRouteOption



Section9.6.SourceandRecordRouteOptions



Section9.7.TimestampOption



Section9.8.ip_insertoptionsFunction




Section9.9.ip_pcboptsFunction



Section9.10.Limitations



Section9.11.Summary



Chapter10.IPFragmentationandReassembly



Section10.1.Introduction



Section10.2.CodeIntroduction



Section10.3.Fragmentation




Section10.4.ip_optcopyFunction



Section10.5.Reassembly



Section10.6.ip_reassFunction



Section10.7.ip_slowtimoFunction



Section10.8.Summary



Chapter11.ICMP:InternetControlMessageProtocol



Section11.1.Introduction



Section11.2.CodeIntroduction





Section11.3.icmpStructure



Section11.4.ICMPprotoswStructure



Section11.5.InputProcessing:icmp_inputFunction



Section11.6.ErrorProcessing



Section11.7.RequestProcessing



Section11.8.RedirectProcessing



Section11.9.ReplyProcessing




Section11.10.OutputProcessing



Section11.11.icmp_errorFunction



Section11.12.icmp_reflectFunction



Section11.13.icmp_sendFunction



Section11.14.icmp_sysctlFunction



Section11.15.Summary



Chapter12.IPMulticasting



Section12.1.Introduction




Section12.2.CodeIntroduction



Section12.3.EthernetMulticastAddresses



Section12.4.ether_multiStructure



Section12.5.EthernetMulticastReception



Section12.6.in_multiStructure



Section12.7.ip_moptionsStructure



Section12.8.MulticastSocketOptions




Section12.9.MulticastTTLValues



Section12.10.ip_setmoptionsFunction



Section12.11.JoininganIPMulticastGroup



Section12.12.LeavinganIPMulticastGroup



Section12.13.ip_getmoptionsFunction



Section12.14.MulticastInputProcessing:ipintrFunction



Section12.15.MulticastOutputProcessing:ip_outputFunction



Section12.16.PerformanceConsiderations




Section12.17.Summary



Chapter13.IGMP:InternetGroupManagementProtocol



Section13.1.Introduction



Section13.2.CodeIntroduction



Section13.3.igmpStructure



Section13.4.IGMPprotoswStructure



Section13.5.JoiningaGroup:igmp_joingroupFunction




Section13.6.igmp_fasttimoFunction



Section13.7.InputProcessing:igmp_inputFunction



Section13.8.LeavingaGroup:igmp_leavegroupFunction



Section13.9.Summary



Chapter14.IPMulticastRouting



Section14.1.Introduction



Section14.2.CodeIntroduction





Section14.3.MulticastOutputProcessingRevisited



Section14.4.mroutedDaemon



Section14.5.VirtualInterfaces



Section14.6.IGMPRevisited



Section14.7.MulticastRouting



Section14.8.MulticastForwarding:ip_mforwardFunction



Section14.9.Cleanup:ip_mrouter_doneFunction



Section14.10.Summary




Chapter15.SocketLayer



Section15.1.Introduction



Section15.2.CodeIntroduction



Section15.3.socketStructure



Section15.4.SystemCalls



Section15.5.Processes,Descriptors,andSockets



Section15.6.socketSystemCall




Section15.7.getsockandsockargsFunctions



Section15.8.bindSystemCall



Section15.9.listenSystemCall



Section15.10.tsleepandwakeupFunctions



Section15.11.acceptSystemCall



Section15.12.sonewconnandsoisconnectedFunctions



Section15.13.connectSystemcall



Section15.14.shutdownSystemCall




Section15.15.closeSystemCall



Section15.16.Summary



Chapter16.SocketI/O



Section16.1.Introduction



Section16.2.CodeIntroduction



Section16.3.SocketBuffers



Section16.4.write,writev,sendto,andsendmsgSystemCalls




Section16.5.sendmsgSystemCall



Section16.6.senditFunction



Section16.7.sosendFunction



Section16.8.read,readv,recvfrom,andrecvmsgSystemCalls



Section16.9.recvmsgSystemCall



Section16.10.recvitFunction



Section16.11.soreceiveFunction



Section16.12.soreceiveCode




Section16.13.selectSystemCall



Section16.14.Summary



Chapter17.SocketOptions



Section17.1.Introduction



Section17.2.CodeIntroduction



Section17.3.setsockoptSystemCall




Section17.4.getsockoptSystemCall




Section17.5.fcntlandioctlSystemCalls



Section17.6.getsocknameSystemCall



Section17.7.getpeernameSystemCall



Section17.8.Summary



Chapter18.RadixTreeRoutingTables



Section18.1.Introduction



Section18.2.RoutingTableStructure



Section18.3.RoutingSockets




Section18.4.CodeIntroduction



Section18.5.RadixNodeDataStructures



Section18.6.RoutingStructures



Section18.7.Initialization:route_initandrtable_initFunctions



Section18.8.Initialization:rn_initandrn_initheadFunctions



Section18.9.DuplicateKeysandMaskLists



Section18.10.rn_matchFunction




Section18.11.rn_searchFunction



Section18.12.Summary



Chapter19.RoutingRequestsandRoutingMessages



Section19.1.Introduction



Section19.2.rtallocandrtalloc1Functions



Section19.3.RTFREEMacroandrtfreeFunction



Section19.4.rtrequestFunction



Section19.5.rt_setgateFunction




Section19.6.rtinitFunction



Section19.7.rtredirectFunction



Section19.8.RoutingMessageStructures



Section19.9.rt_missmsgFunction



Section19.10.rt_ifmsgFunction



Section19.11.rt_newaddrmsgFunction



Section19.12.rt_msg1Function




Section19.13.rt_msg2Function



Section19.14.sysctl_rtableFunction



Section19.15.sysctl_dumpentryFunction



Section19.16.sysctl_iflistFunction



Section19.17.Summary



Chapter20.RoutingSockets



Section20.1.Introduction



Section20.2.routedomainandprotoswStructures




Section20.3.RoutingControlBlocks



Section20.4.raw_initFunction



Section20.5.route_outputFunction



Section20.6.rt_xaddrsFunction



Section20.7.rt_setmetricsFunction






Section20.8.raw_inputFunction




Section20.9.route_usrreqFunction



Section20.10.raw_usrreqFunction



Section20.11.raw_attach,raw_detach,andraw_disconnectFunctions



Section20.12.Summary



Chapter21.ARP:AddressResolutionProtocol



Section21.1.Introduction



Section21.2.ARPandtheRoutingTable



Section21.3.CodeIntroduction




Section21.4.ARPStructures



Section21.5.arpwhohasFunction



Section21.6.arprequestFunction



Section21.7.arpintrFunction



Section21.8.in_arpinputFunction



Section21.9.ARPTimerFunctions



Section21.10.arpresolveFunction




Section21.11.arplookupFunction



Section21.12.ProxyARP



Section21.13.arp_rtrequestFunction



Section21.14.ARPandMulticasting



Section21.15.Summary



Chapter22.ProtocolControlBlocks



Section22.1.Introduction



Section22.2.CodeIntroduction




Section22.3.inpcbStructure



Section22.4.in_pcballocandin_pcbdetachFunctions



Section22.5.Binding,Connecting,andDemultiplexing



Section22.6.in_pcblookupFunction



Section22.7.in_pcbbindFunction



Section22.8.in_pcbconnectFunction



Section22.9.in_pcbdisconnectFunction




Section22.10.in_setsockaddrandin_setpeeraddrFunctions



Section22.11.in_pcbnotify,in_rtchange,andin_losingFunctions



Section22.12.ImplementationRefinements



Section22.13.Summary



Chapter23.UDP:UserDatagramProtocol



Section23.1.Introduction



Section23.2.CodeIntroduction



Section23.3.UDPprotoswStructure




Section23.4.UDPHeader



Section23.5.udp_initFunction



Section23.6.udp_outputFunction



Section23.7.udp_inputFunction



Section23.8.udp_saveoptFunction




Section23.9.udp_ctlinputFunction



Section23.10.udp_usrreqFunction




Section23.11.udp_sysctlFunction



Section23.12.ImplementationRefinements



Section23.13.Summary



Chapter24.TCP:TransmissionControlProtocol



Section24.1.Introduction



Section24.2.CodeIntroduction



Section24.3.TCPprotoswStructure



Section24.4.TCPHeader




Section24.5.TCPControlBlock



Section24.6.TCPStateTransitionDiagram



Section24.7.TCPSequenceNumbers



Section24.8.tcp_initFunction



Section24.9.Summary



Chapter25.TCPTimers



Section25.1.Introduction




Section25.2.CodeIntroduction



Section25.3.tcp_canceltimersFunction



Section25.4.tcp_fasttimoFunction



Section25.5.tcp_slowtimoFunction



Section25.6.tcp_timersFunction



Section25.7.RetransmissionTimerCalculations



Section25.8.tcp_newtcpcbFunction



Section25.9.tcp_setpersistFunction




Section25.10.tcp_xmit_timerFunction



Section25.11.RetransmissionTimeout:tcp_timersFunction



Section25.12.AnRTTExample



Section25.13.Summary



Chapter26.TCPOutput



Section26.1.Introduction



Section26.2.tcp_outputOverview




Section26.3.DetermineifaSegmentShouldbeSent



Section26.4.TCPOptions



Section26.5.WindowScaleOption



Section26.6.TimestampOption



Section26.7.SendaSegment



Section26.8.tcp_templateFunction



Section26.9.tcp_respondFunction



Section26.10.Summary




Chapter27.TCPFunctions



Section27.1.Introduction



Section27.2.tcp_drainFunction



Section27.3.tcp_dropFunction




Section27.4.tcp_closeFunction



Section27.5.tcp_mssFunction



Section27.6.tcp_ctlinputFunction




Section27.7.tcp_notifyFunction



Section27.8.tcp_quenchFunction



Section27.9.TCP_REASSMacroandtcp_reassFunction



Section27.10.tcp_traceFunction



Section27.11.Summary



Chapter28.TCPInput



Section28.1.Introduction




Section28.2.PreliminaryProcessing



Section28.3.tcp_dooptionsFunction



Section28.4.HeaderPrediction



Section28.5.TCPInput:SlowPathProcessing



Section28.6.InitiationofPassiveOpen,CompletionofActiveOpen



Section28.7.PAWS:ProtectionAgainstWrappedSequenceNumbers



Section28.8.TrimSegmentsoDataisWithinWindow



Section28.9.Self-ConnectsandSimultaneousOpens




Section28.10.RecordTimestamp



Section28.11.RSTProcessing



Section28.12.Summary



Chapter29.TCPInput(Continued)



Section29.1.Introduction



Section29.2.ACKProcessingOverview



Section29.3.CompletionofPassiveOpensandSimultaneousOpens




Section29.4.FastRetransmitandFastRecoveryAlgorithms



Section29.5.ACKProcessing



Section29.6.UpdateWindowInformation



Section29.7.UrgentModeProcessing



Section29.8.tcp_pulloutofbandFunction



Section29.9.ProcessingofReceivedData



Section29.10.FINProcessing



Section29.11.FinalProcessing




Section29.12.ImplementationRefinements



Section29.13.HeaderCompression



Section29.14.Summary



Chapter30.TCPUserRequests



Section30.1.Introduction



Section30.2.tcp_usrreqFunction



Section30.3.tcp_attachFunction




Section30.4.tcp_disconnectFunction



Section30.5.tcp_usrclosedFunction



Section30.6.tcp_ctloutputFunction



Section30.7.Summary




Chapter31.BPF:BSDPacketFilter



Section31.1.Introduction



Section31.2.CodeIntroduction



Section31.3.bpf_ifStructure




Section31.4.bpf_dStructure



Section31.5.BPFInput



Section31.6.BPFOutput



Section31.7.Summary



Chapter32.RawIP



Section32.1.Introduction



Section32.2.CodeIntroduction




Section32.3.RawIPprotoswStructure



Section32.4.rip_initFunction



Section32.5.rip_inputFunction



Section32.6.rip_outputFunction



Section32.7.rip_usrreqFunction



Section32.8.rip_ctloutputFunction



Section32.9.Summary



Epilogue




AppendixA.SolutionstoSelectedExercises



Chapter1



Chapter2



Chapter3



Chapter4



Chapter5



Chapter6




Chapter7



Chapter8



Chapter9



Chapter10



Chapter11



Chapter12



Chapter13



Chapter14




Chapter15



Chapter16



Chapter17



Chapter18



Chapter19



Chapter20



Chapter21




Chapter22



Chapter23



Chapter24




Chapter25



Chapter26



Chapter27



Chapter28




Chapter29



Chapter30



Chapter31



Chapter32



AppendixB.SourceCodeAvailability



URLs:UniformResourceLocators



4.4BSD-Lite



OperatingSystemsthatRunthe4.4BSD-LiteNetworkingSoftware




RFCs



GNUSoftware



PPPSoftware



mroutedSoftware



ISODESoftware



AppendixC.RFC1122Compliance



SectionC.1.Link-LayerRequirements




SectionC.2.IPRequirements



SectionC.3.IPOptionsRequirements



SectionC.4.IPFragmentationandReassemblyRequirements



SectionC.5.ICMPRequirements



SectionC.6.MulticastingRequirements



SectionC.7.IGMPRequirements



SectionC.8.RoutingRequirements



SectionC.9.ARPRequirements




SectionC.10.UDPRequirements



SectionC.11.TCPRequirements



Bibliography

Top

AboutSafari|TermsofService


Team-Fly

TCP/IPIllustrated,Volume2:The
ImplementationByGaryR.Wright,
W.RichardStevens
TableofContents






Copyright

Manyofthedesignationsusedbymanufacturersand
sellerstodistinguishtheirproductsareclaimedas
trademarks.Wherethosedesignationsappearinthis
book,andwewereawareofatrademarkclaim,the
designationshavebeenprintedininitialcapitalletters
orinallcapitals.
Theprogramsandapplicationspresentedinthisbook
havebeenincludedfortheirinstructionalvalue.They
havebeentestedwithcare,butarenotguaranteed
foranyparticularpurpose.Thepublisherdoesnot
offeranywarrantiesorrepresentations,nordoesit
acceptanyliabilitieswithrespecttotheprogramsor
applications.
Thepublisheroffersdiscountsonthisbookwhen
orderedinquantityforspecialsales.Formore
informationpleasecontact:
PearsonEducationCorporateSalesDivision
OneLakeStreet
UpperSaddleRiver,NJ07458
(800)382-3419



VisitAWontheWeb:www.awl.com/cseng/
LibraryofCongressCataloging-in-Publication
Data
(Revisedforvol.2)
Stevens,W.Richard.
TCP/IPillustrated.
(Addison-Wesleyprofessionalcomputingseries)

Vol.2byGaryR.Wright,W.RichardStevens.
Includesbibliographicalreferencesandindexes.
Contents:v.1.Theprotocolsv.2.The
implementation
1.TCP/IP(Computernetworkprotocol)IWright,
GaryR..,II.Title.III.Series.
TK5105.55.S741994004.6'29340000
ISBN0-201-63346-9(v.l)
ISBN0-201-63354-X(v.2)
TheBSDDaemonusedonthecoverofthisbookis
reproducedwiththepermissionofMarshallKirk
McKusick.
Copyright©1995byAddison-Wesley
Allrightsreserved.Nopartofthispublicationmaybe


reproduced,storedinaretrievalsystem,or
transmitted,inanyform,orbyanymeans,electronic,
mechanical,photocopying,recording,orother-wise,
withoutthepriorconsentofthepublisher.Printedin
theUnitedStatesofAmerica.Published
simultaneouslyinCanada.
Textprintedonrecycledandacid-freepaper.
121314151617CR03020100
12thPrintingNovember2000

Dedication
Tomyparentsandmysister,
fortheirloveandsupport.
G.R.W.

Tomyparents,
forthegiftofaneducation,
andtheexampleofaworkethic.
W.R.S.


Team-Fly




Team-Fly

TCP/IPIllustrated,Volume2:The
ImplementationByGaryR.Wright,
W.RichardStevens
TableofContents






Preface
Introduction
OrganizationoftheBook
IntendedAudience




SourceCodeCopyright
Acknowledgments

Team-Fly




Top


Team-Fly





TCP/IPIllustrated,Volume2:The
ImplementationByGaryR.Wright,
W.RichardStevens
TableofContents

Preface

Introduction
Thisbookdescribesandpresentsthe
sourcecodeforthecommonreference
implementationofTCP/IP:the
implementationfromtheComputer
SystemsResearchGroup(CSRG)atthe

UniversityofCaliforniaatBerkeley.
Historicallythishasbeendistributedwith
the4.xBSDsystem(BerkeleySoftware
Distribution).Thisimplementationwas
firstreleasedin1982andhassurvived
manysignificantchanges,muchfine
tuning,andnumerousportstootherUnix
andnon-Unixsystems.Thisisnotatoy
implementation,butthefoundationfor
TCP/IPimplementationsthatarerundaily
onhundredsofthousandsofsystems


worldwide.Thisimplementationalso
providesrouterfunctionality,lettingus
showthedifferencesbetweenahost
implementationofTCP/IPandarouter.
Wedescribetheimplementationand
presenttheentiresourcecodeforthe
kernelimplementationofTCP/IP,
approximately15,000linesofCcode.The
versionoftheBerkeleycodedescribedin
thistextisthe4.4BSD-Literelease.This
codewasmadepubliclyavailableinApril
1994,anditcontainsnumerous
networkingenhancementsthatwere
addedtothe4.3BSDTahoereleasein
1988,the4.3BSDRenoreleasein1990,
andthe4.4BSDreleasein1993.
(AppendixBdescribeshowtoobtainthis

sourcecode.)The4.4BSDreleaseprovides
thelatestTCP/IPfeatures,suchas
multicastingandlongfatpipesupport(for
high-bandwidth,long-delaypaths).Figure
1.1providesadditionaldetailsofthe
variousreleasesoftheBerkeley
networkingcode.
Thisbookisintendedforanyonewishing
tounderstandhowtheTCP/IPprotocols




areimplemented:programmerswriting
networkapplications,system
administratorsresponsibleformaintaining
computersystemsandnetworksutilizing
TCP/IP,andanyprogrammerinterestedin
understandinghowalargebodyof
nontrivialcodefitsintoarealoperating
system.

Team-Fly




Top



Team-Fly





TCP/IPIllustrated,Volume2:The
ImplementationByGaryR.Wright,
W.RichardStevens
TableofContents

Preface

OrganizationoftheBook
Thefollowingfigureshowsthevarious
protocolsandsubsystemsthatare
covered.Theitalicnumbersbyeachbox
indicatethechaptersinwhichthattopicis
described.




Wetakeabottom-upapproachtothe
TCP/IPprotocolsuite,startingatthedatalinklayer,thenthenetworklayer(IP,ICMP,
IGMP,IProuting,andmulticastrouting),
followedbythesocketlayer,andfinishing
withthetransportlayer(UDP,TCP,and
rawIP).


Team-Fly




Top


×