bpf.h 254 KB

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