Tải bản đầy đủ - 0 (trang)
11 in_pcbnotify, in_rtchange, and in_losing Functions

11 in_pcbnotify, in_rtchange, and in_losing Functions

Tải bản đầy đủ - 0trang

WhenanICMPmessageisreceived,icmp_inputiscalle

areclassifiedaserrors(Figures11.1and11.2):

destinationunreachable,

parameterproblem,

redirect,

sourcequench,and



timeexceeded.



Redirectsarehandleddifferentlyfromtheotherfourer

(thequeries)arehandledasdescribedinChapter11



Eachprotocoldefinesitscontrolinputfunction,thepr_

structure(Section7.4).TheonesforTCPandUDPare

udp_ctlinput,andwe'llshowtheircodeinlaterchapter

receivedcontainstheIPheaderofthedatagramthatc

thatcausedtheerror(TCPorUDP)isknown.Fourofth

protocol'scontrolinputfunctiontobecalled.Redirects

functionpfctlinputiscalled,anditinturncallsthecont

protocolsinthefamily(Internet).TCPandUDParethe

familywithcontrolinputfunctions.



Redirectsarehandledspeciallybecausetheyaffect

destination,notjusttheonethatcausedtheredirect.O

fourerrorsneedonlybeprocessedbytheprotocoltha



ThefinalpointsweneedtomakeaboutFigure22.32

quenchesdifferentlyfromtheothererrors,andredirec

in_pcbnotify:thefunctionin_rtchangeiscalled,regard

theerror.



Figure22.33showsthein_pcbnotifyfunction.Whenit

argumentistheaddressoftcbandthefinalargument

tcp_notify.ForUDP,thesetwoargumentsaretheaddr

thefunctionudp_notify.



Figure22.33.in_pcbnotifyfunction:passerror



Verifyarguments

306-324



Thecmdargumentandtheaddressfamilyofthedestin

addressischeckedtoensureitisnot0.0.0.0.



Handleredirectsspecially

325-338



Iftheerrorisaredirectitishandledspecially.(Theerr

errorthatwasgeneratedbytheIMPs.Currentsystems

ahistoricalartifact.)Theforeignport,localport,andlo

thattheforloopthatfollowswon'tcomparethem.For

selectthePCBstoreceivenotificationbasedonlyonth

thatistheIPaddressforwhichourhostreceivedared

calledforaredirectisin_rtchange(Figure22.34

specifiedbythecaller.



Figure22.34.in_rtchangefunction:in



339



Theglobalarrayinetctlerrmapmapsoneoftheprotoco

PRC_xxxvaluesfromFigure11.19)intoitscorrespond

columninFigure11.1).



CallnotifyfunctionforselectedPCBs

340-353



ThisloopselectsthePCBstobenotified.MultiplePCBs

goingevenafteramatchislocated.Thefirstifstatem

anyoneofthefiveistrue,thePCBisskipped:(1)ifth

unequal,(2)ifthePCBdoesnothaveacorresponding

portsareunequal,(4)ifthelocaladdressesareunequ

unequal.Theforeignaddressesmustmatch,whilethe

elementsarecomparedonlyifthecorrespondingargum

isfound,thenotifyfunctioniscalled.



in_rtchangeFunction



Wesawthatin_pcbnotifycallsthefunctionin_rtchange

redirect.ThisfunctioniscalledforallPCBswithaforei

addressthathasbeenredirected.Figure22.34shows



IfthePCBholdsaroute,thatrouteisreleasedbyrtfre

markedasempty.Wedon'ttrytoupdatetherouteatt

addressreturnedintheredirect.Thenewroutewillbe

thisPCBisusednext,basedonthekernel'sroutingtab



redirect,beforepfctlinputiscalled.



RedirectsandRawSockets



Let'sexaminetheinteractionofredirects,rawsockets,

PCB.IfwerunthePingprogram,whichusesarawsoc

isreceivedfortheIPaddressbeingpinged,Pingcontin

theredirectedroute.Wecanseethisasfollows.



Wepingthehostsvr4onthe140.252.13networkfrom

140.252.1network.Thedefaultrouterforgeminiisga

besenttotherouternetbinstead.Figure22.35



Figure22.35.ExampleofICMP



Weexpectgatewaytosendaredirectwhenitreceives



gemini$ping-svsvr4

PING140.252.13.34:56databytes

ICMPHostredirectfromgateway140.25

