bpf.h 279 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. /* Copyright (c) 2011-2014 PLUMgrid, http://plumgrid.com
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of version 2 of the GNU General Public
  6. * License as published by the Free Software Foundation.
  7. */
  8. #ifndef _UAPI__LINUX_BPF_H__
  9. #define _UAPI__LINUX_BPF_H__
  10. #include <linux/types.h>
  11. #include <linux/bpf_common.h>
  12. /* Extended instruction set based on top of classic BPF */
  13. /* instruction classes */
  14. #define BPF_JMP32 0x06 /* jmp mode in word width */
  15. #define BPF_ALU64 0x07 /* alu mode in double word width */
  16. /* ld/ldx fields */
  17. #define BPF_DW 0x18 /* double word (64-bit) */
  18. #define BPF_MEMSX 0x80 /* load with sign extension */
  19. #define BPF_ATOMIC 0xc0 /* atomic memory ops - op type in immediate */
  20. #define BPF_XADD 0xc0 /* exclusive add - legacy name */
  21. /* alu/jmp fields */
  22. #define BPF_MOV 0xb0 /* mov reg to reg */
  23. #define BPF_ARSH 0xc0 /* sign extending arithmetic shift right */
  24. /* change endianness of a register */
  25. #define BPF_END 0xd0 /* flags for endianness conversion: */
  26. #define BPF_TO_LE 0x00 /* convert to little-endian */
  27. #define BPF_TO_BE 0x08 /* convert to big-endian */
  28. #define BPF_FROM_LE BPF_TO_LE
  29. #define BPF_FROM_BE BPF_TO_BE
  30. /* jmp encodings */
  31. #define BPF_JNE 0x50 /* jump != */
  32. #define BPF_JLT 0xa0 /* LT is unsigned, '<' */
  33. #define BPF_JLE 0xb0 /* LE is unsigned, '<=' */
  34. #define BPF_JSGT 0x60 /* SGT is signed '>', GT in x86 */
  35. #define BPF_JSGE 0x70 /* SGE is signed '>=', GE in x86 */
  36. #define BPF_JSLT 0xc0 /* SLT is signed, '<' */
  37. #define BPF_JSLE 0xd0 /* SLE is signed, '<=' */
  38. #define BPF_JCOND 0xe0 /* conditional pseudo jumps: may_goto, goto_or_nop */
  39. #define BPF_CALL 0x80 /* function call */
  40. #define BPF_EXIT 0x90 /* function return */
  41. /* atomic op type fields (stored in immediate) */
  42. #define BPF_FETCH 0x01 /* not an opcode on its own, used to build others */
  43. #define BPF_XCHG (0xe0 | BPF_FETCH) /* atomic exchange */
  44. #define BPF_CMPXCHG (0xf0 | BPF_FETCH) /* atomic compare-and-write */
  45. #define BPF_LOAD_ACQ 0x100 /* load-acquire */
  46. #define BPF_STORE_REL 0x110 /* store-release */
  47. enum bpf_cond_pseudo_jmp {
  48. BPF_MAY_GOTO = 0,
  49. };
  50. /* Register numbers */
  51. enum {
  52. BPF_REG_0 = 0,
  53. BPF_REG_1,
  54. BPF_REG_2,
  55. BPF_REG_3,
  56. BPF_REG_4,
  57. BPF_REG_5,
  58. BPF_REG_6,
  59. BPF_REG_7,
  60. BPF_REG_8,
  61. BPF_REG_9,
  62. BPF_REG_10,
  63. __MAX_BPF_REG,
  64. };
  65. /* BPF has 10 general purpose 64-bit registers and stack frame. */
  66. #define MAX_BPF_REG __MAX_BPF_REG
  67. struct bpf_insn {
  68. __u8 code; /* opcode */
  69. __u8 dst_reg:4; /* dest register */
  70. __u8 src_reg:4; /* source register */
  71. __s16 off; /* signed offset */
  72. __s32 imm; /* signed immediate constant */
  73. };
  74. /* Deprecated: use struct bpf_lpm_trie_key_u8 (when the "data" member is needed for
  75. * byte access) or struct bpf_lpm_trie_key_hdr (when using an alternative type for
  76. * the trailing flexible array member) instead.
  77. */
  78. struct bpf_lpm_trie_key {
  79. __u32 prefixlen; /* up to 32 for AF_INET, 128 for AF_INET6 */
  80. __u8 data[0]; /* Arbitrary size */
  81. };
  82. /* Header for bpf_lpm_trie_key structs */
  83. struct bpf_lpm_trie_key_hdr {
  84. __u32 prefixlen;
  85. };
  86. /* Key of an a BPF_MAP_TYPE_LPM_TRIE entry, with trailing byte array. */
  87. struct bpf_lpm_trie_key_u8 {
  88. union {
  89. struct bpf_lpm_trie_key_hdr hdr;
  90. __u32 prefixlen;
  91. };
  92. __u8 data[]; /* Arbitrary size */
  93. };
  94. struct bpf_cgroup_storage_key {
  95. __u64 cgroup_inode_id; /* cgroup inode id */
  96. __u32 attach_type; /* program attach type (enum bpf_attach_type) */
  97. };
  98. enum bpf_cgroup_iter_order {
  99. BPF_CGROUP_ITER_ORDER_UNSPEC = 0,
  100. BPF_CGROUP_ITER_SELF_ONLY, /* process only a single object. */
  101. BPF_CGROUP_ITER_DESCENDANTS_PRE, /* walk descendants in pre-order. */
  102. BPF_CGROUP_ITER_DESCENDANTS_POST, /* walk descendants in post-order. */
  103. BPF_CGROUP_ITER_ANCESTORS_UP, /* walk ancestors upward. */
  104. /*
  105. * Walks the immediate children of the specified parent
  106. * cgroup_subsys_state. Unlike BPF_CGROUP_ITER_DESCENDANTS_PRE,
  107. * BPF_CGROUP_ITER_DESCENDANTS_POST, and BPF_CGROUP_ITER_ANCESTORS_UP
  108. * the iterator does not include the specified parent as one of the
  109. * returned iterator elements.
  110. */
  111. BPF_CGROUP_ITER_CHILDREN,
  112. };
  113. union bpf_iter_link_info {
  114. struct {
  115. __u32 map_fd;
  116. } map;
  117. struct {
  118. enum bpf_cgroup_iter_order order;
  119. /* At most one of cgroup_fd and cgroup_id can be non-zero. If
  120. * both are zero, the walk starts from the default cgroup v2
  121. * root. For walking v1 hierarchy, one should always explicitly
  122. * specify cgroup_fd.
  123. */
  124. __u32 cgroup_fd;
  125. __u64 cgroup_id;
  126. } cgroup;
  127. /* Parameters of task iterators. */
  128. struct {
  129. __u32 tid;
  130. __u32 pid;
  131. __u32 pid_fd;
  132. } task;
  133. };
  134. /* BPF syscall commands, see bpf(2) man-page for more details. */
  135. /**
  136. * DOC: eBPF Syscall Preamble
  137. *
  138. * The operation to be performed by the **bpf**\ () system call is determined
  139. * by the *cmd* argument. Each operation takes an accompanying argument,
  140. * provided via *attr*, which is a pointer to a union of type *bpf_attr* (see
  141. * below). The size argument is the size of the union pointed to by *attr*.
  142. */
  143. /**
  144. * DOC: eBPF Syscall Commands
  145. *
  146. * BPF_MAP_CREATE
  147. * Description
  148. * Create a map and return a file descriptor that refers to the
  149. * map. The close-on-exec file descriptor flag (see **fcntl**\ (2))
  150. * is automatically enabled for the new file descriptor.
  151. *
  152. * Applying **close**\ (2) to the file descriptor returned by
  153. * **BPF_MAP_CREATE** will delete the map (but see NOTES).
  154. *
  155. * Return
  156. * A new file descriptor (a nonnegative integer), or -1 if an
  157. * error occurred (in which case, *errno* is set appropriately).
  158. *
  159. * BPF_MAP_LOOKUP_ELEM
  160. * Description
  161. * Look up an element with a given *key* in the map referred to
  162. * by the file descriptor *map_fd*.
  163. *
  164. * The *flags* argument may be specified as one of the
  165. * following:
  166. *
  167. * **BPF_F_LOCK**
  168. * Look up the value of a spin-locked map without
  169. * returning the lock. This must be specified if the
  170. * elements contain a spinlock.
  171. *
  172. * Return
  173. * Returns zero on success. On error, -1 is returned and *errno*
  174. * is set appropriately.
  175. *
  176. * BPF_MAP_UPDATE_ELEM
  177. * Description
  178. * Create or update an element (key/value pair) in a specified map.
  179. *
  180. * The *flags* argument should be specified as one of the
  181. * following:
  182. *
  183. * **BPF_ANY**
  184. * Create a new element or update an existing element.
  185. * **BPF_NOEXIST**
  186. * Create a new element only if it did not exist.
  187. * **BPF_EXIST**
  188. * Update an existing element.
  189. * **BPF_F_LOCK**
  190. * Update a spin_lock-ed map element.
  191. *
  192. * Return
  193. * Returns zero on success. On error, -1 is returned and *errno*
  194. * is set appropriately.
  195. *
  196. * May set *errno* to **EINVAL**, **EPERM**, **ENOMEM**,
  197. * **E2BIG**, **EEXIST**, or **ENOENT**.
  198. *
  199. * **E2BIG**
  200. * The number of elements in the map reached the
  201. * *max_entries* limit specified at map creation time.
  202. * **EEXIST**
  203. * If *flags* specifies **BPF_NOEXIST** and the element
  204. * with *key* already exists in the map.
  205. * **ENOENT**
  206. * If *flags* specifies **BPF_EXIST** and the element with
  207. * *key* does not exist in the map.
  208. *
  209. * BPF_MAP_DELETE_ELEM
  210. * Description
  211. * Look up and delete an element by key in a specified map.
  212. *
  213. * Return
  214. * Returns zero on success. On error, -1 is returned and *errno*
  215. * is set appropriately.
  216. *
  217. * BPF_MAP_GET_NEXT_KEY
  218. * Description
  219. * Look up an element by key in a specified map and return the key
  220. * of the next element. Can be used to iterate over all elements
  221. * in the map.
  222. *
  223. * Return
  224. * Returns zero on success. On error, -1 is returned and *errno*
  225. * is set appropriately.
  226. *
  227. * The following cases can be used to iterate over all elements of
  228. * the map:
  229. *
  230. * * If *key* is not found, the operation returns zero and sets
  231. * the *next_key* pointer to the key of the first element.
  232. * * If *key* is found, the operation returns zero and sets the
  233. * *next_key* pointer to the key of the next element.
  234. * * If *key* is the last element, returns -1 and *errno* is set
  235. * to **ENOENT**.
  236. *
  237. * May set *errno* to **ENOMEM**, **EFAULT**, **EPERM**, or
  238. * **EINVAL** on error.
  239. *
  240. * BPF_PROG_LOAD
  241. * Description
  242. * Verify and load an eBPF program, returning a new file
  243. * descriptor associated with the program.
  244. *
  245. * Applying **close**\ (2) to the file descriptor returned by
  246. * **BPF_PROG_LOAD** will unload the eBPF program (but see NOTES).
  247. *
  248. * The close-on-exec file descriptor flag (see **fcntl**\ (2)) is
  249. * automatically enabled for the new file descriptor.
  250. *
  251. * Return
  252. * A new file descriptor (a nonnegative integer), or -1 if an
  253. * error occurred (in which case, *errno* is set appropriately).
  254. *
  255. * BPF_OBJ_PIN
  256. * Description
  257. * Pin an eBPF program or map referred by the specified *bpf_fd*
  258. * to the provided *pathname* on the filesystem.
  259. *
  260. * The *pathname* argument must not contain a dot (".").
  261. *
  262. * On success, *pathname* retains a reference to the eBPF object,
  263. * preventing deallocation of the object when the original
  264. * *bpf_fd* is closed. This allow the eBPF object to live beyond
  265. * **close**\ (\ *bpf_fd*\ ), and hence the lifetime of the parent
  266. * process.
  267. *
  268. * Applying **unlink**\ (2) or similar calls to the *pathname*
  269. * unpins the object from the filesystem, removing the reference.
  270. * If no other file descriptors or filesystem nodes refer to the
  271. * same object, it will be deallocated (see NOTES).
  272. *
  273. * The filesystem type for the parent directory of *pathname* must
  274. * be **BPF_FS_MAGIC**.
  275. *
  276. * Return
  277. * Returns zero on success. On error, -1 is returned and *errno*
  278. * is set appropriately.
  279. *
  280. * BPF_OBJ_GET
  281. * Description
  282. * Open a file descriptor for the eBPF object pinned to the
  283. * specified *pathname*.
  284. *
  285. * Return
  286. * A new file descriptor (a nonnegative integer), or -1 if an
  287. * error occurred (in which case, *errno* is set appropriately).
  288. *
  289. * BPF_PROG_ATTACH
  290. * Description
  291. * Attach an eBPF program to a *target_fd* at the specified
  292. * *attach_type* hook.
  293. *
  294. * The *attach_type* specifies the eBPF attachment point to
  295. * attach the program to, and must be one of *bpf_attach_type*
  296. * (see below).
  297. *
  298. * The *attach_bpf_fd* must be a valid file descriptor for a
  299. * loaded eBPF program of a cgroup, flow dissector, LIRC, sockmap
  300. * or sock_ops type corresponding to the specified *attach_type*.
  301. *
  302. * The *target_fd* must be a valid file descriptor for a kernel
  303. * object which depends on the attach type of *attach_bpf_fd*:
  304. *
  305. * **BPF_PROG_TYPE_CGROUP_DEVICE**,
  306. * **BPF_PROG_TYPE_CGROUP_SKB**,
  307. * **BPF_PROG_TYPE_CGROUP_SOCK**,
  308. * **BPF_PROG_TYPE_CGROUP_SOCK_ADDR**,
  309. * **BPF_PROG_TYPE_CGROUP_SOCKOPT**,
  310. * **BPF_PROG_TYPE_CGROUP_SYSCTL**,
  311. * **BPF_PROG_TYPE_SOCK_OPS**
  312. *
  313. * Control Group v2 hierarchy with the eBPF controller
  314. * enabled. Requires the kernel to be compiled with
  315. * **CONFIG_CGROUP_BPF**.
  316. *
  317. * **BPF_PROG_TYPE_FLOW_DISSECTOR**
  318. *
  319. * Network namespace (eg /proc/self/ns/net).
  320. *
  321. * **BPF_PROG_TYPE_LIRC_MODE2**
  322. *
  323. * LIRC device path (eg /dev/lircN). Requires the kernel
  324. * to be compiled with **CONFIG_BPF_LIRC_MODE2**.
  325. *
  326. * **BPF_PROG_TYPE_SK_SKB**,
  327. * **BPF_PROG_TYPE_SK_MSG**
  328. *
  329. * eBPF map of socket type (eg **BPF_MAP_TYPE_SOCKHASH**).
  330. *
  331. * Return
  332. * Returns zero on success. On error, -1 is returned and *errno*
  333. * is set appropriately.
  334. *
  335. * BPF_PROG_DETACH
  336. * Description
  337. * Detach the eBPF program associated with the *target_fd* at the
  338. * hook specified by *attach_type*. The program must have been
  339. * previously attached using **BPF_PROG_ATTACH**.
  340. *
  341. * Return
  342. * Returns zero on success. On error, -1 is returned and *errno*
  343. * is set appropriately.
  344. *
  345. * BPF_PROG_TEST_RUN
  346. * Description
  347. * Run the eBPF program associated with the *prog_fd* a *repeat*
  348. * number of times against a provided program context *ctx_in* and
  349. * data *data_in*, and return the modified program context
  350. * *ctx_out*, *data_out* (for example, packet data), result of the
  351. * execution *retval*, and *duration* of the test run.
  352. *
  353. * The sizes of the buffers provided as input and output
  354. * parameters *ctx_in*, *ctx_out*, *data_in*, and *data_out* must
  355. * be provided in the corresponding variables *ctx_size_in*,
  356. * *ctx_size_out*, *data_size_in*, and/or *data_size_out*. If any
  357. * of these parameters are not provided (ie set to NULL), the
  358. * corresponding size field must be zero.
  359. *
  360. * Some program types have particular requirements:
  361. *
  362. * **BPF_PROG_TYPE_SK_LOOKUP**
  363. * *data_in* and *data_out* must be NULL.
  364. *
  365. * **BPF_PROG_TYPE_RAW_TRACEPOINT**,
  366. * **BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE**
  367. *
  368. * *ctx_out*, *data_in* and *data_out* must be NULL.
  369. * *repeat* must be zero.
  370. *
  371. * BPF_PROG_RUN is an alias for BPF_PROG_TEST_RUN.
  372. *
  373. * Return
  374. * Returns zero on success. On error, -1 is returned and *errno*
  375. * is set appropriately.
  376. *
  377. * **ENOSPC**
  378. * Either *data_size_out* or *ctx_size_out* is too small.
  379. * **ENOTSUPP**
  380. * This command is not supported by the program type of
  381. * the program referred to by *prog_fd*.
  382. *
  383. * BPF_PROG_GET_NEXT_ID
  384. * Description
  385. * Fetch the next eBPF program currently loaded into the kernel.
  386. *
  387. * Looks for the eBPF program with an id greater than *start_id*
  388. * and updates *next_id* on success. If no other eBPF programs
  389. * remain with ids higher than *start_id*, returns -1 and sets
  390. * *errno* to **ENOENT**.
  391. *
  392. * Return
  393. * Returns zero on success. On error, or when no id remains, -1
  394. * is returned and *errno* is set appropriately.
  395. *
  396. * BPF_MAP_GET_NEXT_ID
  397. * Description
  398. * Fetch the next eBPF map currently loaded into the kernel.
  399. *
  400. * Looks for the eBPF map with an id greater than *start_id*
  401. * and updates *next_id* on success. If no other eBPF maps
  402. * remain with ids higher than *start_id*, returns -1 and sets
  403. * *errno* to **ENOENT**.
  404. *
  405. * Return
  406. * Returns zero on success. On error, or when no id remains, -1
  407. * is returned and *errno* is set appropriately.
  408. *
  409. * BPF_PROG_GET_FD_BY_ID
  410. * Description
  411. * Open a file descriptor for the eBPF program corresponding to
  412. * *prog_id*.
  413. *
  414. * Return
  415. * A new file descriptor (a nonnegative integer), or -1 if an
  416. * error occurred (in which case, *errno* is set appropriately).
  417. *
  418. * BPF_MAP_GET_FD_BY_ID
  419. * Description
  420. * Open a file descriptor for the eBPF map corresponding to
  421. * *map_id*.
  422. *
  423. * Return
  424. * A new file descriptor (a nonnegative integer), or -1 if an
  425. * error occurred (in which case, *errno* is set appropriately).
  426. *
  427. * BPF_OBJ_GET_INFO_BY_FD
  428. * Description
  429. * Obtain information about the eBPF object corresponding to
  430. * *bpf_fd*.
  431. *
  432. * Populates up to *info_len* bytes of *info*, which will be in
  433. * one of the following formats depending on the eBPF object type
  434. * of *bpf_fd*:
  435. *
  436. * * **struct bpf_prog_info**
  437. * * **struct bpf_map_info**
  438. * * **struct bpf_btf_info**
  439. * * **struct bpf_link_info**
  440. * * **struct bpf_token_info**
  441. *
  442. * Return
  443. * Returns zero on success. On error, -1 is returned and *errno*
  444. * is set appropriately.
  445. *
  446. * BPF_PROG_QUERY
  447. * Description
  448. * Obtain information about eBPF programs associated with the
  449. * specified *attach_type* hook.
  450. *
  451. * The *target_fd* must be a valid file descriptor for a kernel
  452. * object which depends on the attach type of *attach_bpf_fd*:
  453. *
  454. * **BPF_PROG_TYPE_CGROUP_DEVICE**,
  455. * **BPF_PROG_TYPE_CGROUP_SKB**,
  456. * **BPF_PROG_TYPE_CGROUP_SOCK**,
  457. * **BPF_PROG_TYPE_CGROUP_SOCK_ADDR**,
  458. * **BPF_PROG_TYPE_CGROUP_SOCKOPT**,
  459. * **BPF_PROG_TYPE_CGROUP_SYSCTL**,
  460. * **BPF_PROG_TYPE_SOCK_OPS**
  461. *
  462. * Control Group v2 hierarchy with the eBPF controller
  463. * enabled. Requires the kernel to be compiled with
  464. * **CONFIG_CGROUP_BPF**.
  465. *
  466. * **BPF_PROG_TYPE_FLOW_DISSECTOR**
  467. *
  468. * Network namespace (eg /proc/self/ns/net).
  469. *
  470. * **BPF_PROG_TYPE_LIRC_MODE2**
  471. *
  472. * LIRC device path (eg /dev/lircN). Requires the kernel
  473. * to be compiled with **CONFIG_BPF_LIRC_MODE2**.
  474. *
  475. * **BPF_PROG_QUERY** always fetches the number of programs
  476. * attached and the *attach_flags* which were used to attach those
  477. * programs. Additionally, if *prog_ids* is nonzero and the number
  478. * of attached programs is less than *prog_cnt*, populates
  479. * *prog_ids* with the eBPF program ids of the programs attached
  480. * at *target_fd*.
  481. *
  482. * The following flags may alter the result:
  483. *
  484. * **BPF_F_QUERY_EFFECTIVE**
  485. * Only return information regarding programs which are
  486. * currently effective at the specified *target_fd*.
  487. *
  488. * Return
  489. * Returns zero on success. On error, -1 is returned and *errno*
  490. * is set appropriately.
  491. *
  492. * BPF_RAW_TRACEPOINT_OPEN
  493. * Description
  494. * Attach an eBPF program to a tracepoint *name* to access kernel
  495. * internal arguments of the tracepoint in their raw form.
  496. *
  497. * The *prog_fd* must be a valid file descriptor associated with
  498. * a loaded eBPF program of type **BPF_PROG_TYPE_RAW_TRACEPOINT**.
  499. *
  500. * No ABI guarantees are made about the content of tracepoint
  501. * arguments exposed to the corresponding eBPF program.
  502. *
  503. * Applying **close**\ (2) to the file descriptor returned by
  504. * **BPF_RAW_TRACEPOINT_OPEN** will delete the map (but see NOTES).
  505. *
  506. * Return
  507. * A new file descriptor (a nonnegative integer), or -1 if an
  508. * error occurred (in which case, *errno* is set appropriately).
  509. *
  510. * BPF_BTF_LOAD
  511. * Description
  512. * Verify and load BPF Type Format (BTF) metadata into the kernel,
  513. * returning a new file descriptor associated with the metadata.
  514. * BTF is described in more detail at
  515. * https://www.kernel.org/doc/html/latest/bpf/btf.html.
  516. *
  517. * The *btf* parameter must point to valid memory providing
  518. * *btf_size* bytes of BTF binary metadata.
  519. *
  520. * The returned file descriptor can be passed to other **bpf**\ ()
  521. * subcommands such as **BPF_PROG_LOAD** or **BPF_MAP_CREATE** to
  522. * associate the BTF with those objects.
  523. *
  524. * Similar to **BPF_PROG_LOAD**, **BPF_BTF_LOAD** has optional
  525. * parameters to specify a *btf_log_buf*, *btf_log_size* and
  526. * *btf_log_level* which allow the kernel to return freeform log
  527. * output regarding the BTF verification process.
  528. *
  529. * Return
  530. * A new file descriptor (a nonnegative integer), or -1 if an
  531. * error occurred (in which case, *errno* is set appropriately).
  532. *
  533. * BPF_BTF_GET_FD_BY_ID
  534. * Description
  535. * Open a file descriptor for the BPF Type Format (BTF)
  536. * corresponding to *btf_id*.
  537. *
  538. * Return
  539. * A new file descriptor (a nonnegative integer), or -1 if an
  540. * error occurred (in which case, *errno* is set appropriately).
  541. *
  542. * BPF_TASK_FD_QUERY
  543. * Description
  544. * Obtain information about eBPF programs associated with the
  545. * target process identified by *pid* and *fd*.
  546. *
  547. * If the *pid* and *fd* are associated with a tracepoint, kprobe
  548. * or uprobe perf event, then the *prog_id* and *fd_type* will
  549. * be populated with the eBPF program id and file descriptor type
  550. * of type **bpf_task_fd_type**. If associated with a kprobe or
  551. * uprobe, the *probe_offset* and *probe_addr* will also be
  552. * populated. Optionally, if *buf* is provided, then up to
  553. * *buf_len* bytes of *buf* will be populated with the name of
  554. * the tracepoint, kprobe or uprobe.
  555. *
  556. * The resulting *prog_id* may be introspected in deeper detail
  557. * using **BPF_PROG_GET_FD_BY_ID** and **BPF_OBJ_GET_INFO_BY_FD**.
  558. *
  559. * Return
  560. * Returns zero on success. On error, -1 is returned and *errno*
  561. * is set appropriately.
  562. *
  563. * BPF_MAP_LOOKUP_AND_DELETE_ELEM
  564. * Description
  565. * Look up an element with the given *key* in the map referred to
  566. * by the file descriptor *fd*, and if found, delete the element.
  567. *
  568. * For **BPF_MAP_TYPE_QUEUE** and **BPF_MAP_TYPE_STACK** map
  569. * types, the *flags* argument needs to be set to 0, but for other
  570. * map types, it may be specified as:
  571. *
  572. * **BPF_F_LOCK**
  573. * Look up and delete the value of a spin-locked map
  574. * without returning the lock. This must be specified if
  575. * the elements contain a spinlock.
  576. *
  577. * The **BPF_MAP_TYPE_QUEUE** and **BPF_MAP_TYPE_STACK** map types
  578. * implement this command as a "pop" operation, deleting the top
  579. * element rather than one corresponding to *key*.
  580. * The *key* and *key_len* parameters should be zeroed when
  581. * issuing this operation for these map types.
  582. *
  583. * This command is only valid for the following map types:
  584. * * **BPF_MAP_TYPE_QUEUE**
  585. * * **BPF_MAP_TYPE_STACK**
  586. * * **BPF_MAP_TYPE_HASH**
  587. * * **BPF_MAP_TYPE_PERCPU_HASH**
  588. * * **BPF_MAP_TYPE_LRU_HASH**
  589. * * **BPF_MAP_TYPE_LRU_PERCPU_HASH**
  590. *
  591. * Return
  592. * Returns zero on success. On error, -1 is returned and *errno*
  593. * is set appropriately.
  594. *
  595. * BPF_MAP_FREEZE
  596. * Description
  597. * Freeze the permissions of the specified map.
  598. *
  599. * Write permissions may be frozen by passing zero *flags*.
  600. * Upon success, no future syscall invocations may alter the
  601. * map state of *map_fd*. Write operations from eBPF programs
  602. * are still possible for a frozen map.
  603. *
  604. * Not supported for maps of type **BPF_MAP_TYPE_STRUCT_OPS**.
  605. *
  606. * Return
  607. * Returns zero on success. On error, -1 is returned and *errno*
  608. * is set appropriately.
  609. *
  610. * BPF_BTF_GET_NEXT_ID
  611. * Description
  612. * Fetch the next BPF Type Format (BTF) object currently loaded
  613. * into the kernel.
  614. *
  615. * Looks for the BTF object with an id greater than *start_id*
  616. * and updates *next_id* on success. If no other BTF objects
  617. * remain with ids higher than *start_id*, returns -1 and sets
  618. * *errno* to **ENOENT**.
  619. *
  620. * Return
  621. * Returns zero on success. On error, or when no id remains, -1
  622. * is returned and *errno* is set appropriately.
  623. *
  624. * BPF_MAP_LOOKUP_BATCH
  625. * Description
  626. * Iterate and fetch multiple elements in a map.
  627. *
  628. * Two opaque values are used to manage batch operations,
  629. * *in_batch* and *out_batch*. Initially, *in_batch* must be set
  630. * to NULL to begin the batched operation. After each subsequent
  631. * **BPF_MAP_LOOKUP_BATCH**, the caller should pass the resultant
  632. * *out_batch* as the *in_batch* for the next operation to
  633. * continue iteration from the current point. Both *in_batch* and
  634. * *out_batch* must point to memory large enough to hold a key,
  635. * except for maps of type **BPF_MAP_TYPE_{HASH, PERCPU_HASH,
  636. * LRU_HASH, LRU_PERCPU_HASH}**, for which batch parameters
  637. * must be at least 4 bytes wide regardless of key size.
  638. *
  639. * The *keys* and *values* are output parameters which must point
  640. * to memory large enough to hold *count* items based on the key
  641. * and value size of the map *map_fd*. The *keys* buffer must be
  642. * of *key_size* * *count*. The *values* buffer must be of
  643. * *value_size* * *count*.
  644. *
  645. * The *elem_flags* argument may be specified as one of the
  646. * following:
  647. *
  648. * **BPF_F_LOCK**
  649. * Look up the value of a spin-locked map without
  650. * returning the lock. This must be specified if the
  651. * elements contain a spinlock.
  652. *
  653. * On success, *count* elements from the map are copied into the
  654. * user buffer, with the keys copied into *keys* and the values
  655. * copied into the corresponding indices in *values*.
  656. *
  657. * If an error is returned and *errno* is not **EFAULT**, *count*
  658. * is set to the number of successfully processed elements.
  659. *
  660. * Return
  661. * Returns zero on success. On error, -1 is returned and *errno*
  662. * is set appropriately.
  663. *
  664. * May set *errno* to **ENOSPC** to indicate that *keys* or
  665. * *values* is too small to dump an entire bucket during
  666. * iteration of a hash-based map type.
  667. *
  668. * BPF_MAP_LOOKUP_AND_DELETE_BATCH
  669. * Description
  670. * Iterate and delete all elements in a map.
  671. *
  672. * This operation has the same behavior as
  673. * **BPF_MAP_LOOKUP_BATCH** with two exceptions:
  674. *
  675. * * Every element that is successfully returned is also deleted
  676. * from the map. This is at least *count* elements. Note that
  677. * *count* is both an input and an output parameter.
  678. * * Upon returning with *errno* set to **EFAULT**, up to
  679. * *count* elements may be deleted without returning the keys
  680. * and values of the deleted elements.
  681. *
  682. * Return
  683. * Returns zero on success. On error, -1 is returned and *errno*
  684. * is set appropriately.
  685. *
  686. * BPF_MAP_UPDATE_BATCH
  687. * Description
  688. * Update multiple elements in a map by *key*.
  689. *
  690. * The *keys* and *values* are input parameters which must point
  691. * to memory large enough to hold *count* items based on the key
  692. * and value size of the map *map_fd*. The *keys* buffer must be
  693. * of *key_size* * *count*. The *values* buffer must be of
  694. * *value_size* * *count*.
  695. *
  696. * Each element specified in *keys* is sequentially updated to the
  697. * value in the corresponding index in *values*. The *in_batch*
  698. * and *out_batch* parameters are ignored and should be zeroed.
  699. *
  700. * The *elem_flags* argument should be specified as one of the
  701. * following:
  702. *
  703. * **BPF_ANY**
  704. * Create new elements or update a existing elements.
  705. * **BPF_NOEXIST**
  706. * Create new elements only if they do not exist.
  707. * **BPF_EXIST**
  708. * Update existing elements.
  709. * **BPF_F_LOCK**
  710. * Update spin_lock-ed map elements. This must be
  711. * specified if the map value contains a spinlock.
  712. *
  713. * On success, *count* elements from the map are updated.
  714. *
  715. * If an error is returned and *errno* is not **EFAULT**, *count*
  716. * is set to the number of successfully processed elements.
  717. *
  718. * Return
  719. * Returns zero on success. On error, -1 is returned and *errno*
  720. * is set appropriately.
  721. *
  722. * May set *errno* to **EINVAL**, **EPERM**, **ENOMEM**, or
  723. * **E2BIG**. **E2BIG** indicates that the number of elements in
  724. * the map reached the *max_entries* limit specified at map
  725. * creation time.
  726. *
  727. * May set *errno* to one of the following error codes under
  728. * specific circumstances:
  729. *
  730. * **EEXIST**
  731. * If *flags* specifies **BPF_NOEXIST** and the element
  732. * with *key* already exists in the map.
  733. * **ENOENT**
  734. * If *flags* specifies **BPF_EXIST** and the element with
  735. * *key* does not exist in the map.
  736. *
  737. * BPF_MAP_DELETE_BATCH
  738. * Description
  739. * Delete multiple elements in a map by *key*.
  740. *
  741. * The *keys* parameter is an input parameter which must point
  742. * to memory large enough to hold *count* items based on the key
  743. * size of the map *map_fd*, that is, *key_size* * *count*.
  744. *
  745. * Each element specified in *keys* is sequentially deleted. The
  746. * *in_batch*, *out_batch*, and *values* parameters are ignored
  747. * and should be zeroed.
  748. *
  749. * The *elem_flags* argument may be specified as one of the
  750. * following:
  751. *
  752. * **BPF_F_LOCK**
  753. * Look up the value of a spin-locked map without
  754. * returning the lock. This must be specified if the
  755. * elements contain a spinlock.
  756. *
  757. * On success, *count* elements from the map are updated.
  758. *
  759. * If an error is returned and *errno* is not **EFAULT**, *count*
  760. * is set to the number of successfully processed elements. If
  761. * *errno* is **EFAULT**, up to *count* elements may be been
  762. * deleted.
  763. *
  764. * Return
  765. * Returns zero on success. On error, -1 is returned and *errno*
  766. * is set appropriately.
  767. *
  768. * BPF_LINK_CREATE
  769. * Description
  770. * Attach an eBPF program to a *target_fd* at the specified
  771. * *attach_type* hook and return a file descriptor handle for
  772. * managing the link.
  773. *
  774. * Return
  775. * A new file descriptor (a nonnegative integer), or -1 if an
  776. * error occurred (in which case, *errno* is set appropriately).
  777. *
  778. * BPF_LINK_UPDATE
  779. * Description
  780. * Update the eBPF program in the specified *link_fd* to
  781. * *new_prog_fd*.
  782. *
  783. * Return
  784. * Returns zero on success. On error, -1 is returned and *errno*
  785. * is set appropriately.
  786. *
  787. * BPF_LINK_GET_FD_BY_ID
  788. * Description
  789. * Open a file descriptor for the eBPF Link corresponding to
  790. * *link_id*.
  791. *
  792. * Return
  793. * A new file descriptor (a nonnegative integer), or -1 if an
  794. * error occurred (in which case, *errno* is set appropriately).
  795. *
  796. * BPF_LINK_GET_NEXT_ID
  797. * Description
  798. * Fetch the next eBPF link currently loaded into the kernel.
  799. *
  800. * Looks for the eBPF link with an id greater than *start_id*
  801. * and updates *next_id* on success. If no other eBPF links
  802. * remain with ids higher than *start_id*, returns -1 and sets
  803. * *errno* to **ENOENT**.
  804. *
  805. * Return
  806. * Returns zero on success. On error, or when no id remains, -1
  807. * is returned and *errno* is set appropriately.
  808. *
  809. * BPF_ENABLE_STATS
  810. * Description
  811. * Enable eBPF runtime statistics gathering.
  812. *
  813. * Runtime statistics gathering for the eBPF runtime is disabled
  814. * by default to minimize the corresponding performance overhead.
  815. * This command enables statistics globally.
  816. *
  817. * Multiple programs may independently enable statistics.
  818. * After gathering the desired statistics, eBPF runtime statistics
  819. * may be disabled again by calling **close**\ (2) for the file
  820. * descriptor returned by this function. Statistics will only be
  821. * disabled system-wide when all outstanding file descriptors
  822. * returned by prior calls for this subcommand are closed.
  823. *
  824. * Return
  825. * A new file descriptor (a nonnegative integer), or -1 if an
  826. * error occurred (in which case, *errno* is set appropriately).
  827. *
  828. * BPF_ITER_CREATE
  829. * Description
  830. * Create an iterator on top of the specified *link_fd* (as
  831. * previously created using **BPF_LINK_CREATE**) and return a
  832. * file descriptor that can be used to trigger the iteration.
  833. *
  834. * If the resulting file descriptor is pinned to the filesystem
  835. * using **BPF_OBJ_PIN**, then subsequent **read**\ (2) syscalls
  836. * for that path will trigger the iterator to read kernel state
  837. * using the eBPF program attached to *link_fd*.
  838. *
  839. * Return
  840. * A new file descriptor (a nonnegative integer), or -1 if an
  841. * error occurred (in which case, *errno* is set appropriately).
  842. *
  843. * BPF_LINK_DETACH
  844. * Description
  845. * Forcefully detach the specified *link_fd* from its
  846. * corresponding attachment point.
  847. *
  848. * Return
  849. * Returns zero on success. On error, -1 is returned and *errno*
  850. * is set appropriately.
  851. *
  852. * BPF_PROG_BIND_MAP
  853. * Description
  854. * Bind a map to the lifetime of an eBPF program.
  855. *
  856. * The map identified by *map_fd* is bound to the program
  857. * identified by *prog_fd* and only released when *prog_fd* is
  858. * released. This may be used in cases where metadata should be
  859. * associated with a program which otherwise does not contain any
  860. * references to the map (for example, embedded in the eBPF
  861. * program instructions).
  862. *
  863. * Return
  864. * Returns zero on success. On error, -1 is returned and *errno*
  865. * is set appropriately.
  866. *
  867. * BPF_TOKEN_CREATE
  868. * Description
  869. * Create BPF token with embedded information about what
  870. * BPF-related functionality it allows:
  871. * - a set of allowed bpf() syscall commands;
  872. * - a set of allowed BPF map types to be created with
  873. * BPF_MAP_CREATE command, if BPF_MAP_CREATE itself is allowed;
  874. * - a set of allowed BPF program types and BPF program attach
  875. * types to be loaded with BPF_PROG_LOAD command, if
  876. * BPF_PROG_LOAD itself is allowed.
  877. *
  878. * BPF token is created (derived) from an instance of BPF FS,
  879. * assuming it has necessary delegation mount options specified.
  880. * This BPF token can be passed as an extra parameter to various
  881. * bpf() syscall commands to grant BPF subsystem functionality to
  882. * unprivileged processes.
  883. *
  884. * When created, BPF token is "associated" with the owning
  885. * user namespace of BPF FS instance (super block) that it was
  886. * derived from, and subsequent BPF operations performed with
  887. * BPF token would be performing capabilities checks (i.e.,
  888. * CAP_BPF, CAP_PERFMON, CAP_NET_ADMIN, CAP_SYS_ADMIN) within
  889. * that user namespace. Without BPF token, such capabilities
  890. * have to be granted in init user namespace, making bpf()
  891. * syscall incompatible with user namespace, for the most part.
  892. *
  893. * Return
  894. * A new file descriptor (a nonnegative integer), or -1 if an
  895. * error occurred (in which case, *errno* is set appropriately).
  896. *
  897. * BPF_PROG_STREAM_READ_BY_FD
  898. * Description
  899. * Read data of a program's BPF stream. The program is identified
  900. * by *prog_fd*, and the stream is identified by the *stream_id*.
  901. * The data is copied to a buffer pointed to by *stream_buf*, and
  902. * filled less than or equal to *stream_buf_len* bytes.
  903. *
  904. * Return
  905. * Number of bytes read from the stream on success, or -1 if an
  906. * error occurred (in which case, *errno* is set appropriately).
  907. *
  908. * BPF_PROG_ASSOC_STRUCT_OPS
  909. * Description
  910. * Associate a BPF program with a struct_ops map. The struct_ops
  911. * map is identified by *map_fd* and the BPF program is
  912. * identified by *prog_fd*.
  913. *
  914. * Return
  915. * 0 on success or -1 if an error occurred (in which case,
  916. * *errno* is set appropriately).
  917. *
  918. * NOTES
  919. * eBPF objects (maps and programs) can be shared between processes.
  920. *
  921. * * After **fork**\ (2), the child inherits file descriptors
  922. * referring to the same eBPF objects.
  923. * * File descriptors referring to eBPF objects can be transferred over
  924. * **unix**\ (7) domain sockets.
  925. * * File descriptors referring to eBPF objects can be duplicated in the
  926. * usual way, using **dup**\ (2) and similar calls.
  927. * * File descriptors referring to eBPF objects can be pinned to the
  928. * filesystem using the **BPF_OBJ_PIN** command of **bpf**\ (2).
  929. *
  930. * An eBPF object is deallocated only after all file descriptors referring
  931. * to the object have been closed and no references remain pinned to the
  932. * filesystem or attached (for example, bound to a program or device).
  933. */
  934. enum bpf_cmd {
  935. BPF_MAP_CREATE,
  936. BPF_MAP_LOOKUP_ELEM,
  937. BPF_MAP_UPDATE_ELEM,
  938. BPF_MAP_DELETE_ELEM,
  939. BPF_MAP_GET_NEXT_KEY,
  940. BPF_PROG_LOAD,
  941. BPF_OBJ_PIN,
  942. BPF_OBJ_GET,
  943. BPF_PROG_ATTACH,
  944. BPF_PROG_DETACH,
  945. BPF_PROG_TEST_RUN,
  946. BPF_PROG_RUN = BPF_PROG_TEST_RUN,
  947. BPF_PROG_GET_NEXT_ID,
  948. BPF_MAP_GET_NEXT_ID,
  949. BPF_PROG_GET_FD_BY_ID,
  950. BPF_MAP_GET_FD_BY_ID,
  951. BPF_OBJ_GET_INFO_BY_FD,
  952. BPF_PROG_QUERY,
  953. BPF_RAW_TRACEPOINT_OPEN,
  954. BPF_BTF_LOAD,
  955. BPF_BTF_GET_FD_BY_ID,
  956. BPF_TASK_FD_QUERY,
  957. BPF_MAP_LOOKUP_AND_DELETE_ELEM,
  958. BPF_MAP_FREEZE,
  959. BPF_BTF_GET_NEXT_ID,
  960. BPF_MAP_LOOKUP_BATCH,
  961. BPF_MAP_LOOKUP_AND_DELETE_BATCH,
  962. BPF_MAP_UPDATE_BATCH,
  963. BPF_MAP_DELETE_BATCH,
  964. BPF_LINK_CREATE,
  965. BPF_LINK_UPDATE,
  966. BPF_LINK_GET_FD_BY_ID,
  967. BPF_LINK_GET_NEXT_ID,
  968. BPF_ENABLE_STATS,
  969. BPF_ITER_CREATE,
  970. BPF_LINK_DETACH,
  971. BPF_PROG_BIND_MAP,
  972. BPF_TOKEN_CREATE,
  973. BPF_PROG_STREAM_READ_BY_FD,
  974. BPF_PROG_ASSOC_STRUCT_OPS,
  975. __MAX_BPF_CMD,
  976. };
  977. enum bpf_map_type {
  978. BPF_MAP_TYPE_UNSPEC,
  979. BPF_MAP_TYPE_HASH,
  980. BPF_MAP_TYPE_ARRAY,
  981. BPF_MAP_TYPE_PROG_ARRAY,
  982. BPF_MAP_TYPE_PERF_EVENT_ARRAY,
  983. BPF_MAP_TYPE_PERCPU_HASH,
  984. BPF_MAP_TYPE_PERCPU_ARRAY,
  985. BPF_MAP_TYPE_STACK_TRACE,
  986. BPF_MAP_TYPE_CGROUP_ARRAY,
  987. BPF_MAP_TYPE_LRU_HASH,
  988. BPF_MAP_TYPE_LRU_PERCPU_HASH,
  989. BPF_MAP_TYPE_LPM_TRIE,
  990. BPF_MAP_TYPE_ARRAY_OF_MAPS,
  991. BPF_MAP_TYPE_HASH_OF_MAPS,
  992. BPF_MAP_TYPE_DEVMAP,
  993. BPF_MAP_TYPE_SOCKMAP,
  994. BPF_MAP_TYPE_CPUMAP,
  995. BPF_MAP_TYPE_XSKMAP,
  996. BPF_MAP_TYPE_SOCKHASH,
  997. BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED,
  998. /* BPF_MAP_TYPE_CGROUP_STORAGE is available to bpf programs attaching
  999. * to a cgroup. The newer BPF_MAP_TYPE_CGRP_STORAGE is available to
  1000. * both cgroup-attached and other progs and supports all functionality
  1001. * provided by BPF_MAP_TYPE_CGROUP_STORAGE. So mark
  1002. * BPF_MAP_TYPE_CGROUP_STORAGE deprecated.
  1003. */
  1004. BPF_MAP_TYPE_CGROUP_STORAGE = BPF_MAP_TYPE_CGROUP_STORAGE_DEPRECATED,
  1005. BPF_MAP_TYPE_REUSEPORT_SOCKARRAY,
  1006. BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE_DEPRECATED,
  1007. /* BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE is available to bpf programs
  1008. * attaching to a cgroup. The new mechanism (BPF_MAP_TYPE_CGRP_STORAGE +
  1009. * local percpu kptr) supports all BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE
  1010. * functionality and more. So mark * BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE
  1011. * deprecated.
  1012. */
  1013. BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE = BPF_MAP_TYPE_PERCPU_CGROUP_STORAGE_DEPRECATED,
  1014. BPF_MAP_TYPE_QUEUE,
  1015. BPF_MAP_TYPE_STACK,
  1016. BPF_MAP_TYPE_SK_STORAGE,
  1017. BPF_MAP_TYPE_DEVMAP_HASH,
  1018. BPF_MAP_TYPE_STRUCT_OPS,
  1019. BPF_MAP_TYPE_RINGBUF,
  1020. BPF_MAP_TYPE_INODE_STORAGE,
  1021. BPF_MAP_TYPE_TASK_STORAGE,
  1022. BPF_MAP_TYPE_BLOOM_FILTER,
  1023. BPF_MAP_TYPE_USER_RINGBUF,
  1024. BPF_MAP_TYPE_CGRP_STORAGE,
  1025. BPF_MAP_TYPE_ARENA,
  1026. BPF_MAP_TYPE_INSN_ARRAY,
  1027. __MAX_BPF_MAP_TYPE
  1028. };
  1029. /* Note that tracing related programs such as
  1030. * BPF_PROG_TYPE_{KPROBE,TRACEPOINT,PERF_EVENT,RAW_TRACEPOINT}
  1031. * are not subject to a stable API since kernel internal data
  1032. * structures can change from release to release and may
  1033. * therefore break existing tracing BPF programs. Tracing BPF
  1034. * programs correspond to /a/ specific kernel which is to be
  1035. * analyzed, and not /a/ specific kernel /and/ all future ones.
  1036. */
  1037. enum bpf_prog_type {
  1038. BPF_PROG_TYPE_UNSPEC,
  1039. BPF_PROG_TYPE_SOCKET_FILTER,
  1040. BPF_PROG_TYPE_KPROBE,
  1041. BPF_PROG_TYPE_SCHED_CLS,
  1042. BPF_PROG_TYPE_SCHED_ACT,
  1043. BPF_PROG_TYPE_TRACEPOINT,
  1044. BPF_PROG_TYPE_XDP,
  1045. BPF_PROG_TYPE_PERF_EVENT,
  1046. BPF_PROG_TYPE_CGROUP_SKB,
  1047. BPF_PROG_TYPE_CGROUP_SOCK,
  1048. BPF_PROG_TYPE_LWT_IN,
  1049. BPF_PROG_TYPE_LWT_OUT,
  1050. BPF_PROG_TYPE_LWT_XMIT,
  1051. BPF_PROG_TYPE_SOCK_OPS,
  1052. BPF_PROG_TYPE_SK_SKB,
  1053. BPF_PROG_TYPE_CGROUP_DEVICE,
  1054. BPF_PROG_TYPE_SK_MSG,
  1055. BPF_PROG_TYPE_RAW_TRACEPOINT,
  1056. BPF_PROG_TYPE_CGROUP_SOCK_ADDR,
  1057. BPF_PROG_TYPE_LWT_SEG6LOCAL,
  1058. BPF_PROG_TYPE_LIRC_MODE2,
  1059. BPF_PROG_TYPE_SK_REUSEPORT,
  1060. BPF_PROG_TYPE_FLOW_DISSECTOR,
  1061. BPF_PROG_TYPE_CGROUP_SYSCTL,
  1062. BPF_PROG_TYPE_RAW_TRACEPOINT_WRITABLE,
  1063. BPF_PROG_TYPE_CGROUP_SOCKOPT,
  1064. BPF_PROG_TYPE_TRACING,
  1065. BPF_PROG_TYPE_STRUCT_OPS,
  1066. BPF_PROG_TYPE_EXT,
  1067. BPF_PROG_TYPE_LSM,
  1068. BPF_PROG_TYPE_SK_LOOKUP,
  1069. BPF_PROG_TYPE_SYSCALL, /* a program that can execute syscalls */
  1070. BPF_PROG_TYPE_NETFILTER,
  1071. __MAX_BPF_PROG_TYPE
  1072. };
  1073. enum bpf_attach_type {
  1074. BPF_CGROUP_INET_INGRESS,
  1075. BPF_CGROUP_INET_EGRESS,
  1076. BPF_CGROUP_INET_SOCK_CREATE,
  1077. BPF_CGROUP_SOCK_OPS,
  1078. BPF_SK_SKB_STREAM_PARSER,
  1079. BPF_SK_SKB_STREAM_VERDICT,
  1080. BPF_CGROUP_DEVICE,
  1081. BPF_SK_MSG_VERDICT,
  1082. BPF_CGROUP_INET4_BIND,
  1083. BPF_CGROUP_INET6_BIND,
  1084. BPF_CGROUP_INET4_CONNECT,
  1085. BPF_CGROUP_INET6_CONNECT,
  1086. BPF_CGROUP_INET4_POST_BIND,
  1087. BPF_CGROUP_INET6_POST_BIND,
  1088. BPF_CGROUP_UDP4_SENDMSG,
  1089. BPF_CGROUP_UDP6_SENDMSG,
  1090. BPF_LIRC_MODE2,
  1091. BPF_FLOW_DISSECTOR,
  1092. BPF_CGROUP_SYSCTL,
  1093. BPF_CGROUP_UDP4_RECVMSG,
  1094. BPF_CGROUP_UDP6_RECVMSG,
  1095. BPF_CGROUP_GETSOCKOPT,
  1096. BPF_CGROUP_SETSOCKOPT,
  1097. BPF_TRACE_RAW_TP,
  1098. BPF_TRACE_FENTRY,
  1099. BPF_TRACE_FEXIT,
  1100. BPF_MODIFY_RETURN,
  1101. BPF_LSM_MAC,
  1102. BPF_TRACE_ITER,
  1103. BPF_CGROUP_INET4_GETPEERNAME,
  1104. BPF_CGROUP_INET6_GETPEERNAME,
  1105. BPF_CGROUP_INET4_GETSOCKNAME,
  1106. BPF_CGROUP_INET6_GETSOCKNAME,
  1107. BPF_XDP_DEVMAP,
  1108. BPF_CGROUP_INET_SOCK_RELEASE,
  1109. BPF_XDP_CPUMAP,
  1110. BPF_SK_LOOKUP,
  1111. BPF_XDP,
  1112. BPF_SK_SKB_VERDICT,
  1113. BPF_SK_REUSEPORT_SELECT,
  1114. BPF_SK_REUSEPORT_SELECT_OR_MIGRATE,
  1115. BPF_PERF_EVENT,
  1116. BPF_TRACE_KPROBE_MULTI,
  1117. BPF_LSM_CGROUP,
  1118. BPF_STRUCT_OPS,
  1119. BPF_NETFILTER,
  1120. BPF_TCX_INGRESS,
  1121. BPF_TCX_EGRESS,
  1122. BPF_TRACE_UPROBE_MULTI,
  1123. BPF_CGROUP_UNIX_CONNECT,
  1124. BPF_CGROUP_UNIX_SENDMSG,
  1125. BPF_CGROUP_UNIX_RECVMSG,
  1126. BPF_CGROUP_UNIX_GETPEERNAME,
  1127. BPF_CGROUP_UNIX_GETSOCKNAME,
  1128. BPF_NETKIT_PRIMARY,
  1129. BPF_NETKIT_PEER,
  1130. BPF_TRACE_KPROBE_SESSION,
  1131. BPF_TRACE_UPROBE_SESSION,
  1132. BPF_TRACE_FSESSION,
  1133. __MAX_BPF_ATTACH_TYPE
  1134. };
  1135. #define MAX_BPF_ATTACH_TYPE __MAX_BPF_ATTACH_TYPE
  1136. /* Add BPF_LINK_TYPE(type, name) in bpf_types.h to keep bpf_link_type_strs[]
  1137. * in sync with the definitions below.
  1138. */
  1139. enum bpf_link_type {
  1140. BPF_LINK_TYPE_UNSPEC = 0,
  1141. BPF_LINK_TYPE_RAW_TRACEPOINT = 1,
  1142. BPF_LINK_TYPE_TRACING = 2,
  1143. BPF_LINK_TYPE_CGROUP = 3,
  1144. BPF_LINK_TYPE_ITER = 4,
  1145. BPF_LINK_TYPE_NETNS = 5,
  1146. BPF_LINK_TYPE_XDP = 6,
  1147. BPF_LINK_TYPE_PERF_EVENT = 7,
  1148. BPF_LINK_TYPE_KPROBE_MULTI = 8,
  1149. BPF_LINK_TYPE_STRUCT_OPS = 9,
  1150. BPF_LINK_TYPE_NETFILTER = 10,
  1151. BPF_LINK_TYPE_TCX = 11,
  1152. BPF_LINK_TYPE_UPROBE_MULTI = 12,
  1153. BPF_LINK_TYPE_NETKIT = 13,
  1154. BPF_LINK_TYPE_SOCKMAP = 14,
  1155. __MAX_BPF_LINK_TYPE,
  1156. };
  1157. #define MAX_BPF_LINK_TYPE __MAX_BPF_LINK_TYPE
  1158. enum bpf_perf_event_type {
  1159. BPF_PERF_EVENT_UNSPEC = 0,
  1160. BPF_PERF_EVENT_UPROBE = 1,
  1161. BPF_PERF_EVENT_URETPROBE = 2,
  1162. BPF_PERF_EVENT_KPROBE = 3,
  1163. BPF_PERF_EVENT_KRETPROBE = 4,
  1164. BPF_PERF_EVENT_TRACEPOINT = 5,
  1165. BPF_PERF_EVENT_EVENT = 6,
  1166. };
  1167. /* cgroup-bpf attach flags used in BPF_PROG_ATTACH command
  1168. *
  1169. * NONE(default): No further bpf programs allowed in the subtree.
  1170. *
  1171. * BPF_F_ALLOW_OVERRIDE: If a sub-cgroup installs some bpf program,
  1172. * the program in this cgroup yields to sub-cgroup program.
  1173. *
  1174. * BPF_F_ALLOW_MULTI: If a sub-cgroup installs some bpf program,
  1175. * that cgroup program gets run in addition to the program in this cgroup.
  1176. *
  1177. * Only one program is allowed to be attached to a cgroup with
  1178. * NONE or BPF_F_ALLOW_OVERRIDE flag.
  1179. * Attaching another program on top of NONE or BPF_F_ALLOW_OVERRIDE will
  1180. * release old program and attach the new one. Attach flags has to match.
  1181. *
  1182. * Multiple programs are allowed to be attached to a cgroup with
  1183. * BPF_F_ALLOW_MULTI flag. They are executed in FIFO order
  1184. * (those that were attached first, run first)
  1185. * The programs of sub-cgroup are executed first, then programs of
  1186. * this cgroup and then programs of parent cgroup.
  1187. * When children program makes decision (like picking TCP CA or sock bind)
  1188. * parent program has a chance to override it.
  1189. *
  1190. * With BPF_F_ALLOW_MULTI a new program is added to the end of the list of
  1191. * programs for a cgroup. Though it's possible to replace an old program at
  1192. * any position by also specifying BPF_F_REPLACE flag and position itself in
  1193. * replace_bpf_fd attribute. Old program at this position will be released.
  1194. *
  1195. * A cgroup with MULTI or OVERRIDE flag allows any attach flags in sub-cgroups.
  1196. * A cgroup with NONE doesn't allow any programs in sub-cgroups.
  1197. * Ex1:
  1198. * cgrp1 (MULTI progs A, B) ->
  1199. * cgrp2 (OVERRIDE prog C) ->
  1200. * cgrp3 (MULTI prog D) ->
  1201. * cgrp4 (OVERRIDE prog E) ->
  1202. * cgrp5 (NONE prog F)
  1203. * the event in cgrp5 triggers execution of F,D,A,B in that order.
  1204. * if prog F is detached, the execution is E,D,A,B
  1205. * if prog F and D are detached, the execution is E,A,B
  1206. * if prog F, E and D are detached, the execution is C,A,B
  1207. *
  1208. * All eligible programs are executed regardless of return code from
  1209. * earlier programs.
  1210. */
  1211. #define BPF_F_ALLOW_OVERRIDE (1U << 0)
  1212. #define BPF_F_ALLOW_MULTI (1U << 1)
  1213. /* Generic attachment flags. */
  1214. #define BPF_F_REPLACE (1U << 2)
  1215. #define BPF_F_BEFORE (1U << 3)
  1216. #define BPF_F_AFTER (1U << 4)
  1217. #define BPF_F_ID (1U << 5)
  1218. #define BPF_F_PREORDER (1U << 6)
  1219. #define BPF_F_LINK BPF_F_LINK /* 1 << 13 */
  1220. /* If BPF_F_STRICT_ALIGNMENT is used in BPF_PROG_LOAD command, the
  1221. * verifier will perform strict alignment checking as if the kernel
  1222. * has been built with CONFIG_EFFICIENT_UNALIGNED_ACCESS not set,
  1223. * and NET_IP_ALIGN defined to 2.
  1224. */
  1225. #define BPF_F_STRICT_ALIGNMENT (1U << 0)
  1226. /* If BPF_F_ANY_ALIGNMENT is used in BPF_PROG_LOAD command, the
  1227. * verifier will allow any alignment whatsoever. On platforms
  1228. * with strict alignment requirements for loads ands stores (such
  1229. * as sparc and mips) the verifier validates that all loads and
  1230. * stores provably follow this requirement. This flag turns that
  1231. * checking and enforcement off.
  1232. *
  1233. * It is mostly used for testing when we want to validate the
  1234. * context and memory access aspects of the verifier, but because
  1235. * of an unaligned access the alignment check would trigger before
  1236. * the one we are interested in.
  1237. */
  1238. #define BPF_F_ANY_ALIGNMENT (1U << 1)
  1239. /* BPF_F_TEST_RND_HI32 is used in BPF_PROG_LOAD command for testing purpose.
  1240. * Verifier does sub-register def/use analysis and identifies instructions whose
  1241. * def only matters for low 32-bit, high 32-bit is never referenced later
  1242. * through implicit zero extension. Therefore verifier notifies JIT back-ends
  1243. * that it is safe to ignore clearing high 32-bit for these instructions. This
  1244. * saves some back-ends a lot of code-gen. However such optimization is not
  1245. * necessary on some arches, for example x86_64, arm64 etc, whose JIT back-ends
  1246. * hence hasn't used verifier's analysis result. But, we really want to have a
  1247. * way to be able to verify the correctness of the described optimization on
  1248. * x86_64 on which testsuites are frequently exercised.
  1249. *
  1250. * So, this flag is introduced. Once it is set, verifier will randomize high
  1251. * 32-bit for those instructions who has been identified as safe to ignore them.
  1252. * Then, if verifier is not doing correct analysis, such randomization will
  1253. * regress tests to expose bugs.
  1254. */
  1255. #define BPF_F_TEST_RND_HI32 (1U << 2)
  1256. /* The verifier internal test flag. Behavior is undefined */
  1257. #define BPF_F_TEST_STATE_FREQ (1U << 3)
  1258. /* If BPF_F_SLEEPABLE is used in BPF_PROG_LOAD command, the verifier will
  1259. * restrict map and helper usage for such programs. Sleepable BPF programs can
  1260. * only be attached to hooks where kernel execution context allows sleeping.
  1261. * Such programs are allowed to use helpers that may sleep like
  1262. * bpf_copy_from_user().
  1263. */
  1264. #define BPF_F_SLEEPABLE (1U << 4)
  1265. /* If BPF_F_XDP_HAS_FRAGS is used in BPF_PROG_LOAD command, the loaded program
  1266. * fully support xdp frags.
  1267. */
  1268. #define BPF_F_XDP_HAS_FRAGS (1U << 5)
  1269. /* If BPF_F_XDP_DEV_BOUND_ONLY is used in BPF_PROG_LOAD command, the loaded
  1270. * program becomes device-bound but can access XDP metadata.
  1271. */
  1272. #define BPF_F_XDP_DEV_BOUND_ONLY (1U << 6)
  1273. /* The verifier internal test flag. Behavior is undefined */
  1274. #define BPF_F_TEST_REG_INVARIANTS (1U << 7)
  1275. /* link_create.kprobe_multi.flags used in LINK_CREATE command for
  1276. * BPF_TRACE_KPROBE_MULTI attach type to create return probe.
  1277. */
  1278. enum {
  1279. BPF_F_KPROBE_MULTI_RETURN = (1U << 0)
  1280. };
  1281. /* link_create.uprobe_multi.flags used in LINK_CREATE command for
  1282. * BPF_TRACE_UPROBE_MULTI attach type to create return probe.
  1283. */
  1284. enum {
  1285. BPF_F_UPROBE_MULTI_RETURN = (1U << 0)
  1286. };
  1287. /* link_create.netfilter.flags used in LINK_CREATE command for
  1288. * BPF_PROG_TYPE_NETFILTER to enable IP packet defragmentation.
  1289. */
  1290. #define BPF_F_NETFILTER_IP_DEFRAG (1U << 0)
  1291. /* When BPF ldimm64's insn[0].src_reg != 0 then this can have
  1292. * the following extensions:
  1293. *
  1294. * insn[0].src_reg: BPF_PSEUDO_MAP_[FD|IDX]
  1295. * insn[0].imm: map fd or fd_idx
  1296. * insn[1].imm: 0
  1297. * insn[0].off: 0
  1298. * insn[1].off: 0
  1299. * ldimm64 rewrite: address of map
  1300. * verifier type: CONST_PTR_TO_MAP
  1301. */
  1302. #define BPF_PSEUDO_MAP_FD 1
  1303. #define BPF_PSEUDO_MAP_IDX 5
  1304. /* insn[0].src_reg: BPF_PSEUDO_MAP_[IDX_]VALUE
  1305. * insn[0].imm: map fd or fd_idx
  1306. * insn[1].imm: offset into value
  1307. * insn[0].off: 0
  1308. * insn[1].off: 0
  1309. * ldimm64 rewrite: address of map[0]+offset
  1310. * verifier type: PTR_TO_MAP_VALUE
  1311. */
  1312. #define BPF_PSEUDO_MAP_VALUE 2
  1313. #define BPF_PSEUDO_MAP_IDX_VALUE 6
  1314. /* insn[0].src_reg: BPF_PSEUDO_BTF_ID
  1315. * insn[0].imm: kernel btd id of VAR
  1316. * insn[1].imm: 0
  1317. * insn[0].off: 0
  1318. * insn[1].off: 0
  1319. * ldimm64 rewrite: address of the kernel variable
  1320. * verifier type: PTR_TO_BTF_ID or PTR_TO_MEM, depending on whether the var
  1321. * is struct/union.
  1322. */
  1323. #define BPF_PSEUDO_BTF_ID 3
  1324. /* insn[0].src_reg: BPF_PSEUDO_FUNC
  1325. * insn[0].imm: insn offset to the func
  1326. * insn[1].imm: 0
  1327. * insn[0].off: 0
  1328. * insn[1].off: 0
  1329. * ldimm64 rewrite: address of the function
  1330. * verifier type: PTR_TO_FUNC.
  1331. */
  1332. #define BPF_PSEUDO_FUNC 4
  1333. /* when bpf_call->src_reg == BPF_PSEUDO_CALL, bpf_call->imm == pc-relative
  1334. * offset to another bpf function
  1335. */
  1336. #define BPF_PSEUDO_CALL 1
  1337. /* when bpf_call->src_reg == BPF_PSEUDO_KFUNC_CALL,
  1338. * bpf_call->imm == btf_id of a BTF_KIND_FUNC in the running kernel
  1339. */
  1340. #define BPF_PSEUDO_KFUNC_CALL 2
  1341. enum bpf_addr_space_cast {
  1342. BPF_ADDR_SPACE_CAST = 1,
  1343. };
  1344. /* flags for BPF_MAP_UPDATE_ELEM command */
  1345. enum {
  1346. BPF_ANY = 0, /* create new element or update existing */
  1347. BPF_NOEXIST = 1, /* create new element if it didn't exist */
  1348. BPF_EXIST = 2, /* update existing element */
  1349. BPF_F_LOCK = 4, /* spin_lock-ed map_lookup/map_update */
  1350. BPF_F_CPU = 8, /* cpu flag for percpu maps, upper 32-bit of flags is a cpu number */
  1351. BPF_F_ALL_CPUS = 16, /* update value across all CPUs for percpu maps */
  1352. };
  1353. /* flags for BPF_MAP_CREATE command */
  1354. enum {
  1355. BPF_F_NO_PREALLOC = (1U << 0),
  1356. /* Instead of having one common LRU list in the
  1357. * BPF_MAP_TYPE_LRU_[PERCPU_]HASH map, use a percpu LRU list
  1358. * which can scale and perform better.
  1359. * Note, the LRU nodes (including free nodes) cannot be moved
  1360. * across different LRU lists.
  1361. */
  1362. BPF_F_NO_COMMON_LRU = (1U << 1),
  1363. /* Specify numa node during map creation */
  1364. BPF_F_NUMA_NODE = (1U << 2),
  1365. /* Flags for accessing BPF object from syscall side. */
  1366. BPF_F_RDONLY = (1U << 3),
  1367. BPF_F_WRONLY = (1U << 4),
  1368. /* Flag for stack_map, store build_id+offset instead of pointer */
  1369. BPF_F_STACK_BUILD_ID = (1U << 5),
  1370. /* Zero-initialize hash function seed. This should only be used for testing. */
  1371. BPF_F_ZERO_SEED = (1U << 6),
  1372. /* Flags for accessing BPF object from program side. */
  1373. BPF_F_RDONLY_PROG = (1U << 7),
  1374. BPF_F_WRONLY_PROG = (1U << 8),
  1375. /* Clone map from listener for newly accepted socket */
  1376. BPF_F_CLONE = (1U << 9),
  1377. /* Enable memory-mapping BPF map */
  1378. BPF_F_MMAPABLE = (1U << 10),
  1379. /* Share perf_event among processes */
  1380. BPF_F_PRESERVE_ELEMS = (1U << 11),
  1381. /* Create a map that is suitable to be an inner map with dynamic max entries */
  1382. BPF_F_INNER_MAP = (1U << 12),
  1383. /* Create a map that will be registered/unregesitered by the backed bpf_link */
  1384. BPF_F_LINK = (1U << 13),
  1385. /* Get path from provided FD in BPF_OBJ_PIN/BPF_OBJ_GET commands */
  1386. BPF_F_PATH_FD = (1U << 14),
  1387. /* Flag for value_type_btf_obj_fd, the fd is available */
  1388. BPF_F_VTYPE_BTF_OBJ_FD = (1U << 15),
  1389. /* BPF token FD is passed in a corresponding command's token_fd field */
  1390. BPF_F_TOKEN_FD = (1U << 16),
  1391. /* When user space page faults in bpf_arena send SIGSEGV instead of inserting new page */
  1392. BPF_F_SEGV_ON_FAULT = (1U << 17),
  1393. /* Do not translate kernel bpf_arena pointers to user pointers */
  1394. BPF_F_NO_USER_CONV = (1U << 18),
  1395. /* Enable BPF ringbuf overwrite mode */
  1396. BPF_F_RB_OVERWRITE = (1U << 19),
  1397. };
  1398. /* Flags for BPF_PROG_QUERY. */
  1399. /* Query effective (directly attached + inherited from ancestor cgroups)
  1400. * programs that will be executed for events within a cgroup.
  1401. * attach_flags with this flag are always returned 0.
  1402. */
  1403. #define BPF_F_QUERY_EFFECTIVE (1U << 0)
  1404. /* Flags for BPF_PROG_TEST_RUN */
  1405. /* If set, run the test on the cpu specified by bpf_attr.test.cpu */
  1406. #define BPF_F_TEST_RUN_ON_CPU (1U << 0)
  1407. /* If set, XDP frames will be transmitted after processing */
  1408. #define BPF_F_TEST_XDP_LIVE_FRAMES (1U << 1)
  1409. /* If set, apply CHECKSUM_COMPLETE to skb and validate the checksum */
  1410. #define BPF_F_TEST_SKB_CHECKSUM_COMPLETE (1U << 2)
  1411. /* type for BPF_ENABLE_STATS */
  1412. enum bpf_stats_type {
  1413. /* enabled run_time_ns and run_cnt */
  1414. BPF_STATS_RUN_TIME = 0,
  1415. };
  1416. enum bpf_stack_build_id_status {
  1417. /* user space need an empty entry to identify end of a trace */
  1418. BPF_STACK_BUILD_ID_EMPTY = 0,
  1419. /* with valid build_id and offset */
  1420. BPF_STACK_BUILD_ID_VALID = 1,
  1421. /* couldn't get build_id, fallback to ip */
  1422. BPF_STACK_BUILD_ID_IP = 2,
  1423. };
  1424. #define BPF_BUILD_ID_SIZE 20
  1425. struct bpf_stack_build_id {
  1426. __s32 status;
  1427. unsigned char build_id[BPF_BUILD_ID_SIZE];
  1428. union {
  1429. __u64 offset;
  1430. __u64 ip;
  1431. };
  1432. };
  1433. #define BPF_OBJ_NAME_LEN 16U
  1434. enum {
  1435. BPF_STREAM_STDOUT = 1,
  1436. BPF_STREAM_STDERR = 2,
  1437. };
  1438. union bpf_attr {
  1439. struct { /* anonymous struct used by BPF_MAP_CREATE command */
  1440. __u32 map_type; /* one of enum bpf_map_type */
  1441. __u32 key_size; /* size of key in bytes */
  1442. __u32 value_size; /* size of value in bytes */
  1443. __u32 max_entries; /* max number of entries in a map */
  1444. __u32 map_flags; /* BPF_MAP_CREATE related
  1445. * flags defined above.
  1446. */
  1447. __u32 inner_map_fd; /* fd pointing to the inner map */
  1448. __u32 numa_node; /* numa node (effective only if
  1449. * BPF_F_NUMA_NODE is set).
  1450. */
  1451. char map_name[BPF_OBJ_NAME_LEN];
  1452. __u32 map_ifindex; /* ifindex of netdev to create on */
  1453. __u32 btf_fd; /* fd pointing to a BTF type data */
  1454. __u32 btf_key_type_id; /* BTF type_id of the key */
  1455. __u32 btf_value_type_id; /* BTF type_id of the value */
  1456. __u32 btf_vmlinux_value_type_id;/* BTF type_id of a kernel-
  1457. * struct stored as the
  1458. * map value
  1459. */
  1460. /* Any per-map-type extra fields
  1461. *
  1462. * BPF_MAP_TYPE_BLOOM_FILTER - the lowest 4 bits indicate the
  1463. * number of hash functions (if 0, the bloom filter will default
  1464. * to using 5 hash functions).
  1465. *
  1466. * BPF_MAP_TYPE_ARENA - contains the address where user space
  1467. * is going to mmap() the arena. It has to be page aligned.
  1468. */
  1469. __u64 map_extra;
  1470. __s32 value_type_btf_obj_fd; /* fd pointing to a BTF
  1471. * type data for
  1472. * btf_vmlinux_value_type_id.
  1473. */
  1474. /* BPF token FD to use with BPF_MAP_CREATE operation.
  1475. * If provided, map_flags should have BPF_F_TOKEN_FD flag set.
  1476. */
  1477. __s32 map_token_fd;
  1478. /* Hash of the program that has exclusive access to the map.
  1479. */
  1480. __aligned_u64 excl_prog_hash;
  1481. /* Size of the passed excl_prog_hash. */
  1482. __u32 excl_prog_hash_size;
  1483. };
  1484. struct { /* anonymous struct used by BPF_MAP_*_ELEM and BPF_MAP_FREEZE commands */
  1485. __u32 map_fd;
  1486. __aligned_u64 key;
  1487. union {
  1488. __aligned_u64 value;
  1489. __aligned_u64 next_key;
  1490. };
  1491. __u64 flags;
  1492. };
  1493. struct { /* struct used by BPF_MAP_*_BATCH commands */
  1494. __aligned_u64 in_batch; /* start batch,
  1495. * NULL to start from beginning
  1496. */
  1497. __aligned_u64 out_batch; /* output: next start batch */
  1498. __aligned_u64 keys;
  1499. __aligned_u64 values;
  1500. __u32 count; /* input/output:
  1501. * input: # of key/value
  1502. * elements
  1503. * output: # of filled elements
  1504. */
  1505. __u32 map_fd;
  1506. __u64 elem_flags;
  1507. __u64 flags;
  1508. } batch;
  1509. struct { /* anonymous struct used by BPF_PROG_LOAD command */
  1510. __u32 prog_type; /* one of enum bpf_prog_type */
  1511. __u32 insn_cnt;
  1512. __aligned_u64 insns;
  1513. __aligned_u64 license;
  1514. __u32 log_level; /* verbosity level of verifier */
  1515. __u32 log_size; /* size of user buffer */
  1516. __aligned_u64 log_buf; /* user supplied buffer */
  1517. __u32 kern_version; /* not used */
  1518. __u32 prog_flags;
  1519. char prog_name[BPF_OBJ_NAME_LEN];
  1520. __u32 prog_ifindex; /* ifindex of netdev to prep for */
  1521. /* For some prog types expected attach type must be known at
  1522. * load time to verify attach type specific parts of prog
  1523. * (context accesses, allowed helpers, etc).
  1524. */
  1525. __u32 expected_attach_type;
  1526. __u32 prog_btf_fd; /* fd pointing to BTF type data */
  1527. __u32 func_info_rec_size; /* userspace bpf_func_info size */
  1528. __aligned_u64 func_info; /* func info */
  1529. __u32 func_info_cnt; /* number of bpf_func_info records */
  1530. __u32 line_info_rec_size; /* userspace bpf_line_info size */
  1531. __aligned_u64 line_info; /* line info */
  1532. __u32 line_info_cnt; /* number of bpf_line_info records */
  1533. __u32 attach_btf_id; /* in-kernel BTF type id to attach to */
  1534. union {
  1535. /* valid prog_fd to attach to bpf prog */
  1536. __u32 attach_prog_fd;
  1537. /* or valid module BTF object fd or 0 to attach to vmlinux */
  1538. __u32 attach_btf_obj_fd;
  1539. };
  1540. __u32 core_relo_cnt; /* number of bpf_core_relo */
  1541. __aligned_u64 fd_array; /* array of FDs */
  1542. __aligned_u64 core_relos;
  1543. __u32 core_relo_rec_size; /* sizeof(struct bpf_core_relo) */
  1544. /* output: actual total log contents size (including termintaing zero).
  1545. * It could be both larger than original log_size (if log was
  1546. * truncated), or smaller (if log buffer wasn't filled completely).
  1547. */
  1548. __u32 log_true_size;
  1549. /* BPF token FD to use with BPF_PROG_LOAD operation.
  1550. * If provided, prog_flags should have BPF_F_TOKEN_FD flag set.
  1551. */
  1552. __s32 prog_token_fd;
  1553. /* The fd_array_cnt can be used to pass the length of the
  1554. * fd_array array. In this case all the [map] file descriptors
  1555. * passed in this array will be bound to the program, even if
  1556. * the maps are not referenced directly. The functionality is
  1557. * similar to the BPF_PROG_BIND_MAP syscall, but maps can be
  1558. * used by the verifier during the program load. If provided,
  1559. * then the fd_array[0,...,fd_array_cnt-1] is expected to be
  1560. * continuous.
  1561. */
  1562. __u32 fd_array_cnt;
  1563. /* Pointer to a buffer containing the signature of the BPF
  1564. * program.
  1565. */
  1566. __aligned_u64 signature;
  1567. /* Size of the signature buffer in bytes. */
  1568. __u32 signature_size;
  1569. /* ID of the kernel keyring to be used for signature
  1570. * verification.
  1571. */
  1572. __s32 keyring_id;
  1573. };
  1574. struct { /* anonymous struct used by BPF_OBJ_* commands */
  1575. __aligned_u64 pathname;
  1576. __u32 bpf_fd;
  1577. __u32 file_flags;
  1578. /* Same as dirfd in openat() syscall; see openat(2)
  1579. * manpage for details of path FD and pathname semantics;
  1580. * path_fd should accompanied by BPF_F_PATH_FD flag set in
  1581. * file_flags field, otherwise it should be set to zero;
  1582. * if BPF_F_PATH_FD flag is not set, AT_FDCWD is assumed.
  1583. */
  1584. __s32 path_fd;
  1585. };
  1586. struct { /* anonymous struct used by BPF_PROG_ATTACH/DETACH commands */
  1587. union {
  1588. __u32 target_fd; /* target object to attach to or ... */
  1589. __u32 target_ifindex; /* target ifindex */
  1590. };
  1591. __u32 attach_bpf_fd;
  1592. __u32 attach_type;
  1593. __u32 attach_flags;
  1594. __u32 replace_bpf_fd;
  1595. union {
  1596. __u32 relative_fd;
  1597. __u32 relative_id;
  1598. };
  1599. __u64 expected_revision;
  1600. };
  1601. struct { /* anonymous struct used by BPF_PROG_TEST_RUN command */
  1602. __u32 prog_fd;
  1603. __u32 retval;
  1604. __u32 data_size_in; /* input: len of data_in */
  1605. __u32 data_size_out; /* input/output: len of data_out
  1606. * returns ENOSPC if data_out
  1607. * is too small.
  1608. */
  1609. __aligned_u64 data_in;
  1610. __aligned_u64 data_out;
  1611. __u32 repeat;
  1612. __u32 duration;
  1613. __u32 ctx_size_in; /* input: len of ctx_in */
  1614. __u32 ctx_size_out; /* input/output: len of ctx_out
  1615. * returns ENOSPC if ctx_out
  1616. * is too small.
  1617. */
  1618. __aligned_u64 ctx_in;
  1619. __aligned_u64 ctx_out;
  1620. __u32 flags;
  1621. __u32 cpu;
  1622. __u32 batch_size;
  1623. } test;
  1624. struct { /* anonymous struct used by BPF_*_GET_*_ID */
  1625. union {
  1626. __u32 start_id;
  1627. __u32 prog_id;
  1628. __u32 map_id;
  1629. __u32 btf_id;
  1630. __u32 link_id;
  1631. };
  1632. __u32 next_id;
  1633. __u32 open_flags;
  1634. __s32 fd_by_id_token_fd;
  1635. };
  1636. struct { /* anonymous struct used by BPF_OBJ_GET_INFO_BY_FD */
  1637. __u32 bpf_fd;
  1638. __u32 info_len;
  1639. __aligned_u64 info;
  1640. } info;
  1641. struct { /* anonymous struct used by BPF_PROG_QUERY command */
  1642. union {
  1643. __u32 target_fd; /* target object to query or ... */
  1644. __u32 target_ifindex; /* target ifindex */
  1645. };
  1646. __u32 attach_type;
  1647. __u32 query_flags;
  1648. __u32 attach_flags;
  1649. __aligned_u64 prog_ids;
  1650. union {
  1651. __u32 prog_cnt;
  1652. __u32 count;
  1653. };
  1654. __u32 :32;
  1655. /* output: per-program attach_flags.
  1656. * not allowed to be set during effective query.
  1657. */
  1658. __aligned_u64 prog_attach_flags;
  1659. __aligned_u64 link_ids;
  1660. __aligned_u64 link_attach_flags;
  1661. __u64 revision;
  1662. } query;
  1663. struct { /* anonymous struct used by BPF_RAW_TRACEPOINT_OPEN command */
  1664. __u64 name;
  1665. __u32 prog_fd;
  1666. __u32 :32;
  1667. __aligned_u64 cookie;
  1668. } raw_tracepoint;
  1669. struct { /* anonymous struct for BPF_BTF_LOAD */
  1670. __aligned_u64 btf;
  1671. __aligned_u64 btf_log_buf;
  1672. __u32 btf_size;
  1673. __u32 btf_log_size;
  1674. __u32 btf_log_level;
  1675. /* output: actual total log contents size (including termintaing zero).
  1676. * It could be both larger than original log_size (if log was
  1677. * truncated), or smaller (if log buffer wasn't filled completely).
  1678. */
  1679. __u32 btf_log_true_size;
  1680. __u32 btf_flags;
  1681. /* BPF token FD to use with BPF_BTF_LOAD operation.
  1682. * If provided, btf_flags should have BPF_F_TOKEN_FD flag set.
  1683. */
  1684. __s32 btf_token_fd;
  1685. };
  1686. struct {
  1687. __u32 pid; /* input: pid */
  1688. __u32 fd; /* input: fd */
  1689. __u32 flags; /* input: flags */
  1690. __u32 buf_len; /* input/output: buf len */
  1691. __aligned_u64 buf; /* input/output:
  1692. * tp_name for tracepoint
  1693. * symbol for kprobe
  1694. * filename for uprobe
  1695. */
  1696. __u32 prog_id; /* output: prod_id */
  1697. __u32 fd_type; /* output: BPF_FD_TYPE_* */
  1698. __u64 probe_offset; /* output: probe_offset */
  1699. __u64 probe_addr; /* output: probe_addr */
  1700. } task_fd_query;
  1701. struct { /* struct used by BPF_LINK_CREATE command */
  1702. union {
  1703. __u32 prog_fd; /* eBPF program to attach */
  1704. __u32 map_fd; /* struct_ops to attach */
  1705. };
  1706. union {
  1707. __u32 target_fd; /* target object to attach to or ... */
  1708. __u32 target_ifindex; /* target ifindex */
  1709. };
  1710. __u32 attach_type; /* attach type */
  1711. __u32 flags; /* extra flags */
  1712. union {
  1713. __u32 target_btf_id; /* btf_id of target to attach to */
  1714. struct {
  1715. __aligned_u64 iter_info; /* extra bpf_iter_link_info */
  1716. __u32 iter_info_len; /* iter_info length */
  1717. };
  1718. struct {
  1719. /* black box user-provided value passed through
  1720. * to BPF program at the execution time and
  1721. * accessible through bpf_get_attach_cookie() BPF helper
  1722. */
  1723. __u64 bpf_cookie;
  1724. } perf_event;
  1725. struct {
  1726. __u32 flags;
  1727. __u32 cnt;
  1728. __aligned_u64 syms;
  1729. __aligned_u64 addrs;
  1730. __aligned_u64 cookies;
  1731. } kprobe_multi;
  1732. struct {
  1733. /* this is overlaid with the target_btf_id above. */
  1734. __u32 target_btf_id;
  1735. /* black box user-provided value passed through
  1736. * to BPF program at the execution time and
  1737. * accessible through bpf_get_attach_cookie() BPF helper
  1738. */
  1739. __u64 cookie;
  1740. } tracing;
  1741. struct {
  1742. __u32 pf;
  1743. __u32 hooknum;
  1744. __s32 priority;
  1745. __u32 flags;
  1746. } netfilter;
  1747. struct {
  1748. union {
  1749. __u32 relative_fd;
  1750. __u32 relative_id;
  1751. };
  1752. __u64 expected_revision;
  1753. } tcx;
  1754. struct {
  1755. __aligned_u64 path;
  1756. __aligned_u64 offsets;
  1757. __aligned_u64 ref_ctr_offsets;
  1758. __aligned_u64 cookies;
  1759. __u32 cnt;
  1760. __u32 flags;
  1761. __u32 pid;
  1762. } uprobe_multi;
  1763. struct {
  1764. union {
  1765. __u32 relative_fd;
  1766. __u32 relative_id;
  1767. };
  1768. __u64 expected_revision;
  1769. } netkit;
  1770. struct {
  1771. union {
  1772. __u32 relative_fd;
  1773. __u32 relative_id;
  1774. };
  1775. __u64 expected_revision;
  1776. } cgroup;
  1777. };
  1778. } link_create;
  1779. struct { /* struct used by BPF_LINK_UPDATE command */
  1780. __u32 link_fd; /* link fd */
  1781. union {
  1782. /* new program fd to update link with */
  1783. __u32 new_prog_fd;
  1784. /* new struct_ops map fd to update link with */
  1785. __u32 new_map_fd;
  1786. };
  1787. __u32 flags; /* extra flags */
  1788. union {
  1789. /* expected link's program fd; is specified only if
  1790. * BPF_F_REPLACE flag is set in flags.
  1791. */
  1792. __u32 old_prog_fd;
  1793. /* expected link's map fd; is specified only
  1794. * if BPF_F_REPLACE flag is set.
  1795. */
  1796. __u32 old_map_fd;
  1797. };
  1798. } link_update;
  1799. struct {
  1800. __u32 link_fd;
  1801. } link_detach;
  1802. struct { /* struct used by BPF_ENABLE_STATS command */
  1803. __u32 type;
  1804. } enable_stats;
  1805. struct { /* struct used by BPF_ITER_CREATE command */
  1806. __u32 link_fd;
  1807. __u32 flags;
  1808. } iter_create;
  1809. struct { /* struct used by BPF_PROG_BIND_MAP command */
  1810. __u32 prog_fd;
  1811. __u32 map_fd;
  1812. __u32 flags; /* extra flags */
  1813. } prog_bind_map;
  1814. struct { /* struct used by BPF_TOKEN_CREATE command */
  1815. __u32 flags;
  1816. __u32 bpffs_fd;
  1817. } token_create;
  1818. struct {
  1819. __aligned_u64 stream_buf;
  1820. __u32 stream_buf_len;
  1821. __u32 stream_id;
  1822. __u32 prog_fd;
  1823. } prog_stream_read;
  1824. struct {
  1825. __u32 map_fd;
  1826. __u32 prog_fd;
  1827. __u32 flags;
  1828. } prog_assoc_struct_ops;
  1829. } __attribute__((aligned(8)));
  1830. /* The description below is an attempt at providing documentation to eBPF
  1831. * developers about the multiple available eBPF helper functions. It can be
  1832. * parsed and used to produce a manual page. The workflow is the following,
  1833. * and requires the rst2man utility:
  1834. *
  1835. * $ ./scripts/bpf_doc.py \
  1836. * --filename include/uapi/linux/bpf.h > /tmp/bpf-helpers.rst
  1837. * $ rst2man /tmp/bpf-helpers.rst > /tmp/bpf-helpers.7
  1838. * $ man /tmp/bpf-helpers.7
  1839. *
  1840. * Note that in order to produce this external documentation, some RST
  1841. * formatting is used in the descriptions to get "bold" and "italics" in
  1842. * manual pages. Also note that the few trailing white spaces are
  1843. * intentional, removing them would break paragraphs for rst2man.
  1844. *
  1845. * Start of BPF helper function descriptions:
  1846. *
  1847. * void *bpf_map_lookup_elem(struct bpf_map *map, const void *key)
  1848. * Description
  1849. * Perform a lookup in *map* for an entry associated to *key*.
  1850. * Return
  1851. * Map value associated to *key*, or **NULL** if no entry was
  1852. * found.
  1853. *
  1854. * long bpf_map_update_elem(struct bpf_map *map, const void *key, const void *value, u64 flags)
  1855. * Description
  1856. * Add or update the value of the entry associated to *key* in
  1857. * *map* with *value*. *flags* is one of:
  1858. *
  1859. * **BPF_NOEXIST**
  1860. * The entry for *key* must not exist in the map.
  1861. * **BPF_EXIST**
  1862. * The entry for *key* must already exist in the map.
  1863. * **BPF_ANY**
  1864. * No condition on the existence of the entry for *key*.
  1865. *
  1866. * Flag value **BPF_NOEXIST** cannot be used for maps of types
  1867. * **BPF_MAP_TYPE_ARRAY** or **BPF_MAP_TYPE_PERCPU_ARRAY** (all
  1868. * elements always exist), the helper would return an error.
  1869. * Return
  1870. * 0 on success, or a negative error in case of failure.
  1871. *
  1872. * long bpf_map_delete_elem(struct bpf_map *map, const void *key)
  1873. * Description
  1874. * Delete entry with *key* from *map*.
  1875. * Return
  1876. * 0 on success, or a negative error in case of failure.
  1877. *
  1878. * long bpf_probe_read(void *dst, u32 size, const void *unsafe_ptr)
  1879. * Description
  1880. * For tracing programs, safely attempt to read *size* bytes from
  1881. * kernel space address *unsafe_ptr* and store the data in *dst*.
  1882. *
  1883. * Generally, use **bpf_probe_read_user**\ () or
  1884. * **bpf_probe_read_kernel**\ () instead.
  1885. * Return
  1886. * 0 on success, or a negative error in case of failure.
  1887. *
  1888. * u64 bpf_ktime_get_ns(void)
  1889. * Description
  1890. * Return the time elapsed since system boot, in nanoseconds.
  1891. * Does not include time the system was suspended.
  1892. * See: **clock_gettime**\ (**CLOCK_MONOTONIC**)
  1893. * Return
  1894. * Current *ktime*.
  1895. *
  1896. * long bpf_trace_printk(const char *fmt, u32 fmt_size, ...)
  1897. * Description
  1898. * This helper is a "printk()-like" facility for debugging. It
  1899. * prints a message defined by format *fmt* (of size *fmt_size*)
  1900. * to file *\/sys/kernel/tracing/trace* from TraceFS, if
  1901. * available. It can take up to three additional **u64**
  1902. * arguments (as an eBPF helpers, the total number of arguments is
  1903. * limited to five).
  1904. *
  1905. * Each time the helper is called, it appends a line to the trace.
  1906. * Lines are discarded while *\/sys/kernel/tracing/trace* is
  1907. * open, use *\/sys/kernel/tracing/trace_pipe* to avoid this.
  1908. * The format of the trace is customizable, and the exact output
  1909. * one will get depends on the options set in
  1910. * *\/sys/kernel/tracing/trace_options* (see also the
  1911. * *README* file under the same directory). However, it usually
  1912. * defaults to something like:
  1913. *
  1914. * ::
  1915. *
  1916. * telnet-470 [001] .N.. 419421.045894: 0x00000001: <formatted msg>
  1917. *
  1918. * In the above:
  1919. *
  1920. * * ``telnet`` is the name of the current task.
  1921. * * ``470`` is the PID of the current task.
  1922. * * ``001`` is the CPU number on which the task is
  1923. * running.
  1924. * * In ``.N..``, each character refers to a set of
  1925. * options (whether irqs are enabled, scheduling
  1926. * options, whether hard/softirqs are running, level of
  1927. * preempt_disabled respectively). **N** means that
  1928. * **TIF_NEED_RESCHED** and **PREEMPT_NEED_RESCHED**
  1929. * are set.
  1930. * * ``419421.045894`` is a timestamp.
  1931. * * ``0x00000001`` is a fake value used by BPF for the
  1932. * instruction pointer register.
  1933. * * ``<formatted msg>`` is the message formatted with
  1934. * *fmt*.
  1935. *
  1936. * The conversion specifiers supported by *fmt* are similar, but
  1937. * more limited than for printk(). They are **%d**, **%i**,
  1938. * **%u**, **%x**, **%ld**, **%li**, **%lu**, **%lx**, **%lld**,
  1939. * **%lli**, **%llu**, **%llx**, **%p**, **%s**. No modifier (size
  1940. * of field, padding with zeroes, etc.) is available, and the
  1941. * helper will return **-EINVAL** (but print nothing) if it
  1942. * encounters an unknown specifier.
  1943. *
  1944. * Also, note that **bpf_trace_printk**\ () is slow, and should
  1945. * only be used for debugging purposes. For this reason, a notice
  1946. * block (spanning several lines) is printed to kernel logs and
  1947. * states that the helper should not be used "for production use"
  1948. * the first time this helper is used (or more precisely, when
  1949. * **trace_printk**\ () buffers are allocated). For passing values
  1950. * to user space, perf events should be preferred.
  1951. * Return
  1952. * The number of bytes written to the buffer, or a negative error
  1953. * in case of failure.
  1954. *
  1955. * u32 bpf_get_prandom_u32(void)
  1956. * Description
  1957. * Get a pseudo-random number.
  1958. *
  1959. * From a security point of view, this helper uses its own
  1960. * pseudo-random internal state, and cannot be used to infer the
  1961. * seed of other random functions in the kernel. However, it is
  1962. * essential to note that the generator used by the helper is not
  1963. * cryptographically secure.
  1964. * Return
  1965. * A random 32-bit unsigned value.
  1966. *
  1967. * u32 bpf_get_smp_processor_id(void)
  1968. * Description
  1969. * Get the SMP (symmetric multiprocessing) processor id. Note that
  1970. * all programs run with migration disabled, which means that the
  1971. * SMP processor id is stable during all the execution of the
  1972. * program.
  1973. * Return
  1974. * The SMP id of the processor running the program.
  1975. * Attributes
  1976. * __bpf_fastcall
  1977. *
  1978. * long bpf_skb_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len, u64 flags)
  1979. * Description
  1980. * Store *len* bytes from address *from* into the packet
  1981. * associated to *skb*, at *offset*. The *flags* are a combination
  1982. * of the following values:
  1983. *
  1984. * **BPF_F_RECOMPUTE_CSUM**
  1985. * Automatically update *skb*\ **->csum** after storing the
  1986. * bytes.
  1987. * **BPF_F_INVALIDATE_HASH**
  1988. * Set *skb*\ **->hash**, *skb*\ **->swhash** and *skb*\
  1989. * **->l4hash** to 0.
  1990. *
  1991. * A call to this helper is susceptible to change the underlying
  1992. * packet buffer. Therefore, at load time, all checks on pointers
  1993. * previously done by the verifier are invalidated and must be
  1994. * performed again, if the helper is used in combination with
  1995. * direct packet access.
  1996. * Return
  1997. * 0 on success, or a negative error in case of failure.
  1998. *
  1999. * long bpf_l3_csum_replace(struct sk_buff *skb, u32 offset, u64 from, u64 to, u64 size)
  2000. * Description
  2001. * Recompute the layer 3 (e.g. IP) checksum for the packet
  2002. * associated to *skb*. Computation is incremental, so the helper
  2003. * must know the former value of the header field that was
  2004. * modified (*from*), the new value of this field (*to*), and the
  2005. * number of bytes (2 or 4) for this field, stored in *size*.
  2006. * Alternatively, it is possible to store the difference between
  2007. * the previous and the new values of the header field in *to*, by
  2008. * setting *from* and *size* to 0. For both methods, *offset*
  2009. * indicates the location of the IP checksum within the packet.
  2010. *
  2011. * This helper works in combination with **bpf_csum_diff**\ (),
  2012. * which does not update the checksum in-place, but offers more
  2013. * flexibility and can handle sizes larger than 2 or 4 for the
  2014. * checksum to update.
  2015. *
  2016. * A call to this helper is susceptible to change the underlying
  2017. * packet buffer. Therefore, at load time, all checks on pointers
  2018. * previously done by the verifier are invalidated and must be
  2019. * performed again, if the helper is used in combination with
  2020. * direct packet access.
  2021. * Return
  2022. * 0 on success, or a negative error in case of failure.
  2023. *
  2024. * long bpf_l4_csum_replace(struct sk_buff *skb, u32 offset, u64 from, u64 to, u64 flags)
  2025. * Description
  2026. * Recompute the layer 4 (e.g. TCP, UDP or ICMP) checksum for the
  2027. * packet associated to *skb*. Computation is incremental, so the
  2028. * helper must know the former value of the header field that was
  2029. * modified (*from*), the new value of this field (*to*), and the
  2030. * number of bytes (2 or 4) for this field, stored on the lowest
  2031. * four bits of *flags*. Alternatively, it is possible to store
  2032. * the difference between the previous and the new values of the
  2033. * header field in *to*, by setting *from* and the four lowest
  2034. * bits of *flags* to 0. For both methods, *offset* indicates the
  2035. * location of the IP checksum within the packet. In addition to
  2036. * the size of the field, *flags* can be added (bitwise OR) actual
  2037. * flags. With **BPF_F_MARK_MANGLED_0**, a null checksum is left
  2038. * untouched (unless **BPF_F_MARK_ENFORCE** is added as well), and
  2039. * for updates resulting in a null checksum the value is set to
  2040. * **CSUM_MANGLED_0** instead. Flag **BPF_F_PSEUDO_HDR** indicates
  2041. * that the modified header field is part of the pseudo-header.
  2042. * Flag **BPF_F_IPV6** should be set for IPv6 packets.
  2043. *
  2044. * This helper works in combination with **bpf_csum_diff**\ (),
  2045. * which does not update the checksum in-place, but offers more
  2046. * flexibility and can handle sizes larger than 2 or 4 for the
  2047. * checksum to update.
  2048. *
  2049. * A call to this helper is susceptible to change the underlying
  2050. * packet buffer. Therefore, at load time, all checks on pointers
  2051. * previously done by the verifier are invalidated and must be
  2052. * performed again, if the helper is used in combination with
  2053. * direct packet access.
  2054. * Return
  2055. * 0 on success, or a negative error in case of failure.
  2056. *
  2057. * long bpf_tail_call(void *ctx, struct bpf_map *prog_array_map, u32 index)
  2058. * Description
  2059. * This special helper is used to trigger a "tail call", or in
  2060. * other words, to jump into another eBPF program. The same stack
  2061. * frame is used (but values on stack and in registers for the
  2062. * caller are not accessible to the callee). This mechanism allows
  2063. * for program chaining, either for raising the maximum number of
  2064. * available eBPF instructions, or to execute given programs in
  2065. * conditional blocks. For security reasons, there is an upper
  2066. * limit to the number of successive tail calls that can be
  2067. * performed.
  2068. *
  2069. * Upon call of this helper, the program attempts to jump into a
  2070. * program referenced at index *index* in *prog_array_map*, a
  2071. * special map of type **BPF_MAP_TYPE_PROG_ARRAY**, and passes
  2072. * *ctx*, a pointer to the context.
  2073. *
  2074. * If the call succeeds, the kernel immediately runs the first
  2075. * instruction of the new program. This is not a function call,
  2076. * and it never returns to the previous program. If the call
  2077. * fails, then the helper has no effect, and the caller continues
  2078. * to run its subsequent instructions. A call can fail if the
  2079. * destination program for the jump does not exist (i.e. *index*
  2080. * is superior to the number of entries in *prog_array_map*), or
  2081. * if the maximum number of tail calls has been reached for this
  2082. * chain of programs. This limit is defined in the kernel by the
  2083. * macro **MAX_TAIL_CALL_CNT** (not accessible to user space),
  2084. * which is currently set to 33.
  2085. * Return
  2086. * 0 on success, or a negative error in case of failure.
  2087. *
  2088. * long bpf_clone_redirect(struct sk_buff *skb, u32 ifindex, u64 flags)
  2089. * Description
  2090. * Clone and redirect the packet associated to *skb* to another
  2091. * net device of index *ifindex*. Both ingress and egress
  2092. * interfaces can be used for redirection. The **BPF_F_INGRESS**
  2093. * value in *flags* is used to make the distinction (ingress path
  2094. * is selected if the flag is present, egress path otherwise).
  2095. * This is the only flag supported for now.
  2096. *
  2097. * In comparison with **bpf_redirect**\ () helper,
  2098. * **bpf_clone_redirect**\ () has the associated cost of
  2099. * duplicating the packet buffer, but this can be executed out of
  2100. * the eBPF program. Conversely, **bpf_redirect**\ () is more
  2101. * efficient, but it is handled through an action code where the
  2102. * redirection happens only after the eBPF program has returned.
  2103. *
  2104. * A call to this helper is susceptible to change the underlying
  2105. * packet buffer. Therefore, at load time, all checks on pointers
  2106. * previously done by the verifier are invalidated and must be
  2107. * performed again, if the helper is used in combination with
  2108. * direct packet access.
  2109. * Return
  2110. * 0 on success, or a negative error in case of failure. Positive
  2111. * error indicates a potential drop or congestion in the target
  2112. * device. The particular positive error codes are not defined.
  2113. *
  2114. * u64 bpf_get_current_pid_tgid(void)
  2115. * Description
  2116. * Get the current pid and tgid.
  2117. * Return
  2118. * A 64-bit integer containing the current tgid and pid, and
  2119. * created as such:
  2120. * *current_task*\ **->tgid << 32 \|**
  2121. * *current_task*\ **->pid**.
  2122. *
  2123. * u64 bpf_get_current_uid_gid(void)
  2124. * Description
  2125. * Get the current uid and gid.
  2126. * Return
  2127. * A 64-bit integer containing the current GID and UID, and
  2128. * created as such: *current_gid* **<< 32 \|** *current_uid*.
  2129. *
  2130. * long bpf_get_current_comm(void *buf, u32 size_of_buf)
  2131. * Description
  2132. * Copy the **comm** attribute of the current task into *buf* of
  2133. * *size_of_buf*. The **comm** attribute contains the name of
  2134. * the executable (excluding the path) for the current task. The
  2135. * *size_of_buf* must be strictly positive. On success, the
  2136. * helper makes sure that the *buf* is NUL-terminated. On failure,
  2137. * it is filled with zeroes.
  2138. * Return
  2139. * 0 on success, or a negative error in case of failure.
  2140. *
  2141. * u32 bpf_get_cgroup_classid(struct sk_buff *skb)
  2142. * Description
  2143. * Retrieve the classid for the current task, i.e. for the net_cls
  2144. * cgroup to which *skb* belongs.
  2145. *
  2146. * This helper can be used on TC egress path, but not on ingress.
  2147. *
  2148. * The net_cls cgroup provides an interface to tag network packets
  2149. * based on a user-provided identifier for all traffic coming from
  2150. * the tasks belonging to the related cgroup. See also the related
  2151. * kernel documentation, available from the Linux sources in file
  2152. * *Documentation/admin-guide/cgroup-v1/net_cls.rst*.
  2153. *
  2154. * The Linux kernel has two versions for cgroups: there are
  2155. * cgroups v1 and cgroups v2. Both are available to users, who can
  2156. * use a mixture of them, but note that the net_cls cgroup is for
  2157. * cgroup v1 only. This makes it incompatible with BPF programs
  2158. * run on cgroups, which is a cgroup-v2-only feature (a socket can
  2159. * only hold data for one version of cgroups at a time).
  2160. *
  2161. * This helper is only available is the kernel was compiled with
  2162. * the **CONFIG_CGROUP_NET_CLASSID** configuration option set to
  2163. * "**y**" or to "**m**".
  2164. * Return
  2165. * The classid, or 0 for the default unconfigured classid.
  2166. *
  2167. * long bpf_skb_vlan_push(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci)
  2168. * Description
  2169. * Push a *vlan_tci* (VLAN tag control information) of protocol
  2170. * *vlan_proto* to the packet associated to *skb*, then update
  2171. * the checksum. Note that if *vlan_proto* is different from
  2172. * **ETH_P_8021Q** and **ETH_P_8021AD**, it is considered to
  2173. * be **ETH_P_8021Q**.
  2174. *
  2175. * A call to this helper is susceptible to change the underlying
  2176. * packet buffer. Therefore, at load time, all checks on pointers
  2177. * previously done by the verifier are invalidated and must be
  2178. * performed again, if the helper is used in combination with
  2179. * direct packet access.
  2180. * Return
  2181. * 0 on success, or a negative error in case of failure.
  2182. *
  2183. * long bpf_skb_vlan_pop(struct sk_buff *skb)
  2184. * Description
  2185. * Pop a VLAN header from the packet associated to *skb*.
  2186. *
  2187. * A call to this helper is susceptible to change the underlying
  2188. * packet buffer. Therefore, at load time, all checks on pointers
  2189. * previously done by the verifier are invalidated and must be
  2190. * performed again, if the helper is used in combination with
  2191. * direct packet access.
  2192. * Return
  2193. * 0 on success, or a negative error in case of failure.
  2194. *
  2195. * long bpf_skb_get_tunnel_key(struct sk_buff *skb, struct bpf_tunnel_key *key, u32 size, u64 flags)
  2196. * Description
  2197. * Get tunnel metadata. This helper takes a pointer *key* to an
  2198. * empty **struct bpf_tunnel_key** of **size**, that will be
  2199. * filled with tunnel metadata for the packet associated to *skb*.
  2200. * The *flags* can be set to **BPF_F_TUNINFO_IPV6**, which
  2201. * indicates that the tunnel is based on IPv6 protocol instead of
  2202. * IPv4.
  2203. *
  2204. * The **struct bpf_tunnel_key** is an object that generalizes the
  2205. * principal parameters used by various tunneling protocols into a
  2206. * single struct. This way, it can be used to easily make a
  2207. * decision based on the contents of the encapsulation header,
  2208. * "summarized" in this struct. In particular, it holds the IP
  2209. * address of the remote end (IPv4 or IPv6, depending on the case)
  2210. * in *key*\ **->remote_ipv4** or *key*\ **->remote_ipv6**. Also,
  2211. * this struct exposes the *key*\ **->tunnel_id**, which is
  2212. * generally mapped to a VNI (Virtual Network Identifier), making
  2213. * it programmable together with the **bpf_skb_set_tunnel_key**\
  2214. * () helper.
  2215. *
  2216. * Let's imagine that the following code is part of a program
  2217. * attached to the TC ingress interface, on one end of a GRE
  2218. * tunnel, and is supposed to filter out all messages coming from
  2219. * remote ends with IPv4 address other than 10.0.0.1:
  2220. *
  2221. * ::
  2222. *
  2223. * int ret;
  2224. * struct bpf_tunnel_key key = {};
  2225. *
  2226. * ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
  2227. * if (ret < 0)
  2228. * return TC_ACT_SHOT; // drop packet
  2229. *
  2230. * if (key.remote_ipv4 != 0x0a000001)
  2231. * return TC_ACT_SHOT; // drop packet
  2232. *
  2233. * return TC_ACT_OK; // accept packet
  2234. *
  2235. * This interface can also be used with all encapsulation devices
  2236. * that can operate in "collect metadata" mode: instead of having
  2237. * one network device per specific configuration, the "collect
  2238. * metadata" mode only requires a single device where the
  2239. * configuration can be extracted from this helper.
  2240. *
  2241. * This can be used together with various tunnels such as VXLan,
  2242. * Geneve, GRE or IP in IP (IPIP).
  2243. * Return
  2244. * 0 on success, or a negative error in case of failure.
  2245. *
  2246. * long bpf_skb_set_tunnel_key(struct sk_buff *skb, struct bpf_tunnel_key *key, u32 size, u64 flags)
  2247. * Description
  2248. * Populate tunnel metadata for packet associated to *skb.* The
  2249. * tunnel metadata is set to the contents of *key*, of *size*. The
  2250. * *flags* can be set to a combination of the following values:
  2251. *
  2252. * **BPF_F_TUNINFO_IPV6**
  2253. * Indicate that the tunnel is based on IPv6 protocol
  2254. * instead of IPv4.
  2255. * **BPF_F_ZERO_CSUM_TX**
  2256. * For IPv4 packets, add a flag to tunnel metadata
  2257. * indicating that checksum computation should be skipped
  2258. * and checksum set to zeroes.
  2259. * **BPF_F_DONT_FRAGMENT**
  2260. * Add a flag to tunnel metadata indicating that the
  2261. * packet should not be fragmented.
  2262. * **BPF_F_SEQ_NUMBER**
  2263. * Add a flag to tunnel metadata indicating that a
  2264. * sequence number should be added to tunnel header before
  2265. * sending the packet. This flag was added for GRE
  2266. * encapsulation, but might be used with other protocols
  2267. * as well in the future.
  2268. * **BPF_F_NO_TUNNEL_KEY**
  2269. * Add a flag to tunnel metadata indicating that no tunnel
  2270. * key should be set in the resulting tunnel header.
  2271. *
  2272. * Here is a typical usage on the transmit path:
  2273. *
  2274. * ::
  2275. *
  2276. * struct bpf_tunnel_key key;
  2277. * populate key ...
  2278. * bpf_skb_set_tunnel_key(skb, &key, sizeof(key), 0);
  2279. * bpf_clone_redirect(skb, vxlan_dev_ifindex, 0);
  2280. *
  2281. * See also the description of the **bpf_skb_get_tunnel_key**\ ()
  2282. * helper for additional information.
  2283. * Return
  2284. * 0 on success, or a negative error in case of failure.
  2285. *
  2286. * u64 bpf_perf_event_read(struct bpf_map *map, u64 flags)
  2287. * Description
  2288. * Read the value of a perf event counter. This helper relies on a
  2289. * *map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. The nature of
  2290. * the perf event counter is selected when *map* is updated with
  2291. * perf event file descriptors. The *map* is an array whose size
  2292. * is the number of available CPUs, and each cell contains a value
  2293. * relative to one CPU. The value to retrieve is indicated by
  2294. * *flags*, that contains the index of the CPU to look up, masked
  2295. * with **BPF_F_INDEX_MASK**. Alternatively, *flags* can be set to
  2296. * **BPF_F_CURRENT_CPU** to indicate that the value for the
  2297. * current CPU should be retrieved.
  2298. *
  2299. * Note that before Linux 4.13, only hardware perf event can be
  2300. * retrieved.
  2301. *
  2302. * Also, be aware that the newer helper
  2303. * **bpf_perf_event_read_value**\ () is recommended over
  2304. * **bpf_perf_event_read**\ () in general. The latter has some ABI
  2305. * quirks where error and counter value are used as a return code
  2306. * (which is wrong to do since ranges may overlap). This issue is
  2307. * fixed with **bpf_perf_event_read_value**\ (), which at the same
  2308. * time provides more features over the **bpf_perf_event_read**\
  2309. * () interface. Please refer to the description of
  2310. * **bpf_perf_event_read_value**\ () for details.
  2311. * Return
  2312. * The value of the perf event counter read from the map, or a
  2313. * negative error code in case of failure.
  2314. *
  2315. * long bpf_redirect(u32 ifindex, u64 flags)
  2316. * Description
  2317. * Redirect the packet to another net device of index *ifindex*.
  2318. * This helper is somewhat similar to **bpf_clone_redirect**\
  2319. * (), except that the packet is not cloned, which provides
  2320. * increased performance.
  2321. *
  2322. * Except for XDP, both ingress and egress interfaces can be used
  2323. * for redirection. The **BPF_F_INGRESS** value in *flags* is used
  2324. * to make the distinction (ingress path is selected if the flag
  2325. * is present, egress path otherwise). Currently, XDP only
  2326. * supports redirection to the egress interface, and accepts no
  2327. * flag at all.
  2328. *
  2329. * The same effect can also be attained with the more generic
  2330. * **bpf_redirect_map**\ (), which uses a BPF map to store the
  2331. * redirect target instead of providing it directly to the helper.
  2332. * Return
  2333. * For XDP, the helper returns **XDP_REDIRECT** on success or
  2334. * **XDP_ABORTED** on error. For other program types, the values
  2335. * are **TC_ACT_REDIRECT** on success or **TC_ACT_SHOT** on
  2336. * error.
  2337. *
  2338. * u32 bpf_get_route_realm(struct sk_buff *skb)
  2339. * Description
  2340. * Retrieve the realm or the route, that is to say the
  2341. * **tclassid** field of the destination for the *skb*. The
  2342. * identifier retrieved is a user-provided tag, similar to the
  2343. * one used with the net_cls cgroup (see description for
  2344. * **bpf_get_cgroup_classid**\ () helper), but here this tag is
  2345. * held by a route (a destination entry), not by a task.
  2346. *
  2347. * Retrieving this identifier works with the clsact TC egress hook
  2348. * (see also **tc-bpf(8)**), or alternatively on conventional
  2349. * classful egress qdiscs, but not on TC ingress path. In case of
  2350. * clsact TC egress hook, this has the advantage that, internally,
  2351. * the destination entry has not been dropped yet in the transmit
  2352. * path. Therefore, the destination entry does not need to be
  2353. * artificially held via **netif_keep_dst**\ () for a classful
  2354. * qdisc until the *skb* is freed.
  2355. *
  2356. * This helper is available only if the kernel was compiled with
  2357. * **CONFIG_IP_ROUTE_CLASSID** configuration option.
  2358. * Return
  2359. * The realm of the route for the packet associated to *skb*, or 0
  2360. * if none was found.
  2361. *
  2362. * long bpf_perf_event_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
  2363. * Description
  2364. * Write raw *data* blob into a special BPF perf event held by
  2365. * *map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
  2366. * event must have the following attributes: **PERF_SAMPLE_RAW**
  2367. * as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
  2368. * **PERF_COUNT_SW_BPF_OUTPUT** as **config**.
  2369. *
  2370. * The *flags* are used to indicate the index in *map* for which
  2371. * the value must be put, masked with **BPF_F_INDEX_MASK**.
  2372. * Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
  2373. * to indicate that the index of the current CPU core should be
  2374. * used.
  2375. *
  2376. * The value to write, of *size*, is passed through eBPF stack and
  2377. * pointed by *data*.
  2378. *
  2379. * The context of the program *ctx* needs also be passed to the
  2380. * helper.
  2381. *
  2382. * On user space, a program willing to read the values needs to
  2383. * call **perf_event_open**\ () on the perf event (either for
  2384. * one or for all CPUs) and to store the file descriptor into the
  2385. * *map*. This must be done before the eBPF program can send data
  2386. * into it. An example is available in file
  2387. * *samples/bpf/trace_output_user.c* in the Linux kernel source
  2388. * tree (the eBPF program counterpart is in
  2389. * *samples/bpf/trace_output.bpf.c*).
  2390. *
  2391. * **bpf_perf_event_output**\ () achieves better performance
  2392. * than **bpf_trace_printk**\ () for sharing data with user
  2393. * space, and is much better suitable for streaming data from eBPF
  2394. * programs.
  2395. *
  2396. * Note that this helper is not restricted to tracing use cases
  2397. * and can be used with programs attached to TC or XDP as well,
  2398. * where it allows for passing data to user space listeners. Data
  2399. * can be:
  2400. *
  2401. * * Only custom structs,
  2402. * * Only the packet payload, or
  2403. * * A combination of both.
  2404. * Return
  2405. * 0 on success, or a negative error in case of failure.
  2406. *
  2407. * long bpf_skb_load_bytes(const void *skb, u32 offset, void *to, u32 len)
  2408. * Description
  2409. * This helper was provided as an easy way to load data from a
  2410. * packet. It can be used to load *len* bytes from *offset* from
  2411. * the packet associated to *skb*, into the buffer pointed by
  2412. * *to*.
  2413. *
  2414. * Since Linux 4.7, usage of this helper has mostly been replaced
  2415. * by "direct packet access", enabling packet data to be
  2416. * manipulated with *skb*\ **->data** and *skb*\ **->data_end**
  2417. * pointing respectively to the first byte of packet data and to
  2418. * the byte after the last byte of packet data. However, it
  2419. * remains useful if one wishes to read large quantities of data
  2420. * at once from a packet into the eBPF stack.
  2421. * Return
  2422. * 0 on success, or a negative error in case of failure.
  2423. *
  2424. * long bpf_get_stackid(void *ctx, struct bpf_map *map, u64 flags)
  2425. * Description
  2426. * Walk a user or a kernel stack and return its id. To achieve
  2427. * this, the helper needs *ctx*, which is a pointer to the context
  2428. * on which the tracing program is executed, and a pointer to a
  2429. * *map* of type **BPF_MAP_TYPE_STACK_TRACE**.
  2430. *
  2431. * The last argument, *flags*, holds the number of stack frames to
  2432. * skip (from 0 to 255), masked with
  2433. * **BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
  2434. * a combination of the following flags:
  2435. *
  2436. * **BPF_F_USER_STACK**
  2437. * Collect a user space stack instead of a kernel stack.
  2438. * **BPF_F_FAST_STACK_CMP**
  2439. * Compare stacks by hash only.
  2440. * **BPF_F_REUSE_STACKID**
  2441. * If two different stacks hash into the same *stackid*,
  2442. * discard the old one.
  2443. *
  2444. * The stack id retrieved is a 32 bit long integer handle which
  2445. * can be further combined with other data (including other stack
  2446. * ids) and used as a key into maps. This can be useful for
  2447. * generating a variety of graphs (such as flame graphs or off-cpu
  2448. * graphs).
  2449. *
  2450. * For walking a stack, this helper is an improvement over
  2451. * **bpf_probe_read**\ (), which can be used with unrolled loops
  2452. * but is not efficient and consumes a lot of eBPF instructions.
  2453. * Instead, **bpf_get_stackid**\ () can collect up to
  2454. * **PERF_MAX_STACK_DEPTH** both kernel and user frames. Note that
  2455. * this limit can be controlled with the **sysctl** program, and
  2456. * that it should be manually increased in order to profile long
  2457. * user stacks (such as stacks for Java programs). To do so, use:
  2458. *
  2459. * ::
  2460. *
  2461. * # sysctl kernel.perf_event_max_stack=<new value>
  2462. * Return
  2463. * The positive or null stack id on success, or a negative error
  2464. * in case of failure.
  2465. *
  2466. * s64 bpf_csum_diff(__be32 *from, u32 from_size, __be32 *to, u32 to_size, __wsum seed)
  2467. * Description
  2468. * Compute a checksum difference, from the raw buffer pointed by
  2469. * *from*, of length *from_size* (that must be a multiple of 4),
  2470. * towards the raw buffer pointed by *to*, of size *to_size*
  2471. * (same remark). An optional *seed* can be added to the value
  2472. * (this can be cascaded, the seed may come from a previous call
  2473. * to the helper).
  2474. *
  2475. * This is flexible enough to be used in several ways:
  2476. *
  2477. * * With *from_size* == 0, *to_size* > 0 and *seed* set to
  2478. * checksum, it can be used when pushing new data.
  2479. * * With *from_size* > 0, *to_size* == 0 and *seed* set to
  2480. * checksum, it can be used when removing data from a packet.
  2481. * * With *from_size* > 0, *to_size* > 0 and *seed* set to 0, it
  2482. * can be used to compute a diff. Note that *from_size* and
  2483. * *to_size* do not need to be equal.
  2484. *
  2485. * This helper can be used in combination with
  2486. * **bpf_l3_csum_replace**\ () and **bpf_l4_csum_replace**\ (), to
  2487. * which one can feed in the difference computed with
  2488. * **bpf_csum_diff**\ ().
  2489. * Return
  2490. * The checksum result, or a negative error code in case of
  2491. * failure.
  2492. *
  2493. * long bpf_skb_get_tunnel_opt(struct sk_buff *skb, void *opt, u32 size)
  2494. * Description
  2495. * Retrieve tunnel options metadata for the packet associated to
  2496. * *skb*, and store the raw tunnel option data to the buffer *opt*
  2497. * of *size*.
  2498. *
  2499. * This helper can be used with encapsulation devices that can
  2500. * operate in "collect metadata" mode (please refer to the related
  2501. * note in the description of **bpf_skb_get_tunnel_key**\ () for
  2502. * more details). A particular example where this can be used is
  2503. * in combination with the Geneve encapsulation protocol, where it
  2504. * allows for pushing (with **bpf_skb_get_tunnel_opt**\ () helper)
  2505. * and retrieving arbitrary TLVs (Type-Length-Value headers) from
  2506. * the eBPF program. This allows for full customization of these
  2507. * headers.
  2508. * Return
  2509. * The size of the option data retrieved.
  2510. *
  2511. * long bpf_skb_set_tunnel_opt(struct sk_buff *skb, void *opt, u32 size)
  2512. * Description
  2513. * Set tunnel options metadata for the packet associated to *skb*
  2514. * to the option data contained in the raw buffer *opt* of *size*.
  2515. *
  2516. * See also the description of the **bpf_skb_get_tunnel_opt**\ ()
  2517. * helper for additional information.
  2518. * Return
  2519. * 0 on success, or a negative error in case of failure.
  2520. *
  2521. * long bpf_skb_change_proto(struct sk_buff *skb, __be16 proto, u64 flags)
  2522. * Description
  2523. * Change the protocol of the *skb* to *proto*. Currently
  2524. * supported are transition from IPv4 to IPv6, and from IPv6 to
  2525. * IPv4. The helper takes care of the groundwork for the
  2526. * transition, including resizing the socket buffer. The eBPF
  2527. * program is expected to fill the new headers, if any, via
  2528. * **skb_store_bytes**\ () and to recompute the checksums with
  2529. * **bpf_l3_csum_replace**\ () and **bpf_l4_csum_replace**\
  2530. * (). The main case for this helper is to perform NAT64
  2531. * operations out of an eBPF program.
  2532. *
  2533. * Internally, the GSO type is marked as dodgy so that headers are
  2534. * checked and segments are recalculated by the GSO/GRO engine.
  2535. * The size for GSO target is adapted as well.
  2536. *
  2537. * All values for *flags* are reserved for future usage, and must
  2538. * be left at zero.
  2539. *
  2540. * A call to this helper is susceptible to change the underlying
  2541. * packet buffer. Therefore, at load time, all checks on pointers
  2542. * previously done by the verifier are invalidated and must be
  2543. * performed again, if the helper is used in combination with
  2544. * direct packet access.
  2545. * Return
  2546. * 0 on success, or a negative error in case of failure.
  2547. *
  2548. * long bpf_skb_change_type(struct sk_buff *skb, u32 type)
  2549. * Description
  2550. * Change the packet type for the packet associated to *skb*. This
  2551. * comes down to setting *skb*\ **->pkt_type** to *type*, except
  2552. * the eBPF program does not have a write access to *skb*\
  2553. * **->pkt_type** beside this helper. Using a helper here allows
  2554. * for graceful handling of errors.
  2555. *
  2556. * The major use case is to change incoming *skb*s to
  2557. * **PACKET_HOST** in a programmatic way instead of having to
  2558. * recirculate via **redirect**\ (..., **BPF_F_INGRESS**), for
  2559. * example.
  2560. *
  2561. * Note that *type* only allows certain values. At this time, they
  2562. * are:
  2563. *
  2564. * **PACKET_HOST**
  2565. * Packet is for us.
  2566. * **PACKET_BROADCAST**
  2567. * Send packet to all.
  2568. * **PACKET_MULTICAST**
  2569. * Send packet to group.
  2570. * **PACKET_OTHERHOST**
  2571. * Send packet to someone else.
  2572. * Return
  2573. * 0 on success, or a negative error in case of failure.
  2574. *
  2575. * long bpf_skb_under_cgroup(struct sk_buff *skb, struct bpf_map *map, u32 index)
  2576. * Description
  2577. * Check whether *skb* is a descendant of the cgroup2 held by
  2578. * *map* of type **BPF_MAP_TYPE_CGROUP_ARRAY**, at *index*.
  2579. * Return
  2580. * The return value depends on the result of the test, and can be:
  2581. *
  2582. * * 0, if the *skb* failed the cgroup2 descendant test.
  2583. * * 1, if the *skb* succeeded the cgroup2 descendant test.
  2584. * * A negative error code, if an error occurred.
  2585. *
  2586. * u32 bpf_get_hash_recalc(struct sk_buff *skb)
  2587. * Description
  2588. * Retrieve the hash of the packet, *skb*\ **->hash**. If it is
  2589. * not set, in particular if the hash was cleared due to mangling,
  2590. * recompute this hash. Later accesses to the hash can be done
  2591. * directly with *skb*\ **->hash**.
  2592. *
  2593. * Calling **bpf_set_hash_invalid**\ (), changing a packet
  2594. * prototype with **bpf_skb_change_proto**\ (), or calling
  2595. * **bpf_skb_store_bytes**\ () with the
  2596. * **BPF_F_INVALIDATE_HASH** are actions susceptible to clear
  2597. * the hash and to trigger a new computation for the next call to
  2598. * **bpf_get_hash_recalc**\ ().
  2599. * Return
  2600. * The 32-bit hash.
  2601. *
  2602. * u64 bpf_get_current_task(void)
  2603. * Description
  2604. * Get the current task.
  2605. * Return
  2606. * A pointer to the current task struct.
  2607. *
  2608. * long bpf_probe_write_user(void *dst, const void *src, u32 len)
  2609. * Description
  2610. * Attempt in a safe way to write *len* bytes from the buffer
  2611. * *src* to *dst* in memory. It only works for threads that are in
  2612. * user context, and *dst* must be a valid user space address.
  2613. *
  2614. * This helper should not be used to implement any kind of
  2615. * security mechanism because of TOC-TOU attacks, but rather to
  2616. * debug, divert, and manipulate execution of semi-cooperative
  2617. * processes.
  2618. *
  2619. * Keep in mind that this feature is meant for experiments, and it
  2620. * has a risk of crashing the system and running programs.
  2621. * Therefore, when an eBPF program using this helper is attached,
  2622. * a warning including PID and process name is printed to kernel
  2623. * logs.
  2624. * Return
  2625. * 0 on success, or a negative error in case of failure.
  2626. *
  2627. * long bpf_current_task_under_cgroup(struct bpf_map *map, u32 index)
  2628. * Description
  2629. * Check whether the probe is being run is the context of a given
  2630. * subset of the cgroup2 hierarchy. The cgroup2 to test is held by
  2631. * *map* of type **BPF_MAP_TYPE_CGROUP_ARRAY**, at *index*.
  2632. * Return
  2633. * The return value depends on the result of the test, and can be:
  2634. *
  2635. * * 1, if current task belongs to the cgroup2.
  2636. * * 0, if current task does not belong to the cgroup2.
  2637. * * A negative error code, if an error occurred.
  2638. *
  2639. * long bpf_skb_change_tail(struct sk_buff *skb, u32 len, u64 flags)
  2640. * Description
  2641. * Resize (trim or grow) the packet associated to *skb* to the
  2642. * new *len*. The *flags* are reserved for future usage, and must
  2643. * be left at zero.
  2644. *
  2645. * The basic idea is that the helper performs the needed work to
  2646. * change the size of the packet, then the eBPF program rewrites
  2647. * the rest via helpers like **bpf_skb_store_bytes**\ (),
  2648. * **bpf_l3_csum_replace**\ (), **bpf_l3_csum_replace**\ ()
  2649. * and others. This helper is a slow path utility intended for
  2650. * replies with control messages. And because it is targeted for
  2651. * slow path, the helper itself can afford to be slow: it
  2652. * implicitly linearizes, unclones and drops offloads from the
  2653. * *skb*.
  2654. *
  2655. * A call to this helper is susceptible to change the underlying
  2656. * packet buffer. Therefore, at load time, all checks on pointers
  2657. * previously done by the verifier are invalidated and must be
  2658. * performed again, if the helper is used in combination with
  2659. * direct packet access.
  2660. * Return
  2661. * 0 on success, or a negative error in case of failure.
  2662. *
  2663. * long bpf_skb_pull_data(struct sk_buff *skb, u32 len)
  2664. * Description
  2665. * Pull in non-linear data in case the *skb* is non-linear and not
  2666. * all of *len* are part of the linear section. Make *len* bytes
  2667. * from *skb* readable and writable. If a zero value is passed for
  2668. * *len*, then all bytes in the linear part of *skb* will be made
  2669. * readable and writable.
  2670. *
  2671. * This helper is only needed for reading and writing with direct
  2672. * packet access.
  2673. *
  2674. * For direct packet access, testing that offsets to access
  2675. * are within packet boundaries (test on *skb*\ **->data_end**) is
  2676. * susceptible to fail if offsets are invalid, or if the requested
  2677. * data is in non-linear parts of the *skb*. On failure the
  2678. * program can just bail out, or in the case of a non-linear
  2679. * buffer, use a helper to make the data available. The
  2680. * **bpf_skb_load_bytes**\ () helper is a first solution to access
  2681. * the data. Another one consists in using **bpf_skb_pull_data**
  2682. * to pull in once the non-linear parts, then retesting and
  2683. * eventually access the data.
  2684. *
  2685. * At the same time, this also makes sure the *skb* is uncloned,
  2686. * which is a necessary condition for direct write. As this needs
  2687. * to be an invariant for the write part only, the verifier
  2688. * detects writes and adds a prologue that is calling
  2689. * **bpf_skb_pull_data()** to effectively unclone the *skb* from
  2690. * the very beginning in case it is indeed cloned.
  2691. *
  2692. * A call to this helper is susceptible to change the underlying
  2693. * packet buffer. Therefore, at load time, all checks on pointers
  2694. * previously done by the verifier are invalidated and must be
  2695. * performed again, if the helper is used in combination with
  2696. * direct packet access.
  2697. * Return
  2698. * 0 on success, or a negative error in case of failure.
  2699. *
  2700. * s64 bpf_csum_update(struct sk_buff *skb, __wsum csum)
  2701. * Description
  2702. * Add the checksum *csum* into *skb*\ **->csum** in case the
  2703. * driver has supplied a checksum for the entire packet into that
  2704. * field. Return an error otherwise. This helper is intended to be
  2705. * used in combination with **bpf_csum_diff**\ (), in particular
  2706. * when the checksum needs to be updated after data has been
  2707. * written into the packet through direct packet access.
  2708. * Return
  2709. * The checksum on success, or a negative error code in case of
  2710. * failure.
  2711. *
  2712. * void bpf_set_hash_invalid(struct sk_buff *skb)
  2713. * Description
  2714. * Invalidate the current *skb*\ **->hash**. It can be used after
  2715. * mangling on headers through direct packet access, in order to
  2716. * indicate that the hash is outdated and to trigger a
  2717. * recalculation the next time the kernel tries to access this
  2718. * hash or when the **bpf_get_hash_recalc**\ () helper is called.
  2719. * Return
  2720. * void.
  2721. *
  2722. * long bpf_get_numa_node_id(void)
  2723. * Description
  2724. * Return the id of the current NUMA node. The primary use case
  2725. * for this helper is the selection of sockets for the local NUMA
  2726. * node, when the program is attached to sockets using the
  2727. * **SO_ATTACH_REUSEPORT_EBPF** option (see also **socket(7)**),
  2728. * but the helper is also available to other eBPF program types,
  2729. * similarly to **bpf_get_smp_processor_id**\ ().
  2730. * Return
  2731. * The id of current NUMA node.
  2732. *
  2733. * long bpf_skb_change_head(struct sk_buff *skb, u32 len, u64 flags)
  2734. * Description
  2735. * Grows headroom of packet associated to *skb* and adjusts the
  2736. * offset of the MAC header accordingly, adding *len* bytes of
  2737. * space. It automatically extends and reallocates memory as
  2738. * required.
  2739. *
  2740. * This helper can be used on a layer 3 *skb* to push a MAC header
  2741. * for redirection into a layer 2 device.
  2742. *
  2743. * All values for *flags* are reserved for future usage, and must
  2744. * be left at zero.
  2745. *
  2746. * A call to this helper is susceptible to change the underlying
  2747. * packet buffer. Therefore, at load time, all checks on pointers
  2748. * previously done by the verifier are invalidated and must be
  2749. * performed again, if the helper is used in combination with
  2750. * direct packet access.
  2751. * Return
  2752. * 0 on success, or a negative error in case of failure.
  2753. *
  2754. * long bpf_xdp_adjust_head(struct xdp_buff *xdp_md, int delta)
  2755. * Description
  2756. * Adjust (move) *xdp_md*\ **->data** by *delta* bytes. Note that
  2757. * it is possible to use a negative value for *delta*. This helper
  2758. * can be used to prepare the packet for pushing or popping
  2759. * headers.
  2760. *
  2761. * A call to this helper is susceptible to change the underlying
  2762. * packet buffer. Therefore, at load time, all checks on pointers
  2763. * previously done by the verifier are invalidated and must be
  2764. * performed again, if the helper is used in combination with
  2765. * direct packet access.
  2766. * Return
  2767. * 0 on success, or a negative error in case of failure.
  2768. *
  2769. * long bpf_probe_read_str(void *dst, u32 size, const void *unsafe_ptr)
  2770. * Description
  2771. * Copy a NUL terminated string from an unsafe kernel address
  2772. * *unsafe_ptr* to *dst*. See **bpf_probe_read_kernel_str**\ () for
  2773. * more details.
  2774. *
  2775. * Generally, use **bpf_probe_read_user_str**\ () or
  2776. * **bpf_probe_read_kernel_str**\ () instead.
  2777. * Return
  2778. * On success, the strictly positive length of the string,
  2779. * including the trailing NUL character. On error, a negative
  2780. * value.
  2781. *
  2782. * u64 bpf_get_socket_cookie(struct sk_buff *skb)
  2783. * Description
  2784. * If the **struct sk_buff** pointed by *skb* has a known socket,
  2785. * retrieve the cookie (generated by the kernel) of this socket.
  2786. * If no cookie has been set yet, generate a new cookie. Once
  2787. * generated, the socket cookie remains stable for the life of the
  2788. * socket. This helper can be useful for monitoring per socket
  2789. * networking traffic statistics as it provides a global socket
  2790. * identifier that can be assumed unique.
  2791. * Return
  2792. * A 8-byte long unique number on success, or 0 if the socket
  2793. * field is missing inside *skb*.
  2794. *
  2795. * u64 bpf_get_socket_cookie(struct bpf_sock_addr *ctx)
  2796. * Description
  2797. * Equivalent to bpf_get_socket_cookie() helper that accepts
  2798. * *skb*, but gets socket from **struct bpf_sock_addr** context.
  2799. * Return
  2800. * A 8-byte long unique number.
  2801. *
  2802. * u64 bpf_get_socket_cookie(struct bpf_sock_ops *ctx)
  2803. * Description
  2804. * Equivalent to **bpf_get_socket_cookie**\ () helper that accepts
  2805. * *skb*, but gets socket from **struct bpf_sock_ops** context.
  2806. * Return
  2807. * A 8-byte long unique number.
  2808. *
  2809. * u64 bpf_get_socket_cookie(struct sock *sk)
  2810. * Description
  2811. * Equivalent to **bpf_get_socket_cookie**\ () helper that accepts
  2812. * *sk*, but gets socket from a BTF **struct sock**. This helper
  2813. * also works for sleepable programs.
  2814. * Return
  2815. * A 8-byte long unique number or 0 if *sk* is NULL.
  2816. *
  2817. * u32 bpf_get_socket_uid(struct sk_buff *skb)
  2818. * Description
  2819. * Get the owner UID of the socked associated to *skb*.
  2820. * Return
  2821. * The owner UID of the socket associated to *skb*. If the socket
  2822. * is **NULL**, or if it is not a full socket (i.e. if it is a
  2823. * time-wait or a request socket instead), **overflowuid** value
  2824. * is returned (note that **overflowuid** might also be the actual
  2825. * UID value for the socket).
  2826. *
  2827. * long bpf_set_hash(struct sk_buff *skb, u32 hash)
  2828. * Description
  2829. * Set the full hash for *skb* (set the field *skb*\ **->hash**)
  2830. * to value *hash*.
  2831. * Return
  2832. * 0
  2833. *
  2834. * long bpf_setsockopt(void *bpf_socket, int level, int optname, void *optval, int optlen)
  2835. * Description
  2836. * Emulate a call to **setsockopt()** on the socket associated to
  2837. * *bpf_socket*, which must be a full socket. The *level* at
  2838. * which the option resides and the name *optname* of the option
  2839. * must be specified, see **setsockopt(2)** for more information.
  2840. * The option value of length *optlen* is pointed by *optval*.
  2841. *
  2842. * *bpf_socket* should be one of the following:
  2843. *
  2844. * * **struct bpf_sock_ops** for **BPF_PROG_TYPE_SOCK_OPS**.
  2845. * * **struct bpf_sock_addr** for **BPF_CGROUP_INET4_CONNECT**,
  2846. * **BPF_CGROUP_INET6_CONNECT** and **BPF_CGROUP_UNIX_CONNECT**.
  2847. *
  2848. * This helper actually implements a subset of **setsockopt()**.
  2849. * It supports the following *level*\ s:
  2850. *
  2851. * * **SOL_SOCKET**, which supports the following *optname*\ s:
  2852. * **SO_RCVBUF**, **SO_SNDBUF**, **SO_MAX_PACING_RATE**,
  2853. * **SO_PRIORITY**, **SO_RCVLOWAT**, **SO_MARK**,
  2854. * **SO_BINDTODEVICE**, **SO_KEEPALIVE**, **SO_REUSEADDR**,
  2855. * **SO_REUSEPORT**, **SO_BINDTOIFINDEX**, **SO_TXREHASH**.
  2856. * * **IPPROTO_TCP**, which supports the following *optname*\ s:
  2857. * **TCP_CONGESTION**, **TCP_BPF_IW**,
  2858. * **TCP_BPF_SNDCWND_CLAMP**, **TCP_SAVE_SYN**,
  2859. * **TCP_KEEPIDLE**, **TCP_KEEPINTVL**, **TCP_KEEPCNT**,
  2860. * **TCP_SYNCNT**, **TCP_USER_TIMEOUT**, **TCP_NOTSENT_LOWAT**,
  2861. * **TCP_NODELAY**, **TCP_MAXSEG**, **TCP_WINDOW_CLAMP**,
  2862. * **TCP_THIN_LINEAR_TIMEOUTS**, **TCP_BPF_DELACK_MAX**,
  2863. * **TCP_BPF_RTO_MIN**, **TCP_BPF_SOCK_OPS_CB_FLAGS**.
  2864. * * **IPPROTO_IP**, which supports *optname* **IP_TOS**.
  2865. * * **IPPROTO_IPV6**, which supports the following *optname*\ s:
  2866. * **IPV6_TCLASS**, **IPV6_AUTOFLOWLABEL**.
  2867. * Return
  2868. * 0 on success, or a negative error in case of failure.
  2869. *
  2870. * long bpf_skb_adjust_room(struct sk_buff *skb, s32 len_diff, u32 mode, u64 flags)
  2871. * Description
  2872. * Grow or shrink the room for data in the packet associated to
  2873. * *skb* by *len_diff*, and according to the selected *mode*.
  2874. *
  2875. * By default, the helper will reset any offloaded checksum
  2876. * indicator of the skb to CHECKSUM_NONE. This can be avoided
  2877. * by the following flag:
  2878. *
  2879. * * **BPF_F_ADJ_ROOM_NO_CSUM_RESET**: Do not reset offloaded
  2880. * checksum data of the skb to CHECKSUM_NONE.
  2881. *
  2882. * There are two supported modes at this time:
  2883. *
  2884. * * **BPF_ADJ_ROOM_MAC**: Adjust room at the mac layer
  2885. * (room space is added or removed between the layer 2 and
  2886. * layer 3 headers).
  2887. *
  2888. * * **BPF_ADJ_ROOM_NET**: Adjust room at the network layer
  2889. * (room space is added or removed between the layer 3 and
  2890. * layer 4 headers).
  2891. *
  2892. * The following flags are supported at this time:
  2893. *
  2894. * * **BPF_F_ADJ_ROOM_FIXED_GSO**: Do not adjust gso_size.
  2895. * Adjusting mss in this way is not allowed for datagrams.
  2896. *
  2897. * * **BPF_F_ADJ_ROOM_ENCAP_L3_IPV4**,
  2898. * **BPF_F_ADJ_ROOM_ENCAP_L3_IPV6**:
  2899. * Any new space is reserved to hold a tunnel header.
  2900. * Configure skb offsets and other fields accordingly.
  2901. *
  2902. * * **BPF_F_ADJ_ROOM_ENCAP_L4_GRE**,
  2903. * **BPF_F_ADJ_ROOM_ENCAP_L4_UDP**:
  2904. * Use with ENCAP_L3 flags to further specify the tunnel type.
  2905. *
  2906. * * **BPF_F_ADJ_ROOM_ENCAP_L2**\ (*len*):
  2907. * Use with ENCAP_L3/L4 flags to further specify the tunnel
  2908. * type; *len* is the length of the inner MAC header.
  2909. *
  2910. * * **BPF_F_ADJ_ROOM_ENCAP_L2_ETH**:
  2911. * Use with BPF_F_ADJ_ROOM_ENCAP_L2 flag to further specify the
  2912. * L2 type as Ethernet.
  2913. *
  2914. * * **BPF_F_ADJ_ROOM_DECAP_L3_IPV4**,
  2915. * **BPF_F_ADJ_ROOM_DECAP_L3_IPV6**:
  2916. * Indicate the new IP header version after decapsulating the outer
  2917. * IP header. Used when the inner and outer IP versions are different.
  2918. *
  2919. * A call to this helper is susceptible to change the underlying
  2920. * packet buffer. Therefore, at load time, all checks on pointers
  2921. * previously done by the verifier are invalidated and must be
  2922. * performed again, if the helper is used in combination with
  2923. * direct packet access.
  2924. * Return
  2925. * 0 on success, or a negative error in case of failure.
  2926. *
  2927. * long bpf_redirect_map(struct bpf_map *map, u64 key, u64 flags)
  2928. * Description
  2929. * Redirect the packet to the endpoint referenced by *map* at
  2930. * index *key*. Depending on its type, this *map* can contain
  2931. * references to net devices (for forwarding packets through other
  2932. * ports), or to CPUs (for redirecting XDP frames to another CPU;
  2933. * but this is only implemented for native XDP (with driver
  2934. * support) as of this writing).
  2935. *
  2936. * The lower two bits of *flags* are used as the return code if
  2937. * the map lookup fails. This is so that the return value can be
  2938. * one of the XDP program return codes up to **XDP_TX**, as chosen
  2939. * by the caller. The higher bits of *flags* can be set to
  2940. * BPF_F_BROADCAST or BPF_F_EXCLUDE_INGRESS as defined below.
  2941. *
  2942. * With BPF_F_BROADCAST the packet will be broadcasted to all the
  2943. * interfaces in the map, with BPF_F_EXCLUDE_INGRESS the ingress
  2944. * interface will be excluded when do broadcasting.
  2945. *
  2946. * See also **bpf_redirect**\ (), which only supports redirecting
  2947. * to an ifindex, but doesn't require a map to do so.
  2948. * Return
  2949. * **XDP_REDIRECT** on success, or the value of the two lower bits
  2950. * of the *flags* argument on error.
  2951. *
  2952. * long bpf_sk_redirect_map(struct sk_buff *skb, struct bpf_map *map, u32 key, u64 flags)
  2953. * Description
  2954. * Redirect the packet to the socket referenced by *map* (of type
  2955. * **BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and
  2956. * egress interfaces can be used for redirection. The
  2957. * **BPF_F_INGRESS** value in *flags* is used to make the
  2958. * distinction (ingress path is selected if the flag is present,
  2959. * egress path otherwise). This is the only flag supported for now.
  2960. * Return
  2961. * **SK_PASS** on success, or **SK_DROP** on error.
  2962. *
  2963. * long bpf_sock_map_update(struct bpf_sock_ops *skops, struct bpf_map *map, void *key, u64 flags)
  2964. * Description
  2965. * Add an entry to, or update a *map* referencing sockets. The
  2966. * *skops* is used as a new value for the entry associated to
  2967. * *key*. *flags* is one of:
  2968. *
  2969. * **BPF_NOEXIST**
  2970. * The entry for *key* must not exist in the map.
  2971. * **BPF_EXIST**
  2972. * The entry for *key* must already exist in the map.
  2973. * **BPF_ANY**
  2974. * No condition on the existence of the entry for *key*.
  2975. *
  2976. * If the *map* has eBPF programs (parser and verdict), those will
  2977. * be inherited by the socket being added. If the socket is
  2978. * already attached to eBPF programs, this results in an error.
  2979. * Return
  2980. * 0 on success, or a negative error in case of failure.
  2981. *
  2982. * long bpf_xdp_adjust_meta(struct xdp_buff *xdp_md, int delta)
  2983. * Description
  2984. * Adjust the address pointed by *xdp_md*\ **->data_meta** by
  2985. * *delta* (which can be positive or negative). Note that this
  2986. * operation modifies the address stored in *xdp_md*\ **->data**,
  2987. * so the latter must be loaded only after the helper has been
  2988. * called.
  2989. *
  2990. * The use of *xdp_md*\ **->data_meta** is optional and programs
  2991. * are not required to use it. The rationale is that when the
  2992. * packet is processed with XDP (e.g. as DoS filter), it is
  2993. * possible to push further meta data along with it before passing
  2994. * to the stack, and to give the guarantee that an ingress eBPF
  2995. * program attached as a TC classifier on the same device can pick
  2996. * this up for further post-processing. Since TC works with socket
  2997. * buffers, it remains possible to set from XDP the **mark** or
  2998. * **priority** pointers, or other pointers for the socket buffer.
  2999. * Having this scratch space generic and programmable allows for
  3000. * more flexibility as the user is free to store whatever meta
  3001. * data they need.
  3002. *
  3003. * A call to this helper is susceptible to change the underlying
  3004. * packet buffer. Therefore, at load time, all checks on pointers
  3005. * previously done by the verifier are invalidated and must be
  3006. * performed again, if the helper is used in combination with
  3007. * direct packet access.
  3008. * Return
  3009. * 0 on success, or a negative error in case of failure.
  3010. *
  3011. * long bpf_perf_event_read_value(struct bpf_map *map, u64 flags, struct bpf_perf_event_value *buf, u32 buf_size)
  3012. * Description
  3013. * Read the value of a perf event counter, and store it into *buf*
  3014. * of size *buf_size*. This helper relies on a *map* of type
  3015. * **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. The nature of the perf event
  3016. * counter is selected when *map* is updated with perf event file
  3017. * descriptors. The *map* is an array whose size is the number of
  3018. * available CPUs, and each cell contains a value relative to one
  3019. * CPU. The value to retrieve is indicated by *flags*, that
  3020. * contains the index of the CPU to look up, masked with
  3021. * **BPF_F_INDEX_MASK**. Alternatively, *flags* can be set to
  3022. * **BPF_F_CURRENT_CPU** to indicate that the value for the
  3023. * current CPU should be retrieved.
  3024. *
  3025. * This helper behaves in a way close to
  3026. * **bpf_perf_event_read**\ () helper, save that instead of
  3027. * just returning the value observed, it fills the *buf*
  3028. * structure. This allows for additional data to be retrieved: in
  3029. * particular, the enabled and running times (in *buf*\
  3030. * **->enabled** and *buf*\ **->running**, respectively) are
  3031. * copied. In general, **bpf_perf_event_read_value**\ () is
  3032. * recommended over **bpf_perf_event_read**\ (), which has some
  3033. * ABI issues and provides fewer functionalities.
  3034. *
  3035. * These values are interesting, because hardware PMU (Performance
  3036. * Monitoring Unit) counters are limited resources. When there are
  3037. * more PMU based perf events opened than available counters,
  3038. * kernel will multiplex these events so each event gets certain
  3039. * percentage (but not all) of the PMU time. In case that
  3040. * multiplexing happens, the number of samples or counter value
  3041. * will not reflect the case compared to when no multiplexing
  3042. * occurs. This makes comparison between different runs difficult.
  3043. * Typically, the counter value should be normalized before
  3044. * comparing to other experiments. The usual normalization is done
  3045. * as follows.
  3046. *
  3047. * ::
  3048. *
  3049. * normalized_counter = counter * t_enabled / t_running
  3050. *
  3051. * Where t_enabled is the time enabled for event and t_running is
  3052. * the time running for event since last normalization. The
  3053. * enabled and running times are accumulated since the perf event
  3054. * open. To achieve scaling factor between two invocations of an
  3055. * eBPF program, users can use CPU id as the key (which is
  3056. * typical for perf array usage model) to remember the previous
  3057. * value and do the calculation inside the eBPF program.
  3058. * Return
  3059. * 0 on success, or a negative error in case of failure.
  3060. *
  3061. * long bpf_perf_prog_read_value(struct bpf_perf_event_data *ctx, struct bpf_perf_event_value *buf, u32 buf_size)
  3062. * Description
  3063. * For an eBPF program attached to a perf event, retrieve the
  3064. * value of the event counter associated to *ctx* and store it in
  3065. * the structure pointed by *buf* and of size *buf_size*. Enabled
  3066. * and running times are also stored in the structure (see
  3067. * description of helper **bpf_perf_event_read_value**\ () for
  3068. * more details).
  3069. * Return
  3070. * 0 on success, or a negative error in case of failure.
  3071. *
  3072. * long bpf_getsockopt(void *bpf_socket, int level, int optname, void *optval, int optlen)
  3073. * Description
  3074. * Emulate a call to **getsockopt()** on the socket associated to
  3075. * *bpf_socket*, which must be a full socket. The *level* at
  3076. * which the option resides and the name *optname* of the option
  3077. * must be specified, see **getsockopt(2)** for more information.
  3078. * The retrieved value is stored in the structure pointed by
  3079. * *opval* and of length *optlen*.
  3080. *
  3081. * *bpf_socket* should be one of the following:
  3082. *
  3083. * * **struct bpf_sock_ops** for **BPF_PROG_TYPE_SOCK_OPS**.
  3084. * * **struct bpf_sock_addr** for **BPF_CGROUP_INET4_CONNECT**,
  3085. * **BPF_CGROUP_INET6_CONNECT** and **BPF_CGROUP_UNIX_CONNECT**.
  3086. *
  3087. * This helper actually implements a subset of **getsockopt()**.
  3088. * It supports the same set of *optname*\ s that is supported by
  3089. * the **bpf_setsockopt**\ () helper. The exceptions are
  3090. * **TCP_BPF_*** is **bpf_setsockopt**\ () only and
  3091. * **TCP_SAVED_SYN** is **bpf_getsockopt**\ () only.
  3092. * Return
  3093. * 0 on success, or a negative error in case of failure.
  3094. *
  3095. * long bpf_override_return(struct pt_regs *regs, u64 rc)
  3096. * Description
  3097. * Used for error injection, this helper uses kprobes to override
  3098. * the return value of the probed function, and to set it to *rc*.
  3099. * The first argument is the context *regs* on which the kprobe
  3100. * works.
  3101. *
  3102. * This helper works by setting the PC (program counter)
  3103. * to an override function which is run in place of the original
  3104. * probed function. This means the probed function is not run at
  3105. * all. The replacement function just returns with the required
  3106. * value.
  3107. *
  3108. * This helper has security implications, and thus is subject to
  3109. * restrictions. It is only available if the kernel was compiled
  3110. * with the **CONFIG_BPF_KPROBE_OVERRIDE** configuration
  3111. * option, and in this case it only works on functions tagged with
  3112. * **ALLOW_ERROR_INJECTION** in the kernel code.
  3113. * Return
  3114. * 0
  3115. *
  3116. * long bpf_sock_ops_cb_flags_set(struct bpf_sock_ops *bpf_sock, int argval)
  3117. * Description
  3118. * Attempt to set the value of the **bpf_sock_ops_cb_flags** field
  3119. * for the full TCP socket associated to *bpf_sock_ops* to
  3120. * *argval*.
  3121. *
  3122. * The primary use of this field is to determine if there should
  3123. * be calls to eBPF programs of type
  3124. * **BPF_PROG_TYPE_SOCK_OPS** at various points in the TCP
  3125. * code. A program of the same type can change its value, per
  3126. * connection and as necessary, when the connection is
  3127. * established. This field is directly accessible for reading, but
  3128. * this helper must be used for updates in order to return an
  3129. * error if an eBPF program tries to set a callback that is not
  3130. * supported in the current kernel.
  3131. *
  3132. * *argval* is a flag array which can combine these flags:
  3133. *
  3134. * * **BPF_SOCK_OPS_RTO_CB_FLAG** (retransmission time out)
  3135. * * **BPF_SOCK_OPS_RETRANS_CB_FLAG** (retransmission)
  3136. * * **BPF_SOCK_OPS_STATE_CB_FLAG** (TCP state change)
  3137. * * **BPF_SOCK_OPS_RTT_CB_FLAG** (every RTT)
  3138. *
  3139. * Therefore, this function can be used to clear a callback flag by
  3140. * setting the appropriate bit to zero. e.g. to disable the RTO
  3141. * callback:
  3142. *
  3143. * **bpf_sock_ops_cb_flags_set(bpf_sock,**
  3144. * **bpf_sock->bpf_sock_ops_cb_flags & ~BPF_SOCK_OPS_RTO_CB_FLAG)**
  3145. *
  3146. * Here are some examples of where one could call such eBPF
  3147. * program:
  3148. *
  3149. * * When RTO fires.
  3150. * * When a packet is retransmitted.
  3151. * * When the connection terminates.
  3152. * * When a packet is sent.
  3153. * * When a packet is received.
  3154. * Return
  3155. * Code **-EINVAL** if the socket is not a full TCP socket;
  3156. * otherwise, a positive number containing the bits that could not
  3157. * be set is returned (which comes down to 0 if all bits were set
  3158. * as required).
  3159. *
  3160. * long bpf_msg_redirect_map(struct sk_msg_buff *msg, struct bpf_map *map, u32 key, u64 flags)
  3161. * Description
  3162. * This helper is used in programs implementing policies at the
  3163. * socket level. If the message *msg* is allowed to pass (i.e. if
  3164. * the verdict eBPF program returns **SK_PASS**), redirect it to
  3165. * the socket referenced by *map* (of type
  3166. * **BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and
  3167. * egress interfaces can be used for redirection. The
  3168. * **BPF_F_INGRESS** value in *flags* is used to make the
  3169. * distinction (ingress path is selected if the flag is present,
  3170. * egress path otherwise). This is the only flag supported for now.
  3171. * Return
  3172. * **SK_PASS** on success, or **SK_DROP** on error.
  3173. *
  3174. * long bpf_msg_apply_bytes(struct sk_msg_buff *msg, u32 bytes)
  3175. * Description
  3176. * For socket policies, apply the verdict of the eBPF program to
  3177. * the next *bytes* (number of bytes) of message *msg*.
  3178. *
  3179. * For example, this helper can be used in the following cases:
  3180. *
  3181. * * A single **sendmsg**\ () or **sendfile**\ () system call
  3182. * contains multiple logical messages that the eBPF program is
  3183. * supposed to read and for which it should apply a verdict.
  3184. * * An eBPF program only cares to read the first *bytes* of a
  3185. * *msg*. If the message has a large payload, then setting up
  3186. * and calling the eBPF program repeatedly for all bytes, even
  3187. * though the verdict is already known, would create unnecessary
  3188. * overhead.
  3189. *
  3190. * When called from within an eBPF program, the helper sets a
  3191. * counter internal to the BPF infrastructure, that is used to
  3192. * apply the last verdict to the next *bytes*. If *bytes* is
  3193. * smaller than the current data being processed from a
  3194. * **sendmsg**\ () or **sendfile**\ () system call, the first
  3195. * *bytes* will be sent and the eBPF program will be re-run with
  3196. * the pointer for start of data pointing to byte number *bytes*
  3197. * **+ 1**. If *bytes* is larger than the current data being
  3198. * processed, then the eBPF verdict will be applied to multiple
  3199. * **sendmsg**\ () or **sendfile**\ () calls until *bytes* are
  3200. * consumed.
  3201. *
  3202. * Note that if a socket closes with the internal counter holding
  3203. * a non-zero value, this is not a problem because data is not
  3204. * being buffered for *bytes* and is sent as it is received.
  3205. * Return
  3206. * 0
  3207. *
  3208. * long bpf_msg_cork_bytes(struct sk_msg_buff *msg, u32 bytes)
  3209. * Description
  3210. * For socket policies, prevent the execution of the verdict eBPF
  3211. * program for message *msg* until *bytes* (byte number) have been
  3212. * accumulated.
  3213. *
  3214. * This can be used when one needs a specific number of bytes
  3215. * before a verdict can be assigned, even if the data spans
  3216. * multiple **sendmsg**\ () or **sendfile**\ () calls. The extreme
  3217. * case would be a user calling **sendmsg**\ () repeatedly with
  3218. * 1-byte long message segments. Obviously, this is bad for
  3219. * performance, but it is still valid. If the eBPF program needs
  3220. * *bytes* bytes to validate a header, this helper can be used to
  3221. * prevent the eBPF program to be called again until *bytes* have
  3222. * been accumulated.
  3223. * Return
  3224. * 0
  3225. *
  3226. * long bpf_msg_pull_data(struct sk_msg_buff *msg, u32 start, u32 end, u64 flags)
  3227. * Description
  3228. * For socket policies, pull in non-linear data from user space
  3229. * for *msg* and set pointers *msg*\ **->data** and *msg*\
  3230. * **->data_end** to *start* and *end* bytes offsets into *msg*,
  3231. * respectively.
  3232. *
  3233. * If a program of type **BPF_PROG_TYPE_SK_MSG** is run on a
  3234. * *msg* it can only parse data that the (**data**, **data_end**)
  3235. * pointers have already consumed. For **sendmsg**\ () hooks this
  3236. * is likely the first scatterlist element. But for calls relying
  3237. * on the **sendpage** handler (e.g. **sendfile**\ ()) this will
  3238. * be the range (**0**, **0**) because the data is shared with
  3239. * user space and by default the objective is to avoid allowing
  3240. * user space to modify data while (or after) eBPF verdict is
  3241. * being decided. This helper can be used to pull in data and to
  3242. * set the start and end pointer to given values. Data will be
  3243. * copied if necessary (i.e. if data was not linear and if start
  3244. * and end pointers do not point to the same chunk).
  3245. *
  3246. * A call to this helper is susceptible to change the underlying
  3247. * packet buffer. Therefore, at load time, all checks on pointers
  3248. * previously done by the verifier are invalidated and must be
  3249. * performed again, if the helper is used in combination with
  3250. * direct packet access.
  3251. *
  3252. * All values for *flags* are reserved for future usage, and must
  3253. * be left at zero.
  3254. * Return
  3255. * 0 on success, or a negative error in case of failure.
  3256. *
  3257. * long bpf_bind(struct bpf_sock_addr *ctx, struct sockaddr *addr, int addr_len)
  3258. * Description
  3259. * Bind the socket associated to *ctx* to the address pointed by
  3260. * *addr*, of length *addr_len*. This allows for making outgoing
  3261. * connection from the desired IP address, which can be useful for
  3262. * example when all processes inside a cgroup should use one
  3263. * single IP address on a host that has multiple IP configured.
  3264. *
  3265. * This helper works for IPv4 and IPv6, TCP and UDP sockets. The
  3266. * domain (*addr*\ **->sa_family**) must be **AF_INET** (or
  3267. * **AF_INET6**). It's advised to pass zero port (**sin_port**
  3268. * or **sin6_port**) which triggers IP_BIND_ADDRESS_NO_PORT-like
  3269. * behavior and lets the kernel efficiently pick up an unused
  3270. * port as long as 4-tuple is unique. Passing non-zero port might
  3271. * lead to degraded performance.
  3272. * Return
  3273. * 0 on success, or a negative error in case of failure.
  3274. *
  3275. * long bpf_xdp_adjust_tail(struct xdp_buff *xdp_md, int delta)
  3276. * Description
  3277. * Adjust (move) *xdp_md*\ **->data_end** by *delta* bytes. It is
  3278. * possible to both shrink and grow the packet tail.
  3279. * Shrink done via *delta* being a negative integer.
  3280. *
  3281. * A call to this helper is susceptible to change the underlying
  3282. * packet buffer. Therefore, at load time, all checks on pointers
  3283. * previously done by the verifier are invalidated and must be
  3284. * performed again, if the helper is used in combination with
  3285. * direct packet access.
  3286. * Return
  3287. * 0 on success, or a negative error in case of failure.
  3288. *
  3289. * long bpf_skb_get_xfrm_state(struct sk_buff *skb, u32 index, struct bpf_xfrm_state *xfrm_state, u32 size, u64 flags)
  3290. * Description
  3291. * Retrieve the XFRM state (IP transform framework, see also
  3292. * **ip-xfrm(8)**) at *index* in XFRM "security path" for *skb*.
  3293. *
  3294. * The retrieved value is stored in the **struct bpf_xfrm_state**
  3295. * pointed by *xfrm_state* and of length *size*.
  3296. *
  3297. * All values for *flags* are reserved for future usage, and must
  3298. * be left at zero.
  3299. *
  3300. * This helper is available only if the kernel was compiled with
  3301. * **CONFIG_XFRM** configuration option.
  3302. * Return
  3303. * 0 on success, or a negative error in case of failure.
  3304. *
  3305. * long bpf_get_stack(void *ctx, void *buf, u32 size, u64 flags)
  3306. * Description
  3307. * Return a user or a kernel stack in bpf program provided buffer.
  3308. * To achieve this, the helper needs *ctx*, which is a pointer
  3309. * to the context on which the tracing program is executed.
  3310. * To store the stacktrace, the bpf program provides *buf* with
  3311. * a nonnegative *size*.
  3312. *
  3313. * The last argument, *flags*, holds the number of stack frames to
  3314. * skip (from 0 to 255), masked with
  3315. * **BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
  3316. * the following flags:
  3317. *
  3318. * **BPF_F_USER_STACK**
  3319. * Collect a user space stack instead of a kernel stack.
  3320. * **BPF_F_USER_BUILD_ID**
  3321. * Collect (build_id, file_offset) instead of ips for user
  3322. * stack, only valid if **BPF_F_USER_STACK** is also
  3323. * specified.
  3324. *
  3325. * *file_offset* is an offset relative to the beginning
  3326. * of the executable or shared object file backing the vma
  3327. * which the *ip* falls in. It is *not* an offset relative
  3328. * to that object's base address. Accordingly, it must be
  3329. * adjusted by adding (sh_addr - sh_offset), where
  3330. * sh_{addr,offset} correspond to the executable section
  3331. * containing *file_offset* in the object, for comparisons
  3332. * to symbols' st_value to be valid.
  3333. *
  3334. * **bpf_get_stack**\ () can collect up to
  3335. * **PERF_MAX_STACK_DEPTH** both kernel and user frames, subject
  3336. * to sufficient large buffer size. Note that
  3337. * this limit can be controlled with the **sysctl** program, and
  3338. * that it should be manually increased in order to profile long
  3339. * user stacks (such as stacks for Java programs). To do so, use:
  3340. *
  3341. * ::
  3342. *
  3343. * # sysctl kernel.perf_event_max_stack=<new value>
  3344. * Return
  3345. * The non-negative copied *buf* length equal to or less than
  3346. * *size* on success, or a negative error in case of failure.
  3347. *
  3348. * long bpf_skb_load_bytes_relative(const void *skb, u32 offset, void *to, u32 len, u32 start_header)
  3349. * Description
  3350. * This helper is similar to **bpf_skb_load_bytes**\ () in that
  3351. * it provides an easy way to load *len* bytes from *offset*
  3352. * from the packet associated to *skb*, into the buffer pointed
  3353. * by *to*. The difference to **bpf_skb_load_bytes**\ () is that
  3354. * a fifth argument *start_header* exists in order to select a
  3355. * base offset to start from. *start_header* can be one of:
  3356. *
  3357. * **BPF_HDR_START_MAC**
  3358. * Base offset to load data from is *skb*'s mac header.
  3359. * **BPF_HDR_START_NET**
  3360. * Base offset to load data from is *skb*'s network header.
  3361. *
  3362. * In general, "direct packet access" is the preferred method to
  3363. * access packet data, however, this helper is in particular useful
  3364. * in socket filters where *skb*\ **->data** does not always point
  3365. * to the start of the mac header and where "direct packet access"
  3366. * is not available.
  3367. * Return
  3368. * 0 on success, or a negative error in case of failure.
  3369. *
  3370. * long bpf_fib_lookup(void *ctx, struct bpf_fib_lookup *params, int plen, u32 flags)
  3371. * Description
  3372. * Do FIB lookup in kernel tables using parameters in *params*.
  3373. * If lookup is successful and result shows packet is to be
  3374. * forwarded, the neighbor tables are searched for the nexthop.
  3375. * If successful (ie., FIB lookup shows forwarding and nexthop
  3376. * is resolved), the nexthop address is returned in ipv4_dst
  3377. * or ipv6_dst based on family, smac is set to mac address of
  3378. * egress device, dmac is set to nexthop mac address, rt_metric
  3379. * is set to metric from route (IPv4/IPv6 only), and ifindex
  3380. * is set to the device index of the nexthop from the FIB lookup.
  3381. *
  3382. * *plen* argument is the size of the passed in struct.
  3383. * *flags* argument can be a combination of one or more of the
  3384. * following values:
  3385. *
  3386. * **BPF_FIB_LOOKUP_DIRECT**
  3387. * Do a direct table lookup vs full lookup using FIB
  3388. * rules.
  3389. * **BPF_FIB_LOOKUP_TBID**
  3390. * Used with BPF_FIB_LOOKUP_DIRECT.
  3391. * Use the routing table ID present in *params*->tbid
  3392. * for the fib lookup.
  3393. * **BPF_FIB_LOOKUP_OUTPUT**
  3394. * Perform lookup from an egress perspective (default is
  3395. * ingress).
  3396. * **BPF_FIB_LOOKUP_SKIP_NEIGH**
  3397. * Skip the neighbour table lookup. *params*->dmac
  3398. * and *params*->smac will not be set as output. A common
  3399. * use case is to call **bpf_redirect_neigh**\ () after
  3400. * doing **bpf_fib_lookup**\ ().
  3401. * **BPF_FIB_LOOKUP_SRC**
  3402. * Derive and set source IP addr in *params*->ipv{4,6}_src
  3403. * for the nexthop. If the src addr cannot be derived,
  3404. * **BPF_FIB_LKUP_RET_NO_SRC_ADDR** is returned. In this
  3405. * case, *params*->dmac and *params*->smac are not set either.
  3406. * **BPF_FIB_LOOKUP_MARK**
  3407. * Use the mark present in *params*->mark for the fib lookup.
  3408. * This option should not be used with BPF_FIB_LOOKUP_DIRECT,
  3409. * as it only has meaning for full lookups.
  3410. *
  3411. * *ctx* is either **struct xdp_md** for XDP programs or
  3412. * **struct sk_buff** tc cls_act programs.
  3413. * Return
  3414. * * < 0 if any input argument is invalid
  3415. * * 0 on success (packet is forwarded, nexthop neighbor exists)
  3416. * * > 0 one of **BPF_FIB_LKUP_RET_** codes explaining why the
  3417. * packet is not forwarded or needs assist from full stack
  3418. *
  3419. * If lookup fails with BPF_FIB_LKUP_RET_FRAG_NEEDED, then the MTU
  3420. * was exceeded and output params->mtu_result contains the MTU.
  3421. *
  3422. * long bpf_sock_hash_update(struct bpf_sock_ops *skops, struct bpf_map *map, void *key, u64 flags)
  3423. * Description
  3424. * Add an entry to, or update a sockhash *map* referencing sockets.
  3425. * The *skops* is used as a new value for the entry associated to
  3426. * *key*. *flags* is one of:
  3427. *
  3428. * **BPF_NOEXIST**
  3429. * The entry for *key* must not exist in the map.
  3430. * **BPF_EXIST**
  3431. * The entry for *key* must already exist in the map.
  3432. * **BPF_ANY**
  3433. * No condition on the existence of the entry for *key*.
  3434. *
  3435. * If the *map* has eBPF programs (parser and verdict), those will
  3436. * be inherited by the socket being added. If the socket is
  3437. * already attached to eBPF programs, this results in an error.
  3438. * Return
  3439. * 0 on success, or a negative error in case of failure.
  3440. *
  3441. * long bpf_msg_redirect_hash(struct sk_msg_buff *msg, struct bpf_map *map, void *key, u64 flags)
  3442. * Description
  3443. * This helper is used in programs implementing policies at the
  3444. * socket level. If the message *msg* is allowed to pass (i.e. if
  3445. * the verdict eBPF program returns **SK_PASS**), redirect it to
  3446. * the socket referenced by *map* (of type
  3447. * **BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and
  3448. * egress interfaces can be used for redirection. The
  3449. * **BPF_F_INGRESS** value in *flags* is used to make the
  3450. * distinction (ingress path is selected if the flag is present,
  3451. * egress path otherwise). This is the only flag supported for now.
  3452. * Return
  3453. * **SK_PASS** on success, or **SK_DROP** on error.
  3454. *
  3455. * long bpf_sk_redirect_hash(struct sk_buff *skb, struct bpf_map *map, void *key, u64 flags)
  3456. * Description
  3457. * This helper is used in programs implementing policies at the
  3458. * skb socket level. If the sk_buff *skb* is allowed to pass (i.e.
  3459. * if the verdict eBPF program returns **SK_PASS**), redirect it
  3460. * to the socket referenced by *map* (of type
  3461. * **BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and
  3462. * egress interfaces can be used for redirection. The
  3463. * **BPF_F_INGRESS** value in *flags* is used to make the
  3464. * distinction (ingress path is selected if the flag is present,
  3465. * egress otherwise). This is the only flag supported for now.
  3466. * Return
  3467. * **SK_PASS** on success, or **SK_DROP** on error.
  3468. *
  3469. * long bpf_lwt_push_encap(struct sk_buff *skb, u32 type, void *hdr, u32 len)
  3470. * Description
  3471. * Encapsulate the packet associated to *skb* within a Layer 3
  3472. * protocol header. This header is provided in the buffer at
  3473. * address *hdr*, with *len* its size in bytes. *type* indicates
  3474. * the protocol of the header and can be one of:
  3475. *
  3476. * **BPF_LWT_ENCAP_SEG6**
  3477. * IPv6 encapsulation with Segment Routing Header
  3478. * (**struct ipv6_sr_hdr**). *hdr* only contains the SRH,
  3479. * the IPv6 header is computed by the kernel.
  3480. * **BPF_LWT_ENCAP_SEG6_INLINE**
  3481. * Only works if *skb* contains an IPv6 packet. Insert a
  3482. * Segment Routing Header (**struct ipv6_sr_hdr**) inside
  3483. * the IPv6 header.
  3484. * **BPF_LWT_ENCAP_IP**
  3485. * IP encapsulation (GRE/GUE/IPIP/etc). The outer header
  3486. * must be IPv4 or IPv6, followed by zero or more
  3487. * additional headers, up to **LWT_BPF_MAX_HEADROOM**
  3488. * total bytes in all prepended headers. Please note that
  3489. * if **skb_is_gso**\ (*skb*) is true, no more than two
  3490. * headers can be prepended, and the inner header, if
  3491. * present, should be either GRE or UDP/GUE.
  3492. *
  3493. * **BPF_LWT_ENCAP_SEG6**\ \* types can be called by BPF programs
  3494. * of type **BPF_PROG_TYPE_LWT_IN**; **BPF_LWT_ENCAP_IP** type can
  3495. * be called by bpf programs of types **BPF_PROG_TYPE_LWT_IN** and
  3496. * **BPF_PROG_TYPE_LWT_XMIT**.
  3497. *
  3498. * A call to this helper is susceptible to change the underlying
  3499. * packet buffer. Therefore, at load time, all checks on pointers
  3500. * previously done by the verifier are invalidated and must be
  3501. * performed again, if the helper is used in combination with
  3502. * direct packet access.
  3503. * Return
  3504. * 0 on success, or a negative error in case of failure.
  3505. *
  3506. * long bpf_lwt_seg6_store_bytes(struct sk_buff *skb, u32 offset, const void *from, u32 len)
  3507. * Description
  3508. * Store *len* bytes from address *from* into the packet
  3509. * associated to *skb*, at *offset*. Only the flags, tag and TLVs
  3510. * inside the outermost IPv6 Segment Routing Header can be
  3511. * modified through this helper.
  3512. *
  3513. * A call to this helper is susceptible to change the underlying
  3514. * packet buffer. Therefore, at load time, all checks on pointers
  3515. * previously done by the verifier are invalidated and must be
  3516. * performed again, if the helper is used in combination with
  3517. * direct packet access.
  3518. * Return
  3519. * 0 on success, or a negative error in case of failure.
  3520. *
  3521. * long bpf_lwt_seg6_adjust_srh(struct sk_buff *skb, u32 offset, s32 delta)
  3522. * Description
  3523. * Adjust the size allocated to TLVs in the outermost IPv6
  3524. * Segment Routing Header contained in the packet associated to
  3525. * *skb*, at position *offset* by *delta* bytes. Only offsets
  3526. * after the segments are accepted. *delta* can be as well
  3527. * positive (growing) as negative (shrinking).
  3528. *
  3529. * A call to this helper is susceptible to change the underlying
  3530. * packet buffer. Therefore, at load time, all checks on pointers
  3531. * previously done by the verifier are invalidated and must be
  3532. * performed again, if the helper is used in combination with
  3533. * direct packet access.
  3534. * Return
  3535. * 0 on success, or a negative error in case of failure.
  3536. *
  3537. * long bpf_lwt_seg6_action(struct sk_buff *skb, u32 action, void *param, u32 param_len)
  3538. * Description
  3539. * Apply an IPv6 Segment Routing action of type *action* to the
  3540. * packet associated to *skb*. Each action takes a parameter
  3541. * contained at address *param*, and of length *param_len* bytes.
  3542. * *action* can be one of:
  3543. *
  3544. * **SEG6_LOCAL_ACTION_END_X**
  3545. * End.X action: Endpoint with Layer-3 cross-connect.
  3546. * Type of *param*: **struct in6_addr**.
  3547. * **SEG6_LOCAL_ACTION_END_T**
  3548. * End.T action: Endpoint with specific IPv6 table lookup.
  3549. * Type of *param*: **int**.
  3550. * **SEG6_LOCAL_ACTION_END_B6**
  3551. * End.B6 action: Endpoint bound to an SRv6 policy.
  3552. * Type of *param*: **struct ipv6_sr_hdr**.
  3553. * **SEG6_LOCAL_ACTION_END_B6_ENCAP**
  3554. * End.B6.Encap action: Endpoint bound to an SRv6
  3555. * encapsulation policy.
  3556. * Type of *param*: **struct ipv6_sr_hdr**.
  3557. *
  3558. * A call to this helper is susceptible to change the underlying
  3559. * packet buffer. Therefore, at load time, all checks on pointers
  3560. * previously done by the verifier are invalidated and must be
  3561. * performed again, if the helper is used in combination with
  3562. * direct packet access.
  3563. * Return
  3564. * 0 on success, or a negative error in case of failure.
  3565. *
  3566. * long bpf_rc_repeat(void *ctx)
  3567. * Description
  3568. * This helper is used in programs implementing IR decoding, to
  3569. * report a successfully decoded repeat key message. This delays
  3570. * the generation of a key up event for previously generated
  3571. * key down event.
  3572. *
  3573. * Some IR protocols like NEC have a special IR message for
  3574. * repeating last button, for when a button is held down.
  3575. *
  3576. * The *ctx* should point to the lirc sample as passed into
  3577. * the program.
  3578. *
  3579. * This helper is only available is the kernel was compiled with
  3580. * the **CONFIG_BPF_LIRC_MODE2** configuration option set to
  3581. * "**y**".
  3582. * Return
  3583. * 0
  3584. *
  3585. * long bpf_rc_keydown(void *ctx, u32 protocol, u64 scancode, u32 toggle)
  3586. * Description
  3587. * This helper is used in programs implementing IR decoding, to
  3588. * report a successfully decoded key press with *scancode*,
  3589. * *toggle* value in the given *protocol*. The scancode will be
  3590. * translated to a keycode using the rc keymap, and reported as
  3591. * an input key down event. After a period a key up event is
  3592. * generated. This period can be extended by calling either
  3593. * **bpf_rc_keydown**\ () again with the same values, or calling
  3594. * **bpf_rc_repeat**\ ().
  3595. *
  3596. * Some protocols include a toggle bit, in case the button was
  3597. * released and pressed again between consecutive scancodes.
  3598. *
  3599. * The *ctx* should point to the lirc sample as passed into
  3600. * the program.
  3601. *
  3602. * The *protocol* is the decoded protocol number (see
  3603. * **enum rc_proto** for some predefined values).
  3604. *
  3605. * This helper is only available is the kernel was compiled with
  3606. * the **CONFIG_BPF_LIRC_MODE2** configuration option set to
  3607. * "**y**".
  3608. * Return
  3609. * 0
  3610. *
  3611. * u64 bpf_skb_cgroup_id(struct sk_buff *skb)
  3612. * Description
  3613. * Return the cgroup v2 id of the socket associated with the *skb*.
  3614. * This is roughly similar to the **bpf_get_cgroup_classid**\ ()
  3615. * helper for cgroup v1 by providing a tag resp. identifier that
  3616. * can be matched on or used for map lookups e.g. to implement
  3617. * policy. The cgroup v2 id of a given path in the hierarchy is
  3618. * exposed in user space through the f_handle API in order to get
  3619. * to the same 64-bit id.
  3620. *
  3621. * This helper can be used on TC egress path, but not on ingress,
  3622. * and is available only if the kernel was compiled with the
  3623. * **CONFIG_SOCK_CGROUP_DATA** configuration option.
  3624. * Return
  3625. * The id is returned or 0 in case the id could not be retrieved.
  3626. *
  3627. * u64 bpf_get_current_cgroup_id(void)
  3628. * Description
  3629. * Get the current cgroup id based on the cgroup within which
  3630. * the current task is running.
  3631. * Return
  3632. * A 64-bit integer containing the current cgroup id based
  3633. * on the cgroup within which the current task is running.
  3634. *
  3635. * void *bpf_get_local_storage(void *map, u64 flags)
  3636. * Description
  3637. * Get the pointer to the local storage area.
  3638. * The type and the size of the local storage is defined
  3639. * by the *map* argument.
  3640. * The *flags* meaning is specific for each map type,
  3641. * and has to be 0 for cgroup local storage.
  3642. *
  3643. * Depending on the BPF program type, a local storage area
  3644. * can be shared between multiple instances of the BPF program,
  3645. * running simultaneously.
  3646. *
  3647. * A user should care about the synchronization by himself.
  3648. * For example, by using the **BPF_ATOMIC** instructions to alter
  3649. * the shared data.
  3650. * Return
  3651. * A pointer to the local storage area.
  3652. *
  3653. * long bpf_sk_select_reuseport(struct sk_reuseport_md *reuse, struct bpf_map *map, void *key, u64 flags)
  3654. * Description
  3655. * Select a **SO_REUSEPORT** socket from a
  3656. * **BPF_MAP_TYPE_REUSEPORT_SOCKARRAY** *map*.
  3657. * It checks the selected socket is matching the incoming
  3658. * request in the socket buffer.
  3659. * Return
  3660. * 0 on success, or a negative error in case of failure.
  3661. *
  3662. * u64 bpf_skb_ancestor_cgroup_id(struct sk_buff *skb, int ancestor_level)
  3663. * Description
  3664. * Return id of cgroup v2 that is ancestor of cgroup associated
  3665. * with the *skb* at the *ancestor_level*. The root cgroup is at
  3666. * *ancestor_level* zero and each step down the hierarchy
  3667. * increments the level. If *ancestor_level* == level of cgroup
  3668. * associated with *skb*, then return value will be same as that
  3669. * of **bpf_skb_cgroup_id**\ ().
  3670. *
  3671. * The helper is useful to implement policies based on cgroups
  3672. * that are upper in hierarchy than immediate cgroup associated
  3673. * with *skb*.
  3674. *
  3675. * The format of returned id and helper limitations are same as in
  3676. * **bpf_skb_cgroup_id**\ ().
  3677. * Return
  3678. * The id is returned or 0 in case the id could not be retrieved.
  3679. *
  3680. * struct bpf_sock *bpf_sk_lookup_tcp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
  3681. * Description
  3682. * Look for TCP socket matching *tuple*, optionally in a child
  3683. * network namespace *netns*. The return value must be checked,
  3684. * and if non-**NULL**, released via **bpf_sk_release**\ ().
  3685. *
  3686. * The *ctx* should point to the context of the program, such as
  3687. * the skb or socket (depending on the hook in use). This is used
  3688. * to determine the base network namespace for the lookup.
  3689. *
  3690. * *tuple_size* must be one of:
  3691. *
  3692. * **sizeof**\ (*tuple*\ **->ipv4**)
  3693. * Look for an IPv4 socket.
  3694. * **sizeof**\ (*tuple*\ **->ipv6**)
  3695. * Look for an IPv6 socket.
  3696. *
  3697. * If the *netns* is a negative signed 32-bit integer, then the
  3698. * socket lookup table in the netns associated with the *ctx*
  3699. * will be used. For the TC hooks, this is the netns of the device
  3700. * in the skb. For socket hooks, this is the netns of the socket.
  3701. * If *netns* is any other signed 32-bit value greater than or
  3702. * equal to zero then it specifies the ID of the netns relative to
  3703. * the netns associated with the *ctx*. *netns* values beyond the
  3704. * range of 32-bit integers are reserved for future use.
  3705. *
  3706. * All values for *flags* are reserved for future usage, and must
  3707. * be left at zero.
  3708. *
  3709. * This helper is available only if the kernel was compiled with
  3710. * **CONFIG_NET** configuration option.
  3711. * Return
  3712. * Pointer to **struct bpf_sock**, or **NULL** in case of failure.
  3713. * For sockets with reuseport option, the **struct bpf_sock**
  3714. * result is from *reuse*\ **->socks**\ [] using the hash of the
  3715. * tuple.
  3716. *
  3717. * struct bpf_sock *bpf_sk_lookup_udp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
  3718. * Description
  3719. * Look for UDP socket matching *tuple*, optionally in a child
  3720. * network namespace *netns*. The return value must be checked,
  3721. * and if non-**NULL**, released via **bpf_sk_release**\ ().
  3722. *
  3723. * The *ctx* should point to the context of the program, such as
  3724. * the skb or socket (depending on the hook in use). This is used
  3725. * to determine the base network namespace for the lookup.
  3726. *
  3727. * *tuple_size* must be one of:
  3728. *
  3729. * **sizeof**\ (*tuple*\ **->ipv4**)
  3730. * Look for an IPv4 socket.
  3731. * **sizeof**\ (*tuple*\ **->ipv6**)
  3732. * Look for an IPv6 socket.
  3733. *
  3734. * If the *netns* is a negative signed 32-bit integer, then the
  3735. * socket lookup table in the netns associated with the *ctx*
  3736. * will be used. For the TC hooks, this is the netns of the device
  3737. * in the skb. For socket hooks, this is the netns of the socket.
  3738. * If *netns* is any other signed 32-bit value greater than or
  3739. * equal to zero then it specifies the ID of the netns relative to
  3740. * the netns associated with the *ctx*. *netns* values beyond the
  3741. * range of 32-bit integers are reserved for future use.
  3742. *
  3743. * All values for *flags* are reserved for future usage, and must
  3744. * be left at zero.
  3745. *
  3746. * This helper is available only if the kernel was compiled with
  3747. * **CONFIG_NET** configuration option.
  3748. * Return
  3749. * Pointer to **struct bpf_sock**, or **NULL** in case of failure.
  3750. * For sockets with reuseport option, the **struct bpf_sock**
  3751. * result is from *reuse*\ **->socks**\ [] using the hash of the
  3752. * tuple.
  3753. *
  3754. * long bpf_sk_release(void *sock)
  3755. * Description
  3756. * Release the reference held by *sock*. *sock* must be a
  3757. * non-**NULL** pointer that was returned from
  3758. * **bpf_sk_lookup_xxx**\ ().
  3759. * Return
  3760. * 0 on success, or a negative error in case of failure.
  3761. *
  3762. * long bpf_map_push_elem(struct bpf_map *map, const void *value, u64 flags)
  3763. * Description
  3764. * Push an element *value* in *map*. *flags* is one of:
  3765. *
  3766. * **BPF_EXIST**
  3767. * If the queue/stack is full, the oldest element is
  3768. * removed to make room for this.
  3769. * Return
  3770. * 0 on success, or a negative error in case of failure.
  3771. *
  3772. * long bpf_map_pop_elem(struct bpf_map *map, void *value)
  3773. * Description
  3774. * Pop an element from *map*.
  3775. * Return
  3776. * 0 on success, or a negative error in case of failure.
  3777. *
  3778. * long bpf_map_peek_elem(struct bpf_map *map, void *value)
  3779. * Description
  3780. * Get an element from *map* without removing it.
  3781. * Return
  3782. * 0 on success, or a negative error in case of failure.
  3783. *
  3784. * long bpf_msg_push_data(struct sk_msg_buff *msg, u32 start, u32 len, u64 flags)
  3785. * Description
  3786. * For socket policies, insert *len* bytes into *msg* at offset
  3787. * *start*.
  3788. *
  3789. * If a program of type **BPF_PROG_TYPE_SK_MSG** is run on a
  3790. * *msg* it may want to insert metadata or options into the *msg*.
  3791. * This can later be read and used by any of the lower layer BPF
  3792. * hooks.
  3793. *
  3794. * This helper may fail if under memory pressure (a malloc
  3795. * fails) in these cases BPF programs will get an appropriate
  3796. * error and BPF programs will need to handle them.
  3797. * Return
  3798. * 0 on success, or a negative error in case of failure.
  3799. *
  3800. * long bpf_msg_pop_data(struct sk_msg_buff *msg, u32 start, u32 len, u64 flags)
  3801. * Description
  3802. * Will remove *len* bytes from a *msg* starting at byte *start*.
  3803. * This may result in **ENOMEM** errors under certain situations if
  3804. * an allocation and copy are required due to a full ring buffer.
  3805. * However, the helper will try to avoid doing the allocation
  3806. * if possible. Other errors can occur if input parameters are
  3807. * invalid either due to *start* byte not being valid part of *msg*
  3808. * payload and/or *pop* value being to large.
  3809. * Return
  3810. * 0 on success, or a negative error in case of failure.
  3811. *
  3812. * long bpf_rc_pointer_rel(void *ctx, s32 rel_x, s32 rel_y)
  3813. * Description
  3814. * This helper is used in programs implementing IR decoding, to
  3815. * report a successfully decoded pointer movement.
  3816. *
  3817. * The *ctx* should point to the lirc sample as passed into
  3818. * the program.
  3819. *
  3820. * This helper is only available is the kernel was compiled with
  3821. * the **CONFIG_BPF_LIRC_MODE2** configuration option set to
  3822. * "**y**".
  3823. * Return
  3824. * 0
  3825. *
  3826. * long bpf_spin_lock(struct bpf_spin_lock *lock)
  3827. * Description
  3828. * Acquire a spinlock represented by the pointer *lock*, which is
  3829. * stored as part of a value of a map. Taking the lock allows to
  3830. * safely update the rest of the fields in that value. The
  3831. * spinlock can (and must) later be released with a call to
  3832. * **bpf_spin_unlock**\ (\ *lock*\ ).
  3833. *
  3834. * Spinlocks in BPF programs come with a number of restrictions
  3835. * and constraints:
  3836. *
  3837. * * **bpf_spin_lock** objects are only allowed inside maps of
  3838. * types **BPF_MAP_TYPE_HASH** and **BPF_MAP_TYPE_ARRAY** (this
  3839. * list could be extended in the future).
  3840. * * BTF description of the map is mandatory.
  3841. * * The BPF program can take ONE lock at a time, since taking two
  3842. * or more could cause dead locks.
  3843. * * Only one **struct bpf_spin_lock** is allowed per map element.
  3844. * * When the lock is taken, calls (either BPF to BPF or helpers)
  3845. * are not allowed.
  3846. * * The **BPF_LD_ABS** and **BPF_LD_IND** instructions are not
  3847. * allowed inside a spinlock-ed region.
  3848. * * The BPF program MUST call **bpf_spin_unlock**\ () to release
  3849. * the lock, on all execution paths, before it returns.
  3850. * * The BPF program can access **struct bpf_spin_lock** only via
  3851. * the **bpf_spin_lock**\ () and **bpf_spin_unlock**\ ()
  3852. * helpers. Loading or storing data into the **struct
  3853. * bpf_spin_lock** *lock*\ **;** field of a map is not allowed.
  3854. * * To use the **bpf_spin_lock**\ () helper, the BTF description
  3855. * of the map value must be a struct and have **struct
  3856. * bpf_spin_lock** *anyname*\ **;** field at the top level.
  3857. * Nested lock inside another struct is not allowed.
  3858. * * The **struct bpf_spin_lock** *lock* field in a map value must
  3859. * be aligned on a multiple of 4 bytes in that value.
  3860. * * Syscall with command **BPF_MAP_LOOKUP_ELEM** does not copy
  3861. * the **bpf_spin_lock** field to user space.
  3862. * * Syscall with command **BPF_MAP_UPDATE_ELEM**, or update from
  3863. * a BPF program, do not update the **bpf_spin_lock** field.
  3864. * * **bpf_spin_lock** cannot be on the stack or inside a
  3865. * networking packet (it can only be inside of a map values).
  3866. * * **bpf_spin_lock** is available to root only.
  3867. * * Tracing programs and socket filter programs cannot use
  3868. * **bpf_spin_lock**\ () due to insufficient preemption checks
  3869. * (but this may change in the future).
  3870. * * **bpf_spin_lock** is not allowed in inner maps of map-in-map.
  3871. * Return
  3872. * 0
  3873. *
  3874. * long bpf_spin_unlock(struct bpf_spin_lock *lock)
  3875. * Description
  3876. * Release the *lock* previously locked by a call to
  3877. * **bpf_spin_lock**\ (\ *lock*\ ).
  3878. * Return
  3879. * 0
  3880. *
  3881. * struct bpf_sock *bpf_sk_fullsock(struct bpf_sock *sk)
  3882. * Description
  3883. * This helper gets a **struct bpf_sock** pointer such
  3884. * that all the fields in this **bpf_sock** can be accessed.
  3885. * Return
  3886. * A **struct bpf_sock** pointer on success, or **NULL** in
  3887. * case of failure.
  3888. *
  3889. * struct bpf_tcp_sock *bpf_tcp_sock(struct bpf_sock *sk)
  3890. * Description
  3891. * This helper gets a **struct bpf_tcp_sock** pointer from a
  3892. * **struct bpf_sock** pointer.
  3893. * Return
  3894. * A **struct bpf_tcp_sock** pointer on success, or **NULL** in
  3895. * case of failure.
  3896. *
  3897. * long bpf_skb_ecn_set_ce(struct sk_buff *skb)
  3898. * Description
  3899. * Set ECN (Explicit Congestion Notification) field of IP header
  3900. * to **CE** (Congestion Encountered) if current value is **ECT**
  3901. * (ECN Capable Transport). Otherwise, do nothing. Works with IPv6
  3902. * and IPv4.
  3903. * Return
  3904. * 1 if the **CE** flag is set (either by the current helper call
  3905. * or because it was already present), 0 if it is not set.
  3906. *
  3907. * struct bpf_sock *bpf_get_listener_sock(struct bpf_sock *sk)
  3908. * Description
  3909. * Return a **struct bpf_sock** pointer in **TCP_LISTEN** state.
  3910. * **bpf_sk_release**\ () is unnecessary and not allowed.
  3911. * Return
  3912. * A **struct bpf_sock** pointer on success, or **NULL** in
  3913. * case of failure.
  3914. *
  3915. * struct bpf_sock *bpf_skc_lookup_tcp(void *ctx, struct bpf_sock_tuple *tuple, u32 tuple_size, u64 netns, u64 flags)
  3916. * Description
  3917. * Look for TCP socket matching *tuple*, optionally in a child
  3918. * network namespace *netns*. The return value must be checked,
  3919. * and if non-**NULL**, released via **bpf_sk_release**\ ().
  3920. *
  3921. * This function is identical to **bpf_sk_lookup_tcp**\ (), except
  3922. * that it also returns timewait or request sockets. Use
  3923. * **bpf_sk_fullsock**\ () or **bpf_tcp_sock**\ () to access the
  3924. * full structure.
  3925. *
  3926. * This helper is available only if the kernel was compiled with
  3927. * **CONFIG_NET** configuration option.
  3928. * Return
  3929. * Pointer to **struct bpf_sock**, or **NULL** in case of failure.
  3930. * For sockets with reuseport option, the **struct bpf_sock**
  3931. * result is from *reuse*\ **->socks**\ [] using the hash of the
  3932. * tuple.
  3933. *
  3934. * long bpf_tcp_check_syncookie(void *sk, void *iph, u32 iph_len, struct tcphdr *th, u32 th_len)
  3935. * Description
  3936. * Check whether *iph* and *th* contain a valid SYN cookie ACK for
  3937. * the listening socket in *sk*.
  3938. *
  3939. * *iph* points to the start of the IPv4 or IPv6 header, while
  3940. * *iph_len* contains **sizeof**\ (**struct iphdr**) or
  3941. * **sizeof**\ (**struct ipv6hdr**).
  3942. *
  3943. * *th* points to the start of the TCP header, while *th_len*
  3944. * contains the length of the TCP header (at least
  3945. * **sizeof**\ (**struct tcphdr**)).
  3946. * Return
  3947. * 0 if *iph* and *th* are a valid SYN cookie ACK, or a negative
  3948. * error otherwise.
  3949. *
  3950. * long bpf_sysctl_get_name(struct bpf_sysctl *ctx, char *buf, size_t buf_len, u64 flags)
  3951. * Description
  3952. * Get name of sysctl in /proc/sys/ and copy it into provided by
  3953. * program buffer *buf* of size *buf_len*.
  3954. *
  3955. * The buffer is always NUL terminated, unless it's zero-sized.
  3956. *
  3957. * If *flags* is zero, full name (e.g. "net/ipv4/tcp_mem") is
  3958. * copied. Use **BPF_F_SYSCTL_BASE_NAME** flag to copy base name
  3959. * only (e.g. "tcp_mem").
  3960. * Return
  3961. * Number of character copied (not including the trailing NUL).
  3962. *
  3963. * **-E2BIG** if the buffer wasn't big enough (*buf* will contain
  3964. * truncated name in this case).
  3965. *
  3966. * long bpf_sysctl_get_current_value(struct bpf_sysctl *ctx, char *buf, size_t buf_len)
  3967. * Description
  3968. * Get current value of sysctl as it is presented in /proc/sys
  3969. * (incl. newline, etc), and copy it as a string into provided
  3970. * by program buffer *buf* of size *buf_len*.
  3971. *
  3972. * The whole value is copied, no matter what file position user
  3973. * space issued e.g. sys_read at.
  3974. *
  3975. * The buffer is always NUL terminated, unless it's zero-sized.
  3976. * Return
  3977. * Number of character copied (not including the trailing NUL).
  3978. *
  3979. * **-E2BIG** if the buffer wasn't big enough (*buf* will contain
  3980. * truncated name in this case).
  3981. *
  3982. * **-EINVAL** if current value was unavailable, e.g. because
  3983. * sysctl is uninitialized and read returns -EIO for it.
  3984. *
  3985. * long bpf_sysctl_get_new_value(struct bpf_sysctl *ctx, char *buf, size_t buf_len)
  3986. * Description
  3987. * Get new value being written by user space to sysctl (before
  3988. * the actual write happens) and copy it as a string into
  3989. * provided by program buffer *buf* of size *buf_len*.
  3990. *
  3991. * User space may write new value at file position > 0.
  3992. *
  3993. * The buffer is always NUL terminated, unless it's zero-sized.
  3994. * Return
  3995. * Number of character copied (not including the trailing NUL).
  3996. *
  3997. * **-E2BIG** if the buffer wasn't big enough (*buf* will contain
  3998. * truncated name in this case).
  3999. *
  4000. * **-EINVAL** if sysctl is being read.
  4001. *
  4002. * long bpf_sysctl_set_new_value(struct bpf_sysctl *ctx, const char *buf, size_t buf_len)
  4003. * Description
  4004. * Override new value being written by user space to sysctl with
  4005. * value provided by program in buffer *buf* of size *buf_len*.
  4006. *
  4007. * *buf* should contain a string in same form as provided by user
  4008. * space on sysctl write.
  4009. *
  4010. * User space may write new value at file position > 0. To override
  4011. * the whole sysctl value file position should be set to zero.
  4012. * Return
  4013. * 0 on success.
  4014. *
  4015. * **-E2BIG** if the *buf_len* is too big.
  4016. *
  4017. * **-EINVAL** if sysctl is being read.
  4018. *
  4019. * long bpf_strtol(const char *buf, size_t buf_len, u64 flags, long *res)
  4020. * Description
  4021. * Convert the initial part of the string from buffer *buf* of
  4022. * size *buf_len* to a long integer according to the given base
  4023. * and save the result in *res*.
  4024. *
  4025. * The string may begin with an arbitrary amount of white space
  4026. * (as determined by **isspace**\ (3)) followed by a single
  4027. * optional '**-**' sign.
  4028. *
  4029. * Five least significant bits of *flags* encode base, other bits
  4030. * are currently unused.
  4031. *
  4032. * Base must be either 8, 10, 16 or 0 to detect it automatically
  4033. * similar to user space **strtol**\ (3).
  4034. * Return
  4035. * Number of characters consumed on success. Must be positive but
  4036. * no more than *buf_len*.
  4037. *
  4038. * **-EINVAL** if no valid digits were found or unsupported base
  4039. * was provided.
  4040. *
  4041. * **-ERANGE** if resulting value was out of range.
  4042. *
  4043. * long bpf_strtoul(const char *buf, size_t buf_len, u64 flags, unsigned long *res)
  4044. * Description
  4045. * Convert the initial part of the string from buffer *buf* of
  4046. * size *buf_len* to an unsigned long integer according to the
  4047. * given base and save the result in *res*.
  4048. *
  4049. * The string may begin with an arbitrary amount of white space
  4050. * (as determined by **isspace**\ (3)).
  4051. *
  4052. * Five least significant bits of *flags* encode base, other bits
  4053. * are currently unused.
  4054. *
  4055. * Base must be either 8, 10, 16 or 0 to detect it automatically
  4056. * similar to user space **strtoul**\ (3).
  4057. * Return
  4058. * Number of characters consumed on success. Must be positive but
  4059. * no more than *buf_len*.
  4060. *
  4061. * **-EINVAL** if no valid digits were found or unsupported base
  4062. * was provided.
  4063. *
  4064. * **-ERANGE** if resulting value was out of range.
  4065. *
  4066. * void *bpf_sk_storage_get(struct bpf_map *map, void *sk, void *value, u64 flags)
  4067. * Description
  4068. * Get a bpf-local-storage from a *sk*.
  4069. *
  4070. * Logically, it could be thought of getting the value from
  4071. * a *map* with *sk* as the **key**. From this
  4072. * perspective, the usage is not much different from
  4073. * **bpf_map_lookup_elem**\ (*map*, **&**\ *sk*) except this
  4074. * helper enforces the key must be a full socket and the map must
  4075. * be a **BPF_MAP_TYPE_SK_STORAGE** also.
  4076. *
  4077. * Underneath, the value is stored locally at *sk* instead of
  4078. * the *map*. The *map* is used as the bpf-local-storage
  4079. * "type". The bpf-local-storage "type" (i.e. the *map*) is
  4080. * searched against all bpf-local-storages residing at *sk*.
  4081. *
  4082. * *sk* is a kernel **struct sock** pointer for LSM program.
  4083. * *sk* is a **struct bpf_sock** pointer for other program types.
  4084. *
  4085. * An optional *flags* (**BPF_SK_STORAGE_GET_F_CREATE**) can be
  4086. * used such that a new bpf-local-storage will be
  4087. * created if one does not exist. *value* can be used
  4088. * together with **BPF_SK_STORAGE_GET_F_CREATE** to specify
  4089. * the initial value of a bpf-local-storage. If *value* is
  4090. * **NULL**, the new bpf-local-storage will be zero initialized.
  4091. * Return
  4092. * A bpf-local-storage pointer is returned on success.
  4093. *
  4094. * **NULL** if not found or there was an error in adding
  4095. * a new bpf-local-storage.
  4096. *
  4097. * long bpf_sk_storage_delete(struct bpf_map *map, void *sk)
  4098. * Description
  4099. * Delete a bpf-local-storage from a *sk*.
  4100. * Return
  4101. * 0 on success.
  4102. *
  4103. * **-ENOENT** if the bpf-local-storage cannot be found.
  4104. * **-EINVAL** if sk is not a fullsock (e.g. a request_sock).
  4105. *
  4106. * long bpf_send_signal(u32 sig)
  4107. * Description
  4108. * Send signal *sig* to the process of the current task.
  4109. * The signal may be delivered to any of this process's threads.
  4110. * Return
  4111. * 0 on success or successfully queued.
  4112. *
  4113. * **-EBUSY** if work queue under nmi is full.
  4114. *
  4115. * **-EINVAL** if *sig* is invalid.
  4116. *
  4117. * **-EPERM** if no permission to send the *sig*.
  4118. *
  4119. * **-EAGAIN** if bpf program can try again.
  4120. *
  4121. * s64 bpf_tcp_gen_syncookie(void *sk, void *iph, u32 iph_len, struct tcphdr *th, u32 th_len)
  4122. * Description
  4123. * Try to issue a SYN cookie for the packet with corresponding
  4124. * IP/TCP headers, *iph* and *th*, on the listening socket in *sk*.
  4125. *
  4126. * *iph* points to the start of the IPv4 or IPv6 header, while
  4127. * *iph_len* contains **sizeof**\ (**struct iphdr**) or
  4128. * **sizeof**\ (**struct ipv6hdr**).
  4129. *
  4130. * *th* points to the start of the TCP header, while *th_len*
  4131. * contains the length of the TCP header with options (at least
  4132. * **sizeof**\ (**struct tcphdr**)).
  4133. * Return
  4134. * On success, lower 32 bits hold the generated SYN cookie in
  4135. * followed by 16 bits which hold the MSS value for that cookie,
  4136. * and the top 16 bits are unused.
  4137. *
  4138. * On failure, the returned value is one of the following:
  4139. *
  4140. * **-EINVAL** SYN cookie cannot be issued due to error
  4141. *
  4142. * **-ENOENT** SYN cookie should not be issued (no SYN flood)
  4143. *
  4144. * **-EOPNOTSUPP** kernel configuration does not enable SYN cookies
  4145. *
  4146. * **-EPROTONOSUPPORT** IP packet version is not 4 or 6
  4147. *
  4148. * long bpf_skb_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
  4149. * Description
  4150. * Write raw *data* blob into a special BPF perf event held by
  4151. * *map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
  4152. * event must have the following attributes: **PERF_SAMPLE_RAW**
  4153. * as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
  4154. * **PERF_COUNT_SW_BPF_OUTPUT** as **config**.
  4155. *
  4156. * The *flags* are used to indicate the index in *map* for which
  4157. * the value must be put, masked with **BPF_F_INDEX_MASK**.
  4158. * Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
  4159. * to indicate that the index of the current CPU core should be
  4160. * used.
  4161. *
  4162. * The value to write, of *size*, is passed through eBPF stack and
  4163. * pointed by *data*.
  4164. *
  4165. * *ctx* is a pointer to in-kernel struct sk_buff.
  4166. *
  4167. * This helper is similar to **bpf_perf_event_output**\ () but
  4168. * restricted to raw_tracepoint bpf programs.
  4169. * Return
  4170. * 0 on success, or a negative error in case of failure.
  4171. *
  4172. * long bpf_probe_read_user(void *dst, u32 size, const void *unsafe_ptr)
  4173. * Description
  4174. * Safely attempt to read *size* bytes from user space address
  4175. * *unsafe_ptr* and store the data in *dst*.
  4176. * Return
  4177. * 0 on success, or a negative error in case of failure.
  4178. *
  4179. * long bpf_probe_read_kernel(void *dst, u32 size, const void *unsafe_ptr)
  4180. * Description
  4181. * Safely attempt to read *size* bytes from kernel space address
  4182. * *unsafe_ptr* and store the data in *dst*.
  4183. * Return
  4184. * 0 on success, or a negative error in case of failure.
  4185. *
  4186. * long bpf_probe_read_user_str(void *dst, u32 size, const void *unsafe_ptr)
  4187. * Description
  4188. * Copy a NUL terminated string from an unsafe user address
  4189. * *unsafe_ptr* to *dst*. The *size* should include the
  4190. * terminating NUL byte. In case the string length is smaller than
  4191. * *size*, the target is not padded with further NUL bytes. If the
  4192. * string length is larger than *size*, just *size*-1 bytes are
  4193. * copied and the last byte is set to NUL.
  4194. *
  4195. * On success, returns the number of bytes that were written,
  4196. * including the terminal NUL. This makes this helper useful in
  4197. * tracing programs for reading strings, and more importantly to
  4198. * get its length at runtime. See the following snippet:
  4199. *
  4200. * ::
  4201. *
  4202. * SEC("kprobe/sys_open")
  4203. * void bpf_sys_open(struct pt_regs *ctx)
  4204. * {
  4205. * char buf[PATHLEN]; // PATHLEN is defined to 256
  4206. * int res = bpf_probe_read_user_str(buf, sizeof(buf),
  4207. * ctx->di);
  4208. *
  4209. * // Consume buf, for example push it to
  4210. * // userspace via bpf_perf_event_output(); we
  4211. * // can use res (the string length) as event
  4212. * // size, after checking its boundaries.
  4213. * }
  4214. *
  4215. * In comparison, using **bpf_probe_read_user**\ () helper here
  4216. * instead to read the string would require to estimate the length
  4217. * at compile time, and would often result in copying more memory
  4218. * than necessary.
  4219. *
  4220. * Another useful use case is when parsing individual process
  4221. * arguments or individual environment variables navigating
  4222. * *current*\ **->mm->arg_start** and *current*\
  4223. * **->mm->env_start**: using this helper and the return value,
  4224. * one can quickly iterate at the right offset of the memory area.
  4225. * Return
  4226. * On success, the strictly positive length of the output string,
  4227. * including the trailing NUL character. On error, a negative
  4228. * value.
  4229. *
  4230. * long bpf_probe_read_kernel_str(void *dst, u32 size, const void *unsafe_ptr)
  4231. * Description
  4232. * Copy a NUL terminated string from an unsafe kernel address *unsafe_ptr*
  4233. * to *dst*. Same semantics as with **bpf_probe_read_user_str**\ () apply.
  4234. * Return
  4235. * On success, the strictly positive length of the string, including
  4236. * the trailing NUL character. On error, a negative value.
  4237. *
  4238. * long bpf_tcp_send_ack(void *tp, u32 rcv_nxt)
  4239. * Description
  4240. * Send out a tcp-ack. *tp* is the in-kernel struct **tcp_sock**.
  4241. * *rcv_nxt* is the ack_seq to be sent out.
  4242. * Return
  4243. * 0 on success, or a negative error in case of failure.
  4244. *
  4245. * long bpf_send_signal_thread(u32 sig)
  4246. * Description
  4247. * Send signal *sig* to the thread corresponding to the current task.
  4248. * Return
  4249. * 0 on success or successfully queued.
  4250. *
  4251. * **-EBUSY** if work queue under nmi is full.
  4252. *
  4253. * **-EINVAL** if *sig* is invalid.
  4254. *
  4255. * **-EPERM** if no permission to send the *sig*.
  4256. *
  4257. * **-EAGAIN** if bpf program can try again.
  4258. *
  4259. * u64 bpf_jiffies64(void)
  4260. * Description
  4261. * Obtain the 64bit jiffies
  4262. * Return
  4263. * The 64 bit jiffies
  4264. *
  4265. * long bpf_read_branch_records(struct bpf_perf_event_data *ctx, void *buf, u32 size, u64 flags)
  4266. * Description
  4267. * For an eBPF program attached to a perf event, retrieve the
  4268. * branch records (**struct perf_branch_entry**) associated to *ctx*
  4269. * and store it in the buffer pointed by *buf* up to size
  4270. * *size* bytes.
  4271. * Return
  4272. * On success, number of bytes written to *buf*. On error, a
  4273. * negative value.
  4274. *
  4275. * The *flags* can be set to **BPF_F_GET_BRANCH_RECORDS_SIZE** to
  4276. * instead return the number of bytes required to store all the
  4277. * branch entries. If this flag is set, *buf* may be NULL.
  4278. *
  4279. * **-EINVAL** if arguments invalid or **size** not a multiple
  4280. * of **sizeof**\ (**struct perf_branch_entry**\ ).
  4281. *
  4282. * **-ENOENT** if architecture does not support branch records.
  4283. *
  4284. * long bpf_get_ns_current_pid_tgid(u64 dev, u64 ino, struct bpf_pidns_info *nsdata, u32 size)
  4285. * Description
  4286. * Returns 0 on success, values for *pid* and *tgid* as seen from the current
  4287. * *namespace* will be returned in *nsdata*.
  4288. * Return
  4289. * 0 on success, or one of the following in case of failure:
  4290. *
  4291. * **-EINVAL** if dev and inum supplied don't match dev_t and inode number
  4292. * with nsfs of current task, or if dev conversion to dev_t lost high bits.
  4293. *
  4294. * **-ENOENT** if pidns does not exists for the current task.
  4295. *
  4296. * long bpf_xdp_output(void *ctx, struct bpf_map *map, u64 flags, void *data, u64 size)
  4297. * Description
  4298. * Write raw *data* blob into a special BPF perf event held by
  4299. * *map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
  4300. * event must have the following attributes: **PERF_SAMPLE_RAW**
  4301. * as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
  4302. * **PERF_COUNT_SW_BPF_OUTPUT** as **config**.
  4303. *
  4304. * The *flags* are used to indicate the index in *map* for which
  4305. * the value must be put, masked with **BPF_F_INDEX_MASK**.
  4306. * Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
  4307. * to indicate that the index of the current CPU core should be
  4308. * used.
  4309. *
  4310. * The value to write, of *size*, is passed through eBPF stack and
  4311. * pointed by *data*.
  4312. *
  4313. * *ctx* is a pointer to in-kernel struct xdp_buff.
  4314. *
  4315. * This helper is similar to **bpf_perf_eventoutput**\ () but
  4316. * restricted to raw_tracepoint bpf programs.
  4317. * Return
  4318. * 0 on success, or a negative error in case of failure.
  4319. *
  4320. * u64 bpf_get_netns_cookie(void *ctx)
  4321. * Description
  4322. * Retrieve the cookie (generated by the kernel) of the network
  4323. * namespace the input *ctx* is associated with. The network
  4324. * namespace cookie remains stable for its lifetime and provides
  4325. * a global identifier that can be assumed unique. If *ctx* is
  4326. * NULL, then the helper returns the cookie for the initial
  4327. * network namespace. The cookie itself is very similar to that
  4328. * of **bpf_get_socket_cookie**\ () helper, but for network
  4329. * namespaces instead of sockets.
  4330. * Return
  4331. * A 8-byte long opaque number.
  4332. *
  4333. * u64 bpf_get_current_ancestor_cgroup_id(int ancestor_level)
  4334. * Description
  4335. * Return id of cgroup v2 that is ancestor of the cgroup associated
  4336. * with the current task at the *ancestor_level*. The root cgroup
  4337. * is at *ancestor_level* zero and each step down the hierarchy
  4338. * increments the level. If *ancestor_level* == level of cgroup
  4339. * associated with the current task, then return value will be the
  4340. * same as that of **bpf_get_current_cgroup_id**\ ().
  4341. *
  4342. * The helper is useful to implement policies based on cgroups
  4343. * that are upper in hierarchy than immediate cgroup associated
  4344. * with the current task.
  4345. *
  4346. * The format of returned id and helper limitations are same as in
  4347. * **bpf_get_current_cgroup_id**\ ().
  4348. * Return
  4349. * The id is returned or 0 in case the id could not be retrieved.
  4350. *
  4351. * long bpf_sk_assign(struct sk_buff *skb, void *sk, u64 flags)
  4352. * Description
  4353. * Helper is overloaded depending on BPF program type. This
  4354. * description applies to **BPF_PROG_TYPE_SCHED_CLS** and
  4355. * **BPF_PROG_TYPE_SCHED_ACT** programs.
  4356. *
  4357. * Assign the *sk* to the *skb*. When combined with appropriate
  4358. * routing configuration to receive the packet towards the socket,
  4359. * will cause *skb* to be delivered to the specified socket.
  4360. * Subsequent redirection of *skb* via **bpf_redirect**\ (),
  4361. * **bpf_clone_redirect**\ () or other methods outside of BPF may
  4362. * interfere with successful delivery to the socket.
  4363. *
  4364. * This operation is only valid from TC ingress path.
  4365. *
  4366. * The *flags* argument must be zero.
  4367. * Return
  4368. * 0 on success, or a negative error in case of failure:
  4369. *
  4370. * **-EINVAL** if specified *flags* are not supported.
  4371. *
  4372. * **-ENOENT** if the socket is unavailable for assignment.
  4373. *
  4374. * **-ENETUNREACH** if the socket is unreachable (wrong netns).
  4375. *
  4376. * **-EOPNOTSUPP** if the operation is not supported, for example
  4377. * a call from outside of TC ingress.
  4378. *
  4379. * long bpf_sk_assign(struct bpf_sk_lookup *ctx, struct bpf_sock *sk, u64 flags)
  4380. * Description
  4381. * Helper is overloaded depending on BPF program type. This
  4382. * description applies to **BPF_PROG_TYPE_SK_LOOKUP** programs.
  4383. *
  4384. * Select the *sk* as a result of a socket lookup.
  4385. *
  4386. * For the operation to succeed passed socket must be compatible
  4387. * with the packet description provided by the *ctx* object.
  4388. *
  4389. * L4 protocol (**IPPROTO_TCP** or **IPPROTO_UDP**) must
  4390. * be an exact match. While IP family (**AF_INET** or
  4391. * **AF_INET6**) must be compatible, that is IPv6 sockets
  4392. * that are not v6-only can be selected for IPv4 packets.
  4393. *
  4394. * Only TCP listeners and UDP unconnected sockets can be
  4395. * selected. *sk* can also be NULL to reset any previous
  4396. * selection.
  4397. *
  4398. * *flags* argument can combination of following values:
  4399. *
  4400. * * **BPF_SK_LOOKUP_F_REPLACE** to override the previous
  4401. * socket selection, potentially done by a BPF program
  4402. * that ran before us.
  4403. *
  4404. * * **BPF_SK_LOOKUP_F_NO_REUSEPORT** to skip
  4405. * load-balancing within reuseport group for the socket
  4406. * being selected.
  4407. *
  4408. * On success *ctx->sk* will point to the selected socket.
  4409. *
  4410. * Return
  4411. * 0 on success, or a negative errno in case of failure.
  4412. *
  4413. * * **-EAFNOSUPPORT** if socket family (*sk->family*) is
  4414. * not compatible with packet family (*ctx->family*).
  4415. *
  4416. * * **-EEXIST** if socket has been already selected,
  4417. * potentially by another program, and
  4418. * **BPF_SK_LOOKUP_F_REPLACE** flag was not specified.
  4419. *
  4420. * * **-EINVAL** if unsupported flags were specified.
  4421. *
  4422. * * **-EPROTOTYPE** if socket L4 protocol
  4423. * (*sk->protocol*) doesn't match packet protocol
  4424. * (*ctx->protocol*).
  4425. *
  4426. * * **-ESOCKTNOSUPPORT** if socket is not in allowed
  4427. * state (TCP listening or UDP unconnected).
  4428. *
  4429. * u64 bpf_ktime_get_boot_ns(void)
  4430. * Description
  4431. * Return the time elapsed since system boot, in nanoseconds.
  4432. * Does include the time the system was suspended.
  4433. * See: **clock_gettime**\ (**CLOCK_BOOTTIME**)
  4434. * Return
  4435. * Current *ktime*.
  4436. *
  4437. * long bpf_seq_printf(struct seq_file *m, const char *fmt, u32 fmt_size, const void *data, u32 data_len)
  4438. * Description
  4439. * **bpf_seq_printf**\ () uses seq_file **seq_printf**\ () to print
  4440. * out the format string.
  4441. * The *m* represents the seq_file. The *fmt* and *fmt_size* are for
  4442. * the format string itself. The *data* and *data_len* are format string
  4443. * arguments. The *data* are a **u64** array and corresponding format string
  4444. * values are stored in the array. For strings and pointers where pointees
  4445. * are accessed, only the pointer values are stored in the *data* array.
  4446. * The *data_len* is the size of *data* in bytes - must be a multiple of 8.
  4447. *
  4448. * Formats **%s**, **%p{i,I}{4,6}** requires to read kernel memory.
  4449. * Reading kernel memory may fail due to either invalid address or
  4450. * valid address but requiring a major memory fault. If reading kernel memory
  4451. * fails, the string for **%s** will be an empty string, and the ip
  4452. * address for **%p{i,I}{4,6}** will be 0. Not returning error to
  4453. * bpf program is consistent with what **bpf_trace_printk**\ () does for now.
  4454. * Return
  4455. * 0 on success, or a negative error in case of failure:
  4456. *
  4457. * **-EBUSY** if per-CPU memory copy buffer is busy, can try again
  4458. * by returning 1 from bpf program.
  4459. *
  4460. * **-EINVAL** if arguments are invalid, or if *fmt* is invalid/unsupported.
  4461. *
  4462. * **-E2BIG** if *fmt* contains too many format specifiers.
  4463. *
  4464. * **-EOVERFLOW** if an overflow happened: The same object will be tried again.
  4465. *
  4466. * long bpf_seq_write(struct seq_file *m, const void *data, u32 len)
  4467. * Description
  4468. * **bpf_seq_write**\ () uses seq_file **seq_write**\ () to write the data.
  4469. * The *m* represents the seq_file. The *data* and *len* represent the
  4470. * data to write in bytes.
  4471. * Return
  4472. * 0 on success, or a negative error in case of failure:
  4473. *
  4474. * **-EOVERFLOW** if an overflow happened: The same object will be tried again.
  4475. *
  4476. * u64 bpf_sk_cgroup_id(void *sk)
  4477. * Description
  4478. * Return the cgroup v2 id of the socket *sk*.
  4479. *
  4480. * *sk* must be a non-**NULL** pointer to a socket, e.g. one
  4481. * returned from **bpf_sk_lookup_xxx**\ (),
  4482. * **bpf_sk_fullsock**\ (), etc. The format of returned id is
  4483. * same as in **bpf_skb_cgroup_id**\ ().
  4484. *
  4485. * This helper is available only if the kernel was compiled with
  4486. * the **CONFIG_SOCK_CGROUP_DATA** configuration option.
  4487. * Return
  4488. * The id is returned or 0 in case the id could not be retrieved.
  4489. *
  4490. * u64 bpf_sk_ancestor_cgroup_id(void *sk, int ancestor_level)
  4491. * Description
  4492. * Return id of cgroup v2 that is ancestor of cgroup associated
  4493. * with the *sk* at the *ancestor_level*. The root cgroup is at
  4494. * *ancestor_level* zero and each step down the hierarchy
  4495. * increments the level. If *ancestor_level* == level of cgroup
  4496. * associated with *sk*, then return value will be same as that
  4497. * of **bpf_sk_cgroup_id**\ ().
  4498. *
  4499. * The helper is useful to implement policies based on cgroups
  4500. * that are upper in hierarchy than immediate cgroup associated
  4501. * with *sk*.
  4502. *
  4503. * The format of returned id and helper limitations are same as in
  4504. * **bpf_sk_cgroup_id**\ ().
  4505. * Return
  4506. * The id is returned or 0 in case the id could not be retrieved.
  4507. *
  4508. * long bpf_ringbuf_output(void *ringbuf, void *data, u64 size, u64 flags)
  4509. * Description
  4510. * Copy *size* bytes from *data* into a ring buffer *ringbuf*.
  4511. * If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
  4512. * of new data availability is sent.
  4513. * If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
  4514. * of new data availability is sent unconditionally.
  4515. * If **0** is specified in *flags*, an adaptive notification
  4516. * of new data availability is sent.
  4517. *
  4518. * An adaptive notification is a notification sent whenever the user-space
  4519. * process has caught up and consumed all available payloads. In case the user-space
  4520. * process is still processing a previous payload, then no notification is needed
  4521. * as it will process the newly added payload automatically.
  4522. * Return
  4523. * 0 on success, or a negative error in case of failure.
  4524. *
  4525. * void *bpf_ringbuf_reserve(void *ringbuf, u64 size, u64 flags)
  4526. * Description
  4527. * Reserve *size* bytes of payload in a ring buffer *ringbuf*.
  4528. * *flags* must be 0.
  4529. * Return
  4530. * Valid pointer with *size* bytes of memory available; NULL,
  4531. * otherwise.
  4532. *
  4533. * void bpf_ringbuf_submit(void *data, u64 flags)
  4534. * Description
  4535. * Submit reserved ring buffer sample, pointed to by *data*.
  4536. * If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
  4537. * of new data availability is sent.
  4538. * If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
  4539. * of new data availability is sent unconditionally.
  4540. * If **0** is specified in *flags*, an adaptive notification
  4541. * of new data availability is sent.
  4542. *
  4543. * See 'bpf_ringbuf_output()' for the definition of adaptive notification.
  4544. * Return
  4545. * Nothing. Always succeeds.
  4546. *
  4547. * void bpf_ringbuf_discard(void *data, u64 flags)
  4548. * Description
  4549. * Discard reserved ring buffer sample, pointed to by *data*.
  4550. * If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
  4551. * of new data availability is sent.
  4552. * If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
  4553. * of new data availability is sent unconditionally.
  4554. * If **0** is specified in *flags*, an adaptive notification
  4555. * of new data availability is sent.
  4556. *
  4557. * See 'bpf_ringbuf_output()' for the definition of adaptive notification.
  4558. * Return
  4559. * Nothing. Always succeeds.
  4560. *
  4561. * u64 bpf_ringbuf_query(void *ringbuf, u64 flags)
  4562. * Description
  4563. * Query various characteristics of provided ring buffer. What
  4564. * exactly is queries is determined by *flags*:
  4565. *
  4566. * * **BPF_RB_AVAIL_DATA**: Amount of data not yet consumed.
  4567. * * **BPF_RB_RING_SIZE**: The size of ring buffer.
  4568. * * **BPF_RB_CONS_POS**: Consumer position (can wrap around).
  4569. * * **BPF_RB_PROD_POS**: Producer(s) position (can wrap around).
  4570. *
  4571. * Data returned is just a momentary snapshot of actual values
  4572. * and could be inaccurate, so this facility should be used to
  4573. * power heuristics and for reporting, not to make 100% correct
  4574. * calculation.
  4575. * Return
  4576. * Requested value, or 0, if *flags* are not recognized.
  4577. *
  4578. * long bpf_csum_level(struct sk_buff *skb, u64 level)
  4579. * Description
  4580. * Change the skbs checksum level by one layer up or down, or
  4581. * reset it entirely to none in order to have the stack perform
  4582. * checksum validation. The level is applicable to the following
  4583. * protocols: TCP, UDP, GRE, SCTP, FCOE. For example, a decap of
  4584. * | ETH | IP | UDP | GUE | IP | TCP | into | ETH | IP | TCP |
  4585. * through **bpf_skb_adjust_room**\ () helper with passing in
  4586. * **BPF_F_ADJ_ROOM_NO_CSUM_RESET** flag would require one call
  4587. * to **bpf_csum_level**\ () with **BPF_CSUM_LEVEL_DEC** since
  4588. * the UDP header is removed. Similarly, an encap of the latter
  4589. * into the former could be accompanied by a helper call to
  4590. * **bpf_csum_level**\ () with **BPF_CSUM_LEVEL_INC** if the
  4591. * skb is still intended to be processed in higher layers of the
  4592. * stack instead of just egressing at tc.
  4593. *
  4594. * There are three supported level settings at this time:
  4595. *
  4596. * * **BPF_CSUM_LEVEL_INC**: Increases skb->csum_level for skbs
  4597. * with CHECKSUM_UNNECESSARY.
  4598. * * **BPF_CSUM_LEVEL_DEC**: Decreases skb->csum_level for skbs
  4599. * with CHECKSUM_UNNECESSARY.
  4600. * * **BPF_CSUM_LEVEL_RESET**: Resets skb->csum_level to 0 and
  4601. * sets CHECKSUM_NONE to force checksum validation by the stack.
  4602. * * **BPF_CSUM_LEVEL_QUERY**: No-op, returns the current
  4603. * skb->csum_level.
  4604. * Return
  4605. * 0 on success, or a negative error in case of failure. In the
  4606. * case of **BPF_CSUM_LEVEL_QUERY**, the current skb->csum_level
  4607. * is returned or the error code -EACCES in case the skb is not
  4608. * subject to CHECKSUM_UNNECESSARY.
  4609. *
  4610. * struct tcp6_sock *bpf_skc_to_tcp6_sock(void *sk)
  4611. * Description
  4612. * Dynamically cast a *sk* pointer to a *tcp6_sock* pointer.
  4613. * Return
  4614. * *sk* if casting is valid, or **NULL** otherwise.
  4615. *
  4616. * struct tcp_sock *bpf_skc_to_tcp_sock(void *sk)
  4617. * Description
  4618. * Dynamically cast a *sk* pointer to a *tcp_sock* pointer.
  4619. * Return
  4620. * *sk* if casting is valid, or **NULL** otherwise.
  4621. *
  4622. * struct tcp_timewait_sock *bpf_skc_to_tcp_timewait_sock(void *sk)
  4623. * Description
  4624. * Dynamically cast a *sk* pointer to a *tcp_timewait_sock* pointer.
  4625. * Return
  4626. * *sk* if casting is valid, or **NULL** otherwise.
  4627. *
  4628. * struct tcp_request_sock *bpf_skc_to_tcp_request_sock(void *sk)
  4629. * Description
  4630. * Dynamically cast a *sk* pointer to a *tcp_request_sock* pointer.
  4631. * Return
  4632. * *sk* if casting is valid, or **NULL** otherwise.
  4633. *
  4634. * struct udp6_sock *bpf_skc_to_udp6_sock(void *sk)
  4635. * Description
  4636. * Dynamically cast a *sk* pointer to a *udp6_sock* pointer.
  4637. * Return
  4638. * *sk* if casting is valid, or **NULL** otherwise.
  4639. *
  4640. * long bpf_get_task_stack(struct task_struct *task, void *buf, u32 size, u64 flags)
  4641. * Description
  4642. * Return a user or a kernel stack in bpf program provided buffer.
  4643. * Note: the user stack will only be populated if the *task* is
  4644. * the current task; all other tasks will return -EOPNOTSUPP.
  4645. * To achieve this, the helper needs *task*, which is a valid
  4646. * pointer to **struct task_struct**. To store the stacktrace, the
  4647. * bpf program provides *buf* with a nonnegative *size*.
  4648. *
  4649. * The last argument, *flags*, holds the number of stack frames to
  4650. * skip (from 0 to 255), masked with
  4651. * **BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
  4652. * the following flags:
  4653. *
  4654. * **BPF_F_USER_STACK**
  4655. * Collect a user space stack instead of a kernel stack.
  4656. * The *task* must be the current task.
  4657. * **BPF_F_USER_BUILD_ID**
  4658. * Collect buildid+offset instead of ips for user stack,
  4659. * only valid if **BPF_F_USER_STACK** is also specified.
  4660. *
  4661. * **bpf_get_task_stack**\ () can collect up to
  4662. * **PERF_MAX_STACK_DEPTH** both kernel and user frames, subject
  4663. * to sufficient large buffer size. Note that
  4664. * this limit can be controlled with the **sysctl** program, and
  4665. * that it should be manually increased in order to profile long
  4666. * user stacks (such as stacks for Java programs). To do so, use:
  4667. *
  4668. * ::
  4669. *
  4670. * # sysctl kernel.perf_event_max_stack=<new value>
  4671. * Return
  4672. * The non-negative copied *buf* length equal to or less than
  4673. * *size* on success, or a negative error in case of failure.
  4674. *
  4675. * long bpf_load_hdr_opt(struct bpf_sock_ops *skops, void *searchby_res, u32 len, u64 flags)
  4676. * Description
  4677. * Load header option. Support reading a particular TCP header
  4678. * option for bpf program (**BPF_PROG_TYPE_SOCK_OPS**).
  4679. *
  4680. * If *flags* is 0, it will search the option from the
  4681. * *skops*\ **->skb_data**. The comment in **struct bpf_sock_ops**
  4682. * has details on what skb_data contains under different
  4683. * *skops*\ **->op**.
  4684. *
  4685. * The first byte of the *searchby_res* specifies the
  4686. * kind that it wants to search.
  4687. *
  4688. * If the searching kind is an experimental kind
  4689. * (i.e. 253 or 254 according to RFC6994). It also
  4690. * needs to specify the "magic" which is either
  4691. * 2 bytes or 4 bytes. It then also needs to
  4692. * specify the size of the magic by using
  4693. * the 2nd byte which is "kind-length" of a TCP
  4694. * header option and the "kind-length" also
  4695. * includes the first 2 bytes "kind" and "kind-length"
  4696. * itself as a normal TCP header option also does.
  4697. *
  4698. * For example, to search experimental kind 254 with
  4699. * 2 byte magic 0xeB9F, the searchby_res should be
  4700. * [ 254, 4, 0xeB, 0x9F, 0, 0, .... 0 ].
  4701. *
  4702. * To search for the standard window scale option (3),
  4703. * the *searchby_res* should be [ 3, 0, 0, .... 0 ].
  4704. * Note, kind-length must be 0 for regular option.
  4705. *
  4706. * Searching for No-Op (0) and End-of-Option-List (1) are
  4707. * not supported.
  4708. *
  4709. * *len* must be at least 2 bytes which is the minimal size
  4710. * of a header option.
  4711. *
  4712. * Supported flags:
  4713. *
  4714. * * **BPF_LOAD_HDR_OPT_TCP_SYN** to search from the
  4715. * saved_syn packet or the just-received syn packet.
  4716. *
  4717. * Return
  4718. * > 0 when found, the header option is copied to *searchby_res*.
  4719. * The return value is the total length copied. On failure, a
  4720. * negative error code is returned:
  4721. *
  4722. * **-EINVAL** if a parameter is invalid.
  4723. *
  4724. * **-ENOMSG** if the option is not found.
  4725. *
  4726. * **-ENOENT** if no syn packet is available when
  4727. * **BPF_LOAD_HDR_OPT_TCP_SYN** is used.
  4728. *
  4729. * **-ENOSPC** if there is not enough space. Only *len* number of
  4730. * bytes are copied.
  4731. *
  4732. * **-EFAULT** on failure to parse the header options in the
  4733. * packet.
  4734. *
  4735. * **-EPERM** if the helper cannot be used under the current
  4736. * *skops*\ **->op**.
  4737. *
  4738. * long bpf_store_hdr_opt(struct bpf_sock_ops *skops, const void *from, u32 len, u64 flags)
  4739. * Description
  4740. * Store header option. The data will be copied
  4741. * from buffer *from* with length *len* to the TCP header.
  4742. *
  4743. * The buffer *from* should have the whole option that
  4744. * includes the kind, kind-length, and the actual
  4745. * option data. The *len* must be at least kind-length
  4746. * long. The kind-length does not have to be 4 byte
  4747. * aligned. The kernel will take care of the padding
  4748. * and setting the 4 bytes aligned value to th->doff.
  4749. *
  4750. * This helper will check for duplicated option
  4751. * by searching the same option in the outgoing skb.
  4752. *
  4753. * This helper can only be called during
  4754. * **BPF_SOCK_OPS_WRITE_HDR_OPT_CB**.
  4755. *
  4756. * Return
  4757. * 0 on success, or negative error in case of failure:
  4758. *
  4759. * **-EINVAL** If param is invalid.
  4760. *
  4761. * **-ENOSPC** if there is not enough space in the header.
  4762. * Nothing has been written
  4763. *
  4764. * **-EEXIST** if the option already exists.
  4765. *
  4766. * **-EFAULT** on failure to parse the existing header options.
  4767. *
  4768. * **-EPERM** if the helper cannot be used under the current
  4769. * *skops*\ **->op**.
  4770. *
  4771. * long bpf_reserve_hdr_opt(struct bpf_sock_ops *skops, u32 len, u64 flags)
  4772. * Description
  4773. * Reserve *len* bytes for the bpf header option. The
  4774. * space will be used by **bpf_store_hdr_opt**\ () later in
  4775. * **BPF_SOCK_OPS_WRITE_HDR_OPT_CB**.
  4776. *
  4777. * If **bpf_reserve_hdr_opt**\ () is called multiple times,
  4778. * the total number of bytes will be reserved.
  4779. *
  4780. * This helper can only be called during
  4781. * **BPF_SOCK_OPS_HDR_OPT_LEN_CB**.
  4782. *
  4783. * Return
  4784. * 0 on success, or negative error in case of failure:
  4785. *
  4786. * **-EINVAL** if a parameter is invalid.
  4787. *
  4788. * **-ENOSPC** if there is not enough space in the header.
  4789. *
  4790. * **-EPERM** if the helper cannot be used under the current
  4791. * *skops*\ **->op**.
  4792. *
  4793. * void *bpf_inode_storage_get(struct bpf_map *map, void *inode, void *value, u64 flags)
  4794. * Description
  4795. * Get a bpf_local_storage from an *inode*.
  4796. *
  4797. * Logically, it could be thought of as getting the value from
  4798. * a *map* with *inode* as the **key**. From this
  4799. * perspective, the usage is not much different from
  4800. * **bpf_map_lookup_elem**\ (*map*, **&**\ *inode*) except this
  4801. * helper enforces the key must be an inode and the map must also
  4802. * be a **BPF_MAP_TYPE_INODE_STORAGE**.
  4803. *
  4804. * Underneath, the value is stored locally at *inode* instead of
  4805. * the *map*. The *map* is used as the bpf-local-storage
  4806. * "type". The bpf-local-storage "type" (i.e. the *map*) is
  4807. * searched against all bpf_local_storage residing at *inode*.
  4808. *
  4809. * An optional *flags* (**BPF_LOCAL_STORAGE_GET_F_CREATE**) can be
  4810. * used such that a new bpf_local_storage will be
  4811. * created if one does not exist. *value* can be used
  4812. * together with **BPF_LOCAL_STORAGE_GET_F_CREATE** to specify
  4813. * the initial value of a bpf_local_storage. If *value* is
  4814. * **NULL**, the new bpf_local_storage will be zero initialized.
  4815. * Return
  4816. * A bpf_local_storage pointer is returned on success.
  4817. *
  4818. * **NULL** if not found or there was an error in adding
  4819. * a new bpf_local_storage.
  4820. *
  4821. * int bpf_inode_storage_delete(struct bpf_map *map, void *inode)
  4822. * Description
  4823. * Delete a bpf_local_storage from an *inode*.
  4824. * Return
  4825. * 0 on success.
  4826. *
  4827. * **-ENOENT** if the bpf_local_storage cannot be found.
  4828. *
  4829. * long bpf_d_path(const struct path *path, char *buf, u32 sz)
  4830. * Description
  4831. * Return full path for given **struct path** object, which
  4832. * needs to be the kernel BTF *path* object. The path is
  4833. * returned in the provided buffer *buf* of size *sz* and
  4834. * is zero terminated.
  4835. *
  4836. * Return
  4837. * On success, the strictly positive length of the string,
  4838. * including the trailing NUL character. On error, a negative
  4839. * value.
  4840. *
  4841. * long bpf_copy_from_user(void *dst, u32 size, const void *user_ptr)
  4842. * Description
  4843. * Read *size* bytes from user space address *user_ptr* and store
  4844. * the data in *dst*. This is a wrapper of **copy_from_user**\ ().
  4845. * Return
  4846. * 0 on success, or a negative error in case of failure.
  4847. *
  4848. * long bpf_snprintf_btf(char *str, u32 str_size, struct btf_ptr *ptr, u32 btf_ptr_size, u64 flags)
  4849. * Description
  4850. * Use BTF to store a string representation of *ptr*->ptr in *str*,
  4851. * using *ptr*->type_id. This value should specify the type
  4852. * that *ptr*->ptr points to. LLVM __builtin_btf_type_id(type, 1)
  4853. * can be used to look up vmlinux BTF type ids. Traversing the
  4854. * data structure using BTF, the type information and values are
  4855. * stored in the first *str_size* - 1 bytes of *str*. Safe copy of
  4856. * the pointer data is carried out to avoid kernel crashes during
  4857. * operation. Smaller types can use string space on the stack;
  4858. * larger programs can use map data to store the string
  4859. * representation.
  4860. *
  4861. * The string can be subsequently shared with userspace via
  4862. * bpf_perf_event_output() or ring buffer interfaces.
  4863. * bpf_trace_printk() is to be avoided as it places too small
  4864. * a limit on string size to be useful.
  4865. *
  4866. * *flags* is a combination of
  4867. *
  4868. * **BTF_F_COMPACT**
  4869. * no formatting around type information
  4870. * **BTF_F_NONAME**
  4871. * no struct/union member names/types
  4872. * **BTF_F_PTR_RAW**
  4873. * show raw (unobfuscated) pointer values;
  4874. * equivalent to printk specifier %px.
  4875. * **BTF_F_ZERO**
  4876. * show zero-valued struct/union members; they
  4877. * are not displayed by default
  4878. *
  4879. * Return
  4880. * The number of bytes that were written (or would have been
  4881. * written if output had to be truncated due to string size),
  4882. * or a negative error in cases of failure.
  4883. *
  4884. * long bpf_seq_printf_btf(struct seq_file *m, struct btf_ptr *ptr, u32 ptr_size, u64 flags)
  4885. * Description
  4886. * Use BTF to write to seq_write a string representation of
  4887. * *ptr*->ptr, using *ptr*->type_id as per bpf_snprintf_btf().
  4888. * *flags* are identical to those used for bpf_snprintf_btf.
  4889. * Return
  4890. * 0 on success or a negative error in case of failure.
  4891. *
  4892. * u64 bpf_skb_cgroup_classid(struct sk_buff *skb)
  4893. * Description
  4894. * See **bpf_get_cgroup_classid**\ () for the main description.
  4895. * This helper differs from **bpf_get_cgroup_classid**\ () in that
  4896. * the cgroup v1 net_cls class is retrieved only from the *skb*'s
  4897. * associated socket instead of the current process.
  4898. * Return
  4899. * The id is returned or 0 in case the id could not be retrieved.
  4900. *
  4901. * long bpf_redirect_neigh(u32 ifindex, struct bpf_redir_neigh *params, int plen, u64 flags)
  4902. * Description
  4903. * Redirect the packet to another net device of index *ifindex*
  4904. * and fill in L2 addresses from neighboring subsystem. This helper
  4905. * is somewhat similar to **bpf_redirect**\ (), except that it
  4906. * populates L2 addresses as well, meaning, internally, the helper
  4907. * relies on the neighbor lookup for the L2 address of the nexthop.
  4908. *
  4909. * The helper will perform a FIB lookup based on the skb's
  4910. * networking header to get the address of the next hop, unless
  4911. * this is supplied by the caller in the *params* argument. The
  4912. * *plen* argument indicates the len of *params* and should be set
  4913. * to 0 if *params* is NULL.
  4914. *
  4915. * The *flags* argument is reserved and must be 0. The helper is
  4916. * currently only supported for tc BPF program types, and enabled
  4917. * for IPv4 and IPv6 protocols.
  4918. * Return
  4919. * The helper returns **TC_ACT_REDIRECT** on success or
  4920. * **TC_ACT_SHOT** on error.
  4921. *
  4922. * void *bpf_per_cpu_ptr(const void *percpu_ptr, u32 cpu)
  4923. * Description
  4924. * Take a pointer to a percpu ksym, *percpu_ptr*, and return a
  4925. * pointer to the percpu kernel variable on *cpu*. A ksym is an
  4926. * extern variable decorated with '__ksym'. For ksym, there is a
  4927. * global var (either static or global) defined of the same name
  4928. * in the kernel. The ksym is percpu if the global var is percpu.
  4929. * The returned pointer points to the global percpu var on *cpu*.
  4930. *
  4931. * bpf_per_cpu_ptr() has the same semantic as per_cpu_ptr() in the
  4932. * kernel, except that bpf_per_cpu_ptr() may return NULL. This
  4933. * happens if *cpu* is larger than nr_cpu_ids. The caller of
  4934. * bpf_per_cpu_ptr() must check the returned value.
  4935. * Return
  4936. * A pointer pointing to the kernel percpu variable on *cpu*, or
  4937. * NULL, if *cpu* is invalid.
  4938. *
  4939. * void *bpf_this_cpu_ptr(const void *percpu_ptr)
  4940. * Description
  4941. * Take a pointer to a percpu ksym, *percpu_ptr*, and return a
  4942. * pointer to the percpu kernel variable on this cpu. See the
  4943. * description of 'ksym' in **bpf_per_cpu_ptr**\ ().
  4944. *
  4945. * bpf_this_cpu_ptr() has the same semantic as this_cpu_ptr() in
  4946. * the kernel. Different from **bpf_per_cpu_ptr**\ (), it would
  4947. * never return NULL.
  4948. * Return
  4949. * A pointer pointing to the kernel percpu variable on this cpu.
  4950. *
  4951. * long bpf_redirect_peer(u32 ifindex, u64 flags)
  4952. * Description
  4953. * Redirect the packet to another net device of index *ifindex*.
  4954. * This helper is somewhat similar to **bpf_redirect**\ (), except
  4955. * that the redirection happens to the *ifindex*' peer device and
  4956. * the netns switch takes place from ingress to ingress without
  4957. * going through the CPU's backlog queue.
  4958. *
  4959. * *skb*\ **->mark** and *skb*\ **->tstamp** are not cleared during
  4960. * the netns switch.
  4961. *
  4962. * The *flags* argument is reserved and must be 0. The helper is
  4963. * currently only supported for tc BPF program types at the
  4964. * ingress hook and for veth and netkit target device types. The
  4965. * peer device must reside in a different network namespace.
  4966. * Return
  4967. * The helper returns **TC_ACT_REDIRECT** on success or
  4968. * **TC_ACT_SHOT** on error.
  4969. *
  4970. * void *bpf_task_storage_get(struct bpf_map *map, struct task_struct *task, void *value, u64 flags)
  4971. * Description
  4972. * Get a bpf_local_storage from the *task*.
  4973. *
  4974. * Logically, it could be thought of as getting the value from
  4975. * a *map* with *task* as the **key**. From this
  4976. * perspective, the usage is not much different from
  4977. * **bpf_map_lookup_elem**\ (*map*, **&**\ *task*) except this
  4978. * helper enforces the key must be a task_struct and the map must also
  4979. * be a **BPF_MAP_TYPE_TASK_STORAGE**.
  4980. *
  4981. * Underneath, the value is stored locally at *task* instead of
  4982. * the *map*. The *map* is used as the bpf-local-storage
  4983. * "type". The bpf-local-storage "type" (i.e. the *map*) is
  4984. * searched against all bpf_local_storage residing at *task*.
  4985. *
  4986. * An optional *flags* (**BPF_LOCAL_STORAGE_GET_F_CREATE**) can be
  4987. * used such that a new bpf_local_storage will be
  4988. * created if one does not exist. *value* can be used
  4989. * together with **BPF_LOCAL_STORAGE_GET_F_CREATE** to specify
  4990. * the initial value of a bpf_local_storage. If *value* is
  4991. * **NULL**, the new bpf_local_storage will be zero initialized.
  4992. * Return
  4993. * A bpf_local_storage pointer is returned on success.
  4994. *
  4995. * **NULL** if not found or there was an error in adding
  4996. * a new bpf_local_storage.
  4997. *
  4998. * long bpf_task_storage_delete(struct bpf_map *map, struct task_struct *task)
  4999. * Description
  5000. * Delete a bpf_local_storage from a *task*.
  5001. * Return
  5002. * 0 on success.
  5003. *
  5004. * **-ENOENT** if the bpf_local_storage cannot be found.
  5005. *
  5006. * struct task_struct *bpf_get_current_task_btf(void)
  5007. * Description
  5008. * Return a BTF pointer to the "current" task.
  5009. * This pointer can also be used in helpers that accept an
  5010. * *ARG_PTR_TO_BTF_ID* of type *task_struct*.
  5011. * Return
  5012. * Pointer to the current task.
  5013. *
  5014. * long bpf_bprm_opts_set(struct linux_binprm *bprm, u64 flags)
  5015. * Description
  5016. * Set or clear certain options on *bprm*:
  5017. *
  5018. * **BPF_F_BPRM_SECUREEXEC** Set the secureexec bit
  5019. * which sets the **AT_SECURE** auxv for glibc. The bit
  5020. * is cleared if the flag is not specified.
  5021. * Return
  5022. * **-EINVAL** if invalid *flags* are passed, zero otherwise.
  5023. *
  5024. * u64 bpf_ktime_get_coarse_ns(void)
  5025. * Description
  5026. * Return a coarse-grained version of the time elapsed since
  5027. * system boot, in nanoseconds. Does not include time the system
  5028. * was suspended.
  5029. *
  5030. * See: **clock_gettime**\ (**CLOCK_MONOTONIC_COARSE**)
  5031. * Return
  5032. * Current *ktime*.
  5033. *
  5034. * long bpf_ima_inode_hash(struct inode *inode, void *dst, u32 size)
  5035. * Description
  5036. * Returns the stored IMA hash of the *inode* (if it's available).
  5037. * If the hash is larger than *size*, then only *size*
  5038. * bytes will be copied to *dst*
  5039. * Return
  5040. * The **hash_algo** is returned on success,
  5041. * **-EOPNOTSUPP** if IMA is disabled or **-EINVAL** if
  5042. * invalid arguments are passed.
  5043. *
  5044. * struct socket *bpf_sock_from_file(struct file *file)
  5045. * Description
  5046. * If the given file represents a socket, returns the associated
  5047. * socket.
  5048. * Return
  5049. * A pointer to a struct socket on success or NULL if the file is
  5050. * not a socket.
  5051. *
  5052. * long bpf_check_mtu(void *ctx, u32 ifindex, u32 *mtu_len, s32 len_diff, u64 flags)
  5053. * Description
  5054. * Check packet size against exceeding MTU of net device (based
  5055. * on *ifindex*). This helper will likely be used in combination
  5056. * with helpers that adjust/change the packet size.
  5057. *
  5058. * The argument *len_diff* can be used for querying with a planned
  5059. * size change. This allows to check MTU prior to changing packet
  5060. * ctx. Providing a *len_diff* adjustment that is larger than the
  5061. * actual packet size (resulting in negative packet size) will in
  5062. * principle not exceed the MTU, which is why it is not considered
  5063. * a failure. Other BPF helpers are needed for performing the
  5064. * planned size change; therefore the responsibility for catching
  5065. * a negative packet size belongs in those helpers.
  5066. *
  5067. * Specifying *ifindex* zero means the MTU check is performed
  5068. * against the current net device. This is practical if this isn't
  5069. * used prior to redirect.
  5070. *
  5071. * On input *mtu_len* must be a valid pointer, else verifier will
  5072. * reject BPF program. If the value *mtu_len* is initialized to
  5073. * zero then the ctx packet size is use. When value *mtu_len* is
  5074. * provided as input this specify the L3 length that the MTU check
  5075. * is done against. Remember XDP and TC length operate at L2, but
  5076. * this value is L3 as this correlate to MTU and IP-header tot_len
  5077. * values which are L3 (similar behavior as bpf_fib_lookup).
  5078. *
  5079. * The Linux kernel route table can configure MTUs on a more
  5080. * specific per route level, which is not provided by this helper.
  5081. * For route level MTU checks use the **bpf_fib_lookup**\ ()
  5082. * helper.
  5083. *
  5084. * *ctx* is either **struct xdp_md** for XDP programs or
  5085. * **struct sk_buff** for tc cls_act programs.
  5086. *
  5087. * The *flags* argument can be a combination of one or more of the
  5088. * following values:
  5089. *
  5090. * **BPF_MTU_CHK_SEGS**
  5091. * This flag will only works for *ctx* **struct sk_buff**.
  5092. * If packet context contains extra packet segment buffers
  5093. * (often knows as GSO skb), then MTU check is harder to
  5094. * check at this point, because in transmit path it is
  5095. * possible for the skb packet to get re-segmented
  5096. * (depending on net device features). This could still be
  5097. * a MTU violation, so this flag enables performing MTU
  5098. * check against segments, with a different violation
  5099. * return code to tell it apart. Check cannot use len_diff.
  5100. *
  5101. * On return *mtu_len* pointer contains the MTU value of the net
  5102. * device. Remember the net device configured MTU is the L3 size,
  5103. * which is returned here and XDP and TC length operate at L2.
  5104. * Helper take this into account for you, but remember when using
  5105. * MTU value in your BPF-code.
  5106. *
  5107. * Return
  5108. * * 0 on success, and populate MTU value in *mtu_len* pointer.
  5109. *
  5110. * * < 0 if any input argument is invalid (*mtu_len* not updated)
  5111. *
  5112. * MTU violations return positive values, but also populate MTU
  5113. * value in *mtu_len* pointer, as this can be needed for
  5114. * implementing PMTU handing:
  5115. *
  5116. * * **BPF_MTU_CHK_RET_FRAG_NEEDED**
  5117. * * **BPF_MTU_CHK_RET_SEGS_TOOBIG**
  5118. *
  5119. * long bpf_for_each_map_elem(struct bpf_map *map, void *callback_fn, void *callback_ctx, u64 flags)
  5120. * Description
  5121. * For each element in **map**, call **callback_fn** function with
  5122. * **map**, **callback_ctx** and other map-specific parameters.
  5123. * The **callback_fn** should be a static function and
  5124. * the **callback_ctx** should be a pointer to the stack.
  5125. * The **flags** is used to control certain aspects of the helper.
  5126. * Currently, the **flags** must be 0.
  5127. *
  5128. * The following are a list of supported map types and their
  5129. * respective expected callback signatures:
  5130. *
  5131. * BPF_MAP_TYPE_HASH, BPF_MAP_TYPE_PERCPU_HASH,
  5132. * BPF_MAP_TYPE_LRU_HASH, BPF_MAP_TYPE_LRU_PERCPU_HASH,
  5133. * BPF_MAP_TYPE_ARRAY, BPF_MAP_TYPE_PERCPU_ARRAY
  5134. *
  5135. * long (\*callback_fn)(struct bpf_map \*map, const void \*key, void \*value, void \*ctx);
  5136. *
  5137. * For per_cpu maps, the map_value is the value on the cpu where the
  5138. * bpf_prog is running.
  5139. *
  5140. * If **callback_fn** return 0, the helper will continue to the next
  5141. * element. If return value is 1, the helper will skip the rest of
  5142. * elements and return. Other return values are not used now.
  5143. *
  5144. * Return
  5145. * The number of traversed map elements for success, **-EINVAL** for
  5146. * invalid **flags**.
  5147. *
  5148. * long bpf_snprintf(char *str, u32 str_size, const char *fmt, u64 *data, u32 data_len)
  5149. * Description
  5150. * Outputs a string into the **str** buffer of size **str_size**
  5151. * based on a format string stored in a read-only map pointed by
  5152. * **fmt**.
  5153. *
  5154. * Each format specifier in **fmt** corresponds to one u64 element
  5155. * in the **data** array. For strings and pointers where pointees
  5156. * are accessed, only the pointer values are stored in the *data*
  5157. * array. The *data_len* is the size of *data* in bytes - must be
  5158. * a multiple of 8.
  5159. *
  5160. * Formats **%s** and **%p{i,I}{4,6}** require to read kernel
  5161. * memory. Reading kernel memory may fail due to either invalid
  5162. * address or valid address but requiring a major memory fault. If
  5163. * reading kernel memory fails, the string for **%s** will be an
  5164. * empty string, and the ip address for **%p{i,I}{4,6}** will be 0.
  5165. * Not returning error to bpf program is consistent with what
  5166. * **bpf_trace_printk**\ () does for now.
  5167. *
  5168. * Return
  5169. * The strictly positive length of the formatted string, including
  5170. * the trailing zero character. If the return value is greater than
  5171. * **str_size**, **str** contains a truncated string, guaranteed to
  5172. * be zero-terminated except when **str_size** is 0.
  5173. *
  5174. * Or **-EBUSY** if the per-CPU memory copy buffer is busy.
  5175. *
  5176. * long bpf_sys_bpf(u32 cmd, void *attr, u32 attr_size)
  5177. * Description
  5178. * Execute bpf syscall with given arguments.
  5179. * Return
  5180. * A syscall result.
  5181. *
  5182. * long bpf_btf_find_by_name_kind(char *name, int name_sz, u32 kind, int flags)
  5183. * Description
  5184. * Find BTF type with given name and kind in vmlinux BTF or in module's BTFs.
  5185. * Return
  5186. * Returns btf_id and btf_obj_fd in lower and upper 32 bits.
  5187. *
  5188. * long bpf_sys_close(u32 fd)
  5189. * Description
  5190. * Execute close syscall for given FD.
  5191. * Return
  5192. * A syscall result.
  5193. *
  5194. * long bpf_timer_init(struct bpf_timer *timer, struct bpf_map *map, u64 flags)
  5195. * Description
  5196. * Initialize the timer.
  5197. * First 4 bits of *flags* specify clockid.
  5198. * Only CLOCK_MONOTONIC, CLOCK_REALTIME, CLOCK_BOOTTIME are allowed.
  5199. * All other bits of *flags* are reserved.
  5200. * The verifier will reject the program if *timer* is not from
  5201. * the same *map*.
  5202. * Return
  5203. * 0 on success.
  5204. * **-EBUSY** if *timer* is already initialized.
  5205. * **-EINVAL** if invalid *flags* are passed.
  5206. * **-EPERM** if *timer* is in a map that doesn't have any user references.
  5207. * The user space should either hold a file descriptor to a map with timers
  5208. * or pin such map in bpffs. When map is unpinned or file descriptor is
  5209. * closed all timers in the map will be cancelled and freed.
  5210. *
  5211. * long bpf_timer_set_callback(struct bpf_timer *timer, void *callback_fn)
  5212. * Description
  5213. * Configure the timer to call *callback_fn* static function.
  5214. * Return
  5215. * 0 on success.
  5216. * **-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier.
  5217. * **-EPERM** if *timer* is in a map that doesn't have any user references.
  5218. * The user space should either hold a file descriptor to a map with timers
  5219. * or pin such map in bpffs. When map is unpinned or file descriptor is
  5220. * closed all timers in the map will be cancelled and freed.
  5221. *
  5222. * long bpf_timer_start(struct bpf_timer *timer, u64 nsecs, u64 flags)
  5223. * Description
  5224. * Set timer expiration N nanoseconds from the current time. The
  5225. * configured callback will be invoked in soft irq context on some cpu
  5226. * and will not repeat unless another bpf_timer_start() is made.
  5227. * In such case the next invocation can migrate to a different cpu.
  5228. * Since struct bpf_timer is a field inside map element the map
  5229. * owns the timer. The bpf_timer_set_callback() will increment refcnt
  5230. * of BPF program to make sure that callback_fn code stays valid.
  5231. * When user space reference to a map reaches zero all timers
  5232. * in a map are cancelled and corresponding program's refcnts are
  5233. * decremented. This is done to make sure that Ctrl-C of a user
  5234. * process doesn't leave any timers running. If map is pinned in
  5235. * bpffs the callback_fn can re-arm itself indefinitely.
  5236. * bpf_map_update/delete_elem() helpers and user space sys_bpf commands
  5237. * cancel and free the timer in the given map element.
  5238. * The map can contain timers that invoke callback_fn-s from different
  5239. * programs. The same callback_fn can serve different timers from
  5240. * different maps if key/value layout matches across maps.
  5241. * Every bpf_timer_set_callback() can have different callback_fn.
  5242. *
  5243. * *flags* can be one of:
  5244. *
  5245. * **BPF_F_TIMER_ABS**
  5246. * Start the timer in absolute expire value instead of the
  5247. * default relative one.
  5248. * **BPF_F_TIMER_CPU_PIN**
  5249. * Timer will be pinned to the CPU of the caller.
  5250. *
  5251. * Return
  5252. * 0 on success.
  5253. * **-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier
  5254. * or invalid *flags* are passed.
  5255. *
  5256. * long bpf_timer_cancel(struct bpf_timer *timer)
  5257. * Description
  5258. * Cancel the timer and wait for callback_fn to finish if it was running.
  5259. * Return
  5260. * 0 if the timer was not active.
  5261. * 1 if the timer was active.
  5262. * **-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier.
  5263. * **-EDEADLK** if callback_fn tried to call bpf_timer_cancel() on its
  5264. * own timer which would have led to a deadlock otherwise.
  5265. *
  5266. * u64 bpf_get_func_ip(void *ctx)
  5267. * Description
  5268. * Get address of the traced function (for tracing and kprobe programs).
  5269. *
  5270. * When called for kprobe program attached as uprobe it returns
  5271. * probe address for both entry and return uprobe.
  5272. *
  5273. * Return
  5274. * Address of the traced function for kprobe.
  5275. * 0 for kprobes placed within the function (not at the entry).
  5276. * Address of the probe for uprobe and return uprobe.
  5277. *
  5278. * u64 bpf_get_attach_cookie(void *ctx)
  5279. * Description
  5280. * Get bpf_cookie value provided (optionally) during the program
  5281. * attachment. It might be different for each individual
  5282. * attachment, even if BPF program itself is the same.
  5283. * Expects BPF program context *ctx* as a first argument.
  5284. *
  5285. * Supported for the following program types:
  5286. * - kprobe/uprobe;
  5287. * - tracepoint;
  5288. * - perf_event.
  5289. * Return
  5290. * Value specified by user at BPF link creation/attachment time
  5291. * or 0, if it was not specified.
  5292. *
  5293. * long bpf_task_pt_regs(struct task_struct *task)
  5294. * Description
  5295. * Get the struct pt_regs associated with **task**.
  5296. * Return
  5297. * A pointer to struct pt_regs.
  5298. *
  5299. * long bpf_get_branch_snapshot(void *entries, u32 size, u64 flags)
  5300. * Description
  5301. * Get branch trace from hardware engines like Intel LBR. The
  5302. * hardware engine is stopped shortly after the helper is
  5303. * called. Therefore, the user need to filter branch entries
  5304. * based on the actual use case. To capture branch trace
  5305. * before the trigger point of the BPF program, the helper
  5306. * should be called at the beginning of the BPF program.
  5307. *
  5308. * The data is stored as struct perf_branch_entry into output
  5309. * buffer *entries*. *size* is the size of *entries* in bytes.
  5310. * *flags* is reserved for now and must be zero.
  5311. *
  5312. * Return
  5313. * On success, number of bytes written to *buf*. On error, a
  5314. * negative value.
  5315. *
  5316. * **-EINVAL** if *flags* is not zero.
  5317. *
  5318. * **-ENOENT** if architecture does not support branch records.
  5319. *
  5320. * long bpf_trace_vprintk(const char *fmt, u32 fmt_size, const void *data, u32 data_len)
  5321. * Description
  5322. * Behaves like **bpf_trace_printk**\ () helper, but takes an array of u64
  5323. * to format and can handle more format args as a result.
  5324. *
  5325. * Arguments are to be used as in **bpf_seq_printf**\ () helper.
  5326. * Return
  5327. * The number of bytes written to the buffer, or a negative error
  5328. * in case of failure.
  5329. *
  5330. * struct unix_sock *bpf_skc_to_unix_sock(void *sk)
  5331. * Description
  5332. * Dynamically cast a *sk* pointer to a *unix_sock* pointer.
  5333. * Return
  5334. * *sk* if casting is valid, or **NULL** otherwise.
  5335. *
  5336. * long bpf_kallsyms_lookup_name(const char *name, int name_sz, int flags, u64 *res)
  5337. * Description
  5338. * Get the address of a kernel symbol, returned in *res*. *res* is
  5339. * set to 0 if the symbol is not found.
  5340. * Return
  5341. * On success, zero. On error, a negative value.
  5342. *
  5343. * **-EINVAL** if *flags* is not zero.
  5344. *
  5345. * **-EINVAL** if string *name* is not the same size as *name_sz*.
  5346. *
  5347. * **-ENOENT** if symbol is not found.
  5348. *
  5349. * **-EPERM** if caller does not have permission to obtain kernel address.
  5350. *
  5351. * long bpf_find_vma(struct task_struct *task, u64 addr, void *callback_fn, void *callback_ctx, u64 flags)
  5352. * Description
  5353. * Find vma of *task* that contains *addr*, call *callback_fn*
  5354. * function with *task*, *vma*, and *callback_ctx*.
  5355. * The *callback_fn* should be a static function and
  5356. * the *callback_ctx* should be a pointer to the stack.
  5357. * The *flags* is used to control certain aspects of the helper.
  5358. * Currently, the *flags* must be 0.
  5359. *
  5360. * The expected callback signature is
  5361. *
  5362. * long (\*callback_fn)(struct task_struct \*task, struct vm_area_struct \*vma, void \*callback_ctx);
  5363. *
  5364. * Return
  5365. * 0 on success.
  5366. * **-ENOENT** if *task->mm* is NULL, or no vma contains *addr*.
  5367. * **-EBUSY** if failed to try lock mmap_lock.
  5368. * **-EINVAL** for invalid **flags**.
  5369. *
  5370. * long bpf_loop(u32 nr_loops, void *callback_fn, void *callback_ctx, u64 flags)
  5371. * Description
  5372. * For **nr_loops**, call **callback_fn** function
  5373. * with **callback_ctx** as the context parameter.
  5374. * The **callback_fn** should be a static function and
  5375. * the **callback_ctx** should be a pointer to the stack.
  5376. * The **flags** is used to control certain aspects of the helper.
  5377. * Currently, the **flags** must be 0. Currently, nr_loops is
  5378. * limited to 1 << 23 (~8 million) loops.
  5379. *
  5380. * long (\*callback_fn)(u64 index, void \*ctx);
  5381. *
  5382. * where **index** is the current index in the loop. The index
  5383. * is zero-indexed.
  5384. *
  5385. * If **callback_fn** returns 0, the helper will continue to the next
  5386. * loop. If return value is 1, the helper will skip the rest of
  5387. * the loops and return. Other return values are not used now,
  5388. * and will be rejected by the verifier.
  5389. *
  5390. * Return
  5391. * The number of loops performed, **-EINVAL** for invalid **flags**,
  5392. * **-E2BIG** if **nr_loops** exceeds the maximum number of loops.
  5393. *
  5394. * long bpf_strncmp(const char *s1, u32 s1_sz, const char *s2)
  5395. * Description
  5396. * Do strncmp() between **s1** and **s2**. **s1** doesn't need
  5397. * to be null-terminated and **s1_sz** is the maximum storage
  5398. * size of **s1**. **s2** must be a read-only string.
  5399. * Return
  5400. * An integer less than, equal to, or greater than zero
  5401. * if the first **s1_sz** bytes of **s1** is found to be
  5402. * less than, to match, or be greater than **s2**.
  5403. *
  5404. * long bpf_get_func_arg(void *ctx, u32 n, u64 *value)
  5405. * Description
  5406. * Get **n**-th argument register (zero based) of the traced function (for tracing programs)
  5407. * returned in **value**.
  5408. *
  5409. * Return
  5410. * 0 on success.
  5411. * **-EINVAL** if n >= argument register count of traced function.
  5412. *
  5413. * long bpf_get_func_ret(void *ctx, u64 *value)
  5414. * Description
  5415. * Get return value of the traced function (for tracing programs)
  5416. * in **value**.
  5417. *
  5418. * Return
  5419. * 0 on success.
  5420. * **-EOPNOTSUPP** for tracing programs other than BPF_TRACE_FEXIT or BPF_MODIFY_RETURN.
  5421. *
  5422. * long bpf_get_func_arg_cnt(void *ctx)
  5423. * Description
  5424. * Get number of registers of the traced function (for tracing programs) where
  5425. * function arguments are stored in these registers.
  5426. *
  5427. * Return
  5428. * The number of argument registers of the traced function.
  5429. *
  5430. * int bpf_get_retval(void)
  5431. * Description
  5432. * Get the BPF program's return value that will be returned to the upper layers.
  5433. *
  5434. * This helper is currently supported by cgroup programs and only by the hooks
  5435. * where BPF program's return value is returned to the userspace via errno.
  5436. * Return
  5437. * The BPF program's return value.
  5438. *
  5439. * int bpf_set_retval(int retval)
  5440. * Description
  5441. * Set the BPF program's return value that will be returned to the upper layers.
  5442. *
  5443. * This helper is currently supported by cgroup programs and only by the hooks
  5444. * where BPF program's return value is returned to the userspace via errno.
  5445. *
  5446. * Note that there is the following corner case where the program exports an error
  5447. * via bpf_set_retval but signals success via 'return 1':
  5448. *
  5449. * bpf_set_retval(-EPERM);
  5450. * return 1;
  5451. *
  5452. * In this case, the BPF program's return value will use helper's -EPERM. This
  5453. * still holds true for cgroup/bind{4,6} which supports extra 'return 3' success case.
  5454. *
  5455. * Return
  5456. * 0 on success, or a negative error in case of failure.
  5457. *
  5458. * u64 bpf_xdp_get_buff_len(struct xdp_buff *xdp_md)
  5459. * Description
  5460. * Get the total size of a given xdp buff (linear and paged area)
  5461. * Return
  5462. * The total size of a given xdp buffer.
  5463. *
  5464. * long bpf_xdp_load_bytes(struct xdp_buff *xdp_md, u32 offset, void *buf, u32 len)
  5465. * Description
  5466. * This helper is provided as an easy way to load data from a
  5467. * xdp buffer. It can be used to load *len* bytes from *offset* from
  5468. * the frame associated to *xdp_md*, into the buffer pointed by
  5469. * *buf*.
  5470. * Return
  5471. * 0 on success, or a negative error in case of failure.
  5472. *
  5473. * long bpf_xdp_store_bytes(struct xdp_buff *xdp_md, u32 offset, void *buf, u32 len)
  5474. * Description
  5475. * Store *len* bytes from buffer *buf* into the frame
  5476. * associated to *xdp_md*, at *offset*.
  5477. * Return
  5478. * 0 on success, or a negative error in case of failure.
  5479. *
  5480. * long bpf_copy_from_user_task(void *dst, u32 size, const void *user_ptr, struct task_struct *tsk, u64 flags)
  5481. * Description
  5482. * Read *size* bytes from user space address *user_ptr* in *tsk*'s
  5483. * address space, and stores the data in *dst*. *flags* is not
  5484. * used yet and is provided for future extensibility. This helper
  5485. * can only be used by sleepable programs.
  5486. * Return
  5487. * 0 on success, or a negative error in case of failure. On error
  5488. * *dst* buffer is zeroed out.
  5489. *
  5490. * long bpf_skb_set_tstamp(struct sk_buff *skb, u64 tstamp, u32 tstamp_type)
  5491. * Description
  5492. * Change the __sk_buff->tstamp_type to *tstamp_type*
  5493. * and set *tstamp* to the __sk_buff->tstamp together.
  5494. *
  5495. * If there is no need to change the __sk_buff->tstamp_type,
  5496. * the tstamp value can be directly written to __sk_buff->tstamp
  5497. * instead.
  5498. *
  5499. * BPF_SKB_TSTAMP_DELIVERY_MONO is the only tstamp that
  5500. * will be kept during bpf_redirect_*(). A non zero
  5501. * *tstamp* must be used with the BPF_SKB_TSTAMP_DELIVERY_MONO
  5502. * *tstamp_type*.
  5503. *
  5504. * A BPF_SKB_TSTAMP_UNSPEC *tstamp_type* can only be used
  5505. * with a zero *tstamp*.
  5506. *
  5507. * Only IPv4 and IPv6 skb->protocol are supported.
  5508. *
  5509. * This function is most useful when it needs to set a
  5510. * mono delivery time to __sk_buff->tstamp and then
  5511. * bpf_redirect_*() to the egress of an iface. For example,
  5512. * changing the (rcv) timestamp in __sk_buff->tstamp at
  5513. * ingress to a mono delivery time and then bpf_redirect_*()
  5514. * to sch_fq@phy-dev.
  5515. * Return
  5516. * 0 on success.
  5517. * **-EINVAL** for invalid input
  5518. * **-EOPNOTSUPP** for unsupported protocol
  5519. *
  5520. * long bpf_ima_file_hash(struct file *file, void *dst, u32 size)
  5521. * Description
  5522. * Returns a calculated IMA hash of the *file*.
  5523. * If the hash is larger than *size*, then only *size*
  5524. * bytes will be copied to *dst*
  5525. * Return
  5526. * The **hash_algo** is returned on success,
  5527. * **-EOPNOTSUPP** if the hash calculation failed or **-EINVAL** if
  5528. * invalid arguments are passed.
  5529. *
  5530. * void *bpf_kptr_xchg(void *dst, void *ptr)
  5531. * Description
  5532. * Exchange kptr at pointer *dst* with *ptr*, and return the old value.
  5533. * *dst* can be map value or local kptr. *ptr* can be NULL, otherwise
  5534. * it must be a referenced pointer which will be released when this helper
  5535. * is called.
  5536. * Return
  5537. * The old value of kptr (which can be NULL). The returned pointer
  5538. * if not NULL, is a reference which must be released using its
  5539. * corresponding release function, or moved into a BPF map before
  5540. * program exit.
  5541. *
  5542. * void *bpf_map_lookup_percpu_elem(struct bpf_map *map, const void *key, u32 cpu)
  5543. * Description
  5544. * Perform a lookup in *percpu map* for an entry associated to
  5545. * *key* on *cpu*.
  5546. * Return
  5547. * Map value associated to *key* on *cpu*, or **NULL** if no entry
  5548. * was found or *cpu* is invalid.
  5549. *
  5550. * struct mptcp_sock *bpf_skc_to_mptcp_sock(void *sk)
  5551. * Description
  5552. * Dynamically cast a *sk* pointer to a *mptcp_sock* pointer.
  5553. * Return
  5554. * *sk* if casting is valid, or **NULL** otherwise.
  5555. *
  5556. * long bpf_dynptr_from_mem(void *data, u64 size, u64 flags, struct bpf_dynptr *ptr)
  5557. * Description
  5558. * Get a dynptr to local memory *data*.
  5559. *
  5560. * *data* must be a ptr to a map value.
  5561. * The maximum *size* supported is DYNPTR_MAX_SIZE.
  5562. * *flags* is currently unused.
  5563. * Return
  5564. * 0 on success, -E2BIG if the size exceeds DYNPTR_MAX_SIZE,
  5565. * -EINVAL if flags is not 0.
  5566. *
  5567. * long bpf_ringbuf_reserve_dynptr(void *ringbuf, u32 size, u64 flags, struct bpf_dynptr *ptr)
  5568. * Description
  5569. * Reserve *size* bytes of payload in a ring buffer *ringbuf*
  5570. * through the dynptr interface. *flags* must be 0.
  5571. *
  5572. * Please note that a corresponding bpf_ringbuf_submit_dynptr or
  5573. * bpf_ringbuf_discard_dynptr must be called on *ptr*, even if the
  5574. * reservation fails. This is enforced by the verifier.
  5575. * Return
  5576. * 0 on success, or a negative error in case of failure.
  5577. *
  5578. * void bpf_ringbuf_submit_dynptr(struct bpf_dynptr *ptr, u64 flags)
  5579. * Description
  5580. * Submit reserved ring buffer sample, pointed to by *data*,
  5581. * through the dynptr interface. This is a no-op if the dynptr is
  5582. * invalid/null.
  5583. *
  5584. * For more information on *flags*, please see
  5585. * 'bpf_ringbuf_submit'.
  5586. * Return
  5587. * Nothing. Always succeeds.
  5588. *
  5589. * void bpf_ringbuf_discard_dynptr(struct bpf_dynptr *ptr, u64 flags)
  5590. * Description
  5591. * Discard reserved ring buffer sample through the dynptr
  5592. * interface. This is a no-op if the dynptr is invalid/null.
  5593. *
  5594. * For more information on *flags*, please see
  5595. * 'bpf_ringbuf_discard'.
  5596. * Return
  5597. * Nothing. Always succeeds.
  5598. *
  5599. * long bpf_dynptr_read(void *dst, u64 len, const struct bpf_dynptr *src, u64 offset, u64 flags)
  5600. * Description
  5601. * Read *len* bytes from *src* into *dst*, starting from *offset*
  5602. * into *src*.
  5603. * *flags* is currently unused.
  5604. * Return
  5605. * 0 on success, -E2BIG if *offset* + *len* exceeds the length
  5606. * of *src*'s data, -EINVAL if *src* is an invalid dynptr or if
  5607. * *flags* is not 0.
  5608. *
  5609. * long bpf_dynptr_write(const struct bpf_dynptr *dst, u64 offset, void *src, u64 len, u64 flags)
  5610. * Description
  5611. * Write *len* bytes from *src* into *dst*, starting from *offset*
  5612. * into *dst*.
  5613. *
  5614. * *flags* must be 0 except for skb-type dynptrs.
  5615. *
  5616. * For skb-type dynptrs:
  5617. * * All data slices of the dynptr are automatically
  5618. * invalidated after **bpf_dynptr_write**\ (). This is
  5619. * because writing may pull the skb and change the
  5620. * underlying packet buffer.
  5621. *
  5622. * * For *flags*, please see the flags accepted by
  5623. * **bpf_skb_store_bytes**\ ().
  5624. * Return
  5625. * 0 on success, -E2BIG if *offset* + *len* exceeds the length
  5626. * of *dst*'s data, -EINVAL if *dst* is an invalid dynptr or if *dst*
  5627. * is a read-only dynptr or if *flags* is not correct. For skb-type dynptrs,
  5628. * other errors correspond to errors returned by **bpf_skb_store_bytes**\ ().
  5629. *
  5630. * void *bpf_dynptr_data(const struct bpf_dynptr *ptr, u64 offset, u64 len)
  5631. * Description
  5632. * Get a pointer to the underlying dynptr data.
  5633. *
  5634. * *len* must be a statically known value. The returned data slice
  5635. * is invalidated whenever the dynptr is invalidated.
  5636. *
  5637. * skb and xdp type dynptrs may not use bpf_dynptr_data. They should
  5638. * instead use bpf_dynptr_slice and bpf_dynptr_slice_rdwr.
  5639. * Return
  5640. * Pointer to the underlying dynptr data, NULL if the dynptr is
  5641. * read-only, if the dynptr is invalid, or if the offset and length
  5642. * is out of bounds.
  5643. *
  5644. * s64 bpf_tcp_raw_gen_syncookie_ipv4(struct iphdr *iph, struct tcphdr *th, u32 th_len)
  5645. * Description
  5646. * Try to issue a SYN cookie for the packet with corresponding
  5647. * IPv4/TCP headers, *iph* and *th*, without depending on a
  5648. * listening socket.
  5649. *
  5650. * *iph* points to the IPv4 header.
  5651. *
  5652. * *th* points to the start of the TCP header, while *th_len*
  5653. * contains the length of the TCP header (at least
  5654. * **sizeof**\ (**struct tcphdr**)).
  5655. * Return
  5656. * On success, lower 32 bits hold the generated SYN cookie in
  5657. * followed by 16 bits which hold the MSS value for that cookie,
  5658. * and the top 16 bits are unused.
  5659. *
  5660. * On failure, the returned value is one of the following:
  5661. *
  5662. * **-EINVAL** if *th_len* is invalid.
  5663. *
  5664. * s64 bpf_tcp_raw_gen_syncookie_ipv6(struct ipv6hdr *iph, struct tcphdr *th, u32 th_len)
  5665. * Description
  5666. * Try to issue a SYN cookie for the packet with corresponding
  5667. * IPv6/TCP headers, *iph* and *th*, without depending on a
  5668. * listening socket.
  5669. *
  5670. * *iph* points to the IPv6 header.
  5671. *
  5672. * *th* points to the start of the TCP header, while *th_len*
  5673. * contains the length of the TCP header (at least
  5674. * **sizeof**\ (**struct tcphdr**)).
  5675. * Return
  5676. * On success, lower 32 bits hold the generated SYN cookie in
  5677. * followed by 16 bits which hold the MSS value for that cookie,
  5678. * and the top 16 bits are unused.
  5679. *
  5680. * On failure, the returned value is one of the following:
  5681. *
  5682. * **-EINVAL** if *th_len* is invalid.
  5683. *
  5684. * **-EPROTONOSUPPORT** if CONFIG_IPV6 is not builtin.
  5685. *
  5686. * long bpf_tcp_raw_check_syncookie_ipv4(struct iphdr *iph, struct tcphdr *th)
  5687. * Description
  5688. * Check whether *iph* and *th* contain a valid SYN cookie ACK
  5689. * without depending on a listening socket.
  5690. *
  5691. * *iph* points to the IPv4 header.
  5692. *
  5693. * *th* points to the TCP header.
  5694. * Return
  5695. * 0 if *iph* and *th* are a valid SYN cookie ACK.
  5696. *
  5697. * On failure, the returned value is one of the following:
  5698. *
  5699. * **-EACCES** if the SYN cookie is not valid.
  5700. *
  5701. * long bpf_tcp_raw_check_syncookie_ipv6(struct ipv6hdr *iph, struct tcphdr *th)
  5702. * Description
  5703. * Check whether *iph* and *th* contain a valid SYN cookie ACK
  5704. * without depending on a listening socket.
  5705. *
  5706. * *iph* points to the IPv6 header.
  5707. *
  5708. * *th* points to the TCP header.
  5709. * Return
  5710. * 0 if *iph* and *th* are a valid SYN cookie ACK.
  5711. *
  5712. * On failure, the returned value is one of the following:
  5713. *
  5714. * **-EACCES** if the SYN cookie is not valid.
  5715. *
  5716. * **-EPROTONOSUPPORT** if CONFIG_IPV6 is not builtin.
  5717. *
  5718. * u64 bpf_ktime_get_tai_ns(void)
  5719. * Description
  5720. * A nonsettable system-wide clock derived from wall-clock time but
  5721. * ignoring leap seconds. This clock does not experience
  5722. * discontinuities and backwards jumps caused by NTP inserting leap
  5723. * seconds as CLOCK_REALTIME does.
  5724. *
  5725. * See: **clock_gettime**\ (**CLOCK_TAI**)
  5726. * Return
  5727. * Current *ktime*.
  5728. *
  5729. * long bpf_user_ringbuf_drain(struct bpf_map *map, void *callback_fn, void *ctx, u64 flags)
  5730. * Description
  5731. * Drain samples from the specified user ring buffer, and invoke
  5732. * the provided callback for each such sample:
  5733. *
  5734. * long (\*callback_fn)(const struct bpf_dynptr \*dynptr, void \*ctx);
  5735. *
  5736. * If **callback_fn** returns 0, the helper will continue to try
  5737. * and drain the next sample, up to a maximum of
  5738. * BPF_MAX_USER_RINGBUF_SAMPLES samples. If the return value is 1,
  5739. * the helper will skip the rest of the samples and return. Other
  5740. * return values are not used now, and will be rejected by the
  5741. * verifier.
  5742. * Return
  5743. * The number of drained samples if no error was encountered while
  5744. * draining samples, or 0 if no samples were present in the ring
  5745. * buffer. If a user-space producer was epoll-waiting on this map,
  5746. * and at least one sample was drained, they will receive an event
  5747. * notification notifying them of available space in the ring
  5748. * buffer. If the BPF_RB_NO_WAKEUP flag is passed to this
  5749. * function, no wakeup notification will be sent. If the
  5750. * BPF_RB_FORCE_WAKEUP flag is passed, a wakeup notification will
  5751. * be sent even if no sample was drained.
  5752. *
  5753. * On failure, the returned value is one of the following:
  5754. *
  5755. * **-EBUSY** if the ring buffer is contended, and another calling
  5756. * context was concurrently draining the ring buffer.
  5757. *
  5758. * **-EINVAL** if user-space is not properly tracking the ring
  5759. * buffer due to the producer position not being aligned to 8
  5760. * bytes, a sample not being aligned to 8 bytes, or the producer
  5761. * position not matching the advertised length of a sample.
  5762. *
  5763. * **-E2BIG** if user-space has tried to publish a sample which is
  5764. * larger than the size of the ring buffer, or which cannot fit
  5765. * within a struct bpf_dynptr.
  5766. *
  5767. * void *bpf_cgrp_storage_get(struct bpf_map *map, struct cgroup *cgroup, void *value, u64 flags)
  5768. * Description
  5769. * Get a bpf_local_storage from the *cgroup*.
  5770. *
  5771. * Logically, it could be thought of as getting the value from
  5772. * a *map* with *cgroup* as the **key**. From this
  5773. * perspective, the usage is not much different from
  5774. * **bpf_map_lookup_elem**\ (*map*, **&**\ *cgroup*) except this
  5775. * helper enforces the key must be a cgroup struct and the map must also
  5776. * be a **BPF_MAP_TYPE_CGRP_STORAGE**.
  5777. *
  5778. * In reality, the local-storage value is embedded directly inside of the
  5779. * *cgroup* object itself, rather than being located in the
  5780. * **BPF_MAP_TYPE_CGRP_STORAGE** map. When the local-storage value is
  5781. * queried for some *map* on a *cgroup* object, the kernel will perform an
  5782. * O(n) iteration over all of the live local-storage values for that
  5783. * *cgroup* object until the local-storage value for the *map* is found.
  5784. *
  5785. * An optional *flags* (**BPF_LOCAL_STORAGE_GET_F_CREATE**) can be
  5786. * used such that a new bpf_local_storage will be
  5787. * created if one does not exist. *value* can be used
  5788. * together with **BPF_LOCAL_STORAGE_GET_F_CREATE** to specify
  5789. * the initial value of a bpf_local_storage. If *value* is
  5790. * **NULL**, the new bpf_local_storage will be zero initialized.
  5791. * Return
  5792. * A bpf_local_storage pointer is returned on success.
  5793. *
  5794. * **NULL** if not found or there was an error in adding
  5795. * a new bpf_local_storage.
  5796. *
  5797. * long bpf_cgrp_storage_delete(struct bpf_map *map, struct cgroup *cgroup)
  5798. * Description
  5799. * Delete a bpf_local_storage from a *cgroup*.
  5800. * Return
  5801. * 0 on success.
  5802. *
  5803. * **-ENOENT** if the bpf_local_storage cannot be found.
  5804. */
  5805. #define ___BPF_FUNC_MAPPER(FN, ctx...) \
  5806. FN(unspec, 0, ##ctx) \
  5807. FN(map_lookup_elem, 1, ##ctx) \
  5808. FN(map_update_elem, 2, ##ctx) \
  5809. FN(map_delete_elem, 3, ##ctx) \
  5810. FN(probe_read, 4, ##ctx) \
  5811. FN(ktime_get_ns, 5, ##ctx) \
  5812. FN(trace_printk, 6, ##ctx) \
  5813. FN(get_prandom_u32, 7, ##ctx) \
  5814. FN(get_smp_processor_id, 8, ##ctx) \
  5815. FN(skb_store_bytes, 9, ##ctx) \
  5816. FN(l3_csum_replace, 10, ##ctx) \
  5817. FN(l4_csum_replace, 11, ##ctx) \
  5818. FN(tail_call, 12, ##ctx) \
  5819. FN(clone_redirect, 13, ##ctx) \
  5820. FN(get_current_pid_tgid, 14, ##ctx) \
  5821. FN(get_current_uid_gid, 15, ##ctx) \
  5822. FN(get_current_comm, 16, ##ctx) \
  5823. FN(get_cgroup_classid, 17, ##ctx) \
  5824. FN(skb_vlan_push, 18, ##ctx) \
  5825. FN(skb_vlan_pop, 19, ##ctx) \
  5826. FN(skb_get_tunnel_key, 20, ##ctx) \
  5827. FN(skb_set_tunnel_key, 21, ##ctx) \
  5828. FN(perf_event_read, 22, ##ctx) \
  5829. FN(redirect, 23, ##ctx) \
  5830. FN(get_route_realm, 24, ##ctx) \
  5831. FN(perf_event_output, 25, ##ctx) \
  5832. FN(skb_load_bytes, 26, ##ctx) \
  5833. FN(get_stackid, 27, ##ctx) \
  5834. FN(csum_diff, 28, ##ctx) \
  5835. FN(skb_get_tunnel_opt, 29, ##ctx) \
  5836. FN(skb_set_tunnel_opt, 30, ##ctx) \
  5837. FN(skb_change_proto, 31, ##ctx) \
  5838. FN(skb_change_type, 32, ##ctx) \
  5839. FN(skb_under_cgroup, 33, ##ctx) \
  5840. FN(get_hash_recalc, 34, ##ctx) \
  5841. FN(get_current_task, 35, ##ctx) \
  5842. FN(probe_write_user, 36, ##ctx) \
  5843. FN(current_task_under_cgroup, 37, ##ctx) \
  5844. FN(skb_change_tail, 38, ##ctx) \
  5845. FN(skb_pull_data, 39, ##ctx) \
  5846. FN(csum_update, 40, ##ctx) \
  5847. FN(set_hash_invalid, 41, ##ctx) \
  5848. FN(get_numa_node_id, 42, ##ctx) \
  5849. FN(skb_change_head, 43, ##ctx) \
  5850. FN(xdp_adjust_head, 44, ##ctx) \
  5851. FN(probe_read_str, 45, ##ctx) \
  5852. FN(get_socket_cookie, 46, ##ctx) \
  5853. FN(get_socket_uid, 47, ##ctx) \
  5854. FN(set_hash, 48, ##ctx) \
  5855. FN(setsockopt, 49, ##ctx) \
  5856. FN(skb_adjust_room, 50, ##ctx) \
  5857. FN(redirect_map, 51, ##ctx) \
  5858. FN(sk_redirect_map, 52, ##ctx) \
  5859. FN(sock_map_update, 53, ##ctx) \
  5860. FN(xdp_adjust_meta, 54, ##ctx) \
  5861. FN(perf_event_read_value, 55, ##ctx) \
  5862. FN(perf_prog_read_value, 56, ##ctx) \
  5863. FN(getsockopt, 57, ##ctx) \
  5864. FN(override_return, 58, ##ctx) \
  5865. FN(sock_ops_cb_flags_set, 59, ##ctx) \
  5866. FN(msg_redirect_map, 60, ##ctx) \
  5867. FN(msg_apply_bytes, 61, ##ctx) \
  5868. FN(msg_cork_bytes, 62, ##ctx) \
  5869. FN(msg_pull_data, 63, ##ctx) \
  5870. FN(bind, 64, ##ctx) \
  5871. FN(xdp_adjust_tail, 65, ##ctx) \
  5872. FN(skb_get_xfrm_state, 66, ##ctx) \
  5873. FN(get_stack, 67, ##ctx) \
  5874. FN(skb_load_bytes_relative, 68, ##ctx) \
  5875. FN(fib_lookup, 69, ##ctx) \
  5876. FN(sock_hash_update, 70, ##ctx) \
  5877. FN(msg_redirect_hash, 71, ##ctx) \
  5878. FN(sk_redirect_hash, 72, ##ctx) \
  5879. FN(lwt_push_encap, 73, ##ctx) \
  5880. FN(lwt_seg6_store_bytes, 74, ##ctx) \
  5881. FN(lwt_seg6_adjust_srh, 75, ##ctx) \
  5882. FN(lwt_seg6_action, 76, ##ctx) \
  5883. FN(rc_repeat, 77, ##ctx) \
  5884. FN(rc_keydown, 78, ##ctx) \
  5885. FN(skb_cgroup_id, 79, ##ctx) \
  5886. FN(get_current_cgroup_id, 80, ##ctx) \
  5887. FN(get_local_storage, 81, ##ctx) \
  5888. FN(sk_select_reuseport, 82, ##ctx) \
  5889. FN(skb_ancestor_cgroup_id, 83, ##ctx) \
  5890. FN(sk_lookup_tcp, 84, ##ctx) \
  5891. FN(sk_lookup_udp, 85, ##ctx) \
  5892. FN(sk_release, 86, ##ctx) \
  5893. FN(map_push_elem, 87, ##ctx) \
  5894. FN(map_pop_elem, 88, ##ctx) \
  5895. FN(map_peek_elem, 89, ##ctx) \
  5896. FN(msg_push_data, 90, ##ctx) \
  5897. FN(msg_pop_data, 91, ##ctx) \
  5898. FN(rc_pointer_rel, 92, ##ctx) \
  5899. FN(spin_lock, 93, ##ctx) \
  5900. FN(spin_unlock, 94, ##ctx) \
  5901. FN(sk_fullsock, 95, ##ctx) \
  5902. FN(tcp_sock, 96, ##ctx) \
  5903. FN(skb_ecn_set_ce, 97, ##ctx) \
  5904. FN(get_listener_sock, 98, ##ctx) \
  5905. FN(skc_lookup_tcp, 99, ##ctx) \
  5906. FN(tcp_check_syncookie, 100, ##ctx) \
  5907. FN(sysctl_get_name, 101, ##ctx) \
  5908. FN(sysctl_get_current_value, 102, ##ctx) \
  5909. FN(sysctl_get_new_value, 103, ##ctx) \
  5910. FN(sysctl_set_new_value, 104, ##ctx) \
  5911. FN(strtol, 105, ##ctx) \
  5912. FN(strtoul, 106, ##ctx) \
  5913. FN(sk_storage_get, 107, ##ctx) \
  5914. FN(sk_storage_delete, 108, ##ctx) \
  5915. FN(send_signal, 109, ##ctx) \
  5916. FN(tcp_gen_syncookie, 110, ##ctx) \
  5917. FN(skb_output, 111, ##ctx) \
  5918. FN(probe_read_user, 112, ##ctx) \
  5919. FN(probe_read_kernel, 113, ##ctx) \
  5920. FN(probe_read_user_str, 114, ##ctx) \
  5921. FN(probe_read_kernel_str, 115, ##ctx) \
  5922. FN(tcp_send_ack, 116, ##ctx) \
  5923. FN(send_signal_thread, 117, ##ctx) \
  5924. FN(jiffies64, 118, ##ctx) \
  5925. FN(read_branch_records, 119, ##ctx) \
  5926. FN(get_ns_current_pid_tgid, 120, ##ctx) \
  5927. FN(xdp_output, 121, ##ctx) \
  5928. FN(get_netns_cookie, 122, ##ctx) \
  5929. FN(get_current_ancestor_cgroup_id, 123, ##ctx) \
  5930. FN(sk_assign, 124, ##ctx) \
  5931. FN(ktime_get_boot_ns, 125, ##ctx) \
  5932. FN(seq_printf, 126, ##ctx) \
  5933. FN(seq_write, 127, ##ctx) \
  5934. FN(sk_cgroup_id, 128, ##ctx) \
  5935. FN(sk_ancestor_cgroup_id, 129, ##ctx) \
  5936. FN(ringbuf_output, 130, ##ctx) \
  5937. FN(ringbuf_reserve, 131, ##ctx) \
  5938. FN(ringbuf_submit, 132, ##ctx) \
  5939. FN(ringbuf_discard, 133, ##ctx) \
  5940. FN(ringbuf_query, 134, ##ctx) \
  5941. FN(csum_level, 135, ##ctx) \
  5942. FN(skc_to_tcp6_sock, 136, ##ctx) \
  5943. FN(skc_to_tcp_sock, 137, ##ctx) \
  5944. FN(skc_to_tcp_timewait_sock, 138, ##ctx) \
  5945. FN(skc_to_tcp_request_sock, 139, ##ctx) \
  5946. FN(skc_to_udp6_sock, 140, ##ctx) \
  5947. FN(get_task_stack, 141, ##ctx) \
  5948. FN(load_hdr_opt, 142, ##ctx) \
  5949. FN(store_hdr_opt, 143, ##ctx) \
  5950. FN(reserve_hdr_opt, 144, ##ctx) \
  5951. FN(inode_storage_get, 145, ##ctx) \
  5952. FN(inode_storage_delete, 146, ##ctx) \
  5953. FN(d_path, 147, ##ctx) \
  5954. FN(copy_from_user, 148, ##ctx) \
  5955. FN(snprintf_btf, 149, ##ctx) \
  5956. FN(seq_printf_btf, 150, ##ctx) \
  5957. FN(skb_cgroup_classid, 151, ##ctx) \
  5958. FN(redirect_neigh, 152, ##ctx) \
  5959. FN(per_cpu_ptr, 153, ##ctx) \
  5960. FN(this_cpu_ptr, 154, ##ctx) \
  5961. FN(redirect_peer, 155, ##ctx) \
  5962. FN(task_storage_get, 156, ##ctx) \
  5963. FN(task_storage_delete, 157, ##ctx) \
  5964. FN(get_current_task_btf, 158, ##ctx) \
  5965. FN(bprm_opts_set, 159, ##ctx) \
  5966. FN(ktime_get_coarse_ns, 160, ##ctx) \
  5967. FN(ima_inode_hash, 161, ##ctx) \
  5968. FN(sock_from_file, 162, ##ctx) \
  5969. FN(check_mtu, 163, ##ctx) \
  5970. FN(for_each_map_elem, 164, ##ctx) \
  5971. FN(snprintf, 165, ##ctx) \
  5972. FN(sys_bpf, 166, ##ctx) \
  5973. FN(btf_find_by_name_kind, 167, ##ctx) \
  5974. FN(sys_close, 168, ##ctx) \
  5975. FN(timer_init, 169, ##ctx) \
  5976. FN(timer_set_callback, 170, ##ctx) \
  5977. FN(timer_start, 171, ##ctx) \
  5978. FN(timer_cancel, 172, ##ctx) \
  5979. FN(get_func_ip, 173, ##ctx) \
  5980. FN(get_attach_cookie, 174, ##ctx) \
  5981. FN(task_pt_regs, 175, ##ctx) \
  5982. FN(get_branch_snapshot, 176, ##ctx) \
  5983. FN(trace_vprintk, 177, ##ctx) \
  5984. FN(skc_to_unix_sock, 178, ##ctx) \
  5985. FN(kallsyms_lookup_name, 179, ##ctx) \
  5986. FN(find_vma, 180, ##ctx) \
  5987. FN(loop, 181, ##ctx) \
  5988. FN(strncmp, 182, ##ctx) \
  5989. FN(get_func_arg, 183, ##ctx) \
  5990. FN(get_func_ret, 184, ##ctx) \
  5991. FN(get_func_arg_cnt, 185, ##ctx) \
  5992. FN(get_retval, 186, ##ctx) \
  5993. FN(set_retval, 187, ##ctx) \
  5994. FN(xdp_get_buff_len, 188, ##ctx) \
  5995. FN(xdp_load_bytes, 189, ##ctx) \
  5996. FN(xdp_store_bytes, 190, ##ctx) \
  5997. FN(copy_from_user_task, 191, ##ctx) \
  5998. FN(skb_set_tstamp, 192, ##ctx) \
  5999. FN(ima_file_hash, 193, ##ctx) \
  6000. FN(kptr_xchg, 194, ##ctx) \
  6001. FN(map_lookup_percpu_elem, 195, ##ctx) \
  6002. FN(skc_to_mptcp_sock, 196, ##ctx) \
  6003. FN(dynptr_from_mem, 197, ##ctx) \
  6004. FN(ringbuf_reserve_dynptr, 198, ##ctx) \
  6005. FN(ringbuf_submit_dynptr, 199, ##ctx) \
  6006. FN(ringbuf_discard_dynptr, 200, ##ctx) \
  6007. FN(dynptr_read, 201, ##ctx) \
  6008. FN(dynptr_write, 202, ##ctx) \
  6009. FN(dynptr_data, 203, ##ctx) \
  6010. FN(tcp_raw_gen_syncookie_ipv4, 204, ##ctx) \
  6011. FN(tcp_raw_gen_syncookie_ipv6, 205, ##ctx) \
  6012. FN(tcp_raw_check_syncookie_ipv4, 206, ##ctx) \
  6013. FN(tcp_raw_check_syncookie_ipv6, 207, ##ctx) \
  6014. FN(ktime_get_tai_ns, 208, ##ctx) \
  6015. FN(user_ringbuf_drain, 209, ##ctx) \
  6016. FN(cgrp_storage_get, 210, ##ctx) \
  6017. FN(cgrp_storage_delete, 211, ##ctx) \
  6018. /* This helper list is effectively frozen. If you are trying to \
  6019. * add a new helper, you should add a kfunc instead which has \
  6020. * less stability guarantees. See Documentation/bpf/kfuncs.rst \
  6021. */
  6022. /* backwards-compatibility macros for users of __BPF_FUNC_MAPPER that don't
  6023. * know or care about integer value that is now passed as second argument
  6024. */
  6025. #define __BPF_FUNC_MAPPER_APPLY(name, value, FN) FN(name),
  6026. #define __BPF_FUNC_MAPPER(FN) ___BPF_FUNC_MAPPER(__BPF_FUNC_MAPPER_APPLY, FN)
  6027. /* integer value in 'imm' field of BPF_CALL instruction selects which helper
  6028. * function eBPF program intends to call
  6029. */
  6030. #define __BPF_ENUM_FN(x, y) BPF_FUNC_ ## x = y,
  6031. enum bpf_func_id {
  6032. ___BPF_FUNC_MAPPER(__BPF_ENUM_FN)
  6033. __BPF_FUNC_MAX_ID,
  6034. };
  6035. #undef __BPF_ENUM_FN
  6036. /* All flags used by eBPF helper functions, placed here. */
  6037. /* BPF_FUNC_skb_store_bytes flags. */
  6038. enum {
  6039. BPF_F_RECOMPUTE_CSUM = (1ULL << 0),
  6040. BPF_F_INVALIDATE_HASH = (1ULL << 1),
  6041. };
  6042. /* BPF_FUNC_l3_csum_replace and BPF_FUNC_l4_csum_replace flags.
  6043. * First 4 bits are for passing the header field size.
  6044. */
  6045. enum {
  6046. BPF_F_HDR_FIELD_MASK = 0xfULL,
  6047. };
  6048. /* BPF_FUNC_l4_csum_replace flags. */
  6049. enum {
  6050. BPF_F_PSEUDO_HDR = (1ULL << 4),
  6051. BPF_F_MARK_MANGLED_0 = (1ULL << 5),
  6052. BPF_F_MARK_ENFORCE = (1ULL << 6),
  6053. BPF_F_IPV6 = (1ULL << 7),
  6054. };
  6055. /* BPF_FUNC_skb_set_tunnel_key and BPF_FUNC_skb_get_tunnel_key flags. */
  6056. enum {
  6057. BPF_F_TUNINFO_IPV6 = (1ULL << 0),
  6058. };
  6059. /* flags for both BPF_FUNC_get_stackid and BPF_FUNC_get_stack. */
  6060. enum {
  6061. BPF_F_SKIP_FIELD_MASK = 0xffULL,
  6062. BPF_F_USER_STACK = (1ULL << 8),
  6063. /* flags used by BPF_FUNC_get_stackid only. */
  6064. BPF_F_FAST_STACK_CMP = (1ULL << 9),
  6065. BPF_F_REUSE_STACKID = (1ULL << 10),
  6066. /* flags used by BPF_FUNC_get_stack only. */
  6067. BPF_F_USER_BUILD_ID = (1ULL << 11),
  6068. };
  6069. /* BPF_FUNC_skb_set_tunnel_key flags. */
  6070. enum {
  6071. BPF_F_ZERO_CSUM_TX = (1ULL << 1),
  6072. BPF_F_DONT_FRAGMENT = (1ULL << 2),
  6073. BPF_F_SEQ_NUMBER = (1ULL << 3),
  6074. BPF_F_NO_TUNNEL_KEY = (1ULL << 4),
  6075. };
  6076. /* BPF_FUNC_skb_get_tunnel_key flags. */
  6077. enum {
  6078. BPF_F_TUNINFO_FLAGS = (1ULL << 4),
  6079. };
  6080. /* BPF_FUNC_perf_event_output, BPF_FUNC_perf_event_read and
  6081. * BPF_FUNC_perf_event_read_value flags.
  6082. */
  6083. enum {
  6084. BPF_F_INDEX_MASK = 0xffffffffULL,
  6085. BPF_F_CURRENT_CPU = BPF_F_INDEX_MASK,
  6086. /* BPF_FUNC_perf_event_output for sk_buff input context. */
  6087. BPF_F_CTXLEN_MASK = (0xfffffULL << 32),
  6088. };
  6089. /* Current network namespace */
  6090. enum {
  6091. BPF_F_CURRENT_NETNS = (-1L),
  6092. };
  6093. /* BPF_FUNC_csum_level level values. */
  6094. enum {
  6095. BPF_CSUM_LEVEL_QUERY,
  6096. BPF_CSUM_LEVEL_INC,
  6097. BPF_CSUM_LEVEL_DEC,
  6098. BPF_CSUM_LEVEL_RESET,
  6099. };
  6100. /* BPF_FUNC_skb_adjust_room flags. */
  6101. enum {
  6102. BPF_F_ADJ_ROOM_FIXED_GSO = (1ULL << 0),
  6103. BPF_F_ADJ_ROOM_ENCAP_L3_IPV4 = (1ULL << 1),
  6104. BPF_F_ADJ_ROOM_ENCAP_L3_IPV6 = (1ULL << 2),
  6105. BPF_F_ADJ_ROOM_ENCAP_L4_GRE = (1ULL << 3),
  6106. BPF_F_ADJ_ROOM_ENCAP_L4_UDP = (1ULL << 4),
  6107. BPF_F_ADJ_ROOM_NO_CSUM_RESET = (1ULL << 5),
  6108. BPF_F_ADJ_ROOM_ENCAP_L2_ETH = (1ULL << 6),
  6109. BPF_F_ADJ_ROOM_DECAP_L3_IPV4 = (1ULL << 7),
  6110. BPF_F_ADJ_ROOM_DECAP_L3_IPV6 = (1ULL << 8),
  6111. };
  6112. enum {
  6113. BPF_ADJ_ROOM_ENCAP_L2_MASK = 0xff,
  6114. BPF_ADJ_ROOM_ENCAP_L2_SHIFT = 56,
  6115. };
  6116. #define BPF_F_ADJ_ROOM_ENCAP_L2(len) (((__u64)len & \
  6117. BPF_ADJ_ROOM_ENCAP_L2_MASK) \
  6118. << BPF_ADJ_ROOM_ENCAP_L2_SHIFT)
  6119. /* BPF_FUNC_sysctl_get_name flags. */
  6120. enum {
  6121. BPF_F_SYSCTL_BASE_NAME = (1ULL << 0),
  6122. };
  6123. /* BPF_FUNC_<kernel_obj>_storage_get flags */
  6124. enum {
  6125. BPF_LOCAL_STORAGE_GET_F_CREATE = (1ULL << 0),
  6126. /* BPF_SK_STORAGE_GET_F_CREATE is only kept for backward compatibility
  6127. * and BPF_LOCAL_STORAGE_GET_F_CREATE must be used instead.
  6128. */
  6129. BPF_SK_STORAGE_GET_F_CREATE = BPF_LOCAL_STORAGE_GET_F_CREATE,
  6130. };
  6131. /* BPF_FUNC_read_branch_records flags. */
  6132. enum {
  6133. BPF_F_GET_BRANCH_RECORDS_SIZE = (1ULL << 0),
  6134. };
  6135. /* BPF_FUNC_bpf_ringbuf_commit, BPF_FUNC_bpf_ringbuf_discard, and
  6136. * BPF_FUNC_bpf_ringbuf_output flags.
  6137. */
  6138. enum {
  6139. BPF_RB_NO_WAKEUP = (1ULL << 0),
  6140. BPF_RB_FORCE_WAKEUP = (1ULL << 1),
  6141. };
  6142. /* BPF_FUNC_bpf_ringbuf_query flags */
  6143. enum {
  6144. BPF_RB_AVAIL_DATA = 0,
  6145. BPF_RB_RING_SIZE = 1,
  6146. BPF_RB_CONS_POS = 2,
  6147. BPF_RB_PROD_POS = 3,
  6148. BPF_RB_OVERWRITE_POS = 4,
  6149. };
  6150. /* BPF ring buffer constants */
  6151. enum {
  6152. BPF_RINGBUF_BUSY_BIT = (1U << 31),
  6153. BPF_RINGBUF_DISCARD_BIT = (1U << 30),
  6154. BPF_RINGBUF_HDR_SZ = 8,
  6155. };
  6156. /* BPF_FUNC_sk_assign flags in bpf_sk_lookup context. */
  6157. enum {
  6158. BPF_SK_LOOKUP_F_REPLACE = (1ULL << 0),
  6159. BPF_SK_LOOKUP_F_NO_REUSEPORT = (1ULL << 1),
  6160. };
  6161. /* Mode for BPF_FUNC_skb_adjust_room helper. */
  6162. enum bpf_adj_room_mode {
  6163. BPF_ADJ_ROOM_NET,
  6164. BPF_ADJ_ROOM_MAC,
  6165. };
  6166. /* Mode for BPF_FUNC_skb_load_bytes_relative helper. */
  6167. enum bpf_hdr_start_off {
  6168. BPF_HDR_START_MAC,
  6169. BPF_HDR_START_NET,
  6170. };
  6171. /* Encapsulation type for BPF_FUNC_lwt_push_encap helper. */
  6172. enum bpf_lwt_encap_mode {
  6173. BPF_LWT_ENCAP_SEG6,
  6174. BPF_LWT_ENCAP_SEG6_INLINE,
  6175. BPF_LWT_ENCAP_IP,
  6176. };
  6177. /* Flags for bpf_bprm_opts_set helper */
  6178. enum {
  6179. BPF_F_BPRM_SECUREEXEC = (1ULL << 0),
  6180. };
  6181. /* Flags for bpf_redirect and bpf_redirect_map helpers */
  6182. enum {
  6183. BPF_F_INGRESS = (1ULL << 0), /* used for skb path */
  6184. BPF_F_BROADCAST = (1ULL << 3), /* used for XDP path */
  6185. BPF_F_EXCLUDE_INGRESS = (1ULL << 4), /* used for XDP path */
  6186. #define BPF_F_REDIRECT_FLAGS (BPF_F_INGRESS | BPF_F_BROADCAST | BPF_F_EXCLUDE_INGRESS)
  6187. };
  6188. #define __bpf_md_ptr(type, name) \
  6189. union { \
  6190. type name; \
  6191. __u64 :64; \
  6192. } __attribute__((aligned(8)))
  6193. /* The enum used in skb->tstamp_type. It specifies the clock type
  6194. * of the time stored in the skb->tstamp.
  6195. */
  6196. enum {
  6197. BPF_SKB_TSTAMP_UNSPEC = 0, /* DEPRECATED */
  6198. BPF_SKB_TSTAMP_DELIVERY_MONO = 1, /* DEPRECATED */
  6199. BPF_SKB_CLOCK_REALTIME = 0,
  6200. BPF_SKB_CLOCK_MONOTONIC = 1,
  6201. BPF_SKB_CLOCK_TAI = 2,
  6202. /* For any future BPF_SKB_CLOCK_* that the bpf prog cannot handle,
  6203. * the bpf prog can try to deduce it by ingress/egress/skb->sk->sk_clockid.
  6204. */
  6205. };
  6206. /* user accessible mirror of in-kernel sk_buff.
  6207. * new fields can only be added to the end of this structure
  6208. */
  6209. struct __sk_buff {
  6210. __u32 len;
  6211. __u32 pkt_type;
  6212. __u32 mark;
  6213. __u32 queue_mapping;
  6214. __u32 protocol;
  6215. __u32 vlan_present;
  6216. __u32 vlan_tci;
  6217. __u32 vlan_proto;
  6218. __u32 priority;
  6219. __u32 ingress_ifindex;
  6220. __u32 ifindex;
  6221. __u32 tc_index;
  6222. __u32 cb[5];
  6223. __u32 hash;
  6224. __u32 tc_classid;
  6225. __u32 data;
  6226. __u32 data_end;
  6227. __u32 napi_id;
  6228. /* Accessed by BPF_PROG_TYPE_sk_skb types from here to ... */
  6229. __u32 family;
  6230. __u32 remote_ip4; /* Stored in network byte order */
  6231. __u32 local_ip4; /* Stored in network byte order */
  6232. __u32 remote_ip6[4]; /* Stored in network byte order */
  6233. __u32 local_ip6[4]; /* Stored in network byte order */
  6234. __u32 remote_port; /* Stored in network byte order */
  6235. __u32 local_port; /* stored in host byte order */
  6236. /* ... here. */
  6237. __u32 data_meta;
  6238. __bpf_md_ptr(struct bpf_flow_keys *, flow_keys);
  6239. __u64 tstamp;
  6240. __u32 wire_len;
  6241. __u32 gso_segs;
  6242. __bpf_md_ptr(struct bpf_sock *, sk);
  6243. __u32 gso_size;
  6244. __u8 tstamp_type;
  6245. __u32 :24; /* Padding, future use. */
  6246. __u64 hwtstamp;
  6247. };
  6248. struct bpf_tunnel_key {
  6249. __u32 tunnel_id;
  6250. union {
  6251. __u32 remote_ipv4;
  6252. __u32 remote_ipv6[4];
  6253. };
  6254. __u8 tunnel_tos;
  6255. __u8 tunnel_ttl;
  6256. union {
  6257. __u16 tunnel_ext; /* compat */
  6258. __be16 tunnel_flags;
  6259. };
  6260. __u32 tunnel_label;
  6261. union {
  6262. __u32 local_ipv4;
  6263. __u32 local_ipv6[4];
  6264. };
  6265. };
  6266. /* user accessible mirror of in-kernel xfrm_state.
  6267. * new fields can only be added to the end of this structure
  6268. */
  6269. struct bpf_xfrm_state {
  6270. __u32 reqid;
  6271. __u32 spi; /* Stored in network byte order */
  6272. __u16 family;
  6273. __u16 ext; /* Padding, future use. */
  6274. union {
  6275. __u32 remote_ipv4; /* Stored in network byte order */
  6276. __u32 remote_ipv6[4]; /* Stored in network byte order */
  6277. };
  6278. };
  6279. /* Generic BPF return codes which all BPF program types may support.
  6280. * The values are binary compatible with their TC_ACT_* counter-part to
  6281. * provide backwards compatibility with existing SCHED_CLS and SCHED_ACT
  6282. * programs.
  6283. *
  6284. * XDP is handled seprately, see XDP_*.
  6285. */
  6286. enum bpf_ret_code {
  6287. BPF_OK = 0,
  6288. /* 1 reserved */
  6289. BPF_DROP = 2,
  6290. /* 3-6 reserved */
  6291. BPF_REDIRECT = 7,
  6292. /* >127 are reserved for prog type specific return codes.
  6293. *
  6294. * BPF_LWT_REROUTE: used by BPF_PROG_TYPE_LWT_IN and
  6295. * BPF_PROG_TYPE_LWT_XMIT to indicate that skb had been
  6296. * changed and should be routed based on its new L3 header.
  6297. * (This is an L3 redirect, as opposed to L2 redirect
  6298. * represented by BPF_REDIRECT above).
  6299. */
  6300. BPF_LWT_REROUTE = 128,
  6301. /* BPF_FLOW_DISSECTOR_CONTINUE: used by BPF_PROG_TYPE_FLOW_DISSECTOR
  6302. * to indicate that no custom dissection was performed, and
  6303. * fallback to standard dissector is requested.
  6304. */
  6305. BPF_FLOW_DISSECTOR_CONTINUE = 129,
  6306. };
  6307. struct bpf_sock {
  6308. __u32 bound_dev_if;
  6309. __u32 family;
  6310. __u32 type;
  6311. __u32 protocol;
  6312. __u32 mark;
  6313. __u32 priority;
  6314. /* IP address also allows 1 and 2 bytes access */
  6315. __u32 src_ip4;
  6316. __u32 src_ip6[4];
  6317. __u32 src_port; /* host byte order */
  6318. __be16 dst_port; /* network byte order */
  6319. __u16 :16; /* zero padding */
  6320. __u32 dst_ip4;
  6321. __u32 dst_ip6[4];
  6322. __u32 state;
  6323. __s32 rx_queue_mapping;
  6324. };
  6325. struct bpf_tcp_sock {
  6326. __u32 snd_cwnd; /* Sending congestion window */
  6327. __u32 srtt_us; /* smoothed round trip time << 3 in usecs */
  6328. __u32 rtt_min;
  6329. __u32 snd_ssthresh; /* Slow start size threshold */
  6330. __u32 rcv_nxt; /* What we want to receive next */
  6331. __u32 snd_nxt; /* Next sequence we send */
  6332. __u32 snd_una; /* First byte we want an ack for */
  6333. __u32 mss_cache; /* Cached effective mss, not including SACKS */
  6334. __u32 ecn_flags; /* ECN status bits. */
  6335. __u32 rate_delivered; /* saved rate sample: packets delivered */
  6336. __u32 rate_interval_us; /* saved rate sample: time elapsed */
  6337. __u32 packets_out; /* Packets which are "in flight" */
  6338. __u32 retrans_out; /* Retransmitted packets out */
  6339. __u32 total_retrans; /* Total retransmits for entire connection */
  6340. __u32 segs_in; /* RFC4898 tcpEStatsPerfSegsIn
  6341. * total number of segments in.
  6342. */
  6343. __u32 data_segs_in; /* RFC4898 tcpEStatsPerfDataSegsIn
  6344. * total number of data segments in.
  6345. */
  6346. __u32 segs_out; /* RFC4898 tcpEStatsPerfSegsOut
  6347. * The total number of segments sent.
  6348. */
  6349. __u32 data_segs_out; /* RFC4898 tcpEStatsPerfDataSegsOut
  6350. * total number of data segments sent.
  6351. */
  6352. __u32 lost_out; /* Lost packets */
  6353. __u32 sacked_out; /* SACK'd packets */
  6354. __u64 bytes_received; /* RFC4898 tcpEStatsAppHCThruOctetsReceived
  6355. * sum(delta(rcv_nxt)), or how many bytes
  6356. * were acked.
  6357. */
  6358. __u64 bytes_acked; /* RFC4898 tcpEStatsAppHCThruOctetsAcked
  6359. * sum(delta(snd_una)), or how many bytes
  6360. * were acked.
  6361. */
  6362. __u32 dsack_dups; /* RFC4898 tcpEStatsStackDSACKDups
  6363. * total number of DSACK blocks received
  6364. */
  6365. __u32 delivered; /* Total data packets delivered incl. rexmits */
  6366. __u32 delivered_ce; /* Like the above but only ECE marked packets */
  6367. __u32 icsk_retransmits; /* Number of unrecovered [RTO] timeouts */
  6368. };
  6369. struct bpf_sock_tuple {
  6370. union {
  6371. struct {
  6372. __be32 saddr;
  6373. __be32 daddr;
  6374. __be16 sport;
  6375. __be16 dport;
  6376. } ipv4;
  6377. struct {
  6378. __be32 saddr[4];
  6379. __be32 daddr[4];
  6380. __be16 sport;
  6381. __be16 dport;
  6382. } ipv6;
  6383. };
  6384. };
  6385. /* (Simplified) user return codes for tcx prog type.
  6386. * A valid tcx program must return one of these defined values. All other
  6387. * return codes are reserved for future use. Must remain compatible with
  6388. * their TC_ACT_* counter-parts. For compatibility in behavior, unknown
  6389. * return codes are mapped to TCX_NEXT.
  6390. */
  6391. enum tcx_action_base {
  6392. TCX_NEXT = -1,
  6393. TCX_PASS = 0,
  6394. TCX_DROP = 2,
  6395. TCX_REDIRECT = 7,
  6396. };
  6397. struct bpf_xdp_sock {
  6398. __u32 queue_id;
  6399. };
  6400. #define XDP_PACKET_HEADROOM 256
  6401. /* User return codes for XDP prog type.
  6402. * A valid XDP program must return one of these defined values. All other
  6403. * return codes are reserved for future use. Unknown return codes will
  6404. * result in packet drops and a warning via bpf_warn_invalid_xdp_action().
  6405. */
  6406. enum xdp_action {
  6407. XDP_ABORTED = 0,
  6408. XDP_DROP,
  6409. XDP_PASS,
  6410. XDP_TX,
  6411. XDP_REDIRECT,
  6412. };
  6413. /* user accessible metadata for XDP packet hook
  6414. * new fields must be added to the end of this structure
  6415. */
  6416. struct xdp_md {
  6417. __u32 data;
  6418. __u32 data_end;
  6419. __u32 data_meta;
  6420. /* Below access go through struct xdp_rxq_info */
  6421. __u32 ingress_ifindex; /* rxq->dev->ifindex */
  6422. __u32 rx_queue_index; /* rxq->queue_index */
  6423. __u32 egress_ifindex; /* txq->dev->ifindex */
  6424. };
  6425. /* DEVMAP map-value layout
  6426. *
  6427. * The struct data-layout of map-value is a configuration interface.
  6428. * New members can only be added to the end of this structure.
  6429. */
  6430. struct bpf_devmap_val {
  6431. __u32 ifindex; /* device index */
  6432. union {
  6433. int fd; /* prog fd on map write */
  6434. __u32 id; /* prog id on map read */
  6435. } bpf_prog;
  6436. };
  6437. /* CPUMAP map-value layout
  6438. *
  6439. * The struct data-layout of map-value is a configuration interface.
  6440. * New members can only be added to the end of this structure.
  6441. */
  6442. struct bpf_cpumap_val {
  6443. __u32 qsize; /* queue size to remote target CPU */
  6444. union {
  6445. int fd; /* prog fd on map write */
  6446. __u32 id; /* prog id on map read */
  6447. } bpf_prog;
  6448. };
  6449. enum sk_action {
  6450. SK_DROP = 0,
  6451. SK_PASS,
  6452. };
  6453. /* user accessible metadata for SK_MSG packet hook, new fields must
  6454. * be added to the end of this structure
  6455. */
  6456. struct sk_msg_md {
  6457. __bpf_md_ptr(void *, data);
  6458. __bpf_md_ptr(void *, data_end);
  6459. __u32 family;
  6460. __u32 remote_ip4; /* Stored in network byte order */
  6461. __u32 local_ip4; /* Stored in network byte order */
  6462. __u32 remote_ip6[4]; /* Stored in network byte order */
  6463. __u32 local_ip6[4]; /* Stored in network byte order */
  6464. __u32 remote_port; /* Stored in network byte order */
  6465. __u32 local_port; /* stored in host byte order */
  6466. __u32 size; /* Total size of sk_msg */
  6467. __bpf_md_ptr(struct bpf_sock *, sk); /* current socket */
  6468. };
  6469. struct sk_reuseport_md {
  6470. /*
  6471. * Start of directly accessible data. It begins from
  6472. * the tcp/udp header.
  6473. */
  6474. __bpf_md_ptr(void *, data);
  6475. /* End of directly accessible data */
  6476. __bpf_md_ptr(void *, data_end);
  6477. /*
  6478. * Total length of packet (starting from the tcp/udp header).
  6479. * Note that the directly accessible bytes (data_end - data)
  6480. * could be less than this "len". Those bytes could be
  6481. * indirectly read by a helper "bpf_skb_load_bytes()".
  6482. */
  6483. __u32 len;
  6484. /*
  6485. * Eth protocol in the mac header (network byte order). e.g.
  6486. * ETH_P_IP(0x0800) and ETH_P_IPV6(0x86DD)
  6487. */
  6488. __u32 eth_protocol;
  6489. __u32 ip_protocol; /* IP protocol. e.g. IPPROTO_TCP, IPPROTO_UDP */
  6490. __u32 bind_inany; /* Is sock bound to an INANY address? */
  6491. __u32 hash; /* A hash of the packet 4 tuples */
  6492. /* When reuse->migrating_sk is NULL, it is selecting a sk for the
  6493. * new incoming connection request (e.g. selecting a listen sk for
  6494. * the received SYN in the TCP case). reuse->sk is one of the sk
  6495. * in the reuseport group. The bpf prog can use reuse->sk to learn
  6496. * the local listening ip/port without looking into the skb.
  6497. *
  6498. * When reuse->migrating_sk is not NULL, reuse->sk is closed and
  6499. * reuse->migrating_sk is the socket that needs to be migrated
  6500. * to another listening socket. migrating_sk could be a fullsock
  6501. * sk that is fully established or a reqsk that is in-the-middle
  6502. * of 3-way handshake.
  6503. */
  6504. __bpf_md_ptr(struct bpf_sock *, sk);
  6505. __bpf_md_ptr(struct bpf_sock *, migrating_sk);
  6506. };
  6507. #define BPF_TAG_SIZE 8
  6508. struct bpf_prog_info {
  6509. __u32 type;
  6510. __u32 id;
  6511. __u8 tag[BPF_TAG_SIZE];
  6512. __u32 jited_prog_len;
  6513. __u32 xlated_prog_len;
  6514. __aligned_u64 jited_prog_insns;
  6515. __aligned_u64 xlated_prog_insns;
  6516. __u64 load_time; /* ns since boottime */
  6517. __u32 created_by_uid;
  6518. __u32 nr_map_ids;
  6519. __aligned_u64 map_ids;
  6520. char name[BPF_OBJ_NAME_LEN];
  6521. __u32 ifindex;
  6522. __u32 gpl_compatible:1;
  6523. __u32 :31; /* alignment pad */
  6524. __u64 netns_dev;
  6525. __u64 netns_ino;
  6526. __u32 nr_jited_ksyms;
  6527. __u32 nr_jited_func_lens;
  6528. __aligned_u64 jited_ksyms;
  6529. __aligned_u64 jited_func_lens;
  6530. __u32 btf_id;
  6531. __u32 func_info_rec_size;
  6532. __aligned_u64 func_info;
  6533. __u32 nr_func_info;
  6534. __u32 nr_line_info;
  6535. __aligned_u64 line_info;
  6536. __aligned_u64 jited_line_info;
  6537. __u32 nr_jited_line_info;
  6538. __u32 line_info_rec_size;
  6539. __u32 jited_line_info_rec_size;
  6540. __u32 nr_prog_tags;
  6541. __aligned_u64 prog_tags;
  6542. __u64 run_time_ns;
  6543. __u64 run_cnt;
  6544. __u64 recursion_misses;
  6545. __u32 verified_insns;
  6546. __u32 attach_btf_obj_id;
  6547. __u32 attach_btf_id;
  6548. } __attribute__((aligned(8)));
  6549. struct bpf_map_info {
  6550. __u32 type;
  6551. __u32 id;
  6552. __u32 key_size;
  6553. __u32 value_size;
  6554. __u32 max_entries;
  6555. __u32 map_flags;
  6556. char name[BPF_OBJ_NAME_LEN];
  6557. __u32 ifindex;
  6558. __u32 btf_vmlinux_value_type_id;
  6559. __u64 netns_dev;
  6560. __u64 netns_ino;
  6561. __u32 btf_id;
  6562. __u32 btf_key_type_id;
  6563. __u32 btf_value_type_id;
  6564. __u32 btf_vmlinux_id;
  6565. __u64 map_extra;
  6566. __aligned_u64 hash;
  6567. __u32 hash_size;
  6568. } __attribute__((aligned(8)));
  6569. struct bpf_btf_info {
  6570. __aligned_u64 btf;
  6571. __u32 btf_size;
  6572. __u32 id;
  6573. __aligned_u64 name;
  6574. __u32 name_len;
  6575. __u32 kernel_btf;
  6576. } __attribute__((aligned(8)));
  6577. struct bpf_link_info {
  6578. __u32 type;
  6579. __u32 id;
  6580. __u32 prog_id;
  6581. union {
  6582. struct {
  6583. __aligned_u64 tp_name; /* in/out: tp_name buffer ptr */
  6584. __u32 tp_name_len; /* in/out: tp_name buffer len */
  6585. __u32 :32;
  6586. __u64 cookie;
  6587. } raw_tracepoint;
  6588. struct {
  6589. __u32 attach_type;
  6590. __u32 target_obj_id; /* prog_id for PROG_EXT, otherwise btf object id */
  6591. __u32 target_btf_id; /* BTF type id inside the object */
  6592. __u32 :32;
  6593. __u64 cookie;
  6594. } tracing;
  6595. struct {
  6596. __u64 cgroup_id;
  6597. __u32 attach_type;
  6598. } cgroup;
  6599. struct {
  6600. __aligned_u64 target_name; /* in/out: target_name buffer ptr */
  6601. __u32 target_name_len; /* in/out: target_name buffer len */
  6602. /* If the iter specific field is 32 bits, it can be put
  6603. * in the first or second union. Otherwise it should be
  6604. * put in the second union.
  6605. */
  6606. union {
  6607. struct {
  6608. __u32 map_id;
  6609. } map;
  6610. };
  6611. union {
  6612. struct {
  6613. __u64 cgroup_id;
  6614. __u32 order;
  6615. } cgroup;
  6616. struct {
  6617. __u32 tid;
  6618. __u32 pid;
  6619. } task;
  6620. };
  6621. } iter;
  6622. struct {
  6623. __u32 netns_ino;
  6624. __u32 attach_type;
  6625. } netns;
  6626. struct {
  6627. __u32 ifindex;
  6628. } xdp;
  6629. struct {
  6630. __u32 map_id;
  6631. } struct_ops;
  6632. struct {
  6633. __u32 pf;
  6634. __u32 hooknum;
  6635. __s32 priority;
  6636. __u32 flags;
  6637. } netfilter;
  6638. struct {
  6639. __aligned_u64 addrs;
  6640. __u32 count; /* in/out: kprobe_multi function count */
  6641. __u32 flags;
  6642. __u64 missed;
  6643. __aligned_u64 cookies;
  6644. } kprobe_multi;
  6645. struct {
  6646. __aligned_u64 path;
  6647. __aligned_u64 offsets;
  6648. __aligned_u64 ref_ctr_offsets;
  6649. __aligned_u64 cookies;
  6650. __u32 path_size; /* in/out: real path size on success, including zero byte */
  6651. __u32 count; /* in/out: uprobe_multi offsets/ref_ctr_offsets/cookies count */
  6652. __u32 flags;
  6653. __u32 pid;
  6654. } uprobe_multi;
  6655. struct {
  6656. __u32 type; /* enum bpf_perf_event_type */
  6657. __u32 :32;
  6658. union {
  6659. struct {
  6660. __aligned_u64 file_name; /* in/out */
  6661. __u32 name_len;
  6662. __u32 offset; /* offset from file_name */
  6663. __u64 cookie;
  6664. __u64 ref_ctr_offset;
  6665. } uprobe; /* BPF_PERF_EVENT_UPROBE, BPF_PERF_EVENT_URETPROBE */
  6666. struct {
  6667. __aligned_u64 func_name; /* in/out */
  6668. __u32 name_len;
  6669. __u32 offset; /* offset from func_name */
  6670. __u64 addr;
  6671. __u64 missed;
  6672. __u64 cookie;
  6673. } kprobe; /* BPF_PERF_EVENT_KPROBE, BPF_PERF_EVENT_KRETPROBE */
  6674. struct {
  6675. __aligned_u64 tp_name; /* in/out */
  6676. __u32 name_len;
  6677. __u32 :32;
  6678. __u64 cookie;
  6679. } tracepoint; /* BPF_PERF_EVENT_TRACEPOINT */
  6680. struct {
  6681. __u64 config;
  6682. __u32 type;
  6683. __u32 :32;
  6684. __u64 cookie;
  6685. } event; /* BPF_PERF_EVENT_EVENT */
  6686. };
  6687. } perf_event;
  6688. struct {
  6689. __u32 ifindex;
  6690. __u32 attach_type;
  6691. } tcx;
  6692. struct {
  6693. __u32 ifindex;
  6694. __u32 attach_type;
  6695. } netkit;
  6696. struct {
  6697. __u32 map_id;
  6698. __u32 attach_type;
  6699. } sockmap;
  6700. };
  6701. } __attribute__((aligned(8)));
  6702. struct bpf_token_info {
  6703. __u64 allowed_cmds;
  6704. __u64 allowed_maps;
  6705. __u64 allowed_progs;
  6706. __u64 allowed_attachs;
  6707. } __attribute__((aligned(8)));
  6708. /* User bpf_sock_addr struct to access socket fields and sockaddr struct passed
  6709. * by user and intended to be used by socket (e.g. to bind to, depends on
  6710. * attach type).
  6711. */
  6712. struct bpf_sock_addr {
  6713. __u32 user_family; /* Allows 4-byte read, but no write. */
  6714. __u32 user_ip4; /* Allows 1,2,4-byte read and 4-byte write.
  6715. * Stored in network byte order.
  6716. */
  6717. __u32 user_ip6[4]; /* Allows 1,2,4,8-byte read and 4,8-byte write.
  6718. * Stored in network byte order.
  6719. */
  6720. __u32 user_port; /* Allows 1,2,4-byte read and 4-byte write.
  6721. * Stored in network byte order
  6722. */
  6723. __u32 family; /* Allows 4-byte read, but no write */
  6724. __u32 type; /* Allows 4-byte read, but no write */
  6725. __u32 protocol; /* Allows 4-byte read, but no write */
  6726. __u32 msg_src_ip4; /* Allows 1,2,4-byte read and 4-byte write.
  6727. * Stored in network byte order.
  6728. */
  6729. __u32 msg_src_ip6[4]; /* Allows 1,2,4,8-byte read and 4,8-byte write.
  6730. * Stored in network byte order.
  6731. */
  6732. __bpf_md_ptr(struct bpf_sock *, sk);
  6733. };
  6734. /* User bpf_sock_ops struct to access socket values and specify request ops
  6735. * and their replies.
  6736. * Some of this fields are in network (bigendian) byte order and may need
  6737. * to be converted before use (bpf_ntohl() defined in samples/bpf/bpf_endian.h).
  6738. * New fields can only be added at the end of this structure
  6739. */
  6740. struct bpf_sock_ops {
  6741. __u32 op;
  6742. union {
  6743. __u32 args[4]; /* Optionally passed to bpf program */
  6744. __u32 reply; /* Returned by bpf program */
  6745. __u32 replylong[4]; /* Optionally returned by bpf prog */
  6746. };
  6747. __u32 family;
  6748. __u32 remote_ip4; /* Stored in network byte order */
  6749. __u32 local_ip4; /* Stored in network byte order */
  6750. __u32 remote_ip6[4]; /* Stored in network byte order */
  6751. __u32 local_ip6[4]; /* Stored in network byte order */
  6752. __u32 remote_port; /* Stored in network byte order */
  6753. __u32 local_port; /* stored in host byte order */
  6754. __u32 is_fullsock; /* Some TCP fields are only valid if
  6755. * there is a full socket. If not, the
  6756. * fields read as zero.
  6757. */
  6758. __u32 snd_cwnd;
  6759. __u32 srtt_us; /* Averaged RTT << 3 in usecs */
  6760. __u32 bpf_sock_ops_cb_flags; /* flags defined in uapi/linux/tcp.h */
  6761. __u32 state;
  6762. __u32 rtt_min;
  6763. __u32 snd_ssthresh;
  6764. __u32 rcv_nxt;
  6765. __u32 snd_nxt;
  6766. __u32 snd_una;
  6767. __u32 mss_cache;
  6768. __u32 ecn_flags;
  6769. __u32 rate_delivered;
  6770. __u32 rate_interval_us;
  6771. __u32 packets_out;
  6772. __u32 retrans_out;
  6773. __u32 total_retrans;
  6774. __u32 segs_in;
  6775. __u32 data_segs_in;
  6776. __u32 segs_out;
  6777. __u32 data_segs_out;
  6778. __u32 lost_out;
  6779. __u32 sacked_out;
  6780. __u32 sk_txhash;
  6781. __u64 bytes_received;
  6782. __u64 bytes_acked;
  6783. __bpf_md_ptr(struct bpf_sock *, sk);
  6784. /* [skb_data, skb_data_end) covers the whole TCP header.
  6785. *
  6786. * BPF_SOCK_OPS_PARSE_HDR_OPT_CB: The packet received
  6787. * BPF_SOCK_OPS_HDR_OPT_LEN_CB: Not useful because the
  6788. * header has not been written.
  6789. * BPF_SOCK_OPS_WRITE_HDR_OPT_CB: The header and options have
  6790. * been written so far.
  6791. * BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB: The SYNACK that concludes
  6792. * the 3WHS.
  6793. * BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB: The ACK that concludes
  6794. * the 3WHS.
  6795. *
  6796. * bpf_load_hdr_opt() can also be used to read a particular option.
  6797. */
  6798. __bpf_md_ptr(void *, skb_data);
  6799. __bpf_md_ptr(void *, skb_data_end);
  6800. __u32 skb_len; /* The total length of a packet.
  6801. * It includes the header, options,
  6802. * and payload.
  6803. */
  6804. __u32 skb_tcp_flags; /* tcp_flags of the header. It provides
  6805. * an easy way to check for tcp_flags
  6806. * without parsing skb_data.
  6807. *
  6808. * In particular, the skb_tcp_flags
  6809. * will still be available in
  6810. * BPF_SOCK_OPS_HDR_OPT_LEN even though
  6811. * the outgoing header has not
  6812. * been written yet.
  6813. */
  6814. __u64 skb_hwtstamp;
  6815. };
  6816. /* Definitions for bpf_sock_ops_cb_flags */
  6817. enum {
  6818. BPF_SOCK_OPS_RTO_CB_FLAG = (1<<0),
  6819. BPF_SOCK_OPS_RETRANS_CB_FLAG = (1<<1),
  6820. BPF_SOCK_OPS_STATE_CB_FLAG = (1<<2),
  6821. BPF_SOCK_OPS_RTT_CB_FLAG = (1<<3),
  6822. /* Call bpf for all received TCP headers. The bpf prog will be
  6823. * called under sock_ops->op == BPF_SOCK_OPS_PARSE_HDR_OPT_CB
  6824. *
  6825. * Please refer to the comment in BPF_SOCK_OPS_PARSE_HDR_OPT_CB
  6826. * for the header option related helpers that will be useful
  6827. * to the bpf programs.
  6828. *
  6829. * It could be used at the client/active side (i.e. connect() side)
  6830. * when the server told it that the server was in syncookie
  6831. * mode and required the active side to resend the bpf-written
  6832. * options. The active side can keep writing the bpf-options until
  6833. * it received a valid packet from the server side to confirm
  6834. * the earlier packet (and options) has been received. The later
  6835. * example patch is using it like this at the active side when the
  6836. * server is in syncookie mode.
  6837. *
  6838. * The bpf prog will usually turn this off in the common cases.
  6839. */
  6840. BPF_SOCK_OPS_PARSE_ALL_HDR_OPT_CB_FLAG = (1<<4),
  6841. /* Call bpf when kernel has received a header option that
  6842. * the kernel cannot handle. The bpf prog will be called under
  6843. * sock_ops->op == BPF_SOCK_OPS_PARSE_HDR_OPT_CB.
  6844. *
  6845. * Please refer to the comment in BPF_SOCK_OPS_PARSE_HDR_OPT_CB
  6846. * for the header option related helpers that will be useful
  6847. * to the bpf programs.
  6848. */
  6849. BPF_SOCK_OPS_PARSE_UNKNOWN_HDR_OPT_CB_FLAG = (1<<5),
  6850. /* Call bpf when the kernel is writing header options for the
  6851. * outgoing packet. The bpf prog will first be called
  6852. * to reserve space in a skb under
  6853. * sock_ops->op == BPF_SOCK_OPS_HDR_OPT_LEN_CB. Then
  6854. * the bpf prog will be called to write the header option(s)
  6855. * under sock_ops->op == BPF_SOCK_OPS_WRITE_HDR_OPT_CB.
  6856. *
  6857. * Please refer to the comment in BPF_SOCK_OPS_HDR_OPT_LEN_CB
  6858. * and BPF_SOCK_OPS_WRITE_HDR_OPT_CB for the header option
  6859. * related helpers that will be useful to the bpf programs.
  6860. *
  6861. * The kernel gets its chance to reserve space and write
  6862. * options first before the BPF program does.
  6863. */
  6864. BPF_SOCK_OPS_WRITE_HDR_OPT_CB_FLAG = (1<<6),
  6865. /* Mask of all currently supported cb flags */
  6866. BPF_SOCK_OPS_ALL_CB_FLAGS = 0x7F,
  6867. };
  6868. enum {
  6869. SK_BPF_CB_TX_TIMESTAMPING = 1<<0,
  6870. SK_BPF_CB_MASK = (SK_BPF_CB_TX_TIMESTAMPING - 1) |
  6871. SK_BPF_CB_TX_TIMESTAMPING
  6872. };
  6873. /* List of known BPF sock_ops operators.
  6874. * New entries can only be added at the end
  6875. */
  6876. enum {
  6877. BPF_SOCK_OPS_VOID,
  6878. BPF_SOCK_OPS_TIMEOUT_INIT, /* Should return SYN-RTO value to use or
  6879. * -1 if default value should be used
  6880. */
  6881. BPF_SOCK_OPS_RWND_INIT, /* Should return initial advertized
  6882. * window (in packets) or -1 if default
  6883. * value should be used
  6884. */
  6885. BPF_SOCK_OPS_TCP_CONNECT_CB, /* Calls BPF program right before an
  6886. * active connection is initialized
  6887. */
  6888. BPF_SOCK_OPS_ACTIVE_ESTABLISHED_CB, /* Calls BPF program when an
  6889. * active connection is
  6890. * established
  6891. */
  6892. BPF_SOCK_OPS_PASSIVE_ESTABLISHED_CB, /* Calls BPF program when a
  6893. * passive connection is
  6894. * established
  6895. */
  6896. BPF_SOCK_OPS_NEEDS_ECN, /* If connection's congestion control
  6897. * needs ECN
  6898. */
  6899. BPF_SOCK_OPS_BASE_RTT, /* Get base RTT. The correct value is
  6900. * based on the path and may be
  6901. * dependent on the congestion control
  6902. * algorithm. In general it indicates
  6903. * a congestion threshold. RTTs above
  6904. * this indicate congestion
  6905. */
  6906. BPF_SOCK_OPS_RTO_CB, /* Called when an RTO has triggered.
  6907. * Arg1: value of icsk_retransmits
  6908. * Arg2: value of icsk_rto
  6909. * Arg3: whether RTO has expired
  6910. */
  6911. BPF_SOCK_OPS_RETRANS_CB, /* Called when skb is retransmitted.
  6912. * Arg1: sequence number of 1st byte
  6913. * Arg2: # segments
  6914. * Arg3: return value of
  6915. * tcp_transmit_skb (0 => success)
  6916. */
  6917. BPF_SOCK_OPS_STATE_CB, /* Called when TCP changes state.
  6918. * Arg1: old_state
  6919. * Arg2: new_state
  6920. */
  6921. BPF_SOCK_OPS_TCP_LISTEN_CB, /* Called on listen(2), right after
  6922. * socket transition to LISTEN state.
  6923. */
  6924. BPF_SOCK_OPS_RTT_CB, /* Called on every RTT.
  6925. * Arg1: measured RTT input (mrtt)
  6926. * Arg2: updated srtt
  6927. */
  6928. BPF_SOCK_OPS_PARSE_HDR_OPT_CB, /* Parse the header option.
  6929. * It will be called to handle
  6930. * the packets received at
  6931. * an already established
  6932. * connection.
  6933. *
  6934. * sock_ops->skb_data:
  6935. * Referring to the received skb.
  6936. * It covers the TCP header only.
  6937. *
  6938. * bpf_load_hdr_opt() can also
  6939. * be used to search for a
  6940. * particular option.
  6941. */
  6942. BPF_SOCK_OPS_HDR_OPT_LEN_CB, /* Reserve space for writing the
  6943. * header option later in
  6944. * BPF_SOCK_OPS_WRITE_HDR_OPT_CB.
  6945. * Arg1: bool want_cookie. (in
  6946. * writing SYNACK only)
  6947. *
  6948. * sock_ops->skb_data:
  6949. * Not available because no header has
  6950. * been written yet.
  6951. *
  6952. * sock_ops->skb_tcp_flags:
  6953. * The tcp_flags of the
  6954. * outgoing skb. (e.g. SYN, ACK, FIN).
  6955. *
  6956. * bpf_reserve_hdr_opt() should
  6957. * be used to reserve space.
  6958. */
  6959. BPF_SOCK_OPS_WRITE_HDR_OPT_CB, /* Write the header options
  6960. * Arg1: bool want_cookie. (in
  6961. * writing SYNACK only)
  6962. *
  6963. * sock_ops->skb_data:
  6964. * Referring to the outgoing skb.
  6965. * It covers the TCP header
  6966. * that has already been written
  6967. * by the kernel and the
  6968. * earlier bpf-progs.
  6969. *
  6970. * sock_ops->skb_tcp_flags:
  6971. * The tcp_flags of the outgoing
  6972. * skb. (e.g. SYN, ACK, FIN).
  6973. *
  6974. * bpf_store_hdr_opt() should
  6975. * be used to write the
  6976. * option.
  6977. *
  6978. * bpf_load_hdr_opt() can also
  6979. * be used to search for a
  6980. * particular option that
  6981. * has already been written
  6982. * by the kernel or the
  6983. * earlier bpf-progs.
  6984. */
  6985. BPF_SOCK_OPS_TSTAMP_SCHED_CB, /* Called when skb is passing
  6986. * through dev layer when
  6987. * SK_BPF_CB_TX_TIMESTAMPING
  6988. * feature is on.
  6989. */
  6990. BPF_SOCK_OPS_TSTAMP_SND_SW_CB, /* Called when skb is about to send
  6991. * to the nic when SK_BPF_CB_TX_TIMESTAMPING
  6992. * feature is on.
  6993. */
  6994. BPF_SOCK_OPS_TSTAMP_SND_HW_CB, /* Called in hardware phase when
  6995. * SK_BPF_CB_TX_TIMESTAMPING feature
  6996. * is on.
  6997. */
  6998. BPF_SOCK_OPS_TSTAMP_ACK_CB, /* Called when all the skbs in the
  6999. * same sendmsg call are acked
  7000. * when SK_BPF_CB_TX_TIMESTAMPING
  7001. * feature is on.
  7002. */
  7003. BPF_SOCK_OPS_TSTAMP_SENDMSG_CB, /* Called when every sendmsg syscall
  7004. * is triggered. It's used to correlate
  7005. * sendmsg timestamp with corresponding
  7006. * tskey.
  7007. */
  7008. };
  7009. /* List of TCP states. There is a build check in net/ipv4/tcp.c to detect
  7010. * changes between the TCP and BPF versions. Ideally this should never happen.
  7011. * If it does, we need to add code to convert them before calling
  7012. * the BPF sock_ops function.
  7013. */
  7014. enum {
  7015. BPF_TCP_ESTABLISHED = 1,
  7016. BPF_TCP_SYN_SENT,
  7017. BPF_TCP_SYN_RECV,
  7018. BPF_TCP_FIN_WAIT1,
  7019. BPF_TCP_FIN_WAIT2,
  7020. BPF_TCP_TIME_WAIT,
  7021. BPF_TCP_CLOSE,
  7022. BPF_TCP_CLOSE_WAIT,
  7023. BPF_TCP_LAST_ACK,
  7024. BPF_TCP_LISTEN,
  7025. BPF_TCP_CLOSING, /* Now a valid state */
  7026. BPF_TCP_NEW_SYN_RECV,
  7027. BPF_TCP_BOUND_INACTIVE,
  7028. BPF_TCP_MAX_STATES /* Leave at the end! */
  7029. };
  7030. enum {
  7031. TCP_BPF_IW = 1001, /* Set TCP initial congestion window */
  7032. TCP_BPF_SNDCWND_CLAMP = 1002, /* Set sndcwnd_clamp */
  7033. TCP_BPF_DELACK_MAX = 1003, /* Max delay ack in usecs */
  7034. TCP_BPF_RTO_MIN = 1004, /* Min delay ack in usecs */
  7035. /* Copy the SYN pkt to optval
  7036. *
  7037. * BPF_PROG_TYPE_SOCK_OPS only. It is similar to the
  7038. * bpf_getsockopt(TCP_SAVED_SYN) but it does not limit
  7039. * to only getting from the saved_syn. It can either get the
  7040. * syn packet from:
  7041. *
  7042. * 1. the just-received SYN packet (only available when writing the
  7043. * SYNACK). It will be useful when it is not necessary to
  7044. * save the SYN packet for latter use. It is also the only way
  7045. * to get the SYN during syncookie mode because the syn
  7046. * packet cannot be saved during syncookie.
  7047. *
  7048. * OR
  7049. *
  7050. * 2. the earlier saved syn which was done by
  7051. * bpf_setsockopt(TCP_SAVE_SYN).
  7052. *
  7053. * The bpf_getsockopt(TCP_BPF_SYN*) option will hide where the
  7054. * SYN packet is obtained.
  7055. *
  7056. * If the bpf-prog does not need the IP[46] header, the
  7057. * bpf-prog can avoid parsing the IP header by using
  7058. * TCP_BPF_SYN. Otherwise, the bpf-prog can get both
  7059. * IP[46] and TCP header by using TCP_BPF_SYN_IP.
  7060. *
  7061. * >0: Total number of bytes copied
  7062. * -ENOSPC: Not enough space in optval. Only optlen number of
  7063. * bytes is copied.
  7064. * -ENOENT: The SYN skb is not available now and the earlier SYN pkt
  7065. * is not saved by setsockopt(TCP_SAVE_SYN).
  7066. */
  7067. TCP_BPF_SYN = 1005, /* Copy the TCP header */
  7068. TCP_BPF_SYN_IP = 1006, /* Copy the IP[46] and TCP header */
  7069. TCP_BPF_SYN_MAC = 1007, /* Copy the MAC, IP[46], and TCP header */
  7070. TCP_BPF_SOCK_OPS_CB_FLAGS = 1008, /* Get or Set TCP sock ops flags */
  7071. SK_BPF_CB_FLAGS = 1009, /* Get or set sock ops flags in socket */
  7072. SK_BPF_BYPASS_PROT_MEM = 1010, /* Get or Set sk->sk_bypass_prot_mem */
  7073. };
  7074. enum {
  7075. BPF_LOAD_HDR_OPT_TCP_SYN = (1ULL << 0),
  7076. };
  7077. /* args[0] value during BPF_SOCK_OPS_HDR_OPT_LEN_CB and
  7078. * BPF_SOCK_OPS_WRITE_HDR_OPT_CB.
  7079. */
  7080. enum {
  7081. BPF_WRITE_HDR_TCP_CURRENT_MSS = 1, /* Kernel is finding the
  7082. * total option spaces
  7083. * required for an established
  7084. * sk in order to calculate the
  7085. * MSS. No skb is actually
  7086. * sent.
  7087. */
  7088. BPF_WRITE_HDR_TCP_SYNACK_COOKIE = 2, /* Kernel is in syncookie mode
  7089. * when sending a SYN.
  7090. */
  7091. };
  7092. struct bpf_perf_event_value {
  7093. __u64 counter;
  7094. __u64 enabled;
  7095. __u64 running;
  7096. };
  7097. enum {
  7098. BPF_DEVCG_ACC_MKNOD = (1ULL << 0),
  7099. BPF_DEVCG_ACC_READ = (1ULL << 1),
  7100. BPF_DEVCG_ACC_WRITE = (1ULL << 2),
  7101. };
  7102. enum {
  7103. BPF_DEVCG_DEV_BLOCK = (1ULL << 0),
  7104. BPF_DEVCG_DEV_CHAR = (1ULL << 1),
  7105. };
  7106. struct bpf_cgroup_dev_ctx {
  7107. /* access_type encoded as (BPF_DEVCG_ACC_* << 16) | BPF_DEVCG_DEV_* */
  7108. __u32 access_type;
  7109. __u32 major;
  7110. __u32 minor;
  7111. };
  7112. struct bpf_raw_tracepoint_args {
  7113. __u64 args[0];
  7114. };
  7115. /* DIRECT: Skip the FIB rules and go to FIB table associated with device
  7116. * OUTPUT: Do lookup from egress perspective; default is ingress
  7117. */
  7118. enum {
  7119. BPF_FIB_LOOKUP_DIRECT = (1U << 0),
  7120. BPF_FIB_LOOKUP_OUTPUT = (1U << 1),
  7121. BPF_FIB_LOOKUP_SKIP_NEIGH = (1U << 2),
  7122. BPF_FIB_LOOKUP_TBID = (1U << 3),
  7123. BPF_FIB_LOOKUP_SRC = (1U << 4),
  7124. BPF_FIB_LOOKUP_MARK = (1U << 5),
  7125. };
  7126. enum {
  7127. BPF_FIB_LKUP_RET_SUCCESS, /* lookup successful */
  7128. BPF_FIB_LKUP_RET_BLACKHOLE, /* dest is blackholed; can be dropped */
  7129. BPF_FIB_LKUP_RET_UNREACHABLE, /* dest is unreachable; can be dropped */
  7130. BPF_FIB_LKUP_RET_PROHIBIT, /* dest not allowed; can be dropped */
  7131. BPF_FIB_LKUP_RET_NOT_FWDED, /* packet is not forwarded */
  7132. BPF_FIB_LKUP_RET_FWD_DISABLED, /* fwding is not enabled on ingress */
  7133. BPF_FIB_LKUP_RET_UNSUPP_LWT, /* fwd requires encapsulation */
  7134. BPF_FIB_LKUP_RET_NO_NEIGH, /* no neighbor entry for nh */
  7135. BPF_FIB_LKUP_RET_FRAG_NEEDED, /* fragmentation required to fwd */
  7136. BPF_FIB_LKUP_RET_NO_SRC_ADDR, /* failed to derive IP src addr */
  7137. };
  7138. struct bpf_fib_lookup {
  7139. /* input: network family for lookup (AF_INET, AF_INET6)
  7140. * output: network family of egress nexthop
  7141. */
  7142. __u8 family;
  7143. /* set if lookup is to consider L4 data - e.g., FIB rules */
  7144. __u8 l4_protocol;
  7145. __be16 sport;
  7146. __be16 dport;
  7147. union { /* used for MTU check */
  7148. /* input to lookup */
  7149. __u16 tot_len; /* L3 length from network hdr (iph->tot_len) */
  7150. /* output: MTU value */
  7151. __u16 mtu_result;
  7152. } __attribute__((packed, aligned(2)));
  7153. /* input: L3 device index for lookup
  7154. * output: device index from FIB lookup
  7155. */
  7156. __u32 ifindex;
  7157. union {
  7158. /* inputs to lookup */
  7159. __u8 tos; /* AF_INET */
  7160. __be32 flowinfo; /* AF_INET6, flow_label + priority */
  7161. /* output: metric of fib result (IPv4/IPv6 only) */
  7162. __u32 rt_metric;
  7163. };
  7164. /* input: source address to consider for lookup
  7165. * output: source address result from lookup
  7166. */
  7167. union {
  7168. __be32 ipv4_src;
  7169. __u32 ipv6_src[4]; /* in6_addr; network order */
  7170. };
  7171. /* input to bpf_fib_lookup, ipv{4,6}_dst is destination address in
  7172. * network header. output: bpf_fib_lookup sets to gateway address
  7173. * if FIB lookup returns gateway route
  7174. */
  7175. union {
  7176. __be32 ipv4_dst;
  7177. __u32 ipv6_dst[4]; /* in6_addr; network order */
  7178. };
  7179. union {
  7180. struct {
  7181. /* output */
  7182. __be16 h_vlan_proto;
  7183. __be16 h_vlan_TCI;
  7184. };
  7185. /* input: when accompanied with the
  7186. * 'BPF_FIB_LOOKUP_DIRECT | BPF_FIB_LOOKUP_TBID` flags, a
  7187. * specific routing table to use for the fib lookup.
  7188. */
  7189. __u32 tbid;
  7190. };
  7191. union {
  7192. /* input */
  7193. struct {
  7194. __u32 mark; /* policy routing */
  7195. /* 2 4-byte holes for input */
  7196. };
  7197. /* output: source and dest mac */
  7198. struct {
  7199. __u8 smac[6]; /* ETH_ALEN */
  7200. __u8 dmac[6]; /* ETH_ALEN */
  7201. };
  7202. };
  7203. };
  7204. struct bpf_redir_neigh {
  7205. /* network family for lookup (AF_INET, AF_INET6) */
  7206. __u32 nh_family;
  7207. /* network address of nexthop; skips fib lookup to find gateway */
  7208. union {
  7209. __be32 ipv4_nh;
  7210. __u32 ipv6_nh[4]; /* in6_addr; network order */
  7211. };
  7212. };
  7213. /* bpf_check_mtu flags*/
  7214. enum bpf_check_mtu_flags {
  7215. BPF_MTU_CHK_SEGS = (1U << 0),
  7216. };
  7217. enum bpf_check_mtu_ret {
  7218. BPF_MTU_CHK_RET_SUCCESS, /* check and lookup successful */
  7219. BPF_MTU_CHK_RET_FRAG_NEEDED, /* fragmentation required to fwd */
  7220. BPF_MTU_CHK_RET_SEGS_TOOBIG, /* GSO re-segmentation needed to fwd */
  7221. };
  7222. enum bpf_task_fd_type {
  7223. BPF_FD_TYPE_RAW_TRACEPOINT, /* tp name */
  7224. BPF_FD_TYPE_TRACEPOINT, /* tp name */
  7225. BPF_FD_TYPE_KPROBE, /* (symbol + offset) or addr */
  7226. BPF_FD_TYPE_KRETPROBE, /* (symbol + offset) or addr */
  7227. BPF_FD_TYPE_UPROBE, /* filename + offset */
  7228. BPF_FD_TYPE_URETPROBE, /* filename + offset */
  7229. };
  7230. enum {
  7231. BPF_FLOW_DISSECTOR_F_PARSE_1ST_FRAG = (1U << 0),
  7232. BPF_FLOW_DISSECTOR_F_STOP_AT_FLOW_LABEL = (1U << 1),
  7233. BPF_FLOW_DISSECTOR_F_STOP_AT_ENCAP = (1U << 2),
  7234. };
  7235. struct bpf_flow_keys {
  7236. __u16 nhoff;
  7237. __u16 thoff;
  7238. __u16 addr_proto; /* ETH_P_* of valid addrs */
  7239. __u8 is_frag;
  7240. __u8 is_first_frag;
  7241. __u8 is_encap;
  7242. __u8 ip_proto;
  7243. __be16 n_proto;
  7244. __be16 sport;
  7245. __be16 dport;
  7246. union {
  7247. struct {
  7248. __be32 ipv4_src;
  7249. __be32 ipv4_dst;
  7250. };
  7251. struct {
  7252. __u32 ipv6_src[4]; /* in6_addr; network order */
  7253. __u32 ipv6_dst[4]; /* in6_addr; network order */
  7254. };
  7255. };
  7256. __u32 flags;
  7257. __be32 flow_label;
  7258. };
  7259. struct bpf_func_info {
  7260. __u32 insn_off;
  7261. __u32 type_id;
  7262. };
  7263. #define BPF_LINE_INFO_LINE_NUM(line_col) ((line_col) >> 10)
  7264. #define BPF_LINE_INFO_LINE_COL(line_col) ((line_col) & 0x3ff)
  7265. struct bpf_line_info {
  7266. __u32 insn_off;
  7267. __u32 file_name_off;
  7268. __u32 line_off;
  7269. __u32 line_col;
  7270. };
  7271. struct bpf_spin_lock {
  7272. __u32 val;
  7273. };
  7274. struct bpf_timer {
  7275. __u64 __opaque[2];
  7276. } __attribute__((aligned(8)));
  7277. struct bpf_task_work {
  7278. __u64 __opaque;
  7279. } __attribute__((aligned(8)));
  7280. struct bpf_wq {
  7281. __u64 __opaque[2];
  7282. } __attribute__((aligned(8)));
  7283. struct bpf_dynptr {
  7284. __u64 __opaque[2];
  7285. } __attribute__((aligned(8)));
  7286. struct bpf_list_head {
  7287. __u64 __opaque[2];
  7288. } __attribute__((aligned(8)));
  7289. struct bpf_list_node {
  7290. __u64 __opaque[3];
  7291. } __attribute__((aligned(8)));
  7292. struct bpf_rb_root {
  7293. __u64 __opaque[2];
  7294. } __attribute__((aligned(8)));
  7295. struct bpf_rb_node {
  7296. __u64 __opaque[4];
  7297. } __attribute__((aligned(8)));
  7298. struct bpf_refcount {
  7299. __u32 __opaque[1];
  7300. } __attribute__((aligned(4)));
  7301. struct bpf_sysctl {
  7302. __u32 write; /* Sysctl is being read (= 0) or written (= 1).
  7303. * Allows 1,2,4-byte read, but no write.
  7304. */
  7305. __u32 file_pos; /* Sysctl file position to read from, write to.
  7306. * Allows 1,2,4-byte read an 4-byte write.
  7307. */
  7308. };
  7309. struct bpf_sockopt {
  7310. __bpf_md_ptr(struct bpf_sock *, sk);
  7311. __bpf_md_ptr(void *, optval);
  7312. __bpf_md_ptr(void *, optval_end);
  7313. __s32 level;
  7314. __s32 optname;
  7315. __s32 optlen;
  7316. __s32 retval;
  7317. };
  7318. struct bpf_pidns_info {
  7319. __u32 pid;
  7320. __u32 tgid;
  7321. };
  7322. /* User accessible data for SK_LOOKUP programs. Add new fields at the end. */
  7323. struct bpf_sk_lookup {
  7324. union {
  7325. __bpf_md_ptr(struct bpf_sock *, sk); /* Selected socket */
  7326. __u64 cookie; /* Non-zero if socket was selected in PROG_TEST_RUN */
  7327. };
  7328. __u32 family; /* Protocol family (AF_INET, AF_INET6) */
  7329. __u32 protocol; /* IP protocol (IPPROTO_TCP, IPPROTO_UDP) */
  7330. __u32 remote_ip4; /* Network byte order */
  7331. __u32 remote_ip6[4]; /* Network byte order */
  7332. __be16 remote_port; /* Network byte order */
  7333. __u16 :16; /* Zero padding */
  7334. __u32 local_ip4; /* Network byte order */
  7335. __u32 local_ip6[4]; /* Network byte order */
  7336. __u32 local_port; /* Host byte order */
  7337. __u32 ingress_ifindex; /* The arriving interface. Determined by inet_iif. */
  7338. };
  7339. /*
  7340. * struct btf_ptr is used for typed pointer representation; the
  7341. * type id is used to render the pointer data as the appropriate type
  7342. * via the bpf_snprintf_btf() helper described above. A flags field -
  7343. * potentially to specify additional details about the BTF pointer
  7344. * (rather than its mode of display) - is included for future use.
  7345. * Display flags - BTF_F_* - are passed to bpf_snprintf_btf separately.
  7346. */
  7347. struct btf_ptr {
  7348. void *ptr;
  7349. __u32 type_id;
  7350. __u32 flags; /* BTF ptr flags; unused at present. */
  7351. };
  7352. /*
  7353. * Flags to control bpf_snprintf_btf() behaviour.
  7354. * - BTF_F_COMPACT: no formatting around type information
  7355. * - BTF_F_NONAME: no struct/union member names/types
  7356. * - BTF_F_PTR_RAW: show raw (unobfuscated) pointer values;
  7357. * equivalent to %px.
  7358. * - BTF_F_ZERO: show zero-valued struct/union members; they
  7359. * are not displayed by default
  7360. */
  7361. enum {
  7362. BTF_F_COMPACT = (1ULL << 0),
  7363. BTF_F_NONAME = (1ULL << 1),
  7364. BTF_F_PTR_RAW = (1ULL << 2),
  7365. BTF_F_ZERO = (1ULL << 3),
  7366. };
  7367. /* bpf_core_relo_kind encodes which aspect of captured field/type/enum value
  7368. * has to be adjusted by relocations. It is emitted by llvm and passed to
  7369. * libbpf and later to the kernel.
  7370. */
  7371. enum bpf_core_relo_kind {
  7372. BPF_CORE_FIELD_BYTE_OFFSET = 0, /* field byte offset */
  7373. BPF_CORE_FIELD_BYTE_SIZE = 1, /* field size in bytes */
  7374. BPF_CORE_FIELD_EXISTS = 2, /* field existence in target kernel */
  7375. BPF_CORE_FIELD_SIGNED = 3, /* field signedness (0 - unsigned, 1 - signed) */
  7376. BPF_CORE_FIELD_LSHIFT_U64 = 4, /* bitfield-specific left bitshift */
  7377. BPF_CORE_FIELD_RSHIFT_U64 = 5, /* bitfield-specific right bitshift */
  7378. BPF_CORE_TYPE_ID_LOCAL = 6, /* type ID in local BPF object */
  7379. BPF_CORE_TYPE_ID_TARGET = 7, /* type ID in target kernel */
  7380. BPF_CORE_TYPE_EXISTS = 8, /* type existence in target kernel */
  7381. BPF_CORE_TYPE_SIZE = 9, /* type size in bytes */
  7382. BPF_CORE_ENUMVAL_EXISTS = 10, /* enum value existence in target kernel */
  7383. BPF_CORE_ENUMVAL_VALUE = 11, /* enum value integer value */
  7384. BPF_CORE_TYPE_MATCHES = 12, /* type match in target kernel */
  7385. };
  7386. /*
  7387. * "struct bpf_core_relo" is used to pass relocation data form LLVM to libbpf
  7388. * and from libbpf to the kernel.
  7389. *
  7390. * CO-RE relocation captures the following data:
  7391. * - insn_off - instruction offset (in bytes) within a BPF program that needs
  7392. * its insn->imm field to be relocated with actual field info;
  7393. * - type_id - BTF type ID of the "root" (containing) entity of a relocatable
  7394. * type or field;
  7395. * - access_str_off - offset into corresponding .BTF string section. String
  7396. * interpretation depends on specific relocation kind:
  7397. * - for field-based relocations, string encodes an accessed field using
  7398. * a sequence of field and array indices, separated by colon (:). It's
  7399. * conceptually very close to LLVM's getelementptr ([0]) instruction's
  7400. * arguments for identifying offset to a field.
  7401. * - for type-based relocations, strings is expected to be just "0";
  7402. * - for enum value-based relocations, string contains an index of enum
  7403. * value within its enum type;
  7404. * - kind - one of enum bpf_core_relo_kind;
  7405. *
  7406. * Example:
  7407. * struct sample {
  7408. * int a;
  7409. * struct {
  7410. * int b[10];
  7411. * };
  7412. * };
  7413. *
  7414. * struct sample *s = ...;
  7415. * int *x = &s->a; // encoded as "0:0" (a is field #0)
  7416. * int *y = &s->b[5]; // encoded as "0:1:0:5" (anon struct is field #1,
  7417. * // b is field #0 inside anon struct, accessing elem #5)
  7418. * int *z = &s[10]->b; // encoded as "10:1" (ptr is used as an array)
  7419. *
  7420. * type_id for all relocs in this example will capture BTF type id of
  7421. * `struct sample`.
  7422. *
  7423. * Such relocation is emitted when using __builtin_preserve_access_index()
  7424. * Clang built-in, passing expression that captures field address, e.g.:
  7425. *
  7426. * bpf_probe_read(&dst, sizeof(dst),
  7427. * __builtin_preserve_access_index(&src->a.b.c));
  7428. *
  7429. * In this case Clang will emit field relocation recording necessary data to
  7430. * be able to find offset of embedded `a.b.c` field within `src` struct.
  7431. *
  7432. * [0] https://llvm.org/docs/LangRef.html#getelementptr-instruction
  7433. */
  7434. struct bpf_core_relo {
  7435. __u32 insn_off;
  7436. __u32 type_id;
  7437. __u32 access_str_off;
  7438. enum bpf_core_relo_kind kind;
  7439. };
  7440. /*
  7441. * Flags to control bpf_timer_start() behaviour.
  7442. * - BPF_F_TIMER_ABS: Timeout passed is absolute time, by default it is
  7443. * relative to current time.
  7444. * - BPF_F_TIMER_CPU_PIN: Timer will be pinned to the CPU of the caller.
  7445. */
  7446. enum {
  7447. BPF_F_TIMER_ABS = (1ULL << 0),
  7448. BPF_F_TIMER_CPU_PIN = (1ULL << 1),
  7449. };
  7450. /* BPF numbers iterator state */
  7451. struct bpf_iter_num {
  7452. /* opaque iterator state; having __u64 here allows to preserve correct
  7453. * alignment requirements in vmlinux.h, generated from BTF
  7454. */
  7455. __u64 __opaque[1];
  7456. } __attribute__((aligned(8)));
  7457. /*
  7458. * Flags to control BPF kfunc behaviour.
  7459. * - BPF_F_PAD_ZEROS: Pad destination buffer with zeros. (See the respective
  7460. * helper documentation for details.)
  7461. */
  7462. enum bpf_kfunc_flags {
  7463. BPF_F_PAD_ZEROS = (1ULL << 0),
  7464. };
  7465. /*
  7466. * Values of a BPF_MAP_TYPE_INSN_ARRAY entry must be of this type.
  7467. *
  7468. * Before the map is used the orig_off field should point to an
  7469. * instruction inside the program being loaded. The other fields
  7470. * must be set to 0.
  7471. *
  7472. * After the program is loaded, the xlated_off will be adjusted
  7473. * by the verifier to point to the index of the original instruction
  7474. * in the xlated program. If the instruction is deleted, it will
  7475. * be set to (u32)-1. The jitted_off will be set to the corresponding
  7476. * offset in the jitted image of the program.
  7477. */
  7478. struct bpf_insn_array_value {
  7479. __u32 orig_off;
  7480. __u32 xlated_off;
  7481. __u32 jitted_off;
  7482. __u32 :32;
  7483. };
  7484. #endif /* _UAPI__LINUX_BPF_H__ */