bpf.h 254 KB

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