sm_statefuns.c 209 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /* SCTP kernel implementation
  3. * (C) Copyright IBM Corp. 2001, 2004
  4. * Copyright (c) 1999-2000 Cisco, Inc.
  5. * Copyright (c) 1999-2001 Motorola, Inc.
  6. * Copyright (c) 2001-2002 Intel Corp.
  7. * Copyright (c) 2002 Nokia Corp.
  8. *
  9. * This is part of the SCTP Linux Kernel Implementation.
  10. *
  11. * These are the state functions for the state machine.
  12. *
  13. * Please send any bug reports or fixes you make to the
  14. * email address(es):
  15. * lksctp developers <linux-sctp@vger.kernel.org>
  16. *
  17. * Written or modified by:
  18. * La Monte H.P. Yarroll <piggy@acm.org>
  19. * Karl Knutson <karl@athena.chicago.il.us>
  20. * Mathew Kotowsky <kotowsky@sctp.org>
  21. * Sridhar Samudrala <samudrala@us.ibm.com>
  22. * Jon Grimm <jgrimm@us.ibm.com>
  23. * Hui Huang <hui.huang@nokia.com>
  24. * Dajiang Zhang <dajiang.zhang@nokia.com>
  25. * Daisy Chang <daisyc@us.ibm.com>
  26. * Ardelle Fan <ardelle.fan@intel.com>
  27. * Ryan Layer <rmlayer@us.ibm.com>
  28. * Kevin Gao <kevin.gao@intel.com>
  29. */
  30. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  31. #include <linux/types.h>
  32. #include <linux/kernel.h>
  33. #include <linux/ip.h>
  34. #include <linux/ipv6.h>
  35. #include <linux/net.h>
  36. #include <linux/inet.h>
  37. #include <linux/slab.h>
  38. #include <net/sock.h>
  39. #include <net/proto_memory.h>
  40. #include <net/inet_ecn.h>
  41. #include <linux/skbuff.h>
  42. #include <net/sctp/sctp.h>
  43. #include <net/sctp/sm.h>
  44. #include <net/sctp/structs.h>
  45. #define CREATE_TRACE_POINTS
  46. #include <trace/events/sctp.h>
  47. static struct sctp_packet *sctp_abort_pkt_new(
  48. struct net *net,
  49. const struct sctp_endpoint *ep,
  50. const struct sctp_association *asoc,
  51. struct sctp_chunk *chunk,
  52. const void *payload, size_t paylen);
  53. static int sctp_eat_data(const struct sctp_association *asoc,
  54. struct sctp_chunk *chunk,
  55. struct sctp_cmd_seq *commands);
  56. static struct sctp_packet *sctp_ootb_pkt_new(
  57. struct net *net,
  58. const struct sctp_association *asoc,
  59. const struct sctp_chunk *chunk);
  60. static void sctp_send_stale_cookie_err(struct net *net,
  61. const struct sctp_endpoint *ep,
  62. const struct sctp_association *asoc,
  63. const struct sctp_chunk *chunk,
  64. struct sctp_cmd_seq *commands,
  65. struct sctp_chunk *err_chunk);
  66. static enum sctp_disposition sctp_sf_do_5_2_6_stale(
  67. struct net *net,
  68. const struct sctp_endpoint *ep,
  69. const struct sctp_association *asoc,
  70. const union sctp_subtype type,
  71. void *arg,
  72. struct sctp_cmd_seq *commands);
  73. static enum sctp_disposition sctp_sf_shut_8_4_5(
  74. struct net *net,
  75. const struct sctp_endpoint *ep,
  76. const struct sctp_association *asoc,
  77. const union sctp_subtype type,
  78. void *arg,
  79. struct sctp_cmd_seq *commands);
  80. static enum sctp_disposition sctp_sf_tabort_8_4_8(
  81. struct net *net,
  82. const struct sctp_endpoint *ep,
  83. const struct sctp_association *asoc,
  84. const union sctp_subtype type,
  85. void *arg,
  86. struct sctp_cmd_seq *commands);
  87. static enum sctp_disposition sctp_sf_new_encap_port(
  88. struct net *net,
  89. const struct sctp_endpoint *ep,
  90. const struct sctp_association *asoc,
  91. const union sctp_subtype type,
  92. void *arg,
  93. struct sctp_cmd_seq *commands);
  94. static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk);
  95. static enum sctp_disposition sctp_stop_t1_and_abort(
  96. struct net *net,
  97. struct sctp_cmd_seq *commands,
  98. __be16 error, int sk_err,
  99. const struct sctp_association *asoc,
  100. struct sctp_transport *transport);
  101. static enum sctp_disposition sctp_sf_abort_violation(
  102. struct net *net,
  103. const struct sctp_endpoint *ep,
  104. const struct sctp_association *asoc,
  105. void *arg,
  106. struct sctp_cmd_seq *commands,
  107. const __u8 *payload,
  108. const size_t paylen);
  109. static enum sctp_disposition sctp_sf_violation_chunklen(
  110. struct net *net,
  111. const struct sctp_endpoint *ep,
  112. const struct sctp_association *asoc,
  113. const union sctp_subtype type,
  114. void *arg,
  115. struct sctp_cmd_seq *commands);
  116. static enum sctp_disposition sctp_sf_violation_paramlen(
  117. struct net *net,
  118. const struct sctp_endpoint *ep,
  119. const struct sctp_association *asoc,
  120. const union sctp_subtype type,
  121. void *arg, void *ext,
  122. struct sctp_cmd_seq *commands);
  123. static enum sctp_disposition sctp_sf_violation_ctsn(
  124. struct net *net,
  125. const struct sctp_endpoint *ep,
  126. const struct sctp_association *asoc,
  127. const union sctp_subtype type,
  128. void *arg,
  129. struct sctp_cmd_seq *commands);
  130. static enum sctp_disposition sctp_sf_violation_chunk(
  131. struct net *net,
  132. const struct sctp_endpoint *ep,
  133. const struct sctp_association *asoc,
  134. const union sctp_subtype type,
  135. void *arg,
  136. struct sctp_cmd_seq *commands);
  137. static enum sctp_ierror sctp_sf_authenticate(
  138. const struct sctp_association *asoc,
  139. struct sctp_chunk *chunk);
  140. static enum sctp_disposition __sctp_sf_do_9_1_abort(
  141. struct net *net,
  142. const struct sctp_endpoint *ep,
  143. const struct sctp_association *asoc,
  144. const union sctp_subtype type,
  145. void *arg,
  146. struct sctp_cmd_seq *commands);
  147. static enum sctp_disposition
  148. __sctp_sf_do_9_2_reshutack(struct net *net, const struct sctp_endpoint *ep,
  149. const struct sctp_association *asoc,
  150. const union sctp_subtype type, void *arg,
  151. struct sctp_cmd_seq *commands);
  152. /* Small helper function that checks if the chunk length
  153. * is of the appropriate length. The 'required_length' argument
  154. * is set to be the size of a specific chunk we are testing.
  155. * Return Values: true = Valid length
  156. * false = Invalid length
  157. *
  158. */
  159. static inline bool sctp_chunk_length_valid(struct sctp_chunk *chunk,
  160. __u16 required_length)
  161. {
  162. __u16 chunk_length = ntohs(chunk->chunk_hdr->length);
  163. /* Previously already marked? */
  164. if (unlikely(chunk->pdiscard))
  165. return false;
  166. if (unlikely(chunk_length < required_length))
  167. return false;
  168. return true;
  169. }
  170. /* Check for format error in an ABORT chunk */
  171. static inline bool sctp_err_chunk_valid(struct sctp_chunk *chunk)
  172. {
  173. struct sctp_errhdr *err;
  174. sctp_walk_errors(err, chunk->chunk_hdr);
  175. return (void *)err == (void *)chunk->chunk_end;
  176. }
  177. /**********************************************************
  178. * These are the state functions for handling chunk events.
  179. **********************************************************/
  180. /*
  181. * Process the final SHUTDOWN COMPLETE.
  182. *
  183. * Section: 4 (C) (diagram), 9.2
  184. * Upon reception of the SHUTDOWN COMPLETE chunk the endpoint will verify
  185. * that it is in SHUTDOWN-ACK-SENT state, if it is not the chunk should be
  186. * discarded. If the endpoint is in the SHUTDOWN-ACK-SENT state the endpoint
  187. * should stop the T2-shutdown timer and remove all knowledge of the
  188. * association (and thus the association enters the CLOSED state).
  189. *
  190. * Verification Tag: 8.5.1(C), sctpimpguide 2.41.
  191. * C) Rules for packet carrying SHUTDOWN COMPLETE:
  192. * ...
  193. * - The receiver of a SHUTDOWN COMPLETE shall accept the packet
  194. * if the Verification Tag field of the packet matches its own tag and
  195. * the T bit is not set
  196. * OR
  197. * it is set to its peer's tag and the T bit is set in the Chunk
  198. * Flags.
  199. * Otherwise, the receiver MUST silently discard the packet
  200. * and take no further action. An endpoint MUST ignore the
  201. * SHUTDOWN COMPLETE if it is not in the SHUTDOWN-ACK-SENT state.
  202. *
  203. * Inputs
  204. * (endpoint, asoc, chunk)
  205. *
  206. * Outputs
  207. * (asoc, reply_msg, msg_up, timers, counters)
  208. *
  209. * The return value is the disposition of the chunk.
  210. */
  211. enum sctp_disposition sctp_sf_do_4_C(struct net *net,
  212. const struct sctp_endpoint *ep,
  213. const struct sctp_association *asoc,
  214. const union sctp_subtype type,
  215. void *arg, struct sctp_cmd_seq *commands)
  216. {
  217. struct sctp_chunk *chunk = arg;
  218. struct sctp_ulpevent *ev;
  219. if (!sctp_vtag_verify_either(chunk, asoc))
  220. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  221. /* RFC 2960 6.10 Bundling
  222. *
  223. * An endpoint MUST NOT bundle INIT, INIT ACK or
  224. * SHUTDOWN COMPLETE with any other chunks.
  225. */
  226. if (!chunk->singleton)
  227. return sctp_sf_violation_chunk(net, ep, asoc, type, arg, commands);
  228. /* Make sure that the SHUTDOWN_COMPLETE chunk has a valid length. */
  229. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
  230. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  231. commands);
  232. /* RFC 2960 10.2 SCTP-to-ULP
  233. *
  234. * H) SHUTDOWN COMPLETE notification
  235. *
  236. * When SCTP completes the shutdown procedures (section 9.2) this
  237. * notification is passed to the upper layer.
  238. */
  239. ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
  240. 0, 0, 0, NULL, GFP_ATOMIC);
  241. if (ev)
  242. sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
  243. SCTP_ULPEVENT(ev));
  244. /* Upon reception of the SHUTDOWN COMPLETE chunk the endpoint
  245. * will verify that it is in SHUTDOWN-ACK-SENT state, if it is
  246. * not the chunk should be discarded. If the endpoint is in
  247. * the SHUTDOWN-ACK-SENT state the endpoint should stop the
  248. * T2-shutdown timer and remove all knowledge of the
  249. * association (and thus the association enters the CLOSED
  250. * state).
  251. */
  252. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  253. SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
  254. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  255. SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
  256. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
  257. SCTP_STATE(SCTP_STATE_CLOSED));
  258. SCTP_INC_STATS(net, SCTP_MIB_SHUTDOWNS);
  259. SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
  260. sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
  261. return SCTP_DISPOSITION_DELETE_TCB;
  262. }
  263. /*
  264. * Respond to a normal INIT chunk.
  265. * We are the side that is being asked for an association.
  266. *
  267. * Section: 5.1 Normal Establishment of an Association, B
  268. * B) "Z" shall respond immediately with an INIT ACK chunk. The
  269. * destination IP address of the INIT ACK MUST be set to the source
  270. * IP address of the INIT to which this INIT ACK is responding. In
  271. * the response, besides filling in other parameters, "Z" must set the
  272. * Verification Tag field to Tag_A, and also provide its own
  273. * Verification Tag (Tag_Z) in the Initiate Tag field.
  274. *
  275. * Verification Tag: Must be 0.
  276. *
  277. * Inputs
  278. * (endpoint, asoc, chunk)
  279. *
  280. * Outputs
  281. * (asoc, reply_msg, msg_up, timers, counters)
  282. *
  283. * The return value is the disposition of the chunk.
  284. */
  285. enum sctp_disposition sctp_sf_do_5_1B_init(struct net *net,
  286. const struct sctp_endpoint *ep,
  287. const struct sctp_association *asoc,
  288. const union sctp_subtype type,
  289. void *arg,
  290. struct sctp_cmd_seq *commands)
  291. {
  292. struct sctp_chunk *chunk = arg, *repl, *err_chunk;
  293. struct sctp_unrecognized_param *unk_param;
  294. struct sctp_association *new_asoc;
  295. struct sctp_packet *packet;
  296. int len;
  297. /* 6.10 Bundling
  298. * An endpoint MUST NOT bundle INIT, INIT ACK or
  299. * SHUTDOWN COMPLETE with any other chunks.
  300. *
  301. * IG Section 2.11.2
  302. * Furthermore, we require that the receiver of an INIT chunk MUST
  303. * enforce these rules by silently discarding an arriving packet
  304. * with an INIT chunk that is bundled with other chunks.
  305. */
  306. if (!chunk->singleton)
  307. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  308. /* Make sure that the INIT chunk has a valid length.
  309. * Normally, this would cause an ABORT with a Protocol Violation
  310. * error, but since we don't have an association, we'll
  311. * just discard the packet.
  312. */
  313. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_init_chunk)))
  314. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  315. /* If the packet is an OOTB packet which is temporarily on the
  316. * control endpoint, respond with an ABORT.
  317. */
  318. if (ep == sctp_sk(net->sctp.ctl_sock)->ep) {
  319. SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES);
  320. return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
  321. }
  322. /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
  323. * Tag.
  324. */
  325. if (chunk->sctp_hdr->vtag != 0)
  326. return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
  327. /* If the INIT is coming toward a closing socket, we'll send back
  328. * and ABORT. Essentially, this catches the race of INIT being
  329. * backloged to the socket at the same time as the user issues close().
  330. * Since the socket and all its associations are going away, we
  331. * can treat this OOTB
  332. */
  333. if (sctp_sstate(ep->base.sk, CLOSING))
  334. return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
  335. /* Verify the INIT chunk before processing it. */
  336. err_chunk = NULL;
  337. if (!sctp_verify_init(net, ep, asoc, chunk->chunk_hdr->type,
  338. (struct sctp_init_chunk *)chunk->chunk_hdr, chunk,
  339. &err_chunk)) {
  340. /* This chunk contains fatal error. It is to be discarded.
  341. * Send an ABORT, with causes if there is any.
  342. */
  343. if (err_chunk) {
  344. packet = sctp_abort_pkt_new(net, ep, asoc, arg,
  345. (__u8 *)(err_chunk->chunk_hdr) +
  346. sizeof(struct sctp_chunkhdr),
  347. ntohs(err_chunk->chunk_hdr->length) -
  348. sizeof(struct sctp_chunkhdr));
  349. sctp_chunk_free(err_chunk);
  350. if (packet) {
  351. sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
  352. SCTP_PACKET(packet));
  353. SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
  354. return SCTP_DISPOSITION_CONSUME;
  355. } else {
  356. return SCTP_DISPOSITION_NOMEM;
  357. }
  358. } else {
  359. return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg,
  360. commands);
  361. }
  362. }
  363. /* Grab the INIT header. */
  364. chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data;
  365. /* Tag the variable length parameters. */
  366. chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(struct sctp_inithdr));
  367. new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
  368. if (!new_asoc)
  369. goto nomem;
  370. /* Update socket peer label if first association. */
  371. if (security_sctp_assoc_request(new_asoc, chunk->skb)) {
  372. sctp_association_free(new_asoc);
  373. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  374. }
  375. if (sctp_assoc_set_bind_addr_from_ep(new_asoc,
  376. sctp_scope(sctp_source(chunk)),
  377. GFP_ATOMIC) < 0)
  378. goto nomem_init;
  379. /* The call, sctp_process_init(), can fail on memory allocation. */
  380. if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk),
  381. (struct sctp_init_chunk *)chunk->chunk_hdr,
  382. GFP_ATOMIC))
  383. goto nomem_init;
  384. /* B) "Z" shall respond immediately with an INIT ACK chunk. */
  385. /* If there are errors need to be reported for unknown parameters,
  386. * make sure to reserve enough room in the INIT ACK for them.
  387. */
  388. len = 0;
  389. if (err_chunk)
  390. len = ntohs(err_chunk->chunk_hdr->length) -
  391. sizeof(struct sctp_chunkhdr);
  392. repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
  393. if (!repl)
  394. goto nomem_init;
  395. /* If there are errors need to be reported for unknown parameters,
  396. * include them in the outgoing INIT ACK as "Unrecognized parameter"
  397. * parameter.
  398. */
  399. if (err_chunk) {
  400. /* Get the "Unrecognized parameter" parameter(s) out of the
  401. * ERROR chunk generated by sctp_verify_init(). Since the
  402. * error cause code for "unknown parameter" and the
  403. * "Unrecognized parameter" type is the same, we can
  404. * construct the parameters in INIT ACK by copying the
  405. * ERROR causes over.
  406. */
  407. unk_param = (struct sctp_unrecognized_param *)
  408. ((__u8 *)(err_chunk->chunk_hdr) +
  409. sizeof(struct sctp_chunkhdr));
  410. /* Replace the cause code with the "Unrecognized parameter"
  411. * parameter type.
  412. */
  413. sctp_addto_chunk(repl, len, unk_param);
  414. sctp_chunk_free(err_chunk);
  415. }
  416. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
  417. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
  418. /*
  419. * Note: After sending out INIT ACK with the State Cookie parameter,
  420. * "Z" MUST NOT allocate any resources, nor keep any states for the
  421. * new association. Otherwise, "Z" will be vulnerable to resource
  422. * attacks.
  423. */
  424. sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
  425. return SCTP_DISPOSITION_DELETE_TCB;
  426. nomem_init:
  427. sctp_association_free(new_asoc);
  428. nomem:
  429. if (err_chunk)
  430. sctp_chunk_free(err_chunk);
  431. return SCTP_DISPOSITION_NOMEM;
  432. }
  433. /*
  434. * Respond to a normal INIT ACK chunk.
  435. * We are the side that is initiating the association.
  436. *
  437. * Section: 5.1 Normal Establishment of an Association, C
  438. * C) Upon reception of the INIT ACK from "Z", "A" shall stop the T1-init
  439. * timer and leave COOKIE-WAIT state. "A" shall then send the State
  440. * Cookie received in the INIT ACK chunk in a COOKIE ECHO chunk, start
  441. * the T1-cookie timer, and enter the COOKIE-ECHOED state.
  442. *
  443. * Note: The COOKIE ECHO chunk can be bundled with any pending outbound
  444. * DATA chunks, but it MUST be the first chunk in the packet and
  445. * until the COOKIE ACK is returned the sender MUST NOT send any
  446. * other packets to the peer.
  447. *
  448. * Verification Tag: 3.3.3
  449. * If the value of the Initiate Tag in a received INIT ACK chunk is
  450. * found to be 0, the receiver MUST treat it as an error and close the
  451. * association by transmitting an ABORT.
  452. *
  453. * Inputs
  454. * (endpoint, asoc, chunk)
  455. *
  456. * Outputs
  457. * (asoc, reply_msg, msg_up, timers, counters)
  458. *
  459. * The return value is the disposition of the chunk.
  460. */
  461. enum sctp_disposition sctp_sf_do_5_1C_ack(struct net *net,
  462. const struct sctp_endpoint *ep,
  463. const struct sctp_association *asoc,
  464. const union sctp_subtype type,
  465. void *arg,
  466. struct sctp_cmd_seq *commands)
  467. {
  468. struct sctp_init_chunk *initchunk;
  469. struct sctp_chunk *chunk = arg;
  470. struct sctp_chunk *err_chunk;
  471. struct sctp_packet *packet;
  472. if (!sctp_vtag_verify(chunk, asoc))
  473. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  474. /* 6.10 Bundling
  475. * An endpoint MUST NOT bundle INIT, INIT ACK or
  476. * SHUTDOWN COMPLETE with any other chunks.
  477. */
  478. if (!chunk->singleton)
  479. return sctp_sf_violation_chunk(net, ep, asoc, type, arg, commands);
  480. /* Make sure that the INIT-ACK chunk has a valid length */
  481. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_initack_chunk)))
  482. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  483. commands);
  484. /* Grab the INIT header. */
  485. chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data;
  486. /* Verify the INIT chunk before processing it. */
  487. err_chunk = NULL;
  488. if (!sctp_verify_init(net, ep, asoc, chunk->chunk_hdr->type,
  489. (struct sctp_init_chunk *)chunk->chunk_hdr, chunk,
  490. &err_chunk)) {
  491. enum sctp_error error = SCTP_ERROR_NO_RESOURCE;
  492. /* This chunk contains fatal error. It is to be discarded.
  493. * Send an ABORT, with causes. If there are no causes,
  494. * then there wasn't enough memory. Just terminate
  495. * the association.
  496. */
  497. if (err_chunk) {
  498. packet = sctp_abort_pkt_new(net, ep, asoc, arg,
  499. (__u8 *)(err_chunk->chunk_hdr) +
  500. sizeof(struct sctp_chunkhdr),
  501. ntohs(err_chunk->chunk_hdr->length) -
  502. sizeof(struct sctp_chunkhdr));
  503. sctp_chunk_free(err_chunk);
  504. if (packet) {
  505. sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
  506. SCTP_PACKET(packet));
  507. SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
  508. error = SCTP_ERROR_INV_PARAM;
  509. }
  510. }
  511. /* SCTP-AUTH, Section 6.3:
  512. * It should be noted that if the receiver wants to tear
  513. * down an association in an authenticated way only, the
  514. * handling of malformed packets should not result in
  515. * tearing down the association.
  516. *
  517. * This means that if we only want to abort associations
  518. * in an authenticated way (i.e AUTH+ABORT), then we
  519. * can't destroy this association just because the packet
  520. * was malformed.
  521. */
  522. if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
  523. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  524. SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
  525. return sctp_stop_t1_and_abort(net, commands, error, ECONNREFUSED,
  526. asoc, chunk->transport);
  527. }
  528. /* Tag the variable length parameters. Note that we never
  529. * convert the parameters in an INIT chunk.
  530. */
  531. chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(struct sctp_inithdr));
  532. initchunk = (struct sctp_init_chunk *)chunk->chunk_hdr;
  533. sctp_add_cmd_sf(commands, SCTP_CMD_PEER_INIT,
  534. SCTP_PEER_INIT(initchunk));
  535. /* Reset init error count upon receipt of INIT-ACK. */
  536. sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
  537. /* 5.1 C) "A" shall stop the T1-init timer and leave
  538. * COOKIE-WAIT state. "A" shall then ... start the T1-cookie
  539. * timer, and enter the COOKIE-ECHOED state.
  540. */
  541. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  542. SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
  543. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
  544. SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
  545. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
  546. SCTP_STATE(SCTP_STATE_COOKIE_ECHOED));
  547. /* SCTP-AUTH: generate the association shared keys so that
  548. * we can potentially sign the COOKIE-ECHO.
  549. */
  550. sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_SHKEY, SCTP_NULL());
  551. /* 5.1 C) "A" shall then send the State Cookie received in the
  552. * INIT ACK chunk in a COOKIE ECHO chunk, ...
  553. */
  554. /* If there is any errors to report, send the ERROR chunk generated
  555. * for unknown parameters as well.
  556. */
  557. sctp_add_cmd_sf(commands, SCTP_CMD_GEN_COOKIE_ECHO,
  558. SCTP_CHUNK(err_chunk));
  559. return SCTP_DISPOSITION_CONSUME;
  560. }
  561. static bool sctp_auth_chunk_verify(struct net *net, struct sctp_chunk *chunk,
  562. const struct sctp_association *asoc)
  563. {
  564. struct sctp_chunk auth;
  565. if (!chunk->auth_chunk)
  566. return true;
  567. /* SCTP-AUTH: auth_chunk pointer is only set when the cookie-echo
  568. * is supposed to be authenticated and we have to do delayed
  569. * authentication. We've just recreated the association using
  570. * the information in the cookie and now it's much easier to
  571. * do the authentication.
  572. */
  573. /* Make sure that we and the peer are AUTH capable */
  574. if (!net->sctp.auth_enable || !asoc->peer.auth_capable)
  575. return false;
  576. /* set-up our fake chunk so that we can process it */
  577. auth.skb = chunk->auth_chunk;
  578. auth.asoc = chunk->asoc;
  579. auth.sctp_hdr = chunk->sctp_hdr;
  580. auth.chunk_hdr = (struct sctp_chunkhdr *)
  581. skb_push(chunk->auth_chunk,
  582. sizeof(struct sctp_chunkhdr));
  583. skb_pull(chunk->auth_chunk, sizeof(struct sctp_chunkhdr));
  584. auth.transport = chunk->transport;
  585. return sctp_sf_authenticate(asoc, &auth) == SCTP_IERROR_NO_ERROR;
  586. }
  587. /*
  588. * Respond to a normal COOKIE ECHO chunk.
  589. * We are the side that is being asked for an association.
  590. *
  591. * Section: 5.1 Normal Establishment of an Association, D
  592. * D) Upon reception of the COOKIE ECHO chunk, Endpoint "Z" will reply
  593. * with a COOKIE ACK chunk after building a TCB and moving to
  594. * the ESTABLISHED state. A COOKIE ACK chunk may be bundled with
  595. * any pending DATA chunks (and/or SACK chunks), but the COOKIE ACK
  596. * chunk MUST be the first chunk in the packet.
  597. *
  598. * IMPLEMENTATION NOTE: An implementation may choose to send the
  599. * Communication Up notification to the SCTP user upon reception
  600. * of a valid COOKIE ECHO chunk.
  601. *
  602. * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
  603. * D) Rules for packet carrying a COOKIE ECHO
  604. *
  605. * - When sending a COOKIE ECHO, the endpoint MUST use the value of the
  606. * Initial Tag received in the INIT ACK.
  607. *
  608. * - The receiver of a COOKIE ECHO follows the procedures in Section 5.
  609. *
  610. * Inputs
  611. * (endpoint, asoc, chunk)
  612. *
  613. * Outputs
  614. * (asoc, reply_msg, msg_up, timers, counters)
  615. *
  616. * The return value is the disposition of the chunk.
  617. */
  618. enum sctp_disposition sctp_sf_do_5_1D_ce(struct net *net,
  619. const struct sctp_endpoint *ep,
  620. const struct sctp_association *asoc,
  621. const union sctp_subtype type,
  622. void *arg,
  623. struct sctp_cmd_seq *commands)
  624. {
  625. struct sctp_ulpevent *ev, *ai_ev = NULL, *auth_ev = NULL;
  626. struct sctp_association *new_asoc;
  627. struct sctp_init_chunk *peer_init;
  628. struct sctp_chunk *chunk = arg;
  629. struct sctp_chunk *err_chk_p;
  630. struct sctp_chunk *repl;
  631. struct sock *sk;
  632. int error = 0;
  633. if (asoc && !sctp_vtag_verify(chunk, asoc))
  634. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  635. /* If the packet is an OOTB packet which is temporarily on the
  636. * control endpoint, respond with an ABORT.
  637. */
  638. if (ep == sctp_sk(net->sctp.ctl_sock)->ep) {
  639. SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES);
  640. return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
  641. }
  642. /* Make sure that the COOKIE_ECHO chunk has a valid length.
  643. * In this case, we check that we have enough for at least a
  644. * chunk header. More detailed verification is done
  645. * in sctp_unpack_cookie().
  646. */
  647. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
  648. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  649. commands);
  650. /* If the endpoint is not listening or if the number of associations
  651. * on the TCP-style socket exceed the max backlog, respond with an
  652. * ABORT.
  653. */
  654. sk = ep->base.sk;
  655. if (!sctp_sstate(sk, LISTENING) ||
  656. (sctp_style(sk, TCP) && sk_acceptq_is_full(sk)))
  657. return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
  658. /* "Decode" the chunk. We have no optional parameters so we
  659. * are in good shape.
  660. */
  661. chunk->subh.cookie_hdr =
  662. (struct sctp_signed_cookie *)chunk->skb->data;
  663. if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
  664. sizeof(struct sctp_chunkhdr)))
  665. goto nomem;
  666. /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint
  667. * "Z" will reply with a COOKIE ACK chunk after building a TCB
  668. * and moving to the ESTABLISHED state.
  669. */
  670. new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
  671. &err_chk_p);
  672. /* FIXME:
  673. * If the re-build failed, what is the proper error path
  674. * from here?
  675. *
  676. * [We should abort the association. --piggy]
  677. */
  678. if (!new_asoc) {
  679. /* FIXME: Several errors are possible. A bad cookie should
  680. * be silently discarded, but think about logging it too.
  681. */
  682. switch (error) {
  683. case -SCTP_IERROR_NOMEM:
  684. goto nomem;
  685. case -SCTP_IERROR_STALE_COOKIE:
  686. sctp_send_stale_cookie_err(net, ep, asoc, chunk, commands,
  687. err_chk_p);
  688. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  689. case -SCTP_IERROR_BAD_SIG:
  690. default:
  691. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  692. }
  693. }
  694. if (security_sctp_assoc_request(new_asoc, chunk->head_skb ?: chunk->skb)) {
  695. sctp_association_free(new_asoc);
  696. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  697. }
  698. /* Delay state machine commands until later.
  699. *
  700. * Re-build the bind address for the association is done in
  701. * the sctp_unpack_cookie() already.
  702. */
  703. /* This is a brand-new association, so these are not yet side
  704. * effects--it is safe to run them here.
  705. */
  706. peer_init = (struct sctp_init_chunk *)(chunk->subh.cookie_hdr + 1);
  707. if (!sctp_process_init(new_asoc, chunk,
  708. &chunk->subh.cookie_hdr->c.peer_addr,
  709. peer_init, GFP_ATOMIC))
  710. goto nomem_init;
  711. /* SCTP-AUTH: Now that we've populate required fields in
  712. * sctp_process_init, set up the association shared keys as
  713. * necessary so that we can potentially authenticate the ACK
  714. */
  715. error = sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC);
  716. if (error)
  717. goto nomem_init;
  718. if (!sctp_auth_chunk_verify(net, chunk, new_asoc)) {
  719. sctp_association_free(new_asoc);
  720. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  721. }
  722. repl = sctp_make_cookie_ack(new_asoc, chunk);
  723. if (!repl)
  724. goto nomem_init;
  725. /* RFC 2960 5.1 Normal Establishment of an Association
  726. *
  727. * D) IMPLEMENTATION NOTE: An implementation may choose to
  728. * send the Communication Up notification to the SCTP user
  729. * upon reception of a valid COOKIE ECHO chunk.
  730. */
  731. ev = sctp_ulpevent_make_assoc_change(new_asoc, 0, SCTP_COMM_UP, 0,
  732. new_asoc->c.sinit_num_ostreams,
  733. new_asoc->c.sinit_max_instreams,
  734. NULL, GFP_ATOMIC);
  735. if (!ev)
  736. goto nomem_ev;
  737. /* Sockets API Draft Section 5.3.1.6
  738. * When a peer sends a Adaptation Layer Indication parameter , SCTP
  739. * delivers this notification to inform the application that of the
  740. * peers requested adaptation layer.
  741. */
  742. if (new_asoc->peer.adaptation_ind) {
  743. ai_ev = sctp_ulpevent_make_adaptation_indication(new_asoc,
  744. GFP_ATOMIC);
  745. if (!ai_ev)
  746. goto nomem_aiev;
  747. }
  748. if (!new_asoc->peer.auth_capable) {
  749. auth_ev = sctp_ulpevent_make_authkey(new_asoc, 0,
  750. SCTP_AUTH_NO_AUTH,
  751. GFP_ATOMIC);
  752. if (!auth_ev)
  753. goto nomem_authev;
  754. }
  755. /* Add all the state machine commands now since we've created
  756. * everything. This way we don't introduce memory corruptions
  757. * during side-effect processing and correctly count established
  758. * associations.
  759. */
  760. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
  761. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
  762. SCTP_STATE(SCTP_STATE_ESTABLISHED));
  763. SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB);
  764. SCTP_INC_STATS(net, SCTP_MIB_PASSIVEESTABS);
  765. sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
  766. if (new_asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE])
  767. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
  768. SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
  769. /* This will send the COOKIE ACK */
  770. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
  771. /* Queue the ASSOC_CHANGE event */
  772. sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
  773. /* Send up the Adaptation Layer Indication event */
  774. if (ai_ev)
  775. sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
  776. SCTP_ULPEVENT(ai_ev));
  777. if (auth_ev)
  778. sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
  779. SCTP_ULPEVENT(auth_ev));
  780. return SCTP_DISPOSITION_CONSUME;
  781. nomem_authev:
  782. sctp_ulpevent_free(ai_ev);
  783. nomem_aiev:
  784. sctp_ulpevent_free(ev);
  785. nomem_ev:
  786. sctp_chunk_free(repl);
  787. nomem_init:
  788. sctp_association_free(new_asoc);
  789. nomem:
  790. return SCTP_DISPOSITION_NOMEM;
  791. }
  792. /*
  793. * Respond to a normal COOKIE ACK chunk.
  794. * We are the side that is asking for an association.
  795. *
  796. * RFC 2960 5.1 Normal Establishment of an Association
  797. *
  798. * E) Upon reception of the COOKIE ACK, endpoint "A" will move from the
  799. * COOKIE-ECHOED state to the ESTABLISHED state, stopping the T1-cookie
  800. * timer. It may also notify its ULP about the successful
  801. * establishment of the association with a Communication Up
  802. * notification (see Section 10).
  803. *
  804. * Verification Tag:
  805. * Inputs
  806. * (endpoint, asoc, chunk)
  807. *
  808. * Outputs
  809. * (asoc, reply_msg, msg_up, timers, counters)
  810. *
  811. * The return value is the disposition of the chunk.
  812. */
  813. enum sctp_disposition sctp_sf_do_5_1E_ca(struct net *net,
  814. const struct sctp_endpoint *ep,
  815. const struct sctp_association *asoc,
  816. const union sctp_subtype type,
  817. void *arg,
  818. struct sctp_cmd_seq *commands)
  819. {
  820. struct sctp_chunk *chunk = arg;
  821. struct sctp_ulpevent *ev;
  822. if (!sctp_vtag_verify(chunk, asoc))
  823. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  824. /* Set peer label for connection. */
  825. if (security_sctp_assoc_established((struct sctp_association *)asoc,
  826. chunk->head_skb ?: chunk->skb))
  827. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  828. /* Verify that the chunk length for the COOKIE-ACK is OK.
  829. * If we don't do this, any bundled chunks may be junked.
  830. */
  831. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
  832. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  833. commands);
  834. /* Reset init error count upon receipt of COOKIE-ACK,
  835. * to avoid problems with the management of this
  836. * counter in stale cookie situations when a transition back
  837. * from the COOKIE-ECHOED state to the COOKIE-WAIT
  838. * state is performed.
  839. */
  840. sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_RESET, SCTP_NULL());
  841. /* RFC 2960 5.1 Normal Establishment of an Association
  842. *
  843. * E) Upon reception of the COOKIE ACK, endpoint "A" will move
  844. * from the COOKIE-ECHOED state to the ESTABLISHED state,
  845. * stopping the T1-cookie timer.
  846. */
  847. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  848. SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
  849. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
  850. SCTP_STATE(SCTP_STATE_ESTABLISHED));
  851. SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB);
  852. SCTP_INC_STATS(net, SCTP_MIB_ACTIVEESTABS);
  853. sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
  854. if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE])
  855. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
  856. SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
  857. /* It may also notify its ULP about the successful
  858. * establishment of the association with a Communication Up
  859. * notification (see Section 10).
  860. */
  861. ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_COMM_UP,
  862. 0, asoc->c.sinit_num_ostreams,
  863. asoc->c.sinit_max_instreams,
  864. NULL, GFP_ATOMIC);
  865. if (!ev)
  866. goto nomem;
  867. sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
  868. /* Sockets API Draft Section 5.3.1.6
  869. * When a peer sends a Adaptation Layer Indication parameter , SCTP
  870. * delivers this notification to inform the application that of the
  871. * peers requested adaptation layer.
  872. */
  873. if (asoc->peer.adaptation_ind) {
  874. ev = sctp_ulpevent_make_adaptation_indication(asoc, GFP_ATOMIC);
  875. if (!ev)
  876. goto nomem;
  877. sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
  878. SCTP_ULPEVENT(ev));
  879. }
  880. if (!asoc->peer.auth_capable) {
  881. ev = sctp_ulpevent_make_authkey(asoc, 0, SCTP_AUTH_NO_AUTH,
  882. GFP_ATOMIC);
  883. if (!ev)
  884. goto nomem;
  885. sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
  886. SCTP_ULPEVENT(ev));
  887. }
  888. return SCTP_DISPOSITION_CONSUME;
  889. nomem:
  890. return SCTP_DISPOSITION_NOMEM;
  891. }
  892. /* Generate and sendout a heartbeat packet. */
  893. static enum sctp_disposition sctp_sf_heartbeat(
  894. const struct sctp_endpoint *ep,
  895. const struct sctp_association *asoc,
  896. const union sctp_subtype type,
  897. void *arg,
  898. struct sctp_cmd_seq *commands)
  899. {
  900. struct sctp_transport *transport = (struct sctp_transport *) arg;
  901. struct sctp_chunk *reply;
  902. /* Send a heartbeat to our peer. */
  903. reply = sctp_make_heartbeat(asoc, transport, 0);
  904. if (!reply)
  905. return SCTP_DISPOSITION_NOMEM;
  906. /* Set rto_pending indicating that an RTT measurement
  907. * is started with this heartbeat chunk.
  908. */
  909. sctp_add_cmd_sf(commands, SCTP_CMD_RTO_PENDING,
  910. SCTP_TRANSPORT(transport));
  911. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
  912. return SCTP_DISPOSITION_CONSUME;
  913. }
  914. /* Generate a HEARTBEAT packet on the given transport. */
  915. enum sctp_disposition sctp_sf_sendbeat_8_3(struct net *net,
  916. const struct sctp_endpoint *ep,
  917. const struct sctp_association *asoc,
  918. const union sctp_subtype type,
  919. void *arg,
  920. struct sctp_cmd_seq *commands)
  921. {
  922. struct sctp_transport *transport = (struct sctp_transport *) arg;
  923. if (asoc->overall_error_count >= asoc->max_retrans) {
  924. sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
  925. SCTP_ERROR(ETIMEDOUT));
  926. /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
  927. sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
  928. SCTP_PERR(SCTP_ERROR_NO_ERROR));
  929. SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
  930. SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
  931. return SCTP_DISPOSITION_DELETE_TCB;
  932. }
  933. /* Section 3.3.5.
  934. * The Sender-specific Heartbeat Info field should normally include
  935. * information about the sender's current time when this HEARTBEAT
  936. * chunk is sent and the destination transport address to which this
  937. * HEARTBEAT is sent (see Section 8.3).
  938. */
  939. if (transport->param_flags & SPP_HB_ENABLE) {
  940. if (SCTP_DISPOSITION_NOMEM ==
  941. sctp_sf_heartbeat(ep, asoc, type, arg,
  942. commands))
  943. return SCTP_DISPOSITION_NOMEM;
  944. /* Set transport error counter and association error counter
  945. * when sending heartbeat.
  946. */
  947. sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_HB_SENT,
  948. SCTP_TRANSPORT(transport));
  949. }
  950. sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_IDLE,
  951. SCTP_TRANSPORT(transport));
  952. sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMER_UPDATE,
  953. SCTP_TRANSPORT(transport));
  954. return SCTP_DISPOSITION_CONSUME;
  955. }
  956. /* resend asoc strreset_chunk. */
  957. enum sctp_disposition sctp_sf_send_reconf(struct net *net,
  958. const struct sctp_endpoint *ep,
  959. const struct sctp_association *asoc,
  960. const union sctp_subtype type,
  961. void *arg,
  962. struct sctp_cmd_seq *commands)
  963. {
  964. struct sctp_transport *transport = arg;
  965. if (asoc->overall_error_count >= asoc->max_retrans) {
  966. sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
  967. SCTP_ERROR(ETIMEDOUT));
  968. /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
  969. sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
  970. SCTP_PERR(SCTP_ERROR_NO_ERROR));
  971. SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
  972. SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
  973. return SCTP_DISPOSITION_DELETE_TCB;
  974. }
  975. sctp_chunk_hold(asoc->strreset_chunk);
  976. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
  977. SCTP_CHUNK(asoc->strreset_chunk));
  978. sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
  979. return SCTP_DISPOSITION_CONSUME;
  980. }
  981. /* send hb chunk with padding for PLPMUTD. */
  982. enum sctp_disposition sctp_sf_send_probe(struct net *net,
  983. const struct sctp_endpoint *ep,
  984. const struct sctp_association *asoc,
  985. const union sctp_subtype type,
  986. void *arg,
  987. struct sctp_cmd_seq *commands)
  988. {
  989. struct sctp_transport *transport = (struct sctp_transport *)arg;
  990. struct sctp_chunk *reply;
  991. if (!sctp_transport_pl_enabled(transport))
  992. return SCTP_DISPOSITION_CONSUME;
  993. sctp_transport_pl_send(transport);
  994. reply = sctp_make_heartbeat(asoc, transport, transport->pl.probe_size);
  995. if (!reply)
  996. return SCTP_DISPOSITION_NOMEM;
  997. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
  998. sctp_add_cmd_sf(commands, SCTP_CMD_PROBE_TIMER_UPDATE,
  999. SCTP_TRANSPORT(transport));
  1000. return SCTP_DISPOSITION_CONSUME;
  1001. }
  1002. /*
  1003. * Process an heartbeat request.
  1004. *
  1005. * Section: 8.3 Path Heartbeat
  1006. * The receiver of the HEARTBEAT should immediately respond with a
  1007. * HEARTBEAT ACK that contains the Heartbeat Information field copied
  1008. * from the received HEARTBEAT chunk.
  1009. *
  1010. * Verification Tag: 8.5 Verification Tag [Normal verification]
  1011. * When receiving an SCTP packet, the endpoint MUST ensure that the
  1012. * value in the Verification Tag field of the received SCTP packet
  1013. * matches its own Tag. If the received Verification Tag value does not
  1014. * match the receiver's own tag value, the receiver shall silently
  1015. * discard the packet and shall not process it any further except for
  1016. * those cases listed in Section 8.5.1 below.
  1017. *
  1018. * Inputs
  1019. * (endpoint, asoc, chunk)
  1020. *
  1021. * Outputs
  1022. * (asoc, reply_msg, msg_up, timers, counters)
  1023. *
  1024. * The return value is the disposition of the chunk.
  1025. */
  1026. enum sctp_disposition sctp_sf_beat_8_3(struct net *net,
  1027. const struct sctp_endpoint *ep,
  1028. const struct sctp_association *asoc,
  1029. const union sctp_subtype type,
  1030. void *arg, struct sctp_cmd_seq *commands)
  1031. {
  1032. struct sctp_paramhdr *param_hdr;
  1033. struct sctp_chunk *chunk = arg;
  1034. struct sctp_chunk *reply;
  1035. size_t paylen = 0;
  1036. if (!sctp_vtag_verify(chunk, asoc))
  1037. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  1038. /* Make sure that the HEARTBEAT chunk has a valid length. */
  1039. if (!sctp_chunk_length_valid(chunk,
  1040. sizeof(struct sctp_heartbeat_chunk)))
  1041. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  1042. commands);
  1043. /* 8.3 The receiver of the HEARTBEAT should immediately
  1044. * respond with a HEARTBEAT ACK that contains the Heartbeat
  1045. * Information field copied from the received HEARTBEAT chunk.
  1046. */
  1047. chunk->subh.hb_hdr = (struct sctp_heartbeathdr *)chunk->skb->data;
  1048. param_hdr = (struct sctp_paramhdr *)chunk->subh.hb_hdr;
  1049. paylen = ntohs(chunk->chunk_hdr->length) - sizeof(struct sctp_chunkhdr);
  1050. if (ntohs(param_hdr->length) > paylen)
  1051. return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
  1052. param_hdr, commands);
  1053. if (!pskb_pull(chunk->skb, paylen))
  1054. goto nomem;
  1055. reply = sctp_make_heartbeat_ack(asoc, chunk, param_hdr, paylen);
  1056. if (!reply)
  1057. goto nomem;
  1058. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
  1059. return SCTP_DISPOSITION_CONSUME;
  1060. nomem:
  1061. return SCTP_DISPOSITION_NOMEM;
  1062. }
  1063. /*
  1064. * Process the returning HEARTBEAT ACK.
  1065. *
  1066. * Section: 8.3 Path Heartbeat
  1067. * Upon the receipt of the HEARTBEAT ACK, the sender of the HEARTBEAT
  1068. * should clear the error counter of the destination transport
  1069. * address to which the HEARTBEAT was sent, and mark the destination
  1070. * transport address as active if it is not so marked. The endpoint may
  1071. * optionally report to the upper layer when an inactive destination
  1072. * address is marked as active due to the reception of the latest
  1073. * HEARTBEAT ACK. The receiver of the HEARTBEAT ACK must also
  1074. * clear the association overall error count as well (as defined
  1075. * in section 8.1).
  1076. *
  1077. * The receiver of the HEARTBEAT ACK should also perform an RTT
  1078. * measurement for that destination transport address using the time
  1079. * value carried in the HEARTBEAT ACK chunk.
  1080. *
  1081. * Verification Tag: 8.5 Verification Tag [Normal verification]
  1082. *
  1083. * Inputs
  1084. * (endpoint, asoc, chunk)
  1085. *
  1086. * Outputs
  1087. * (asoc, reply_msg, msg_up, timers, counters)
  1088. *
  1089. * The return value is the disposition of the chunk.
  1090. */
  1091. enum sctp_disposition sctp_sf_backbeat_8_3(struct net *net,
  1092. const struct sctp_endpoint *ep,
  1093. const struct sctp_association *asoc,
  1094. const union sctp_subtype type,
  1095. void *arg,
  1096. struct sctp_cmd_seq *commands)
  1097. {
  1098. struct sctp_sender_hb_info *hbinfo;
  1099. struct sctp_chunk *chunk = arg;
  1100. struct sctp_transport *link;
  1101. unsigned long max_interval;
  1102. union sctp_addr from_addr;
  1103. if (!sctp_vtag_verify(chunk, asoc))
  1104. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  1105. /* Make sure that the HEARTBEAT-ACK chunk has a valid length. */
  1106. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr) +
  1107. sizeof(*hbinfo)))
  1108. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  1109. commands);
  1110. hbinfo = (struct sctp_sender_hb_info *)chunk->skb->data;
  1111. /* Make sure that the length of the parameter is what we expect */
  1112. if (ntohs(hbinfo->param_hdr.length) != sizeof(*hbinfo))
  1113. return SCTP_DISPOSITION_DISCARD;
  1114. from_addr = hbinfo->daddr;
  1115. link = sctp_assoc_lookup_paddr(asoc, &from_addr);
  1116. /* This should never happen, but lets log it if so. */
  1117. if (unlikely(!link)) {
  1118. if (from_addr.sa.sa_family == AF_INET6) {
  1119. net_warn_ratelimited("%s association %p could not find address %pI6\n",
  1120. __func__,
  1121. asoc,
  1122. &from_addr.v6.sin6_addr);
  1123. } else {
  1124. net_warn_ratelimited("%s association %p could not find address %pI4\n",
  1125. __func__,
  1126. asoc,
  1127. &from_addr.v4.sin_addr.s_addr);
  1128. }
  1129. return SCTP_DISPOSITION_DISCARD;
  1130. }
  1131. /* Validate the 64-bit random nonce. */
  1132. if (hbinfo->hb_nonce != link->hb_nonce)
  1133. return SCTP_DISPOSITION_DISCARD;
  1134. if (hbinfo->probe_size) {
  1135. if (hbinfo->probe_size != link->pl.probe_size ||
  1136. !sctp_transport_pl_enabled(link))
  1137. return SCTP_DISPOSITION_DISCARD;
  1138. if (sctp_transport_pl_recv(link))
  1139. return SCTP_DISPOSITION_CONSUME;
  1140. return sctp_sf_send_probe(net, ep, asoc, type, link, commands);
  1141. }
  1142. max_interval = link->hbinterval + link->rto;
  1143. /* Check if the timestamp looks valid. */
  1144. if (time_after(hbinfo->sent_at, jiffies) ||
  1145. time_after(jiffies, hbinfo->sent_at + max_interval)) {
  1146. pr_debug("%s: HEARTBEAT ACK with invalid timestamp received "
  1147. "for transport:%p\n", __func__, link);
  1148. return SCTP_DISPOSITION_DISCARD;
  1149. }
  1150. /* 8.3 Upon the receipt of the HEARTBEAT ACK, the sender of
  1151. * the HEARTBEAT should clear the error counter of the
  1152. * destination transport address to which the HEARTBEAT was
  1153. * sent and mark the destination transport address as active if
  1154. * it is not so marked.
  1155. */
  1156. sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_ON, SCTP_TRANSPORT(link));
  1157. return SCTP_DISPOSITION_CONSUME;
  1158. }
  1159. /* Helper function to send out an abort for the restart
  1160. * condition.
  1161. */
  1162. static int sctp_sf_send_restart_abort(struct net *net, union sctp_addr *ssa,
  1163. struct sctp_chunk *init,
  1164. struct sctp_cmd_seq *commands)
  1165. {
  1166. struct sctp_af *af = sctp_get_af_specific(ssa->v4.sin_family);
  1167. union sctp_addr_param *addrparm;
  1168. struct sctp_errhdr *errhdr;
  1169. char buffer[sizeof(*errhdr) + sizeof(*addrparm)];
  1170. struct sctp_endpoint *ep;
  1171. struct sctp_packet *pkt;
  1172. int len;
  1173. /* Build the error on the stack. We are way to malloc crazy
  1174. * throughout the code today.
  1175. */
  1176. errhdr = (struct sctp_errhdr *)buffer;
  1177. addrparm = (union sctp_addr_param *)(errhdr + 1);
  1178. /* Copy into a parm format. */
  1179. len = af->to_addr_param(ssa, addrparm);
  1180. len += sizeof(*errhdr);
  1181. errhdr->cause = SCTP_ERROR_RESTART;
  1182. errhdr->length = htons(len);
  1183. /* Assign to the control socket. */
  1184. ep = sctp_sk(net->sctp.ctl_sock)->ep;
  1185. /* Association is NULL since this may be a restart attack and we
  1186. * want to send back the attacker's vtag.
  1187. */
  1188. pkt = sctp_abort_pkt_new(net, ep, NULL, init, errhdr, len);
  1189. if (!pkt)
  1190. goto out;
  1191. sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(pkt));
  1192. SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
  1193. /* Discard the rest of the inbound packet. */
  1194. sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
  1195. out:
  1196. /* Even if there is no memory, treat as a failure so
  1197. * the packet will get dropped.
  1198. */
  1199. return 0;
  1200. }
  1201. static bool list_has_sctp_addr(const struct list_head *list,
  1202. union sctp_addr *ipaddr)
  1203. {
  1204. struct sctp_transport *addr;
  1205. list_for_each_entry(addr, list, transports) {
  1206. if (sctp_cmp_addr_exact(ipaddr, &addr->ipaddr))
  1207. return true;
  1208. }
  1209. return false;
  1210. }
  1211. /* A restart is occurring, check to make sure no new addresses
  1212. * are being added as we may be under a takeover attack.
  1213. */
  1214. static int sctp_sf_check_restart_addrs(const struct sctp_association *new_asoc,
  1215. const struct sctp_association *asoc,
  1216. struct sctp_chunk *init,
  1217. struct sctp_cmd_seq *commands)
  1218. {
  1219. struct net *net = new_asoc->base.net;
  1220. struct sctp_transport *new_addr;
  1221. int ret = 1;
  1222. /* Implementor's Guide - Section 5.2.2
  1223. * ...
  1224. * Before responding the endpoint MUST check to see if the
  1225. * unexpected INIT adds new addresses to the association. If new
  1226. * addresses are added to the association, the endpoint MUST respond
  1227. * with an ABORT..
  1228. */
  1229. /* Search through all current addresses and make sure
  1230. * we aren't adding any new ones.
  1231. */
  1232. list_for_each_entry(new_addr, &new_asoc->peer.transport_addr_list,
  1233. transports) {
  1234. if (!list_has_sctp_addr(&asoc->peer.transport_addr_list,
  1235. &new_addr->ipaddr)) {
  1236. sctp_sf_send_restart_abort(net, &new_addr->ipaddr, init,
  1237. commands);
  1238. ret = 0;
  1239. break;
  1240. }
  1241. }
  1242. /* Return success if all addresses were found. */
  1243. return ret;
  1244. }
  1245. /* Populate the verification/tie tags based on overlapping INIT
  1246. * scenario.
  1247. *
  1248. * Note: Do not use in CLOSED or SHUTDOWN-ACK-SENT state.
  1249. */
  1250. static void sctp_tietags_populate(struct sctp_association *new_asoc,
  1251. const struct sctp_association *asoc)
  1252. {
  1253. switch (asoc->state) {
  1254. /* 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State */
  1255. case SCTP_STATE_COOKIE_WAIT:
  1256. new_asoc->c.my_vtag = asoc->c.my_vtag;
  1257. new_asoc->c.my_ttag = asoc->c.my_vtag;
  1258. new_asoc->c.peer_ttag = 0;
  1259. break;
  1260. case SCTP_STATE_COOKIE_ECHOED:
  1261. new_asoc->c.my_vtag = asoc->c.my_vtag;
  1262. new_asoc->c.my_ttag = asoc->c.my_vtag;
  1263. new_asoc->c.peer_ttag = asoc->c.peer_vtag;
  1264. break;
  1265. /* 5.2.2 Unexpected INIT in States Other than CLOSED, COOKIE-ECHOED,
  1266. * COOKIE-WAIT and SHUTDOWN-ACK-SENT
  1267. */
  1268. default:
  1269. new_asoc->c.my_ttag = asoc->c.my_vtag;
  1270. new_asoc->c.peer_ttag = asoc->c.peer_vtag;
  1271. break;
  1272. }
  1273. /* Other parameters for the endpoint SHOULD be copied from the
  1274. * existing parameters of the association (e.g. number of
  1275. * outbound streams) into the INIT ACK and cookie.
  1276. */
  1277. new_asoc->rwnd = asoc->rwnd;
  1278. new_asoc->c.sinit_num_ostreams = asoc->c.sinit_num_ostreams;
  1279. new_asoc->c.sinit_max_instreams = asoc->c.sinit_max_instreams;
  1280. new_asoc->c.initial_tsn = asoc->c.initial_tsn;
  1281. }
  1282. /*
  1283. * Compare vtag/tietag values to determine unexpected COOKIE-ECHO
  1284. * handling action.
  1285. *
  1286. * RFC 2960 5.2.4 Handle a COOKIE ECHO when a TCB exists.
  1287. *
  1288. * Returns value representing action to be taken. These action values
  1289. * correspond to Action/Description values in RFC 2960, Table 2.
  1290. */
  1291. static char sctp_tietags_compare(struct sctp_association *new_asoc,
  1292. const struct sctp_association *asoc)
  1293. {
  1294. /* In this case, the peer may have restarted. */
  1295. if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
  1296. (asoc->c.peer_vtag != new_asoc->c.peer_vtag) &&
  1297. (asoc->c.my_vtag == new_asoc->c.my_ttag) &&
  1298. (asoc->c.peer_vtag == new_asoc->c.peer_ttag))
  1299. return 'A';
  1300. /* Collision case B. */
  1301. if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
  1302. ((asoc->c.peer_vtag != new_asoc->c.peer_vtag) ||
  1303. (0 == asoc->c.peer_vtag))) {
  1304. return 'B';
  1305. }
  1306. /* Collision case D. */
  1307. if ((asoc->c.my_vtag == new_asoc->c.my_vtag) &&
  1308. (asoc->c.peer_vtag == new_asoc->c.peer_vtag))
  1309. return 'D';
  1310. /* Collision case C. */
  1311. if ((asoc->c.my_vtag != new_asoc->c.my_vtag) &&
  1312. (asoc->c.peer_vtag == new_asoc->c.peer_vtag) &&
  1313. (0 == new_asoc->c.my_ttag) &&
  1314. (0 == new_asoc->c.peer_ttag))
  1315. return 'C';
  1316. /* No match to any of the special cases; discard this packet. */
  1317. return 'E';
  1318. }
  1319. /* Common helper routine for both duplicate and simultaneous INIT
  1320. * chunk handling.
  1321. */
  1322. static enum sctp_disposition sctp_sf_do_unexpected_init(
  1323. struct net *net,
  1324. const struct sctp_endpoint *ep,
  1325. const struct sctp_association *asoc,
  1326. const union sctp_subtype type,
  1327. void *arg,
  1328. struct sctp_cmd_seq *commands)
  1329. {
  1330. struct sctp_chunk *chunk = arg, *repl, *err_chunk;
  1331. struct sctp_unrecognized_param *unk_param;
  1332. struct sctp_association *new_asoc;
  1333. enum sctp_disposition retval;
  1334. struct sctp_packet *packet;
  1335. int len;
  1336. /* 6.10 Bundling
  1337. * An endpoint MUST NOT bundle INIT, INIT ACK or
  1338. * SHUTDOWN COMPLETE with any other chunks.
  1339. *
  1340. * IG Section 2.11.2
  1341. * Furthermore, we require that the receiver of an INIT chunk MUST
  1342. * enforce these rules by silently discarding an arriving packet
  1343. * with an INIT chunk that is bundled with other chunks.
  1344. */
  1345. if (!chunk->singleton)
  1346. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  1347. /* Make sure that the INIT chunk has a valid length. */
  1348. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_init_chunk)))
  1349. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  1350. /* 3.1 A packet containing an INIT chunk MUST have a zero Verification
  1351. * Tag.
  1352. */
  1353. if (chunk->sctp_hdr->vtag != 0)
  1354. return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
  1355. if (SCTP_INPUT_CB(chunk->skb)->encap_port != chunk->transport->encap_port)
  1356. return sctp_sf_new_encap_port(net, ep, asoc, type, arg, commands);
  1357. /* Grab the INIT header. */
  1358. chunk->subh.init_hdr = (struct sctp_inithdr *)chunk->skb->data;
  1359. /* Tag the variable length parameters. */
  1360. chunk->param_hdr.v = skb_pull(chunk->skb, sizeof(struct sctp_inithdr));
  1361. /* Verify the INIT chunk before processing it. */
  1362. err_chunk = NULL;
  1363. if (!sctp_verify_init(net, ep, asoc, chunk->chunk_hdr->type,
  1364. (struct sctp_init_chunk *)chunk->chunk_hdr, chunk,
  1365. &err_chunk)) {
  1366. /* This chunk contains fatal error. It is to be discarded.
  1367. * Send an ABORT, with causes if there is any.
  1368. */
  1369. if (err_chunk) {
  1370. packet = sctp_abort_pkt_new(net, ep, asoc, arg,
  1371. (__u8 *)(err_chunk->chunk_hdr) +
  1372. sizeof(struct sctp_chunkhdr),
  1373. ntohs(err_chunk->chunk_hdr->length) -
  1374. sizeof(struct sctp_chunkhdr));
  1375. if (packet) {
  1376. sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
  1377. SCTP_PACKET(packet));
  1378. SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
  1379. retval = SCTP_DISPOSITION_CONSUME;
  1380. } else {
  1381. retval = SCTP_DISPOSITION_NOMEM;
  1382. }
  1383. goto cleanup;
  1384. } else {
  1385. return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg,
  1386. commands);
  1387. }
  1388. }
  1389. /*
  1390. * Other parameters for the endpoint SHOULD be copied from the
  1391. * existing parameters of the association (e.g. number of
  1392. * outbound streams) into the INIT ACK and cookie.
  1393. * FIXME: We are copying parameters from the endpoint not the
  1394. * association.
  1395. */
  1396. new_asoc = sctp_make_temp_asoc(ep, chunk, GFP_ATOMIC);
  1397. if (!new_asoc)
  1398. goto nomem;
  1399. /* Update socket peer label if first association. */
  1400. if (security_sctp_assoc_request(new_asoc, chunk->skb)) {
  1401. sctp_association_free(new_asoc);
  1402. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  1403. }
  1404. if (sctp_assoc_set_bind_addr_from_ep(new_asoc,
  1405. sctp_scope(sctp_source(chunk)), GFP_ATOMIC) < 0)
  1406. goto nomem;
  1407. /* In the outbound INIT ACK the endpoint MUST copy its current
  1408. * Verification Tag and Peers Verification tag into a reserved
  1409. * place (local tie-tag and per tie-tag) within the state cookie.
  1410. */
  1411. if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk),
  1412. (struct sctp_init_chunk *)chunk->chunk_hdr,
  1413. GFP_ATOMIC))
  1414. goto nomem;
  1415. /* Make sure no new addresses are being added during the
  1416. * restart. Do not do this check for COOKIE-WAIT state,
  1417. * since there are no peer addresses to check against.
  1418. * Upon return an ABORT will have been sent if needed.
  1419. */
  1420. if (!sctp_state(asoc, COOKIE_WAIT)) {
  1421. if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk,
  1422. commands)) {
  1423. retval = SCTP_DISPOSITION_CONSUME;
  1424. goto nomem_retval;
  1425. }
  1426. }
  1427. sctp_tietags_populate(new_asoc, asoc);
  1428. /* B) "Z" shall respond immediately with an INIT ACK chunk. */
  1429. /* If there are errors need to be reported for unknown parameters,
  1430. * make sure to reserve enough room in the INIT ACK for them.
  1431. */
  1432. len = 0;
  1433. if (err_chunk) {
  1434. len = ntohs(err_chunk->chunk_hdr->length) -
  1435. sizeof(struct sctp_chunkhdr);
  1436. }
  1437. repl = sctp_make_init_ack(new_asoc, chunk, GFP_ATOMIC, len);
  1438. if (!repl)
  1439. goto nomem;
  1440. /* If there are errors need to be reported for unknown parameters,
  1441. * include them in the outgoing INIT ACK as "Unrecognized parameter"
  1442. * parameter.
  1443. */
  1444. if (err_chunk) {
  1445. /* Get the "Unrecognized parameter" parameter(s) out of the
  1446. * ERROR chunk generated by sctp_verify_init(). Since the
  1447. * error cause code for "unknown parameter" and the
  1448. * "Unrecognized parameter" type is the same, we can
  1449. * construct the parameters in INIT ACK by copying the
  1450. * ERROR causes over.
  1451. */
  1452. unk_param = (struct sctp_unrecognized_param *)
  1453. ((__u8 *)(err_chunk->chunk_hdr) +
  1454. sizeof(struct sctp_chunkhdr));
  1455. /* Replace the cause code with the "Unrecognized parameter"
  1456. * parameter type.
  1457. */
  1458. sctp_addto_chunk(repl, len, unk_param);
  1459. }
  1460. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(new_asoc));
  1461. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
  1462. /*
  1463. * Note: After sending out INIT ACK with the State Cookie parameter,
  1464. * "Z" MUST NOT allocate any resources for this new association.
  1465. * Otherwise, "Z" will be vulnerable to resource attacks.
  1466. */
  1467. sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
  1468. retval = SCTP_DISPOSITION_CONSUME;
  1469. return retval;
  1470. nomem:
  1471. retval = SCTP_DISPOSITION_NOMEM;
  1472. nomem_retval:
  1473. if (new_asoc)
  1474. sctp_association_free(new_asoc);
  1475. cleanup:
  1476. if (err_chunk)
  1477. sctp_chunk_free(err_chunk);
  1478. return retval;
  1479. }
  1480. /*
  1481. * Handle simultaneous INIT.
  1482. * This means we started an INIT and then we got an INIT request from
  1483. * our peer.
  1484. *
  1485. * Section: 5.2.1 INIT received in COOKIE-WAIT or COOKIE-ECHOED State (Item B)
  1486. * This usually indicates an initialization collision, i.e., each
  1487. * endpoint is attempting, at about the same time, to establish an
  1488. * association with the other endpoint.
  1489. *
  1490. * Upon receipt of an INIT in the COOKIE-WAIT or COOKIE-ECHOED state, an
  1491. * endpoint MUST respond with an INIT ACK using the same parameters it
  1492. * sent in its original INIT chunk (including its Verification Tag,
  1493. * unchanged). These original parameters are combined with those from the
  1494. * newly received INIT chunk. The endpoint shall also generate a State
  1495. * Cookie with the INIT ACK. The endpoint uses the parameters sent in its
  1496. * INIT to calculate the State Cookie.
  1497. *
  1498. * After that, the endpoint MUST NOT change its state, the T1-init
  1499. * timer shall be left running and the corresponding TCB MUST NOT be
  1500. * destroyed. The normal procedures for handling State Cookies when
  1501. * a TCB exists will resolve the duplicate INITs to a single association.
  1502. *
  1503. * For an endpoint that is in the COOKIE-ECHOED state it MUST populate
  1504. * its Tie-Tags with the Tag information of itself and its peer (see
  1505. * section 5.2.2 for a description of the Tie-Tags).
  1506. *
  1507. * Verification Tag: Not explicit, but an INIT can not have a valid
  1508. * verification tag, so we skip the check.
  1509. *
  1510. * Inputs
  1511. * (endpoint, asoc, chunk)
  1512. *
  1513. * Outputs
  1514. * (asoc, reply_msg, msg_up, timers, counters)
  1515. *
  1516. * The return value is the disposition of the chunk.
  1517. */
  1518. enum sctp_disposition sctp_sf_do_5_2_1_siminit(
  1519. struct net *net,
  1520. const struct sctp_endpoint *ep,
  1521. const struct sctp_association *asoc,
  1522. const union sctp_subtype type,
  1523. void *arg,
  1524. struct sctp_cmd_seq *commands)
  1525. {
  1526. /* Call helper to do the real work for both simultaneous and
  1527. * duplicate INIT chunk handling.
  1528. */
  1529. return sctp_sf_do_unexpected_init(net, ep, asoc, type, arg, commands);
  1530. }
  1531. /*
  1532. * Handle duplicated INIT messages. These are usually delayed
  1533. * restransmissions.
  1534. *
  1535. * Section: 5.2.2 Unexpected INIT in States Other than CLOSED,
  1536. * COOKIE-ECHOED and COOKIE-WAIT
  1537. *
  1538. * Unless otherwise stated, upon reception of an unexpected INIT for
  1539. * this association, the endpoint shall generate an INIT ACK with a
  1540. * State Cookie. In the outbound INIT ACK the endpoint MUST copy its
  1541. * current Verification Tag and peer's Verification Tag into a reserved
  1542. * place within the state cookie. We shall refer to these locations as
  1543. * the Peer's-Tie-Tag and the Local-Tie-Tag. The outbound SCTP packet
  1544. * containing this INIT ACK MUST carry a Verification Tag value equal to
  1545. * the Initiation Tag found in the unexpected INIT. And the INIT ACK
  1546. * MUST contain a new Initiation Tag (randomly generated see Section
  1547. * 5.3.1). Other parameters for the endpoint SHOULD be copied from the
  1548. * existing parameters of the association (e.g. number of outbound
  1549. * streams) into the INIT ACK and cookie.
  1550. *
  1551. * After sending out the INIT ACK, the endpoint shall take no further
  1552. * actions, i.e., the existing association, including its current state,
  1553. * and the corresponding TCB MUST NOT be changed.
  1554. *
  1555. * Note: Only when a TCB exists and the association is not in a COOKIE-
  1556. * WAIT state are the Tie-Tags populated. For a normal association INIT
  1557. * (i.e. the endpoint is in a COOKIE-WAIT state), the Tie-Tags MUST be
  1558. * set to 0 (indicating that no previous TCB existed). The INIT ACK and
  1559. * State Cookie are populated as specified in section 5.2.1.
  1560. *
  1561. * Verification Tag: Not specified, but an INIT has no way of knowing
  1562. * what the verification tag could be, so we ignore it.
  1563. *
  1564. * Inputs
  1565. * (endpoint, asoc, chunk)
  1566. *
  1567. * Outputs
  1568. * (asoc, reply_msg, msg_up, timers, counters)
  1569. *
  1570. * The return value is the disposition of the chunk.
  1571. */
  1572. enum sctp_disposition sctp_sf_do_5_2_2_dupinit(
  1573. struct net *net,
  1574. const struct sctp_endpoint *ep,
  1575. const struct sctp_association *asoc,
  1576. const union sctp_subtype type,
  1577. void *arg,
  1578. struct sctp_cmd_seq *commands)
  1579. {
  1580. /* Call helper to do the real work for both simultaneous and
  1581. * duplicate INIT chunk handling.
  1582. */
  1583. return sctp_sf_do_unexpected_init(net, ep, asoc, type, arg, commands);
  1584. }
  1585. /*
  1586. * Unexpected INIT-ACK handler.
  1587. *
  1588. * Section 5.2.3
  1589. * If an INIT ACK received by an endpoint in any state other than the
  1590. * COOKIE-WAIT state, the endpoint should discard the INIT ACK chunk.
  1591. * An unexpected INIT ACK usually indicates the processing of an old or
  1592. * duplicated INIT chunk.
  1593. */
  1594. enum sctp_disposition sctp_sf_do_5_2_3_initack(
  1595. struct net *net,
  1596. const struct sctp_endpoint *ep,
  1597. const struct sctp_association *asoc,
  1598. const union sctp_subtype type,
  1599. void *arg,
  1600. struct sctp_cmd_seq *commands)
  1601. {
  1602. /* Per the above section, we'll discard the chunk if we have an
  1603. * endpoint. If this is an OOTB INIT-ACK, treat it as such.
  1604. */
  1605. if (ep == sctp_sk(net->sctp.ctl_sock)->ep)
  1606. return sctp_sf_ootb(net, ep, asoc, type, arg, commands);
  1607. else
  1608. return sctp_sf_discard_chunk(net, ep, asoc, type, arg, commands);
  1609. }
  1610. static int sctp_sf_do_assoc_update(struct sctp_association *asoc,
  1611. struct sctp_association *new,
  1612. struct sctp_cmd_seq *cmds)
  1613. {
  1614. struct net *net = asoc->base.net;
  1615. struct sctp_chunk *abort;
  1616. if (!sctp_assoc_update(asoc, new))
  1617. return 0;
  1618. abort = sctp_make_abort(asoc, NULL, sizeof(struct sctp_errhdr));
  1619. if (abort) {
  1620. sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, 0);
  1621. sctp_add_cmd_sf(cmds, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
  1622. }
  1623. sctp_add_cmd_sf(cmds, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNABORTED));
  1624. sctp_add_cmd_sf(cmds, SCTP_CMD_ASSOC_FAILED,
  1625. SCTP_PERR(SCTP_ERROR_RSRC_LOW));
  1626. SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
  1627. SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
  1628. return -ENOMEM;
  1629. }
  1630. /* Unexpected COOKIE-ECHO handler for peer restart (Table 2, action 'A')
  1631. *
  1632. * Section 5.2.4
  1633. * A) In this case, the peer may have restarted.
  1634. */
  1635. static enum sctp_disposition sctp_sf_do_dupcook_a(
  1636. struct net *net,
  1637. const struct sctp_endpoint *ep,
  1638. const struct sctp_association *asoc,
  1639. struct sctp_chunk *chunk,
  1640. struct sctp_cmd_seq *commands,
  1641. struct sctp_association *new_asoc)
  1642. {
  1643. struct sctp_init_chunk *peer_init;
  1644. enum sctp_disposition disposition;
  1645. struct sctp_ulpevent *ev;
  1646. struct sctp_chunk *repl;
  1647. struct sctp_chunk *err;
  1648. /* new_asoc is a brand-new association, so these are not yet
  1649. * side effects--it is safe to run them here.
  1650. */
  1651. peer_init = (struct sctp_init_chunk *)(chunk->subh.cookie_hdr + 1);
  1652. if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk), peer_init,
  1653. GFP_ATOMIC))
  1654. goto nomem;
  1655. if (sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC))
  1656. goto nomem;
  1657. if (!sctp_auth_chunk_verify(net, chunk, new_asoc))
  1658. return SCTP_DISPOSITION_DISCARD;
  1659. /* Make sure no new addresses are being added during the
  1660. * restart. Though this is a pretty complicated attack
  1661. * since you'd have to get inside the cookie.
  1662. */
  1663. if (!sctp_sf_check_restart_addrs(new_asoc, asoc, chunk, commands))
  1664. return SCTP_DISPOSITION_CONSUME;
  1665. /* If the endpoint is in the SHUTDOWN-ACK-SENT state and recognizes
  1666. * the peer has restarted (Action A), it MUST NOT setup a new
  1667. * association but instead resend the SHUTDOWN ACK and send an ERROR
  1668. * chunk with a "Cookie Received while Shutting Down" error cause to
  1669. * its peer.
  1670. */
  1671. if (sctp_state(asoc, SHUTDOWN_ACK_SENT)) {
  1672. disposition = __sctp_sf_do_9_2_reshutack(net, ep, asoc,
  1673. SCTP_ST_CHUNK(chunk->chunk_hdr->type),
  1674. chunk, commands);
  1675. if (SCTP_DISPOSITION_NOMEM == disposition)
  1676. goto nomem;
  1677. err = sctp_make_op_error(asoc, chunk,
  1678. SCTP_ERROR_COOKIE_IN_SHUTDOWN,
  1679. NULL, 0, 0);
  1680. if (err)
  1681. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
  1682. SCTP_CHUNK(err));
  1683. return SCTP_DISPOSITION_CONSUME;
  1684. }
  1685. /* For now, stop pending T3-rtx and SACK timers, fail any unsent/unacked
  1686. * data. Consider the optional choice of resending of this data.
  1687. */
  1688. sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL());
  1689. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  1690. SCTP_TO(SCTP_EVENT_TIMEOUT_SACK));
  1691. sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_OUTQUEUE, SCTP_NULL());
  1692. /* Stop pending T4-rto timer, teardown ASCONF queue, ASCONF-ACK queue
  1693. * and ASCONF-ACK cache.
  1694. */
  1695. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  1696. SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
  1697. sctp_add_cmd_sf(commands, SCTP_CMD_PURGE_ASCONF_QUEUE, SCTP_NULL());
  1698. /* Update the content of current association. */
  1699. if (sctp_sf_do_assoc_update((struct sctp_association *)asoc, new_asoc, commands))
  1700. goto nomem;
  1701. repl = sctp_make_cookie_ack(asoc, chunk);
  1702. if (!repl)
  1703. goto nomem;
  1704. /* Report association restart to upper layer. */
  1705. ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_RESTART, 0,
  1706. asoc->c.sinit_num_ostreams,
  1707. asoc->c.sinit_max_instreams,
  1708. NULL, GFP_ATOMIC);
  1709. if (!ev)
  1710. goto nomem_ev;
  1711. sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
  1712. if ((sctp_state(asoc, SHUTDOWN_PENDING) ||
  1713. sctp_state(asoc, SHUTDOWN_SENT)) &&
  1714. (sctp_sstate(asoc->base.sk, CLOSING) ||
  1715. sock_flag(asoc->base.sk, SOCK_DEAD))) {
  1716. /* If the socket has been closed by user, don't
  1717. * transition to ESTABLISHED. Instead trigger SHUTDOWN
  1718. * bundled with COOKIE_ACK.
  1719. */
  1720. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
  1721. return sctp_sf_do_9_2_start_shutdown(net, ep, asoc,
  1722. SCTP_ST_CHUNK(0), repl,
  1723. commands);
  1724. } else {
  1725. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
  1726. SCTP_STATE(SCTP_STATE_ESTABLISHED));
  1727. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
  1728. }
  1729. return SCTP_DISPOSITION_CONSUME;
  1730. nomem_ev:
  1731. sctp_chunk_free(repl);
  1732. nomem:
  1733. return SCTP_DISPOSITION_NOMEM;
  1734. }
  1735. /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'B')
  1736. *
  1737. * Section 5.2.4
  1738. * B) In this case, both sides may be attempting to start an association
  1739. * at about the same time but the peer endpoint started its INIT
  1740. * after responding to the local endpoint's INIT
  1741. */
  1742. /* This case represents an initialization collision. */
  1743. static enum sctp_disposition sctp_sf_do_dupcook_b(
  1744. struct net *net,
  1745. const struct sctp_endpoint *ep,
  1746. const struct sctp_association *asoc,
  1747. struct sctp_chunk *chunk,
  1748. struct sctp_cmd_seq *commands,
  1749. struct sctp_association *new_asoc)
  1750. {
  1751. struct sctp_init_chunk *peer_init;
  1752. struct sctp_chunk *repl;
  1753. /* new_asoc is a brand-new association, so these are not yet
  1754. * side effects--it is safe to run them here.
  1755. */
  1756. peer_init = (struct sctp_init_chunk *)(chunk->subh.cookie_hdr + 1);
  1757. if (!sctp_process_init(new_asoc, chunk, sctp_source(chunk), peer_init,
  1758. GFP_ATOMIC))
  1759. goto nomem;
  1760. if (sctp_auth_asoc_init_active_key(new_asoc, GFP_ATOMIC))
  1761. goto nomem;
  1762. if (!sctp_auth_chunk_verify(net, chunk, new_asoc))
  1763. return SCTP_DISPOSITION_DISCARD;
  1764. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
  1765. SCTP_STATE(SCTP_STATE_ESTABLISHED));
  1766. if (asoc->state < SCTP_STATE_ESTABLISHED)
  1767. SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB);
  1768. sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START, SCTP_NULL());
  1769. /* Update the content of current association. */
  1770. if (sctp_sf_do_assoc_update((struct sctp_association *)asoc, new_asoc, commands))
  1771. goto nomem;
  1772. repl = sctp_make_cookie_ack(asoc, chunk);
  1773. if (!repl)
  1774. goto nomem;
  1775. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
  1776. /* RFC 2960 5.1 Normal Establishment of an Association
  1777. *
  1778. * D) IMPLEMENTATION NOTE: An implementation may choose to
  1779. * send the Communication Up notification to the SCTP user
  1780. * upon reception of a valid COOKIE ECHO chunk.
  1781. *
  1782. * Sadly, this needs to be implemented as a side-effect, because
  1783. * we are not guaranteed to have set the association id of the real
  1784. * association and so these notifications need to be delayed until
  1785. * the association id is allocated.
  1786. */
  1787. sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_CHANGE, SCTP_U8(SCTP_COMM_UP));
  1788. /* Sockets API Draft Section 5.3.1.6
  1789. * When a peer sends a Adaptation Layer Indication parameter , SCTP
  1790. * delivers this notification to inform the application that of the
  1791. * peers requested adaptation layer.
  1792. *
  1793. * This also needs to be done as a side effect for the same reason as
  1794. * above.
  1795. */
  1796. if (asoc->peer.adaptation_ind)
  1797. sctp_add_cmd_sf(commands, SCTP_CMD_ADAPTATION_IND, SCTP_NULL());
  1798. if (!asoc->peer.auth_capable)
  1799. sctp_add_cmd_sf(commands, SCTP_CMD_PEER_NO_AUTH, SCTP_NULL());
  1800. return SCTP_DISPOSITION_CONSUME;
  1801. nomem:
  1802. return SCTP_DISPOSITION_NOMEM;
  1803. }
  1804. /* Unexpected COOKIE-ECHO handler for setup collision (Table 2, action 'C')
  1805. *
  1806. * Section 5.2.4
  1807. * C) In this case, the local endpoint's cookie has arrived late.
  1808. * Before it arrived, the local endpoint sent an INIT and received an
  1809. * INIT-ACK and finally sent a COOKIE ECHO with the peer's same tag
  1810. * but a new tag of its own.
  1811. */
  1812. /* This case represents an initialization collision. */
  1813. static enum sctp_disposition sctp_sf_do_dupcook_c(
  1814. struct net *net,
  1815. const struct sctp_endpoint *ep,
  1816. const struct sctp_association *asoc,
  1817. struct sctp_chunk *chunk,
  1818. struct sctp_cmd_seq *commands,
  1819. struct sctp_association *new_asoc)
  1820. {
  1821. /* The cookie should be silently discarded.
  1822. * The endpoint SHOULD NOT change states and should leave
  1823. * any timers running.
  1824. */
  1825. return SCTP_DISPOSITION_DISCARD;
  1826. }
  1827. /* Unexpected COOKIE-ECHO handler lost chunk (Table 2, action 'D')
  1828. *
  1829. * Section 5.2.4
  1830. *
  1831. * D) When both local and remote tags match the endpoint should always
  1832. * enter the ESTABLISHED state, if it has not already done so.
  1833. */
  1834. /* This case represents an initialization collision. */
  1835. static enum sctp_disposition sctp_sf_do_dupcook_d(
  1836. struct net *net,
  1837. const struct sctp_endpoint *ep,
  1838. const struct sctp_association *asoc,
  1839. struct sctp_chunk *chunk,
  1840. struct sctp_cmd_seq *commands,
  1841. struct sctp_association *new_asoc)
  1842. {
  1843. struct sctp_ulpevent *ev = NULL, *ai_ev = NULL, *auth_ev = NULL;
  1844. struct sctp_chunk *repl;
  1845. /* Clarification from Implementor's Guide:
  1846. * D) When both local and remote tags match the endpoint should
  1847. * enter the ESTABLISHED state, if it is in the COOKIE-ECHOED state.
  1848. * It should stop any cookie timer that may be running and send
  1849. * a COOKIE ACK.
  1850. */
  1851. if (!sctp_auth_chunk_verify(net, chunk, asoc))
  1852. return SCTP_DISPOSITION_DISCARD;
  1853. /* Don't accidentally move back into established state. */
  1854. if (asoc->state < SCTP_STATE_ESTABLISHED) {
  1855. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  1856. SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
  1857. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
  1858. SCTP_STATE(SCTP_STATE_ESTABLISHED));
  1859. SCTP_INC_STATS(net, SCTP_MIB_CURRESTAB);
  1860. sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_START,
  1861. SCTP_NULL());
  1862. /* RFC 2960 5.1 Normal Establishment of an Association
  1863. *
  1864. * D) IMPLEMENTATION NOTE: An implementation may choose
  1865. * to send the Communication Up notification to the
  1866. * SCTP user upon reception of a valid COOKIE
  1867. * ECHO chunk.
  1868. */
  1869. ev = sctp_ulpevent_make_assoc_change(asoc, 0,
  1870. SCTP_COMM_UP, 0,
  1871. asoc->c.sinit_num_ostreams,
  1872. asoc->c.sinit_max_instreams,
  1873. NULL, GFP_ATOMIC);
  1874. if (!ev)
  1875. goto nomem;
  1876. /* Sockets API Draft Section 5.3.1.6
  1877. * When a peer sends a Adaptation Layer Indication parameter,
  1878. * SCTP delivers this notification to inform the application
  1879. * that of the peers requested adaptation layer.
  1880. */
  1881. if (asoc->peer.adaptation_ind) {
  1882. ai_ev = sctp_ulpevent_make_adaptation_indication(asoc,
  1883. GFP_ATOMIC);
  1884. if (!ai_ev)
  1885. goto nomem;
  1886. }
  1887. if (!asoc->peer.auth_capable) {
  1888. auth_ev = sctp_ulpevent_make_authkey(asoc, 0,
  1889. SCTP_AUTH_NO_AUTH,
  1890. GFP_ATOMIC);
  1891. if (!auth_ev)
  1892. goto nomem;
  1893. }
  1894. }
  1895. repl = sctp_make_cookie_ack(asoc, chunk);
  1896. if (!repl)
  1897. goto nomem;
  1898. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
  1899. if (ev)
  1900. sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
  1901. SCTP_ULPEVENT(ev));
  1902. if (ai_ev)
  1903. sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
  1904. SCTP_ULPEVENT(ai_ev));
  1905. if (auth_ev)
  1906. sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
  1907. SCTP_ULPEVENT(auth_ev));
  1908. return SCTP_DISPOSITION_CONSUME;
  1909. nomem:
  1910. if (auth_ev)
  1911. sctp_ulpevent_free(auth_ev);
  1912. if (ai_ev)
  1913. sctp_ulpevent_free(ai_ev);
  1914. if (ev)
  1915. sctp_ulpevent_free(ev);
  1916. return SCTP_DISPOSITION_NOMEM;
  1917. }
  1918. /*
  1919. * Handle a duplicate COOKIE-ECHO. This usually means a cookie-carrying
  1920. * chunk was retransmitted and then delayed in the network.
  1921. *
  1922. * Section: 5.2.4 Handle a COOKIE ECHO when a TCB exists
  1923. *
  1924. * Verification Tag: None. Do cookie validation.
  1925. *
  1926. * Inputs
  1927. * (endpoint, asoc, chunk)
  1928. *
  1929. * Outputs
  1930. * (asoc, reply_msg, msg_up, timers, counters)
  1931. *
  1932. * The return value is the disposition of the chunk.
  1933. */
  1934. enum sctp_disposition sctp_sf_do_5_2_4_dupcook(
  1935. struct net *net,
  1936. const struct sctp_endpoint *ep,
  1937. const struct sctp_association *asoc,
  1938. const union sctp_subtype type,
  1939. void *arg,
  1940. struct sctp_cmd_seq *commands)
  1941. {
  1942. struct sctp_association *new_asoc;
  1943. struct sctp_chunk *chunk = arg;
  1944. enum sctp_disposition retval;
  1945. struct sctp_chunk *err_chk_p;
  1946. int error = 0;
  1947. char action;
  1948. /* Make sure that the chunk has a valid length from the protocol
  1949. * perspective. In this case check to make sure we have at least
  1950. * enough for the chunk header. Cookie length verification is
  1951. * done later.
  1952. */
  1953. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr))) {
  1954. if (!sctp_vtag_verify(chunk, asoc))
  1955. asoc = NULL;
  1956. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg, commands);
  1957. }
  1958. /* "Decode" the chunk. We have no optional parameters so we
  1959. * are in good shape.
  1960. */
  1961. chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data;
  1962. if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) -
  1963. sizeof(struct sctp_chunkhdr)))
  1964. goto nomem;
  1965. /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie
  1966. * of a duplicate COOKIE ECHO match the Verification Tags of the
  1967. * current association, consider the State Cookie valid even if
  1968. * the lifespan is exceeded.
  1969. */
  1970. new_asoc = sctp_unpack_cookie(ep, asoc, chunk, GFP_ATOMIC, &error,
  1971. &err_chk_p);
  1972. /* FIXME:
  1973. * If the re-build failed, what is the proper error path
  1974. * from here?
  1975. *
  1976. * [We should abort the association. --piggy]
  1977. */
  1978. if (!new_asoc) {
  1979. /* FIXME: Several errors are possible. A bad cookie should
  1980. * be silently discarded, but think about logging it too.
  1981. */
  1982. switch (error) {
  1983. case -SCTP_IERROR_NOMEM:
  1984. goto nomem;
  1985. case -SCTP_IERROR_STALE_COOKIE:
  1986. sctp_send_stale_cookie_err(net, ep, asoc, chunk, commands,
  1987. err_chk_p);
  1988. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  1989. case -SCTP_IERROR_BAD_SIG:
  1990. default:
  1991. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  1992. }
  1993. }
  1994. /* Set temp so that it won't be added into hashtable */
  1995. new_asoc->temp = 1;
  1996. /* Compare the tie_tag in cookie with the verification tag of
  1997. * current association.
  1998. */
  1999. action = sctp_tietags_compare(new_asoc, asoc);
  2000. /* In cases C and E the association doesn't enter the ESTABLISHED
  2001. * state, so there is no need to call security_sctp_assoc_request().
  2002. */
  2003. switch (action) {
  2004. case 'A': /* Association restart. */
  2005. case 'B': /* Collision case B. */
  2006. case 'D': /* Collision case D. */
  2007. /* Update socket peer label if first association. */
  2008. if (security_sctp_assoc_request((struct sctp_association *)asoc,
  2009. chunk->head_skb ?: chunk->skb)) {
  2010. sctp_association_free(new_asoc);
  2011. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2012. }
  2013. break;
  2014. }
  2015. switch (action) {
  2016. case 'A': /* Association restart. */
  2017. retval = sctp_sf_do_dupcook_a(net, ep, asoc, chunk, commands,
  2018. new_asoc);
  2019. break;
  2020. case 'B': /* Collision case B. */
  2021. retval = sctp_sf_do_dupcook_b(net, ep, asoc, chunk, commands,
  2022. new_asoc);
  2023. break;
  2024. case 'C': /* Collision case C. */
  2025. retval = sctp_sf_do_dupcook_c(net, ep, asoc, chunk, commands,
  2026. new_asoc);
  2027. break;
  2028. case 'D': /* Collision case D. */
  2029. retval = sctp_sf_do_dupcook_d(net, ep, asoc, chunk, commands,
  2030. new_asoc);
  2031. break;
  2032. default: /* Discard packet for all others. */
  2033. retval = sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2034. break;
  2035. }
  2036. /* Delete the temporary new association. */
  2037. sctp_add_cmd_sf(commands, SCTP_CMD_SET_ASOC, SCTP_ASOC(new_asoc));
  2038. sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
  2039. /* Restore association pointer to provide SCTP command interpreter
  2040. * with a valid context in case it needs to manipulate
  2041. * the queues */
  2042. sctp_add_cmd_sf(commands, SCTP_CMD_SET_ASOC,
  2043. SCTP_ASOC((struct sctp_association *)asoc));
  2044. return retval;
  2045. nomem:
  2046. return SCTP_DISPOSITION_NOMEM;
  2047. }
  2048. /*
  2049. * Process an ABORT. (SHUTDOWN-PENDING state)
  2050. *
  2051. * See sctp_sf_do_9_1_abort().
  2052. */
  2053. enum sctp_disposition sctp_sf_shutdown_pending_abort(
  2054. struct net *net,
  2055. const struct sctp_endpoint *ep,
  2056. const struct sctp_association *asoc,
  2057. const union sctp_subtype type,
  2058. void *arg,
  2059. struct sctp_cmd_seq *commands)
  2060. {
  2061. struct sctp_chunk *chunk = arg;
  2062. if (!sctp_vtag_verify_either(chunk, asoc))
  2063. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2064. /* Make sure that the ABORT chunk has a valid length.
  2065. * Since this is an ABORT chunk, we have to discard it
  2066. * because of the following text:
  2067. * RFC 2960, Section 3.3.7
  2068. * If an endpoint receives an ABORT with a format error or for an
  2069. * association that doesn't exist, it MUST silently discard it.
  2070. * Because the length is "invalid", we can't really discard just
  2071. * as we do not know its true length. So, to be safe, discard the
  2072. * packet.
  2073. */
  2074. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk)))
  2075. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2076. /* ADD-IP: Special case for ABORT chunks
  2077. * F4) One special consideration is that ABORT Chunks arriving
  2078. * destined to the IP address being deleted MUST be
  2079. * ignored (see Section 5.3.1 for further details).
  2080. */
  2081. if (SCTP_ADDR_DEL ==
  2082. sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
  2083. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2084. if (!sctp_err_chunk_valid(chunk))
  2085. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2086. return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands);
  2087. }
  2088. /*
  2089. * Process an ABORT. (SHUTDOWN-SENT state)
  2090. *
  2091. * See sctp_sf_do_9_1_abort().
  2092. */
  2093. enum sctp_disposition sctp_sf_shutdown_sent_abort(
  2094. struct net *net,
  2095. const struct sctp_endpoint *ep,
  2096. const struct sctp_association *asoc,
  2097. const union sctp_subtype type,
  2098. void *arg,
  2099. struct sctp_cmd_seq *commands)
  2100. {
  2101. struct sctp_chunk *chunk = arg;
  2102. if (!sctp_vtag_verify_either(chunk, asoc))
  2103. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2104. /* Make sure that the ABORT chunk has a valid length.
  2105. * Since this is an ABORT chunk, we have to discard it
  2106. * because of the following text:
  2107. * RFC 2960, Section 3.3.7
  2108. * If an endpoint receives an ABORT with a format error or for an
  2109. * association that doesn't exist, it MUST silently discard it.
  2110. * Because the length is "invalid", we can't really discard just
  2111. * as we do not know its true length. So, to be safe, discard the
  2112. * packet.
  2113. */
  2114. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk)))
  2115. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2116. /* ADD-IP: Special case for ABORT chunks
  2117. * F4) One special consideration is that ABORT Chunks arriving
  2118. * destined to the IP address being deleted MUST be
  2119. * ignored (see Section 5.3.1 for further details).
  2120. */
  2121. if (SCTP_ADDR_DEL ==
  2122. sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
  2123. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2124. if (!sctp_err_chunk_valid(chunk))
  2125. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2126. /* Stop the T2-shutdown timer. */
  2127. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  2128. SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
  2129. /* Stop the T5-shutdown guard timer. */
  2130. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  2131. SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
  2132. return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands);
  2133. }
  2134. /*
  2135. * Process an ABORT. (SHUTDOWN-ACK-SENT state)
  2136. *
  2137. * See sctp_sf_do_9_1_abort().
  2138. */
  2139. enum sctp_disposition sctp_sf_shutdown_ack_sent_abort(
  2140. struct net *net,
  2141. const struct sctp_endpoint *ep,
  2142. const struct sctp_association *asoc,
  2143. const union sctp_subtype type,
  2144. void *arg,
  2145. struct sctp_cmd_seq *commands)
  2146. {
  2147. /* The same T2 timer, so we should be able to use
  2148. * common function with the SHUTDOWN-SENT state.
  2149. */
  2150. return sctp_sf_shutdown_sent_abort(net, ep, asoc, type, arg, commands);
  2151. }
  2152. /*
  2153. * Handle an Error received in COOKIE_ECHOED state.
  2154. *
  2155. * Only handle the error type of stale COOKIE Error, the other errors will
  2156. * be ignored.
  2157. *
  2158. * Inputs
  2159. * (endpoint, asoc, chunk)
  2160. *
  2161. * Outputs
  2162. * (asoc, reply_msg, msg_up, timers, counters)
  2163. *
  2164. * The return value is the disposition of the chunk.
  2165. */
  2166. enum sctp_disposition sctp_sf_cookie_echoed_err(
  2167. struct net *net,
  2168. const struct sctp_endpoint *ep,
  2169. const struct sctp_association *asoc,
  2170. const union sctp_subtype type,
  2171. void *arg,
  2172. struct sctp_cmd_seq *commands)
  2173. {
  2174. struct sctp_chunk *chunk = arg;
  2175. struct sctp_errhdr *err;
  2176. if (!sctp_vtag_verify(chunk, asoc))
  2177. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2178. /* Make sure that the ERROR chunk has a valid length.
  2179. * The parameter walking depends on this as well.
  2180. */
  2181. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_operr_chunk)))
  2182. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  2183. commands);
  2184. /* Process the error here */
  2185. /* FUTURE FIXME: When PR-SCTP related and other optional
  2186. * parms are emitted, this will have to change to handle multiple
  2187. * errors.
  2188. */
  2189. sctp_walk_errors(err, chunk->chunk_hdr) {
  2190. if (SCTP_ERROR_STALE_COOKIE == err->cause)
  2191. return sctp_sf_do_5_2_6_stale(net, ep, asoc, type,
  2192. arg, commands);
  2193. }
  2194. /* It is possible to have malformed error causes, and that
  2195. * will cause us to end the walk early. However, since
  2196. * we are discarding the packet, there should be no adverse
  2197. * affects.
  2198. */
  2199. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2200. }
  2201. /*
  2202. * Handle a Stale COOKIE Error
  2203. *
  2204. * Section: 5.2.6 Handle Stale COOKIE Error
  2205. * If the association is in the COOKIE-ECHOED state, the endpoint may elect
  2206. * one of the following three alternatives.
  2207. * ...
  2208. * 3) Send a new INIT chunk to the endpoint, adding a Cookie
  2209. * Preservative parameter requesting an extension to the lifetime of
  2210. * the State Cookie. When calculating the time extension, an
  2211. * implementation SHOULD use the RTT information measured based on the
  2212. * previous COOKIE ECHO / ERROR exchange, and should add no more
  2213. * than 1 second beyond the measured RTT, due to long State Cookie
  2214. * lifetimes making the endpoint more subject to a replay attack.
  2215. *
  2216. * Verification Tag: Not explicit, but safe to ignore.
  2217. *
  2218. * Inputs
  2219. * (endpoint, asoc, chunk)
  2220. *
  2221. * Outputs
  2222. * (asoc, reply_msg, msg_up, timers, counters)
  2223. *
  2224. * The return value is the disposition of the chunk.
  2225. */
  2226. static enum sctp_disposition sctp_sf_do_5_2_6_stale(
  2227. struct net *net,
  2228. const struct sctp_endpoint *ep,
  2229. const struct sctp_association *asoc,
  2230. const union sctp_subtype type,
  2231. void *arg,
  2232. struct sctp_cmd_seq *commands)
  2233. {
  2234. int attempts = asoc->init_err_counter + 1;
  2235. struct sctp_chunk *chunk = arg, *reply;
  2236. struct sctp_cookie_preserve_param bht;
  2237. struct sctp_bind_addr *bp;
  2238. struct sctp_errhdr *err;
  2239. u32 stale;
  2240. if (attempts > asoc->max_init_attempts) {
  2241. sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
  2242. SCTP_ERROR(ETIMEDOUT));
  2243. sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
  2244. SCTP_PERR(SCTP_ERROR_STALE_COOKIE));
  2245. return SCTP_DISPOSITION_DELETE_TCB;
  2246. }
  2247. err = (struct sctp_errhdr *)(chunk->skb->data);
  2248. /* When calculating the time extension, an implementation
  2249. * SHOULD use the RTT information measured based on the
  2250. * previous COOKIE ECHO / ERROR exchange, and should add no
  2251. * more than 1 second beyond the measured RTT, due to long
  2252. * State Cookie lifetimes making the endpoint more subject to
  2253. * a replay attack.
  2254. * Measure of Staleness's unit is usec. (1/1000000 sec)
  2255. * Suggested Cookie Life-span Increment's unit is msec.
  2256. * (1/1000 sec)
  2257. * In general, if you use the suggested cookie life, the value
  2258. * found in the field of measure of staleness should be doubled
  2259. * to give ample time to retransmit the new cookie and thus
  2260. * yield a higher probability of success on the reattempt.
  2261. */
  2262. stale = ntohl(*(__be32 *)((u8 *)err + sizeof(*err)));
  2263. stale = (stale * 2) / 1000;
  2264. bht.param_hdr.type = SCTP_PARAM_COOKIE_PRESERVATIVE;
  2265. bht.param_hdr.length = htons(sizeof(bht));
  2266. bht.lifespan_increment = htonl(stale);
  2267. /* Build that new INIT chunk. */
  2268. bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
  2269. reply = sctp_make_init(asoc, bp, GFP_ATOMIC, sizeof(bht));
  2270. if (!reply)
  2271. goto nomem;
  2272. sctp_addto_chunk(reply, sizeof(bht), &bht);
  2273. /* Clear peer's init_tag cached in assoc as we are sending a new INIT */
  2274. sctp_add_cmd_sf(commands, SCTP_CMD_CLEAR_INIT_TAG, SCTP_NULL());
  2275. /* Stop pending T3-rtx and heartbeat timers */
  2276. sctp_add_cmd_sf(commands, SCTP_CMD_T3_RTX_TIMERS_STOP, SCTP_NULL());
  2277. sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
  2278. /* Delete non-primary peer ip addresses since we are transitioning
  2279. * back to the COOKIE-WAIT state
  2280. */
  2281. sctp_add_cmd_sf(commands, SCTP_CMD_DEL_NON_PRIMARY, SCTP_NULL());
  2282. /* If we've sent any data bundled with COOKIE-ECHO we will need to
  2283. * resend
  2284. */
  2285. sctp_add_cmd_sf(commands, SCTP_CMD_T1_RETRAN,
  2286. SCTP_TRANSPORT(asoc->peer.primary_path));
  2287. /* Cast away the const modifier, as we want to just
  2288. * rerun it through as a sideffect.
  2289. */
  2290. sctp_add_cmd_sf(commands, SCTP_CMD_INIT_COUNTER_INC, SCTP_NULL());
  2291. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  2292. SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
  2293. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
  2294. SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
  2295. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
  2296. SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
  2297. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
  2298. return SCTP_DISPOSITION_CONSUME;
  2299. nomem:
  2300. return SCTP_DISPOSITION_NOMEM;
  2301. }
  2302. /*
  2303. * Process an ABORT.
  2304. *
  2305. * Section: 9.1
  2306. * After checking the Verification Tag, the receiving endpoint shall
  2307. * remove the association from its record, and shall report the
  2308. * termination to its upper layer.
  2309. *
  2310. * Verification Tag: 8.5.1 Exceptions in Verification Tag Rules
  2311. * B) Rules for packet carrying ABORT:
  2312. *
  2313. * - The endpoint shall always fill in the Verification Tag field of the
  2314. * outbound packet with the destination endpoint's tag value if it
  2315. * is known.
  2316. *
  2317. * - If the ABORT is sent in response to an OOTB packet, the endpoint
  2318. * MUST follow the procedure described in Section 8.4.
  2319. *
  2320. * - The receiver MUST accept the packet if the Verification Tag
  2321. * matches either its own tag, OR the tag of its peer. Otherwise, the
  2322. * receiver MUST silently discard the packet and take no further
  2323. * action.
  2324. *
  2325. * Inputs
  2326. * (endpoint, asoc, chunk)
  2327. *
  2328. * Outputs
  2329. * (asoc, reply_msg, msg_up, timers, counters)
  2330. *
  2331. * The return value is the disposition of the chunk.
  2332. */
  2333. enum sctp_disposition sctp_sf_do_9_1_abort(
  2334. struct net *net,
  2335. const struct sctp_endpoint *ep,
  2336. const struct sctp_association *asoc,
  2337. const union sctp_subtype type,
  2338. void *arg,
  2339. struct sctp_cmd_seq *commands)
  2340. {
  2341. struct sctp_chunk *chunk = arg;
  2342. if (!sctp_vtag_verify_either(chunk, asoc))
  2343. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2344. /* Make sure that the ABORT chunk has a valid length.
  2345. * Since this is an ABORT chunk, we have to discard it
  2346. * because of the following text:
  2347. * RFC 2960, Section 3.3.7
  2348. * If an endpoint receives an ABORT with a format error or for an
  2349. * association that doesn't exist, it MUST silently discard it.
  2350. * Because the length is "invalid", we can't really discard just
  2351. * as we do not know its true length. So, to be safe, discard the
  2352. * packet.
  2353. */
  2354. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk)))
  2355. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2356. /* ADD-IP: Special case for ABORT chunks
  2357. * F4) One special consideration is that ABORT Chunks arriving
  2358. * destined to the IP address being deleted MUST be
  2359. * ignored (see Section 5.3.1 for further details).
  2360. */
  2361. if (SCTP_ADDR_DEL ==
  2362. sctp_bind_addr_state(&asoc->base.bind_addr, &chunk->dest))
  2363. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2364. if (!sctp_err_chunk_valid(chunk))
  2365. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2366. return __sctp_sf_do_9_1_abort(net, ep, asoc, type, arg, commands);
  2367. }
  2368. static enum sctp_disposition __sctp_sf_do_9_1_abort(
  2369. struct net *net,
  2370. const struct sctp_endpoint *ep,
  2371. const struct sctp_association *asoc,
  2372. const union sctp_subtype type,
  2373. void *arg,
  2374. struct sctp_cmd_seq *commands)
  2375. {
  2376. __be16 error = SCTP_ERROR_NO_ERROR;
  2377. struct sctp_chunk *chunk = arg;
  2378. unsigned int len;
  2379. /* See if we have an error cause code in the chunk. */
  2380. len = ntohs(chunk->chunk_hdr->length);
  2381. if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
  2382. error = ((struct sctp_errhdr *)chunk->skb->data)->cause;
  2383. sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(ECONNRESET));
  2384. /* ASSOC_FAILED will DELETE_TCB. */
  2385. sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED, SCTP_PERR(error));
  2386. SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
  2387. SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
  2388. return SCTP_DISPOSITION_ABORT;
  2389. }
  2390. /*
  2391. * Process an ABORT. (COOKIE-WAIT state)
  2392. *
  2393. * See sctp_sf_do_9_1_abort() above.
  2394. */
  2395. enum sctp_disposition sctp_sf_cookie_wait_abort(
  2396. struct net *net,
  2397. const struct sctp_endpoint *ep,
  2398. const struct sctp_association *asoc,
  2399. const union sctp_subtype type,
  2400. void *arg,
  2401. struct sctp_cmd_seq *commands)
  2402. {
  2403. __be16 error = SCTP_ERROR_NO_ERROR;
  2404. struct sctp_chunk *chunk = arg;
  2405. unsigned int len;
  2406. if (!sctp_vtag_verify_either(chunk, asoc))
  2407. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2408. /* Make sure that the ABORT chunk has a valid length.
  2409. * Since this is an ABORT chunk, we have to discard it
  2410. * because of the following text:
  2411. * RFC 2960, Section 3.3.7
  2412. * If an endpoint receives an ABORT with a format error or for an
  2413. * association that doesn't exist, it MUST silently discard it.
  2414. * Because the length is "invalid", we can't really discard just
  2415. * as we do not know its true length. So, to be safe, discard the
  2416. * packet.
  2417. */
  2418. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_abort_chunk)))
  2419. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2420. /* See if we have an error cause code in the chunk. */
  2421. len = ntohs(chunk->chunk_hdr->length);
  2422. if (len >= sizeof(struct sctp_chunkhdr) + sizeof(struct sctp_errhdr))
  2423. error = ((struct sctp_errhdr *)chunk->skb->data)->cause;
  2424. return sctp_stop_t1_and_abort(net, commands, error, ECONNREFUSED, asoc,
  2425. chunk->transport);
  2426. }
  2427. /*
  2428. * Process an incoming ICMP as an ABORT. (COOKIE-WAIT state)
  2429. */
  2430. enum sctp_disposition sctp_sf_cookie_wait_icmp_abort(
  2431. struct net *net,
  2432. const struct sctp_endpoint *ep,
  2433. const struct sctp_association *asoc,
  2434. const union sctp_subtype type,
  2435. void *arg,
  2436. struct sctp_cmd_seq *commands)
  2437. {
  2438. return sctp_stop_t1_and_abort(net, commands, SCTP_ERROR_NO_ERROR,
  2439. ENOPROTOOPT, asoc,
  2440. (struct sctp_transport *)arg);
  2441. }
  2442. /*
  2443. * Process an ABORT. (COOKIE-ECHOED state)
  2444. */
  2445. enum sctp_disposition sctp_sf_cookie_echoed_abort(
  2446. struct net *net,
  2447. const struct sctp_endpoint *ep,
  2448. const struct sctp_association *asoc,
  2449. const union sctp_subtype type,
  2450. void *arg,
  2451. struct sctp_cmd_seq *commands)
  2452. {
  2453. /* There is a single T1 timer, so we should be able to use
  2454. * common function with the COOKIE-WAIT state.
  2455. */
  2456. return sctp_sf_cookie_wait_abort(net, ep, asoc, type, arg, commands);
  2457. }
  2458. /*
  2459. * Stop T1 timer and abort association with "INIT failed".
  2460. *
  2461. * This is common code called by several sctp_sf_*_abort() functions above.
  2462. */
  2463. static enum sctp_disposition sctp_stop_t1_and_abort(
  2464. struct net *net,
  2465. struct sctp_cmd_seq *commands,
  2466. __be16 error, int sk_err,
  2467. const struct sctp_association *asoc,
  2468. struct sctp_transport *transport)
  2469. {
  2470. pr_debug("%s: ABORT received (INIT)\n", __func__);
  2471. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
  2472. SCTP_STATE(SCTP_STATE_CLOSED));
  2473. SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
  2474. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  2475. SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
  2476. sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR, SCTP_ERROR(sk_err));
  2477. /* CMD_INIT_FAILED will DELETE_TCB. */
  2478. sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
  2479. SCTP_PERR(error));
  2480. return SCTP_DISPOSITION_ABORT;
  2481. }
  2482. /*
  2483. * sctp_sf_do_9_2_shut
  2484. *
  2485. * Section: 9.2
  2486. * Upon the reception of the SHUTDOWN, the peer endpoint shall
  2487. * - enter the SHUTDOWN-RECEIVED state,
  2488. *
  2489. * - stop accepting new data from its SCTP user
  2490. *
  2491. * - verify, by checking the Cumulative TSN Ack field of the chunk,
  2492. * that all its outstanding DATA chunks have been received by the
  2493. * SHUTDOWN sender.
  2494. *
  2495. * Once an endpoint as reached the SHUTDOWN-RECEIVED state it MUST NOT
  2496. * send a SHUTDOWN in response to a ULP request. And should discard
  2497. * subsequent SHUTDOWN chunks.
  2498. *
  2499. * If there are still outstanding DATA chunks left, the SHUTDOWN
  2500. * receiver shall continue to follow normal data transmission
  2501. * procedures defined in Section 6 until all outstanding DATA chunks
  2502. * are acknowledged; however, the SHUTDOWN receiver MUST NOT accept
  2503. * new data from its SCTP user.
  2504. *
  2505. * Verification Tag: 8.5 Verification Tag [Normal verification]
  2506. *
  2507. * Inputs
  2508. * (endpoint, asoc, chunk)
  2509. *
  2510. * Outputs
  2511. * (asoc, reply_msg, msg_up, timers, counters)
  2512. *
  2513. * The return value is the disposition of the chunk.
  2514. */
  2515. enum sctp_disposition sctp_sf_do_9_2_shutdown(
  2516. struct net *net,
  2517. const struct sctp_endpoint *ep,
  2518. const struct sctp_association *asoc,
  2519. const union sctp_subtype type,
  2520. void *arg,
  2521. struct sctp_cmd_seq *commands)
  2522. {
  2523. enum sctp_disposition disposition;
  2524. struct sctp_chunk *chunk = arg;
  2525. struct sctp_shutdownhdr *sdh;
  2526. struct sctp_ulpevent *ev;
  2527. __u32 ctsn;
  2528. if (!sctp_vtag_verify(chunk, asoc))
  2529. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2530. /* Make sure that the SHUTDOWN chunk has a valid length. */
  2531. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk)))
  2532. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  2533. commands);
  2534. /* Convert the elaborate header. */
  2535. sdh = (struct sctp_shutdownhdr *)chunk->skb->data;
  2536. skb_pull(chunk->skb, sizeof(*sdh));
  2537. chunk->subh.shutdown_hdr = sdh;
  2538. ctsn = ntohl(sdh->cum_tsn_ack);
  2539. if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
  2540. pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__, ctsn,
  2541. asoc->ctsn_ack_point);
  2542. return SCTP_DISPOSITION_DISCARD;
  2543. }
  2544. /* If Cumulative TSN Ack beyond the max tsn currently
  2545. * send, terminating the association and respond to the
  2546. * sender with an ABORT.
  2547. */
  2548. if (!TSN_lt(ctsn, asoc->next_tsn))
  2549. return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands);
  2550. /* API 5.3.1.5 SCTP_SHUTDOWN_EVENT
  2551. * When a peer sends a SHUTDOWN, SCTP delivers this notification to
  2552. * inform the application that it should cease sending data.
  2553. */
  2554. ev = sctp_ulpevent_make_shutdown_event(asoc, 0, GFP_ATOMIC);
  2555. if (!ev) {
  2556. disposition = SCTP_DISPOSITION_NOMEM;
  2557. goto out;
  2558. }
  2559. sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
  2560. /* Upon the reception of the SHUTDOWN, the peer endpoint shall
  2561. * - enter the SHUTDOWN-RECEIVED state,
  2562. * - stop accepting new data from its SCTP user
  2563. *
  2564. * [This is implicit in the new state.]
  2565. */
  2566. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
  2567. SCTP_STATE(SCTP_STATE_SHUTDOWN_RECEIVED));
  2568. disposition = SCTP_DISPOSITION_CONSUME;
  2569. if (sctp_outq_is_empty(&asoc->outqueue)) {
  2570. disposition = sctp_sf_do_9_2_shutdown_ack(net, ep, asoc, type,
  2571. arg, commands);
  2572. }
  2573. if (SCTP_DISPOSITION_NOMEM == disposition)
  2574. goto out;
  2575. /* - verify, by checking the Cumulative TSN Ack field of the
  2576. * chunk, that all its outstanding DATA chunks have been
  2577. * received by the SHUTDOWN sender.
  2578. */
  2579. sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
  2580. SCTP_BE32(chunk->subh.shutdown_hdr->cum_tsn_ack));
  2581. out:
  2582. return disposition;
  2583. }
  2584. /*
  2585. * sctp_sf_do_9_2_shut_ctsn
  2586. *
  2587. * Once an endpoint has reached the SHUTDOWN-RECEIVED state,
  2588. * it MUST NOT send a SHUTDOWN in response to a ULP request.
  2589. * The Cumulative TSN Ack of the received SHUTDOWN chunk
  2590. * MUST be processed.
  2591. */
  2592. enum sctp_disposition sctp_sf_do_9_2_shut_ctsn(
  2593. struct net *net,
  2594. const struct sctp_endpoint *ep,
  2595. const struct sctp_association *asoc,
  2596. const union sctp_subtype type,
  2597. void *arg,
  2598. struct sctp_cmd_seq *commands)
  2599. {
  2600. struct sctp_chunk *chunk = arg;
  2601. struct sctp_shutdownhdr *sdh;
  2602. __u32 ctsn;
  2603. if (!sctp_vtag_verify(chunk, asoc))
  2604. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2605. /* Make sure that the SHUTDOWN chunk has a valid length. */
  2606. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_shutdown_chunk)))
  2607. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  2608. commands);
  2609. sdh = (struct sctp_shutdownhdr *)chunk->skb->data;
  2610. ctsn = ntohl(sdh->cum_tsn_ack);
  2611. if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
  2612. pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__, ctsn,
  2613. asoc->ctsn_ack_point);
  2614. return SCTP_DISPOSITION_DISCARD;
  2615. }
  2616. /* If Cumulative TSN Ack beyond the max tsn currently
  2617. * send, terminating the association and respond to the
  2618. * sender with an ABORT.
  2619. */
  2620. if (!TSN_lt(ctsn, asoc->next_tsn))
  2621. return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands);
  2622. /* verify, by checking the Cumulative TSN Ack field of the
  2623. * chunk, that all its outstanding DATA chunks have been
  2624. * received by the SHUTDOWN sender.
  2625. */
  2626. sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_CTSN,
  2627. SCTP_BE32(sdh->cum_tsn_ack));
  2628. return SCTP_DISPOSITION_CONSUME;
  2629. }
  2630. /* RFC 2960 9.2
  2631. * If an endpoint is in SHUTDOWN-ACK-SENT state and receives an INIT chunk
  2632. * (e.g., if the SHUTDOWN COMPLETE was lost) with source and destination
  2633. * transport addresses (either in the IP addresses or in the INIT chunk)
  2634. * that belong to this association, it should discard the INIT chunk and
  2635. * retransmit the SHUTDOWN ACK chunk.
  2636. */
  2637. static enum sctp_disposition
  2638. __sctp_sf_do_9_2_reshutack(struct net *net, const struct sctp_endpoint *ep,
  2639. const struct sctp_association *asoc,
  2640. const union sctp_subtype type, void *arg,
  2641. struct sctp_cmd_seq *commands)
  2642. {
  2643. struct sctp_chunk *chunk = arg;
  2644. struct sctp_chunk *reply;
  2645. /* Make sure that the chunk has a valid length */
  2646. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
  2647. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  2648. commands);
  2649. /* Since we are not going to really process this INIT, there
  2650. * is no point in verifying chunk boundaries. Just generate
  2651. * the SHUTDOWN ACK.
  2652. */
  2653. reply = sctp_make_shutdown_ack(asoc, chunk);
  2654. if (NULL == reply)
  2655. goto nomem;
  2656. /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
  2657. * the T2-SHUTDOWN timer.
  2658. */
  2659. sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
  2660. /* and restart the T2-shutdown timer. */
  2661. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
  2662. SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
  2663. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
  2664. return SCTP_DISPOSITION_CONSUME;
  2665. nomem:
  2666. return SCTP_DISPOSITION_NOMEM;
  2667. }
  2668. enum sctp_disposition
  2669. sctp_sf_do_9_2_reshutack(struct net *net, const struct sctp_endpoint *ep,
  2670. const struct sctp_association *asoc,
  2671. const union sctp_subtype type, void *arg,
  2672. struct sctp_cmd_seq *commands)
  2673. {
  2674. struct sctp_chunk *chunk = arg;
  2675. if (!chunk->singleton)
  2676. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2677. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_init_chunk)))
  2678. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2679. if (chunk->sctp_hdr->vtag != 0)
  2680. return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
  2681. return __sctp_sf_do_9_2_reshutack(net, ep, asoc, type, arg, commands);
  2682. }
  2683. /*
  2684. * sctp_sf_do_ecn_cwr
  2685. *
  2686. * Section: Appendix A: Explicit Congestion Notification
  2687. *
  2688. * CWR:
  2689. *
  2690. * RFC 2481 details a specific bit for a sender to send in the header of
  2691. * its next outbound TCP segment to indicate to its peer that it has
  2692. * reduced its congestion window. This is termed the CWR bit. For
  2693. * SCTP the same indication is made by including the CWR chunk.
  2694. * This chunk contains one data element, i.e. the TSN number that
  2695. * was sent in the ECNE chunk. This element represents the lowest
  2696. * TSN number in the datagram that was originally marked with the
  2697. * CE bit.
  2698. *
  2699. * Verification Tag: 8.5 Verification Tag [Normal verification]
  2700. * Inputs
  2701. * (endpoint, asoc, chunk)
  2702. *
  2703. * Outputs
  2704. * (asoc, reply_msg, msg_up, timers, counters)
  2705. *
  2706. * The return value is the disposition of the chunk.
  2707. */
  2708. enum sctp_disposition sctp_sf_do_ecn_cwr(struct net *net,
  2709. const struct sctp_endpoint *ep,
  2710. const struct sctp_association *asoc,
  2711. const union sctp_subtype type,
  2712. void *arg,
  2713. struct sctp_cmd_seq *commands)
  2714. {
  2715. struct sctp_chunk *chunk = arg;
  2716. struct sctp_cwrhdr *cwr;
  2717. u32 lowest_tsn;
  2718. if (!sctp_vtag_verify(chunk, asoc))
  2719. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2720. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_ecne_chunk)))
  2721. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  2722. commands);
  2723. cwr = (struct sctp_cwrhdr *)chunk->skb->data;
  2724. skb_pull(chunk->skb, sizeof(*cwr));
  2725. lowest_tsn = ntohl(cwr->lowest_tsn);
  2726. /* Does this CWR ack the last sent congestion notification? */
  2727. if (TSN_lte(asoc->last_ecne_tsn, lowest_tsn)) {
  2728. /* Stop sending ECNE. */
  2729. sctp_add_cmd_sf(commands,
  2730. SCTP_CMD_ECN_CWR,
  2731. SCTP_U32(lowest_tsn));
  2732. }
  2733. return SCTP_DISPOSITION_CONSUME;
  2734. }
  2735. /*
  2736. * sctp_sf_do_ecne
  2737. *
  2738. * Section: Appendix A: Explicit Congestion Notification
  2739. *
  2740. * ECN-Echo
  2741. *
  2742. * RFC 2481 details a specific bit for a receiver to send back in its
  2743. * TCP acknowledgements to notify the sender of the Congestion
  2744. * Experienced (CE) bit having arrived from the network. For SCTP this
  2745. * same indication is made by including the ECNE chunk. This chunk
  2746. * contains one data element, i.e. the lowest TSN associated with the IP
  2747. * datagram marked with the CE bit.....
  2748. *
  2749. * Verification Tag: 8.5 Verification Tag [Normal verification]
  2750. * Inputs
  2751. * (endpoint, asoc, chunk)
  2752. *
  2753. * Outputs
  2754. * (asoc, reply_msg, msg_up, timers, counters)
  2755. *
  2756. * The return value is the disposition of the chunk.
  2757. */
  2758. enum sctp_disposition sctp_sf_do_ecne(struct net *net,
  2759. const struct sctp_endpoint *ep,
  2760. const struct sctp_association *asoc,
  2761. const union sctp_subtype type,
  2762. void *arg, struct sctp_cmd_seq *commands)
  2763. {
  2764. struct sctp_chunk *chunk = arg;
  2765. struct sctp_ecnehdr *ecne;
  2766. if (!sctp_vtag_verify(chunk, asoc))
  2767. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2768. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_ecne_chunk)))
  2769. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  2770. commands);
  2771. ecne = (struct sctp_ecnehdr *)chunk->skb->data;
  2772. skb_pull(chunk->skb, sizeof(*ecne));
  2773. /* If this is a newer ECNE than the last CWR packet we sent out */
  2774. sctp_add_cmd_sf(commands, SCTP_CMD_ECN_ECNE,
  2775. SCTP_U32(ntohl(ecne->lowest_tsn)));
  2776. return SCTP_DISPOSITION_CONSUME;
  2777. }
  2778. /*
  2779. * Section: 6.2 Acknowledgement on Reception of DATA Chunks
  2780. *
  2781. * The SCTP endpoint MUST always acknowledge the reception of each valid
  2782. * DATA chunk.
  2783. *
  2784. * The guidelines on delayed acknowledgement algorithm specified in
  2785. * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
  2786. * acknowledgement SHOULD be generated for at least every second packet
  2787. * (not every second DATA chunk) received, and SHOULD be generated within
  2788. * 200 ms of the arrival of any unacknowledged DATA chunk. In some
  2789. * situations it may be beneficial for an SCTP transmitter to be more
  2790. * conservative than the algorithms detailed in this document allow.
  2791. * However, an SCTP transmitter MUST NOT be more aggressive than the
  2792. * following algorithms allow.
  2793. *
  2794. * A SCTP receiver MUST NOT generate more than one SACK for every
  2795. * incoming packet, other than to update the offered window as the
  2796. * receiving application consumes new data.
  2797. *
  2798. * Verification Tag: 8.5 Verification Tag [Normal verification]
  2799. *
  2800. * Inputs
  2801. * (endpoint, asoc, chunk)
  2802. *
  2803. * Outputs
  2804. * (asoc, reply_msg, msg_up, timers, counters)
  2805. *
  2806. * The return value is the disposition of the chunk.
  2807. */
  2808. enum sctp_disposition sctp_sf_eat_data_6_2(struct net *net,
  2809. const struct sctp_endpoint *ep,
  2810. const struct sctp_association *asoc,
  2811. const union sctp_subtype type,
  2812. void *arg,
  2813. struct sctp_cmd_seq *commands)
  2814. {
  2815. union sctp_arg force = SCTP_NOFORCE();
  2816. struct sctp_chunk *chunk = arg;
  2817. int error;
  2818. if (!sctp_vtag_verify(chunk, asoc)) {
  2819. sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
  2820. SCTP_NULL());
  2821. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2822. }
  2823. if (!sctp_chunk_length_valid(chunk, sctp_datachk_len(&asoc->stream)))
  2824. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  2825. commands);
  2826. error = sctp_eat_data(asoc, chunk, commands);
  2827. switch (error) {
  2828. case SCTP_IERROR_NO_ERROR:
  2829. break;
  2830. case SCTP_IERROR_HIGH_TSN:
  2831. case SCTP_IERROR_BAD_STREAM:
  2832. SCTP_INC_STATS(net, SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
  2833. goto discard_noforce;
  2834. case SCTP_IERROR_DUP_TSN:
  2835. case SCTP_IERROR_IGNORE_TSN:
  2836. SCTP_INC_STATS(net, SCTP_MIB_IN_DATA_CHUNK_DISCARDS);
  2837. goto discard_force;
  2838. case SCTP_IERROR_NO_DATA:
  2839. return SCTP_DISPOSITION_ABORT;
  2840. case SCTP_IERROR_PROTO_VIOLATION:
  2841. return sctp_sf_abort_violation(net, ep, asoc, chunk, commands,
  2842. (u8 *)chunk->subh.data_hdr,
  2843. sctp_datahdr_len(&asoc->stream));
  2844. default:
  2845. BUG();
  2846. }
  2847. if (chunk->chunk_hdr->flags & SCTP_DATA_SACK_IMM)
  2848. force = SCTP_FORCE();
  2849. if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) {
  2850. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
  2851. SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
  2852. }
  2853. /* If this is the last chunk in a packet, we need to count it
  2854. * toward sack generation. Note that we need to SACK every
  2855. * OTHER packet containing data chunks, EVEN IF WE DISCARD
  2856. * THEM. We elect to NOT generate SACK's if the chunk fails
  2857. * the verification tag test.
  2858. *
  2859. * RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
  2860. *
  2861. * The SCTP endpoint MUST always acknowledge the reception of
  2862. * each valid DATA chunk.
  2863. *
  2864. * The guidelines on delayed acknowledgement algorithm
  2865. * specified in Section 4.2 of [RFC2581] SHOULD be followed.
  2866. * Specifically, an acknowledgement SHOULD be generated for at
  2867. * least every second packet (not every second DATA chunk)
  2868. * received, and SHOULD be generated within 200 ms of the
  2869. * arrival of any unacknowledged DATA chunk. In some
  2870. * situations it may be beneficial for an SCTP transmitter to
  2871. * be more conservative than the algorithms detailed in this
  2872. * document allow. However, an SCTP transmitter MUST NOT be
  2873. * more aggressive than the following algorithms allow.
  2874. */
  2875. if (chunk->end_of_packet)
  2876. sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, force);
  2877. return SCTP_DISPOSITION_CONSUME;
  2878. discard_force:
  2879. /* RFC 2960 6.2 Acknowledgement on Reception of DATA Chunks
  2880. *
  2881. * When a packet arrives with duplicate DATA chunk(s) and with
  2882. * no new DATA chunk(s), the endpoint MUST immediately send a
  2883. * SACK with no delay. If a packet arrives with duplicate
  2884. * DATA chunk(s) bundled with new DATA chunks, the endpoint
  2885. * MAY immediately send a SACK. Normally receipt of duplicate
  2886. * DATA chunks will occur when the original SACK chunk was lost
  2887. * and the peer's RTO has expired. The duplicate TSN number(s)
  2888. * SHOULD be reported in the SACK as duplicate.
  2889. */
  2890. /* In our case, we split the MAY SACK advice up whether or not
  2891. * the last chunk is a duplicate.'
  2892. */
  2893. if (chunk->end_of_packet)
  2894. sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
  2895. return SCTP_DISPOSITION_DISCARD;
  2896. discard_noforce:
  2897. if (chunk->end_of_packet)
  2898. sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, force);
  2899. return SCTP_DISPOSITION_DISCARD;
  2900. }
  2901. /*
  2902. * sctp_sf_eat_data_fast_4_4
  2903. *
  2904. * Section: 4 (4)
  2905. * (4) In SHUTDOWN-SENT state the endpoint MUST acknowledge any received
  2906. * DATA chunks without delay.
  2907. *
  2908. * Verification Tag: 8.5 Verification Tag [Normal verification]
  2909. * Inputs
  2910. * (endpoint, asoc, chunk)
  2911. *
  2912. * Outputs
  2913. * (asoc, reply_msg, msg_up, timers, counters)
  2914. *
  2915. * The return value is the disposition of the chunk.
  2916. */
  2917. enum sctp_disposition sctp_sf_eat_data_fast_4_4(
  2918. struct net *net,
  2919. const struct sctp_endpoint *ep,
  2920. const struct sctp_association *asoc,
  2921. const union sctp_subtype type,
  2922. void *arg,
  2923. struct sctp_cmd_seq *commands)
  2924. {
  2925. struct sctp_chunk *chunk = arg;
  2926. int error;
  2927. if (!sctp_vtag_verify(chunk, asoc)) {
  2928. sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
  2929. SCTP_NULL());
  2930. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  2931. }
  2932. if (!sctp_chunk_length_valid(chunk, sctp_datachk_len(&asoc->stream)))
  2933. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  2934. commands);
  2935. error = sctp_eat_data(asoc, chunk, commands);
  2936. switch (error) {
  2937. case SCTP_IERROR_NO_ERROR:
  2938. case SCTP_IERROR_HIGH_TSN:
  2939. case SCTP_IERROR_DUP_TSN:
  2940. case SCTP_IERROR_IGNORE_TSN:
  2941. case SCTP_IERROR_BAD_STREAM:
  2942. break;
  2943. case SCTP_IERROR_NO_DATA:
  2944. return SCTP_DISPOSITION_ABORT;
  2945. case SCTP_IERROR_PROTO_VIOLATION:
  2946. return sctp_sf_abort_violation(net, ep, asoc, chunk, commands,
  2947. (u8 *)chunk->subh.data_hdr,
  2948. sctp_datahdr_len(&asoc->stream));
  2949. default:
  2950. BUG();
  2951. }
  2952. /* Go a head and force a SACK, since we are shutting down. */
  2953. /* Implementor's Guide.
  2954. *
  2955. * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
  2956. * respond to each received packet containing one or more DATA chunk(s)
  2957. * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
  2958. */
  2959. if (chunk->end_of_packet) {
  2960. /* We must delay the chunk creation since the cumulative
  2961. * TSN has not been updated yet.
  2962. */
  2963. sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
  2964. sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
  2965. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
  2966. SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
  2967. }
  2968. return SCTP_DISPOSITION_CONSUME;
  2969. }
  2970. /*
  2971. * Section: 6.2 Processing a Received SACK
  2972. * D) Any time a SACK arrives, the endpoint performs the following:
  2973. *
  2974. * i) If Cumulative TSN Ack is less than the Cumulative TSN Ack Point,
  2975. * then drop the SACK. Since Cumulative TSN Ack is monotonically
  2976. * increasing, a SACK whose Cumulative TSN Ack is less than the
  2977. * Cumulative TSN Ack Point indicates an out-of-order SACK.
  2978. *
  2979. * ii) Set rwnd equal to the newly received a_rwnd minus the number
  2980. * of bytes still outstanding after processing the Cumulative TSN Ack
  2981. * and the Gap Ack Blocks.
  2982. *
  2983. * iii) If the SACK is missing a TSN that was previously
  2984. * acknowledged via a Gap Ack Block (e.g., the data receiver
  2985. * reneged on the data), then mark the corresponding DATA chunk
  2986. * as available for retransmit: Mark it as missing for fast
  2987. * retransmit as described in Section 7.2.4 and if no retransmit
  2988. * timer is running for the destination address to which the DATA
  2989. * chunk was originally transmitted, then T3-rtx is started for
  2990. * that destination address.
  2991. *
  2992. * Verification Tag: 8.5 Verification Tag [Normal verification]
  2993. *
  2994. * Inputs
  2995. * (endpoint, asoc, chunk)
  2996. *
  2997. * Outputs
  2998. * (asoc, reply_msg, msg_up, timers, counters)
  2999. *
  3000. * The return value is the disposition of the chunk.
  3001. */
  3002. enum sctp_disposition sctp_sf_eat_sack_6_2(struct net *net,
  3003. const struct sctp_endpoint *ep,
  3004. const struct sctp_association *asoc,
  3005. const union sctp_subtype type,
  3006. void *arg,
  3007. struct sctp_cmd_seq *commands)
  3008. {
  3009. struct sctp_chunk *chunk = arg;
  3010. struct sctp_sackhdr *sackh;
  3011. __u32 ctsn;
  3012. if (!sctp_vtag_verify(chunk, asoc))
  3013. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  3014. /* Make sure that the SACK chunk has a valid length. */
  3015. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_sack_chunk)))
  3016. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  3017. commands);
  3018. /* Pull the SACK chunk from the data buffer */
  3019. sackh = sctp_sm_pull_sack(chunk);
  3020. /* Was this a bogus SACK? */
  3021. if (!sackh)
  3022. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  3023. chunk->subh.sack_hdr = sackh;
  3024. ctsn = ntohl(sackh->cum_tsn_ack);
  3025. /* If Cumulative TSN Ack beyond the max tsn currently
  3026. * send, terminating the association and respond to the
  3027. * sender with an ABORT.
  3028. */
  3029. if (TSN_lte(asoc->next_tsn, ctsn))
  3030. return sctp_sf_violation_ctsn(net, ep, asoc, type, arg, commands);
  3031. trace_sctp_probe(ep, asoc, chunk);
  3032. /* i) If Cumulative TSN Ack is less than the Cumulative TSN
  3033. * Ack Point, then drop the SACK. Since Cumulative TSN
  3034. * Ack is monotonically increasing, a SACK whose
  3035. * Cumulative TSN Ack is less than the Cumulative TSN Ack
  3036. * Point indicates an out-of-order SACK.
  3037. */
  3038. if (TSN_lt(ctsn, asoc->ctsn_ack_point)) {
  3039. pr_debug("%s: ctsn:%x, ctsn_ack_point:%x\n", __func__, ctsn,
  3040. asoc->ctsn_ack_point);
  3041. return SCTP_DISPOSITION_DISCARD;
  3042. }
  3043. /* Return this SACK for further processing. */
  3044. sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_SACK, SCTP_CHUNK(chunk));
  3045. /* Note: We do the rest of the work on the PROCESS_SACK
  3046. * sideeffect.
  3047. */
  3048. return SCTP_DISPOSITION_CONSUME;
  3049. }
  3050. /*
  3051. * Generate an ABORT in response to a packet.
  3052. *
  3053. * Section: 8.4 Handle "Out of the blue" Packets, sctpimpguide 2.41
  3054. *
  3055. * 8) The receiver should respond to the sender of the OOTB packet with
  3056. * an ABORT. When sending the ABORT, the receiver of the OOTB packet
  3057. * MUST fill in the Verification Tag field of the outbound packet
  3058. * with the value found in the Verification Tag field of the OOTB
  3059. * packet and set the T-bit in the Chunk Flags to indicate that the
  3060. * Verification Tag is reflected. After sending this ABORT, the
  3061. * receiver of the OOTB packet shall discard the OOTB packet and take
  3062. * no further action.
  3063. *
  3064. * Verification Tag:
  3065. *
  3066. * The return value is the disposition of the chunk.
  3067. */
  3068. static enum sctp_disposition sctp_sf_tabort_8_4_8(
  3069. struct net *net,
  3070. const struct sctp_endpoint *ep,
  3071. const struct sctp_association *asoc,
  3072. const union sctp_subtype type,
  3073. void *arg,
  3074. struct sctp_cmd_seq *commands)
  3075. {
  3076. struct sctp_packet *packet = NULL;
  3077. struct sctp_chunk *chunk = arg;
  3078. struct sctp_chunk *abort;
  3079. packet = sctp_ootb_pkt_new(net, asoc, chunk);
  3080. if (!packet)
  3081. return SCTP_DISPOSITION_NOMEM;
  3082. /* Make an ABORT. The T bit will be set if the asoc
  3083. * is NULL.
  3084. */
  3085. abort = sctp_make_abort(asoc, chunk, 0);
  3086. if (!abort) {
  3087. sctp_ootb_pkt_free(packet);
  3088. return SCTP_DISPOSITION_NOMEM;
  3089. }
  3090. /* Reflect vtag if T-Bit is set */
  3091. if (sctp_test_T_bit(abort))
  3092. packet->vtag = ntohl(chunk->sctp_hdr->vtag);
  3093. /* Set the skb to the belonging sock for accounting. */
  3094. abort->skb->sk = ep->base.sk;
  3095. sctp_packet_append_chunk(packet, abort);
  3096. sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT, SCTP_PACKET(packet));
  3097. SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
  3098. sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  3099. return SCTP_DISPOSITION_CONSUME;
  3100. }
  3101. /* Handling of SCTP Packets Containing an INIT Chunk Matching an
  3102. * Existing Associations when the UDP encap port is incorrect.
  3103. *
  3104. * From Section 4 at draft-tuexen-tsvwg-sctp-udp-encaps-cons-03.
  3105. */
  3106. static enum sctp_disposition sctp_sf_new_encap_port(
  3107. struct net *net,
  3108. const struct sctp_endpoint *ep,
  3109. const struct sctp_association *asoc,
  3110. const union sctp_subtype type,
  3111. void *arg,
  3112. struct sctp_cmd_seq *commands)
  3113. {
  3114. struct sctp_packet *packet = NULL;
  3115. struct sctp_chunk *chunk = arg;
  3116. struct sctp_chunk *abort;
  3117. packet = sctp_ootb_pkt_new(net, asoc, chunk);
  3118. if (!packet)
  3119. return SCTP_DISPOSITION_NOMEM;
  3120. abort = sctp_make_new_encap_port(asoc, chunk);
  3121. if (!abort) {
  3122. sctp_ootb_pkt_free(packet);
  3123. return SCTP_DISPOSITION_NOMEM;
  3124. }
  3125. abort->skb->sk = ep->base.sk;
  3126. sctp_packet_append_chunk(packet, abort);
  3127. sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
  3128. SCTP_PACKET(packet));
  3129. SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
  3130. sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  3131. return SCTP_DISPOSITION_CONSUME;
  3132. }
  3133. /*
  3134. * Received an ERROR chunk from peer. Generate SCTP_REMOTE_ERROR
  3135. * event as ULP notification for each cause included in the chunk.
  3136. *
  3137. * API 5.3.1.3 - SCTP_REMOTE_ERROR
  3138. *
  3139. * The return value is the disposition of the chunk.
  3140. */
  3141. enum sctp_disposition sctp_sf_operr_notify(struct net *net,
  3142. const struct sctp_endpoint *ep,
  3143. const struct sctp_association *asoc,
  3144. const union sctp_subtype type,
  3145. void *arg,
  3146. struct sctp_cmd_seq *commands)
  3147. {
  3148. struct sctp_chunk *chunk = arg;
  3149. struct sctp_errhdr *err;
  3150. if (!sctp_vtag_verify(chunk, asoc))
  3151. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  3152. /* Make sure that the ERROR chunk has a valid length. */
  3153. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_operr_chunk)))
  3154. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  3155. commands);
  3156. sctp_walk_errors(err, chunk->chunk_hdr);
  3157. if ((void *)err != (void *)chunk->chunk_end)
  3158. return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
  3159. (void *)err, commands);
  3160. sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_OPERR,
  3161. SCTP_CHUNK(chunk));
  3162. return SCTP_DISPOSITION_CONSUME;
  3163. }
  3164. /*
  3165. * Process an inbound SHUTDOWN ACK.
  3166. *
  3167. * From Section 9.2:
  3168. * Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
  3169. * stop the T2-shutdown timer, send a SHUTDOWN COMPLETE chunk to its
  3170. * peer, and remove all record of the association.
  3171. *
  3172. * The return value is the disposition.
  3173. */
  3174. enum sctp_disposition sctp_sf_do_9_2_final(struct net *net,
  3175. const struct sctp_endpoint *ep,
  3176. const struct sctp_association *asoc,
  3177. const union sctp_subtype type,
  3178. void *arg,
  3179. struct sctp_cmd_seq *commands)
  3180. {
  3181. struct sctp_chunk *chunk = arg;
  3182. struct sctp_chunk *reply;
  3183. struct sctp_ulpevent *ev;
  3184. if (!sctp_vtag_verify(chunk, asoc))
  3185. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  3186. /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
  3187. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
  3188. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  3189. commands);
  3190. /* 10.2 H) SHUTDOWN COMPLETE notification
  3191. *
  3192. * When SCTP completes the shutdown procedures (section 9.2) this
  3193. * notification is passed to the upper layer.
  3194. */
  3195. ev = sctp_ulpevent_make_assoc_change(asoc, 0, SCTP_SHUTDOWN_COMP,
  3196. 0, 0, 0, NULL, GFP_ATOMIC);
  3197. if (!ev)
  3198. goto nomem;
  3199. /* ...send a SHUTDOWN COMPLETE chunk to its peer, */
  3200. reply = sctp_make_shutdown_complete(asoc, chunk);
  3201. if (!reply)
  3202. goto nomem_chunk;
  3203. /* Do all the commands now (after allocation), so that we
  3204. * have consistent state if memory allocation fails
  3205. */
  3206. sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(ev));
  3207. /* Upon the receipt of the SHUTDOWN ACK, the SHUTDOWN sender shall
  3208. * stop the T2-shutdown timer,
  3209. */
  3210. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  3211. SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
  3212. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  3213. SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
  3214. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
  3215. SCTP_STATE(SCTP_STATE_CLOSED));
  3216. SCTP_INC_STATS(net, SCTP_MIB_SHUTDOWNS);
  3217. SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
  3218. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
  3219. /* ...and remove all record of the association. */
  3220. sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
  3221. return SCTP_DISPOSITION_DELETE_TCB;
  3222. nomem_chunk:
  3223. sctp_ulpevent_free(ev);
  3224. nomem:
  3225. return SCTP_DISPOSITION_NOMEM;
  3226. }
  3227. /*
  3228. * RFC 2960, 8.4 - Handle "Out of the blue" Packets, sctpimpguide 2.41.
  3229. *
  3230. * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
  3231. * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
  3232. * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
  3233. * packet must fill in the Verification Tag field of the outbound
  3234. * packet with the Verification Tag received in the SHUTDOWN ACK and
  3235. * set the T-bit in the Chunk Flags to indicate that the Verification
  3236. * Tag is reflected.
  3237. *
  3238. * 8) The receiver should respond to the sender of the OOTB packet with
  3239. * an ABORT. When sending the ABORT, the receiver of the OOTB packet
  3240. * MUST fill in the Verification Tag field of the outbound packet
  3241. * with the value found in the Verification Tag field of the OOTB
  3242. * packet and set the T-bit in the Chunk Flags to indicate that the
  3243. * Verification Tag is reflected. After sending this ABORT, the
  3244. * receiver of the OOTB packet shall discard the OOTB packet and take
  3245. * no further action.
  3246. */
  3247. enum sctp_disposition sctp_sf_ootb(struct net *net,
  3248. const struct sctp_endpoint *ep,
  3249. const struct sctp_association *asoc,
  3250. const union sctp_subtype type,
  3251. void *arg, struct sctp_cmd_seq *commands)
  3252. {
  3253. struct sctp_chunk *chunk = arg;
  3254. struct sk_buff *skb = chunk->skb;
  3255. struct sctp_chunkhdr *ch;
  3256. struct sctp_errhdr *err;
  3257. int ootb_cookie_ack = 0;
  3258. int ootb_shut_ack = 0;
  3259. __u8 *ch_end;
  3260. SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES);
  3261. if (asoc && !sctp_vtag_verify(chunk, asoc))
  3262. asoc = NULL;
  3263. ch = (struct sctp_chunkhdr *)chunk->chunk_hdr;
  3264. do {
  3265. /* Report violation if the chunk is less then minimal */
  3266. if (ntohs(ch->length) < sizeof(*ch))
  3267. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  3268. commands);
  3269. /* Report violation if chunk len overflows */
  3270. ch_end = ((__u8 *)ch) + SCTP_PAD4(ntohs(ch->length));
  3271. if (ch_end > skb_tail_pointer(skb))
  3272. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  3273. commands);
  3274. /* Now that we know we at least have a chunk header,
  3275. * do things that are type appropriate.
  3276. */
  3277. if (SCTP_CID_SHUTDOWN_ACK == ch->type)
  3278. ootb_shut_ack = 1;
  3279. /* RFC 2960, Section 3.3.7
  3280. * Moreover, under any circumstances, an endpoint that
  3281. * receives an ABORT MUST NOT respond to that ABORT by
  3282. * sending an ABORT of its own.
  3283. */
  3284. if (SCTP_CID_ABORT == ch->type)
  3285. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  3286. /* RFC 8.4, 7) If the packet contains a "Stale cookie" ERROR
  3287. * or a COOKIE ACK the SCTP Packet should be silently
  3288. * discarded.
  3289. */
  3290. if (SCTP_CID_COOKIE_ACK == ch->type)
  3291. ootb_cookie_ack = 1;
  3292. if (SCTP_CID_ERROR == ch->type) {
  3293. sctp_walk_errors(err, ch) {
  3294. if (SCTP_ERROR_STALE_COOKIE == err->cause) {
  3295. ootb_cookie_ack = 1;
  3296. break;
  3297. }
  3298. }
  3299. }
  3300. ch = (struct sctp_chunkhdr *)ch_end;
  3301. } while (ch_end + sizeof(*ch) < skb_tail_pointer(skb));
  3302. if (ootb_shut_ack)
  3303. return sctp_sf_shut_8_4_5(net, ep, asoc, type, arg, commands);
  3304. else if (ootb_cookie_ack)
  3305. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  3306. else
  3307. return sctp_sf_tabort_8_4_8(net, ep, asoc, type, arg, commands);
  3308. }
  3309. /*
  3310. * Handle an "Out of the blue" SHUTDOWN ACK.
  3311. *
  3312. * Section: 8.4 5, sctpimpguide 2.41.
  3313. *
  3314. * 5) If the packet contains a SHUTDOWN ACK chunk, the receiver should
  3315. * respond to the sender of the OOTB packet with a SHUTDOWN COMPLETE.
  3316. * When sending the SHUTDOWN COMPLETE, the receiver of the OOTB
  3317. * packet must fill in the Verification Tag field of the outbound
  3318. * packet with the Verification Tag received in the SHUTDOWN ACK and
  3319. * set the T-bit in the Chunk Flags to indicate that the Verification
  3320. * Tag is reflected.
  3321. *
  3322. * Inputs
  3323. * (endpoint, asoc, type, arg, commands)
  3324. *
  3325. * Outputs
  3326. * (enum sctp_disposition)
  3327. *
  3328. * The return value is the disposition of the chunk.
  3329. */
  3330. static enum sctp_disposition sctp_sf_shut_8_4_5(
  3331. struct net *net,
  3332. const struct sctp_endpoint *ep,
  3333. const struct sctp_association *asoc,
  3334. const union sctp_subtype type,
  3335. void *arg,
  3336. struct sctp_cmd_seq *commands)
  3337. {
  3338. struct sctp_packet *packet = NULL;
  3339. struct sctp_chunk *chunk = arg;
  3340. struct sctp_chunk *shut;
  3341. packet = sctp_ootb_pkt_new(net, asoc, chunk);
  3342. if (!packet)
  3343. return SCTP_DISPOSITION_NOMEM;
  3344. /* Make an SHUTDOWN_COMPLETE.
  3345. * The T bit will be set if the asoc is NULL.
  3346. */
  3347. shut = sctp_make_shutdown_complete(asoc, chunk);
  3348. if (!shut) {
  3349. sctp_ootb_pkt_free(packet);
  3350. return SCTP_DISPOSITION_NOMEM;
  3351. }
  3352. /* Reflect vtag if T-Bit is set */
  3353. if (sctp_test_T_bit(shut))
  3354. packet->vtag = ntohl(chunk->sctp_hdr->vtag);
  3355. /* Set the skb to the belonging sock for accounting. */
  3356. shut->skb->sk = ep->base.sk;
  3357. sctp_packet_append_chunk(packet, shut);
  3358. sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
  3359. SCTP_PACKET(packet));
  3360. SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
  3361. /* We need to discard the rest of the packet to prevent
  3362. * potential boomming attacks from additional bundled chunks.
  3363. * This is documented in SCTP Threats ID.
  3364. */
  3365. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  3366. }
  3367. /*
  3368. * Handle SHUTDOWN ACK in COOKIE_ECHOED or COOKIE_WAIT state.
  3369. *
  3370. * Verification Tag: 8.5.1 E) Rules for packet carrying a SHUTDOWN ACK
  3371. * If the receiver is in COOKIE-ECHOED or COOKIE-WAIT state the
  3372. * procedures in section 8.4 SHOULD be followed, in other words it
  3373. * should be treated as an Out Of The Blue packet.
  3374. * [This means that we do NOT check the Verification Tag on these
  3375. * chunks. --piggy ]
  3376. *
  3377. */
  3378. enum sctp_disposition sctp_sf_do_8_5_1_E_sa(struct net *net,
  3379. const struct sctp_endpoint *ep,
  3380. const struct sctp_association *asoc,
  3381. const union sctp_subtype type,
  3382. void *arg,
  3383. struct sctp_cmd_seq *commands)
  3384. {
  3385. struct sctp_chunk *chunk = arg;
  3386. if (!sctp_vtag_verify(chunk, asoc))
  3387. asoc = NULL;
  3388. /* Make sure that the SHUTDOWN_ACK chunk has a valid length. */
  3389. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
  3390. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  3391. commands);
  3392. /* Although we do have an association in this case, it corresponds
  3393. * to a restarted association. So the packet is treated as an OOTB
  3394. * packet and the state function that handles OOTB SHUTDOWN_ACK is
  3395. * called with a NULL association.
  3396. */
  3397. SCTP_INC_STATS(net, SCTP_MIB_OUTOFBLUES);
  3398. return sctp_sf_shut_8_4_5(net, ep, NULL, type, arg, commands);
  3399. }
  3400. /* ADDIP Section 4.2 Upon reception of an ASCONF Chunk. */
  3401. enum sctp_disposition sctp_sf_do_asconf(struct net *net,
  3402. const struct sctp_endpoint *ep,
  3403. const struct sctp_association *asoc,
  3404. const union sctp_subtype type,
  3405. void *arg,
  3406. struct sctp_cmd_seq *commands)
  3407. {
  3408. struct sctp_paramhdr *err_param = NULL;
  3409. struct sctp_chunk *asconf_ack = NULL;
  3410. struct sctp_chunk *chunk = arg;
  3411. struct sctp_addiphdr *hdr;
  3412. __u32 serial;
  3413. if (!sctp_vtag_verify(chunk, asoc)) {
  3414. sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
  3415. SCTP_NULL());
  3416. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  3417. }
  3418. /* Make sure that the ASCONF ADDIP chunk has a valid length. */
  3419. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_addip_chunk)))
  3420. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  3421. commands);
  3422. /* ADD-IP: Section 4.1.1
  3423. * This chunk MUST be sent in an authenticated way by using
  3424. * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
  3425. * is received unauthenticated it MUST be silently discarded as
  3426. * described in [I-D.ietf-tsvwg-sctp-auth].
  3427. */
  3428. if (!asoc->peer.asconf_capable ||
  3429. (!net->sctp.addip_noauth && !chunk->auth))
  3430. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  3431. hdr = (struct sctp_addiphdr *)chunk->skb->data;
  3432. serial = ntohl(hdr->serial);
  3433. /* Verify the ASCONF chunk before processing it. */
  3434. if (!sctp_verify_asconf(asoc, chunk, true, &err_param))
  3435. return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
  3436. (void *)err_param, commands);
  3437. /* ADDIP 5.2 E1) Compare the value of the serial number to the value
  3438. * the endpoint stored in a new association variable
  3439. * 'Peer-Serial-Number'.
  3440. */
  3441. if (serial == asoc->peer.addip_serial + 1) {
  3442. /* If this is the first instance of ASCONF in the packet,
  3443. * we can clean our old ASCONF-ACKs.
  3444. */
  3445. if (!chunk->has_asconf)
  3446. sctp_assoc_clean_asconf_ack_cache(asoc);
  3447. /* ADDIP 5.2 E4) When the Sequence Number matches the next one
  3448. * expected, process the ASCONF as described below and after
  3449. * processing the ASCONF Chunk, append an ASCONF-ACK Chunk to
  3450. * the response packet and cache a copy of it (in the event it
  3451. * later needs to be retransmitted).
  3452. *
  3453. * Essentially, do V1-V5.
  3454. */
  3455. asconf_ack = sctp_process_asconf((struct sctp_association *)
  3456. asoc, chunk);
  3457. if (!asconf_ack)
  3458. return SCTP_DISPOSITION_NOMEM;
  3459. } else if (serial < asoc->peer.addip_serial + 1) {
  3460. /* ADDIP 5.2 E2)
  3461. * If the value found in the Sequence Number is less than the
  3462. * ('Peer- Sequence-Number' + 1), simply skip to the next
  3463. * ASCONF, and include in the outbound response packet
  3464. * any previously cached ASCONF-ACK response that was
  3465. * sent and saved that matches the Sequence Number of the
  3466. * ASCONF. Note: It is possible that no cached ASCONF-ACK
  3467. * Chunk exists. This will occur when an older ASCONF
  3468. * arrives out of order. In such a case, the receiver
  3469. * should skip the ASCONF Chunk and not include ASCONF-ACK
  3470. * Chunk for that chunk.
  3471. */
  3472. asconf_ack = sctp_assoc_lookup_asconf_ack(asoc, hdr->serial);
  3473. if (!asconf_ack)
  3474. return SCTP_DISPOSITION_DISCARD;
  3475. /* Reset the transport so that we select the correct one
  3476. * this time around. This is to make sure that we don't
  3477. * accidentally use a stale transport that's been removed.
  3478. */
  3479. asconf_ack->transport = NULL;
  3480. } else {
  3481. /* ADDIP 5.2 E5) Otherwise, the ASCONF Chunk is discarded since
  3482. * it must be either a stale packet or from an attacker.
  3483. */
  3484. return SCTP_DISPOSITION_DISCARD;
  3485. }
  3486. /* ADDIP 5.2 E6) The destination address of the SCTP packet
  3487. * containing the ASCONF-ACK Chunks MUST be the source address of
  3488. * the SCTP packet that held the ASCONF Chunks.
  3489. *
  3490. * To do this properly, we'll set the destination address of the chunk
  3491. * and at the transmit time, will try look up the transport to use.
  3492. * Since ASCONFs may be bundled, the correct transport may not be
  3493. * created until we process the entire packet, thus this workaround.
  3494. */
  3495. asconf_ack->dest = chunk->source;
  3496. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(asconf_ack));
  3497. if (asoc->new_transport) {
  3498. sctp_sf_heartbeat(ep, asoc, type, asoc->new_transport, commands);
  3499. ((struct sctp_association *)asoc)->new_transport = NULL;
  3500. }
  3501. return SCTP_DISPOSITION_CONSUME;
  3502. }
  3503. static enum sctp_disposition sctp_send_next_asconf(
  3504. struct net *net,
  3505. const struct sctp_endpoint *ep,
  3506. struct sctp_association *asoc,
  3507. const union sctp_subtype type,
  3508. struct sctp_cmd_seq *commands)
  3509. {
  3510. struct sctp_chunk *asconf;
  3511. struct list_head *entry;
  3512. if (list_empty(&asoc->addip_chunk_list))
  3513. return SCTP_DISPOSITION_CONSUME;
  3514. entry = asoc->addip_chunk_list.next;
  3515. asconf = list_entry(entry, struct sctp_chunk, list);
  3516. list_del_init(entry);
  3517. sctp_chunk_hold(asconf);
  3518. asoc->addip_last_asconf = asconf;
  3519. return sctp_sf_do_prm_asconf(net, ep, asoc, type, asconf, commands);
  3520. }
  3521. /*
  3522. * ADDIP Section 4.3 General rules for address manipulation
  3523. * When building TLV parameters for the ASCONF Chunk that will add or
  3524. * delete IP addresses the D0 to D13 rules should be applied:
  3525. */
  3526. enum sctp_disposition sctp_sf_do_asconf_ack(struct net *net,
  3527. const struct sctp_endpoint *ep,
  3528. const struct sctp_association *asoc,
  3529. const union sctp_subtype type,
  3530. void *arg,
  3531. struct sctp_cmd_seq *commands)
  3532. {
  3533. struct sctp_chunk *last_asconf = asoc->addip_last_asconf;
  3534. struct sctp_paramhdr *err_param = NULL;
  3535. struct sctp_chunk *asconf_ack = arg;
  3536. struct sctp_addiphdr *addip_hdr;
  3537. __u32 sent_serial, rcvd_serial;
  3538. struct sctp_chunk *abort;
  3539. if (!sctp_vtag_verify(asconf_ack, asoc)) {
  3540. sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
  3541. SCTP_NULL());
  3542. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  3543. }
  3544. /* Make sure that the ADDIP chunk has a valid length. */
  3545. if (!sctp_chunk_length_valid(asconf_ack,
  3546. sizeof(struct sctp_addip_chunk)))
  3547. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  3548. commands);
  3549. /* ADD-IP, Section 4.1.2:
  3550. * This chunk MUST be sent in an authenticated way by using
  3551. * the mechanism defined in [I-D.ietf-tsvwg-sctp-auth]. If this chunk
  3552. * is received unauthenticated it MUST be silently discarded as
  3553. * described in [I-D.ietf-tsvwg-sctp-auth].
  3554. */
  3555. if (!asoc->peer.asconf_capable ||
  3556. (!net->sctp.addip_noauth && !asconf_ack->auth))
  3557. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  3558. addip_hdr = (struct sctp_addiphdr *)asconf_ack->skb->data;
  3559. rcvd_serial = ntohl(addip_hdr->serial);
  3560. /* Verify the ASCONF-ACK chunk before processing it. */
  3561. if (!sctp_verify_asconf(asoc, asconf_ack, false, &err_param))
  3562. return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
  3563. (void *)err_param, commands);
  3564. if (last_asconf) {
  3565. addip_hdr = last_asconf->subh.addip_hdr;
  3566. sent_serial = ntohl(addip_hdr->serial);
  3567. } else {
  3568. sent_serial = asoc->addip_serial - 1;
  3569. }
  3570. /* D0) If an endpoint receives an ASCONF-ACK that is greater than or
  3571. * equal to the next serial number to be used but no ASCONF chunk is
  3572. * outstanding the endpoint MUST ABORT the association. Note that a
  3573. * sequence number is greater than if it is no more than 2^^31-1
  3574. * larger than the current sequence number (using serial arithmetic).
  3575. */
  3576. if (ADDIP_SERIAL_gte(rcvd_serial, sent_serial + 1) &&
  3577. !(asoc->addip_last_asconf)) {
  3578. abort = sctp_make_abort(asoc, asconf_ack,
  3579. sizeof(struct sctp_errhdr));
  3580. if (abort) {
  3581. sctp_init_cause(abort, SCTP_ERROR_ASCONF_ACK, 0);
  3582. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
  3583. SCTP_CHUNK(abort));
  3584. }
  3585. /* We are going to ABORT, so we might as well stop
  3586. * processing the rest of the chunks in the packet.
  3587. */
  3588. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  3589. SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
  3590. sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
  3591. sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
  3592. SCTP_ERROR(ECONNABORTED));
  3593. sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
  3594. SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
  3595. SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
  3596. SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
  3597. return SCTP_DISPOSITION_ABORT;
  3598. }
  3599. if ((rcvd_serial == sent_serial) && asoc->addip_last_asconf) {
  3600. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  3601. SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
  3602. if (!sctp_process_asconf_ack((struct sctp_association *)asoc,
  3603. asconf_ack))
  3604. return sctp_send_next_asconf(net, ep,
  3605. (struct sctp_association *)asoc,
  3606. type, commands);
  3607. abort = sctp_make_abort(asoc, asconf_ack,
  3608. sizeof(struct sctp_errhdr));
  3609. if (abort) {
  3610. sctp_init_cause(abort, SCTP_ERROR_RSRC_LOW, 0);
  3611. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
  3612. SCTP_CHUNK(abort));
  3613. }
  3614. /* We are going to ABORT, so we might as well stop
  3615. * processing the rest of the chunks in the packet.
  3616. */
  3617. sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
  3618. sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
  3619. SCTP_ERROR(ECONNABORTED));
  3620. sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
  3621. SCTP_PERR(SCTP_ERROR_ASCONF_ACK));
  3622. SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
  3623. SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
  3624. return SCTP_DISPOSITION_ABORT;
  3625. }
  3626. return SCTP_DISPOSITION_DISCARD;
  3627. }
  3628. /* RE-CONFIG Section 5.2 Upon reception of an RECONF Chunk. */
  3629. enum sctp_disposition sctp_sf_do_reconf(struct net *net,
  3630. const struct sctp_endpoint *ep,
  3631. const struct sctp_association *asoc,
  3632. const union sctp_subtype type,
  3633. void *arg,
  3634. struct sctp_cmd_seq *commands)
  3635. {
  3636. struct sctp_paramhdr *err_param = NULL;
  3637. struct sctp_chunk *chunk = arg;
  3638. struct sctp_reconf_chunk *hdr;
  3639. union sctp_params param;
  3640. if (!sctp_vtag_verify(chunk, asoc)) {
  3641. sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
  3642. SCTP_NULL());
  3643. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  3644. }
  3645. /* Make sure that the RECONF chunk has a valid length. */
  3646. if (!sctp_chunk_length_valid(chunk, sizeof(*hdr)))
  3647. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  3648. commands);
  3649. if (!sctp_verify_reconf(asoc, chunk, &err_param))
  3650. return sctp_sf_violation_paramlen(net, ep, asoc, type, arg,
  3651. (void *)err_param, commands);
  3652. hdr = (struct sctp_reconf_chunk *)chunk->chunk_hdr;
  3653. sctp_walk_params(param, hdr) {
  3654. struct sctp_chunk *reply = NULL;
  3655. struct sctp_ulpevent *ev = NULL;
  3656. if (param.p->type == SCTP_PARAM_RESET_OUT_REQUEST)
  3657. reply = sctp_process_strreset_outreq(
  3658. (struct sctp_association *)asoc, param, &ev);
  3659. else if (param.p->type == SCTP_PARAM_RESET_IN_REQUEST)
  3660. reply = sctp_process_strreset_inreq(
  3661. (struct sctp_association *)asoc, param, &ev);
  3662. else if (param.p->type == SCTP_PARAM_RESET_TSN_REQUEST)
  3663. reply = sctp_process_strreset_tsnreq(
  3664. (struct sctp_association *)asoc, param, &ev);
  3665. else if (param.p->type == SCTP_PARAM_RESET_ADD_OUT_STREAMS)
  3666. reply = sctp_process_strreset_addstrm_out(
  3667. (struct sctp_association *)asoc, param, &ev);
  3668. else if (param.p->type == SCTP_PARAM_RESET_ADD_IN_STREAMS)
  3669. reply = sctp_process_strreset_addstrm_in(
  3670. (struct sctp_association *)asoc, param, &ev);
  3671. else if (param.p->type == SCTP_PARAM_RESET_RESPONSE)
  3672. reply = sctp_process_strreset_resp(
  3673. (struct sctp_association *)asoc, param, &ev);
  3674. if (ev)
  3675. sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
  3676. SCTP_ULPEVENT(ev));
  3677. if (reply)
  3678. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
  3679. SCTP_CHUNK(reply));
  3680. }
  3681. return SCTP_DISPOSITION_CONSUME;
  3682. }
  3683. /*
  3684. * PR-SCTP Section 3.6 Receiver Side Implementation of PR-SCTP
  3685. *
  3686. * When a FORWARD TSN chunk arrives, the data receiver MUST first update
  3687. * its cumulative TSN point to the value carried in the FORWARD TSN
  3688. * chunk, and then MUST further advance its cumulative TSN point locally
  3689. * if possible.
  3690. * After the above processing, the data receiver MUST stop reporting any
  3691. * missing TSNs earlier than or equal to the new cumulative TSN point.
  3692. *
  3693. * Verification Tag: 8.5 Verification Tag [Normal verification]
  3694. *
  3695. * The return value is the disposition of the chunk.
  3696. */
  3697. enum sctp_disposition sctp_sf_eat_fwd_tsn(struct net *net,
  3698. const struct sctp_endpoint *ep,
  3699. const struct sctp_association *asoc,
  3700. const union sctp_subtype type,
  3701. void *arg,
  3702. struct sctp_cmd_seq *commands)
  3703. {
  3704. struct sctp_fwdtsn_hdr *fwdtsn_hdr;
  3705. struct sctp_chunk *chunk = arg;
  3706. __u16 len;
  3707. __u32 tsn;
  3708. if (!sctp_vtag_verify(chunk, asoc)) {
  3709. sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
  3710. SCTP_NULL());
  3711. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  3712. }
  3713. if (!asoc->peer.prsctp_capable)
  3714. return sctp_sf_unk_chunk(net, ep, asoc, type, arg, commands);
  3715. /* Make sure that the FORWARD_TSN chunk has valid length. */
  3716. if (!sctp_chunk_length_valid(chunk, sctp_ftsnchk_len(&asoc->stream)))
  3717. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  3718. commands);
  3719. fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
  3720. chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
  3721. len = ntohs(chunk->chunk_hdr->length);
  3722. len -= sizeof(struct sctp_chunkhdr);
  3723. skb_pull(chunk->skb, len);
  3724. tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
  3725. pr_debug("%s: TSN 0x%x\n", __func__, tsn);
  3726. /* The TSN is too high--silently discard the chunk and count on it
  3727. * getting retransmitted later.
  3728. */
  3729. if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
  3730. goto discard_noforce;
  3731. if (!asoc->stream.si->validate_ftsn(chunk))
  3732. goto discard_noforce;
  3733. sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
  3734. if (len > sctp_ftsnhdr_len(&asoc->stream))
  3735. sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
  3736. SCTP_CHUNK(chunk));
  3737. /* Count this as receiving DATA. */
  3738. if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE]) {
  3739. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
  3740. SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
  3741. }
  3742. /* FIXME: For now send a SACK, but DATA processing may
  3743. * send another.
  3744. */
  3745. sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_NOFORCE());
  3746. return SCTP_DISPOSITION_CONSUME;
  3747. discard_noforce:
  3748. return SCTP_DISPOSITION_DISCARD;
  3749. }
  3750. enum sctp_disposition sctp_sf_eat_fwd_tsn_fast(
  3751. struct net *net,
  3752. const struct sctp_endpoint *ep,
  3753. const struct sctp_association *asoc,
  3754. const union sctp_subtype type,
  3755. void *arg,
  3756. struct sctp_cmd_seq *commands)
  3757. {
  3758. struct sctp_fwdtsn_hdr *fwdtsn_hdr;
  3759. struct sctp_chunk *chunk = arg;
  3760. __u16 len;
  3761. __u32 tsn;
  3762. if (!sctp_vtag_verify(chunk, asoc)) {
  3763. sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
  3764. SCTP_NULL());
  3765. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  3766. }
  3767. if (!asoc->peer.prsctp_capable)
  3768. return sctp_sf_unk_chunk(net, ep, asoc, type, arg, commands);
  3769. /* Make sure that the FORWARD_TSN chunk has a valid length. */
  3770. if (!sctp_chunk_length_valid(chunk, sctp_ftsnchk_len(&asoc->stream)))
  3771. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  3772. commands);
  3773. fwdtsn_hdr = (struct sctp_fwdtsn_hdr *)chunk->skb->data;
  3774. chunk->subh.fwdtsn_hdr = fwdtsn_hdr;
  3775. len = ntohs(chunk->chunk_hdr->length);
  3776. len -= sizeof(struct sctp_chunkhdr);
  3777. skb_pull(chunk->skb, len);
  3778. tsn = ntohl(fwdtsn_hdr->new_cum_tsn);
  3779. pr_debug("%s: TSN 0x%x\n", __func__, tsn);
  3780. /* The TSN is too high--silently discard the chunk and count on it
  3781. * getting retransmitted later.
  3782. */
  3783. if (sctp_tsnmap_check(&asoc->peer.tsn_map, tsn) < 0)
  3784. goto gen_shutdown;
  3785. if (!asoc->stream.si->validate_ftsn(chunk))
  3786. goto gen_shutdown;
  3787. sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_FWDTSN, SCTP_U32(tsn));
  3788. if (len > sctp_ftsnhdr_len(&asoc->stream))
  3789. sctp_add_cmd_sf(commands, SCTP_CMD_PROCESS_FWDTSN,
  3790. SCTP_CHUNK(chunk));
  3791. /* Go a head and force a SACK, since we are shutting down. */
  3792. gen_shutdown:
  3793. /* Implementor's Guide.
  3794. *
  3795. * While in SHUTDOWN-SENT state, the SHUTDOWN sender MUST immediately
  3796. * respond to each received packet containing one or more DATA chunk(s)
  3797. * with a SACK, a SHUTDOWN chunk, and restart the T2-shutdown timer
  3798. */
  3799. sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SHUTDOWN, SCTP_NULL());
  3800. sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
  3801. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
  3802. SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
  3803. return SCTP_DISPOSITION_CONSUME;
  3804. }
  3805. /*
  3806. * SCTP-AUTH Section 6.3 Receiving authenticated chunks
  3807. *
  3808. * The receiver MUST use the HMAC algorithm indicated in the HMAC
  3809. * Identifier field. If this algorithm was not specified by the
  3810. * receiver in the HMAC-ALGO parameter in the INIT or INIT-ACK chunk
  3811. * during association setup, the AUTH chunk and all chunks after it MUST
  3812. * be discarded and an ERROR chunk SHOULD be sent with the error cause
  3813. * defined in Section 4.1.
  3814. *
  3815. * If an endpoint with no shared key receives a Shared Key Identifier
  3816. * other than 0, it MUST silently discard all authenticated chunks. If
  3817. * the endpoint has at least one endpoint pair shared key for the peer,
  3818. * it MUST use the key specified by the Shared Key Identifier if a
  3819. * key has been configured for that Shared Key Identifier. If no
  3820. * endpoint pair shared key has been configured for that Shared Key
  3821. * Identifier, all authenticated chunks MUST be silently discarded.
  3822. *
  3823. * Verification Tag: 8.5 Verification Tag [Normal verification]
  3824. *
  3825. * The return value is the disposition of the chunk.
  3826. */
  3827. static enum sctp_ierror sctp_sf_authenticate(
  3828. const struct sctp_association *asoc,
  3829. struct sctp_chunk *chunk)
  3830. {
  3831. struct sctp_shared_key *sh_key = NULL;
  3832. struct sctp_authhdr *auth_hdr;
  3833. __u8 *save_digest, *digest;
  3834. struct sctp_hmac *hmac;
  3835. unsigned int sig_len;
  3836. __u16 key_id;
  3837. /* Pull in the auth header, so we can do some more verification */
  3838. auth_hdr = (struct sctp_authhdr *)chunk->skb->data;
  3839. chunk->subh.auth_hdr = auth_hdr;
  3840. skb_pull(chunk->skb, sizeof(*auth_hdr));
  3841. /* Make sure that we support the HMAC algorithm from the auth
  3842. * chunk.
  3843. */
  3844. if (!sctp_auth_asoc_verify_hmac_id(asoc, auth_hdr->hmac_id))
  3845. return SCTP_IERROR_AUTH_BAD_HMAC;
  3846. /* Make sure that the provided shared key identifier has been
  3847. * configured
  3848. */
  3849. key_id = ntohs(auth_hdr->shkey_id);
  3850. if (key_id != asoc->active_key_id) {
  3851. sh_key = sctp_auth_get_shkey(asoc, key_id);
  3852. if (!sh_key)
  3853. return SCTP_IERROR_AUTH_BAD_KEYID;
  3854. }
  3855. /* Make sure that the length of the signature matches what
  3856. * we expect.
  3857. */
  3858. sig_len = ntohs(chunk->chunk_hdr->length) -
  3859. sizeof(struct sctp_auth_chunk);
  3860. hmac = sctp_auth_get_hmac(ntohs(auth_hdr->hmac_id));
  3861. if (sig_len != hmac->hmac_len)
  3862. return SCTP_IERROR_PROTO_VIOLATION;
  3863. /* Now that we've done validation checks, we can compute and
  3864. * verify the hmac. The steps involved are:
  3865. * 1. Save the digest from the chunk.
  3866. * 2. Zero out the digest in the chunk.
  3867. * 3. Compute the new digest
  3868. * 4. Compare saved and new digests.
  3869. */
  3870. digest = (u8 *)(auth_hdr + 1);
  3871. skb_pull(chunk->skb, sig_len);
  3872. save_digest = kmemdup(digest, sig_len, GFP_ATOMIC);
  3873. if (!save_digest)
  3874. goto nomem;
  3875. memset(digest, 0, sig_len);
  3876. sctp_auth_calculate_hmac(asoc, chunk->skb,
  3877. (struct sctp_auth_chunk *)chunk->chunk_hdr,
  3878. sh_key, GFP_ATOMIC);
  3879. /* Discard the packet if the digests do not match */
  3880. if (memcmp(save_digest, digest, sig_len)) {
  3881. kfree(save_digest);
  3882. return SCTP_IERROR_BAD_SIG;
  3883. }
  3884. kfree(save_digest);
  3885. chunk->auth = 1;
  3886. return SCTP_IERROR_NO_ERROR;
  3887. nomem:
  3888. return SCTP_IERROR_NOMEM;
  3889. }
  3890. enum sctp_disposition sctp_sf_eat_auth(struct net *net,
  3891. const struct sctp_endpoint *ep,
  3892. const struct sctp_association *asoc,
  3893. const union sctp_subtype type,
  3894. void *arg, struct sctp_cmd_seq *commands)
  3895. {
  3896. struct sctp_chunk *chunk = arg;
  3897. struct sctp_authhdr *auth_hdr;
  3898. struct sctp_chunk *err_chunk;
  3899. enum sctp_ierror error;
  3900. /* Make sure that the peer has AUTH capable */
  3901. if (!asoc->peer.auth_capable)
  3902. return sctp_sf_unk_chunk(net, ep, asoc, type, arg, commands);
  3903. if (!sctp_vtag_verify(chunk, asoc)) {
  3904. sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_BAD_TAG,
  3905. SCTP_NULL());
  3906. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  3907. }
  3908. /* Make sure that the AUTH chunk has valid length. */
  3909. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_auth_chunk)))
  3910. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  3911. commands);
  3912. auth_hdr = (struct sctp_authhdr *)chunk->skb->data;
  3913. error = sctp_sf_authenticate(asoc, chunk);
  3914. switch (error) {
  3915. case SCTP_IERROR_AUTH_BAD_HMAC:
  3916. /* Generate the ERROR chunk and discard the rest
  3917. * of the packet
  3918. */
  3919. err_chunk = sctp_make_op_error(asoc, chunk,
  3920. SCTP_ERROR_UNSUP_HMAC,
  3921. &auth_hdr->hmac_id,
  3922. sizeof(__u16), 0);
  3923. if (err_chunk) {
  3924. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
  3925. SCTP_CHUNK(err_chunk));
  3926. }
  3927. fallthrough;
  3928. case SCTP_IERROR_AUTH_BAD_KEYID:
  3929. case SCTP_IERROR_BAD_SIG:
  3930. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  3931. case SCTP_IERROR_PROTO_VIOLATION:
  3932. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  3933. commands);
  3934. case SCTP_IERROR_NOMEM:
  3935. return SCTP_DISPOSITION_NOMEM;
  3936. default: /* Prevent gcc warnings */
  3937. break;
  3938. }
  3939. if (asoc->active_key_id != ntohs(auth_hdr->shkey_id)) {
  3940. struct sctp_ulpevent *ev;
  3941. ev = sctp_ulpevent_make_authkey(asoc, ntohs(auth_hdr->shkey_id),
  3942. SCTP_AUTH_NEW_KEY, GFP_ATOMIC);
  3943. if (!ev)
  3944. return SCTP_DISPOSITION_NOMEM;
  3945. sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP,
  3946. SCTP_ULPEVENT(ev));
  3947. }
  3948. return SCTP_DISPOSITION_CONSUME;
  3949. }
  3950. /*
  3951. * Process an unknown chunk.
  3952. *
  3953. * Section: 3.2. Also, 2.1 in the implementor's guide.
  3954. *
  3955. * Chunk Types are encoded such that the highest-order two bits specify
  3956. * the action that must be taken if the processing endpoint does not
  3957. * recognize the Chunk Type.
  3958. *
  3959. * 00 - Stop processing this SCTP packet and discard it, do not process
  3960. * any further chunks within it.
  3961. *
  3962. * 01 - Stop processing this SCTP packet and discard it, do not process
  3963. * any further chunks within it, and report the unrecognized
  3964. * chunk in an 'Unrecognized Chunk Type'.
  3965. *
  3966. * 10 - Skip this chunk and continue processing.
  3967. *
  3968. * 11 - Skip this chunk and continue processing, but report in an ERROR
  3969. * Chunk using the 'Unrecognized Chunk Type' cause of error.
  3970. *
  3971. * The return value is the disposition of the chunk.
  3972. */
  3973. enum sctp_disposition sctp_sf_unk_chunk(struct net *net,
  3974. const struct sctp_endpoint *ep,
  3975. const struct sctp_association *asoc,
  3976. const union sctp_subtype type,
  3977. void *arg,
  3978. struct sctp_cmd_seq *commands)
  3979. {
  3980. struct sctp_chunk *unk_chunk = arg;
  3981. struct sctp_chunk *err_chunk;
  3982. struct sctp_chunkhdr *hdr;
  3983. pr_debug("%s: processing unknown chunk id:%d\n", __func__, type.chunk);
  3984. if (!sctp_vtag_verify(unk_chunk, asoc))
  3985. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  3986. /* Make sure that the chunk has a valid length.
  3987. * Since we don't know the chunk type, we use a general
  3988. * chunkhdr structure to make a comparison.
  3989. */
  3990. if (!sctp_chunk_length_valid(unk_chunk, sizeof(*hdr)))
  3991. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  3992. commands);
  3993. switch (type.chunk & SCTP_CID_ACTION_MASK) {
  3994. case SCTP_CID_ACTION_DISCARD:
  3995. /* Discard the packet. */
  3996. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  3997. case SCTP_CID_ACTION_DISCARD_ERR:
  3998. /* Generate an ERROR chunk as response. */
  3999. hdr = unk_chunk->chunk_hdr;
  4000. err_chunk = sctp_make_op_error(asoc, unk_chunk,
  4001. SCTP_ERROR_UNKNOWN_CHUNK, hdr,
  4002. SCTP_PAD4(ntohs(hdr->length)),
  4003. 0);
  4004. if (err_chunk) {
  4005. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
  4006. SCTP_CHUNK(err_chunk));
  4007. }
  4008. /* Discard the packet. */
  4009. sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  4010. return SCTP_DISPOSITION_CONSUME;
  4011. case SCTP_CID_ACTION_SKIP:
  4012. /* Skip the chunk. */
  4013. return SCTP_DISPOSITION_DISCARD;
  4014. case SCTP_CID_ACTION_SKIP_ERR:
  4015. /* Generate an ERROR chunk as response. */
  4016. hdr = unk_chunk->chunk_hdr;
  4017. err_chunk = sctp_make_op_error(asoc, unk_chunk,
  4018. SCTP_ERROR_UNKNOWN_CHUNK, hdr,
  4019. SCTP_PAD4(ntohs(hdr->length)),
  4020. 0);
  4021. if (err_chunk) {
  4022. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
  4023. SCTP_CHUNK(err_chunk));
  4024. }
  4025. /* Skip the chunk. */
  4026. return SCTP_DISPOSITION_CONSUME;
  4027. default:
  4028. break;
  4029. }
  4030. return SCTP_DISPOSITION_DISCARD;
  4031. }
  4032. /*
  4033. * Discard the chunk.
  4034. *
  4035. * Section: 0.2, 5.2.3, 5.2.5, 5.2.6, 6.0, 8.4.6, 8.5.1c, 9.2
  4036. * [Too numerous to mention...]
  4037. * Verification Tag: No verification needed.
  4038. * Inputs
  4039. * (endpoint, asoc, chunk)
  4040. *
  4041. * Outputs
  4042. * (asoc, reply_msg, msg_up, timers, counters)
  4043. *
  4044. * The return value is the disposition of the chunk.
  4045. */
  4046. enum sctp_disposition sctp_sf_discard_chunk(struct net *net,
  4047. const struct sctp_endpoint *ep,
  4048. const struct sctp_association *asoc,
  4049. const union sctp_subtype type,
  4050. void *arg,
  4051. struct sctp_cmd_seq *commands)
  4052. {
  4053. struct sctp_chunk *chunk = arg;
  4054. if (asoc && !sctp_vtag_verify(chunk, asoc))
  4055. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  4056. /* Make sure that the chunk has a valid length.
  4057. * Since we don't know the chunk type, we use a general
  4058. * chunkhdr structure to make a comparison.
  4059. */
  4060. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
  4061. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  4062. commands);
  4063. pr_debug("%s: chunk:%d is discarded\n", __func__, type.chunk);
  4064. return SCTP_DISPOSITION_DISCARD;
  4065. }
  4066. /*
  4067. * Discard the whole packet.
  4068. *
  4069. * Section: 8.4 2)
  4070. *
  4071. * 2) If the OOTB packet contains an ABORT chunk, the receiver MUST
  4072. * silently discard the OOTB packet and take no further action.
  4073. *
  4074. * Verification Tag: No verification necessary
  4075. *
  4076. * Inputs
  4077. * (endpoint, asoc, chunk)
  4078. *
  4079. * Outputs
  4080. * (asoc, reply_msg, msg_up, timers, counters)
  4081. *
  4082. * The return value is the disposition of the chunk.
  4083. */
  4084. enum sctp_disposition sctp_sf_pdiscard(struct net *net,
  4085. const struct sctp_endpoint *ep,
  4086. const struct sctp_association *asoc,
  4087. const union sctp_subtype type,
  4088. void *arg, struct sctp_cmd_seq *commands)
  4089. {
  4090. SCTP_INC_STATS(net, SCTP_MIB_IN_PKT_DISCARDS);
  4091. sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
  4092. return SCTP_DISPOSITION_CONSUME;
  4093. }
  4094. /*
  4095. * The other end is violating protocol.
  4096. *
  4097. * Section: Not specified
  4098. * Verification Tag: Not specified
  4099. * Inputs
  4100. * (endpoint, asoc, chunk)
  4101. *
  4102. * Outputs
  4103. * (asoc, reply_msg, msg_up, timers, counters)
  4104. *
  4105. * We simply tag the chunk as a violation. The state machine will log
  4106. * the violation and continue.
  4107. */
  4108. enum sctp_disposition sctp_sf_violation(struct net *net,
  4109. const struct sctp_endpoint *ep,
  4110. const struct sctp_association *asoc,
  4111. const union sctp_subtype type,
  4112. void *arg,
  4113. struct sctp_cmd_seq *commands)
  4114. {
  4115. struct sctp_chunk *chunk = arg;
  4116. if (!sctp_vtag_verify(chunk, asoc))
  4117. return sctp_sf_pdiscard(net, ep, asoc, type, arg, commands);
  4118. /* Make sure that the chunk has a valid length. */
  4119. if (!sctp_chunk_length_valid(chunk, sizeof(struct sctp_chunkhdr)))
  4120. return sctp_sf_violation_chunklen(net, ep, asoc, type, arg,
  4121. commands);
  4122. return SCTP_DISPOSITION_VIOLATION;
  4123. }
  4124. /*
  4125. * Common function to handle a protocol violation.
  4126. */
  4127. static enum sctp_disposition sctp_sf_abort_violation(
  4128. struct net *net,
  4129. const struct sctp_endpoint *ep,
  4130. const struct sctp_association *asoc,
  4131. void *arg,
  4132. struct sctp_cmd_seq *commands,
  4133. const __u8 *payload,
  4134. const size_t paylen)
  4135. {
  4136. struct sctp_packet *packet = NULL;
  4137. struct sctp_chunk *chunk = arg;
  4138. struct sctp_chunk *abort = NULL;
  4139. /* SCTP-AUTH, Section 6.3:
  4140. * It should be noted that if the receiver wants to tear
  4141. * down an association in an authenticated way only, the
  4142. * handling of malformed packets should not result in
  4143. * tearing down the association.
  4144. *
  4145. * This means that if we only want to abort associations
  4146. * in an authenticated way (i.e AUTH+ABORT), then we
  4147. * can't destroy this association just because the packet
  4148. * was malformed.
  4149. */
  4150. if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
  4151. goto discard;
  4152. /* Make the abort chunk. */
  4153. abort = sctp_make_abort_violation(asoc, chunk, payload, paylen);
  4154. if (!abort)
  4155. goto nomem;
  4156. if (asoc) {
  4157. /* Treat INIT-ACK as a special case during COOKIE-WAIT. */
  4158. if (chunk->chunk_hdr->type == SCTP_CID_INIT_ACK &&
  4159. !asoc->peer.i.init_tag) {
  4160. struct sctp_initack_chunk *initack;
  4161. initack = (struct sctp_initack_chunk *)chunk->chunk_hdr;
  4162. if (!sctp_chunk_length_valid(chunk, sizeof(*initack)))
  4163. abort->chunk_hdr->flags |= SCTP_CHUNK_FLAG_T;
  4164. else {
  4165. unsigned int inittag;
  4166. inittag = ntohl(initack->init_hdr.init_tag);
  4167. sctp_add_cmd_sf(commands, SCTP_CMD_UPDATE_INITTAG,
  4168. SCTP_U32(inittag));
  4169. }
  4170. }
  4171. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
  4172. SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
  4173. if (asoc->state <= SCTP_STATE_COOKIE_ECHOED) {
  4174. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  4175. SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
  4176. sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
  4177. SCTP_ERROR(ECONNREFUSED));
  4178. sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
  4179. SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
  4180. } else {
  4181. sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
  4182. SCTP_ERROR(ECONNABORTED));
  4183. sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
  4184. SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
  4185. SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
  4186. }
  4187. } else {
  4188. packet = sctp_ootb_pkt_new(net, asoc, chunk);
  4189. if (!packet)
  4190. goto nomem_pkt;
  4191. if (sctp_test_T_bit(abort))
  4192. packet->vtag = ntohl(chunk->sctp_hdr->vtag);
  4193. abort->skb->sk = ep->base.sk;
  4194. sctp_packet_append_chunk(packet, abort);
  4195. sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
  4196. SCTP_PACKET(packet));
  4197. SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
  4198. }
  4199. SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
  4200. discard:
  4201. sctp_sf_pdiscard(net, ep, asoc, SCTP_ST_CHUNK(0), arg, commands);
  4202. return SCTP_DISPOSITION_ABORT;
  4203. nomem_pkt:
  4204. sctp_chunk_free(abort);
  4205. nomem:
  4206. return SCTP_DISPOSITION_NOMEM;
  4207. }
  4208. /*
  4209. * Handle a protocol violation when the chunk length is invalid.
  4210. * "Invalid" length is identified as smaller than the minimal length a
  4211. * given chunk can be. For example, a SACK chunk has invalid length
  4212. * if its length is set to be smaller than the size of struct sctp_sack_chunk.
  4213. *
  4214. * We inform the other end by sending an ABORT with a Protocol Violation
  4215. * error code.
  4216. *
  4217. * Section: Not specified
  4218. * Verification Tag: Nothing to do
  4219. * Inputs
  4220. * (endpoint, asoc, chunk)
  4221. *
  4222. * Outputs
  4223. * (reply_msg, msg_up, counters)
  4224. *
  4225. * Generate an ABORT chunk and terminate the association.
  4226. */
  4227. static enum sctp_disposition sctp_sf_violation_chunklen(
  4228. struct net *net,
  4229. const struct sctp_endpoint *ep,
  4230. const struct sctp_association *asoc,
  4231. const union sctp_subtype type,
  4232. void *arg,
  4233. struct sctp_cmd_seq *commands)
  4234. {
  4235. static const char err_str[] = "The following chunk had invalid length:";
  4236. return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str,
  4237. sizeof(err_str));
  4238. }
  4239. /*
  4240. * Handle a protocol violation when the parameter length is invalid.
  4241. * If the length is smaller than the minimum length of a given parameter,
  4242. * or accumulated length in multi parameters exceeds the end of the chunk,
  4243. * the length is considered as invalid.
  4244. */
  4245. static enum sctp_disposition sctp_sf_violation_paramlen(
  4246. struct net *net,
  4247. const struct sctp_endpoint *ep,
  4248. const struct sctp_association *asoc,
  4249. const union sctp_subtype type,
  4250. void *arg, void *ext,
  4251. struct sctp_cmd_seq *commands)
  4252. {
  4253. struct sctp_paramhdr *param = ext;
  4254. struct sctp_chunk *abort = NULL;
  4255. struct sctp_chunk *chunk = arg;
  4256. if (sctp_auth_recv_cid(SCTP_CID_ABORT, asoc))
  4257. goto discard;
  4258. /* Make the abort chunk. */
  4259. abort = sctp_make_violation_paramlen(asoc, chunk, param);
  4260. if (!abort)
  4261. goto nomem;
  4262. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
  4263. SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
  4264. sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
  4265. SCTP_ERROR(ECONNABORTED));
  4266. sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
  4267. SCTP_PERR(SCTP_ERROR_PROTO_VIOLATION));
  4268. SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
  4269. SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
  4270. discard:
  4271. sctp_sf_pdiscard(net, ep, asoc, SCTP_ST_CHUNK(0), arg, commands);
  4272. return SCTP_DISPOSITION_ABORT;
  4273. nomem:
  4274. return SCTP_DISPOSITION_NOMEM;
  4275. }
  4276. /* Handle a protocol violation when the peer trying to advance the
  4277. * cumulative tsn ack to a point beyond the max tsn currently sent.
  4278. *
  4279. * We inform the other end by sending an ABORT with a Protocol Violation
  4280. * error code.
  4281. */
  4282. static enum sctp_disposition sctp_sf_violation_ctsn(
  4283. struct net *net,
  4284. const struct sctp_endpoint *ep,
  4285. const struct sctp_association *asoc,
  4286. const union sctp_subtype type,
  4287. void *arg,
  4288. struct sctp_cmd_seq *commands)
  4289. {
  4290. static const char err_str[] = "The cumulative tsn ack beyond the max tsn currently sent:";
  4291. return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str,
  4292. sizeof(err_str));
  4293. }
  4294. /* Handle protocol violation of an invalid chunk bundling. For example,
  4295. * when we have an association and we receive bundled INIT-ACK, or
  4296. * SHUTDOWN-COMPLETE, our peer is clearly violating the "MUST NOT bundle"
  4297. * statement from the specs. Additionally, there might be an attacker
  4298. * on the path and we may not want to continue this communication.
  4299. */
  4300. static enum sctp_disposition sctp_sf_violation_chunk(
  4301. struct net *net,
  4302. const struct sctp_endpoint *ep,
  4303. const struct sctp_association *asoc,
  4304. const union sctp_subtype type,
  4305. void *arg,
  4306. struct sctp_cmd_seq *commands)
  4307. {
  4308. static const char err_str[] = "The following chunk violates protocol:";
  4309. return sctp_sf_abort_violation(net, ep, asoc, arg, commands, err_str,
  4310. sizeof(err_str));
  4311. }
  4312. /***************************************************************************
  4313. * These are the state functions for handling primitive (Section 10) events.
  4314. ***************************************************************************/
  4315. /*
  4316. * sctp_sf_do_prm_asoc
  4317. *
  4318. * Section: 10.1 ULP-to-SCTP
  4319. * B) Associate
  4320. *
  4321. * Format: ASSOCIATE(local SCTP instance name, destination transport addr,
  4322. * outbound stream count)
  4323. * -> association id [,destination transport addr list] [,outbound stream
  4324. * count]
  4325. *
  4326. * This primitive allows the upper layer to initiate an association to a
  4327. * specific peer endpoint.
  4328. *
  4329. * The peer endpoint shall be specified by one of the transport addresses
  4330. * which defines the endpoint (see Section 1.4). If the local SCTP
  4331. * instance has not been initialized, the ASSOCIATE is considered an
  4332. * error.
  4333. * [This is not relevant for the kernel implementation since we do all
  4334. * initialization at boot time. It we hadn't initialized we wouldn't
  4335. * get anywhere near this code.]
  4336. *
  4337. * An association id, which is a local handle to the SCTP association,
  4338. * will be returned on successful establishment of the association. If
  4339. * SCTP is not able to open an SCTP association with the peer endpoint,
  4340. * an error is returned.
  4341. * [In the kernel implementation, the struct sctp_association needs to
  4342. * be created BEFORE causing this primitive to run.]
  4343. *
  4344. * Other association parameters may be returned, including the
  4345. * complete destination transport addresses of the peer as well as the
  4346. * outbound stream count of the local endpoint. One of the transport
  4347. * address from the returned destination addresses will be selected by
  4348. * the local endpoint as default primary path for sending SCTP packets
  4349. * to this peer. The returned "destination transport addr list" can
  4350. * be used by the ULP to change the default primary path or to force
  4351. * sending a packet to a specific transport address. [All of this
  4352. * stuff happens when the INIT ACK arrives. This is a NON-BLOCKING
  4353. * function.]
  4354. *
  4355. * Mandatory attributes:
  4356. *
  4357. * o local SCTP instance name - obtained from the INITIALIZE operation.
  4358. * [This is the argument asoc.]
  4359. * o destination transport addr - specified as one of the transport
  4360. * addresses of the peer endpoint with which the association is to be
  4361. * established.
  4362. * [This is asoc->peer.active_path.]
  4363. * o outbound stream count - the number of outbound streams the ULP
  4364. * would like to open towards this peer endpoint.
  4365. * [BUG: This is not currently implemented.]
  4366. * Optional attributes:
  4367. *
  4368. * None.
  4369. *
  4370. * The return value is a disposition.
  4371. */
  4372. enum sctp_disposition sctp_sf_do_prm_asoc(struct net *net,
  4373. const struct sctp_endpoint *ep,
  4374. const struct sctp_association *asoc,
  4375. const union sctp_subtype type,
  4376. void *arg,
  4377. struct sctp_cmd_seq *commands)
  4378. {
  4379. struct sctp_association *my_asoc;
  4380. struct sctp_chunk *repl;
  4381. /* The comment below says that we enter COOKIE-WAIT AFTER
  4382. * sending the INIT, but that doesn't actually work in our
  4383. * implementation...
  4384. */
  4385. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
  4386. SCTP_STATE(SCTP_STATE_COOKIE_WAIT));
  4387. /* RFC 2960 5.1 Normal Establishment of an Association
  4388. *
  4389. * A) "A" first sends an INIT chunk to "Z". In the INIT, "A"
  4390. * must provide its Verification Tag (Tag_A) in the Initiate
  4391. * Tag field. Tag_A SHOULD be a random number in the range of
  4392. * 1 to 4294967295 (see 5.3.1 for Tag value selection). ...
  4393. */
  4394. repl = sctp_make_init(asoc, &asoc->base.bind_addr, GFP_ATOMIC, 0);
  4395. if (!repl)
  4396. goto nomem;
  4397. /* Choose transport for INIT. */
  4398. sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
  4399. SCTP_CHUNK(repl));
  4400. /* Cast away the const modifier, as we want to just
  4401. * rerun it through as a sideffect.
  4402. */
  4403. my_asoc = (struct sctp_association *)asoc;
  4404. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_ASOC, SCTP_ASOC(my_asoc));
  4405. /* After sending the INIT, "A" starts the T1-init timer and
  4406. * enters the COOKIE-WAIT state.
  4407. */
  4408. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
  4409. SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
  4410. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
  4411. return SCTP_DISPOSITION_CONSUME;
  4412. nomem:
  4413. return SCTP_DISPOSITION_NOMEM;
  4414. }
  4415. /*
  4416. * Process the SEND primitive.
  4417. *
  4418. * Section: 10.1 ULP-to-SCTP
  4419. * E) Send
  4420. *
  4421. * Format: SEND(association id, buffer address, byte count [,context]
  4422. * [,stream id] [,life time] [,destination transport address]
  4423. * [,unorder flag] [,no-bundle flag] [,payload protocol-id] )
  4424. * -> result
  4425. *
  4426. * This is the main method to send user data via SCTP.
  4427. *
  4428. * Mandatory attributes:
  4429. *
  4430. * o association id - local handle to the SCTP association
  4431. *
  4432. * o buffer address - the location where the user message to be
  4433. * transmitted is stored;
  4434. *
  4435. * o byte count - The size of the user data in number of bytes;
  4436. *
  4437. * Optional attributes:
  4438. *
  4439. * o context - an optional 32 bit integer that will be carried in the
  4440. * sending failure notification to the ULP if the transportation of
  4441. * this User Message fails.
  4442. *
  4443. * o stream id - to indicate which stream to send the data on. If not
  4444. * specified, stream 0 will be used.
  4445. *
  4446. * o life time - specifies the life time of the user data. The user data
  4447. * will not be sent by SCTP after the life time expires. This
  4448. * parameter can be used to avoid efforts to transmit stale
  4449. * user messages. SCTP notifies the ULP if the data cannot be
  4450. * initiated to transport (i.e. sent to the destination via SCTP's
  4451. * send primitive) within the life time variable. However, the
  4452. * user data will be transmitted if SCTP has attempted to transmit a
  4453. * chunk before the life time expired.
  4454. *
  4455. * o destination transport address - specified as one of the destination
  4456. * transport addresses of the peer endpoint to which this packet
  4457. * should be sent. Whenever possible, SCTP should use this destination
  4458. * transport address for sending the packets, instead of the current
  4459. * primary path.
  4460. *
  4461. * o unorder flag - this flag, if present, indicates that the user
  4462. * would like the data delivered in an unordered fashion to the peer
  4463. * (i.e., the U flag is set to 1 on all DATA chunks carrying this
  4464. * message).
  4465. *
  4466. * o no-bundle flag - instructs SCTP not to bundle this user data with
  4467. * other outbound DATA chunks. SCTP MAY still bundle even when
  4468. * this flag is present, when faced with network congestion.
  4469. *
  4470. * o payload protocol-id - A 32 bit unsigned integer that is to be
  4471. * passed to the peer indicating the type of payload protocol data
  4472. * being transmitted. This value is passed as opaque data by SCTP.
  4473. *
  4474. * The return value is the disposition.
  4475. */
  4476. enum sctp_disposition sctp_sf_do_prm_send(struct net *net,
  4477. const struct sctp_endpoint *ep,
  4478. const struct sctp_association *asoc,
  4479. const union sctp_subtype type,
  4480. void *arg,
  4481. struct sctp_cmd_seq *commands)
  4482. {
  4483. struct sctp_datamsg *msg = arg;
  4484. sctp_add_cmd_sf(commands, SCTP_CMD_SEND_MSG, SCTP_DATAMSG(msg));
  4485. return SCTP_DISPOSITION_CONSUME;
  4486. }
  4487. /*
  4488. * Process the SHUTDOWN primitive.
  4489. *
  4490. * Section: 10.1:
  4491. * C) Shutdown
  4492. *
  4493. * Format: SHUTDOWN(association id)
  4494. * -> result
  4495. *
  4496. * Gracefully closes an association. Any locally queued user data
  4497. * will be delivered to the peer. The association will be terminated only
  4498. * after the peer acknowledges all the SCTP packets sent. A success code
  4499. * will be returned on successful termination of the association. If
  4500. * attempting to terminate the association results in a failure, an error
  4501. * code shall be returned.
  4502. *
  4503. * Mandatory attributes:
  4504. *
  4505. * o association id - local handle to the SCTP association
  4506. *
  4507. * Optional attributes:
  4508. *
  4509. * None.
  4510. *
  4511. * The return value is the disposition.
  4512. */
  4513. enum sctp_disposition sctp_sf_do_9_2_prm_shutdown(
  4514. struct net *net,
  4515. const struct sctp_endpoint *ep,
  4516. const struct sctp_association *asoc,
  4517. const union sctp_subtype type,
  4518. void *arg,
  4519. struct sctp_cmd_seq *commands)
  4520. {
  4521. enum sctp_disposition disposition;
  4522. /* From 9.2 Shutdown of an Association
  4523. * Upon receipt of the SHUTDOWN primitive from its upper
  4524. * layer, the endpoint enters SHUTDOWN-PENDING state and
  4525. * remains there until all outstanding data has been
  4526. * acknowledged by its peer. The endpoint accepts no new data
  4527. * from its upper layer, but retransmits data to the far end
  4528. * if necessary to fill gaps.
  4529. */
  4530. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
  4531. SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
  4532. disposition = SCTP_DISPOSITION_CONSUME;
  4533. if (sctp_outq_is_empty(&asoc->outqueue)) {
  4534. disposition = sctp_sf_do_9_2_start_shutdown(net, ep, asoc, type,
  4535. arg, commands);
  4536. }
  4537. return disposition;
  4538. }
  4539. /*
  4540. * Process the ABORT primitive.
  4541. *
  4542. * Section: 10.1:
  4543. * C) Abort
  4544. *
  4545. * Format: Abort(association id [, cause code])
  4546. * -> result
  4547. *
  4548. * Ungracefully closes an association. Any locally queued user data
  4549. * will be discarded and an ABORT chunk is sent to the peer. A success code
  4550. * will be returned on successful abortion of the association. If
  4551. * attempting to abort the association results in a failure, an error
  4552. * code shall be returned.
  4553. *
  4554. * Mandatory attributes:
  4555. *
  4556. * o association id - local handle to the SCTP association
  4557. *
  4558. * Optional attributes:
  4559. *
  4560. * o cause code - reason of the abort to be passed to the peer
  4561. *
  4562. * None.
  4563. *
  4564. * The return value is the disposition.
  4565. */
  4566. enum sctp_disposition sctp_sf_do_9_1_prm_abort(
  4567. struct net *net,
  4568. const struct sctp_endpoint *ep,
  4569. const struct sctp_association *asoc,
  4570. const union sctp_subtype type,
  4571. void *arg,
  4572. struct sctp_cmd_seq *commands)
  4573. {
  4574. /* From 9.1 Abort of an Association
  4575. * Upon receipt of the ABORT primitive from its upper
  4576. * layer, the endpoint enters CLOSED state and
  4577. * discard all outstanding data has been
  4578. * acknowledged by its peer. The endpoint accepts no new data
  4579. * from its upper layer, but retransmits data to the far end
  4580. * if necessary to fill gaps.
  4581. */
  4582. struct sctp_chunk *abort = arg;
  4583. if (abort)
  4584. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
  4585. /* Even if we can't send the ABORT due to low memory delete the
  4586. * TCB. This is a departure from our typical NOMEM handling.
  4587. */
  4588. sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
  4589. SCTP_ERROR(ECONNABORTED));
  4590. /* Delete the established association. */
  4591. sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
  4592. SCTP_PERR(SCTP_ERROR_USER_ABORT));
  4593. SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
  4594. SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
  4595. return SCTP_DISPOSITION_ABORT;
  4596. }
  4597. /* We tried an illegal operation on an association which is closed. */
  4598. enum sctp_disposition sctp_sf_error_closed(struct net *net,
  4599. const struct sctp_endpoint *ep,
  4600. const struct sctp_association *asoc,
  4601. const union sctp_subtype type,
  4602. void *arg,
  4603. struct sctp_cmd_seq *commands)
  4604. {
  4605. sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR, SCTP_ERROR(-EINVAL));
  4606. return SCTP_DISPOSITION_CONSUME;
  4607. }
  4608. /* We tried an illegal operation on an association which is shutting
  4609. * down.
  4610. */
  4611. enum sctp_disposition sctp_sf_error_shutdown(
  4612. struct net *net,
  4613. const struct sctp_endpoint *ep,
  4614. const struct sctp_association *asoc,
  4615. const union sctp_subtype type,
  4616. void *arg,
  4617. struct sctp_cmd_seq *commands)
  4618. {
  4619. sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_ERROR,
  4620. SCTP_ERROR(-ESHUTDOWN));
  4621. return SCTP_DISPOSITION_CONSUME;
  4622. }
  4623. /*
  4624. * sctp_cookie_wait_prm_shutdown
  4625. *
  4626. * Section: 4 Note: 2
  4627. * Verification Tag:
  4628. * Inputs
  4629. * (endpoint, asoc)
  4630. *
  4631. * The RFC does not explicitly address this issue, but is the route through the
  4632. * state table when someone issues a shutdown while in COOKIE_WAIT state.
  4633. *
  4634. * Outputs
  4635. * (timers)
  4636. */
  4637. enum sctp_disposition sctp_sf_cookie_wait_prm_shutdown(
  4638. struct net *net,
  4639. const struct sctp_endpoint *ep,
  4640. const struct sctp_association *asoc,
  4641. const union sctp_subtype type,
  4642. void *arg,
  4643. struct sctp_cmd_seq *commands)
  4644. {
  4645. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  4646. SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
  4647. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
  4648. SCTP_STATE(SCTP_STATE_CLOSED));
  4649. SCTP_INC_STATS(net, SCTP_MIB_SHUTDOWNS);
  4650. sctp_add_cmd_sf(commands, SCTP_CMD_DELETE_TCB, SCTP_NULL());
  4651. return SCTP_DISPOSITION_DELETE_TCB;
  4652. }
  4653. /*
  4654. * sctp_cookie_echoed_prm_shutdown
  4655. *
  4656. * Section: 4 Note: 2
  4657. * Verification Tag:
  4658. * Inputs
  4659. * (endpoint, asoc)
  4660. *
  4661. * The RFC does not explicitly address this issue, but is the route through the
  4662. * state table when someone issues a shutdown while in COOKIE_ECHOED state.
  4663. *
  4664. * Outputs
  4665. * (timers)
  4666. */
  4667. enum sctp_disposition sctp_sf_cookie_echoed_prm_shutdown(
  4668. struct net *net,
  4669. const struct sctp_endpoint *ep,
  4670. const struct sctp_association *asoc,
  4671. const union sctp_subtype type,
  4672. void *arg,
  4673. struct sctp_cmd_seq *commands)
  4674. {
  4675. /* There is a single T1 timer, so we should be able to use
  4676. * common function with the COOKIE-WAIT state.
  4677. */
  4678. return sctp_sf_cookie_wait_prm_shutdown(net, ep, asoc, type, arg, commands);
  4679. }
  4680. /*
  4681. * sctp_sf_cookie_wait_prm_abort
  4682. *
  4683. * Section: 4 Note: 2
  4684. * Verification Tag:
  4685. * Inputs
  4686. * (endpoint, asoc)
  4687. *
  4688. * The RFC does not explicitly address this issue, but is the route through the
  4689. * state table when someone issues an abort while in COOKIE_WAIT state.
  4690. *
  4691. * Outputs
  4692. * (timers)
  4693. */
  4694. enum sctp_disposition sctp_sf_cookie_wait_prm_abort(
  4695. struct net *net,
  4696. const struct sctp_endpoint *ep,
  4697. const struct sctp_association *asoc,
  4698. const union sctp_subtype type,
  4699. void *arg,
  4700. struct sctp_cmd_seq *commands)
  4701. {
  4702. struct sctp_chunk *abort = arg;
  4703. /* Stop T1-init timer */
  4704. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  4705. SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
  4706. if (abort)
  4707. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(abort));
  4708. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
  4709. SCTP_STATE(SCTP_STATE_CLOSED));
  4710. SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
  4711. /* Even if we can't send the ABORT due to low memory delete the
  4712. * TCB. This is a departure from our typical NOMEM handling.
  4713. */
  4714. sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
  4715. SCTP_ERROR(ECONNREFUSED));
  4716. /* Delete the established association. */
  4717. sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
  4718. SCTP_PERR(SCTP_ERROR_USER_ABORT));
  4719. return SCTP_DISPOSITION_ABORT;
  4720. }
  4721. /*
  4722. * sctp_sf_cookie_echoed_prm_abort
  4723. *
  4724. * Section: 4 Note: 3
  4725. * Verification Tag:
  4726. * Inputs
  4727. * (endpoint, asoc)
  4728. *
  4729. * The RFC does not explcitly address this issue, but is the route through the
  4730. * state table when someone issues an abort while in COOKIE_ECHOED state.
  4731. *
  4732. * Outputs
  4733. * (timers)
  4734. */
  4735. enum sctp_disposition sctp_sf_cookie_echoed_prm_abort(
  4736. struct net *net,
  4737. const struct sctp_endpoint *ep,
  4738. const struct sctp_association *asoc,
  4739. const union sctp_subtype type,
  4740. void *arg,
  4741. struct sctp_cmd_seq *commands)
  4742. {
  4743. /* There is a single T1 timer, so we should be able to use
  4744. * common function with the COOKIE-WAIT state.
  4745. */
  4746. return sctp_sf_cookie_wait_prm_abort(net, ep, asoc, type, arg, commands);
  4747. }
  4748. /*
  4749. * sctp_sf_shutdown_pending_prm_abort
  4750. *
  4751. * Inputs
  4752. * (endpoint, asoc)
  4753. *
  4754. * The RFC does not explicitly address this issue, but is the route through the
  4755. * state table when someone issues an abort while in SHUTDOWN-PENDING state.
  4756. *
  4757. * Outputs
  4758. * (timers)
  4759. */
  4760. enum sctp_disposition sctp_sf_shutdown_pending_prm_abort(
  4761. struct net *net,
  4762. const struct sctp_endpoint *ep,
  4763. const struct sctp_association *asoc,
  4764. const union sctp_subtype type,
  4765. void *arg,
  4766. struct sctp_cmd_seq *commands)
  4767. {
  4768. /* Stop the T5-shutdown guard timer. */
  4769. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  4770. SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
  4771. return sctp_sf_do_9_1_prm_abort(net, ep, asoc, type, arg, commands);
  4772. }
  4773. /*
  4774. * sctp_sf_shutdown_sent_prm_abort
  4775. *
  4776. * Inputs
  4777. * (endpoint, asoc)
  4778. *
  4779. * The RFC does not explicitly address this issue, but is the route through the
  4780. * state table when someone issues an abort while in SHUTDOWN-SENT state.
  4781. *
  4782. * Outputs
  4783. * (timers)
  4784. */
  4785. enum sctp_disposition sctp_sf_shutdown_sent_prm_abort(
  4786. struct net *net,
  4787. const struct sctp_endpoint *ep,
  4788. const struct sctp_association *asoc,
  4789. const union sctp_subtype type,
  4790. void *arg,
  4791. struct sctp_cmd_seq *commands)
  4792. {
  4793. /* Stop the T2-shutdown timer. */
  4794. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  4795. SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
  4796. /* Stop the T5-shutdown guard timer. */
  4797. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  4798. SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
  4799. return sctp_sf_do_9_1_prm_abort(net, ep, asoc, type, arg, commands);
  4800. }
  4801. /*
  4802. * sctp_sf_cookie_echoed_prm_abort
  4803. *
  4804. * Inputs
  4805. * (endpoint, asoc)
  4806. *
  4807. * The RFC does not explcitly address this issue, but is the route through the
  4808. * state table when someone issues an abort while in COOKIE_ECHOED state.
  4809. *
  4810. * Outputs
  4811. * (timers)
  4812. */
  4813. enum sctp_disposition sctp_sf_shutdown_ack_sent_prm_abort(
  4814. struct net *net,
  4815. const struct sctp_endpoint *ep,
  4816. const struct sctp_association *asoc,
  4817. const union sctp_subtype type,
  4818. void *arg,
  4819. struct sctp_cmd_seq *commands)
  4820. {
  4821. /* The same T2 timer, so we should be able to use
  4822. * common function with the SHUTDOWN-SENT state.
  4823. */
  4824. return sctp_sf_shutdown_sent_prm_abort(net, ep, asoc, type, arg, commands);
  4825. }
  4826. /*
  4827. * Process the REQUESTHEARTBEAT primitive
  4828. *
  4829. * 10.1 ULP-to-SCTP
  4830. * J) Request Heartbeat
  4831. *
  4832. * Format: REQUESTHEARTBEAT(association id, destination transport address)
  4833. *
  4834. * -> result
  4835. *
  4836. * Instructs the local endpoint to perform a HeartBeat on the specified
  4837. * destination transport address of the given association. The returned
  4838. * result should indicate whether the transmission of the HEARTBEAT
  4839. * chunk to the destination address is successful.
  4840. *
  4841. * Mandatory attributes:
  4842. *
  4843. * o association id - local handle to the SCTP association
  4844. *
  4845. * o destination transport address - the transport address of the
  4846. * association on which a heartbeat should be issued.
  4847. */
  4848. enum sctp_disposition sctp_sf_do_prm_requestheartbeat(
  4849. struct net *net,
  4850. const struct sctp_endpoint *ep,
  4851. const struct sctp_association *asoc,
  4852. const union sctp_subtype type,
  4853. void *arg,
  4854. struct sctp_cmd_seq *commands)
  4855. {
  4856. if (SCTP_DISPOSITION_NOMEM == sctp_sf_heartbeat(ep, asoc, type,
  4857. (struct sctp_transport *)arg, commands))
  4858. return SCTP_DISPOSITION_NOMEM;
  4859. /*
  4860. * RFC 2960 (bis), section 8.3
  4861. *
  4862. * D) Request an on-demand HEARTBEAT on a specific destination
  4863. * transport address of a given association.
  4864. *
  4865. * The endpoint should increment the respective error counter of
  4866. * the destination transport address each time a HEARTBEAT is sent
  4867. * to that address and not acknowledged within one RTO.
  4868. *
  4869. */
  4870. sctp_add_cmd_sf(commands, SCTP_CMD_TRANSPORT_HB_SENT,
  4871. SCTP_TRANSPORT(arg));
  4872. return SCTP_DISPOSITION_CONSUME;
  4873. }
  4874. /*
  4875. * ADDIP Section 4.1 ASCONF Chunk Procedures
  4876. * When an endpoint has an ASCONF signaled change to be sent to the
  4877. * remote endpoint it should do A1 to A9
  4878. */
  4879. enum sctp_disposition sctp_sf_do_prm_asconf(struct net *net,
  4880. const struct sctp_endpoint *ep,
  4881. const struct sctp_association *asoc,
  4882. const union sctp_subtype type,
  4883. void *arg,
  4884. struct sctp_cmd_seq *commands)
  4885. {
  4886. struct sctp_chunk *chunk = arg;
  4887. sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
  4888. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
  4889. SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
  4890. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
  4891. return SCTP_DISPOSITION_CONSUME;
  4892. }
  4893. /* RE-CONFIG Section 5.1 RECONF Chunk Procedures */
  4894. enum sctp_disposition sctp_sf_do_prm_reconf(struct net *net,
  4895. const struct sctp_endpoint *ep,
  4896. const struct sctp_association *asoc,
  4897. const union sctp_subtype type,
  4898. void *arg,
  4899. struct sctp_cmd_seq *commands)
  4900. {
  4901. struct sctp_chunk *chunk = arg;
  4902. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(chunk));
  4903. return SCTP_DISPOSITION_CONSUME;
  4904. }
  4905. /*
  4906. * Ignore the primitive event
  4907. *
  4908. * The return value is the disposition of the primitive.
  4909. */
  4910. enum sctp_disposition sctp_sf_ignore_primitive(
  4911. struct net *net,
  4912. const struct sctp_endpoint *ep,
  4913. const struct sctp_association *asoc,
  4914. const union sctp_subtype type,
  4915. void *arg,
  4916. struct sctp_cmd_seq *commands)
  4917. {
  4918. pr_debug("%s: primitive type:%d is ignored\n", __func__,
  4919. type.primitive);
  4920. return SCTP_DISPOSITION_DISCARD;
  4921. }
  4922. /***************************************************************************
  4923. * These are the state functions for the OTHER events.
  4924. ***************************************************************************/
  4925. /*
  4926. * When the SCTP stack has no more user data to send or retransmit, this
  4927. * notification is given to the user. Also, at the time when a user app
  4928. * subscribes to this event, if there is no data to be sent or
  4929. * retransmit, the stack will immediately send up this notification.
  4930. */
  4931. enum sctp_disposition sctp_sf_do_no_pending_tsn(
  4932. struct net *net,
  4933. const struct sctp_endpoint *ep,
  4934. const struct sctp_association *asoc,
  4935. const union sctp_subtype type,
  4936. void *arg,
  4937. struct sctp_cmd_seq *commands)
  4938. {
  4939. struct sctp_ulpevent *event;
  4940. event = sctp_ulpevent_make_sender_dry_event(asoc, GFP_ATOMIC);
  4941. if (!event)
  4942. return SCTP_DISPOSITION_NOMEM;
  4943. sctp_add_cmd_sf(commands, SCTP_CMD_EVENT_ULP, SCTP_ULPEVENT(event));
  4944. return SCTP_DISPOSITION_CONSUME;
  4945. }
  4946. /*
  4947. * Start the shutdown negotiation.
  4948. *
  4949. * From Section 9.2:
  4950. * Once all its outstanding data has been acknowledged, the endpoint
  4951. * shall send a SHUTDOWN chunk to its peer including in the Cumulative
  4952. * TSN Ack field the last sequential TSN it has received from the peer.
  4953. * It shall then start the T2-shutdown timer and enter the SHUTDOWN-SENT
  4954. * state. If the timer expires, the endpoint must re-send the SHUTDOWN
  4955. * with the updated last sequential TSN received from its peer.
  4956. *
  4957. * The return value is the disposition.
  4958. */
  4959. enum sctp_disposition sctp_sf_do_9_2_start_shutdown(
  4960. struct net *net,
  4961. const struct sctp_endpoint *ep,
  4962. const struct sctp_association *asoc,
  4963. const union sctp_subtype type,
  4964. void *arg,
  4965. struct sctp_cmd_seq *commands)
  4966. {
  4967. struct sctp_chunk *reply;
  4968. /* Once all its outstanding data has been acknowledged, the
  4969. * endpoint shall send a SHUTDOWN chunk to its peer including
  4970. * in the Cumulative TSN Ack field the last sequential TSN it
  4971. * has received from the peer.
  4972. */
  4973. reply = sctp_make_shutdown(asoc, arg);
  4974. if (!reply)
  4975. goto nomem;
  4976. /* Set the transport for the SHUTDOWN chunk and the timeout for the
  4977. * T2-shutdown timer.
  4978. */
  4979. sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
  4980. /* It shall then start the T2-shutdown timer */
  4981. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START,
  4982. SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
  4983. /* RFC 4960 Section 9.2
  4984. * The sender of the SHUTDOWN MAY also start an overall guard timer
  4985. * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
  4986. */
  4987. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
  4988. SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
  4989. if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE])
  4990. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  4991. SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
  4992. /* and enter the SHUTDOWN-SENT state. */
  4993. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
  4994. SCTP_STATE(SCTP_STATE_SHUTDOWN_SENT));
  4995. /* sctp-implguide 2.10 Issues with Heartbeating and failover
  4996. *
  4997. * HEARTBEAT ... is discontinued after sending either SHUTDOWN
  4998. * or SHUTDOWN-ACK.
  4999. */
  5000. sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
  5001. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
  5002. return SCTP_DISPOSITION_CONSUME;
  5003. nomem:
  5004. return SCTP_DISPOSITION_NOMEM;
  5005. }
  5006. /*
  5007. * Generate a SHUTDOWN ACK now that everything is SACK'd.
  5008. *
  5009. * From Section 9.2:
  5010. *
  5011. * If it has no more outstanding DATA chunks, the SHUTDOWN receiver
  5012. * shall send a SHUTDOWN ACK and start a T2-shutdown timer of its own,
  5013. * entering the SHUTDOWN-ACK-SENT state. If the timer expires, the
  5014. * endpoint must re-send the SHUTDOWN ACK.
  5015. *
  5016. * The return value is the disposition.
  5017. */
  5018. enum sctp_disposition sctp_sf_do_9_2_shutdown_ack(
  5019. struct net *net,
  5020. const struct sctp_endpoint *ep,
  5021. const struct sctp_association *asoc,
  5022. const union sctp_subtype type,
  5023. void *arg,
  5024. struct sctp_cmd_seq *commands)
  5025. {
  5026. struct sctp_chunk *chunk = arg;
  5027. struct sctp_chunk *reply;
  5028. /* There are 2 ways of getting here:
  5029. * 1) called in response to a SHUTDOWN chunk
  5030. * 2) called when SCTP_EVENT_NO_PENDING_TSN event is issued.
  5031. *
  5032. * For the case (2), the arg parameter is set to NULL. We need
  5033. * to check that we have a chunk before accessing it's fields.
  5034. */
  5035. if (chunk) {
  5036. if (!sctp_vtag_verify(chunk, asoc))
  5037. return sctp_sf_pdiscard(net, ep, asoc, type, arg,
  5038. commands);
  5039. /* Make sure that the SHUTDOWN chunk has a valid length. */
  5040. if (!sctp_chunk_length_valid(
  5041. chunk, sizeof(struct sctp_shutdown_chunk)))
  5042. return sctp_sf_violation_chunklen(net, ep, asoc, type,
  5043. arg, commands);
  5044. }
  5045. /* If it has no more outstanding DATA chunks, the SHUTDOWN receiver
  5046. * shall send a SHUTDOWN ACK ...
  5047. */
  5048. reply = sctp_make_shutdown_ack(asoc, chunk);
  5049. if (!reply)
  5050. goto nomem;
  5051. /* Set the transport for the SHUTDOWN ACK chunk and the timeout for
  5052. * the T2-shutdown timer.
  5053. */
  5054. sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
  5055. /* and start/restart a T2-shutdown timer of its own, */
  5056. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
  5057. SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
  5058. if (asoc->timeouts[SCTP_EVENT_TIMEOUT_AUTOCLOSE])
  5059. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  5060. SCTP_TO(SCTP_EVENT_TIMEOUT_AUTOCLOSE));
  5061. /* Enter the SHUTDOWN-ACK-SENT state. */
  5062. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
  5063. SCTP_STATE(SCTP_STATE_SHUTDOWN_ACK_SENT));
  5064. /* sctp-implguide 2.10 Issues with Heartbeating and failover
  5065. *
  5066. * HEARTBEAT ... is discontinued after sending either SHUTDOWN
  5067. * or SHUTDOWN-ACK.
  5068. */
  5069. sctp_add_cmd_sf(commands, SCTP_CMD_HB_TIMERS_STOP, SCTP_NULL());
  5070. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
  5071. return SCTP_DISPOSITION_CONSUME;
  5072. nomem:
  5073. return SCTP_DISPOSITION_NOMEM;
  5074. }
  5075. /*
  5076. * Ignore the event defined as other
  5077. *
  5078. * The return value is the disposition of the event.
  5079. */
  5080. enum sctp_disposition sctp_sf_ignore_other(struct net *net,
  5081. const struct sctp_endpoint *ep,
  5082. const struct sctp_association *asoc,
  5083. const union sctp_subtype type,
  5084. void *arg,
  5085. struct sctp_cmd_seq *commands)
  5086. {
  5087. pr_debug("%s: the event other type:%d is ignored\n",
  5088. __func__, type.other);
  5089. return SCTP_DISPOSITION_DISCARD;
  5090. }
  5091. /************************************************************
  5092. * These are the state functions for handling timeout events.
  5093. ************************************************************/
  5094. /*
  5095. * RTX Timeout
  5096. *
  5097. * Section: 6.3.3 Handle T3-rtx Expiration
  5098. *
  5099. * Whenever the retransmission timer T3-rtx expires for a destination
  5100. * address, do the following:
  5101. * [See below]
  5102. *
  5103. * The return value is the disposition of the chunk.
  5104. */
  5105. enum sctp_disposition sctp_sf_do_6_3_3_rtx(struct net *net,
  5106. const struct sctp_endpoint *ep,
  5107. const struct sctp_association *asoc,
  5108. const union sctp_subtype type,
  5109. void *arg,
  5110. struct sctp_cmd_seq *commands)
  5111. {
  5112. struct sctp_transport *transport = arg;
  5113. SCTP_INC_STATS(net, SCTP_MIB_T3_RTX_EXPIREDS);
  5114. if (asoc->overall_error_count >= asoc->max_retrans) {
  5115. if (asoc->peer.zero_window_announced &&
  5116. asoc->state == SCTP_STATE_SHUTDOWN_PENDING) {
  5117. /*
  5118. * We are here likely because the receiver had its rwnd
  5119. * closed for a while and we have not been able to
  5120. * transmit the locally queued data within the maximum
  5121. * retransmission attempts limit. Start the T5
  5122. * shutdown guard timer to give the receiver one last
  5123. * chance and some additional time to recover before
  5124. * aborting.
  5125. */
  5126. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_START_ONCE,
  5127. SCTP_TO(SCTP_EVENT_TIMEOUT_T5_SHUTDOWN_GUARD));
  5128. } else {
  5129. sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
  5130. SCTP_ERROR(ETIMEDOUT));
  5131. /* CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
  5132. sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
  5133. SCTP_PERR(SCTP_ERROR_NO_ERROR));
  5134. SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
  5135. SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
  5136. return SCTP_DISPOSITION_DELETE_TCB;
  5137. }
  5138. }
  5139. /* E1) For the destination address for which the timer
  5140. * expires, adjust its ssthresh with rules defined in Section
  5141. * 7.2.3 and set the cwnd <- MTU.
  5142. */
  5143. /* E2) For the destination address for which the timer
  5144. * expires, set RTO <- RTO * 2 ("back off the timer"). The
  5145. * maximum value discussed in rule C7 above (RTO.max) may be
  5146. * used to provide an upper bound to this doubling operation.
  5147. */
  5148. /* E3) Determine how many of the earliest (i.e., lowest TSN)
  5149. * outstanding DATA chunks for the address for which the
  5150. * T3-rtx has expired will fit into a single packet, subject
  5151. * to the MTU constraint for the path corresponding to the
  5152. * destination transport address to which the retransmission
  5153. * is being sent (this may be different from the address for
  5154. * which the timer expires [see Section 6.4]). Call this
  5155. * value K. Bundle and retransmit those K DATA chunks in a
  5156. * single packet to the destination endpoint.
  5157. *
  5158. * Note: Any DATA chunks that were sent to the address for
  5159. * which the T3-rtx timer expired but did not fit in one MTU
  5160. * (rule E3 above), should be marked for retransmission and
  5161. * sent as soon as cwnd allows (normally when a SACK arrives).
  5162. */
  5163. /* Do some failure management (Section 8.2). */
  5164. sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE, SCTP_TRANSPORT(transport));
  5165. /* NB: Rules E4 and F1 are implicit in R1. */
  5166. sctp_add_cmd_sf(commands, SCTP_CMD_RETRAN, SCTP_TRANSPORT(transport));
  5167. return SCTP_DISPOSITION_CONSUME;
  5168. }
  5169. /*
  5170. * Generate delayed SACK on timeout
  5171. *
  5172. * Section: 6.2 Acknowledgement on Reception of DATA Chunks
  5173. *
  5174. * The guidelines on delayed acknowledgement algorithm specified in
  5175. * Section 4.2 of [RFC2581] SHOULD be followed. Specifically, an
  5176. * acknowledgement SHOULD be generated for at least every second packet
  5177. * (not every second DATA chunk) received, and SHOULD be generated
  5178. * within 200 ms of the arrival of any unacknowledged DATA chunk. In
  5179. * some situations it may be beneficial for an SCTP transmitter to be
  5180. * more conservative than the algorithms detailed in this document
  5181. * allow. However, an SCTP transmitter MUST NOT be more aggressive than
  5182. * the following algorithms allow.
  5183. */
  5184. enum sctp_disposition sctp_sf_do_6_2_sack(struct net *net,
  5185. const struct sctp_endpoint *ep,
  5186. const struct sctp_association *asoc,
  5187. const union sctp_subtype type,
  5188. void *arg,
  5189. struct sctp_cmd_seq *commands)
  5190. {
  5191. SCTP_INC_STATS(net, SCTP_MIB_DELAY_SACK_EXPIREDS);
  5192. sctp_add_cmd_sf(commands, SCTP_CMD_GEN_SACK, SCTP_FORCE());
  5193. return SCTP_DISPOSITION_CONSUME;
  5194. }
  5195. /*
  5196. * sctp_sf_t1_init_timer_expire
  5197. *
  5198. * Section: 4 Note: 2
  5199. * Verification Tag:
  5200. * Inputs
  5201. * (endpoint, asoc)
  5202. *
  5203. * RFC 2960 Section 4 Notes
  5204. * 2) If the T1-init timer expires, the endpoint MUST retransmit INIT
  5205. * and re-start the T1-init timer without changing state. This MUST
  5206. * be repeated up to 'Max.Init.Retransmits' times. After that, the
  5207. * endpoint MUST abort the initialization process and report the
  5208. * error to SCTP user.
  5209. *
  5210. * Outputs
  5211. * (timers, events)
  5212. *
  5213. */
  5214. enum sctp_disposition sctp_sf_t1_init_timer_expire(
  5215. struct net *net,
  5216. const struct sctp_endpoint *ep,
  5217. const struct sctp_association *asoc,
  5218. const union sctp_subtype type,
  5219. void *arg,
  5220. struct sctp_cmd_seq *commands)
  5221. {
  5222. int attempts = asoc->init_err_counter + 1;
  5223. struct sctp_chunk *repl = NULL;
  5224. struct sctp_bind_addr *bp;
  5225. pr_debug("%s: timer T1 expired (INIT)\n", __func__);
  5226. SCTP_INC_STATS(net, SCTP_MIB_T1_INIT_EXPIREDS);
  5227. if (attempts <= asoc->max_init_attempts) {
  5228. bp = (struct sctp_bind_addr *) &asoc->base.bind_addr;
  5229. repl = sctp_make_init(asoc, bp, GFP_ATOMIC, 0);
  5230. if (!repl)
  5231. return SCTP_DISPOSITION_NOMEM;
  5232. /* Choose transport for INIT. */
  5233. sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
  5234. SCTP_CHUNK(repl));
  5235. /* Issue a sideeffect to do the needed accounting. */
  5236. sctp_add_cmd_sf(commands, SCTP_CMD_INIT_RESTART,
  5237. SCTP_TO(SCTP_EVENT_TIMEOUT_T1_INIT));
  5238. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
  5239. } else {
  5240. pr_debug("%s: giving up on INIT, attempts:%d "
  5241. "max_init_attempts:%d\n", __func__, attempts,
  5242. asoc->max_init_attempts);
  5243. sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
  5244. SCTP_ERROR(ETIMEDOUT));
  5245. sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
  5246. SCTP_PERR(SCTP_ERROR_NO_ERROR));
  5247. return SCTP_DISPOSITION_DELETE_TCB;
  5248. }
  5249. return SCTP_DISPOSITION_CONSUME;
  5250. }
  5251. /*
  5252. * sctp_sf_t1_cookie_timer_expire
  5253. *
  5254. * Section: 4 Note: 2
  5255. * Verification Tag:
  5256. * Inputs
  5257. * (endpoint, asoc)
  5258. *
  5259. * RFC 2960 Section 4 Notes
  5260. * 3) If the T1-cookie timer expires, the endpoint MUST retransmit
  5261. * COOKIE ECHO and re-start the T1-cookie timer without changing
  5262. * state. This MUST be repeated up to 'Max.Init.Retransmits' times.
  5263. * After that, the endpoint MUST abort the initialization process and
  5264. * report the error to SCTP user.
  5265. *
  5266. * Outputs
  5267. * (timers, events)
  5268. *
  5269. */
  5270. enum sctp_disposition sctp_sf_t1_cookie_timer_expire(
  5271. struct net *net,
  5272. const struct sctp_endpoint *ep,
  5273. const struct sctp_association *asoc,
  5274. const union sctp_subtype type,
  5275. void *arg,
  5276. struct sctp_cmd_seq *commands)
  5277. {
  5278. int attempts = asoc->init_err_counter + 1;
  5279. struct sctp_chunk *repl = NULL;
  5280. pr_debug("%s: timer T1 expired (COOKIE-ECHO)\n", __func__);
  5281. SCTP_INC_STATS(net, SCTP_MIB_T1_COOKIE_EXPIREDS);
  5282. if (attempts <= asoc->max_init_attempts) {
  5283. repl = sctp_make_cookie_echo(asoc, NULL);
  5284. if (!repl)
  5285. return SCTP_DISPOSITION_NOMEM;
  5286. sctp_add_cmd_sf(commands, SCTP_CMD_INIT_CHOOSE_TRANSPORT,
  5287. SCTP_CHUNK(repl));
  5288. /* Issue a sideeffect to do the needed accounting. */
  5289. sctp_add_cmd_sf(commands, SCTP_CMD_COOKIEECHO_RESTART,
  5290. SCTP_TO(SCTP_EVENT_TIMEOUT_T1_COOKIE));
  5291. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(repl));
  5292. } else {
  5293. sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
  5294. SCTP_ERROR(ETIMEDOUT));
  5295. sctp_add_cmd_sf(commands, SCTP_CMD_INIT_FAILED,
  5296. SCTP_PERR(SCTP_ERROR_NO_ERROR));
  5297. return SCTP_DISPOSITION_DELETE_TCB;
  5298. }
  5299. return SCTP_DISPOSITION_CONSUME;
  5300. }
  5301. /* RFC2960 9.2 If the timer expires, the endpoint must re-send the SHUTDOWN
  5302. * with the updated last sequential TSN received from its peer.
  5303. *
  5304. * An endpoint should limit the number of retransmission of the
  5305. * SHUTDOWN chunk to the protocol parameter 'Association.Max.Retrans'.
  5306. * If this threshold is exceeded the endpoint should destroy the TCB and
  5307. * MUST report the peer endpoint unreachable to the upper layer (and
  5308. * thus the association enters the CLOSED state). The reception of any
  5309. * packet from its peer (i.e. as the peer sends all of its queued DATA
  5310. * chunks) should clear the endpoint's retransmission count and restart
  5311. * the T2-Shutdown timer, giving its peer ample opportunity to transmit
  5312. * all of its queued DATA chunks that have not yet been sent.
  5313. */
  5314. enum sctp_disposition sctp_sf_t2_timer_expire(
  5315. struct net *net,
  5316. const struct sctp_endpoint *ep,
  5317. const struct sctp_association *asoc,
  5318. const union sctp_subtype type,
  5319. void *arg,
  5320. struct sctp_cmd_seq *commands)
  5321. {
  5322. struct sctp_chunk *reply = NULL;
  5323. pr_debug("%s: timer T2 expired\n", __func__);
  5324. SCTP_INC_STATS(net, SCTP_MIB_T2_SHUTDOWN_EXPIREDS);
  5325. ((struct sctp_association *)asoc)->shutdown_retries++;
  5326. if (asoc->overall_error_count >= asoc->max_retrans) {
  5327. sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
  5328. SCTP_ERROR(ETIMEDOUT));
  5329. /* Note: CMD_ASSOC_FAILED calls CMD_DELETE_TCB. */
  5330. sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
  5331. SCTP_PERR(SCTP_ERROR_NO_ERROR));
  5332. SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
  5333. SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
  5334. return SCTP_DISPOSITION_DELETE_TCB;
  5335. }
  5336. switch (asoc->state) {
  5337. case SCTP_STATE_SHUTDOWN_SENT:
  5338. reply = sctp_make_shutdown(asoc, NULL);
  5339. break;
  5340. case SCTP_STATE_SHUTDOWN_ACK_SENT:
  5341. reply = sctp_make_shutdown_ack(asoc, NULL);
  5342. break;
  5343. default:
  5344. BUG();
  5345. break;
  5346. }
  5347. if (!reply)
  5348. goto nomem;
  5349. /* Do some failure management (Section 8.2).
  5350. * If we remove the transport an SHUTDOWN was last sent to, don't
  5351. * do failure management.
  5352. */
  5353. if (asoc->shutdown_last_sent_to)
  5354. sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
  5355. SCTP_TRANSPORT(asoc->shutdown_last_sent_to));
  5356. /* Set the transport for the SHUTDOWN/ACK chunk and the timeout for
  5357. * the T2-shutdown timer.
  5358. */
  5359. sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T2, SCTP_CHUNK(reply));
  5360. /* Restart the T2-shutdown timer. */
  5361. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
  5362. SCTP_TO(SCTP_EVENT_TIMEOUT_T2_SHUTDOWN));
  5363. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
  5364. return SCTP_DISPOSITION_CONSUME;
  5365. nomem:
  5366. return SCTP_DISPOSITION_NOMEM;
  5367. }
  5368. /*
  5369. * ADDIP Section 4.1 ASCONF Chunk Procedures
  5370. * If the T4 RTO timer expires the endpoint should do B1 to B5
  5371. */
  5372. enum sctp_disposition sctp_sf_t4_timer_expire(
  5373. struct net *net,
  5374. const struct sctp_endpoint *ep,
  5375. const struct sctp_association *asoc,
  5376. const union sctp_subtype type,
  5377. void *arg,
  5378. struct sctp_cmd_seq *commands)
  5379. {
  5380. struct sctp_chunk *chunk = asoc->addip_last_asconf;
  5381. struct sctp_transport *transport = chunk->transport;
  5382. SCTP_INC_STATS(net, SCTP_MIB_T4_RTO_EXPIREDS);
  5383. /* ADDIP 4.1 B1) Increment the error counters and perform path failure
  5384. * detection on the appropriate destination address as defined in
  5385. * RFC2960 [5] section 8.1 and 8.2.
  5386. */
  5387. if (transport)
  5388. sctp_add_cmd_sf(commands, SCTP_CMD_STRIKE,
  5389. SCTP_TRANSPORT(transport));
  5390. /* Reconfig T4 timer and transport. */
  5391. sctp_add_cmd_sf(commands, SCTP_CMD_SETUP_T4, SCTP_CHUNK(chunk));
  5392. /* ADDIP 4.1 B2) Increment the association error counters and perform
  5393. * endpoint failure detection on the association as defined in
  5394. * RFC2960 [5] section 8.1 and 8.2.
  5395. * association error counter is incremented in SCTP_CMD_STRIKE.
  5396. */
  5397. if (asoc->overall_error_count >= asoc->max_retrans) {
  5398. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_STOP,
  5399. SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
  5400. sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
  5401. SCTP_ERROR(ETIMEDOUT));
  5402. sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
  5403. SCTP_PERR(SCTP_ERROR_NO_ERROR));
  5404. SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
  5405. SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
  5406. return SCTP_DISPOSITION_ABORT;
  5407. }
  5408. /* ADDIP 4.1 B3) Back-off the destination address RTO value to which
  5409. * the ASCONF chunk was sent by doubling the RTO timer value.
  5410. * This is done in SCTP_CMD_STRIKE.
  5411. */
  5412. /* ADDIP 4.1 B4) Re-transmit the ASCONF Chunk last sent and if possible
  5413. * choose an alternate destination address (please refer to RFC2960
  5414. * [5] section 6.4.1). An endpoint MUST NOT add new parameters to this
  5415. * chunk, it MUST be the same (including its serial number) as the last
  5416. * ASCONF sent.
  5417. */
  5418. sctp_chunk_hold(asoc->addip_last_asconf);
  5419. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
  5420. SCTP_CHUNK(asoc->addip_last_asconf));
  5421. /* ADDIP 4.1 B5) Restart the T-4 RTO timer. Note that if a different
  5422. * destination is selected, then the RTO used will be that of the new
  5423. * destination address.
  5424. */
  5425. sctp_add_cmd_sf(commands, SCTP_CMD_TIMER_RESTART,
  5426. SCTP_TO(SCTP_EVENT_TIMEOUT_T4_RTO));
  5427. return SCTP_DISPOSITION_CONSUME;
  5428. }
  5429. /* sctpimpguide-05 Section 2.12.2
  5430. * The sender of the SHUTDOWN MAY also start an overall guard timer
  5431. * 'T5-shutdown-guard' to bound the overall time for shutdown sequence.
  5432. * At the expiration of this timer the sender SHOULD abort the association
  5433. * by sending an ABORT chunk.
  5434. */
  5435. enum sctp_disposition sctp_sf_t5_timer_expire(
  5436. struct net *net,
  5437. const struct sctp_endpoint *ep,
  5438. const struct sctp_association *asoc,
  5439. const union sctp_subtype type,
  5440. void *arg,
  5441. struct sctp_cmd_seq *commands)
  5442. {
  5443. struct sctp_chunk *reply = NULL;
  5444. pr_debug("%s: timer T5 expired\n", __func__);
  5445. SCTP_INC_STATS(net, SCTP_MIB_T5_SHUTDOWN_GUARD_EXPIREDS);
  5446. reply = sctp_make_abort(asoc, NULL, 0);
  5447. if (!reply)
  5448. goto nomem;
  5449. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY, SCTP_CHUNK(reply));
  5450. sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
  5451. SCTP_ERROR(ETIMEDOUT));
  5452. sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
  5453. SCTP_PERR(SCTP_ERROR_NO_ERROR));
  5454. SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
  5455. SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
  5456. return SCTP_DISPOSITION_DELETE_TCB;
  5457. nomem:
  5458. return SCTP_DISPOSITION_NOMEM;
  5459. }
  5460. /* Handle expiration of AUTOCLOSE timer. When the autoclose timer expires,
  5461. * the association is automatically closed by starting the shutdown process.
  5462. * The work that needs to be done is same as when SHUTDOWN is initiated by
  5463. * the user. So this routine looks same as sctp_sf_do_9_2_prm_shutdown().
  5464. */
  5465. enum sctp_disposition sctp_sf_autoclose_timer_expire(
  5466. struct net *net,
  5467. const struct sctp_endpoint *ep,
  5468. const struct sctp_association *asoc,
  5469. const union sctp_subtype type,
  5470. void *arg,
  5471. struct sctp_cmd_seq *commands)
  5472. {
  5473. enum sctp_disposition disposition;
  5474. SCTP_INC_STATS(net, SCTP_MIB_AUTOCLOSE_EXPIREDS);
  5475. /* From 9.2 Shutdown of an Association
  5476. * Upon receipt of the SHUTDOWN primitive from its upper
  5477. * layer, the endpoint enters SHUTDOWN-PENDING state and
  5478. * remains there until all outstanding data has been
  5479. * acknowledged by its peer. The endpoint accepts no new data
  5480. * from its upper layer, but retransmits data to the far end
  5481. * if necessary to fill gaps.
  5482. */
  5483. sctp_add_cmd_sf(commands, SCTP_CMD_NEW_STATE,
  5484. SCTP_STATE(SCTP_STATE_SHUTDOWN_PENDING));
  5485. disposition = SCTP_DISPOSITION_CONSUME;
  5486. if (sctp_outq_is_empty(&asoc->outqueue)) {
  5487. disposition = sctp_sf_do_9_2_start_shutdown(net, ep, asoc, type,
  5488. NULL, commands);
  5489. }
  5490. return disposition;
  5491. }
  5492. /*****************************************************************************
  5493. * These are sa state functions which could apply to all types of events.
  5494. ****************************************************************************/
  5495. /*
  5496. * This table entry is not implemented.
  5497. *
  5498. * Inputs
  5499. * (endpoint, asoc, chunk)
  5500. *
  5501. * The return value is the disposition of the chunk.
  5502. */
  5503. enum sctp_disposition sctp_sf_not_impl(struct net *net,
  5504. const struct sctp_endpoint *ep,
  5505. const struct sctp_association *asoc,
  5506. const union sctp_subtype type,
  5507. void *arg, struct sctp_cmd_seq *commands)
  5508. {
  5509. return SCTP_DISPOSITION_NOT_IMPL;
  5510. }
  5511. /*
  5512. * This table entry represents a bug.
  5513. *
  5514. * Inputs
  5515. * (endpoint, asoc, chunk)
  5516. *
  5517. * The return value is the disposition of the chunk.
  5518. */
  5519. enum sctp_disposition sctp_sf_bug(struct net *net,
  5520. const struct sctp_endpoint *ep,
  5521. const struct sctp_association *asoc,
  5522. const union sctp_subtype type,
  5523. void *arg, struct sctp_cmd_seq *commands)
  5524. {
  5525. return SCTP_DISPOSITION_BUG;
  5526. }
  5527. /*
  5528. * This table entry represents the firing of a timer in the wrong state.
  5529. * Since timer deletion cannot be guaranteed a timer 'may' end up firing
  5530. * when the association is in the wrong state. This event should
  5531. * be ignored, so as to prevent any rearming of the timer.
  5532. *
  5533. * Inputs
  5534. * (endpoint, asoc, chunk)
  5535. *
  5536. * The return value is the disposition of the chunk.
  5537. */
  5538. enum sctp_disposition sctp_sf_timer_ignore(struct net *net,
  5539. const struct sctp_endpoint *ep,
  5540. const struct sctp_association *asoc,
  5541. const union sctp_subtype type,
  5542. void *arg,
  5543. struct sctp_cmd_seq *commands)
  5544. {
  5545. pr_debug("%s: timer %d ignored\n", __func__, type.chunk);
  5546. return SCTP_DISPOSITION_CONSUME;
  5547. }
  5548. /********************************************************************
  5549. * 2nd Level Abstractions
  5550. ********************************************************************/
  5551. /* Pull the SACK chunk based on the SACK header. */
  5552. static struct sctp_sackhdr *sctp_sm_pull_sack(struct sctp_chunk *chunk)
  5553. {
  5554. struct sctp_sackhdr *sack;
  5555. __u16 num_dup_tsns;
  5556. unsigned int len;
  5557. __u16 num_blocks;
  5558. /* Protect ourselves from reading too far into
  5559. * the skb from a bogus sender.
  5560. */
  5561. sack = (struct sctp_sackhdr *) chunk->skb->data;
  5562. num_blocks = ntohs(sack->num_gap_ack_blocks);
  5563. num_dup_tsns = ntohs(sack->num_dup_tsns);
  5564. len = sizeof(struct sctp_sackhdr);
  5565. len += (num_blocks + num_dup_tsns) * sizeof(__u32);
  5566. if (len > chunk->skb->len)
  5567. return NULL;
  5568. skb_pull(chunk->skb, len);
  5569. return sack;
  5570. }
  5571. /* Create an ABORT packet to be sent as a response, with the specified
  5572. * error causes.
  5573. */
  5574. static struct sctp_packet *sctp_abort_pkt_new(
  5575. struct net *net,
  5576. const struct sctp_endpoint *ep,
  5577. const struct sctp_association *asoc,
  5578. struct sctp_chunk *chunk,
  5579. const void *payload, size_t paylen)
  5580. {
  5581. struct sctp_packet *packet;
  5582. struct sctp_chunk *abort;
  5583. packet = sctp_ootb_pkt_new(net, asoc, chunk);
  5584. if (packet) {
  5585. /* Make an ABORT.
  5586. * The T bit will be set if the asoc is NULL.
  5587. */
  5588. abort = sctp_make_abort(asoc, chunk, paylen);
  5589. if (!abort) {
  5590. sctp_ootb_pkt_free(packet);
  5591. return NULL;
  5592. }
  5593. /* Reflect vtag if T-Bit is set */
  5594. if (sctp_test_T_bit(abort))
  5595. packet->vtag = ntohl(chunk->sctp_hdr->vtag);
  5596. /* Add specified error causes, i.e., payload, to the
  5597. * end of the chunk.
  5598. */
  5599. sctp_addto_chunk(abort, paylen, payload);
  5600. /* Set the skb to the belonging sock for accounting. */
  5601. abort->skb->sk = ep->base.sk;
  5602. sctp_packet_append_chunk(packet, abort);
  5603. }
  5604. return packet;
  5605. }
  5606. /* Allocate a packet for responding in the OOTB conditions. */
  5607. static struct sctp_packet *sctp_ootb_pkt_new(
  5608. struct net *net,
  5609. const struct sctp_association *asoc,
  5610. const struct sctp_chunk *chunk)
  5611. {
  5612. struct sctp_transport *transport;
  5613. struct sctp_packet *packet;
  5614. __u16 sport, dport;
  5615. __u32 vtag;
  5616. /* Get the source and destination port from the inbound packet. */
  5617. sport = ntohs(chunk->sctp_hdr->dest);
  5618. dport = ntohs(chunk->sctp_hdr->source);
  5619. /* The V-tag is going to be the same as the inbound packet if no
  5620. * association exists, otherwise, use the peer's vtag.
  5621. */
  5622. if (asoc) {
  5623. /* Special case the INIT-ACK as there is no peer's vtag
  5624. * yet.
  5625. */
  5626. switch (chunk->chunk_hdr->type) {
  5627. case SCTP_CID_INIT:
  5628. case SCTP_CID_INIT_ACK:
  5629. {
  5630. struct sctp_initack_chunk *initack;
  5631. initack = (struct sctp_initack_chunk *)chunk->chunk_hdr;
  5632. vtag = ntohl(initack->init_hdr.init_tag);
  5633. break;
  5634. }
  5635. default:
  5636. vtag = asoc->peer.i.init_tag;
  5637. break;
  5638. }
  5639. } else {
  5640. /* Special case the INIT and stale COOKIE_ECHO as there is no
  5641. * vtag yet.
  5642. */
  5643. switch (chunk->chunk_hdr->type) {
  5644. case SCTP_CID_INIT:
  5645. {
  5646. struct sctp_init_chunk *init;
  5647. init = (struct sctp_init_chunk *)chunk->chunk_hdr;
  5648. vtag = ntohl(init->init_hdr.init_tag);
  5649. break;
  5650. }
  5651. default:
  5652. vtag = ntohl(chunk->sctp_hdr->vtag);
  5653. break;
  5654. }
  5655. }
  5656. /* Make a transport for the bucket, Eliza... */
  5657. transport = sctp_transport_new(net, sctp_source(chunk), GFP_ATOMIC);
  5658. if (!transport)
  5659. goto nomem;
  5660. transport->encap_port = SCTP_INPUT_CB(chunk->skb)->encap_port;
  5661. /* Cache a route for the transport with the chunk's destination as
  5662. * the source address.
  5663. */
  5664. sctp_transport_route(transport, (union sctp_addr *)&chunk->dest,
  5665. sctp_sk(net->sctp.ctl_sock));
  5666. packet = &transport->packet;
  5667. sctp_packet_init(packet, transport, sport, dport);
  5668. sctp_packet_config(packet, vtag, 0);
  5669. return packet;
  5670. nomem:
  5671. return NULL;
  5672. }
  5673. /* Free the packet allocated earlier for responding in the OOTB condition. */
  5674. void sctp_ootb_pkt_free(struct sctp_packet *packet)
  5675. {
  5676. sctp_transport_free(packet->transport);
  5677. }
  5678. /* Send a stale cookie error when a invalid COOKIE ECHO chunk is found */
  5679. static void sctp_send_stale_cookie_err(struct net *net,
  5680. const struct sctp_endpoint *ep,
  5681. const struct sctp_association *asoc,
  5682. const struct sctp_chunk *chunk,
  5683. struct sctp_cmd_seq *commands,
  5684. struct sctp_chunk *err_chunk)
  5685. {
  5686. struct sctp_packet *packet;
  5687. if (err_chunk) {
  5688. packet = sctp_ootb_pkt_new(net, asoc, chunk);
  5689. if (packet) {
  5690. struct sctp_signed_cookie *cookie;
  5691. /* Override the OOTB vtag from the cookie. */
  5692. cookie = chunk->subh.cookie_hdr;
  5693. packet->vtag = cookie->c.peer_vtag;
  5694. /* Set the skb to the belonging sock for accounting. */
  5695. err_chunk->skb->sk = ep->base.sk;
  5696. sctp_packet_append_chunk(packet, err_chunk);
  5697. sctp_add_cmd_sf(commands, SCTP_CMD_SEND_PKT,
  5698. SCTP_PACKET(packet));
  5699. SCTP_INC_STATS(net, SCTP_MIB_OUTCTRLCHUNKS);
  5700. } else
  5701. sctp_chunk_free (err_chunk);
  5702. }
  5703. }
  5704. /* Process a data chunk */
  5705. static int sctp_eat_data(const struct sctp_association *asoc,
  5706. struct sctp_chunk *chunk,
  5707. struct sctp_cmd_seq *commands)
  5708. {
  5709. struct sctp_tsnmap *map = (struct sctp_tsnmap *)&asoc->peer.tsn_map;
  5710. struct sock *sk = asoc->base.sk;
  5711. struct net *net = sock_net(sk);
  5712. struct sctp_datahdr *data_hdr;
  5713. struct sctp_chunk *err;
  5714. enum sctp_verb deliver;
  5715. size_t datalen;
  5716. __u32 tsn;
  5717. int tmp;
  5718. data_hdr = (struct sctp_datahdr *)chunk->skb->data;
  5719. chunk->subh.data_hdr = data_hdr;
  5720. skb_pull(chunk->skb, sctp_datahdr_len(&asoc->stream));
  5721. tsn = ntohl(data_hdr->tsn);
  5722. pr_debug("%s: TSN 0x%x\n", __func__, tsn);
  5723. /* ASSERT: Now skb->data is really the user data. */
  5724. /* Process ECN based congestion.
  5725. *
  5726. * Since the chunk structure is reused for all chunks within
  5727. * a packet, we use ecn_ce_done to track if we've already
  5728. * done CE processing for this packet.
  5729. *
  5730. * We need to do ECN processing even if we plan to discard the
  5731. * chunk later.
  5732. */
  5733. if (asoc->peer.ecn_capable && !chunk->ecn_ce_done) {
  5734. struct sctp_af *af = SCTP_INPUT_CB(chunk->skb)->af;
  5735. chunk->ecn_ce_done = 1;
  5736. if (af->is_ce(sctp_gso_headskb(chunk->skb))) {
  5737. /* Do real work as side effect. */
  5738. sctp_add_cmd_sf(commands, SCTP_CMD_ECN_CE,
  5739. SCTP_U32(tsn));
  5740. }
  5741. }
  5742. tmp = sctp_tsnmap_check(&asoc->peer.tsn_map, tsn);
  5743. if (tmp < 0) {
  5744. /* The TSN is too high--silently discard the chunk and
  5745. * count on it getting retransmitted later.
  5746. */
  5747. if (chunk->asoc)
  5748. chunk->asoc->stats.outofseqtsns++;
  5749. return SCTP_IERROR_HIGH_TSN;
  5750. } else if (tmp > 0) {
  5751. /* This is a duplicate. Record it. */
  5752. sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_DUP, SCTP_U32(tsn));
  5753. return SCTP_IERROR_DUP_TSN;
  5754. }
  5755. /* This is a new TSN. */
  5756. /* Discard if there is no room in the receive window.
  5757. * Actually, allow a little bit of overflow (up to a MTU).
  5758. */
  5759. datalen = ntohs(chunk->chunk_hdr->length);
  5760. datalen -= sctp_datachk_len(&asoc->stream);
  5761. deliver = SCTP_CMD_CHUNK_ULP;
  5762. /* Think about partial delivery. */
  5763. if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) {
  5764. /* Even if we don't accept this chunk there is
  5765. * memory pressure.
  5766. */
  5767. sctp_add_cmd_sf(commands, SCTP_CMD_PART_DELIVER, SCTP_NULL());
  5768. }
  5769. /* Spill over rwnd a little bit. Note: While allowed, this spill over
  5770. * seems a bit troublesome in that frag_point varies based on
  5771. * PMTU. In cases, such as loopback, this might be a rather
  5772. * large spill over.
  5773. */
  5774. if ((!chunk->data_accepted) && (!asoc->rwnd || asoc->rwnd_over ||
  5775. (datalen > asoc->rwnd + asoc->frag_point))) {
  5776. /* If this is the next TSN, consider reneging to make
  5777. * room. Note: Playing nice with a confused sender. A
  5778. * malicious sender can still eat up all our buffer
  5779. * space and in the future we may want to detect and
  5780. * do more drastic reneging.
  5781. */
  5782. if (sctp_tsnmap_has_gap(map) &&
  5783. (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
  5784. pr_debug("%s: reneging for tsn:%u\n", __func__, tsn);
  5785. deliver = SCTP_CMD_RENEGE;
  5786. } else {
  5787. pr_debug("%s: discard tsn:%u len:%zu, rwnd:%d\n",
  5788. __func__, tsn, datalen, asoc->rwnd);
  5789. return SCTP_IERROR_IGNORE_TSN;
  5790. }
  5791. }
  5792. /*
  5793. * Also try to renege to limit our memory usage in the event that
  5794. * we are under memory pressure
  5795. * If we can't renege, don't worry about it, the sk_rmem_schedule
  5796. * in sctp_ulpevent_make_rcvmsg will drop the frame if we grow our
  5797. * memory usage too much
  5798. */
  5799. if (sk_under_memory_pressure(sk)) {
  5800. if (sctp_tsnmap_has_gap(map) &&
  5801. (sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
  5802. pr_debug("%s: under pressure, reneging for tsn:%u\n",
  5803. __func__, tsn);
  5804. deliver = SCTP_CMD_RENEGE;
  5805. }
  5806. }
  5807. /*
  5808. * Section 3.3.10.9 No User Data (9)
  5809. *
  5810. * Cause of error
  5811. * ---------------
  5812. * No User Data: This error cause is returned to the originator of a
  5813. * DATA chunk if a received DATA chunk has no user data.
  5814. */
  5815. if (unlikely(0 == datalen)) {
  5816. err = sctp_make_abort_no_data(asoc, chunk, tsn);
  5817. if (err) {
  5818. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
  5819. SCTP_CHUNK(err));
  5820. }
  5821. /* We are going to ABORT, so we might as well stop
  5822. * processing the rest of the chunks in the packet.
  5823. */
  5824. sctp_add_cmd_sf(commands, SCTP_CMD_DISCARD_PACKET, SCTP_NULL());
  5825. sctp_add_cmd_sf(commands, SCTP_CMD_SET_SK_ERR,
  5826. SCTP_ERROR(ECONNABORTED));
  5827. sctp_add_cmd_sf(commands, SCTP_CMD_ASSOC_FAILED,
  5828. SCTP_PERR(SCTP_ERROR_NO_DATA));
  5829. SCTP_INC_STATS(net, SCTP_MIB_ABORTEDS);
  5830. SCTP_DEC_STATS(net, SCTP_MIB_CURRESTAB);
  5831. return SCTP_IERROR_NO_DATA;
  5832. }
  5833. chunk->data_accepted = 1;
  5834. /* Note: Some chunks may get overcounted (if we drop) or overcounted
  5835. * if we renege and the chunk arrives again.
  5836. */
  5837. if (chunk->chunk_hdr->flags & SCTP_DATA_UNORDERED) {
  5838. SCTP_INC_STATS(net, SCTP_MIB_INUNORDERCHUNKS);
  5839. if (chunk->asoc)
  5840. chunk->asoc->stats.iuodchunks++;
  5841. } else {
  5842. SCTP_INC_STATS(net, SCTP_MIB_INORDERCHUNKS);
  5843. if (chunk->asoc)
  5844. chunk->asoc->stats.iodchunks++;
  5845. }
  5846. /* RFC 2960 6.5 Stream Identifier and Stream Sequence Number
  5847. *
  5848. * If an endpoint receive a DATA chunk with an invalid stream
  5849. * identifier, it shall acknowledge the reception of the DATA chunk
  5850. * following the normal procedure, immediately send an ERROR chunk
  5851. * with cause set to "Invalid Stream Identifier" (See Section 3.3.10)
  5852. * and discard the DATA chunk.
  5853. */
  5854. if (ntohs(data_hdr->stream) >= asoc->stream.incnt) {
  5855. /* Mark tsn as received even though we drop it */
  5856. sctp_add_cmd_sf(commands, SCTP_CMD_REPORT_TSN, SCTP_U32(tsn));
  5857. err = sctp_make_op_error(asoc, chunk, SCTP_ERROR_INV_STRM,
  5858. &data_hdr->stream,
  5859. sizeof(data_hdr->stream),
  5860. sizeof(u16));
  5861. if (err)
  5862. sctp_add_cmd_sf(commands, SCTP_CMD_REPLY,
  5863. SCTP_CHUNK(err));
  5864. return SCTP_IERROR_BAD_STREAM;
  5865. }
  5866. /* Check to see if the SSN is possible for this TSN.
  5867. * The biggest gap we can record is 4K wide. Since SSNs wrap
  5868. * at an unsigned short, there is no way that an SSN can
  5869. * wrap and for a valid TSN. We can simply check if the current
  5870. * SSN is smaller then the next expected one. If it is, it wrapped
  5871. * and is invalid.
  5872. */
  5873. if (!asoc->stream.si->validate_data(chunk))
  5874. return SCTP_IERROR_PROTO_VIOLATION;
  5875. /* Send the data up to the user. Note: Schedule the
  5876. * SCTP_CMD_CHUNK_ULP cmd before the SCTP_CMD_GEN_SACK, as the SACK
  5877. * chunk needs the updated rwnd.
  5878. */
  5879. sctp_add_cmd_sf(commands, deliver, SCTP_CHUNK(chunk));
  5880. return SCTP_IERROR_NO_ERROR;
  5881. }