bpf.h 263 KB

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