tonetb(140.252.1.183)forsvr4(14

64bytesfromsvr4(140.252.13.34):ic



ICMPHostredirectfromgateway140.25

tonetb(140.252.1.183)forsvr4(14

64bytesfromsvr4(140.252.13.34):



The-soptioncausesanICMPechorequesttobesent

optionprintseveryreceivedICMPmessage(insteadof



EveryICMPechorequestelicitsaredirect,buttheraw

noticestheredirecttochangetheroutethatitisusing

calculatedandstoredinthePCB,causingtheIPdatagr

gateway(140.252.1.4),shouldbeupdatedsothatthe

routernetb(140.252.1.183)instead.WeseethattheI

thekernelongemini,buttheyappeartobeignored.



Ifweterminatetheprogramandstartitagain,wenev



gemini$ping-svsvr4

PING140.252.13.34:56databytes

64bytesfromsvr4(140.252.13.34):ic



64bytesfromsvr4(140.252.13.34):ic



ThereasonforthisanomalyisthattherawIPsocketc

acontrolinputfunction.OnlyTCPandUDPhaveacont

redirecterrorisreceived,ICMPupdatesthekernel'sro

pfctlinputiscalled(Figure22.32).Butsincethereisno

rawIPprotocol,thecachedrouteinthePCBassociated

released.WhenwestartthePingprogramasecondtim

allocatedisbasedonthekernel'supdatedroutingtable

redirects.



ICMPErrorsandUDPSockets



OneconfusingpartofthesocketsAPIisthatICMPerro

notpassedtotheapplicationunlesstheapplicationhas

socket,restrictingtheforeignIPaddressandportnum

wherethislimitationisenforcedbyin_pcbnotify.



ConsideranICMPportunreachable,probablythemost

socket.TheforeignIPaddressandtheforeignportnum

in_pcbnotifyaretheIPaddressandportnumberthatc

processhasnotissuedaconnectonthesocket,theinp

ofthePCBareboth0,preventingin_pcbnotifyfromev

thissocket.TheforloopinFigure22.33willskipevery



Thislimitationarisesfortworeasons.First,ifthesend

UDPsocket,theonlynonzeroelementinthesocketpa



assumestheprocessdidnotcallbind.)Thisistheonly

todemultiplextheincomingICMPerrorandpassittot

unlikely,therecouldbemultipleprocessesboundtoth

ambiguouswhichprocessshouldreceivetheerror.The

processthatsentthedatagramthatcausedtheICMPe

anotherprocessthenstartingandusingthesameloca

ephemeralportsareassignedinsequentialorderfrom

aftercyclingaround(Figure22.23).



Thesecondreasonforthislimitationisbecausetheerr

totheprocessanerrnovalueisinadequate.Considera

unconnectedUDPsocketthreetimesinarow,sending

differentdestinations,andthenwaitsforthereplieswi

datagramsgeneratesanICMPportunreachableerror,

thecorrespondingerror(ECONNREFUSED)totherecvf

theerrnovaluedoesn'ttelltheprocesswhichoftheth

ThekernelhasalltheinformationrequiredintheICMP

doesn'tprovideawaytoreturnthistotheprocess.



Thereforethedesigndecisionwasmadethatifaproce

ICMPerrorsonaUDPsocket,thatsocketmustbeconn

errorECONNREFUSEDisreturnedonthatconnectedso

peergeneratedtheerror.



ThereisstillaremotepossibilityofanICMPerrorbeing

process.OneprocesssendstheUDPdatagramthatelic

terminatesbeforetheerrorisreceived.Anotherproces

errorisreceived,bindsthesamelocalport,andconne



andforeignport,causingthisnewprocesstoreceiveth

preventthisfromoccurring,givenUDP'slackofmemo

thiswithitsTIME_WAITstate.



Inourprecedingexample,onewayfortheapplication

tousethreeconnectedUDPsocketsinsteadofoneunc

todeterminewhenanyoneofthethreehasareceived

read.



Herewehaveascenariowherethekernelhastheinf

isinadequate.WithmostimplementationsofUnixSy

API(TLI),thereverseistrue:theTLIfunctiont_rcvu

address,portnumber,andanerrorvalue,butmostS

ofTCP/IPdon'tprovideawayforICMPtopasstheer

endpoint.



Inanidealworld,in_pcbnotifydeliverstheICMPerro

match,eveniftheonlynonwildcardmatchistheloca

theprocesswouldincludethedestinationIPaddress

causedtheerror,allowingtheprocesstodetermineif

datagramsentbytheprocess.



in_losingFunction



ThefinalfunctiondealingwithPCBsisin_losing,shown

TCPwhenitsretransmissiontimerhasexpiredfouror

connection(Figure25.26).



Figure22.36.in_losingfunction:invalidateca



Generateroutingmessage

361-374



IfthePCBholdsaroute,thatrouteisdiscarded.Anrt_

withinformationaboutthecachedroutethatappearst

rt_missmsgisthencalledtogenerateamessagefrom

RTM_LOSING,indicatingaproblemwiththeroute.



Deleteorreleaseroute

375-384



Tài liệu bạn tìm kiếm đã sẵn sàng tải về

11 in_pcbnotify, in_rtchange, and in_losing Functions

Tải bản đầy đủ ngay(0 tr)

×