sm_statefuns.c 176 KB

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