第七章IP协议:报文格式无连接通信思想IP报文格式IP报文选项1引言网络结构—虚拟网络路由器为“节点”物理网为“信道”物理网在路由器间运送IP报文路由器为IP报文选择传输路径2无连接通信思想IP通信的环境穿越多个网络经过多个路由器有多条可能的路径RRRRRRSLIP/PPPSLIP/PPPIP报文无连接通信不同物理网络之间存在差异通信能力、分组长度、延时允许IP报文从不同路径达到目的地路由器为每个IP报文独立选路IP通信不保证可靠性,但灵活性增加多种网络都能满足的通信方式允许多种选路策略(如可靠性、容量、延时)结合应用考虑实际通信策略3IP报文格式IP报文首部携带源、目的地址报文分段、重组ServiceAccessPointIPOptionsOthersIP报文数据AnybytesofdataIP格式图4Bytes边界对齐Data为任意字节VerHLenTOSTotalLengthIdentifierFlagsFragOffsetTTLProtocolHCSSourceIPAddressDestinationIPAddressIPOptions(ifany)PaddingData048161931IPPDUstructurestructIP_PDU{U8VerLen;/*VersionandHeaderLength*/U8TOS;/*Typeofservice*/U16TLen;/*Totalpacketlength*/U16ID;/*packetidentifier*/U16FlgOff;/*FlagsandFrag.Offset*/U8TTL;/*TimeToLive*/U8Prot;/*ProtocolID,--upperSAP*/U16hCS;/*HeaderChechsum*/U32sIP;/*SourceIPaddr.*/U32dIP;/*DestinationIPaddr*/U8OpData[.];/*Optionanddatafields*/};格式域Ver(4bit):版本号(=4)HLen(4bit):首部长度长度单位:4字节TotalLength:本报文总长度长度单位:字节HCS:首部校验和IP只检查首部VerHLenTOSTotalLengthIdentifierFlagsFragOffsetTTLProtocolHCSSourceIPAddressDestinationIPAddressIPOptions(ifany)PaddingDataHLen(4bytesunit)TotalLength(1bytesunit)最大HLen=16,(11x4bytesmaxUsedinIPoption)最大IP报文长度:65535bytes(包括首部)TTL:TimeToLive该报文的寿命(秒,最大255)防止路由成环时,IP被无限次转发协议规定,路由器处理IP报文时,应减去处理所用的时间,TTL为零时,丢弃该报文实际:TTL经过路由器时,被减1Protocol:上层协议类型作为IP提供的SAPTCPUDPICMP1176IPVerHLenTOSTotalLengthIdentifierFlagsFragOffsetTTLProtocolHCSSourceIPAddressDestinationIPAddressIPOptions(ifany)PaddingDataAssignedProtocolNumber0:Reserved1:ICMP2:IGMP3:GGP4:IP6:TCP8:EGP9:IGP17:UDP23:Trunk-125:Leaf-129:ISO-TP446:RSVP48:MHRP88:IGRP89:OSPFIGP93:AX.2594:IPIP97:ETHERIP……IP校验和计算只对首部进行校验和检查,数据部分由高层协议进行校验计算方法把首部看成16bit整数序列:W1、W2、…模65535,即0xFFFF(不是65536)求和,结果取反任何情况下,HCS≠0niMWiHCS1655354TOS,TypeofServiceRFC791Bits0-2:Precedence.Bit3:Delay,0=Normal,1=Low.Bits4:Throughput.0=Normal,1=HighBits5:Relibility.0=Normal,1=HighBits6:Cost.0=Normal,1=LowBits7:Mustbezero.Precedence111-NetworkControl110-InternetworkControl101-CRITIC/ECP100-FlashOverride011-Flash010-Immediate001-Priority000-RoutineVerHLenTOSTotalLengthIdentifierFlagsFragOffsetTTLProtocolHCSSourceIPAddressDestinationIPAddressIPOptions(ifany)PaddingData01234567PrecedenceDTRC0TOS,TypeofServiceRFC1349,TOSfor:ICMPTelnet–minimumDelayFTP–MaxthroughputTFTP--MinimizedelaySMTP--MaximizethroughputAnyIGP--MaximizereliabilitySNMP--maximizereliabilityOtheruseofTOSBinarynumberofTOScoding5.FragmentationTherequirementsofsegmentationTransportIPPhysicalNetworkDatablocksizeisindependentofMTUofunderlyingphysicalnetworkIPpacketsizemustmatchetheMTUofunderlyingphysicalnetworkMTU=MaximumTransmissionUnitTypicalMTU:1500(Ethernet)2000~4000(TokenRing)512(Dial-up)128(RadioLink)others…HostDataBlockIPPacketFragmentationGatewayrequiresfragmentationfordifferentMTUofphysicalnetworksIPMTU1MTU2GatewayExample:MTU1=1500BytesMTU2=600BytesFragmentation&reassemblyCase1:reassemblyatGatewayandhostCase2:reassemblyonlyathostIPIPG1G2MTU=1500MTU=800MTU=100025002200Case1Case2DiscussionIPprotocolspecifythat:Thefragmentationactionwillappearathostorgatewaywhereneeded.TheassemblywillonlyappearatIPdestinationhost.DiscussingtheadvantageanddisadvantageAssemblyatGatewayAssembleonlyatendpoint(Host)FragmentationcontrolIdentifier(16bit)distinguishdifferentIPpacketsAllfragsofapacketholdthesameIdentifierFragoffset(13bit)offsetofaIPpacketdata8bytesunit(match64Klength)FlagSegmentationstatus-Morefragmentsfollows-Don’tfragVerHLenTOSTotalLengthIdentifierFlagsFragOffsetTTLProtocolHCSSourceIPAddressDestinationIPAddressIPOptions(ifany)PaddingDataSomeIPlayercannothandlefragmentationFragmentationexample首部DataLength=1480Bytes首部Data1首部Data2首部Data305761152Offset=0,M=1Offset=72(x8),M=1Offset=144(x8),M=0MTU:1500bytes,Header:20bytesMTU=600ID=aID=bID=bID=aOffsetandM-bitIDcontrolsassemblyImplementationFragNI-2AssemblyRoute&ForwardingNI-1IP-inFragEncapsulationAssemblybufferDatablockAssemblyproblemsintegrityjudgementofdatablock?Len=Length-1+length-2+……?Iffragsarrivedoutofsequence?Missingsomeoffragments?Overlapamongfragments6.IPOptionsCopyClassNumberLengthDescriptionX00--EndofoptionlistX01--NooperationX0211Security.X03VarLooseSourceRouting.X09VarStrictSourceRouting.X07VarRecordRoute.X084StreamID.X24varInternetTimestamp.OpDataOpData0OpCodeOption-1Option-2End01234567CopyClassOptionNumberIPOptionTheoptionsmayappearornotindatagrams.TheymustbeimplementedbyallIPmodules(hostandgateways).CopyIndicatesthatthisoptioniscopiedintoallfragmentsonfragmentation.Class0=control1=reservedforfutureuse2=debuggingandmeasurement3=reservedforfutureuseSecurityThisoptionprovidesawayforhoststosendsecurity,compartmentation,handlingrestrictions,andTCC(closedusergroup)parameters.Theformatforthisoptionisasfollows:Type=130Length=111000001000001011SSSSSSCCCCCCHHHHHHTCCS:16bits,SecurityC:16bits,CompartmentationH:16bits,HandlingTCC:24bits,ClosedUsergroupLooseSourceandRecordRouteTheloosesourceandrecordroute(LSRR)optionprovidesameansforthesourceofaninternetdatagramtosupplyroutinginformationtobeusedbythegatewaysinforwardingthedatagramtothedestination,andtorecordtherouteinformation.10000011LengthP