sm_statefuns.c 209 KB

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