bpf_helper_defs.h 170 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761
  1. /* This is auto-generated file. See bpf_doc.py for details. */
  2. /* Forward declarations of BPF structs */
  3. struct bpf_fib_lookup;
  4. struct bpf_sk_lookup;
  5. struct bpf_perf_event_data;
  6. struct bpf_perf_event_value;
  7. struct bpf_pidns_info;
  8. struct bpf_redir_neigh;
  9. struct bpf_sock;
  10. struct bpf_sock_addr;
  11. struct bpf_sock_ops;
  12. struct bpf_sock_tuple;
  13. struct bpf_spin_lock;
  14. struct bpf_sysctl;
  15. struct bpf_tcp_sock;
  16. struct bpf_tunnel_key;
  17. struct bpf_xfrm_state;
  18. struct linux_binprm;
  19. struct pt_regs;
  20. struct sk_reuseport_md;
  21. struct sockaddr;
  22. struct tcphdr;
  23. struct seq_file;
  24. struct tcp6_sock;
  25. struct tcp_sock;
  26. struct tcp_timewait_sock;
  27. struct tcp_request_sock;
  28. struct udp6_sock;
  29. struct unix_sock;
  30. struct task_struct;
  31. struct cgroup;
  32. struct __sk_buff;
  33. struct sk_msg_md;
  34. struct xdp_md;
  35. struct path;
  36. struct btf_ptr;
  37. struct inode;
  38. struct socket;
  39. struct file;
  40. struct bpf_timer;
  41. struct mptcp_sock;
  42. struct bpf_dynptr;
  43. struct iphdr;
  44. struct ipv6hdr;
  45. /*
  46. * bpf_map_lookup_elem
  47. *
  48. * Perform a lookup in *map* for an entry associated to *key*.
  49. *
  50. * Returns
  51. * Map value associated to *key*, or **NULL** if no entry was
  52. * found.
  53. */
  54. static void *(*bpf_map_lookup_elem)(void *map, const void *key) = (void *) 1;
  55. /*
  56. * bpf_map_update_elem
  57. *
  58. * Add or update the value of the entry associated to *key* in
  59. * *map* with *value*. *flags* is one of:
  60. *
  61. * **BPF_NOEXIST**
  62. * The entry for *key* must not exist in the map.
  63. * **BPF_EXIST**
  64. * The entry for *key* must already exist in the map.
  65. * **BPF_ANY**
  66. * No condition on the existence of the entry for *key*.
  67. *
  68. * Flag value **BPF_NOEXIST** cannot be used for maps of types
  69. * **BPF_MAP_TYPE_ARRAY** or **BPF_MAP_TYPE_PERCPU_ARRAY** (all
  70. * elements always exist), the helper would return an error.
  71. *
  72. * Returns
  73. * 0 on success, or a negative error in case of failure.
  74. */
  75. static long (*bpf_map_update_elem)(void *map, const void *key, const void *value, __u64 flags) = (void *) 2;
  76. /*
  77. * bpf_map_delete_elem
  78. *
  79. * Delete entry with *key* from *map*.
  80. *
  81. * Returns
  82. * 0 on success, or a negative error in case of failure.
  83. */
  84. static long (*bpf_map_delete_elem)(void *map, const void *key) = (void *) 3;
  85. /*
  86. * bpf_probe_read
  87. *
  88. * For tracing programs, safely attempt to read *size* bytes from
  89. * kernel space address *unsafe_ptr* and store the data in *dst*.
  90. *
  91. * Generally, use **bpf_probe_read_user**\ () or
  92. * **bpf_probe_read_kernel**\ () instead.
  93. *
  94. * Returns
  95. * 0 on success, or a negative error in case of failure.
  96. */
  97. static long (*bpf_probe_read)(void *dst, __u32 size, const void *unsafe_ptr) = (void *) 4;
  98. /*
  99. * bpf_ktime_get_ns
  100. *
  101. * Return the time elapsed since system boot, in nanoseconds.
  102. * Does not include time the system was suspended.
  103. * See: **clock_gettime**\ (**CLOCK_MONOTONIC**)
  104. *
  105. * Returns
  106. * Current *ktime*.
  107. */
  108. static __u64 (*bpf_ktime_get_ns)(void) = (void *) 5;
  109. /*
  110. * bpf_trace_printk
  111. *
  112. * This helper is a "printk()-like" facility for debugging. It
  113. * prints a message defined by format *fmt* (of size *fmt_size*)
  114. * to file *\/sys/kernel/tracing/trace* from TraceFS, if
  115. * available. It can take up to three additional **u64**
  116. * arguments (as an eBPF helpers, the total number of arguments is
  117. * limited to five).
  118. *
  119. * Each time the helper is called, it appends a line to the trace.
  120. * Lines are discarded while *\/sys/kernel/tracing/trace* is
  121. * open, use *\/sys/kernel/tracing/trace_pipe* to avoid this.
  122. * The format of the trace is customizable, and the exact output
  123. * one will get depends on the options set in
  124. * *\/sys/kernel/tracing/trace_options* (see also the
  125. * *README* file under the same directory). However, it usually
  126. * defaults to something like:
  127. *
  128. * ::
  129. *
  130. * telnet-470 [001] .N.. 419421.045894: 0x00000001: <formatted msg>
  131. *
  132. * In the above:
  133. *
  134. * * ``telnet`` is the name of the current task.
  135. * * ``470`` is the PID of the current task.
  136. * * ``001`` is the CPU number on which the task is
  137. * running.
  138. * * In ``.N..``, each character refers to a set of
  139. * options (whether irqs are enabled, scheduling
  140. * options, whether hard/softirqs are running, level of
  141. * preempt_disabled respectively). **N** means that
  142. * **TIF_NEED_RESCHED** and **PREEMPT_NEED_RESCHED**
  143. * are set.
  144. * * ``419421.045894`` is a timestamp.
  145. * * ``0x00000001`` is a fake value used by BPF for the
  146. * instruction pointer register.
  147. * * ``<formatted msg>`` is the message formatted with
  148. * *fmt*.
  149. *
  150. * The conversion specifiers supported by *fmt* are similar, but
  151. * more limited than for printk(). They are **%d**, **%i**,
  152. * **%u**, **%x**, **%ld**, **%li**, **%lu**, **%lx**, **%lld**,
  153. * **%lli**, **%llu**, **%llx**, **%p**, **%s**. No modifier (size
  154. * of field, padding with zeroes, etc.) is available, and the
  155. * helper will return **-EINVAL** (but print nothing) if it
  156. * encounters an unknown specifier.
  157. *
  158. * Also, note that **bpf_trace_printk**\ () is slow, and should
  159. * only be used for debugging purposes. For this reason, a notice
  160. * block (spanning several lines) is printed to kernel logs and
  161. * states that the helper should not be used "for production use"
  162. * the first time this helper is used (or more precisely, when
  163. * **trace_printk**\ () buffers are allocated). For passing values
  164. * to user space, perf events should be preferred.
  165. *
  166. * Returns
  167. * The number of bytes written to the buffer, or a negative error
  168. * in case of failure.
  169. */
  170. static long (*bpf_trace_printk)(const char *fmt, __u32 fmt_size, ...) = (void *) 6;
  171. /*
  172. * bpf_get_prandom_u32
  173. *
  174. * Get a pseudo-random number.
  175. *
  176. * From a security point of view, this helper uses its own
  177. * pseudo-random internal state, and cannot be used to infer the
  178. * seed of other random functions in the kernel. However, it is
  179. * essential to note that the generator used by the helper is not
  180. * cryptographically secure.
  181. *
  182. * Returns
  183. * A random 32-bit unsigned value.
  184. */
  185. static __u32 (*bpf_get_prandom_u32)(void) = (void *) 7;
  186. /*
  187. * bpf_get_smp_processor_id
  188. *
  189. * Get the SMP (symmetric multiprocessing) processor id. Note that
  190. * all programs run with migration disabled, which means that the
  191. * SMP processor id is stable during all the execution of the
  192. * program.
  193. *
  194. * Returns
  195. * The SMP id of the processor running the program.
  196. */
  197. static __u32 (*bpf_get_smp_processor_id)(void) = (void *) 8;
  198. /*
  199. * bpf_skb_store_bytes
  200. *
  201. * Store *len* bytes from address *from* into the packet
  202. * associated to *skb*, at *offset*. *flags* are a combination of
  203. * **BPF_F_RECOMPUTE_CSUM** (automatically recompute the
  204. * checksum for the packet after storing the bytes) and
  205. * **BPF_F_INVALIDATE_HASH** (set *skb*\ **->hash**, *skb*\
  206. * **->swhash** and *skb*\ **->l4hash** to 0).
  207. *
  208. * A call to this helper is susceptible to change the underlying
  209. * packet buffer. Therefore, at load time, all checks on pointers
  210. * previously done by the verifier are invalidated and must be
  211. * performed again, if the helper is used in combination with
  212. * direct packet access.
  213. *
  214. * Returns
  215. * 0 on success, or a negative error in case of failure.
  216. */
  217. static long (*bpf_skb_store_bytes)(struct __sk_buff *skb, __u32 offset, const void *from, __u32 len, __u64 flags) = (void *) 9;
  218. /*
  219. * bpf_l3_csum_replace
  220. *
  221. * Recompute the layer 3 (e.g. IP) checksum for the packet
  222. * associated to *skb*. Computation is incremental, so the helper
  223. * must know the former value of the header field that was
  224. * modified (*from*), the new value of this field (*to*), and the
  225. * number of bytes (2 or 4) for this field, stored in *size*.
  226. * Alternatively, it is possible to store the difference between
  227. * the previous and the new values of the header field in *to*, by
  228. * setting *from* and *size* to 0. For both methods, *offset*
  229. * indicates the location of the IP checksum within the packet.
  230. *
  231. * This helper works in combination with **bpf_csum_diff**\ (),
  232. * which does not update the checksum in-place, but offers more
  233. * flexibility and can handle sizes larger than 2 or 4 for the
  234. * checksum to update.
  235. *
  236. * A call to this helper is susceptible to change the underlying
  237. * packet buffer. Therefore, at load time, all checks on pointers
  238. * previously done by the verifier are invalidated and must be
  239. * performed again, if the helper is used in combination with
  240. * direct packet access.
  241. *
  242. * Returns
  243. * 0 on success, or a negative error in case of failure.
  244. */
  245. static long (*bpf_l3_csum_replace)(struct __sk_buff *skb, __u32 offset, __u64 from, __u64 to, __u64 size) = (void *) 10;
  246. /*
  247. * bpf_l4_csum_replace
  248. *
  249. * Recompute the layer 4 (e.g. TCP, UDP or ICMP) checksum for the
  250. * packet associated to *skb*. Computation is incremental, so the
  251. * helper must know the former value of the header field that was
  252. * modified (*from*), the new value of this field (*to*), and the
  253. * number of bytes (2 or 4) for this field, stored on the lowest
  254. * four bits of *flags*. Alternatively, it is possible to store
  255. * the difference between the previous and the new values of the
  256. * header field in *to*, by setting *from* and the four lowest
  257. * bits of *flags* to 0. For both methods, *offset* indicates the
  258. * location of the IP checksum within the packet. In addition to
  259. * the size of the field, *flags* can be added (bitwise OR) actual
  260. * flags. With **BPF_F_MARK_MANGLED_0**, a null checksum is left
  261. * untouched (unless **BPF_F_MARK_ENFORCE** is added as well), and
  262. * for updates resulting in a null checksum the value is set to
  263. * **CSUM_MANGLED_0** instead. Flag **BPF_F_PSEUDO_HDR** indicates
  264. * the checksum is to be computed against a pseudo-header.
  265. *
  266. * This helper works in combination with **bpf_csum_diff**\ (),
  267. * which does not update the checksum in-place, but offers more
  268. * flexibility and can handle sizes larger than 2 or 4 for the
  269. * checksum to update.
  270. *
  271. * A call to this helper is susceptible to change the underlying
  272. * packet buffer. Therefore, at load time, all checks on pointers
  273. * previously done by the verifier are invalidated and must be
  274. * performed again, if the helper is used in combination with
  275. * direct packet access.
  276. *
  277. * Returns
  278. * 0 on success, or a negative error in case of failure.
  279. */
  280. static long (*bpf_l4_csum_replace)(struct __sk_buff *skb, __u32 offset, __u64 from, __u64 to, __u64 flags) = (void *) 11;
  281. /*
  282. * bpf_tail_call
  283. *
  284. * This special helper is used to trigger a "tail call", or in
  285. * other words, to jump into another eBPF program. The same stack
  286. * frame is used (but values on stack and in registers for the
  287. * caller are not accessible to the callee). This mechanism allows
  288. * for program chaining, either for raising the maximum number of
  289. * available eBPF instructions, or to execute given programs in
  290. * conditional blocks. For security reasons, there is an upper
  291. * limit to the number of successive tail calls that can be
  292. * performed.
  293. *
  294. * Upon call of this helper, the program attempts to jump into a
  295. * program referenced at index *index* in *prog_array_map*, a
  296. * special map of type **BPF_MAP_TYPE_PROG_ARRAY**, and passes
  297. * *ctx*, a pointer to the context.
  298. *
  299. * If the call succeeds, the kernel immediately runs the first
  300. * instruction of the new program. This is not a function call,
  301. * and it never returns to the previous program. If the call
  302. * fails, then the helper has no effect, and the caller continues
  303. * to run its subsequent instructions. A call can fail if the
  304. * destination program for the jump does not exist (i.e. *index*
  305. * is superior to the number of entries in *prog_array_map*), or
  306. * if the maximum number of tail calls has been reached for this
  307. * chain of programs. This limit is defined in the kernel by the
  308. * macro **MAX_TAIL_CALL_CNT** (not accessible to user space),
  309. * which is currently set to 33.
  310. *
  311. * Returns
  312. * 0 on success, or a negative error in case of failure.
  313. */
  314. static long (*bpf_tail_call)(void *ctx, void *prog_array_map, __u32 index) = (void *) 12;
  315. /*
  316. * bpf_clone_redirect
  317. *
  318. * Clone and redirect the packet associated to *skb* to another
  319. * net device of index *ifindex*. Both ingress and egress
  320. * interfaces can be used for redirection. The **BPF_F_INGRESS**
  321. * value in *flags* is used to make the distinction (ingress path
  322. * is selected if the flag is present, egress path otherwise).
  323. * This is the only flag supported for now.
  324. *
  325. * In comparison with **bpf_redirect**\ () helper,
  326. * **bpf_clone_redirect**\ () has the associated cost of
  327. * duplicating the packet buffer, but this can be executed out of
  328. * the eBPF program. Conversely, **bpf_redirect**\ () is more
  329. * efficient, but it is handled through an action code where the
  330. * redirection happens only after the eBPF program has returned.
  331. *
  332. * A call to this helper is susceptible to change the underlying
  333. * packet buffer. Therefore, at load time, all checks on pointers
  334. * previously done by the verifier are invalidated and must be
  335. * performed again, if the helper is used in combination with
  336. * direct packet access.
  337. *
  338. * Returns
  339. * 0 on success, or a negative error in case of failure. Positive
  340. * error indicates a potential drop or congestion in the target
  341. * device. The particular positive error codes are not defined.
  342. */
  343. static long (*bpf_clone_redirect)(struct __sk_buff *skb, __u32 ifindex, __u64 flags) = (void *) 13;
  344. /*
  345. * bpf_get_current_pid_tgid
  346. *
  347. * Get the current pid and tgid.
  348. *
  349. * Returns
  350. * A 64-bit integer containing the current tgid and pid, and
  351. * created as such:
  352. * *current_task*\ **->tgid << 32 \|**
  353. * *current_task*\ **->pid**.
  354. */
  355. static __u64 (*bpf_get_current_pid_tgid)(void) = (void *) 14;
  356. /*
  357. * bpf_get_current_uid_gid
  358. *
  359. * Get the current uid and gid.
  360. *
  361. * Returns
  362. * A 64-bit integer containing the current GID and UID, and
  363. * created as such: *current_gid* **<< 32 \|** *current_uid*.
  364. */
  365. static __u64 (*bpf_get_current_uid_gid)(void) = (void *) 15;
  366. /*
  367. * bpf_get_current_comm
  368. *
  369. * Copy the **comm** attribute of the current task into *buf* of
  370. * *size_of_buf*. The **comm** attribute contains the name of
  371. * the executable (excluding the path) for the current task. The
  372. * *size_of_buf* must be strictly positive. On success, the
  373. * helper makes sure that the *buf* is NUL-terminated. On failure,
  374. * it is filled with zeroes.
  375. *
  376. * Returns
  377. * 0 on success, or a negative error in case of failure.
  378. */
  379. static long (*bpf_get_current_comm)(void *buf, __u32 size_of_buf) = (void *) 16;
  380. /*
  381. * bpf_get_cgroup_classid
  382. *
  383. * Retrieve the classid for the current task, i.e. for the net_cls
  384. * cgroup to which *skb* belongs.
  385. *
  386. * This helper can be used on TC egress path, but not on ingress.
  387. *
  388. * The net_cls cgroup provides an interface to tag network packets
  389. * based on a user-provided identifier for all traffic coming from
  390. * the tasks belonging to the related cgroup. See also the related
  391. * kernel documentation, available from the Linux sources in file
  392. * *Documentation/admin-guide/cgroup-v1/net_cls.rst*.
  393. *
  394. * The Linux kernel has two versions for cgroups: there are
  395. * cgroups v1 and cgroups v2. Both are available to users, who can
  396. * use a mixture of them, but note that the net_cls cgroup is for
  397. * cgroup v1 only. This makes it incompatible with BPF programs
  398. * run on cgroups, which is a cgroup-v2-only feature (a socket can
  399. * only hold data for one version of cgroups at a time).
  400. *
  401. * This helper is only available is the kernel was compiled with
  402. * the **CONFIG_CGROUP_NET_CLASSID** configuration option set to
  403. * "**y**" or to "**m**".
  404. *
  405. * Returns
  406. * The classid, or 0 for the default unconfigured classid.
  407. */
  408. static __u32 (*bpf_get_cgroup_classid)(struct __sk_buff *skb) = (void *) 17;
  409. /*
  410. * bpf_skb_vlan_push
  411. *
  412. * Push a *vlan_tci* (VLAN tag control information) of protocol
  413. * *vlan_proto* to the packet associated to *skb*, then update
  414. * the checksum. Note that if *vlan_proto* is different from
  415. * **ETH_P_8021Q** and **ETH_P_8021AD**, it is considered to
  416. * be **ETH_P_8021Q**.
  417. *
  418. * A call to this helper is susceptible to change the underlying
  419. * packet buffer. Therefore, at load time, all checks on pointers
  420. * previously done by the verifier are invalidated and must be
  421. * performed again, if the helper is used in combination with
  422. * direct packet access.
  423. *
  424. * Returns
  425. * 0 on success, or a negative error in case of failure.
  426. */
  427. static long (*bpf_skb_vlan_push)(struct __sk_buff *skb, __be16 vlan_proto, __u16 vlan_tci) = (void *) 18;
  428. /*
  429. * bpf_skb_vlan_pop
  430. *
  431. * Pop a VLAN header from the packet associated to *skb*.
  432. *
  433. * A call to this helper is susceptible to change the underlying
  434. * packet buffer. Therefore, at load time, all checks on pointers
  435. * previously done by the verifier are invalidated and must be
  436. * performed again, if the helper is used in combination with
  437. * direct packet access.
  438. *
  439. * Returns
  440. * 0 on success, or a negative error in case of failure.
  441. */
  442. static long (*bpf_skb_vlan_pop)(struct __sk_buff *skb) = (void *) 19;
  443. /*
  444. * bpf_skb_get_tunnel_key
  445. *
  446. * Get tunnel metadata. This helper takes a pointer *key* to an
  447. * empty **struct bpf_tunnel_key** of **size**, that will be
  448. * filled with tunnel metadata for the packet associated to *skb*.
  449. * The *flags* can be set to **BPF_F_TUNINFO_IPV6**, which
  450. * indicates that the tunnel is based on IPv6 protocol instead of
  451. * IPv4.
  452. *
  453. * The **struct bpf_tunnel_key** is an object that generalizes the
  454. * principal parameters used by various tunneling protocols into a
  455. * single struct. This way, it can be used to easily make a
  456. * decision based on the contents of the encapsulation header,
  457. * "summarized" in this struct. In particular, it holds the IP
  458. * address of the remote end (IPv4 or IPv6, depending on the case)
  459. * in *key*\ **->remote_ipv4** or *key*\ **->remote_ipv6**. Also,
  460. * this struct exposes the *key*\ **->tunnel_id**, which is
  461. * generally mapped to a VNI (Virtual Network Identifier), making
  462. * it programmable together with the **bpf_skb_set_tunnel_key**\
  463. * () helper.
  464. *
  465. * Let's imagine that the following code is part of a program
  466. * attached to the TC ingress interface, on one end of a GRE
  467. * tunnel, and is supposed to filter out all messages coming from
  468. * remote ends with IPv4 address other than 10.0.0.1:
  469. *
  470. * ::
  471. *
  472. * int ret;
  473. * struct bpf_tunnel_key key = {};
  474. *
  475. * ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0);
  476. * if (ret < 0)
  477. * return TC_ACT_SHOT; // drop packet
  478. *
  479. * if (key.remote_ipv4 != 0x0a000001)
  480. * return TC_ACT_SHOT; // drop packet
  481. *
  482. * return TC_ACT_OK; // accept packet
  483. *
  484. * This interface can also be used with all encapsulation devices
  485. * that can operate in "collect metadata" mode: instead of having
  486. * one network device per specific configuration, the "collect
  487. * metadata" mode only requires a single device where the
  488. * configuration can be extracted from this helper.
  489. *
  490. * This can be used together with various tunnels such as VXLan,
  491. * Geneve, GRE or IP in IP (IPIP).
  492. *
  493. * Returns
  494. * 0 on success, or a negative error in case of failure.
  495. */
  496. static long (*bpf_skb_get_tunnel_key)(struct __sk_buff *skb, struct bpf_tunnel_key *key, __u32 size, __u64 flags) = (void *) 20;
  497. /*
  498. * bpf_skb_set_tunnel_key
  499. *
  500. * Populate tunnel metadata for packet associated to *skb.* The
  501. * tunnel metadata is set to the contents of *key*, of *size*. The
  502. * *flags* can be set to a combination of the following values:
  503. *
  504. * **BPF_F_TUNINFO_IPV6**
  505. * Indicate that the tunnel is based on IPv6 protocol
  506. * instead of IPv4.
  507. * **BPF_F_ZERO_CSUM_TX**
  508. * For IPv4 packets, add a flag to tunnel metadata
  509. * indicating that checksum computation should be skipped
  510. * and checksum set to zeroes.
  511. * **BPF_F_DONT_FRAGMENT**
  512. * Add a flag to tunnel metadata indicating that the
  513. * packet should not be fragmented.
  514. * **BPF_F_SEQ_NUMBER**
  515. * Add a flag to tunnel metadata indicating that a
  516. * sequence number should be added to tunnel header before
  517. * sending the packet. This flag was added for GRE
  518. * encapsulation, but might be used with other protocols
  519. * as well in the future.
  520. * **BPF_F_NO_TUNNEL_KEY**
  521. * Add a flag to tunnel metadata indicating that no tunnel
  522. * key should be set in the resulting tunnel header.
  523. *
  524. * Here is a typical usage on the transmit path:
  525. *
  526. * ::
  527. *
  528. * struct bpf_tunnel_key key;
  529. * populate key ...
  530. * bpf_skb_set_tunnel_key(skb, &key, sizeof(key), 0);
  531. * bpf_clone_redirect(skb, vxlan_dev_ifindex, 0);
  532. *
  533. * See also the description of the **bpf_skb_get_tunnel_key**\ ()
  534. * helper for additional information.
  535. *
  536. * Returns
  537. * 0 on success, or a negative error in case of failure.
  538. */
  539. static long (*bpf_skb_set_tunnel_key)(struct __sk_buff *skb, struct bpf_tunnel_key *key, __u32 size, __u64 flags) = (void *) 21;
  540. /*
  541. * bpf_perf_event_read
  542. *
  543. * Read the value of a perf event counter. This helper relies on a
  544. * *map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. The nature of
  545. * the perf event counter is selected when *map* is updated with
  546. * perf event file descriptors. The *map* is an array whose size
  547. * is the number of available CPUs, and each cell contains a value
  548. * relative to one CPU. The value to retrieve is indicated by
  549. * *flags*, that contains the index of the CPU to look up, masked
  550. * with **BPF_F_INDEX_MASK**. Alternatively, *flags* can be set to
  551. * **BPF_F_CURRENT_CPU** to indicate that the value for the
  552. * current CPU should be retrieved.
  553. *
  554. * Note that before Linux 4.13, only hardware perf event can be
  555. * retrieved.
  556. *
  557. * Also, be aware that the newer helper
  558. * **bpf_perf_event_read_value**\ () is recommended over
  559. * **bpf_perf_event_read**\ () in general. The latter has some ABI
  560. * quirks where error and counter value are used as a return code
  561. * (which is wrong to do since ranges may overlap). This issue is
  562. * fixed with **bpf_perf_event_read_value**\ (), which at the same
  563. * time provides more features over the **bpf_perf_event_read**\
  564. * () interface. Please refer to the description of
  565. * **bpf_perf_event_read_value**\ () for details.
  566. *
  567. * Returns
  568. * The value of the perf event counter read from the map, or a
  569. * negative error code in case of failure.
  570. */
  571. static __u64 (*bpf_perf_event_read)(void *map, __u64 flags) = (void *) 22;
  572. /*
  573. * bpf_redirect
  574. *
  575. * Redirect the packet to another net device of index *ifindex*.
  576. * This helper is somewhat similar to **bpf_clone_redirect**\
  577. * (), except that the packet is not cloned, which provides
  578. * increased performance.
  579. *
  580. * Except for XDP, both ingress and egress interfaces can be used
  581. * for redirection. The **BPF_F_INGRESS** value in *flags* is used
  582. * to make the distinction (ingress path is selected if the flag
  583. * is present, egress path otherwise). Currently, XDP only
  584. * supports redirection to the egress interface, and accepts no
  585. * flag at all.
  586. *
  587. * The same effect can also be attained with the more generic
  588. * **bpf_redirect_map**\ (), which uses a BPF map to store the
  589. * redirect target instead of providing it directly to the helper.
  590. *
  591. * Returns
  592. * For XDP, the helper returns **XDP_REDIRECT** on success or
  593. * **XDP_ABORTED** on error. For other program types, the values
  594. * are **TC_ACT_REDIRECT** on success or **TC_ACT_SHOT** on
  595. * error.
  596. */
  597. static long (*bpf_redirect)(__u32 ifindex, __u64 flags) = (void *) 23;
  598. /*
  599. * bpf_get_route_realm
  600. *
  601. * Retrieve the realm or the route, that is to say the
  602. * **tclassid** field of the destination for the *skb*. The
  603. * identifier retrieved is a user-provided tag, similar to the
  604. * one used with the net_cls cgroup (see description for
  605. * **bpf_get_cgroup_classid**\ () helper), but here this tag is
  606. * held by a route (a destination entry), not by a task.
  607. *
  608. * Retrieving this identifier works with the clsact TC egress hook
  609. * (see also **tc-bpf(8)**), or alternatively on conventional
  610. * classful egress qdiscs, but not on TC ingress path. In case of
  611. * clsact TC egress hook, this has the advantage that, internally,
  612. * the destination entry has not been dropped yet in the transmit
  613. * path. Therefore, the destination entry does not need to be
  614. * artificially held via **netif_keep_dst**\ () for a classful
  615. * qdisc until the *skb* is freed.
  616. *
  617. * This helper is available only if the kernel was compiled with
  618. * **CONFIG_IP_ROUTE_CLASSID** configuration option.
  619. *
  620. * Returns
  621. * The realm of the route for the packet associated to *skb*, or 0
  622. * if none was found.
  623. */
  624. static __u32 (*bpf_get_route_realm)(struct __sk_buff *skb) = (void *) 24;
  625. /*
  626. * bpf_perf_event_output
  627. *
  628. * Write raw *data* blob into a special BPF perf event held by
  629. * *map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
  630. * event must have the following attributes: **PERF_SAMPLE_RAW**
  631. * as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
  632. * **PERF_COUNT_SW_BPF_OUTPUT** as **config**.
  633. *
  634. * The *flags* are used to indicate the index in *map* for which
  635. * the value must be put, masked with **BPF_F_INDEX_MASK**.
  636. * Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
  637. * to indicate that the index of the current CPU core should be
  638. * used.
  639. *
  640. * The value to write, of *size*, is passed through eBPF stack and
  641. * pointed by *data*.
  642. *
  643. * The context of the program *ctx* needs also be passed to the
  644. * helper.
  645. *
  646. * On user space, a program willing to read the values needs to
  647. * call **perf_event_open**\ () on the perf event (either for
  648. * one or for all CPUs) and to store the file descriptor into the
  649. * *map*. This must be done before the eBPF program can send data
  650. * into it. An example is available in file
  651. * *samples/bpf/trace_output_user.c* in the Linux kernel source
  652. * tree (the eBPF program counterpart is in
  653. * *samples/bpf/trace_output_kern.c*).
  654. *
  655. * **bpf_perf_event_output**\ () achieves better performance
  656. * than **bpf_trace_printk**\ () for sharing data with user
  657. * space, and is much better suitable for streaming data from eBPF
  658. * programs.
  659. *
  660. * Note that this helper is not restricted to tracing use cases
  661. * and can be used with programs attached to TC or XDP as well,
  662. * where it allows for passing data to user space listeners. Data
  663. * can be:
  664. *
  665. * * Only custom structs,
  666. * * Only the packet payload, or
  667. * * A combination of both.
  668. *
  669. * Returns
  670. * 0 on success, or a negative error in case of failure.
  671. */
  672. static long (*bpf_perf_event_output)(void *ctx, void *map, __u64 flags, void *data, __u64 size) = (void *) 25;
  673. /*
  674. * bpf_skb_load_bytes
  675. *
  676. * This helper was provided as an easy way to load data from a
  677. * packet. It can be used to load *len* bytes from *offset* from
  678. * the packet associated to *skb*, into the buffer pointed by
  679. * *to*.
  680. *
  681. * Since Linux 4.7, usage of this helper has mostly been replaced
  682. * by "direct packet access", enabling packet data to be
  683. * manipulated with *skb*\ **->data** and *skb*\ **->data_end**
  684. * pointing respectively to the first byte of packet data and to
  685. * the byte after the last byte of packet data. However, it
  686. * remains useful if one wishes to read large quantities of data
  687. * at once from a packet into the eBPF stack.
  688. *
  689. * Returns
  690. * 0 on success, or a negative error in case of failure.
  691. */
  692. static long (*bpf_skb_load_bytes)(const void *skb, __u32 offset, void *to, __u32 len) = (void *) 26;
  693. /*
  694. * bpf_get_stackid
  695. *
  696. * Walk a user or a kernel stack and return its id. To achieve
  697. * this, the helper needs *ctx*, which is a pointer to the context
  698. * on which the tracing program is executed, and a pointer to a
  699. * *map* of type **BPF_MAP_TYPE_STACK_TRACE**.
  700. *
  701. * The last argument, *flags*, holds the number of stack frames to
  702. * skip (from 0 to 255), masked with
  703. * **BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
  704. * a combination of the following flags:
  705. *
  706. * **BPF_F_USER_STACK**
  707. * Collect a user space stack instead of a kernel stack.
  708. * **BPF_F_FAST_STACK_CMP**
  709. * Compare stacks by hash only.
  710. * **BPF_F_REUSE_STACKID**
  711. * If two different stacks hash into the same *stackid*,
  712. * discard the old one.
  713. *
  714. * The stack id retrieved is a 32 bit long integer handle which
  715. * can be further combined with other data (including other stack
  716. * ids) and used as a key into maps. This can be useful for
  717. * generating a variety of graphs (such as flame graphs or off-cpu
  718. * graphs).
  719. *
  720. * For walking a stack, this helper is an improvement over
  721. * **bpf_probe_read**\ (), which can be used with unrolled loops
  722. * but is not efficient and consumes a lot of eBPF instructions.
  723. * Instead, **bpf_get_stackid**\ () can collect up to
  724. * **PERF_MAX_STACK_DEPTH** both kernel and user frames. Note that
  725. * this limit can be controlled with the **sysctl** program, and
  726. * that it should be manually increased in order to profile long
  727. * user stacks (such as stacks for Java programs). To do so, use:
  728. *
  729. * ::
  730. *
  731. * # sysctl kernel.perf_event_max_stack=<new value>
  732. *
  733. * Returns
  734. * The positive or null stack id on success, or a negative error
  735. * in case of failure.
  736. */
  737. static long (*bpf_get_stackid)(void *ctx, void *map, __u64 flags) = (void *) 27;
  738. /*
  739. * bpf_csum_diff
  740. *
  741. * Compute a checksum difference, from the raw buffer pointed by
  742. * *from*, of length *from_size* (that must be a multiple of 4),
  743. * towards the raw buffer pointed by *to*, of size *to_size*
  744. * (same remark). An optional *seed* can be added to the value
  745. * (this can be cascaded, the seed may come from a previous call
  746. * to the helper).
  747. *
  748. * This is flexible enough to be used in several ways:
  749. *
  750. * * With *from_size* == 0, *to_size* > 0 and *seed* set to
  751. * checksum, it can be used when pushing new data.
  752. * * With *from_size* > 0, *to_size* == 0 and *seed* set to
  753. * checksum, it can be used when removing data from a packet.
  754. * * With *from_size* > 0, *to_size* > 0 and *seed* set to 0, it
  755. * can be used to compute a diff. Note that *from_size* and
  756. * *to_size* do not need to be equal.
  757. *
  758. * This helper can be used in combination with
  759. * **bpf_l3_csum_replace**\ () and **bpf_l4_csum_replace**\ (), to
  760. * which one can feed in the difference computed with
  761. * **bpf_csum_diff**\ ().
  762. *
  763. * Returns
  764. * The checksum result, or a negative error code in case of
  765. * failure.
  766. */
  767. static __s64 (*bpf_csum_diff)(__be32 *from, __u32 from_size, __be32 *to, __u32 to_size, __wsum seed) = (void *) 28;
  768. /*
  769. * bpf_skb_get_tunnel_opt
  770. *
  771. * Retrieve tunnel options metadata for the packet associated to
  772. * *skb*, and store the raw tunnel option data to the buffer *opt*
  773. * of *size*.
  774. *
  775. * This helper can be used with encapsulation devices that can
  776. * operate in "collect metadata" mode (please refer to the related
  777. * note in the description of **bpf_skb_get_tunnel_key**\ () for
  778. * more details). A particular example where this can be used is
  779. * in combination with the Geneve encapsulation protocol, where it
  780. * allows for pushing (with **bpf_skb_get_tunnel_opt**\ () helper)
  781. * and retrieving arbitrary TLVs (Type-Length-Value headers) from
  782. * the eBPF program. This allows for full customization of these
  783. * headers.
  784. *
  785. * Returns
  786. * The size of the option data retrieved.
  787. */
  788. static long (*bpf_skb_get_tunnel_opt)(struct __sk_buff *skb, void *opt, __u32 size) = (void *) 29;
  789. /*
  790. * bpf_skb_set_tunnel_opt
  791. *
  792. * Set tunnel options metadata for the packet associated to *skb*
  793. * to the option data contained in the raw buffer *opt* of *size*.
  794. *
  795. * See also the description of the **bpf_skb_get_tunnel_opt**\ ()
  796. * helper for additional information.
  797. *
  798. * Returns
  799. * 0 on success, or a negative error in case of failure.
  800. */
  801. static long (*bpf_skb_set_tunnel_opt)(struct __sk_buff *skb, void *opt, __u32 size) = (void *) 30;
  802. /*
  803. * bpf_skb_change_proto
  804. *
  805. * Change the protocol of the *skb* to *proto*. Currently
  806. * supported are transition from IPv4 to IPv6, and from IPv6 to
  807. * IPv4. The helper takes care of the groundwork for the
  808. * transition, including resizing the socket buffer. The eBPF
  809. * program is expected to fill the new headers, if any, via
  810. * **skb_store_bytes**\ () and to recompute the checksums with
  811. * **bpf_l3_csum_replace**\ () and **bpf_l4_csum_replace**\
  812. * (). The main case for this helper is to perform NAT64
  813. * operations out of an eBPF program.
  814. *
  815. * Internally, the GSO type is marked as dodgy so that headers are
  816. * checked and segments are recalculated by the GSO/GRO engine.
  817. * The size for GSO target is adapted as well.
  818. *
  819. * All values for *flags* are reserved for future usage, and must
  820. * be left at zero.
  821. *
  822. * A call to this helper is susceptible to change the underlying
  823. * packet buffer. Therefore, at load time, all checks on pointers
  824. * previously done by the verifier are invalidated and must be
  825. * performed again, if the helper is used in combination with
  826. * direct packet access.
  827. *
  828. * Returns
  829. * 0 on success, or a negative error in case of failure.
  830. */
  831. static long (*bpf_skb_change_proto)(struct __sk_buff *skb, __be16 proto, __u64 flags) = (void *) 31;
  832. /*
  833. * bpf_skb_change_type
  834. *
  835. * Change the packet type for the packet associated to *skb*. This
  836. * comes down to setting *skb*\ **->pkt_type** to *type*, except
  837. * the eBPF program does not have a write access to *skb*\
  838. * **->pkt_type** beside this helper. Using a helper here allows
  839. * for graceful handling of errors.
  840. *
  841. * The major use case is to change incoming *skb*s to
  842. * **PACKET_HOST** in a programmatic way instead of having to
  843. * recirculate via **redirect**\ (..., **BPF_F_INGRESS**), for
  844. * example.
  845. *
  846. * Note that *type* only allows certain values. At this time, they
  847. * are:
  848. *
  849. * **PACKET_HOST**
  850. * Packet is for us.
  851. * **PACKET_BROADCAST**
  852. * Send packet to all.
  853. * **PACKET_MULTICAST**
  854. * Send packet to group.
  855. * **PACKET_OTHERHOST**
  856. * Send packet to someone else.
  857. *
  858. * Returns
  859. * 0 on success, or a negative error in case of failure.
  860. */
  861. static long (*bpf_skb_change_type)(struct __sk_buff *skb, __u32 type) = (void *) 32;
  862. /*
  863. * bpf_skb_under_cgroup
  864. *
  865. * Check whether *skb* is a descendant of the cgroup2 held by
  866. * *map* of type **BPF_MAP_TYPE_CGROUP_ARRAY**, at *index*.
  867. *
  868. * Returns
  869. * The return value depends on the result of the test, and can be:
  870. *
  871. * * 0, if the *skb* failed the cgroup2 descendant test.
  872. * * 1, if the *skb* succeeded the cgroup2 descendant test.
  873. * * A negative error code, if an error occurred.
  874. */
  875. static long (*bpf_skb_under_cgroup)(struct __sk_buff *skb, void *map, __u32 index) = (void *) 33;
  876. /*
  877. * bpf_get_hash_recalc
  878. *
  879. * Retrieve the hash of the packet, *skb*\ **->hash**. If it is
  880. * not set, in particular if the hash was cleared due to mangling,
  881. * recompute this hash. Later accesses to the hash can be done
  882. * directly with *skb*\ **->hash**.
  883. *
  884. * Calling **bpf_set_hash_invalid**\ (), changing a packet
  885. * prototype with **bpf_skb_change_proto**\ (), or calling
  886. * **bpf_skb_store_bytes**\ () with the
  887. * **BPF_F_INVALIDATE_HASH** are actions susceptible to clear
  888. * the hash and to trigger a new computation for the next call to
  889. * **bpf_get_hash_recalc**\ ().
  890. *
  891. * Returns
  892. * The 32-bit hash.
  893. */
  894. static __u32 (*bpf_get_hash_recalc)(struct __sk_buff *skb) = (void *) 34;
  895. /*
  896. * bpf_get_current_task
  897. *
  898. * Get the current task.
  899. *
  900. * Returns
  901. * A pointer to the current task struct.
  902. */
  903. static __u64 (*bpf_get_current_task)(void) = (void *) 35;
  904. /*
  905. * bpf_probe_write_user
  906. *
  907. * Attempt in a safe way to write *len* bytes from the buffer
  908. * *src* to *dst* in memory. It only works for threads that are in
  909. * user context, and *dst* must be a valid user space address.
  910. *
  911. * This helper should not be used to implement any kind of
  912. * security mechanism because of TOC-TOU attacks, but rather to
  913. * debug, divert, and manipulate execution of semi-cooperative
  914. * processes.
  915. *
  916. * Keep in mind that this feature is meant for experiments, and it
  917. * has a risk of crashing the system and running programs.
  918. * Therefore, when an eBPF program using this helper is attached,
  919. * a warning including PID and process name is printed to kernel
  920. * logs.
  921. *
  922. * Returns
  923. * 0 on success, or a negative error in case of failure.
  924. */
  925. static long (*bpf_probe_write_user)(void *dst, const void *src, __u32 len) = (void *) 36;
  926. /*
  927. * bpf_current_task_under_cgroup
  928. *
  929. * Check whether the probe is being run is the context of a given
  930. * subset of the cgroup2 hierarchy. The cgroup2 to test is held by
  931. * *map* of type **BPF_MAP_TYPE_CGROUP_ARRAY**, at *index*.
  932. *
  933. * Returns
  934. * The return value depends on the result of the test, and can be:
  935. *
  936. * * 1, if current task belongs to the cgroup2.
  937. * * 0, if current task does not belong to the cgroup2.
  938. * * A negative error code, if an error occurred.
  939. */
  940. static long (*bpf_current_task_under_cgroup)(void *map, __u32 index) = (void *) 37;
  941. /*
  942. * bpf_skb_change_tail
  943. *
  944. * Resize (trim or grow) the packet associated to *skb* to the
  945. * new *len*. The *flags* are reserved for future usage, and must
  946. * be left at zero.
  947. *
  948. * The basic idea is that the helper performs the needed work to
  949. * change the size of the packet, then the eBPF program rewrites
  950. * the rest via helpers like **bpf_skb_store_bytes**\ (),
  951. * **bpf_l3_csum_replace**\ (), **bpf_l3_csum_replace**\ ()
  952. * and others. This helper is a slow path utility intended for
  953. * replies with control messages. And because it is targeted for
  954. * slow path, the helper itself can afford to be slow: it
  955. * implicitly linearizes, unclones and drops offloads from the
  956. * *skb*.
  957. *
  958. * A call to this helper is susceptible to change the underlying
  959. * packet buffer. Therefore, at load time, all checks on pointers
  960. * previously done by the verifier are invalidated and must be
  961. * performed again, if the helper is used in combination with
  962. * direct packet access.
  963. *
  964. * Returns
  965. * 0 on success, or a negative error in case of failure.
  966. */
  967. static long (*bpf_skb_change_tail)(struct __sk_buff *skb, __u32 len, __u64 flags) = (void *) 38;
  968. /*
  969. * bpf_skb_pull_data
  970. *
  971. * Pull in non-linear data in case the *skb* is non-linear and not
  972. * all of *len* are part of the linear section. Make *len* bytes
  973. * from *skb* readable and writable. If a zero value is passed for
  974. * *len*, then all bytes in the linear part of *skb* will be made
  975. * readable and writable.
  976. *
  977. * This helper is only needed for reading and writing with direct
  978. * packet access.
  979. *
  980. * For direct packet access, testing that offsets to access
  981. * are within packet boundaries (test on *skb*\ **->data_end**) is
  982. * susceptible to fail if offsets are invalid, or if the requested
  983. * data is in non-linear parts of the *skb*. On failure the
  984. * program can just bail out, or in the case of a non-linear
  985. * buffer, use a helper to make the data available. The
  986. * **bpf_skb_load_bytes**\ () helper is a first solution to access
  987. * the data. Another one consists in using **bpf_skb_pull_data**
  988. * to pull in once the non-linear parts, then retesting and
  989. * eventually access the data.
  990. *
  991. * At the same time, this also makes sure the *skb* is uncloned,
  992. * which is a necessary condition for direct write. As this needs
  993. * to be an invariant for the write part only, the verifier
  994. * detects writes and adds a prologue that is calling
  995. * **bpf_skb_pull_data()** to effectively unclone the *skb* from
  996. * the very beginning in case it is indeed cloned.
  997. *
  998. * A call to this helper is susceptible to change the underlying
  999. * packet buffer. Therefore, at load time, all checks on pointers
  1000. * previously done by the verifier are invalidated and must be
  1001. * performed again, if the helper is used in combination with
  1002. * direct packet access.
  1003. *
  1004. * Returns
  1005. * 0 on success, or a negative error in case of failure.
  1006. */
  1007. static long (*bpf_skb_pull_data)(struct __sk_buff *skb, __u32 len) = (void *) 39;
  1008. /*
  1009. * bpf_csum_update
  1010. *
  1011. * Add the checksum *csum* into *skb*\ **->csum** in case the
  1012. * driver has supplied a checksum for the entire packet into that
  1013. * field. Return an error otherwise. This helper is intended to be
  1014. * used in combination with **bpf_csum_diff**\ (), in particular
  1015. * when the checksum needs to be updated after data has been
  1016. * written into the packet through direct packet access.
  1017. *
  1018. * Returns
  1019. * The checksum on success, or a negative error code in case of
  1020. * failure.
  1021. */
  1022. static __s64 (*bpf_csum_update)(struct __sk_buff *skb, __wsum csum) = (void *) 40;
  1023. /*
  1024. * bpf_set_hash_invalid
  1025. *
  1026. * Invalidate the current *skb*\ **->hash**. It can be used after
  1027. * mangling on headers through direct packet access, in order to
  1028. * indicate that the hash is outdated and to trigger a
  1029. * recalculation the next time the kernel tries to access this
  1030. * hash or when the **bpf_get_hash_recalc**\ () helper is called.
  1031. *
  1032. * Returns
  1033. * void.
  1034. */
  1035. static void (*bpf_set_hash_invalid)(struct __sk_buff *skb) = (void *) 41;
  1036. /*
  1037. * bpf_get_numa_node_id
  1038. *
  1039. * Return the id of the current NUMA node. The primary use case
  1040. * for this helper is the selection of sockets for the local NUMA
  1041. * node, when the program is attached to sockets using the
  1042. * **SO_ATTACH_REUSEPORT_EBPF** option (see also **socket(7)**),
  1043. * but the helper is also available to other eBPF program types,
  1044. * similarly to **bpf_get_smp_processor_id**\ ().
  1045. *
  1046. * Returns
  1047. * The id of current NUMA node.
  1048. */
  1049. static long (*bpf_get_numa_node_id)(void) = (void *) 42;
  1050. /*
  1051. * bpf_skb_change_head
  1052. *
  1053. * Grows headroom of packet associated to *skb* and adjusts the
  1054. * offset of the MAC header accordingly, adding *len* bytes of
  1055. * space. It automatically extends and reallocates memory as
  1056. * required.
  1057. *
  1058. * This helper can be used on a layer 3 *skb* to push a MAC header
  1059. * for redirection into a layer 2 device.
  1060. *
  1061. * All values for *flags* are reserved for future usage, and must
  1062. * be left at zero.
  1063. *
  1064. * A call to this helper is susceptible to change the underlying
  1065. * packet buffer. Therefore, at load time, all checks on pointers
  1066. * previously done by the verifier are invalidated and must be
  1067. * performed again, if the helper is used in combination with
  1068. * direct packet access.
  1069. *
  1070. * Returns
  1071. * 0 on success, or a negative error in case of failure.
  1072. */
  1073. static long (*bpf_skb_change_head)(struct __sk_buff *skb, __u32 len, __u64 flags) = (void *) 43;
  1074. /*
  1075. * bpf_xdp_adjust_head
  1076. *
  1077. * Adjust (move) *xdp_md*\ **->data** by *delta* bytes. Note that
  1078. * it is possible to use a negative value for *delta*. This helper
  1079. * can be used to prepare the packet for pushing or popping
  1080. * headers.
  1081. *
  1082. * A call to this helper is susceptible to change the underlying
  1083. * packet buffer. Therefore, at load time, all checks on pointers
  1084. * previously done by the verifier are invalidated and must be
  1085. * performed again, if the helper is used in combination with
  1086. * direct packet access.
  1087. *
  1088. * Returns
  1089. * 0 on success, or a negative error in case of failure.
  1090. */
  1091. static long (*bpf_xdp_adjust_head)(struct xdp_md *xdp_md, int delta) = (void *) 44;
  1092. /*
  1093. * bpf_probe_read_str
  1094. *
  1095. * Copy a NUL terminated string from an unsafe kernel address
  1096. * *unsafe_ptr* to *dst*. See **bpf_probe_read_kernel_str**\ () for
  1097. * more details.
  1098. *
  1099. * Generally, use **bpf_probe_read_user_str**\ () or
  1100. * **bpf_probe_read_kernel_str**\ () instead.
  1101. *
  1102. * Returns
  1103. * On success, the strictly positive length of the string,
  1104. * including the trailing NUL character. On error, a negative
  1105. * value.
  1106. */
  1107. static long (*bpf_probe_read_str)(void *dst, __u32 size, const void *unsafe_ptr) = (void *) 45;
  1108. /*
  1109. * bpf_get_socket_cookie
  1110. *
  1111. * If the **struct sk_buff** pointed by *skb* has a known socket,
  1112. * retrieve the cookie (generated by the kernel) of this socket.
  1113. * If no cookie has been set yet, generate a new cookie. Once
  1114. * generated, the socket cookie remains stable for the life of the
  1115. * socket. This helper can be useful for monitoring per socket
  1116. * networking traffic statistics as it provides a global socket
  1117. * identifier that can be assumed unique.
  1118. *
  1119. * Returns
  1120. * A 8-byte long unique number on success, or 0 if the socket
  1121. * field is missing inside *skb*.
  1122. */
  1123. static __u64 (*bpf_get_socket_cookie)(void *ctx) = (void *) 46;
  1124. /*
  1125. * bpf_get_socket_uid
  1126. *
  1127. * Get the owner UID of the socked associated to *skb*.
  1128. *
  1129. * Returns
  1130. * The owner UID of the socket associated to *skb*. If the socket
  1131. * is **NULL**, or if it is not a full socket (i.e. if it is a
  1132. * time-wait or a request socket instead), **overflowuid** value
  1133. * is returned (note that **overflowuid** might also be the actual
  1134. * UID value for the socket).
  1135. */
  1136. static __u32 (*bpf_get_socket_uid)(struct __sk_buff *skb) = (void *) 47;
  1137. /*
  1138. * bpf_set_hash
  1139. *
  1140. * Set the full hash for *skb* (set the field *skb*\ **->hash**)
  1141. * to value *hash*.
  1142. *
  1143. * Returns
  1144. * 0
  1145. */
  1146. static long (*bpf_set_hash)(struct __sk_buff *skb, __u32 hash) = (void *) 48;
  1147. /*
  1148. * bpf_setsockopt
  1149. *
  1150. * Emulate a call to **setsockopt()** on the socket associated to
  1151. * *bpf_socket*, which must be a full socket. The *level* at
  1152. * which the option resides and the name *optname* of the option
  1153. * must be specified, see **setsockopt(2)** for more information.
  1154. * The option value of length *optlen* is pointed by *optval*.
  1155. *
  1156. * *bpf_socket* should be one of the following:
  1157. *
  1158. * * **struct bpf_sock_ops** for **BPF_PROG_TYPE_SOCK_OPS**.
  1159. * * **struct bpf_sock_addr** for **BPF_CGROUP_INET4_CONNECT**,
  1160. * **BPF_CGROUP_INET6_CONNECT** and **BPF_CGROUP_UNIX_CONNECT**.
  1161. *
  1162. * This helper actually implements a subset of **setsockopt()**.
  1163. * It supports the following *level*\ s:
  1164. *
  1165. * * **SOL_SOCKET**, which supports the following *optname*\ s:
  1166. * **SO_RCVBUF**, **SO_SNDBUF**, **SO_MAX_PACING_RATE**,
  1167. * **SO_PRIORITY**, **SO_RCVLOWAT**, **SO_MARK**,
  1168. * **SO_BINDTODEVICE**, **SO_KEEPALIVE**, **SO_REUSEADDR**,
  1169. * **SO_REUSEPORT**, **SO_BINDTOIFINDEX**, **SO_TXREHASH**.
  1170. * * **IPPROTO_TCP**, which supports the following *optname*\ s:
  1171. * **TCP_CONGESTION**, **TCP_BPF_IW**,
  1172. * **TCP_BPF_SNDCWND_CLAMP**, **TCP_SAVE_SYN**,
  1173. * **TCP_KEEPIDLE**, **TCP_KEEPINTVL**, **TCP_KEEPCNT**,
  1174. * **TCP_SYNCNT**, **TCP_USER_TIMEOUT**, **TCP_NOTSENT_LOWAT**,
  1175. * **TCP_NODELAY**, **TCP_MAXSEG**, **TCP_WINDOW_CLAMP**,
  1176. * **TCP_THIN_LINEAR_TIMEOUTS**, **TCP_BPF_DELACK_MAX**,
  1177. * **TCP_BPF_RTO_MIN**.
  1178. * * **IPPROTO_IP**, which supports *optname* **IP_TOS**.
  1179. * * **IPPROTO_IPV6**, which supports the following *optname*\ s:
  1180. * **IPV6_TCLASS**, **IPV6_AUTOFLOWLABEL**.
  1181. *
  1182. * Returns
  1183. * 0 on success, or a negative error in case of failure.
  1184. */
  1185. static long (*bpf_setsockopt)(void *bpf_socket, int level, int optname, void *optval, int optlen) = (void *) 49;
  1186. /*
  1187. * bpf_skb_adjust_room
  1188. *
  1189. * Grow or shrink the room for data in the packet associated to
  1190. * *skb* by *len_diff*, and according to the selected *mode*.
  1191. *
  1192. * By default, the helper will reset any offloaded checksum
  1193. * indicator of the skb to CHECKSUM_NONE. This can be avoided
  1194. * by the following flag:
  1195. *
  1196. * * **BPF_F_ADJ_ROOM_NO_CSUM_RESET**: Do not reset offloaded
  1197. * checksum data of the skb to CHECKSUM_NONE.
  1198. *
  1199. * There are two supported modes at this time:
  1200. *
  1201. * * **BPF_ADJ_ROOM_MAC**: Adjust room at the mac layer
  1202. * (room space is added or removed between the layer 2 and
  1203. * layer 3 headers).
  1204. *
  1205. * * **BPF_ADJ_ROOM_NET**: Adjust room at the network layer
  1206. * (room space is added or removed between the layer 3 and
  1207. * layer 4 headers).
  1208. *
  1209. * The following flags are supported at this time:
  1210. *
  1211. * * **BPF_F_ADJ_ROOM_FIXED_GSO**: Do not adjust gso_size.
  1212. * Adjusting mss in this way is not allowed for datagrams.
  1213. *
  1214. * * **BPF_F_ADJ_ROOM_ENCAP_L3_IPV4**,
  1215. * **BPF_F_ADJ_ROOM_ENCAP_L3_IPV6**:
  1216. * Any new space is reserved to hold a tunnel header.
  1217. * Configure skb offsets and other fields accordingly.
  1218. *
  1219. * * **BPF_F_ADJ_ROOM_ENCAP_L4_GRE**,
  1220. * **BPF_F_ADJ_ROOM_ENCAP_L4_UDP**:
  1221. * Use with ENCAP_L3 flags to further specify the tunnel type.
  1222. *
  1223. * * **BPF_F_ADJ_ROOM_ENCAP_L2**\ (*len*):
  1224. * Use with ENCAP_L3/L4 flags to further specify the tunnel
  1225. * type; *len* is the length of the inner MAC header.
  1226. *
  1227. * * **BPF_F_ADJ_ROOM_ENCAP_L2_ETH**:
  1228. * Use with BPF_F_ADJ_ROOM_ENCAP_L2 flag to further specify the
  1229. * L2 type as Ethernet.
  1230. *
  1231. * * **BPF_F_ADJ_ROOM_DECAP_L3_IPV4**,
  1232. * **BPF_F_ADJ_ROOM_DECAP_L3_IPV6**:
  1233. * Indicate the new IP header version after decapsulating the outer
  1234. * IP header. Used when the inner and outer IP versions are different.
  1235. *
  1236. * A call to this helper is susceptible to change the underlying
  1237. * packet buffer. Therefore, at load time, all checks on pointers
  1238. * previously done by the verifier are invalidated and must be
  1239. * performed again, if the helper is used in combination with
  1240. * direct packet access.
  1241. *
  1242. * Returns
  1243. * 0 on success, or a negative error in case of failure.
  1244. */
  1245. static long (*bpf_skb_adjust_room)(struct __sk_buff *skb, __s32 len_diff, __u32 mode, __u64 flags) = (void *) 50;
  1246. /*
  1247. * bpf_redirect_map
  1248. *
  1249. * Redirect the packet to the endpoint referenced by *map* at
  1250. * index *key*. Depending on its type, this *map* can contain
  1251. * references to net devices (for forwarding packets through other
  1252. * ports), or to CPUs (for redirecting XDP frames to another CPU;
  1253. * but this is only implemented for native XDP (with driver
  1254. * support) as of this writing).
  1255. *
  1256. * The lower two bits of *flags* are used as the return code if
  1257. * the map lookup fails. This is so that the return value can be
  1258. * one of the XDP program return codes up to **XDP_TX**, as chosen
  1259. * by the caller. The higher bits of *flags* can be set to
  1260. * BPF_F_BROADCAST or BPF_F_EXCLUDE_INGRESS as defined below.
  1261. *
  1262. * With BPF_F_BROADCAST the packet will be broadcasted to all the
  1263. * interfaces in the map, with BPF_F_EXCLUDE_INGRESS the ingress
  1264. * interface will be excluded when do broadcasting.
  1265. *
  1266. * See also **bpf_redirect**\ (), which only supports redirecting
  1267. * to an ifindex, but doesn't require a map to do so.
  1268. *
  1269. * Returns
  1270. * **XDP_REDIRECT** on success, or the value of the two lower bits
  1271. * of the *flags* argument on error.
  1272. */
  1273. static long (*bpf_redirect_map)(void *map, __u64 key, __u64 flags) = (void *) 51;
  1274. /*
  1275. * bpf_sk_redirect_map
  1276. *
  1277. * Redirect the packet to the socket referenced by *map* (of type
  1278. * **BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and
  1279. * egress interfaces can be used for redirection. The
  1280. * **BPF_F_INGRESS** value in *flags* is used to make the
  1281. * distinction (ingress path is selected if the flag is present,
  1282. * egress path otherwise). This is the only flag supported for now.
  1283. *
  1284. * Returns
  1285. * **SK_PASS** on success, or **SK_DROP** on error.
  1286. */
  1287. static long (*bpf_sk_redirect_map)(struct __sk_buff *skb, void *map, __u32 key, __u64 flags) = (void *) 52;
  1288. /*
  1289. * bpf_sock_map_update
  1290. *
  1291. * Add an entry to, or update a *map* referencing sockets. The
  1292. * *skops* is used as a new value for the entry associated to
  1293. * *key*. *flags* is one of:
  1294. *
  1295. * **BPF_NOEXIST**
  1296. * The entry for *key* must not exist in the map.
  1297. * **BPF_EXIST**
  1298. * The entry for *key* must already exist in the map.
  1299. * **BPF_ANY**
  1300. * No condition on the existence of the entry for *key*.
  1301. *
  1302. * If the *map* has eBPF programs (parser and verdict), those will
  1303. * be inherited by the socket being added. If the socket is
  1304. * already attached to eBPF programs, this results in an error.
  1305. *
  1306. * Returns
  1307. * 0 on success, or a negative error in case of failure.
  1308. */
  1309. static long (*bpf_sock_map_update)(struct bpf_sock_ops *skops, void *map, void *key, __u64 flags) = (void *) 53;
  1310. /*
  1311. * bpf_xdp_adjust_meta
  1312. *
  1313. * Adjust the address pointed by *xdp_md*\ **->data_meta** by
  1314. * *delta* (which can be positive or negative). Note that this
  1315. * operation modifies the address stored in *xdp_md*\ **->data**,
  1316. * so the latter must be loaded only after the helper has been
  1317. * called.
  1318. *
  1319. * The use of *xdp_md*\ **->data_meta** is optional and programs
  1320. * are not required to use it. The rationale is that when the
  1321. * packet is processed with XDP (e.g. as DoS filter), it is
  1322. * possible to push further meta data along with it before passing
  1323. * to the stack, and to give the guarantee that an ingress eBPF
  1324. * program attached as a TC classifier on the same device can pick
  1325. * this up for further post-processing. Since TC works with socket
  1326. * buffers, it remains possible to set from XDP the **mark** or
  1327. * **priority** pointers, or other pointers for the socket buffer.
  1328. * Having this scratch space generic and programmable allows for
  1329. * more flexibility as the user is free to store whatever meta
  1330. * data they need.
  1331. *
  1332. * A call to this helper is susceptible to change the underlying
  1333. * packet buffer. Therefore, at load time, all checks on pointers
  1334. * previously done by the verifier are invalidated and must be
  1335. * performed again, if the helper is used in combination with
  1336. * direct packet access.
  1337. *
  1338. * Returns
  1339. * 0 on success, or a negative error in case of failure.
  1340. */
  1341. static long (*bpf_xdp_adjust_meta)(struct xdp_md *xdp_md, int delta) = (void *) 54;
  1342. /*
  1343. * bpf_perf_event_read_value
  1344. *
  1345. * Read the value of a perf event counter, and store it into *buf*
  1346. * of size *buf_size*. This helper relies on a *map* of type
  1347. * **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. The nature of the perf event
  1348. * counter is selected when *map* is updated with perf event file
  1349. * descriptors. The *map* is an array whose size is the number of
  1350. * available CPUs, and each cell contains a value relative to one
  1351. * CPU. The value to retrieve is indicated by *flags*, that
  1352. * contains the index of the CPU to look up, masked with
  1353. * **BPF_F_INDEX_MASK**. Alternatively, *flags* can be set to
  1354. * **BPF_F_CURRENT_CPU** to indicate that the value for the
  1355. * current CPU should be retrieved.
  1356. *
  1357. * This helper behaves in a way close to
  1358. * **bpf_perf_event_read**\ () helper, save that instead of
  1359. * just returning the value observed, it fills the *buf*
  1360. * structure. This allows for additional data to be retrieved: in
  1361. * particular, the enabled and running times (in *buf*\
  1362. * **->enabled** and *buf*\ **->running**, respectively) are
  1363. * copied. In general, **bpf_perf_event_read_value**\ () is
  1364. * recommended over **bpf_perf_event_read**\ (), which has some
  1365. * ABI issues and provides fewer functionalities.
  1366. *
  1367. * These values are interesting, because hardware PMU (Performance
  1368. * Monitoring Unit) counters are limited resources. When there are
  1369. * more PMU based perf events opened than available counters,
  1370. * kernel will multiplex these events so each event gets certain
  1371. * percentage (but not all) of the PMU time. In case that
  1372. * multiplexing happens, the number of samples or counter value
  1373. * will not reflect the case compared to when no multiplexing
  1374. * occurs. This makes comparison between different runs difficult.
  1375. * Typically, the counter value should be normalized before
  1376. * comparing to other experiments. The usual normalization is done
  1377. * as follows.
  1378. *
  1379. * ::
  1380. *
  1381. * normalized_counter = counter * t_enabled / t_running
  1382. *
  1383. * Where t_enabled is the time enabled for event and t_running is
  1384. * the time running for event since last normalization. The
  1385. * enabled and running times are accumulated since the perf event
  1386. * open. To achieve scaling factor between two invocations of an
  1387. * eBPF program, users can use CPU id as the key (which is
  1388. * typical for perf array usage model) to remember the previous
  1389. * value and do the calculation inside the eBPF program.
  1390. *
  1391. * Returns
  1392. * 0 on success, or a negative error in case of failure.
  1393. */
  1394. static long (*bpf_perf_event_read_value)(void *map, __u64 flags, struct bpf_perf_event_value *buf, __u32 buf_size) = (void *) 55;
  1395. /*
  1396. * bpf_perf_prog_read_value
  1397. *
  1398. * For an eBPF program attached to a perf event, retrieve the
  1399. * value of the event counter associated to *ctx* and store it in
  1400. * the structure pointed by *buf* and of size *buf_size*. Enabled
  1401. * and running times are also stored in the structure (see
  1402. * description of helper **bpf_perf_event_read_value**\ () for
  1403. * more details).
  1404. *
  1405. * Returns
  1406. * 0 on success, or a negative error in case of failure.
  1407. */
  1408. static long (*bpf_perf_prog_read_value)(struct bpf_perf_event_data *ctx, struct bpf_perf_event_value *buf, __u32 buf_size) = (void *) 56;
  1409. /*
  1410. * bpf_getsockopt
  1411. *
  1412. * Emulate a call to **getsockopt()** on the socket associated to
  1413. * *bpf_socket*, which must be a full socket. The *level* at
  1414. * which the option resides and the name *optname* of the option
  1415. * must be specified, see **getsockopt(2)** for more information.
  1416. * The retrieved value is stored in the structure pointed by
  1417. * *opval* and of length *optlen*.
  1418. *
  1419. * *bpf_socket* should be one of the following:
  1420. *
  1421. * * **struct bpf_sock_ops** for **BPF_PROG_TYPE_SOCK_OPS**.
  1422. * * **struct bpf_sock_addr** for **BPF_CGROUP_INET4_CONNECT**,
  1423. * **BPF_CGROUP_INET6_CONNECT** and **BPF_CGROUP_UNIX_CONNECT**.
  1424. *
  1425. * This helper actually implements a subset of **getsockopt()**.
  1426. * It supports the same set of *optname*\ s that is supported by
  1427. * the **bpf_setsockopt**\ () helper. The exceptions are
  1428. * **TCP_BPF_*** is **bpf_setsockopt**\ () only and
  1429. * **TCP_SAVED_SYN** is **bpf_getsockopt**\ () only.
  1430. *
  1431. * Returns
  1432. * 0 on success, or a negative error in case of failure.
  1433. */
  1434. static long (*bpf_getsockopt)(void *bpf_socket, int level, int optname, void *optval, int optlen) = (void *) 57;
  1435. /*
  1436. * bpf_override_return
  1437. *
  1438. * Used for error injection, this helper uses kprobes to override
  1439. * the return value of the probed function, and to set it to *rc*.
  1440. * The first argument is the context *regs* on which the kprobe
  1441. * works.
  1442. *
  1443. * This helper works by setting the PC (program counter)
  1444. * to an override function which is run in place of the original
  1445. * probed function. This means the probed function is not run at
  1446. * all. The replacement function just returns with the required
  1447. * value.
  1448. *
  1449. * This helper has security implications, and thus is subject to
  1450. * restrictions. It is only available if the kernel was compiled
  1451. * with the **CONFIG_BPF_KPROBE_OVERRIDE** configuration
  1452. * option, and in this case it only works on functions tagged with
  1453. * **ALLOW_ERROR_INJECTION** in the kernel code.
  1454. *
  1455. * Also, the helper is only available for the architectures having
  1456. * the CONFIG_FUNCTION_ERROR_INJECTION option. As of this writing,
  1457. * x86 architecture is the only one to support this feature.
  1458. *
  1459. * Returns
  1460. * 0
  1461. */
  1462. static long (*bpf_override_return)(struct pt_regs *regs, __u64 rc) = (void *) 58;
  1463. /*
  1464. * bpf_sock_ops_cb_flags_set
  1465. *
  1466. * Attempt to set the value of the **bpf_sock_ops_cb_flags** field
  1467. * for the full TCP socket associated to *bpf_sock_ops* to
  1468. * *argval*.
  1469. *
  1470. * The primary use of this field is to determine if there should
  1471. * be calls to eBPF programs of type
  1472. * **BPF_PROG_TYPE_SOCK_OPS** at various points in the TCP
  1473. * code. A program of the same type can change its value, per
  1474. * connection and as necessary, when the connection is
  1475. * established. This field is directly accessible for reading, but
  1476. * this helper must be used for updates in order to return an
  1477. * error if an eBPF program tries to set a callback that is not
  1478. * supported in the current kernel.
  1479. *
  1480. * *argval* is a flag array which can combine these flags:
  1481. *
  1482. * * **BPF_SOCK_OPS_RTO_CB_FLAG** (retransmission time out)
  1483. * * **BPF_SOCK_OPS_RETRANS_CB_FLAG** (retransmission)
  1484. * * **BPF_SOCK_OPS_STATE_CB_FLAG** (TCP state change)
  1485. * * **BPF_SOCK_OPS_RTT_CB_FLAG** (every RTT)
  1486. *
  1487. * Therefore, this function can be used to clear a callback flag by
  1488. * setting the appropriate bit to zero. e.g. to disable the RTO
  1489. * callback:
  1490. *
  1491. * **bpf_sock_ops_cb_flags_set(bpf_sock,**
  1492. * **bpf_sock->bpf_sock_ops_cb_flags & ~BPF_SOCK_OPS_RTO_CB_FLAG)**
  1493. *
  1494. * Here are some examples of where one could call such eBPF
  1495. * program:
  1496. *
  1497. * * When RTO fires.
  1498. * * When a packet is retransmitted.
  1499. * * When the connection terminates.
  1500. * * When a packet is sent.
  1501. * * When a packet is received.
  1502. *
  1503. * Returns
  1504. * Code **-EINVAL** if the socket is not a full TCP socket;
  1505. * otherwise, a positive number containing the bits that could not
  1506. * be set is returned (which comes down to 0 if all bits were set
  1507. * as required).
  1508. */
  1509. static long (*bpf_sock_ops_cb_flags_set)(struct bpf_sock_ops *bpf_sock, int argval) = (void *) 59;
  1510. /*
  1511. * bpf_msg_redirect_map
  1512. *
  1513. * This helper is used in programs implementing policies at the
  1514. * socket level. If the message *msg* is allowed to pass (i.e. if
  1515. * the verdict eBPF program returns **SK_PASS**), redirect it to
  1516. * the socket referenced by *map* (of type
  1517. * **BPF_MAP_TYPE_SOCKMAP**) at index *key*. Both ingress and
  1518. * egress interfaces can be used for redirection. The
  1519. * **BPF_F_INGRESS** value in *flags* is used to make the
  1520. * distinction (ingress path is selected if the flag is present,
  1521. * egress path otherwise). This is the only flag supported for now.
  1522. *
  1523. * Returns
  1524. * **SK_PASS** on success, or **SK_DROP** on error.
  1525. */
  1526. static long (*bpf_msg_redirect_map)(struct sk_msg_md *msg, void *map, __u32 key, __u64 flags) = (void *) 60;
  1527. /*
  1528. * bpf_msg_apply_bytes
  1529. *
  1530. * For socket policies, apply the verdict of the eBPF program to
  1531. * the next *bytes* (number of bytes) of message *msg*.
  1532. *
  1533. * For example, this helper can be used in the following cases:
  1534. *
  1535. * * A single **sendmsg**\ () or **sendfile**\ () system call
  1536. * contains multiple logical messages that the eBPF program is
  1537. * supposed to read and for which it should apply a verdict.
  1538. * * An eBPF program only cares to read the first *bytes* of a
  1539. * *msg*. If the message has a large payload, then setting up
  1540. * and calling the eBPF program repeatedly for all bytes, even
  1541. * though the verdict is already known, would create unnecessary
  1542. * overhead.
  1543. *
  1544. * When called from within an eBPF program, the helper sets a
  1545. * counter internal to the BPF infrastructure, that is used to
  1546. * apply the last verdict to the next *bytes*. If *bytes* is
  1547. * smaller than the current data being processed from a
  1548. * **sendmsg**\ () or **sendfile**\ () system call, the first
  1549. * *bytes* will be sent and the eBPF program will be re-run with
  1550. * the pointer for start of data pointing to byte number *bytes*
  1551. * **+ 1**. If *bytes* is larger than the current data being
  1552. * processed, then the eBPF verdict will be applied to multiple
  1553. * **sendmsg**\ () or **sendfile**\ () calls until *bytes* are
  1554. * consumed.
  1555. *
  1556. * Note that if a socket closes with the internal counter holding
  1557. * a non-zero value, this is not a problem because data is not
  1558. * being buffered for *bytes* and is sent as it is received.
  1559. *
  1560. * Returns
  1561. * 0
  1562. */
  1563. static long (*bpf_msg_apply_bytes)(struct sk_msg_md *msg, __u32 bytes) = (void *) 61;
  1564. /*
  1565. * bpf_msg_cork_bytes
  1566. *
  1567. * For socket policies, prevent the execution of the verdict eBPF
  1568. * program for message *msg* until *bytes* (byte number) have been
  1569. * accumulated.
  1570. *
  1571. * This can be used when one needs a specific number of bytes
  1572. * before a verdict can be assigned, even if the data spans
  1573. * multiple **sendmsg**\ () or **sendfile**\ () calls. The extreme
  1574. * case would be a user calling **sendmsg**\ () repeatedly with
  1575. * 1-byte long message segments. Obviously, this is bad for
  1576. * performance, but it is still valid. If the eBPF program needs
  1577. * *bytes* bytes to validate a header, this helper can be used to
  1578. * prevent the eBPF program to be called again until *bytes* have
  1579. * been accumulated.
  1580. *
  1581. * Returns
  1582. * 0
  1583. */
  1584. static long (*bpf_msg_cork_bytes)(struct sk_msg_md *msg, __u32 bytes) = (void *) 62;
  1585. /*
  1586. * bpf_msg_pull_data
  1587. *
  1588. * For socket policies, pull in non-linear data from user space
  1589. * for *msg* and set pointers *msg*\ **->data** and *msg*\
  1590. * **->data_end** to *start* and *end* bytes offsets into *msg*,
  1591. * respectively.
  1592. *
  1593. * If a program of type **BPF_PROG_TYPE_SK_MSG** is run on a
  1594. * *msg* it can only parse data that the (**data**, **data_end**)
  1595. * pointers have already consumed. For **sendmsg**\ () hooks this
  1596. * is likely the first scatterlist element. But for calls relying
  1597. * on the **sendpage** handler (e.g. **sendfile**\ ()) this will
  1598. * be the range (**0**, **0**) because the data is shared with
  1599. * user space and by default the objective is to avoid allowing
  1600. * user space to modify data while (or after) eBPF verdict is
  1601. * being decided. This helper can be used to pull in data and to
  1602. * set the start and end pointer to given values. Data will be
  1603. * copied if necessary (i.e. if data was not linear and if start
  1604. * and end pointers do not point to the same chunk).
  1605. *
  1606. * A call to this helper is susceptible to change the underlying
  1607. * packet buffer. Therefore, at load time, all checks on pointers
  1608. * previously done by the verifier are invalidated and must be
  1609. * performed again, if the helper is used in combination with
  1610. * direct packet access.
  1611. *
  1612. * All values for *flags* are reserved for future usage, and must
  1613. * be left at zero.
  1614. *
  1615. * Returns
  1616. * 0 on success, or a negative error in case of failure.
  1617. */
  1618. static long (*bpf_msg_pull_data)(struct sk_msg_md *msg, __u32 start, __u32 end, __u64 flags) = (void *) 63;
  1619. /*
  1620. * bpf_bind
  1621. *
  1622. * Bind the socket associated to *ctx* to the address pointed by
  1623. * *addr*, of length *addr_len*. This allows for making outgoing
  1624. * connection from the desired IP address, which can be useful for
  1625. * example when all processes inside a cgroup should use one
  1626. * single IP address on a host that has multiple IP configured.
  1627. *
  1628. * This helper works for IPv4 and IPv6, TCP and UDP sockets. The
  1629. * domain (*addr*\ **->sa_family**) must be **AF_INET** (or
  1630. * **AF_INET6**). It's advised to pass zero port (**sin_port**
  1631. * or **sin6_port**) which triggers IP_BIND_ADDRESS_NO_PORT-like
  1632. * behavior and lets the kernel efficiently pick up an unused
  1633. * port as long as 4-tuple is unique. Passing non-zero port might
  1634. * lead to degraded performance.
  1635. *
  1636. * Returns
  1637. * 0 on success, or a negative error in case of failure.
  1638. */
  1639. static long (*bpf_bind)(struct bpf_sock_addr *ctx, struct sockaddr *addr, int addr_len) = (void *) 64;
  1640. /*
  1641. * bpf_xdp_adjust_tail
  1642. *
  1643. * Adjust (move) *xdp_md*\ **->data_end** by *delta* bytes. It is
  1644. * possible to both shrink and grow the packet tail.
  1645. * Shrink done via *delta* being a negative integer.
  1646. *
  1647. * A call to this helper is susceptible to change the underlying
  1648. * packet buffer. Therefore, at load time, all checks on pointers
  1649. * previously done by the verifier are invalidated and must be
  1650. * performed again, if the helper is used in combination with
  1651. * direct packet access.
  1652. *
  1653. * Returns
  1654. * 0 on success, or a negative error in case of failure.
  1655. */
  1656. static long (*bpf_xdp_adjust_tail)(struct xdp_md *xdp_md, int delta) = (void *) 65;
  1657. /*
  1658. * bpf_skb_get_xfrm_state
  1659. *
  1660. * Retrieve the XFRM state (IP transform framework, see also
  1661. * **ip-xfrm(8)**) at *index* in XFRM "security path" for *skb*.
  1662. *
  1663. * The retrieved value is stored in the **struct bpf_xfrm_state**
  1664. * pointed by *xfrm_state* and of length *size*.
  1665. *
  1666. * All values for *flags* are reserved for future usage, and must
  1667. * be left at zero.
  1668. *
  1669. * This helper is available only if the kernel was compiled with
  1670. * **CONFIG_XFRM** configuration option.
  1671. *
  1672. * Returns
  1673. * 0 on success, or a negative error in case of failure.
  1674. */
  1675. static long (*bpf_skb_get_xfrm_state)(struct __sk_buff *skb, __u32 index, struct bpf_xfrm_state *xfrm_state, __u32 size, __u64 flags) = (void *) 66;
  1676. /*
  1677. * bpf_get_stack
  1678. *
  1679. * Return a user or a kernel stack in bpf program provided buffer.
  1680. * To achieve this, the helper needs *ctx*, which is a pointer
  1681. * to the context on which the tracing program is executed.
  1682. * To store the stacktrace, the bpf program provides *buf* with
  1683. * a nonnegative *size*.
  1684. *
  1685. * The last argument, *flags*, holds the number of stack frames to
  1686. * skip (from 0 to 255), masked with
  1687. * **BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
  1688. * the following flags:
  1689. *
  1690. * **BPF_F_USER_STACK**
  1691. * Collect a user space stack instead of a kernel stack.
  1692. * **BPF_F_USER_BUILD_ID**
  1693. * Collect (build_id, file_offset) instead of ips for user
  1694. * stack, only valid if **BPF_F_USER_STACK** is also
  1695. * specified.
  1696. *
  1697. * *file_offset* is an offset relative to the beginning
  1698. * of the executable or shared object file backing the vma
  1699. * which the *ip* falls in. It is *not* an offset relative
  1700. * to that object's base address. Accordingly, it must be
  1701. * adjusted by adding (sh_addr - sh_offset), where
  1702. * sh_{addr,offset} correspond to the executable section
  1703. * containing *file_offset* in the object, for comparisons
  1704. * to symbols' st_value to be valid.
  1705. *
  1706. * **bpf_get_stack**\ () can collect up to
  1707. * **PERF_MAX_STACK_DEPTH** both kernel and user frames, subject
  1708. * to sufficient large buffer size. Note that
  1709. * this limit can be controlled with the **sysctl** program, and
  1710. * that it should be manually increased in order to profile long
  1711. * user stacks (such as stacks for Java programs). To do so, use:
  1712. *
  1713. * ::
  1714. *
  1715. * # sysctl kernel.perf_event_max_stack=<new value>
  1716. *
  1717. * Returns
  1718. * The non-negative copied *buf* length equal to or less than
  1719. * *size* on success, or a negative error in case of failure.
  1720. */
  1721. static long (*bpf_get_stack)(void *ctx, void *buf, __u32 size, __u64 flags) = (void *) 67;
  1722. /*
  1723. * bpf_skb_load_bytes_relative
  1724. *
  1725. * This helper is similar to **bpf_skb_load_bytes**\ () in that
  1726. * it provides an easy way to load *len* bytes from *offset*
  1727. * from the packet associated to *skb*, into the buffer pointed
  1728. * by *to*. The difference to **bpf_skb_load_bytes**\ () is that
  1729. * a fifth argument *start_header* exists in order to select a
  1730. * base offset to start from. *start_header* can be one of:
  1731. *
  1732. * **BPF_HDR_START_MAC**
  1733. * Base offset to load data from is *skb*'s mac header.
  1734. * **BPF_HDR_START_NET**
  1735. * Base offset to load data from is *skb*'s network header.
  1736. *
  1737. * In general, "direct packet access" is the preferred method to
  1738. * access packet data, however, this helper is in particular useful
  1739. * in socket filters where *skb*\ **->data** does not always point
  1740. * to the start of the mac header and where "direct packet access"
  1741. * is not available.
  1742. *
  1743. * Returns
  1744. * 0 on success, or a negative error in case of failure.
  1745. */
  1746. static long (*bpf_skb_load_bytes_relative)(const void *skb, __u32 offset, void *to, __u32 len, __u32 start_header) = (void *) 68;
  1747. /*
  1748. * bpf_fib_lookup
  1749. *
  1750. * Do FIB lookup in kernel tables using parameters in *params*.
  1751. * If lookup is successful and result shows packet is to be
  1752. * forwarded, the neighbor tables are searched for the nexthop.
  1753. * If successful (ie., FIB lookup shows forwarding and nexthop
  1754. * is resolved), the nexthop address is returned in ipv4_dst
  1755. * or ipv6_dst based on family, smac is set to mac address of
  1756. * egress device, dmac is set to nexthop mac address, rt_metric
  1757. * is set to metric from route (IPv4/IPv6 only), and ifindex
  1758. * is set to the device index of the nexthop from the FIB lookup.
  1759. *
  1760. * *plen* argument is the size of the passed in struct.
  1761. * *flags* argument can be a combination of one or more of the
  1762. * following values:
  1763. *
  1764. * **BPF_FIB_LOOKUP_DIRECT**
  1765. * Do a direct table lookup vs full lookup using FIB
  1766. * rules.
  1767. * **BPF_FIB_LOOKUP_TBID**
  1768. * Used with BPF_FIB_LOOKUP_DIRECT.
  1769. * Use the routing table ID present in *params*->tbid
  1770. * for the fib lookup.
  1771. * **BPF_FIB_LOOKUP_OUTPUT**
  1772. * Perform lookup from an egress perspective (default is
  1773. * ingress).
  1774. * **BPF_FIB_LOOKUP_SKIP_NEIGH**
  1775. * Skip the neighbour table lookup. *params*->dmac
  1776. * and *params*->smac will not be set as output. A common
  1777. * use case is to call **bpf_redirect_neigh**\ () after
  1778. * doing **bpf_fib_lookup**\ ().
  1779. * **BPF_FIB_LOOKUP_SRC**
  1780. * Derive and set source IP addr in *params*->ipv{4,6}_src
  1781. * for the nexthop. If the src addr cannot be derived,
  1782. * **BPF_FIB_LKUP_RET_NO_SRC_ADDR** is returned. In this
  1783. * case, *params*->dmac and *params*->smac are not set either.
  1784. *
  1785. * *ctx* is either **struct xdp_md** for XDP programs or
  1786. * **struct sk_buff** tc cls_act programs.
  1787. *
  1788. * Returns
  1789. * * < 0 if any input argument is invalid
  1790. * * 0 on success (packet is forwarded, nexthop neighbor exists)
  1791. * * > 0 one of **BPF_FIB_LKUP_RET_** codes explaining why the
  1792. * packet is not forwarded or needs assist from full stack
  1793. *
  1794. * If lookup fails with BPF_FIB_LKUP_RET_FRAG_NEEDED, then the MTU
  1795. * was exceeded and output params->mtu_result contains the MTU.
  1796. */
  1797. static long (*bpf_fib_lookup)(void *ctx, struct bpf_fib_lookup *params, int plen, __u32 flags) = (void *) 69;
  1798. /*
  1799. * bpf_sock_hash_update
  1800. *
  1801. * Add an entry to, or update a sockhash *map* referencing sockets.
  1802. * The *skops* is used as a new value for the entry associated to
  1803. * *key*. *flags* is one of:
  1804. *
  1805. * **BPF_NOEXIST**
  1806. * The entry for *key* must not exist in the map.
  1807. * **BPF_EXIST**
  1808. * The entry for *key* must already exist in the map.
  1809. * **BPF_ANY**
  1810. * No condition on the existence of the entry for *key*.
  1811. *
  1812. * If the *map* has eBPF programs (parser and verdict), those will
  1813. * be inherited by the socket being added. If the socket is
  1814. * already attached to eBPF programs, this results in an error.
  1815. *
  1816. * Returns
  1817. * 0 on success, or a negative error in case of failure.
  1818. */
  1819. static long (*bpf_sock_hash_update)(struct bpf_sock_ops *skops, void *map, void *key, __u64 flags) = (void *) 70;
  1820. /*
  1821. * bpf_msg_redirect_hash
  1822. *
  1823. * This helper is used in programs implementing policies at the
  1824. * socket level. If the message *msg* is allowed to pass (i.e. if
  1825. * the verdict eBPF program returns **SK_PASS**), redirect it to
  1826. * the socket referenced by *map* (of type
  1827. * **BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and
  1828. * egress interfaces can be used for redirection. The
  1829. * **BPF_F_INGRESS** value in *flags* is used to make the
  1830. * distinction (ingress path is selected if the flag is present,
  1831. * egress path otherwise). This is the only flag supported for now.
  1832. *
  1833. * Returns
  1834. * **SK_PASS** on success, or **SK_DROP** on error.
  1835. */
  1836. static long (*bpf_msg_redirect_hash)(struct sk_msg_md *msg, void *map, void *key, __u64 flags) = (void *) 71;
  1837. /*
  1838. * bpf_sk_redirect_hash
  1839. *
  1840. * This helper is used in programs implementing policies at the
  1841. * skb socket level. If the sk_buff *skb* is allowed to pass (i.e.
  1842. * if the verdict eBPF program returns **SK_PASS**), redirect it
  1843. * to the socket referenced by *map* (of type
  1844. * **BPF_MAP_TYPE_SOCKHASH**) using hash *key*. Both ingress and
  1845. * egress interfaces can be used for redirection. The
  1846. * **BPF_F_INGRESS** value in *flags* is used to make the
  1847. * distinction (ingress path is selected if the flag is present,
  1848. * egress otherwise). This is the only flag supported for now.
  1849. *
  1850. * Returns
  1851. * **SK_PASS** on success, or **SK_DROP** on error.
  1852. */
  1853. static long (*bpf_sk_redirect_hash)(struct __sk_buff *skb, void *map, void *key, __u64 flags) = (void *) 72;
  1854. /*
  1855. * bpf_lwt_push_encap
  1856. *
  1857. * Encapsulate the packet associated to *skb* within a Layer 3
  1858. * protocol header. This header is provided in the buffer at
  1859. * address *hdr*, with *len* its size in bytes. *type* indicates
  1860. * the protocol of the header and can be one of:
  1861. *
  1862. * **BPF_LWT_ENCAP_SEG6**
  1863. * IPv6 encapsulation with Segment Routing Header
  1864. * (**struct ipv6_sr_hdr**). *hdr* only contains the SRH,
  1865. * the IPv6 header is computed by the kernel.
  1866. * **BPF_LWT_ENCAP_SEG6_INLINE**
  1867. * Only works if *skb* contains an IPv6 packet. Insert a
  1868. * Segment Routing Header (**struct ipv6_sr_hdr**) inside
  1869. * the IPv6 header.
  1870. * **BPF_LWT_ENCAP_IP**
  1871. * IP encapsulation (GRE/GUE/IPIP/etc). The outer header
  1872. * must be IPv4 or IPv6, followed by zero or more
  1873. * additional headers, up to **LWT_BPF_MAX_HEADROOM**
  1874. * total bytes in all prepended headers. Please note that
  1875. * if **skb_is_gso**\ (*skb*) is true, no more than two
  1876. * headers can be prepended, and the inner header, if
  1877. * present, should be either GRE or UDP/GUE.
  1878. *
  1879. * **BPF_LWT_ENCAP_SEG6**\ \* types can be called by BPF programs
  1880. * of type **BPF_PROG_TYPE_LWT_IN**; **BPF_LWT_ENCAP_IP** type can
  1881. * be called by bpf programs of types **BPF_PROG_TYPE_LWT_IN** and
  1882. * **BPF_PROG_TYPE_LWT_XMIT**.
  1883. *
  1884. * A call to this helper is susceptible to change the underlying
  1885. * packet buffer. Therefore, at load time, all checks on pointers
  1886. * previously done by the verifier are invalidated and must be
  1887. * performed again, if the helper is used in combination with
  1888. * direct packet access.
  1889. *
  1890. * Returns
  1891. * 0 on success, or a negative error in case of failure.
  1892. */
  1893. static long (*bpf_lwt_push_encap)(struct __sk_buff *skb, __u32 type, void *hdr, __u32 len) = (void *) 73;
  1894. /*
  1895. * bpf_lwt_seg6_store_bytes
  1896. *
  1897. * Store *len* bytes from address *from* into the packet
  1898. * associated to *skb*, at *offset*. Only the flags, tag and TLVs
  1899. * inside the outermost IPv6 Segment Routing Header can be
  1900. * modified through this helper.
  1901. *
  1902. * A call to this helper is susceptible to change the underlying
  1903. * packet buffer. Therefore, at load time, all checks on pointers
  1904. * previously done by the verifier are invalidated and must be
  1905. * performed again, if the helper is used in combination with
  1906. * direct packet access.
  1907. *
  1908. * Returns
  1909. * 0 on success, or a negative error in case of failure.
  1910. */
  1911. static long (*bpf_lwt_seg6_store_bytes)(struct __sk_buff *skb, __u32 offset, const void *from, __u32 len) = (void *) 74;
  1912. /*
  1913. * bpf_lwt_seg6_adjust_srh
  1914. *
  1915. * Adjust the size allocated to TLVs in the outermost IPv6
  1916. * Segment Routing Header contained in the packet associated to
  1917. * *skb*, at position *offset* by *delta* bytes. Only offsets
  1918. * after the segments are accepted. *delta* can be as well
  1919. * positive (growing) as negative (shrinking).
  1920. *
  1921. * A call to this helper is susceptible to change the underlying
  1922. * packet buffer. Therefore, at load time, all checks on pointers
  1923. * previously done by the verifier are invalidated and must be
  1924. * performed again, if the helper is used in combination with
  1925. * direct packet access.
  1926. *
  1927. * Returns
  1928. * 0 on success, or a negative error in case of failure.
  1929. */
  1930. static long (*bpf_lwt_seg6_adjust_srh)(struct __sk_buff *skb, __u32 offset, __s32 delta) = (void *) 75;
  1931. /*
  1932. * bpf_lwt_seg6_action
  1933. *
  1934. * Apply an IPv6 Segment Routing action of type *action* to the
  1935. * packet associated to *skb*. Each action takes a parameter
  1936. * contained at address *param*, and of length *param_len* bytes.
  1937. * *action* can be one of:
  1938. *
  1939. * **SEG6_LOCAL_ACTION_END_X**
  1940. * End.X action: Endpoint with Layer-3 cross-connect.
  1941. * Type of *param*: **struct in6_addr**.
  1942. * **SEG6_LOCAL_ACTION_END_T**
  1943. * End.T action: Endpoint with specific IPv6 table lookup.
  1944. * Type of *param*: **int**.
  1945. * **SEG6_LOCAL_ACTION_END_B6**
  1946. * End.B6 action: Endpoint bound to an SRv6 policy.
  1947. * Type of *param*: **struct ipv6_sr_hdr**.
  1948. * **SEG6_LOCAL_ACTION_END_B6_ENCAP**
  1949. * End.B6.Encap action: Endpoint bound to an SRv6
  1950. * encapsulation policy.
  1951. * Type of *param*: **struct ipv6_sr_hdr**.
  1952. *
  1953. * A call to this helper is susceptible to change the underlying
  1954. * packet buffer. Therefore, at load time, all checks on pointers
  1955. * previously done by the verifier are invalidated and must be
  1956. * performed again, if the helper is used in combination with
  1957. * direct packet access.
  1958. *
  1959. * Returns
  1960. * 0 on success, or a negative error in case of failure.
  1961. */
  1962. static long (*bpf_lwt_seg6_action)(struct __sk_buff *skb, __u32 action, void *param, __u32 param_len) = (void *) 76;
  1963. /*
  1964. * bpf_rc_repeat
  1965. *
  1966. * This helper is used in programs implementing IR decoding, to
  1967. * report a successfully decoded repeat key message. This delays
  1968. * the generation of a key up event for previously generated
  1969. * key down event.
  1970. *
  1971. * Some IR protocols like NEC have a special IR message for
  1972. * repeating last button, for when a button is held down.
  1973. *
  1974. * The *ctx* should point to the lirc sample as passed into
  1975. * the program.
  1976. *
  1977. * This helper is only available is the kernel was compiled with
  1978. * the **CONFIG_BPF_LIRC_MODE2** configuration option set to
  1979. * "**y**".
  1980. *
  1981. * Returns
  1982. * 0
  1983. */
  1984. static long (*bpf_rc_repeat)(void *ctx) = (void *) 77;
  1985. /*
  1986. * bpf_rc_keydown
  1987. *
  1988. * This helper is used in programs implementing IR decoding, to
  1989. * report a successfully decoded key press with *scancode*,
  1990. * *toggle* value in the given *protocol*. The scancode will be
  1991. * translated to a keycode using the rc keymap, and reported as
  1992. * an input key down event. After a period a key up event is
  1993. * generated. This period can be extended by calling either
  1994. * **bpf_rc_keydown**\ () again with the same values, or calling
  1995. * **bpf_rc_repeat**\ ().
  1996. *
  1997. * Some protocols include a toggle bit, in case the button was
  1998. * released and pressed again between consecutive scancodes.
  1999. *
  2000. * The *ctx* should point to the lirc sample as passed into
  2001. * the program.
  2002. *
  2003. * The *protocol* is the decoded protocol number (see
  2004. * **enum rc_proto** for some predefined values).
  2005. *
  2006. * This helper is only available is the kernel was compiled with
  2007. * the **CONFIG_BPF_LIRC_MODE2** configuration option set to
  2008. * "**y**".
  2009. *
  2010. * Returns
  2011. * 0
  2012. */
  2013. static long (*bpf_rc_keydown)(void *ctx, __u32 protocol, __u64 scancode, __u32 toggle) = (void *) 78;
  2014. /*
  2015. * bpf_skb_cgroup_id
  2016. *
  2017. * Return the cgroup v2 id of the socket associated with the *skb*.
  2018. * This is roughly similar to the **bpf_get_cgroup_classid**\ ()
  2019. * helper for cgroup v1 by providing a tag resp. identifier that
  2020. * can be matched on or used for map lookups e.g. to implement
  2021. * policy. The cgroup v2 id of a given path in the hierarchy is
  2022. * exposed in user space through the f_handle API in order to get
  2023. * to the same 64-bit id.
  2024. *
  2025. * This helper can be used on TC egress path, but not on ingress,
  2026. * and is available only if the kernel was compiled with the
  2027. * **CONFIG_SOCK_CGROUP_DATA** configuration option.
  2028. *
  2029. * Returns
  2030. * The id is returned or 0 in case the id could not be retrieved.
  2031. */
  2032. static __u64 (*bpf_skb_cgroup_id)(struct __sk_buff *skb) = (void *) 79;
  2033. /*
  2034. * bpf_get_current_cgroup_id
  2035. *
  2036. * Get the current cgroup id based on the cgroup within which
  2037. * the current task is running.
  2038. *
  2039. * Returns
  2040. * A 64-bit integer containing the current cgroup id based
  2041. * on the cgroup within which the current task is running.
  2042. */
  2043. static __u64 (*bpf_get_current_cgroup_id)(void) = (void *) 80;
  2044. /*
  2045. * bpf_get_local_storage
  2046. *
  2047. * Get the pointer to the local storage area.
  2048. * The type and the size of the local storage is defined
  2049. * by the *map* argument.
  2050. * The *flags* meaning is specific for each map type,
  2051. * and has to be 0 for cgroup local storage.
  2052. *
  2053. * Depending on the BPF program type, a local storage area
  2054. * can be shared between multiple instances of the BPF program,
  2055. * running simultaneously.
  2056. *
  2057. * A user should care about the synchronization by himself.
  2058. * For example, by using the **BPF_ATOMIC** instructions to alter
  2059. * the shared data.
  2060. *
  2061. * Returns
  2062. * A pointer to the local storage area.
  2063. */
  2064. static void *(*bpf_get_local_storage)(void *map, __u64 flags) = (void *) 81;
  2065. /*
  2066. * bpf_sk_select_reuseport
  2067. *
  2068. * Select a **SO_REUSEPORT** socket from a
  2069. * **BPF_MAP_TYPE_REUSEPORT_SOCKARRAY** *map*.
  2070. * It checks the selected socket is matching the incoming
  2071. * request in the socket buffer.
  2072. *
  2073. * Returns
  2074. * 0 on success, or a negative error in case of failure.
  2075. */
  2076. static long (*bpf_sk_select_reuseport)(struct sk_reuseport_md *reuse, void *map, void *key, __u64 flags) = (void *) 82;
  2077. /*
  2078. * bpf_skb_ancestor_cgroup_id
  2079. *
  2080. * Return id of cgroup v2 that is ancestor of cgroup associated
  2081. * with the *skb* at the *ancestor_level*. The root cgroup is at
  2082. * *ancestor_level* zero and each step down the hierarchy
  2083. * increments the level. If *ancestor_level* == level of cgroup
  2084. * associated with *skb*, then return value will be same as that
  2085. * of **bpf_skb_cgroup_id**\ ().
  2086. *
  2087. * The helper is useful to implement policies based on cgroups
  2088. * that are upper in hierarchy than immediate cgroup associated
  2089. * with *skb*.
  2090. *
  2091. * The format of returned id and helper limitations are same as in
  2092. * **bpf_skb_cgroup_id**\ ().
  2093. *
  2094. * Returns
  2095. * The id is returned or 0 in case the id could not be retrieved.
  2096. */
  2097. static __u64 (*bpf_skb_ancestor_cgroup_id)(struct __sk_buff *skb, int ancestor_level) = (void *) 83;
  2098. /*
  2099. * bpf_sk_lookup_tcp
  2100. *
  2101. * Look for TCP socket matching *tuple*, optionally in a child
  2102. * network namespace *netns*. The return value must be checked,
  2103. * and if non-**NULL**, released via **bpf_sk_release**\ ().
  2104. *
  2105. * The *ctx* should point to the context of the program, such as
  2106. * the skb or socket (depending on the hook in use). This is used
  2107. * to determine the base network namespace for the lookup.
  2108. *
  2109. * *tuple_size* must be one of:
  2110. *
  2111. * **sizeof**\ (*tuple*\ **->ipv4**)
  2112. * Look for an IPv4 socket.
  2113. * **sizeof**\ (*tuple*\ **->ipv6**)
  2114. * Look for an IPv6 socket.
  2115. *
  2116. * If the *netns* is a negative signed 32-bit integer, then the
  2117. * socket lookup table in the netns associated with the *ctx*
  2118. * will be used. For the TC hooks, this is the netns of the device
  2119. * in the skb. For socket hooks, this is the netns of the socket.
  2120. * If *netns* is any other signed 32-bit value greater than or
  2121. * equal to zero then it specifies the ID of the netns relative to
  2122. * the netns associated with the *ctx*. *netns* values beyond the
  2123. * range of 32-bit integers are reserved for future use.
  2124. *
  2125. * All values for *flags* are reserved for future usage, and must
  2126. * be left at zero.
  2127. *
  2128. * This helper is available only if the kernel was compiled with
  2129. * **CONFIG_NET** configuration option.
  2130. *
  2131. * Returns
  2132. * Pointer to **struct bpf_sock**, or **NULL** in case of failure.
  2133. * For sockets with reuseport option, the **struct bpf_sock**
  2134. * result is from *reuse*\ **->socks**\ [] using the hash of the
  2135. * tuple.
  2136. */
  2137. static struct bpf_sock *(*bpf_sk_lookup_tcp)(void *ctx, struct bpf_sock_tuple *tuple, __u32 tuple_size, __u64 netns, __u64 flags) = (void *) 84;
  2138. /*
  2139. * bpf_sk_lookup_udp
  2140. *
  2141. * Look for UDP socket matching *tuple*, optionally in a child
  2142. * network namespace *netns*. The return value must be checked,
  2143. * and if non-**NULL**, released via **bpf_sk_release**\ ().
  2144. *
  2145. * The *ctx* should point to the context of the program, such as
  2146. * the skb or socket (depending on the hook in use). This is used
  2147. * to determine the base network namespace for the lookup.
  2148. *
  2149. * *tuple_size* must be one of:
  2150. *
  2151. * **sizeof**\ (*tuple*\ **->ipv4**)
  2152. * Look for an IPv4 socket.
  2153. * **sizeof**\ (*tuple*\ **->ipv6**)
  2154. * Look for an IPv6 socket.
  2155. *
  2156. * If the *netns* is a negative signed 32-bit integer, then the
  2157. * socket lookup table in the netns associated with the *ctx*
  2158. * will be used. For the TC hooks, this is the netns of the device
  2159. * in the skb. For socket hooks, this is the netns of the socket.
  2160. * If *netns* is any other signed 32-bit value greater than or
  2161. * equal to zero then it specifies the ID of the netns relative to
  2162. * the netns associated with the *ctx*. *netns* values beyond the
  2163. * range of 32-bit integers are reserved for future use.
  2164. *
  2165. * All values for *flags* are reserved for future usage, and must
  2166. * be left at zero.
  2167. *
  2168. * This helper is available only if the kernel was compiled with
  2169. * **CONFIG_NET** configuration option.
  2170. *
  2171. * Returns
  2172. * Pointer to **struct bpf_sock**, or **NULL** in case of failure.
  2173. * For sockets with reuseport option, the **struct bpf_sock**
  2174. * result is from *reuse*\ **->socks**\ [] using the hash of the
  2175. * tuple.
  2176. */
  2177. static struct bpf_sock *(*bpf_sk_lookup_udp)(void *ctx, struct bpf_sock_tuple *tuple, __u32 tuple_size, __u64 netns, __u64 flags) = (void *) 85;
  2178. /*
  2179. * bpf_sk_release
  2180. *
  2181. * Release the reference held by *sock*. *sock* must be a
  2182. * non-**NULL** pointer that was returned from
  2183. * **bpf_sk_lookup_xxx**\ ().
  2184. *
  2185. * Returns
  2186. * 0 on success, or a negative error in case of failure.
  2187. */
  2188. static long (*bpf_sk_release)(void *sock) = (void *) 86;
  2189. /*
  2190. * bpf_map_push_elem
  2191. *
  2192. * Push an element *value* in *map*. *flags* is one of:
  2193. *
  2194. * **BPF_EXIST**
  2195. * If the queue/stack is full, the oldest element is
  2196. * removed to make room for this.
  2197. *
  2198. * Returns
  2199. * 0 on success, or a negative error in case of failure.
  2200. */
  2201. static long (*bpf_map_push_elem)(void *map, const void *value, __u64 flags) = (void *) 87;
  2202. /*
  2203. * bpf_map_pop_elem
  2204. *
  2205. * Pop an element from *map*.
  2206. *
  2207. * Returns
  2208. * 0 on success, or a negative error in case of failure.
  2209. */
  2210. static long (*bpf_map_pop_elem)(void *map, void *value) = (void *) 88;
  2211. /*
  2212. * bpf_map_peek_elem
  2213. *
  2214. * Get an element from *map* without removing it.
  2215. *
  2216. * Returns
  2217. * 0 on success, or a negative error in case of failure.
  2218. */
  2219. static long (*bpf_map_peek_elem)(void *map, void *value) = (void *) 89;
  2220. /*
  2221. * bpf_msg_push_data
  2222. *
  2223. * For socket policies, insert *len* bytes into *msg* at offset
  2224. * *start*.
  2225. *
  2226. * If a program of type **BPF_PROG_TYPE_SK_MSG** is run on a
  2227. * *msg* it may want to insert metadata or options into the *msg*.
  2228. * This can later be read and used by any of the lower layer BPF
  2229. * hooks.
  2230. *
  2231. * This helper may fail if under memory pressure (a malloc
  2232. * fails) in these cases BPF programs will get an appropriate
  2233. * error and BPF programs will need to handle them.
  2234. *
  2235. * Returns
  2236. * 0 on success, or a negative error in case of failure.
  2237. */
  2238. static long (*bpf_msg_push_data)(struct sk_msg_md *msg, __u32 start, __u32 len, __u64 flags) = (void *) 90;
  2239. /*
  2240. * bpf_msg_pop_data
  2241. *
  2242. * Will remove *len* bytes from a *msg* starting at byte *start*.
  2243. * This may result in **ENOMEM** errors under certain situations if
  2244. * an allocation and copy are required due to a full ring buffer.
  2245. * However, the helper will try to avoid doing the allocation
  2246. * if possible. Other errors can occur if input parameters are
  2247. * invalid either due to *start* byte not being valid part of *msg*
  2248. * payload and/or *pop* value being to large.
  2249. *
  2250. * Returns
  2251. * 0 on success, or a negative error in case of failure.
  2252. */
  2253. static long (*bpf_msg_pop_data)(struct sk_msg_md *msg, __u32 start, __u32 len, __u64 flags) = (void *) 91;
  2254. /*
  2255. * bpf_rc_pointer_rel
  2256. *
  2257. * This helper is used in programs implementing IR decoding, to
  2258. * report a successfully decoded pointer movement.
  2259. *
  2260. * The *ctx* should point to the lirc sample as passed into
  2261. * the program.
  2262. *
  2263. * This helper is only available is the kernel was compiled with
  2264. * the **CONFIG_BPF_LIRC_MODE2** configuration option set to
  2265. * "**y**".
  2266. *
  2267. * Returns
  2268. * 0
  2269. */
  2270. static long (*bpf_rc_pointer_rel)(void *ctx, __s32 rel_x, __s32 rel_y) = (void *) 92;
  2271. /*
  2272. * bpf_spin_lock
  2273. *
  2274. * Acquire a spinlock represented by the pointer *lock*, which is
  2275. * stored as part of a value of a map. Taking the lock allows to
  2276. * safely update the rest of the fields in that value. The
  2277. * spinlock can (and must) later be released with a call to
  2278. * **bpf_spin_unlock**\ (\ *lock*\ ).
  2279. *
  2280. * Spinlocks in BPF programs come with a number of restrictions
  2281. * and constraints:
  2282. *
  2283. * * **bpf_spin_lock** objects are only allowed inside maps of
  2284. * types **BPF_MAP_TYPE_HASH** and **BPF_MAP_TYPE_ARRAY** (this
  2285. * list could be extended in the future).
  2286. * * BTF description of the map is mandatory.
  2287. * * The BPF program can take ONE lock at a time, since taking two
  2288. * or more could cause dead locks.
  2289. * * Only one **struct bpf_spin_lock** is allowed per map element.
  2290. * * When the lock is taken, calls (either BPF to BPF or helpers)
  2291. * are not allowed.
  2292. * * The **BPF_LD_ABS** and **BPF_LD_IND** instructions are not
  2293. * allowed inside a spinlock-ed region.
  2294. * * The BPF program MUST call **bpf_spin_unlock**\ () to release
  2295. * the lock, on all execution paths, before it returns.
  2296. * * The BPF program can access **struct bpf_spin_lock** only via
  2297. * the **bpf_spin_lock**\ () and **bpf_spin_unlock**\ ()
  2298. * helpers. Loading or storing data into the **struct
  2299. * bpf_spin_lock** *lock*\ **;** field of a map is not allowed.
  2300. * * To use the **bpf_spin_lock**\ () helper, the BTF description
  2301. * of the map value must be a struct and have **struct
  2302. * bpf_spin_lock** *anyname*\ **;** field at the top level.
  2303. * Nested lock inside another struct is not allowed.
  2304. * * The **struct bpf_spin_lock** *lock* field in a map value must
  2305. * be aligned on a multiple of 4 bytes in that value.
  2306. * * Syscall with command **BPF_MAP_LOOKUP_ELEM** does not copy
  2307. * the **bpf_spin_lock** field to user space.
  2308. * * Syscall with command **BPF_MAP_UPDATE_ELEM**, or update from
  2309. * a BPF program, do not update the **bpf_spin_lock** field.
  2310. * * **bpf_spin_lock** cannot be on the stack or inside a
  2311. * networking packet (it can only be inside of a map values).
  2312. * * **bpf_spin_lock** is available to root only.
  2313. * * Tracing programs and socket filter programs cannot use
  2314. * **bpf_spin_lock**\ () due to insufficient preemption checks
  2315. * (but this may change in the future).
  2316. * * **bpf_spin_lock** is not allowed in inner maps of map-in-map.
  2317. *
  2318. * Returns
  2319. * 0
  2320. */
  2321. static long (*bpf_spin_lock)(struct bpf_spin_lock *lock) = (void *) 93;
  2322. /*
  2323. * bpf_spin_unlock
  2324. *
  2325. * Release the *lock* previously locked by a call to
  2326. * **bpf_spin_lock**\ (\ *lock*\ ).
  2327. *
  2328. * Returns
  2329. * 0
  2330. */
  2331. static long (*bpf_spin_unlock)(struct bpf_spin_lock *lock) = (void *) 94;
  2332. /*
  2333. * bpf_sk_fullsock
  2334. *
  2335. * This helper gets a **struct bpf_sock** pointer such
  2336. * that all the fields in this **bpf_sock** can be accessed.
  2337. *
  2338. * Returns
  2339. * A **struct bpf_sock** pointer on success, or **NULL** in
  2340. * case of failure.
  2341. */
  2342. static struct bpf_sock *(*bpf_sk_fullsock)(struct bpf_sock *sk) = (void *) 95;
  2343. /*
  2344. * bpf_tcp_sock
  2345. *
  2346. * This helper gets a **struct bpf_tcp_sock** pointer from a
  2347. * **struct bpf_sock** pointer.
  2348. *
  2349. * Returns
  2350. * A **struct bpf_tcp_sock** pointer on success, or **NULL** in
  2351. * case of failure.
  2352. */
  2353. static struct bpf_tcp_sock *(*bpf_tcp_sock)(struct bpf_sock *sk) = (void *) 96;
  2354. /*
  2355. * bpf_skb_ecn_set_ce
  2356. *
  2357. * Set ECN (Explicit Congestion Notification) field of IP header
  2358. * to **CE** (Congestion Encountered) if current value is **ECT**
  2359. * (ECN Capable Transport). Otherwise, do nothing. Works with IPv6
  2360. * and IPv4.
  2361. *
  2362. * Returns
  2363. * 1 if the **CE** flag is set (either by the current helper call
  2364. * or because it was already present), 0 if it is not set.
  2365. */
  2366. static long (*bpf_skb_ecn_set_ce)(struct __sk_buff *skb) = (void *) 97;
  2367. /*
  2368. * bpf_get_listener_sock
  2369. *
  2370. * Return a **struct bpf_sock** pointer in **TCP_LISTEN** state.
  2371. * **bpf_sk_release**\ () is unnecessary and not allowed.
  2372. *
  2373. * Returns
  2374. * A **struct bpf_sock** pointer on success, or **NULL** in
  2375. * case of failure.
  2376. */
  2377. static struct bpf_sock *(*bpf_get_listener_sock)(struct bpf_sock *sk) = (void *) 98;
  2378. /*
  2379. * bpf_skc_lookup_tcp
  2380. *
  2381. * Look for TCP socket matching *tuple*, optionally in a child
  2382. * network namespace *netns*. The return value must be checked,
  2383. * and if non-**NULL**, released via **bpf_sk_release**\ ().
  2384. *
  2385. * This function is identical to **bpf_sk_lookup_tcp**\ (), except
  2386. * that it also returns timewait or request sockets. Use
  2387. * **bpf_sk_fullsock**\ () or **bpf_tcp_sock**\ () to access the
  2388. * full structure.
  2389. *
  2390. * This helper is available only if the kernel was compiled with
  2391. * **CONFIG_NET** configuration option.
  2392. *
  2393. * Returns
  2394. * Pointer to **struct bpf_sock**, or **NULL** in case of failure.
  2395. * For sockets with reuseport option, the **struct bpf_sock**
  2396. * result is from *reuse*\ **->socks**\ [] using the hash of the
  2397. * tuple.
  2398. */
  2399. static struct bpf_sock *(*bpf_skc_lookup_tcp)(void *ctx, struct bpf_sock_tuple *tuple, __u32 tuple_size, __u64 netns, __u64 flags) = (void *) 99;
  2400. /*
  2401. * bpf_tcp_check_syncookie
  2402. *
  2403. * Check whether *iph* and *th* contain a valid SYN cookie ACK for
  2404. * the listening socket in *sk*.
  2405. *
  2406. * *iph* points to the start of the IPv4 or IPv6 header, while
  2407. * *iph_len* contains **sizeof**\ (**struct iphdr**) or
  2408. * **sizeof**\ (**struct ipv6hdr**).
  2409. *
  2410. * *th* points to the start of the TCP header, while *th_len*
  2411. * contains the length of the TCP header (at least
  2412. * **sizeof**\ (**struct tcphdr**)).
  2413. *
  2414. * Returns
  2415. * 0 if *iph* and *th* are a valid SYN cookie ACK, or a negative
  2416. * error otherwise.
  2417. */
  2418. static long (*bpf_tcp_check_syncookie)(void *sk, void *iph, __u32 iph_len, struct tcphdr *th, __u32 th_len) = (void *) 100;
  2419. /*
  2420. * bpf_sysctl_get_name
  2421. *
  2422. * Get name of sysctl in /proc/sys/ and copy it into provided by
  2423. * program buffer *buf* of size *buf_len*.
  2424. *
  2425. * The buffer is always NUL terminated, unless it's zero-sized.
  2426. *
  2427. * If *flags* is zero, full name (e.g. "net/ipv4/tcp_mem") is
  2428. * copied. Use **BPF_F_SYSCTL_BASE_NAME** flag to copy base name
  2429. * only (e.g. "tcp_mem").
  2430. *
  2431. * Returns
  2432. * Number of character copied (not including the trailing NUL).
  2433. *
  2434. * **-E2BIG** if the buffer wasn't big enough (*buf* will contain
  2435. * truncated name in this case).
  2436. */
  2437. static long (*bpf_sysctl_get_name)(struct bpf_sysctl *ctx, char *buf, unsigned long buf_len, __u64 flags) = (void *) 101;
  2438. /*
  2439. * bpf_sysctl_get_current_value
  2440. *
  2441. * Get current value of sysctl as it is presented in /proc/sys
  2442. * (incl. newline, etc), and copy it as a string into provided
  2443. * by program buffer *buf* of size *buf_len*.
  2444. *
  2445. * The whole value is copied, no matter what file position user
  2446. * space issued e.g. sys_read at.
  2447. *
  2448. * The buffer is always NUL terminated, unless it's zero-sized.
  2449. *
  2450. * Returns
  2451. * Number of character copied (not including the trailing NUL).
  2452. *
  2453. * **-E2BIG** if the buffer wasn't big enough (*buf* will contain
  2454. * truncated name in this case).
  2455. *
  2456. * **-EINVAL** if current value was unavailable, e.g. because
  2457. * sysctl is uninitialized and read returns -EIO for it.
  2458. */
  2459. static long (*bpf_sysctl_get_current_value)(struct bpf_sysctl *ctx, char *buf, unsigned long buf_len) = (void *) 102;
  2460. /*
  2461. * bpf_sysctl_get_new_value
  2462. *
  2463. * Get new value being written by user space to sysctl (before
  2464. * the actual write happens) and copy it as a string into
  2465. * provided by program buffer *buf* of size *buf_len*.
  2466. *
  2467. * User space may write new value at file position > 0.
  2468. *
  2469. * The buffer is always NUL terminated, unless it's zero-sized.
  2470. *
  2471. * Returns
  2472. * Number of character copied (not including the trailing NUL).
  2473. *
  2474. * **-E2BIG** if the buffer wasn't big enough (*buf* will contain
  2475. * truncated name in this case).
  2476. *
  2477. * **-EINVAL** if sysctl is being read.
  2478. */
  2479. static long (*bpf_sysctl_get_new_value)(struct bpf_sysctl *ctx, char *buf, unsigned long buf_len) = (void *) 103;
  2480. /*
  2481. * bpf_sysctl_set_new_value
  2482. *
  2483. * Override new value being written by user space to sysctl with
  2484. * value provided by program in buffer *buf* of size *buf_len*.
  2485. *
  2486. * *buf* should contain a string in same form as provided by user
  2487. * space on sysctl write.
  2488. *
  2489. * User space may write new value at file position > 0. To override
  2490. * the whole sysctl value file position should be set to zero.
  2491. *
  2492. * Returns
  2493. * 0 on success.
  2494. *
  2495. * **-E2BIG** if the *buf_len* is too big.
  2496. *
  2497. * **-EINVAL** if sysctl is being read.
  2498. */
  2499. static long (*bpf_sysctl_set_new_value)(struct bpf_sysctl *ctx, const char *buf, unsigned long buf_len) = (void *) 104;
  2500. /*
  2501. * bpf_strtol
  2502. *
  2503. * Convert the initial part of the string from buffer *buf* of
  2504. * size *buf_len* to a long integer according to the given base
  2505. * and save the result in *res*.
  2506. *
  2507. * The string may begin with an arbitrary amount of white space
  2508. * (as determined by **isspace**\ (3)) followed by a single
  2509. * optional '**-**' sign.
  2510. *
  2511. * Five least significant bits of *flags* encode base, other bits
  2512. * are currently unused.
  2513. *
  2514. * Base must be either 8, 10, 16 or 0 to detect it automatically
  2515. * similar to user space **strtol**\ (3).
  2516. *
  2517. * Returns
  2518. * Number of characters consumed on success. Must be positive but
  2519. * no more than *buf_len*.
  2520. *
  2521. * **-EINVAL** if no valid digits were found or unsupported base
  2522. * was provided.
  2523. *
  2524. * **-ERANGE** if resulting value was out of range.
  2525. */
  2526. static long (*bpf_strtol)(const char *buf, unsigned long buf_len, __u64 flags, long *res) = (void *) 105;
  2527. /*
  2528. * bpf_strtoul
  2529. *
  2530. * Convert the initial part of the string from buffer *buf* of
  2531. * size *buf_len* to an unsigned long integer according to the
  2532. * given base and save the result in *res*.
  2533. *
  2534. * The string may begin with an arbitrary amount of white space
  2535. * (as determined by **isspace**\ (3)).
  2536. *
  2537. * Five least significant bits of *flags* encode base, other bits
  2538. * are currently unused.
  2539. *
  2540. * Base must be either 8, 10, 16 or 0 to detect it automatically
  2541. * similar to user space **strtoul**\ (3).
  2542. *
  2543. * Returns
  2544. * Number of characters consumed on success. Must be positive but
  2545. * no more than *buf_len*.
  2546. *
  2547. * **-EINVAL** if no valid digits were found or unsupported base
  2548. * was provided.
  2549. *
  2550. * **-ERANGE** if resulting value was out of range.
  2551. */
  2552. static long (*bpf_strtoul)(const char *buf, unsigned long buf_len, __u64 flags, unsigned long *res) = (void *) 106;
  2553. /*
  2554. * bpf_sk_storage_get
  2555. *
  2556. * Get a bpf-local-storage from a *sk*.
  2557. *
  2558. * Logically, it could be thought of getting the value from
  2559. * a *map* with *sk* as the **key**. From this
  2560. * perspective, the usage is not much different from
  2561. * **bpf_map_lookup_elem**\ (*map*, **&**\ *sk*) except this
  2562. * helper enforces the key must be a full socket and the map must
  2563. * be a **BPF_MAP_TYPE_SK_STORAGE** also.
  2564. *
  2565. * Underneath, the value is stored locally at *sk* instead of
  2566. * the *map*. The *map* is used as the bpf-local-storage
  2567. * "type". The bpf-local-storage "type" (i.e. the *map*) is
  2568. * searched against all bpf-local-storages residing at *sk*.
  2569. *
  2570. * *sk* is a kernel **struct sock** pointer for LSM program.
  2571. * *sk* is a **struct bpf_sock** pointer for other program types.
  2572. *
  2573. * An optional *flags* (**BPF_SK_STORAGE_GET_F_CREATE**) can be
  2574. * used such that a new bpf-local-storage will be
  2575. * created if one does not exist. *value* can be used
  2576. * together with **BPF_SK_STORAGE_GET_F_CREATE** to specify
  2577. * the initial value of a bpf-local-storage. If *value* is
  2578. * **NULL**, the new bpf-local-storage will be zero initialized.
  2579. *
  2580. * Returns
  2581. * A bpf-local-storage pointer is returned on success.
  2582. *
  2583. * **NULL** if not found or there was an error in adding
  2584. * a new bpf-local-storage.
  2585. */
  2586. static void *(*bpf_sk_storage_get)(void *map, void *sk, void *value, __u64 flags) = (void *) 107;
  2587. /*
  2588. * bpf_sk_storage_delete
  2589. *
  2590. * Delete a bpf-local-storage from a *sk*.
  2591. *
  2592. * Returns
  2593. * 0 on success.
  2594. *
  2595. * **-ENOENT** if the bpf-local-storage cannot be found.
  2596. * **-EINVAL** if sk is not a fullsock (e.g. a request_sock).
  2597. */
  2598. static long (*bpf_sk_storage_delete)(void *map, void *sk) = (void *) 108;
  2599. /*
  2600. * bpf_send_signal
  2601. *
  2602. * Send signal *sig* to the process of the current task.
  2603. * The signal may be delivered to any of this process's threads.
  2604. *
  2605. * Returns
  2606. * 0 on success or successfully queued.
  2607. *
  2608. * **-EBUSY** if work queue under nmi is full.
  2609. *
  2610. * **-EINVAL** if *sig* is invalid.
  2611. *
  2612. * **-EPERM** if no permission to send the *sig*.
  2613. *
  2614. * **-EAGAIN** if bpf program can try again.
  2615. */
  2616. static long (*bpf_send_signal)(__u32 sig) = (void *) 109;
  2617. /*
  2618. * bpf_tcp_gen_syncookie
  2619. *
  2620. * Try to issue a SYN cookie for the packet with corresponding
  2621. * IP/TCP headers, *iph* and *th*, on the listening socket in *sk*.
  2622. *
  2623. * *iph* points to the start of the IPv4 or IPv6 header, while
  2624. * *iph_len* contains **sizeof**\ (**struct iphdr**) or
  2625. * **sizeof**\ (**struct ipv6hdr**).
  2626. *
  2627. * *th* points to the start of the TCP header, while *th_len*
  2628. * contains the length of the TCP header with options (at least
  2629. * **sizeof**\ (**struct tcphdr**)).
  2630. *
  2631. * Returns
  2632. * On success, lower 32 bits hold the generated SYN cookie in
  2633. * followed by 16 bits which hold the MSS value for that cookie,
  2634. * and the top 16 bits are unused.
  2635. *
  2636. * On failure, the returned value is one of the following:
  2637. *
  2638. * **-EINVAL** SYN cookie cannot be issued due to error
  2639. *
  2640. * **-ENOENT** SYN cookie should not be issued (no SYN flood)
  2641. *
  2642. * **-EOPNOTSUPP** kernel configuration does not enable SYN cookies
  2643. *
  2644. * **-EPROTONOSUPPORT** IP packet version is not 4 or 6
  2645. */
  2646. static __s64 (*bpf_tcp_gen_syncookie)(void *sk, void *iph, __u32 iph_len, struct tcphdr *th, __u32 th_len) = (void *) 110;
  2647. /*
  2648. * bpf_skb_output
  2649. *
  2650. * Write raw *data* blob into a special BPF perf event held by
  2651. * *map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
  2652. * event must have the following attributes: **PERF_SAMPLE_RAW**
  2653. * as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
  2654. * **PERF_COUNT_SW_BPF_OUTPUT** as **config**.
  2655. *
  2656. * The *flags* are used to indicate the index in *map* for which
  2657. * the value must be put, masked with **BPF_F_INDEX_MASK**.
  2658. * Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
  2659. * to indicate that the index of the current CPU core should be
  2660. * used.
  2661. *
  2662. * The value to write, of *size*, is passed through eBPF stack and
  2663. * pointed by *data*.
  2664. *
  2665. * *ctx* is a pointer to in-kernel struct sk_buff.
  2666. *
  2667. * This helper is similar to **bpf_perf_event_output**\ () but
  2668. * restricted to raw_tracepoint bpf programs.
  2669. *
  2670. * Returns
  2671. * 0 on success, or a negative error in case of failure.
  2672. */
  2673. static long (*bpf_skb_output)(void *ctx, void *map, __u64 flags, void *data, __u64 size) = (void *) 111;
  2674. /*
  2675. * bpf_probe_read_user
  2676. *
  2677. * Safely attempt to read *size* bytes from user space address
  2678. * *unsafe_ptr* and store the data in *dst*.
  2679. *
  2680. * Returns
  2681. * 0 on success, or a negative error in case of failure.
  2682. */
  2683. static long (*bpf_probe_read_user)(void *dst, __u32 size, const void *unsafe_ptr) = (void *) 112;
  2684. /*
  2685. * bpf_probe_read_kernel
  2686. *
  2687. * Safely attempt to read *size* bytes from kernel space address
  2688. * *unsafe_ptr* and store the data in *dst*.
  2689. *
  2690. * Returns
  2691. * 0 on success, or a negative error in case of failure.
  2692. */
  2693. static long (*bpf_probe_read_kernel)(void *dst, __u32 size, const void *unsafe_ptr) = (void *) 113;
  2694. /*
  2695. * bpf_probe_read_user_str
  2696. *
  2697. * Copy a NUL terminated string from an unsafe user address
  2698. * *unsafe_ptr* to *dst*. The *size* should include the
  2699. * terminating NUL byte. In case the string length is smaller than
  2700. * *size*, the target is not padded with further NUL bytes. If the
  2701. * string length is larger than *size*, just *size*-1 bytes are
  2702. * copied and the last byte is set to NUL.
  2703. *
  2704. * On success, returns the number of bytes that were written,
  2705. * including the terminal NUL. This makes this helper useful in
  2706. * tracing programs for reading strings, and more importantly to
  2707. * get its length at runtime. See the following snippet:
  2708. *
  2709. * ::
  2710. *
  2711. * SEC("kprobe/sys_open")
  2712. * void bpf_sys_open(struct pt_regs *ctx)
  2713. * {
  2714. * char buf[PATHLEN]; // PATHLEN is defined to 256
  2715. * int res = bpf_probe_read_user_str(buf, sizeof(buf),
  2716. * ctx->di);
  2717. *
  2718. * // Consume buf, for example push it to
  2719. * // userspace via bpf_perf_event_output(); we
  2720. * // can use res (the string length) as event
  2721. * // size, after checking its boundaries.
  2722. * }
  2723. *
  2724. * In comparison, using **bpf_probe_read_user**\ () helper here
  2725. * instead to read the string would require to estimate the length
  2726. * at compile time, and would often result in copying more memory
  2727. * than necessary.
  2728. *
  2729. * Another useful use case is when parsing individual process
  2730. * arguments or individual environment variables navigating
  2731. * *current*\ **->mm->arg_start** and *current*\
  2732. * **->mm->env_start**: using this helper and the return value,
  2733. * one can quickly iterate at the right offset of the memory area.
  2734. *
  2735. * Returns
  2736. * On success, the strictly positive length of the output string,
  2737. * including the trailing NUL character. On error, a negative
  2738. * value.
  2739. */
  2740. static long (*bpf_probe_read_user_str)(void *dst, __u32 size, const void *unsafe_ptr) = (void *) 114;
  2741. /*
  2742. * bpf_probe_read_kernel_str
  2743. *
  2744. * Copy a NUL terminated string from an unsafe kernel address *unsafe_ptr*
  2745. * to *dst*. Same semantics as with **bpf_probe_read_user_str**\ () apply.
  2746. *
  2747. * Returns
  2748. * On success, the strictly positive length of the string, including
  2749. * the trailing NUL character. On error, a negative value.
  2750. */
  2751. static long (*bpf_probe_read_kernel_str)(void *dst, __u32 size, const void *unsafe_ptr) = (void *) 115;
  2752. /*
  2753. * bpf_tcp_send_ack
  2754. *
  2755. * Send out a tcp-ack. *tp* is the in-kernel struct **tcp_sock**.
  2756. * *rcv_nxt* is the ack_seq to be sent out.
  2757. *
  2758. * Returns
  2759. * 0 on success, or a negative error in case of failure.
  2760. */
  2761. static long (*bpf_tcp_send_ack)(void *tp, __u32 rcv_nxt) = (void *) 116;
  2762. /*
  2763. * bpf_send_signal_thread
  2764. *
  2765. * Send signal *sig* to the thread corresponding to the current task.
  2766. *
  2767. * Returns
  2768. * 0 on success or successfully queued.
  2769. *
  2770. * **-EBUSY** if work queue under nmi is full.
  2771. *
  2772. * **-EINVAL** if *sig* is invalid.
  2773. *
  2774. * **-EPERM** if no permission to send the *sig*.
  2775. *
  2776. * **-EAGAIN** if bpf program can try again.
  2777. */
  2778. static long (*bpf_send_signal_thread)(__u32 sig) = (void *) 117;
  2779. /*
  2780. * bpf_jiffies64
  2781. *
  2782. * Obtain the 64bit jiffies
  2783. *
  2784. * Returns
  2785. * The 64 bit jiffies
  2786. */
  2787. static __u64 (*bpf_jiffies64)(void) = (void *) 118;
  2788. /*
  2789. * bpf_read_branch_records
  2790. *
  2791. * For an eBPF program attached to a perf event, retrieve the
  2792. * branch records (**struct perf_branch_entry**) associated to *ctx*
  2793. * and store it in the buffer pointed by *buf* up to size
  2794. * *size* bytes.
  2795. *
  2796. * Returns
  2797. * On success, number of bytes written to *buf*. On error, a
  2798. * negative value.
  2799. *
  2800. * The *flags* can be set to **BPF_F_GET_BRANCH_RECORDS_SIZE** to
  2801. * instead return the number of bytes required to store all the
  2802. * branch entries. If this flag is set, *buf* may be NULL.
  2803. *
  2804. * **-EINVAL** if arguments invalid or **size** not a multiple
  2805. * of **sizeof**\ (**struct perf_branch_entry**\ ).
  2806. *
  2807. * **-ENOENT** if architecture does not support branch records.
  2808. */
  2809. static long (*bpf_read_branch_records)(struct bpf_perf_event_data *ctx, void *buf, __u32 size, __u64 flags) = (void *) 119;
  2810. /*
  2811. * bpf_get_ns_current_pid_tgid
  2812. *
  2813. * Returns 0 on success, values for *pid* and *tgid* as seen from the current
  2814. * *namespace* will be returned in *nsdata*.
  2815. *
  2816. * Returns
  2817. * 0 on success, or one of the following in case of failure:
  2818. *
  2819. * **-EINVAL** if dev and inum supplied don't match dev_t and inode number
  2820. * with nsfs of current task, or if dev conversion to dev_t lost high bits.
  2821. *
  2822. * **-ENOENT** if pidns does not exists for the current task.
  2823. */
  2824. static long (*bpf_get_ns_current_pid_tgid)(__u64 dev, __u64 ino, struct bpf_pidns_info *nsdata, __u32 size) = (void *) 120;
  2825. /*
  2826. * bpf_xdp_output
  2827. *
  2828. * Write raw *data* blob into a special BPF perf event held by
  2829. * *map* of type **BPF_MAP_TYPE_PERF_EVENT_ARRAY**. This perf
  2830. * event must have the following attributes: **PERF_SAMPLE_RAW**
  2831. * as **sample_type**, **PERF_TYPE_SOFTWARE** as **type**, and
  2832. * **PERF_COUNT_SW_BPF_OUTPUT** as **config**.
  2833. *
  2834. * The *flags* are used to indicate the index in *map* for which
  2835. * the value must be put, masked with **BPF_F_INDEX_MASK**.
  2836. * Alternatively, *flags* can be set to **BPF_F_CURRENT_CPU**
  2837. * to indicate that the index of the current CPU core should be
  2838. * used.
  2839. *
  2840. * The value to write, of *size*, is passed through eBPF stack and
  2841. * pointed by *data*.
  2842. *
  2843. * *ctx* is a pointer to in-kernel struct xdp_buff.
  2844. *
  2845. * This helper is similar to **bpf_perf_eventoutput**\ () but
  2846. * restricted to raw_tracepoint bpf programs.
  2847. *
  2848. * Returns
  2849. * 0 on success, or a negative error in case of failure.
  2850. */
  2851. static long (*bpf_xdp_output)(void *ctx, void *map, __u64 flags, void *data, __u64 size) = (void *) 121;
  2852. /*
  2853. * bpf_get_netns_cookie
  2854. *
  2855. * Retrieve the cookie (generated by the kernel) of the network
  2856. * namespace the input *ctx* is associated with. The network
  2857. * namespace cookie remains stable for its lifetime and provides
  2858. * a global identifier that can be assumed unique. If *ctx* is
  2859. * NULL, then the helper returns the cookie for the initial
  2860. * network namespace. The cookie itself is very similar to that
  2861. * of **bpf_get_socket_cookie**\ () helper, but for network
  2862. * namespaces instead of sockets.
  2863. *
  2864. * Returns
  2865. * A 8-byte long opaque number.
  2866. */
  2867. static __u64 (*bpf_get_netns_cookie)(void *ctx) = (void *) 122;
  2868. /*
  2869. * bpf_get_current_ancestor_cgroup_id
  2870. *
  2871. * Return id of cgroup v2 that is ancestor of the cgroup associated
  2872. * with the current task at the *ancestor_level*. The root cgroup
  2873. * is at *ancestor_level* zero and each step down the hierarchy
  2874. * increments the level. If *ancestor_level* == level of cgroup
  2875. * associated with the current task, then return value will be the
  2876. * same as that of **bpf_get_current_cgroup_id**\ ().
  2877. *
  2878. * The helper is useful to implement policies based on cgroups
  2879. * that are upper in hierarchy than immediate cgroup associated
  2880. * with the current task.
  2881. *
  2882. * The format of returned id and helper limitations are same as in
  2883. * **bpf_get_current_cgroup_id**\ ().
  2884. *
  2885. * Returns
  2886. * The id is returned or 0 in case the id could not be retrieved.
  2887. */
  2888. static __u64 (*bpf_get_current_ancestor_cgroup_id)(int ancestor_level) = (void *) 123;
  2889. /*
  2890. * bpf_sk_assign
  2891. *
  2892. * Helper is overloaded depending on BPF program type. This
  2893. * description applies to **BPF_PROG_TYPE_SCHED_CLS** and
  2894. * **BPF_PROG_TYPE_SCHED_ACT** programs.
  2895. *
  2896. * Assign the *sk* to the *skb*. When combined with appropriate
  2897. * routing configuration to receive the packet towards the socket,
  2898. * will cause *skb* to be delivered to the specified socket.
  2899. * Subsequent redirection of *skb* via **bpf_redirect**\ (),
  2900. * **bpf_clone_redirect**\ () or other methods outside of BPF may
  2901. * interfere with successful delivery to the socket.
  2902. *
  2903. * This operation is only valid from TC ingress path.
  2904. *
  2905. * The *flags* argument must be zero.
  2906. *
  2907. * Returns
  2908. * 0 on success, or a negative error in case of failure:
  2909. *
  2910. * **-EINVAL** if specified *flags* are not supported.
  2911. *
  2912. * **-ENOENT** if the socket is unavailable for assignment.
  2913. *
  2914. * **-ENETUNREACH** if the socket is unreachable (wrong netns).
  2915. *
  2916. * **-EOPNOTSUPP** if the operation is not supported, for example
  2917. * a call from outside of TC ingress.
  2918. */
  2919. static long (*bpf_sk_assign)(void *ctx, void *sk, __u64 flags) = (void *) 124;
  2920. /*
  2921. * bpf_ktime_get_boot_ns
  2922. *
  2923. * Return the time elapsed since system boot, in nanoseconds.
  2924. * Does include the time the system was suspended.
  2925. * See: **clock_gettime**\ (**CLOCK_BOOTTIME**)
  2926. *
  2927. * Returns
  2928. * Current *ktime*.
  2929. */
  2930. static __u64 (*bpf_ktime_get_boot_ns)(void) = (void *) 125;
  2931. /*
  2932. * bpf_seq_printf
  2933. *
  2934. * **bpf_seq_printf**\ () uses seq_file **seq_printf**\ () to print
  2935. * out the format string.
  2936. * The *m* represents the seq_file. The *fmt* and *fmt_size* are for
  2937. * the format string itself. The *data* and *data_len* are format string
  2938. * arguments. The *data* are a **u64** array and corresponding format string
  2939. * values are stored in the array. For strings and pointers where pointees
  2940. * are accessed, only the pointer values are stored in the *data* array.
  2941. * The *data_len* is the size of *data* in bytes - must be a multiple of 8.
  2942. *
  2943. * Formats **%s**, **%p{i,I}{4,6}** requires to read kernel memory.
  2944. * Reading kernel memory may fail due to either invalid address or
  2945. * valid address but requiring a major memory fault. If reading kernel memory
  2946. * fails, the string for **%s** will be an empty string, and the ip
  2947. * address for **%p{i,I}{4,6}** will be 0. Not returning error to
  2948. * bpf program is consistent with what **bpf_trace_printk**\ () does for now.
  2949. *
  2950. * Returns
  2951. * 0 on success, or a negative error in case of failure:
  2952. *
  2953. * **-EBUSY** if per-CPU memory copy buffer is busy, can try again
  2954. * by returning 1 from bpf program.
  2955. *
  2956. * **-EINVAL** if arguments are invalid, or if *fmt* is invalid/unsupported.
  2957. *
  2958. * **-E2BIG** if *fmt* contains too many format specifiers.
  2959. *
  2960. * **-EOVERFLOW** if an overflow happened: The same object will be tried again.
  2961. */
  2962. static long (*bpf_seq_printf)(struct seq_file *m, const char *fmt, __u32 fmt_size, const void *data, __u32 data_len) = (void *) 126;
  2963. /*
  2964. * bpf_seq_write
  2965. *
  2966. * **bpf_seq_write**\ () uses seq_file **seq_write**\ () to write the data.
  2967. * The *m* represents the seq_file. The *data* and *len* represent the
  2968. * data to write in bytes.
  2969. *
  2970. * Returns
  2971. * 0 on success, or a negative error in case of failure:
  2972. *
  2973. * **-EOVERFLOW** if an overflow happened: The same object will be tried again.
  2974. */
  2975. static long (*bpf_seq_write)(struct seq_file *m, const void *data, __u32 len) = (void *) 127;
  2976. /*
  2977. * bpf_sk_cgroup_id
  2978. *
  2979. * Return the cgroup v2 id of the socket *sk*.
  2980. *
  2981. * *sk* must be a non-**NULL** pointer to a socket, e.g. one
  2982. * returned from **bpf_sk_lookup_xxx**\ (),
  2983. * **bpf_sk_fullsock**\ (), etc. The format of returned id is
  2984. * same as in **bpf_skb_cgroup_id**\ ().
  2985. *
  2986. * This helper is available only if the kernel was compiled with
  2987. * the **CONFIG_SOCK_CGROUP_DATA** configuration option.
  2988. *
  2989. * Returns
  2990. * The id is returned or 0 in case the id could not be retrieved.
  2991. */
  2992. static __u64 (*bpf_sk_cgroup_id)(void *sk) = (void *) 128;
  2993. /*
  2994. * bpf_sk_ancestor_cgroup_id
  2995. *
  2996. * Return id of cgroup v2 that is ancestor of cgroup associated
  2997. * with the *sk* at the *ancestor_level*. The root cgroup is at
  2998. * *ancestor_level* zero and each step down the hierarchy
  2999. * increments the level. If *ancestor_level* == level of cgroup
  3000. * associated with *sk*, then return value will be same as that
  3001. * of **bpf_sk_cgroup_id**\ ().
  3002. *
  3003. * The helper is useful to implement policies based on cgroups
  3004. * that are upper in hierarchy than immediate cgroup associated
  3005. * with *sk*.
  3006. *
  3007. * The format of returned id and helper limitations are same as in
  3008. * **bpf_sk_cgroup_id**\ ().
  3009. *
  3010. * Returns
  3011. * The id is returned or 0 in case the id could not be retrieved.
  3012. */
  3013. static __u64 (*bpf_sk_ancestor_cgroup_id)(void *sk, int ancestor_level) = (void *) 129;
  3014. /*
  3015. * bpf_ringbuf_output
  3016. *
  3017. * Copy *size* bytes from *data* into a ring buffer *ringbuf*.
  3018. * If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
  3019. * of new data availability is sent.
  3020. * If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
  3021. * of new data availability is sent unconditionally.
  3022. * If **0** is specified in *flags*, an adaptive notification
  3023. * of new data availability is sent.
  3024. *
  3025. * An adaptive notification is a notification sent whenever the user-space
  3026. * process has caught up and consumed all available payloads. In case the user-space
  3027. * process is still processing a previous payload, then no notification is needed
  3028. * as it will process the newly added payload automatically.
  3029. *
  3030. * Returns
  3031. * 0 on success, or a negative error in case of failure.
  3032. */
  3033. static long (*bpf_ringbuf_output)(void *ringbuf, void *data, __u64 size, __u64 flags) = (void *) 130;
  3034. /*
  3035. * bpf_ringbuf_reserve
  3036. *
  3037. * Reserve *size* bytes of payload in a ring buffer *ringbuf*.
  3038. * *flags* must be 0.
  3039. *
  3040. * Returns
  3041. * Valid pointer with *size* bytes of memory available; NULL,
  3042. * otherwise.
  3043. */
  3044. static void *(*bpf_ringbuf_reserve)(void *ringbuf, __u64 size, __u64 flags) = (void *) 131;
  3045. /*
  3046. * bpf_ringbuf_submit
  3047. *
  3048. * Submit reserved ring buffer sample, pointed to by *data*.
  3049. * If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
  3050. * of new data availability is sent.
  3051. * If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
  3052. * of new data availability is sent unconditionally.
  3053. * If **0** is specified in *flags*, an adaptive notification
  3054. * of new data availability is sent.
  3055. *
  3056. * See 'bpf_ringbuf_output()' for the definition of adaptive notification.
  3057. *
  3058. * Returns
  3059. * Nothing. Always succeeds.
  3060. */
  3061. static void (*bpf_ringbuf_submit)(void *data, __u64 flags) = (void *) 132;
  3062. /*
  3063. * bpf_ringbuf_discard
  3064. *
  3065. * Discard reserved ring buffer sample, pointed to by *data*.
  3066. * If **BPF_RB_NO_WAKEUP** is specified in *flags*, no notification
  3067. * of new data availability is sent.
  3068. * If **BPF_RB_FORCE_WAKEUP** is specified in *flags*, notification
  3069. * of new data availability is sent unconditionally.
  3070. * If **0** is specified in *flags*, an adaptive notification
  3071. * of new data availability is sent.
  3072. *
  3073. * See 'bpf_ringbuf_output()' for the definition of adaptive notification.
  3074. *
  3075. * Returns
  3076. * Nothing. Always succeeds.
  3077. */
  3078. static void (*bpf_ringbuf_discard)(void *data, __u64 flags) = (void *) 133;
  3079. /*
  3080. * bpf_ringbuf_query
  3081. *
  3082. * Query various characteristics of provided ring buffer. What
  3083. * exactly is queries is determined by *flags*:
  3084. *
  3085. * * **BPF_RB_AVAIL_DATA**: Amount of data not yet consumed.
  3086. * * **BPF_RB_RING_SIZE**: The size of ring buffer.
  3087. * * **BPF_RB_CONS_POS**: Consumer position (can wrap around).
  3088. * * **BPF_RB_PROD_POS**: Producer(s) position (can wrap around).
  3089. *
  3090. * Data returned is just a momentary snapshot of actual values
  3091. * and could be inaccurate, so this facility should be used to
  3092. * power heuristics and for reporting, not to make 100% correct
  3093. * calculation.
  3094. *
  3095. * Returns
  3096. * Requested value, or 0, if *flags* are not recognized.
  3097. */
  3098. static __u64 (*bpf_ringbuf_query)(void *ringbuf, __u64 flags) = (void *) 134;
  3099. /*
  3100. * bpf_csum_level
  3101. *
  3102. * Change the skbs checksum level by one layer up or down, or
  3103. * reset it entirely to none in order to have the stack perform
  3104. * checksum validation. The level is applicable to the following
  3105. * protocols: TCP, UDP, GRE, SCTP, FCOE. For example, a decap of
  3106. * | ETH | IP | UDP | GUE | IP | TCP | into | ETH | IP | TCP |
  3107. * through **bpf_skb_adjust_room**\ () helper with passing in
  3108. * **BPF_F_ADJ_ROOM_NO_CSUM_RESET** flag would require one call
  3109. * to **bpf_csum_level**\ () with **BPF_CSUM_LEVEL_DEC** since
  3110. * the UDP header is removed. Similarly, an encap of the latter
  3111. * into the former could be accompanied by a helper call to
  3112. * **bpf_csum_level**\ () with **BPF_CSUM_LEVEL_INC** if the
  3113. * skb is still intended to be processed in higher layers of the
  3114. * stack instead of just egressing at tc.
  3115. *
  3116. * There are three supported level settings at this time:
  3117. *
  3118. * * **BPF_CSUM_LEVEL_INC**: Increases skb->csum_level for skbs
  3119. * with CHECKSUM_UNNECESSARY.
  3120. * * **BPF_CSUM_LEVEL_DEC**: Decreases skb->csum_level for skbs
  3121. * with CHECKSUM_UNNECESSARY.
  3122. * * **BPF_CSUM_LEVEL_RESET**: Resets skb->csum_level to 0 and
  3123. * sets CHECKSUM_NONE to force checksum validation by the stack.
  3124. * * **BPF_CSUM_LEVEL_QUERY**: No-op, returns the current
  3125. * skb->csum_level.
  3126. *
  3127. * Returns
  3128. * 0 on success, or a negative error in case of failure. In the
  3129. * case of **BPF_CSUM_LEVEL_QUERY**, the current skb->csum_level
  3130. * is returned or the error code -EACCES in case the skb is not
  3131. * subject to CHECKSUM_UNNECESSARY.
  3132. */
  3133. static long (*bpf_csum_level)(struct __sk_buff *skb, __u64 level) = (void *) 135;
  3134. /*
  3135. * bpf_skc_to_tcp6_sock
  3136. *
  3137. * Dynamically cast a *sk* pointer to a *tcp6_sock* pointer.
  3138. *
  3139. * Returns
  3140. * *sk* if casting is valid, or **NULL** otherwise.
  3141. */
  3142. static struct tcp6_sock *(*bpf_skc_to_tcp6_sock)(void *sk) = (void *) 136;
  3143. /*
  3144. * bpf_skc_to_tcp_sock
  3145. *
  3146. * Dynamically cast a *sk* pointer to a *tcp_sock* pointer.
  3147. *
  3148. * Returns
  3149. * *sk* if casting is valid, or **NULL** otherwise.
  3150. */
  3151. static struct tcp_sock *(*bpf_skc_to_tcp_sock)(void *sk) = (void *) 137;
  3152. /*
  3153. * bpf_skc_to_tcp_timewait_sock
  3154. *
  3155. * Dynamically cast a *sk* pointer to a *tcp_timewait_sock* pointer.
  3156. *
  3157. * Returns
  3158. * *sk* if casting is valid, or **NULL** otherwise.
  3159. */
  3160. static struct tcp_timewait_sock *(*bpf_skc_to_tcp_timewait_sock)(void *sk) = (void *) 138;
  3161. /*
  3162. * bpf_skc_to_tcp_request_sock
  3163. *
  3164. * Dynamically cast a *sk* pointer to a *tcp_request_sock* pointer.
  3165. *
  3166. * Returns
  3167. * *sk* if casting is valid, or **NULL** otherwise.
  3168. */
  3169. static struct tcp_request_sock *(*bpf_skc_to_tcp_request_sock)(void *sk) = (void *) 139;
  3170. /*
  3171. * bpf_skc_to_udp6_sock
  3172. *
  3173. * Dynamically cast a *sk* pointer to a *udp6_sock* pointer.
  3174. *
  3175. * Returns
  3176. * *sk* if casting is valid, or **NULL** otherwise.
  3177. */
  3178. static struct udp6_sock *(*bpf_skc_to_udp6_sock)(void *sk) = (void *) 140;
  3179. /*
  3180. * bpf_get_task_stack
  3181. *
  3182. * Return a user or a kernel stack in bpf program provided buffer.
  3183. * To achieve this, the helper needs *task*, which is a valid
  3184. * pointer to **struct task_struct**. To store the stacktrace, the
  3185. * bpf program provides *buf* with a nonnegative *size*.
  3186. *
  3187. * The last argument, *flags*, holds the number of stack frames to
  3188. * skip (from 0 to 255), masked with
  3189. * **BPF_F_SKIP_FIELD_MASK**. The next bits can be used to set
  3190. * the following flags:
  3191. *
  3192. * **BPF_F_USER_STACK**
  3193. * Collect a user space stack instead of a kernel stack.
  3194. * **BPF_F_USER_BUILD_ID**
  3195. * Collect buildid+offset instead of ips for user stack,
  3196. * only valid if **BPF_F_USER_STACK** is also specified.
  3197. *
  3198. * **bpf_get_task_stack**\ () can collect up to
  3199. * **PERF_MAX_STACK_DEPTH** both kernel and user frames, subject
  3200. * to sufficient large buffer size. Note that
  3201. * this limit can be controlled with the **sysctl** program, and
  3202. * that it should be manually increased in order to profile long
  3203. * user stacks (such as stacks for Java programs). To do so, use:
  3204. *
  3205. * ::
  3206. *
  3207. * # sysctl kernel.perf_event_max_stack=<new value>
  3208. *
  3209. * Returns
  3210. * The non-negative copied *buf* length equal to or less than
  3211. * *size* on success, or a negative error in case of failure.
  3212. */
  3213. static long (*bpf_get_task_stack)(struct task_struct *task, void *buf, __u32 size, __u64 flags) = (void *) 141;
  3214. /*
  3215. * bpf_load_hdr_opt
  3216. *
  3217. * Load header option. Support reading a particular TCP header
  3218. * option for bpf program (**BPF_PROG_TYPE_SOCK_OPS**).
  3219. *
  3220. * If *flags* is 0, it will search the option from the
  3221. * *skops*\ **->skb_data**. The comment in **struct bpf_sock_ops**
  3222. * has details on what skb_data contains under different
  3223. * *skops*\ **->op**.
  3224. *
  3225. * The first byte of the *searchby_res* specifies the
  3226. * kind that it wants to search.
  3227. *
  3228. * If the searching kind is an experimental kind
  3229. * (i.e. 253 or 254 according to RFC6994). It also
  3230. * needs to specify the "magic" which is either
  3231. * 2 bytes or 4 bytes. It then also needs to
  3232. * specify the size of the magic by using
  3233. * the 2nd byte which is "kind-length" of a TCP
  3234. * header option and the "kind-length" also
  3235. * includes the first 2 bytes "kind" and "kind-length"
  3236. * itself as a normal TCP header option also does.
  3237. *
  3238. * For example, to search experimental kind 254 with
  3239. * 2 byte magic 0xeB9F, the searchby_res should be
  3240. * [ 254, 4, 0xeB, 0x9F, 0, 0, .... 0 ].
  3241. *
  3242. * To search for the standard window scale option (3),
  3243. * the *searchby_res* should be [ 3, 0, 0, .... 0 ].
  3244. * Note, kind-length must be 0 for regular option.
  3245. *
  3246. * Searching for No-Op (0) and End-of-Option-List (1) are
  3247. * not supported.
  3248. *
  3249. * *len* must be at least 2 bytes which is the minimal size
  3250. * of a header option.
  3251. *
  3252. * Supported flags:
  3253. *
  3254. * * **BPF_LOAD_HDR_OPT_TCP_SYN** to search from the
  3255. * saved_syn packet or the just-received syn packet.
  3256. *
  3257. *
  3258. * Returns
  3259. * > 0 when found, the header option is copied to *searchby_res*.
  3260. * The return value is the total length copied. On failure, a
  3261. * negative error code is returned:
  3262. *
  3263. * **-EINVAL** if a parameter is invalid.
  3264. *
  3265. * **-ENOMSG** if the option is not found.
  3266. *
  3267. * **-ENOENT** if no syn packet is available when
  3268. * **BPF_LOAD_HDR_OPT_TCP_SYN** is used.
  3269. *
  3270. * **-ENOSPC** if there is not enough space. Only *len* number of
  3271. * bytes are copied.
  3272. *
  3273. * **-EFAULT** on failure to parse the header options in the
  3274. * packet.
  3275. *
  3276. * **-EPERM** if the helper cannot be used under the current
  3277. * *skops*\ **->op**.
  3278. */
  3279. static long (*bpf_load_hdr_opt)(struct bpf_sock_ops *skops, void *searchby_res, __u32 len, __u64 flags) = (void *) 142;
  3280. /*
  3281. * bpf_store_hdr_opt
  3282. *
  3283. * Store header option. The data will be copied
  3284. * from buffer *from* with length *len* to the TCP header.
  3285. *
  3286. * The buffer *from* should have the whole option that
  3287. * includes the kind, kind-length, and the actual
  3288. * option data. The *len* must be at least kind-length
  3289. * long. The kind-length does not have to be 4 byte
  3290. * aligned. The kernel will take care of the padding
  3291. * and setting the 4 bytes aligned value to th->doff.
  3292. *
  3293. * This helper will check for duplicated option
  3294. * by searching the same option in the outgoing skb.
  3295. *
  3296. * This helper can only be called during
  3297. * **BPF_SOCK_OPS_WRITE_HDR_OPT_CB**.
  3298. *
  3299. *
  3300. * Returns
  3301. * 0 on success, or negative error in case of failure:
  3302. *
  3303. * **-EINVAL** If param is invalid.
  3304. *
  3305. * **-ENOSPC** if there is not enough space in the header.
  3306. * Nothing has been written
  3307. *
  3308. * **-EEXIST** if the option already exists.
  3309. *
  3310. * **-EFAULT** on failure to parse the existing header options.
  3311. *
  3312. * **-EPERM** if the helper cannot be used under the current
  3313. * *skops*\ **->op**.
  3314. */
  3315. static long (*bpf_store_hdr_opt)(struct bpf_sock_ops *skops, const void *from, __u32 len, __u64 flags) = (void *) 143;
  3316. /*
  3317. * bpf_reserve_hdr_opt
  3318. *
  3319. * Reserve *len* bytes for the bpf header option. The
  3320. * space will be used by **bpf_store_hdr_opt**\ () later in
  3321. * **BPF_SOCK_OPS_WRITE_HDR_OPT_CB**.
  3322. *
  3323. * If **bpf_reserve_hdr_opt**\ () is called multiple times,
  3324. * the total number of bytes will be reserved.
  3325. *
  3326. * This helper can only be called during
  3327. * **BPF_SOCK_OPS_HDR_OPT_LEN_CB**.
  3328. *
  3329. *
  3330. * Returns
  3331. * 0 on success, or negative error in case of failure:
  3332. *
  3333. * **-EINVAL** if a parameter is invalid.
  3334. *
  3335. * **-ENOSPC** if there is not enough space in the header.
  3336. *
  3337. * **-EPERM** if the helper cannot be used under the current
  3338. * *skops*\ **->op**.
  3339. */
  3340. static long (*bpf_reserve_hdr_opt)(struct bpf_sock_ops *skops, __u32 len, __u64 flags) = (void *) 144;
  3341. /*
  3342. * bpf_inode_storage_get
  3343. *
  3344. * Get a bpf_local_storage from an *inode*.
  3345. *
  3346. * Logically, it could be thought of as getting the value from
  3347. * a *map* with *inode* as the **key**. From this
  3348. * perspective, the usage is not much different from
  3349. * **bpf_map_lookup_elem**\ (*map*, **&**\ *inode*) except this
  3350. * helper enforces the key must be an inode and the map must also
  3351. * be a **BPF_MAP_TYPE_INODE_STORAGE**.
  3352. *
  3353. * Underneath, the value is stored locally at *inode* instead of
  3354. * the *map*. The *map* is used as the bpf-local-storage
  3355. * "type". The bpf-local-storage "type" (i.e. the *map*) is
  3356. * searched against all bpf_local_storage residing at *inode*.
  3357. *
  3358. * An optional *flags* (**BPF_LOCAL_STORAGE_GET_F_CREATE**) can be
  3359. * used such that a new bpf_local_storage will be
  3360. * created if one does not exist. *value* can be used
  3361. * together with **BPF_LOCAL_STORAGE_GET_F_CREATE** to specify
  3362. * the initial value of a bpf_local_storage. If *value* is
  3363. * **NULL**, the new bpf_local_storage will be zero initialized.
  3364. *
  3365. * Returns
  3366. * A bpf_local_storage pointer is returned on success.
  3367. *
  3368. * **NULL** if not found or there was an error in adding
  3369. * a new bpf_local_storage.
  3370. */
  3371. static void *(*bpf_inode_storage_get)(void *map, void *inode, void *value, __u64 flags) = (void *) 145;
  3372. /*
  3373. * bpf_inode_storage_delete
  3374. *
  3375. * Delete a bpf_local_storage from an *inode*.
  3376. *
  3377. * Returns
  3378. * 0 on success.
  3379. *
  3380. * **-ENOENT** if the bpf_local_storage cannot be found.
  3381. */
  3382. static int (*bpf_inode_storage_delete)(void *map, void *inode) = (void *) 146;
  3383. /*
  3384. * bpf_d_path
  3385. *
  3386. * Return full path for given **struct path** object, which
  3387. * needs to be the kernel BTF *path* object. The path is
  3388. * returned in the provided buffer *buf* of size *sz* and
  3389. * is zero terminated.
  3390. *
  3391. *
  3392. * Returns
  3393. * On success, the strictly positive length of the string,
  3394. * including the trailing NUL character. On error, a negative
  3395. * value.
  3396. */
  3397. static long (*bpf_d_path)(struct path *path, char *buf, __u32 sz) = (void *) 147;
  3398. /*
  3399. * bpf_copy_from_user
  3400. *
  3401. * Read *size* bytes from user space address *user_ptr* and store
  3402. * the data in *dst*. This is a wrapper of **copy_from_user**\ ().
  3403. *
  3404. * Returns
  3405. * 0 on success, or a negative error in case of failure.
  3406. */
  3407. static long (*bpf_copy_from_user)(void *dst, __u32 size, const void *user_ptr) = (void *) 148;
  3408. /*
  3409. * bpf_snprintf_btf
  3410. *
  3411. * Use BTF to store a string representation of *ptr*->ptr in *str*,
  3412. * using *ptr*->type_id. This value should specify the type
  3413. * that *ptr*->ptr points to. LLVM __builtin_btf_type_id(type, 1)
  3414. * can be used to look up vmlinux BTF type ids. Traversing the
  3415. * data structure using BTF, the type information and values are
  3416. * stored in the first *str_size* - 1 bytes of *str*. Safe copy of
  3417. * the pointer data is carried out to avoid kernel crashes during
  3418. * operation. Smaller types can use string space on the stack;
  3419. * larger programs can use map data to store the string
  3420. * representation.
  3421. *
  3422. * The string can be subsequently shared with userspace via
  3423. * bpf_perf_event_output() or ring buffer interfaces.
  3424. * bpf_trace_printk() is to be avoided as it places too small
  3425. * a limit on string size to be useful.
  3426. *
  3427. * *flags* is a combination of
  3428. *
  3429. * **BTF_F_COMPACT**
  3430. * no formatting around type information
  3431. * **BTF_F_NONAME**
  3432. * no struct/union member names/types
  3433. * **BTF_F_PTR_RAW**
  3434. * show raw (unobfuscated) pointer values;
  3435. * equivalent to printk specifier %px.
  3436. * **BTF_F_ZERO**
  3437. * show zero-valued struct/union members; they
  3438. * are not displayed by default
  3439. *
  3440. *
  3441. * Returns
  3442. * The number of bytes that were written (or would have been
  3443. * written if output had to be truncated due to string size),
  3444. * or a negative error in cases of failure.
  3445. */
  3446. static long (*bpf_snprintf_btf)(char *str, __u32 str_size, struct btf_ptr *ptr, __u32 btf_ptr_size, __u64 flags) = (void *) 149;
  3447. /*
  3448. * bpf_seq_printf_btf
  3449. *
  3450. * Use BTF to write to seq_write a string representation of
  3451. * *ptr*->ptr, using *ptr*->type_id as per bpf_snprintf_btf().
  3452. * *flags* are identical to those used for bpf_snprintf_btf.
  3453. *
  3454. * Returns
  3455. * 0 on success or a negative error in case of failure.
  3456. */
  3457. static long (*bpf_seq_printf_btf)(struct seq_file *m, struct btf_ptr *ptr, __u32 ptr_size, __u64 flags) = (void *) 150;
  3458. /*
  3459. * bpf_skb_cgroup_classid
  3460. *
  3461. * See **bpf_get_cgroup_classid**\ () for the main description.
  3462. * This helper differs from **bpf_get_cgroup_classid**\ () in that
  3463. * the cgroup v1 net_cls class is retrieved only from the *skb*'s
  3464. * associated socket instead of the current process.
  3465. *
  3466. * Returns
  3467. * The id is returned or 0 in case the id could not be retrieved.
  3468. */
  3469. static __u64 (*bpf_skb_cgroup_classid)(struct __sk_buff *skb) = (void *) 151;
  3470. /*
  3471. * bpf_redirect_neigh
  3472. *
  3473. * Redirect the packet to another net device of index *ifindex*
  3474. * and fill in L2 addresses from neighboring subsystem. This helper
  3475. * is somewhat similar to **bpf_redirect**\ (), except that it
  3476. * populates L2 addresses as well, meaning, internally, the helper
  3477. * relies on the neighbor lookup for the L2 address of the nexthop.
  3478. *
  3479. * The helper will perform a FIB lookup based on the skb's
  3480. * networking header to get the address of the next hop, unless
  3481. * this is supplied by the caller in the *params* argument. The
  3482. * *plen* argument indicates the len of *params* and should be set
  3483. * to 0 if *params* is NULL.
  3484. *
  3485. * The *flags* argument is reserved and must be 0. The helper is
  3486. * currently only supported for tc BPF program types, and enabled
  3487. * for IPv4 and IPv6 protocols.
  3488. *
  3489. * Returns
  3490. * The helper returns **TC_ACT_REDIRECT** on success or
  3491. * **TC_ACT_SHOT** on error.
  3492. */
  3493. static long (*bpf_redirect_neigh)(__u32 ifindex, struct bpf_redir_neigh *params, int plen, __u64 flags) = (void *) 152;
  3494. /*
  3495. * bpf_per_cpu_ptr
  3496. *
  3497. * Take a pointer to a percpu ksym, *percpu_ptr*, and return a
  3498. * pointer to the percpu kernel variable on *cpu*. A ksym is an
  3499. * extern variable decorated with '__ksym'. For ksym, there is a
  3500. * global var (either static or global) defined of the same name
  3501. * in the kernel. The ksym is percpu if the global var is percpu.
  3502. * The returned pointer points to the global percpu var on *cpu*.
  3503. *
  3504. * bpf_per_cpu_ptr() has the same semantic as per_cpu_ptr() in the
  3505. * kernel, except that bpf_per_cpu_ptr() may return NULL. This
  3506. * happens if *cpu* is larger than nr_cpu_ids. The caller of
  3507. * bpf_per_cpu_ptr() must check the returned value.
  3508. *
  3509. * Returns
  3510. * A pointer pointing to the kernel percpu variable on *cpu*, or
  3511. * NULL, if *cpu* is invalid.
  3512. */
  3513. static void *(*bpf_per_cpu_ptr)(const void *percpu_ptr, __u32 cpu) = (void *) 153;
  3514. /*
  3515. * bpf_this_cpu_ptr
  3516. *
  3517. * Take a pointer to a percpu ksym, *percpu_ptr*, and return a
  3518. * pointer to the percpu kernel variable on this cpu. See the
  3519. * description of 'ksym' in **bpf_per_cpu_ptr**\ ().
  3520. *
  3521. * bpf_this_cpu_ptr() has the same semantic as this_cpu_ptr() in
  3522. * the kernel. Different from **bpf_per_cpu_ptr**\ (), it would
  3523. * never return NULL.
  3524. *
  3525. * Returns
  3526. * A pointer pointing to the kernel percpu variable on this cpu.
  3527. */
  3528. static void *(*bpf_this_cpu_ptr)(const void *percpu_ptr) = (void *) 154;
  3529. /*
  3530. * bpf_redirect_peer
  3531. *
  3532. * Redirect the packet to another net device of index *ifindex*.
  3533. * This helper is somewhat similar to **bpf_redirect**\ (), except
  3534. * that the redirection happens to the *ifindex*' peer device and
  3535. * the netns switch takes place from ingress to ingress without
  3536. * going through the CPU's backlog queue.
  3537. *
  3538. * The *flags* argument is reserved and must be 0. The helper is
  3539. * currently only supported for tc BPF program types at the ingress
  3540. * hook and for veth device types. The peer device must reside in a
  3541. * different network namespace.
  3542. *
  3543. * Returns
  3544. * The helper returns **TC_ACT_REDIRECT** on success or
  3545. * **TC_ACT_SHOT** on error.
  3546. */
  3547. static long (*bpf_redirect_peer)(__u32 ifindex, __u64 flags) = (void *) 155;
  3548. /*
  3549. * bpf_task_storage_get
  3550. *
  3551. * Get a bpf_local_storage from the *task*.
  3552. *
  3553. * Logically, it could be thought of as getting the value from
  3554. * a *map* with *task* as the **key**. From this
  3555. * perspective, the usage is not much different from
  3556. * **bpf_map_lookup_elem**\ (*map*, **&**\ *task*) except this
  3557. * helper enforces the key must be a task_struct and the map must also
  3558. * be a **BPF_MAP_TYPE_TASK_STORAGE**.
  3559. *
  3560. * Underneath, the value is stored locally at *task* instead of
  3561. * the *map*. The *map* is used as the bpf-local-storage
  3562. * "type". The bpf-local-storage "type" (i.e. the *map*) is
  3563. * searched against all bpf_local_storage residing at *task*.
  3564. *
  3565. * An optional *flags* (**BPF_LOCAL_STORAGE_GET_F_CREATE**) can be
  3566. * used such that a new bpf_local_storage will be
  3567. * created if one does not exist. *value* can be used
  3568. * together with **BPF_LOCAL_STORAGE_GET_F_CREATE** to specify
  3569. * the initial value of a bpf_local_storage. If *value* is
  3570. * **NULL**, the new bpf_local_storage will be zero initialized.
  3571. *
  3572. * Returns
  3573. * A bpf_local_storage pointer is returned on success.
  3574. *
  3575. * **NULL** if not found or there was an error in adding
  3576. * a new bpf_local_storage.
  3577. */
  3578. static void *(*bpf_task_storage_get)(void *map, struct task_struct *task, void *value, __u64 flags) = (void *) 156;
  3579. /*
  3580. * bpf_task_storage_delete
  3581. *
  3582. * Delete a bpf_local_storage from a *task*.
  3583. *
  3584. * Returns
  3585. * 0 on success.
  3586. *
  3587. * **-ENOENT** if the bpf_local_storage cannot be found.
  3588. */
  3589. static long (*bpf_task_storage_delete)(void *map, struct task_struct *task) = (void *) 157;
  3590. /*
  3591. * bpf_get_current_task_btf
  3592. *
  3593. * Return a BTF pointer to the "current" task.
  3594. * This pointer can also be used in helpers that accept an
  3595. * *ARG_PTR_TO_BTF_ID* of type *task_struct*.
  3596. *
  3597. * Returns
  3598. * Pointer to the current task.
  3599. */
  3600. static struct task_struct *(*bpf_get_current_task_btf)(void) = (void *) 158;
  3601. /*
  3602. * bpf_bprm_opts_set
  3603. *
  3604. * Set or clear certain options on *bprm*:
  3605. *
  3606. * **BPF_F_BPRM_SECUREEXEC** Set the secureexec bit
  3607. * which sets the **AT_SECURE** auxv for glibc. The bit
  3608. * is cleared if the flag is not specified.
  3609. *
  3610. * Returns
  3611. * **-EINVAL** if invalid *flags* are passed, zero otherwise.
  3612. */
  3613. static long (*bpf_bprm_opts_set)(struct linux_binprm *bprm, __u64 flags) = (void *) 159;
  3614. /*
  3615. * bpf_ktime_get_coarse_ns
  3616. *
  3617. * Return a coarse-grained version of the time elapsed since
  3618. * system boot, in nanoseconds. Does not include time the system
  3619. * was suspended.
  3620. *
  3621. * See: **clock_gettime**\ (**CLOCK_MONOTONIC_COARSE**)
  3622. *
  3623. * Returns
  3624. * Current *ktime*.
  3625. */
  3626. static __u64 (*bpf_ktime_get_coarse_ns)(void) = (void *) 160;
  3627. /*
  3628. * bpf_ima_inode_hash
  3629. *
  3630. * Returns the stored IMA hash of the *inode* (if it's available).
  3631. * If the hash is larger than *size*, then only *size*
  3632. * bytes will be copied to *dst*
  3633. *
  3634. * Returns
  3635. * The **hash_algo** is returned on success,
  3636. * **-EOPNOTSUP** if IMA is disabled or **-EINVAL** if
  3637. * invalid arguments are passed.
  3638. */
  3639. static long (*bpf_ima_inode_hash)(struct inode *inode, void *dst, __u32 size) = (void *) 161;
  3640. /*
  3641. * bpf_sock_from_file
  3642. *
  3643. * If the given file represents a socket, returns the associated
  3644. * socket.
  3645. *
  3646. * Returns
  3647. * A pointer to a struct socket on success or NULL if the file is
  3648. * not a socket.
  3649. */
  3650. static struct socket *(*bpf_sock_from_file)(struct file *file) = (void *) 162;
  3651. /*
  3652. * bpf_check_mtu
  3653. *
  3654. * Check packet size against exceeding MTU of net device (based
  3655. * on *ifindex*). This helper will likely be used in combination
  3656. * with helpers that adjust/change the packet size.
  3657. *
  3658. * The argument *len_diff* can be used for querying with a planned
  3659. * size change. This allows to check MTU prior to changing packet
  3660. * ctx. Providing a *len_diff* adjustment that is larger than the
  3661. * actual packet size (resulting in negative packet size) will in
  3662. * principle not exceed the MTU, which is why it is not considered
  3663. * a failure. Other BPF helpers are needed for performing the
  3664. * planned size change; therefore the responsibility for catching
  3665. * a negative packet size belongs in those helpers.
  3666. *
  3667. * Specifying *ifindex* zero means the MTU check is performed
  3668. * against the current net device. This is practical if this isn't
  3669. * used prior to redirect.
  3670. *
  3671. * On input *mtu_len* must be a valid pointer, else verifier will
  3672. * reject BPF program. If the value *mtu_len* is initialized to
  3673. * zero then the ctx packet size is use. When value *mtu_len* is
  3674. * provided as input this specify the L3 length that the MTU check
  3675. * is done against. Remember XDP and TC length operate at L2, but
  3676. * this value is L3 as this correlate to MTU and IP-header tot_len
  3677. * values which are L3 (similar behavior as bpf_fib_lookup).
  3678. *
  3679. * The Linux kernel route table can configure MTUs on a more
  3680. * specific per route level, which is not provided by this helper.
  3681. * For route level MTU checks use the **bpf_fib_lookup**\ ()
  3682. * helper.
  3683. *
  3684. * *ctx* is either **struct xdp_md** for XDP programs or
  3685. * **struct sk_buff** for tc cls_act programs.
  3686. *
  3687. * The *flags* argument can be a combination of one or more of the
  3688. * following values:
  3689. *
  3690. * **BPF_MTU_CHK_SEGS**
  3691. * This flag will only works for *ctx* **struct sk_buff**.
  3692. * If packet context contains extra packet segment buffers
  3693. * (often knows as GSO skb), then MTU check is harder to
  3694. * check at this point, because in transmit path it is
  3695. * possible for the skb packet to get re-segmented
  3696. * (depending on net device features). This could still be
  3697. * a MTU violation, so this flag enables performing MTU
  3698. * check against segments, with a different violation
  3699. * return code to tell it apart. Check cannot use len_diff.
  3700. *
  3701. * On return *mtu_len* pointer contains the MTU value of the net
  3702. * device. Remember the net device configured MTU is the L3 size,
  3703. * which is returned here and XDP and TC length operate at L2.
  3704. * Helper take this into account for you, but remember when using
  3705. * MTU value in your BPF-code.
  3706. *
  3707. *
  3708. * Returns
  3709. * * 0 on success, and populate MTU value in *mtu_len* pointer.
  3710. *
  3711. * * < 0 if any input argument is invalid (*mtu_len* not updated)
  3712. *
  3713. * MTU violations return positive values, but also populate MTU
  3714. * value in *mtu_len* pointer, as this can be needed for
  3715. * implementing PMTU handing:
  3716. *
  3717. * * **BPF_MTU_CHK_RET_FRAG_NEEDED**
  3718. * * **BPF_MTU_CHK_RET_SEGS_TOOBIG**
  3719. */
  3720. static long (*bpf_check_mtu)(void *ctx, __u32 ifindex, __u32 *mtu_len, __s32 len_diff, __u64 flags) = (void *) 163;
  3721. /*
  3722. * bpf_for_each_map_elem
  3723. *
  3724. * For each element in **map**, call **callback_fn** function with
  3725. * **map**, **callback_ctx** and other map-specific parameters.
  3726. * The **callback_fn** should be a static function and
  3727. * the **callback_ctx** should be a pointer to the stack.
  3728. * The **flags** is used to control certain aspects of the helper.
  3729. * Currently, the **flags** must be 0.
  3730. *
  3731. * The following are a list of supported map types and their
  3732. * respective expected callback signatures:
  3733. *
  3734. * BPF_MAP_TYPE_HASH, BPF_MAP_TYPE_PERCPU_HASH,
  3735. * BPF_MAP_TYPE_LRU_HASH, BPF_MAP_TYPE_LRU_PERCPU_HASH,
  3736. * BPF_MAP_TYPE_ARRAY, BPF_MAP_TYPE_PERCPU_ARRAY
  3737. *
  3738. * long (\*callback_fn)(struct bpf_map \*map, const void \*key, void \*value, void \*ctx);
  3739. *
  3740. * For per_cpu maps, the map_value is the value on the cpu where the
  3741. * bpf_prog is running.
  3742. *
  3743. * If **callback_fn** return 0, the helper will continue to the next
  3744. * element. If return value is 1, the helper will skip the rest of
  3745. * elements and return. Other return values are not used now.
  3746. *
  3747. *
  3748. * Returns
  3749. * The number of traversed map elements for success, **-EINVAL** for
  3750. * invalid **flags**.
  3751. */
  3752. static long (*bpf_for_each_map_elem)(void *map, void *callback_fn, void *callback_ctx, __u64 flags) = (void *) 164;
  3753. /*
  3754. * bpf_snprintf
  3755. *
  3756. * Outputs a string into the **str** buffer of size **str_size**
  3757. * based on a format string stored in a read-only map pointed by
  3758. * **fmt**.
  3759. *
  3760. * Each format specifier in **fmt** corresponds to one u64 element
  3761. * in the **data** array. For strings and pointers where pointees
  3762. * are accessed, only the pointer values are stored in the *data*
  3763. * array. The *data_len* is the size of *data* in bytes - must be
  3764. * a multiple of 8.
  3765. *
  3766. * Formats **%s** and **%p{i,I}{4,6}** require to read kernel
  3767. * memory. Reading kernel memory may fail due to either invalid
  3768. * address or valid address but requiring a major memory fault. If
  3769. * reading kernel memory fails, the string for **%s** will be an
  3770. * empty string, and the ip address for **%p{i,I}{4,6}** will be 0.
  3771. * Not returning error to bpf program is consistent with what
  3772. * **bpf_trace_printk**\ () does for now.
  3773. *
  3774. *
  3775. * Returns
  3776. * The strictly positive length of the formatted string, including
  3777. * the trailing zero character. If the return value is greater than
  3778. * **str_size**, **str** contains a truncated string, guaranteed to
  3779. * be zero-terminated except when **str_size** is 0.
  3780. *
  3781. * Or **-EBUSY** if the per-CPU memory copy buffer is busy.
  3782. */
  3783. static long (*bpf_snprintf)(char *str, __u32 str_size, const char *fmt, __u64 *data, __u32 data_len) = (void *) 165;
  3784. /*
  3785. * bpf_sys_bpf
  3786. *
  3787. * Execute bpf syscall with given arguments.
  3788. *
  3789. * Returns
  3790. * A syscall result.
  3791. */
  3792. static long (*bpf_sys_bpf)(__u32 cmd, void *attr, __u32 attr_size) = (void *) 166;
  3793. /*
  3794. * bpf_btf_find_by_name_kind
  3795. *
  3796. * Find BTF type with given name and kind in vmlinux BTF or in module's BTFs.
  3797. *
  3798. * Returns
  3799. * Returns btf_id and btf_obj_fd in lower and upper 32 bits.
  3800. */
  3801. static long (*bpf_btf_find_by_name_kind)(char *name, int name_sz, __u32 kind, int flags) = (void *) 167;
  3802. /*
  3803. * bpf_sys_close
  3804. *
  3805. * Execute close syscall for given FD.
  3806. *
  3807. * Returns
  3808. * A syscall result.
  3809. */
  3810. static long (*bpf_sys_close)(__u32 fd) = (void *) 168;
  3811. /*
  3812. * bpf_timer_init
  3813. *
  3814. * Initialize the timer.
  3815. * First 4 bits of *flags* specify clockid.
  3816. * Only CLOCK_MONOTONIC, CLOCK_REALTIME, CLOCK_BOOTTIME are allowed.
  3817. * All other bits of *flags* are reserved.
  3818. * The verifier will reject the program if *timer* is not from
  3819. * the same *map*.
  3820. *
  3821. * Returns
  3822. * 0 on success.
  3823. * **-EBUSY** if *timer* is already initialized.
  3824. * **-EINVAL** if invalid *flags* are passed.
  3825. * **-EPERM** if *timer* is in a map that doesn't have any user references.
  3826. * The user space should either hold a file descriptor to a map with timers
  3827. * or pin such map in bpffs. When map is unpinned or file descriptor is
  3828. * closed all timers in the map will be cancelled and freed.
  3829. */
  3830. static long (*bpf_timer_init)(struct bpf_timer *timer, void *map, __u64 flags) = (void *) 169;
  3831. /*
  3832. * bpf_timer_set_callback
  3833. *
  3834. * Configure the timer to call *callback_fn* static function.
  3835. *
  3836. * Returns
  3837. * 0 on success.
  3838. * **-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier.
  3839. * **-EPERM** if *timer* is in a map that doesn't have any user references.
  3840. * The user space should either hold a file descriptor to a map with timers
  3841. * or pin such map in bpffs. When map is unpinned or file descriptor is
  3842. * closed all timers in the map will be cancelled and freed.
  3843. */
  3844. static long (*bpf_timer_set_callback)(struct bpf_timer *timer, void *callback_fn) = (void *) 170;
  3845. /*
  3846. * bpf_timer_start
  3847. *
  3848. * Set timer expiration N nanoseconds from the current time. The
  3849. * configured callback will be invoked in soft irq context on some cpu
  3850. * and will not repeat unless another bpf_timer_start() is made.
  3851. * In such case the next invocation can migrate to a different cpu.
  3852. * Since struct bpf_timer is a field inside map element the map
  3853. * owns the timer. The bpf_timer_set_callback() will increment refcnt
  3854. * of BPF program to make sure that callback_fn code stays valid.
  3855. * When user space reference to a map reaches zero all timers
  3856. * in a map are cancelled and corresponding program's refcnts are
  3857. * decremented. This is done to make sure that Ctrl-C of a user
  3858. * process doesn't leave any timers running. If map is pinned in
  3859. * bpffs the callback_fn can re-arm itself indefinitely.
  3860. * bpf_map_update/delete_elem() helpers and user space sys_bpf commands
  3861. * cancel and free the timer in the given map element.
  3862. * The map can contain timers that invoke callback_fn-s from different
  3863. * programs. The same callback_fn can serve different timers from
  3864. * different maps if key/value layout matches across maps.
  3865. * Every bpf_timer_set_callback() can have different callback_fn.
  3866. *
  3867. * *flags* can be one of:
  3868. *
  3869. * **BPF_F_TIMER_ABS**
  3870. * Start the timer in absolute expire value instead of the
  3871. * default relative one.
  3872. * **BPF_F_TIMER_CPU_PIN**
  3873. * Timer will be pinned to the CPU of the caller.
  3874. *
  3875. *
  3876. * Returns
  3877. * 0 on success.
  3878. * **-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier
  3879. * or invalid *flags* are passed.
  3880. */
  3881. static long (*bpf_timer_start)(struct bpf_timer *timer, __u64 nsecs, __u64 flags) = (void *) 171;
  3882. /*
  3883. * bpf_timer_cancel
  3884. *
  3885. * Cancel the timer and wait for callback_fn to finish if it was running.
  3886. *
  3887. * Returns
  3888. * 0 if the timer was not active.
  3889. * 1 if the timer was active.
  3890. * **-EINVAL** if *timer* was not initialized with bpf_timer_init() earlier.
  3891. * **-EDEADLK** if callback_fn tried to call bpf_timer_cancel() on its
  3892. * own timer which would have led to a deadlock otherwise.
  3893. */
  3894. static long (*bpf_timer_cancel)(struct bpf_timer *timer) = (void *) 172;
  3895. /*
  3896. * bpf_get_func_ip
  3897. *
  3898. * Get address of the traced function (for tracing and kprobe programs).
  3899. *
  3900. * When called for kprobe program attached as uprobe it returns
  3901. * probe address for both entry and return uprobe.
  3902. *
  3903. *
  3904. * Returns
  3905. * Address of the traced function for kprobe.
  3906. * 0 for kprobes placed within the function (not at the entry).
  3907. * Address of the probe for uprobe and return uprobe.
  3908. */
  3909. static __u64 (*bpf_get_func_ip)(void *ctx) = (void *) 173;
  3910. /*
  3911. * bpf_get_attach_cookie
  3912. *
  3913. * Get bpf_cookie value provided (optionally) during the program
  3914. * attachment. It might be different for each individual
  3915. * attachment, even if BPF program itself is the same.
  3916. * Expects BPF program context *ctx* as a first argument.
  3917. *
  3918. * Supported for the following program types:
  3919. * - kprobe/uprobe;
  3920. * - tracepoint;
  3921. * - perf_event.
  3922. *
  3923. * Returns
  3924. * Value specified by user at BPF link creation/attachment time
  3925. * or 0, if it was not specified.
  3926. */
  3927. static __u64 (*bpf_get_attach_cookie)(void *ctx) = (void *) 174;
  3928. /*
  3929. * bpf_task_pt_regs
  3930. *
  3931. * Get the struct pt_regs associated with **task**.
  3932. *
  3933. * Returns
  3934. * A pointer to struct pt_regs.
  3935. */
  3936. static long (*bpf_task_pt_regs)(struct task_struct *task) = (void *) 175;
  3937. /*
  3938. * bpf_get_branch_snapshot
  3939. *
  3940. * Get branch trace from hardware engines like Intel LBR. The
  3941. * hardware engine is stopped shortly after the helper is
  3942. * called. Therefore, the user need to filter branch entries
  3943. * based on the actual use case. To capture branch trace
  3944. * before the trigger point of the BPF program, the helper
  3945. * should be called at the beginning of the BPF program.
  3946. *
  3947. * The data is stored as struct perf_branch_entry into output
  3948. * buffer *entries*. *size* is the size of *entries* in bytes.
  3949. * *flags* is reserved for now and must be zero.
  3950. *
  3951. *
  3952. * Returns
  3953. * On success, number of bytes written to *buf*. On error, a
  3954. * negative value.
  3955. *
  3956. * **-EINVAL** if *flags* is not zero.
  3957. *
  3958. * **-ENOENT** if architecture does not support branch records.
  3959. */
  3960. static long (*bpf_get_branch_snapshot)(void *entries, __u32 size, __u64 flags) = (void *) 176;
  3961. /*
  3962. * bpf_trace_vprintk
  3963. *
  3964. * Behaves like **bpf_trace_printk**\ () helper, but takes an array of u64
  3965. * to format and can handle more format args as a result.
  3966. *
  3967. * Arguments are to be used as in **bpf_seq_printf**\ () helper.
  3968. *
  3969. * Returns
  3970. * The number of bytes written to the buffer, or a negative error
  3971. * in case of failure.
  3972. */
  3973. static long (*bpf_trace_vprintk)(const char *fmt, __u32 fmt_size, const void *data, __u32 data_len) = (void *) 177;
  3974. /*
  3975. * bpf_skc_to_unix_sock
  3976. *
  3977. * Dynamically cast a *sk* pointer to a *unix_sock* pointer.
  3978. *
  3979. * Returns
  3980. * *sk* if casting is valid, or **NULL** otherwise.
  3981. */
  3982. static struct unix_sock *(*bpf_skc_to_unix_sock)(void *sk) = (void *) 178;
  3983. /*
  3984. * bpf_kallsyms_lookup_name
  3985. *
  3986. * Get the address of a kernel symbol, returned in *res*. *res* is
  3987. * set to 0 if the symbol is not found.
  3988. *
  3989. * Returns
  3990. * On success, zero. On error, a negative value.
  3991. *
  3992. * **-EINVAL** if *flags* is not zero.
  3993. *
  3994. * **-EINVAL** if string *name* is not the same size as *name_sz*.
  3995. *
  3996. * **-ENOENT** if symbol is not found.
  3997. *
  3998. * **-EPERM** if caller does not have permission to obtain kernel address.
  3999. */
  4000. static long (*bpf_kallsyms_lookup_name)(const char *name, int name_sz, int flags, __u64 *res) = (void *) 179;
  4001. /*
  4002. * bpf_find_vma
  4003. *
  4004. * Find vma of *task* that contains *addr*, call *callback_fn*
  4005. * function with *task*, *vma*, and *callback_ctx*.
  4006. * The *callback_fn* should be a static function and
  4007. * the *callback_ctx* should be a pointer to the stack.
  4008. * The *flags* is used to control certain aspects of the helper.
  4009. * Currently, the *flags* must be 0.
  4010. *
  4011. * The expected callback signature is
  4012. *
  4013. * long (\*callback_fn)(struct task_struct \*task, struct vm_area_struct \*vma, void \*callback_ctx);
  4014. *
  4015. *
  4016. * Returns
  4017. * 0 on success.
  4018. * **-ENOENT** if *task->mm* is NULL, or no vma contains *addr*.
  4019. * **-EBUSY** if failed to try lock mmap_lock.
  4020. * **-EINVAL** for invalid **flags**.
  4021. */
  4022. static long (*bpf_find_vma)(struct task_struct *task, __u64 addr, void *callback_fn, void *callback_ctx, __u64 flags) = (void *) 180;
  4023. /*
  4024. * bpf_loop
  4025. *
  4026. * For **nr_loops**, call **callback_fn** function
  4027. * with **callback_ctx** as the context parameter.
  4028. * The **callback_fn** should be a static function and
  4029. * the **callback_ctx** should be a pointer to the stack.
  4030. * The **flags** is used to control certain aspects of the helper.
  4031. * Currently, the **flags** must be 0. Currently, nr_loops is
  4032. * limited to 1 << 23 (~8 million) loops.
  4033. *
  4034. * long (\*callback_fn)(u32 index, void \*ctx);
  4035. *
  4036. * where **index** is the current index in the loop. The index
  4037. * is zero-indexed.
  4038. *
  4039. * If **callback_fn** returns 0, the helper will continue to the next
  4040. * loop. If return value is 1, the helper will skip the rest of
  4041. * the loops and return. Other return values are not used now,
  4042. * and will be rejected by the verifier.
  4043. *
  4044. *
  4045. * Returns
  4046. * The number of loops performed, **-EINVAL** for invalid **flags**,
  4047. * **-E2BIG** if **nr_loops** exceeds the maximum number of loops.
  4048. */
  4049. static long (*bpf_loop)(__u32 nr_loops, void *callback_fn, void *callback_ctx, __u64 flags) = (void *) 181;
  4050. /*
  4051. * bpf_strncmp
  4052. *
  4053. * Do strncmp() between **s1** and **s2**. **s1** doesn't need
  4054. * to be null-terminated and **s1_sz** is the maximum storage
  4055. * size of **s1**. **s2** must be a read-only string.
  4056. *
  4057. * Returns
  4058. * An integer less than, equal to, or greater than zero
  4059. * if the first **s1_sz** bytes of **s1** is found to be
  4060. * less than, to match, or be greater than **s2**.
  4061. */
  4062. static long (*bpf_strncmp)(const char *s1, __u32 s1_sz, const char *s2) = (void *) 182;
  4063. /*
  4064. * bpf_get_func_arg
  4065. *
  4066. * Get **n**-th argument register (zero based) of the traced function (for tracing programs)
  4067. * returned in **value**.
  4068. *
  4069. *
  4070. * Returns
  4071. * 0 on success.
  4072. * **-EINVAL** if n >= argument register count of traced function.
  4073. */
  4074. static long (*bpf_get_func_arg)(void *ctx, __u32 n, __u64 *value) = (void *) 183;
  4075. /*
  4076. * bpf_get_func_ret
  4077. *
  4078. * Get return value of the traced function (for tracing programs)
  4079. * in **value**.
  4080. *
  4081. *
  4082. * Returns
  4083. * 0 on success.
  4084. * **-EOPNOTSUPP** for tracing programs other than BPF_TRACE_FEXIT or BPF_MODIFY_RETURN.
  4085. */
  4086. static long (*bpf_get_func_ret)(void *ctx, __u64 *value) = (void *) 184;
  4087. /*
  4088. * bpf_get_func_arg_cnt
  4089. *
  4090. * Get number of registers of the traced function (for tracing programs) where
  4091. * function arguments are stored in these registers.
  4092. *
  4093. *
  4094. * Returns
  4095. * The number of argument registers of the traced function.
  4096. */
  4097. static long (*bpf_get_func_arg_cnt)(void *ctx) = (void *) 185;
  4098. /*
  4099. * bpf_get_retval
  4100. *
  4101. * Get the BPF program's return value that will be returned to the upper layers.
  4102. *
  4103. * This helper is currently supported by cgroup programs and only by the hooks
  4104. * where BPF program's return value is returned to the userspace via errno.
  4105. *
  4106. * Returns
  4107. * The BPF program's return value.
  4108. */
  4109. static int (*bpf_get_retval)(void) = (void *) 186;
  4110. /*
  4111. * bpf_set_retval
  4112. *
  4113. * Set the BPF program's return value that will be returned to the upper layers.
  4114. *
  4115. * This helper is currently supported by cgroup programs and only by the hooks
  4116. * where BPF program's return value is returned to the userspace via errno.
  4117. *
  4118. * Note that there is the following corner case where the program exports an error
  4119. * via bpf_set_retval but signals success via 'return 1':
  4120. *
  4121. * bpf_set_retval(-EPERM);
  4122. * return 1;
  4123. *
  4124. * In this case, the BPF program's return value will use helper's -EPERM. This
  4125. * still holds true for cgroup/bind{4,6} which supports extra 'return 3' success case.
  4126. *
  4127. *
  4128. * Returns
  4129. * 0 on success, or a negative error in case of failure.
  4130. */
  4131. static int (*bpf_set_retval)(int retval) = (void *) 187;
  4132. /*
  4133. * bpf_xdp_get_buff_len
  4134. *
  4135. * Get the total size of a given xdp buff (linear and paged area)
  4136. *
  4137. * Returns
  4138. * The total size of a given xdp buffer.
  4139. */
  4140. static __u64 (*bpf_xdp_get_buff_len)(struct xdp_md *xdp_md) = (void *) 188;
  4141. /*
  4142. * bpf_xdp_load_bytes
  4143. *
  4144. * This helper is provided as an easy way to load data from a
  4145. * xdp buffer. It can be used to load *len* bytes from *offset* from
  4146. * the frame associated to *xdp_md*, into the buffer pointed by
  4147. * *buf*.
  4148. *
  4149. * Returns
  4150. * 0 on success, or a negative error in case of failure.
  4151. */
  4152. static long (*bpf_xdp_load_bytes)(struct xdp_md *xdp_md, __u32 offset, void *buf, __u32 len) = (void *) 189;
  4153. /*
  4154. * bpf_xdp_store_bytes
  4155. *
  4156. * Store *len* bytes from buffer *buf* into the frame
  4157. * associated to *xdp_md*, at *offset*.
  4158. *
  4159. * Returns
  4160. * 0 on success, or a negative error in case of failure.
  4161. */
  4162. static long (*bpf_xdp_store_bytes)(struct xdp_md *xdp_md, __u32 offset, void *buf, __u32 len) = (void *) 190;
  4163. /*
  4164. * bpf_copy_from_user_task
  4165. *
  4166. * Read *size* bytes from user space address *user_ptr* in *tsk*'s
  4167. * address space, and stores the data in *dst*. *flags* is not
  4168. * used yet and is provided for future extensibility. This helper
  4169. * can only be used by sleepable programs.
  4170. *
  4171. * Returns
  4172. * 0 on success, or a negative error in case of failure. On error
  4173. * *dst* buffer is zeroed out.
  4174. */
  4175. static long (*bpf_copy_from_user_task)(void *dst, __u32 size, const void *user_ptr, struct task_struct *tsk, __u64 flags) = (void *) 191;
  4176. /*
  4177. * bpf_skb_set_tstamp
  4178. *
  4179. * Change the __sk_buff->tstamp_type to *tstamp_type*
  4180. * and set *tstamp* to the __sk_buff->tstamp together.
  4181. *
  4182. * If there is no need to change the __sk_buff->tstamp_type,
  4183. * the tstamp value can be directly written to __sk_buff->tstamp
  4184. * instead.
  4185. *
  4186. * BPF_SKB_TSTAMP_DELIVERY_MONO is the only tstamp that
  4187. * will be kept during bpf_redirect_*(). A non zero
  4188. * *tstamp* must be used with the BPF_SKB_TSTAMP_DELIVERY_MONO
  4189. * *tstamp_type*.
  4190. *
  4191. * A BPF_SKB_TSTAMP_UNSPEC *tstamp_type* can only be used
  4192. * with a zero *tstamp*.
  4193. *
  4194. * Only IPv4 and IPv6 skb->protocol are supported.
  4195. *
  4196. * This function is most useful when it needs to set a
  4197. * mono delivery time to __sk_buff->tstamp and then
  4198. * bpf_redirect_*() to the egress of an iface. For example,
  4199. * changing the (rcv) timestamp in __sk_buff->tstamp at
  4200. * ingress to a mono delivery time and then bpf_redirect_*()
  4201. * to sch_fq@phy-dev.
  4202. *
  4203. * Returns
  4204. * 0 on success.
  4205. * **-EINVAL** for invalid input
  4206. * **-EOPNOTSUPP** for unsupported protocol
  4207. */
  4208. static long (*bpf_skb_set_tstamp)(struct __sk_buff *skb, __u64 tstamp, __u32 tstamp_type) = (void *) 192;
  4209. /*
  4210. * bpf_ima_file_hash
  4211. *
  4212. * Returns a calculated IMA hash of the *file*.
  4213. * If the hash is larger than *size*, then only *size*
  4214. * bytes will be copied to *dst*
  4215. *
  4216. * Returns
  4217. * The **hash_algo** is returned on success,
  4218. * **-EOPNOTSUP** if the hash calculation failed or **-EINVAL** if
  4219. * invalid arguments are passed.
  4220. */
  4221. static long (*bpf_ima_file_hash)(struct file *file, void *dst, __u32 size) = (void *) 193;
  4222. /*
  4223. * bpf_kptr_xchg
  4224. *
  4225. * Exchange kptr at pointer *map_value* with *ptr*, and return the
  4226. * old value. *ptr* can be NULL, otherwise it must be a referenced
  4227. * pointer which will be released when this helper is called.
  4228. *
  4229. * Returns
  4230. * The old value of kptr (which can be NULL). The returned pointer
  4231. * if not NULL, is a reference which must be released using its
  4232. * corresponding release function, or moved into a BPF map before
  4233. * program exit.
  4234. */
  4235. static void *(*bpf_kptr_xchg)(void *map_value, void *ptr) = (void *) 194;
  4236. /*
  4237. * bpf_map_lookup_percpu_elem
  4238. *
  4239. * Perform a lookup in *percpu map* for an entry associated to
  4240. * *key* on *cpu*.
  4241. *
  4242. * Returns
  4243. * Map value associated to *key* on *cpu*, or **NULL** if no entry
  4244. * was found or *cpu* is invalid.
  4245. */
  4246. static void *(*bpf_map_lookup_percpu_elem)(void *map, const void *key, __u32 cpu) = (void *) 195;
  4247. /*
  4248. * bpf_skc_to_mptcp_sock
  4249. *
  4250. * Dynamically cast a *sk* pointer to a *mptcp_sock* pointer.
  4251. *
  4252. * Returns
  4253. * *sk* if casting is valid, or **NULL** otherwise.
  4254. */
  4255. static struct mptcp_sock *(*bpf_skc_to_mptcp_sock)(void *sk) = (void *) 196;
  4256. /*
  4257. * bpf_dynptr_from_mem
  4258. *
  4259. * Get a dynptr to local memory *data*.
  4260. *
  4261. * *data* must be a ptr to a map value.
  4262. * The maximum *size* supported is DYNPTR_MAX_SIZE.
  4263. * *flags* is currently unused.
  4264. *
  4265. * Returns
  4266. * 0 on success, -E2BIG if the size exceeds DYNPTR_MAX_SIZE,
  4267. * -EINVAL if flags is not 0.
  4268. */
  4269. static long (*bpf_dynptr_from_mem)(void *data, __u32 size, __u64 flags, struct bpf_dynptr *ptr) = (void *) 197;
  4270. /*
  4271. * bpf_ringbuf_reserve_dynptr
  4272. *
  4273. * Reserve *size* bytes of payload in a ring buffer *ringbuf*
  4274. * through the dynptr interface. *flags* must be 0.
  4275. *
  4276. * Please note that a corresponding bpf_ringbuf_submit_dynptr or
  4277. * bpf_ringbuf_discard_dynptr must be called on *ptr*, even if the
  4278. * reservation fails. This is enforced by the verifier.
  4279. *
  4280. * Returns
  4281. * 0 on success, or a negative error in case of failure.
  4282. */
  4283. static long (*bpf_ringbuf_reserve_dynptr)(void *ringbuf, __u32 size, __u64 flags, struct bpf_dynptr *ptr) = (void *) 198;
  4284. /*
  4285. * bpf_ringbuf_submit_dynptr
  4286. *
  4287. * Submit reserved ring buffer sample, pointed to by *data*,
  4288. * through the dynptr interface. This is a no-op if the dynptr is
  4289. * invalid/null.
  4290. *
  4291. * For more information on *flags*, please see
  4292. * 'bpf_ringbuf_submit'.
  4293. *
  4294. * Returns
  4295. * Nothing. Always succeeds.
  4296. */
  4297. static void (*bpf_ringbuf_submit_dynptr)(struct bpf_dynptr *ptr, __u64 flags) = (void *) 199;
  4298. /*
  4299. * bpf_ringbuf_discard_dynptr
  4300. *
  4301. * Discard reserved ring buffer sample through the dynptr
  4302. * interface. This is a no-op if the dynptr is invalid/null.
  4303. *
  4304. * For more information on *flags*, please see
  4305. * 'bpf_ringbuf_discard'.
  4306. *
  4307. * Returns
  4308. * Nothing. Always succeeds.
  4309. */
  4310. static void (*bpf_ringbuf_discard_dynptr)(struct bpf_dynptr *ptr, __u64 flags) = (void *) 200;
  4311. /*
  4312. * bpf_dynptr_read
  4313. *
  4314. * Read *len* bytes from *src* into *dst*, starting from *offset*
  4315. * into *src*.
  4316. * *flags* is currently unused.
  4317. *
  4318. * Returns
  4319. * 0 on success, -E2BIG if *offset* + *len* exceeds the length
  4320. * of *src*'s data, -EINVAL if *src* is an invalid dynptr or if
  4321. * *flags* is not 0.
  4322. */
  4323. static long (*bpf_dynptr_read)(void *dst, __u32 len, const struct bpf_dynptr *src, __u32 offset, __u64 flags) = (void *) 201;
  4324. /*
  4325. * bpf_dynptr_write
  4326. *
  4327. * Write *len* bytes from *src* into *dst*, starting from *offset*
  4328. * into *dst*.
  4329. *
  4330. * *flags* must be 0 except for skb-type dynptrs.
  4331. *
  4332. * For skb-type dynptrs:
  4333. * * All data slices of the dynptr are automatically
  4334. * invalidated after **bpf_dynptr_write**\ (). This is
  4335. * because writing may pull the skb and change the
  4336. * underlying packet buffer.
  4337. *
  4338. * * For *flags*, please see the flags accepted by
  4339. * **bpf_skb_store_bytes**\ ().
  4340. *
  4341. * Returns
  4342. * 0 on success, -E2BIG if *offset* + *len* exceeds the length
  4343. * of *dst*'s data, -EINVAL if *dst* is an invalid dynptr or if *dst*
  4344. * is a read-only dynptr or if *flags* is not correct. For skb-type dynptrs,
  4345. * other errors correspond to errors returned by **bpf_skb_store_bytes**\ ().
  4346. */
  4347. static long (*bpf_dynptr_write)(const struct bpf_dynptr *dst, __u32 offset, void *src, __u32 len, __u64 flags) = (void *) 202;
  4348. /*
  4349. * bpf_dynptr_data
  4350. *
  4351. * Get a pointer to the underlying dynptr data.
  4352. *
  4353. * *len* must be a statically known value. The returned data slice
  4354. * is invalidated whenever the dynptr is invalidated.
  4355. *
  4356. * skb and xdp type dynptrs may not use bpf_dynptr_data. They should
  4357. * instead use bpf_dynptr_slice and bpf_dynptr_slice_rdwr.
  4358. *
  4359. * Returns
  4360. * Pointer to the underlying dynptr data, NULL if the dynptr is
  4361. * read-only, if the dynptr is invalid, or if the offset and length
  4362. * is out of bounds.
  4363. */
  4364. static void *(*bpf_dynptr_data)(const struct bpf_dynptr *ptr, __u32 offset, __u32 len) = (void *) 203;
  4365. /*
  4366. * bpf_tcp_raw_gen_syncookie_ipv4
  4367. *
  4368. * Try to issue a SYN cookie for the packet with corresponding
  4369. * IPv4/TCP headers, *iph* and *th*, without depending on a
  4370. * listening socket.
  4371. *
  4372. * *iph* points to the IPv4 header.
  4373. *
  4374. * *th* points to the start of the TCP header, while *th_len*
  4375. * contains the length of the TCP header (at least
  4376. * **sizeof**\ (**struct tcphdr**)).
  4377. *
  4378. * Returns
  4379. * On success, lower 32 bits hold the generated SYN cookie in
  4380. * followed by 16 bits which hold the MSS value for that cookie,
  4381. * and the top 16 bits are unused.
  4382. *
  4383. * On failure, the returned value is one of the following:
  4384. *
  4385. * **-EINVAL** if *th_len* is invalid.
  4386. */
  4387. static __s64 (*bpf_tcp_raw_gen_syncookie_ipv4)(struct iphdr *iph, struct tcphdr *th, __u32 th_len) = (void *) 204;
  4388. /*
  4389. * bpf_tcp_raw_gen_syncookie_ipv6
  4390. *
  4391. * Try to issue a SYN cookie for the packet with corresponding
  4392. * IPv6/TCP headers, *iph* and *th*, without depending on a
  4393. * listening socket.
  4394. *
  4395. * *iph* points to the IPv6 header.
  4396. *
  4397. * *th* points to the start of the TCP header, while *th_len*
  4398. * contains the length of the TCP header (at least
  4399. * **sizeof**\ (**struct tcphdr**)).
  4400. *
  4401. * Returns
  4402. * On success, lower 32 bits hold the generated SYN cookie in
  4403. * followed by 16 bits which hold the MSS value for that cookie,
  4404. * and the top 16 bits are unused.
  4405. *
  4406. * On failure, the returned value is one of the following:
  4407. *
  4408. * **-EINVAL** if *th_len* is invalid.
  4409. *
  4410. * **-EPROTONOSUPPORT** if CONFIG_IPV6 is not builtin.
  4411. */
  4412. static __s64 (*bpf_tcp_raw_gen_syncookie_ipv6)(struct ipv6hdr *iph, struct tcphdr *th, __u32 th_len) = (void *) 205;
  4413. /*
  4414. * bpf_tcp_raw_check_syncookie_ipv4
  4415. *
  4416. * Check whether *iph* and *th* contain a valid SYN cookie ACK
  4417. * without depending on a listening socket.
  4418. *
  4419. * *iph* points to the IPv4 header.
  4420. *
  4421. * *th* points to the TCP header.
  4422. *
  4423. * Returns
  4424. * 0 if *iph* and *th* are a valid SYN cookie ACK.
  4425. *
  4426. * On failure, the returned value is one of the following:
  4427. *
  4428. * **-EACCES** if the SYN cookie is not valid.
  4429. */
  4430. static long (*bpf_tcp_raw_check_syncookie_ipv4)(struct iphdr *iph, struct tcphdr *th) = (void *) 206;
  4431. /*
  4432. * bpf_tcp_raw_check_syncookie_ipv6
  4433. *
  4434. * Check whether *iph* and *th* contain a valid SYN cookie ACK
  4435. * without depending on a listening socket.
  4436. *
  4437. * *iph* points to the IPv6 header.
  4438. *
  4439. * *th* points to the TCP header.
  4440. *
  4441. * Returns
  4442. * 0 if *iph* and *th* are a valid SYN cookie ACK.
  4443. *
  4444. * On failure, the returned value is one of the following:
  4445. *
  4446. * **-EACCES** if the SYN cookie is not valid.
  4447. *
  4448. * **-EPROTONOSUPPORT** if CONFIG_IPV6 is not builtin.
  4449. */
  4450. static long (*bpf_tcp_raw_check_syncookie_ipv6)(struct ipv6hdr *iph, struct tcphdr *th) = (void *) 207;
  4451. /*
  4452. * bpf_ktime_get_tai_ns
  4453. *
  4454. * A nonsettable system-wide clock derived from wall-clock time but
  4455. * ignoring leap seconds. This clock does not experience
  4456. * discontinuities and backwards jumps caused by NTP inserting leap
  4457. * seconds as CLOCK_REALTIME does.
  4458. *
  4459. * See: **clock_gettime**\ (**CLOCK_TAI**)
  4460. *
  4461. * Returns
  4462. * Current *ktime*.
  4463. */
  4464. static __u64 (*bpf_ktime_get_tai_ns)(void) = (void *) 208;
  4465. /*
  4466. * bpf_user_ringbuf_drain
  4467. *
  4468. * Drain samples from the specified user ring buffer, and invoke
  4469. * the provided callback for each such sample:
  4470. *
  4471. * long (\*callback_fn)(const struct bpf_dynptr \*dynptr, void \*ctx);
  4472. *
  4473. * If **callback_fn** returns 0, the helper will continue to try
  4474. * and drain the next sample, up to a maximum of
  4475. * BPF_MAX_USER_RINGBUF_SAMPLES samples. If the return value is 1,
  4476. * the helper will skip the rest of the samples and return. Other
  4477. * return values are not used now, and will be rejected by the
  4478. * verifier.
  4479. *
  4480. * Returns
  4481. * The number of drained samples if no error was encountered while
  4482. * draining samples, or 0 if no samples were present in the ring
  4483. * buffer. If a user-space producer was epoll-waiting on this map,
  4484. * and at least one sample was drained, they will receive an event
  4485. * notification notifying them of available space in the ring
  4486. * buffer. If the BPF_RB_NO_WAKEUP flag is passed to this
  4487. * function, no wakeup notification will be sent. If the
  4488. * BPF_RB_FORCE_WAKEUP flag is passed, a wakeup notification will
  4489. * be sent even if no sample was drained.
  4490. *
  4491. * On failure, the returned value is one of the following:
  4492. *
  4493. * **-EBUSY** if the ring buffer is contended, and another calling
  4494. * context was concurrently draining the ring buffer.
  4495. *
  4496. * **-EINVAL** if user-space is not properly tracking the ring
  4497. * buffer due to the producer position not being aligned to 8
  4498. * bytes, a sample not being aligned to 8 bytes, or the producer
  4499. * position not matching the advertised length of a sample.
  4500. *
  4501. * **-E2BIG** if user-space has tried to publish a sample which is
  4502. * larger than the size of the ring buffer, or which cannot fit
  4503. * within a struct bpf_dynptr.
  4504. */
  4505. static long (*bpf_user_ringbuf_drain)(void *map, void *callback_fn, void *ctx, __u64 flags) = (void *) 209;
  4506. /*
  4507. * bpf_cgrp_storage_get
  4508. *
  4509. * Get a bpf_local_storage from the *cgroup*.
  4510. *
  4511. * Logically, it could be thought of as getting the value from
  4512. * a *map* with *cgroup* as the **key**. From this
  4513. * perspective, the usage is not much different from
  4514. * **bpf_map_lookup_elem**\ (*map*, **&**\ *cgroup*) except this
  4515. * helper enforces the key must be a cgroup struct and the map must also
  4516. * be a **BPF_MAP_TYPE_CGRP_STORAGE**.
  4517. *
  4518. * In reality, the local-storage value is embedded directly inside of the
  4519. * *cgroup* object itself, rather than being located in the
  4520. * **BPF_MAP_TYPE_CGRP_STORAGE** map. When the local-storage value is
  4521. * queried for some *map* on a *cgroup* object, the kernel will perform an
  4522. * O(n) iteration over all of the live local-storage values for that
  4523. * *cgroup* object until the local-storage value for the *map* is found.
  4524. *
  4525. * An optional *flags* (**BPF_LOCAL_STORAGE_GET_F_CREATE**) can be
  4526. * used such that a new bpf_local_storage will be
  4527. * created if one does not exist. *value* can be used
  4528. * together with **BPF_LOCAL_STORAGE_GET_F_CREATE** to specify
  4529. * the initial value of a bpf_local_storage. If *value* is
  4530. * **NULL**, the new bpf_local_storage will be zero initialized.
  4531. *
  4532. * Returns
  4533. * A bpf_local_storage pointer is returned on success.
  4534. *
  4535. * **NULL** if not found or there was an error in adding
  4536. * a new bpf_local_storage.
  4537. */
  4538. static void *(*bpf_cgrp_storage_get)(void *map, struct cgroup *cgroup, void *value, __u64 flags) = (void *) 210;
  4539. /*
  4540. * bpf_cgrp_storage_delete
  4541. *
  4542. * Delete a bpf_local_storage from a *cgroup*.
  4543. *
  4544. * Returns
  4545. * 0 on success.
  4546. *
  4547. * **-ENOENT** if the bpf_local_storage cannot be found.
  4548. */
  4549. static long (*bpf_cgrp_storage_delete)(void *map, struct cgroup *cgroup) = (void *) 211;