mib2.c 100 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128
  1. /**
  2. * @file
  3. * Management Information Base II (RFC1213) objects and functions.
  4. *
  5. * @note the object identifiers for this MIB-2 and private MIB tree
  6. * must be kept in sorted ascending order. This to ensure correct getnext operation.
  7. */
  8. /*
  9. * Copyright (c) 2006 Axon Digital Design B.V., The Netherlands.
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or without modification,
  13. * are permitted provided that the following conditions are met:
  14. *
  15. * 1. Redistributions of source code must retain the above copyright notice,
  16. * this list of conditions and the following disclaimer.
  17. * 2. Redistributions in binary form must reproduce the above copyright notice,
  18. * this list of conditions and the following disclaimer in the documentation
  19. * and/or other materials provided with the distribution.
  20. * 3. The name of the author may not be used to endorse or promote products
  21. * derived from this software without specific prior written permission.
  22. *
  23. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
  24. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  25. * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
  26. * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  27. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
  28. * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  30. * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  31. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  32. * OF SUCH DAMAGE.
  33. *
  34. * Author: Christiaan Simons <christiaan.simons@axon.tv>
  35. */
  36. #include "lwip/opt.h"
  37. #if LWIP_SNMP /* don't build if not configured for use in lwipopts.h */
  38. #include "lwip/snmp.h"
  39. #include "lwip/netif.h"
  40. #include "lwip/ip.h"
  41. #include "lwip/ip_frag.h"
  42. #include "lwip/tcp.h"
  43. #include "lwip/udp.h"
  44. #include "lwip/snmp_asn1.h"
  45. #include "lwip/snmp_structs.h"
  46. #include "netif/etharp.h"
  47. /**
  48. * IANA assigned enterprise ID for lwIP is 26381
  49. * @see http://www.iana.org/assignments/enterprise-numbers
  50. *
  51. * @note this enterprise ID is assigned to the lwIP project,
  52. * all object identifiers living under this ID are assigned
  53. * by the lwIP maintainers (contact Christiaan Simons)!
  54. * @note don't change this define, use snmp_set_sysobjid()
  55. *
  56. * If you need to create your own private MIB you'll need
  57. * to apply for your own enterprise ID with IANA:
  58. * http://www.iana.org/numbers.html
  59. */
  60. #define SNMP_ENTERPRISE_ID 26381
  61. #define SNMP_SYSOBJID_LEN 7
  62. #define SNMP_SYSOBJID {1, 3, 6, 1, 4, 1, SNMP_ENTERPRISE_ID}
  63. #ifndef SNMP_SYSSERVICES
  64. #define SNMP_SYSSERVICES ((1 << 6) | (1 << 3) | ((IP_FORWARD) << 2))
  65. #endif
  66. #ifndef SNMP_GET_SYSUPTIME
  67. #define SNMP_GET_SYSUPTIME(sysuptime)
  68. #endif
  69. static void system_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
  70. static void system_get_value(struct obj_def *od, u16_t len, void *value);
  71. static u8_t system_set_test(struct obj_def *od, u16_t len, void *value);
  72. static void system_set_value(struct obj_def *od, u16_t len, void *value);
  73. static void interfaces_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
  74. static void interfaces_get_value(struct obj_def *od, u16_t len, void *value);
  75. static void ifentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
  76. static void ifentry_get_value(struct obj_def *od, u16_t len, void *value);
  77. #if !SNMP_SAFE_REQUESTS
  78. static u8_t ifentry_set_test (struct obj_def *od, u16_t len, void *value);
  79. static void ifentry_set_value (struct obj_def *od, u16_t len, void *value);
  80. #endif /* SNMP_SAFE_REQUESTS */
  81. static void atentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
  82. static void atentry_get_value(struct obj_def *od, u16_t len, void *value);
  83. static void ip_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
  84. static void ip_get_value(struct obj_def *od, u16_t len, void *value);
  85. static u8_t ip_set_test(struct obj_def *od, u16_t len, void *value);
  86. static void ip_addrentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
  87. static void ip_addrentry_get_value(struct obj_def *od, u16_t len, void *value);
  88. static void ip_rteentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
  89. static void ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value);
  90. static void ip_ntomentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
  91. static void ip_ntomentry_get_value(struct obj_def *od, u16_t len, void *value);
  92. static void icmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
  93. static void icmp_get_value(struct obj_def *od, u16_t len, void *value);
  94. #if LWIP_TCP
  95. static void tcp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
  96. static void tcp_get_value(struct obj_def *od, u16_t len, void *value);
  97. #ifdef THIS_SEEMS_UNUSED
  98. static void tcpconnentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
  99. static void tcpconnentry_get_value(struct obj_def *od, u16_t len, void *value);
  100. #endif
  101. #endif
  102. static void udp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
  103. static void udp_get_value(struct obj_def *od, u16_t len, void *value);
  104. static void udpentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
  105. static void udpentry_get_value(struct obj_def *od, u16_t len, void *value);
  106. static void snmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od);
  107. static void snmp_get_value(struct obj_def *od, u16_t len, void *value);
  108. static u8_t snmp_set_test(struct obj_def *od, u16_t len, void *value);
  109. static void snmp_set_value(struct obj_def *od, u16_t len, void *value);
  110. /* snmp .1.3.6.1.2.1.11 */
  111. const mib_scalar_node snmp_scalar = {
  112. &snmp_get_object_def,
  113. &snmp_get_value,
  114. &snmp_set_test,
  115. &snmp_set_value,
  116. MIB_NODE_SC,
  117. 0
  118. };
  119. const s32_t snmp_ids[28] = {
  120. 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16,
  121. 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30
  122. };
  123. struct mib_node* const snmp_nodes[28] = {
  124. (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
  125. (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
  126. (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
  127. (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
  128. (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
  129. (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
  130. (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
  131. (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
  132. (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
  133. (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
  134. (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
  135. (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
  136. (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar,
  137. (struct mib_node*)&snmp_scalar, (struct mib_node*)&snmp_scalar
  138. };
  139. const struct mib_array_node snmp = {
  140. &noleafs_get_object_def,
  141. &noleafs_get_value,
  142. &noleafs_set_test,
  143. &noleafs_set_value,
  144. MIB_NODE_AR,
  145. 28,
  146. snmp_ids,
  147. snmp_nodes
  148. };
  149. /* dot3 and EtherLike MIB not planned. (transmission .1.3.6.1.2.1.10) */
  150. /* historical (some say hysterical). (cmot .1.3.6.1.2.1.9) */
  151. /* lwIP has no EGP, thus may not implement it. (egp .1.3.6.1.2.1.8) */
  152. /* udp .1.3.6.1.2.1.7 */
  153. /** index root node for udpTable */
  154. struct mib_list_rootnode udp_root = {
  155. &noleafs_get_object_def,
  156. &noleafs_get_value,
  157. &noleafs_set_test,
  158. &noleafs_set_value,
  159. MIB_NODE_LR,
  160. 0,
  161. NULL,
  162. NULL,
  163. 0
  164. };
  165. const s32_t udpentry_ids[2] = { 1, 2 };
  166. struct mib_node* const udpentry_nodes[2] = {
  167. (struct mib_node*)&udp_root, (struct mib_node*)&udp_root,
  168. };
  169. const struct mib_array_node udpentry = {
  170. &noleafs_get_object_def,
  171. &noleafs_get_value,
  172. &noleafs_set_test,
  173. &noleafs_set_value,
  174. MIB_NODE_AR,
  175. 2,
  176. udpentry_ids,
  177. udpentry_nodes
  178. };
  179. s32_t udptable_id = 1;
  180. struct mib_node* udptable_node = (struct mib_node*)&udpentry;
  181. struct mib_ram_array_node udptable = {
  182. &noleafs_get_object_def,
  183. &noleafs_get_value,
  184. &noleafs_set_test,
  185. &noleafs_set_value,
  186. MIB_NODE_RA,
  187. 0,
  188. &udptable_id,
  189. &udptable_node
  190. };
  191. const mib_scalar_node udp_scalar = {
  192. &udp_get_object_def,
  193. &udp_get_value,
  194. &noleafs_set_test,
  195. &noleafs_set_value,
  196. MIB_NODE_SC,
  197. 0
  198. };
  199. const s32_t udp_ids[5] = { 1, 2, 3, 4, 5 };
  200. struct mib_node* const udp_nodes[5] = {
  201. (struct mib_node*)&udp_scalar, (struct mib_node*)&udp_scalar,
  202. (struct mib_node*)&udp_scalar, (struct mib_node*)&udp_scalar,
  203. (struct mib_node*)&udptable
  204. };
  205. const struct mib_array_node udp = {
  206. &noleafs_get_object_def,
  207. &noleafs_get_value,
  208. &noleafs_set_test,
  209. &noleafs_set_value,
  210. MIB_NODE_AR,
  211. 5,
  212. udp_ids,
  213. udp_nodes
  214. };
  215. /* tcp .1.3.6.1.2.1.6 */
  216. #if LWIP_TCP
  217. /* only if the TCP protocol is available may implement this group */
  218. /** index root node for tcpConnTable */
  219. struct mib_list_rootnode tcpconntree_root = {
  220. &noleafs_get_object_def,
  221. &noleafs_get_value,
  222. &noleafs_set_test,
  223. &noleafs_set_value,
  224. MIB_NODE_LR,
  225. 0,
  226. NULL,
  227. NULL,
  228. 0
  229. };
  230. const s32_t tcpconnentry_ids[5] = { 1, 2, 3, 4, 5 };
  231. struct mib_node* const tcpconnentry_nodes[5] = {
  232. (struct mib_node*)&tcpconntree_root, (struct mib_node*)&tcpconntree_root,
  233. (struct mib_node*)&tcpconntree_root, (struct mib_node*)&tcpconntree_root,
  234. (struct mib_node*)&tcpconntree_root
  235. };
  236. const struct mib_array_node tcpconnentry = {
  237. &noleafs_get_object_def,
  238. &noleafs_get_value,
  239. &noleafs_set_test,
  240. &noleafs_set_value,
  241. MIB_NODE_AR,
  242. 5,
  243. tcpconnentry_ids,
  244. tcpconnentry_nodes
  245. };
  246. s32_t tcpconntable_id = 1;
  247. struct mib_node* tcpconntable_node = (struct mib_node*)&tcpconnentry;
  248. struct mib_ram_array_node tcpconntable = {
  249. &noleafs_get_object_def,
  250. &noleafs_get_value,
  251. &noleafs_set_test,
  252. &noleafs_set_value,
  253. MIB_NODE_RA,
  254. /** @todo update maxlength when inserting / deleting from table
  255. 0 when table is empty, 1 when more than one entry */
  256. 0,
  257. &tcpconntable_id,
  258. &tcpconntable_node
  259. };
  260. const mib_scalar_node tcp_scalar = {
  261. &tcp_get_object_def,
  262. &tcp_get_value,
  263. &noleafs_set_test,
  264. &noleafs_set_value,
  265. MIB_NODE_SC,
  266. 0
  267. };
  268. const s32_t tcp_ids[15] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 };
  269. struct mib_node* const tcp_nodes[15] = {
  270. (struct mib_node*)&tcp_scalar, (struct mib_node*)&tcp_scalar,
  271. (struct mib_node*)&tcp_scalar, (struct mib_node*)&tcp_scalar,
  272. (struct mib_node*)&tcp_scalar, (struct mib_node*)&tcp_scalar,
  273. (struct mib_node*)&tcp_scalar, (struct mib_node*)&tcp_scalar,
  274. (struct mib_node*)&tcp_scalar, (struct mib_node*)&tcp_scalar,
  275. (struct mib_node*)&tcp_scalar, (struct mib_node*)&tcp_scalar,
  276. (struct mib_node*)&tcpconntable, (struct mib_node*)&tcp_scalar,
  277. (struct mib_node*)&tcp_scalar
  278. };
  279. const struct mib_array_node tcp = {
  280. &noleafs_get_object_def,
  281. &noleafs_get_value,
  282. &noleafs_set_test,
  283. &noleafs_set_value,
  284. MIB_NODE_AR,
  285. 15,
  286. tcp_ids,
  287. tcp_nodes
  288. };
  289. #endif
  290. /* icmp .1.3.6.1.2.1.5 */
  291. const mib_scalar_node icmp_scalar = {
  292. &icmp_get_object_def,
  293. &icmp_get_value,
  294. &noleafs_set_test,
  295. &noleafs_set_value,
  296. MIB_NODE_SC,
  297. 0
  298. };
  299. const s32_t icmp_ids[26] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 };
  300. struct mib_node* const icmp_nodes[26] = {
  301. (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
  302. (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
  303. (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
  304. (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
  305. (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
  306. (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
  307. (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
  308. (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
  309. (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
  310. (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
  311. (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
  312. (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar,
  313. (struct mib_node*)&icmp_scalar, (struct mib_node*)&icmp_scalar
  314. };
  315. const struct mib_array_node icmp = {
  316. &noleafs_get_object_def,
  317. &noleafs_get_value,
  318. &noleafs_set_test,
  319. &noleafs_set_value,
  320. MIB_NODE_AR,
  321. 26,
  322. icmp_ids,
  323. icmp_nodes
  324. };
  325. /** index root node for ipNetToMediaTable */
  326. struct mib_list_rootnode ipntomtree_root = {
  327. &noleafs_get_object_def,
  328. &noleafs_get_value,
  329. &noleafs_set_test,
  330. &noleafs_set_value,
  331. MIB_NODE_LR,
  332. 0,
  333. NULL,
  334. NULL,
  335. 0
  336. };
  337. const s32_t ipntomentry_ids[4] = { 1, 2, 3, 4 };
  338. struct mib_node* const ipntomentry_nodes[4] = {
  339. (struct mib_node*)&ipntomtree_root, (struct mib_node*)&ipntomtree_root,
  340. (struct mib_node*)&ipntomtree_root, (struct mib_node*)&ipntomtree_root
  341. };
  342. const struct mib_array_node ipntomentry = {
  343. &noleafs_get_object_def,
  344. &noleafs_get_value,
  345. &noleafs_set_test,
  346. &noleafs_set_value,
  347. MIB_NODE_AR,
  348. 4,
  349. ipntomentry_ids,
  350. ipntomentry_nodes
  351. };
  352. s32_t ipntomtable_id = 1;
  353. struct mib_node* ipntomtable_node = (struct mib_node*)&ipntomentry;
  354. struct mib_ram_array_node ipntomtable = {
  355. &noleafs_get_object_def,
  356. &noleafs_get_value,
  357. &noleafs_set_test,
  358. &noleafs_set_value,
  359. MIB_NODE_RA,
  360. 0,
  361. &ipntomtable_id,
  362. &ipntomtable_node
  363. };
  364. /** index root node for ipRouteTable */
  365. struct mib_list_rootnode iprtetree_root = {
  366. &noleafs_get_object_def,
  367. &noleafs_get_value,
  368. &noleafs_set_test,
  369. &noleafs_set_value,
  370. MIB_NODE_LR,
  371. 0,
  372. NULL,
  373. NULL,
  374. 0
  375. };
  376. const s32_t iprteentry_ids[13] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
  377. struct mib_node* const iprteentry_nodes[13] = {
  378. (struct mib_node*)&iprtetree_root, (struct mib_node*)&iprtetree_root,
  379. (struct mib_node*)&iprtetree_root, (struct mib_node*)&iprtetree_root,
  380. (struct mib_node*)&iprtetree_root, (struct mib_node*)&iprtetree_root,
  381. (struct mib_node*)&iprtetree_root, (struct mib_node*)&iprtetree_root,
  382. (struct mib_node*)&iprtetree_root, (struct mib_node*)&iprtetree_root,
  383. (struct mib_node*)&iprtetree_root, (struct mib_node*)&iprtetree_root,
  384. (struct mib_node*)&iprtetree_root
  385. };
  386. const struct mib_array_node iprteentry = {
  387. &noleafs_get_object_def,
  388. &noleafs_get_value,
  389. &noleafs_set_test,
  390. &noleafs_set_value,
  391. MIB_NODE_AR,
  392. 13,
  393. iprteentry_ids,
  394. iprteentry_nodes
  395. };
  396. s32_t iprtetable_id = 1;
  397. struct mib_node* iprtetable_node = (struct mib_node*)&iprteentry;
  398. struct mib_ram_array_node iprtetable = {
  399. &noleafs_get_object_def,
  400. &noleafs_get_value,
  401. &noleafs_set_test,
  402. &noleafs_set_value,
  403. MIB_NODE_RA,
  404. 0,
  405. &iprtetable_id,
  406. &iprtetable_node
  407. };
  408. /** index root node for ipAddrTable */
  409. struct mib_list_rootnode ipaddrtree_root = {
  410. &noleafs_get_object_def,
  411. &noleafs_get_value,
  412. &noleafs_set_test,
  413. &noleafs_set_value,
  414. MIB_NODE_LR,
  415. 0,
  416. NULL,
  417. NULL,
  418. 0
  419. };
  420. const s32_t ipaddrentry_ids[5] = { 1, 2, 3, 4, 5 };
  421. struct mib_node* const ipaddrentry_nodes[5] = {
  422. (struct mib_node*)&ipaddrtree_root,
  423. (struct mib_node*)&ipaddrtree_root,
  424. (struct mib_node*)&ipaddrtree_root,
  425. (struct mib_node*)&ipaddrtree_root,
  426. (struct mib_node*)&ipaddrtree_root
  427. };
  428. const struct mib_array_node ipaddrentry = {
  429. &noleafs_get_object_def,
  430. &noleafs_get_value,
  431. &noleafs_set_test,
  432. &noleafs_set_value,
  433. MIB_NODE_AR,
  434. 5,
  435. ipaddrentry_ids,
  436. ipaddrentry_nodes
  437. };
  438. s32_t ipaddrtable_id = 1;
  439. struct mib_node* ipaddrtable_node = (struct mib_node*)&ipaddrentry;
  440. struct mib_ram_array_node ipaddrtable = {
  441. &noleafs_get_object_def,
  442. &noleafs_get_value,
  443. &noleafs_set_test,
  444. &noleafs_set_value,
  445. MIB_NODE_RA,
  446. 0,
  447. &ipaddrtable_id,
  448. &ipaddrtable_node
  449. };
  450. /* ip .1.3.6.1.2.1.4 */
  451. const mib_scalar_node ip_scalar = {
  452. &ip_get_object_def,
  453. &ip_get_value,
  454. &ip_set_test,
  455. &noleafs_set_value,
  456. MIB_NODE_SC,
  457. 0
  458. };
  459. const s32_t ip_ids[23] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23 };
  460. struct mib_node* const ip_nodes[23] = {
  461. (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
  462. (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
  463. (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
  464. (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
  465. (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
  466. (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
  467. (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
  468. (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
  469. (struct mib_node*)&ip_scalar, (struct mib_node*)&ip_scalar,
  470. (struct mib_node*)&ip_scalar, (struct mib_node*)&ipaddrtable,
  471. (struct mib_node*)&iprtetable, (struct mib_node*)&ipntomtable,
  472. (struct mib_node*)&ip_scalar
  473. };
  474. const struct mib_array_node mib2_ip = {
  475. &noleafs_get_object_def,
  476. &noleafs_get_value,
  477. &noleafs_set_test,
  478. &noleafs_set_value,
  479. MIB_NODE_AR,
  480. 23,
  481. ip_ids,
  482. ip_nodes
  483. };
  484. /** index root node for atTable */
  485. struct mib_list_rootnode arptree_root = {
  486. &noleafs_get_object_def,
  487. &noleafs_get_value,
  488. &noleafs_set_test,
  489. &noleafs_set_value,
  490. MIB_NODE_LR,
  491. 0,
  492. NULL,
  493. NULL,
  494. 0
  495. };
  496. const s32_t atentry_ids[3] = { 1, 2, 3 };
  497. struct mib_node* const atentry_nodes[3] = {
  498. (struct mib_node*)&arptree_root,
  499. (struct mib_node*)&arptree_root,
  500. (struct mib_node*)&arptree_root
  501. };
  502. const struct mib_array_node atentry = {
  503. &noleafs_get_object_def,
  504. &noleafs_get_value,
  505. &noleafs_set_test,
  506. &noleafs_set_value,
  507. MIB_NODE_AR,
  508. 3,
  509. atentry_ids,
  510. atentry_nodes
  511. };
  512. const s32_t attable_id = 1;
  513. struct mib_node* const attable_node = (struct mib_node*)&atentry;
  514. const struct mib_array_node attable = {
  515. &noleafs_get_object_def,
  516. &noleafs_get_value,
  517. &noleafs_set_test,
  518. &noleafs_set_value,
  519. MIB_NODE_AR,
  520. 1,
  521. &attable_id,
  522. &attable_node
  523. };
  524. /* at .1.3.6.1.2.1.3 */
  525. s32_t at_id = 1;
  526. struct mib_node* mib2_at_node = (struct mib_node*)&attable;
  527. struct mib_ram_array_node at = {
  528. &noleafs_get_object_def,
  529. &noleafs_get_value,
  530. &noleafs_set_test,
  531. &noleafs_set_value,
  532. MIB_NODE_RA,
  533. 0,
  534. &at_id,
  535. &mib2_at_node
  536. };
  537. /** index root node for ifTable */
  538. struct mib_list_rootnode iflist_root = {
  539. &ifentry_get_object_def,
  540. &ifentry_get_value,
  541. #if SNMP_SAFE_REQUESTS
  542. &noleafs_set_test,
  543. &noleafs_set_value,
  544. #else /* SNMP_SAFE_REQUESTS */
  545. &ifentry_set_test,
  546. &ifentry_set_value,
  547. #endif /* SNMP_SAFE_REQUESTS */
  548. MIB_NODE_LR,
  549. 0,
  550. NULL,
  551. NULL,
  552. 0
  553. };
  554. const s32_t ifentry_ids[22] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22 };
  555. struct mib_node* const ifentry_nodes[22] = {
  556. (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
  557. (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
  558. (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
  559. (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
  560. (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
  561. (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
  562. (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
  563. (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
  564. (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
  565. (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root,
  566. (struct mib_node*)&iflist_root, (struct mib_node*)&iflist_root
  567. };
  568. const struct mib_array_node ifentry = {
  569. &noleafs_get_object_def,
  570. &noleafs_get_value,
  571. &noleafs_set_test,
  572. &noleafs_set_value,
  573. MIB_NODE_AR,
  574. 22,
  575. ifentry_ids,
  576. ifentry_nodes
  577. };
  578. s32_t iftable_id = 1;
  579. struct mib_node* iftable_node = (struct mib_node*)&ifentry;
  580. struct mib_ram_array_node iftable = {
  581. &noleafs_get_object_def,
  582. &noleafs_get_value,
  583. &noleafs_set_test,
  584. &noleafs_set_value,
  585. MIB_NODE_RA,
  586. 0,
  587. &iftable_id,
  588. &iftable_node
  589. };
  590. /* interfaces .1.3.6.1.2.1.2 */
  591. const mib_scalar_node interfaces_scalar = {
  592. &interfaces_get_object_def,
  593. &interfaces_get_value,
  594. &noleafs_set_test,
  595. &noleafs_set_value,
  596. MIB_NODE_SC,
  597. 0
  598. };
  599. const s32_t interfaces_ids[2] = { 1, 2 };
  600. struct mib_node* const interfaces_nodes[2] = {
  601. (struct mib_node*)&interfaces_scalar, (struct mib_node*)&iftable
  602. };
  603. const struct mib_array_node interfaces = {
  604. &noleafs_get_object_def,
  605. &noleafs_get_value,
  606. &noleafs_set_test,
  607. &noleafs_set_value,
  608. MIB_NODE_AR,
  609. 2,
  610. interfaces_ids,
  611. interfaces_nodes
  612. };
  613. /* 0 1 2 3 4 5 6 */
  614. /* system .1.3.6.1.2.1.1 */
  615. const mib_scalar_node sys_tem_scalar = {
  616. &system_get_object_def,
  617. &system_get_value,
  618. &system_set_test,
  619. &system_set_value,
  620. MIB_NODE_SC,
  621. 0
  622. };
  623. const s32_t sys_tem_ids[7] = { 1, 2, 3, 4, 5, 6, 7 };
  624. struct mib_node* const sys_tem_nodes[7] = {
  625. (struct mib_node*)&sys_tem_scalar, (struct mib_node*)&sys_tem_scalar,
  626. (struct mib_node*)&sys_tem_scalar, (struct mib_node*)&sys_tem_scalar,
  627. (struct mib_node*)&sys_tem_scalar, (struct mib_node*)&sys_tem_scalar,
  628. (struct mib_node*)&sys_tem_scalar
  629. };
  630. /* work around name issue with 'sys_tem', some compiler(s?) seem to reserve 'system' */
  631. const struct mib_array_node sys_tem = {
  632. &noleafs_get_object_def,
  633. &noleafs_get_value,
  634. &noleafs_set_test,
  635. &noleafs_set_value,
  636. MIB_NODE_AR,
  637. 7,
  638. sys_tem_ids,
  639. sys_tem_nodes
  640. };
  641. /* mib-2 .1.3.6.1.2.1 */
  642. #if LWIP_TCP
  643. #define MIB2_GROUPS 8
  644. #else
  645. #define MIB2_GROUPS 7
  646. #endif
  647. const s32_t mib2_ids[MIB2_GROUPS] =
  648. {
  649. 1,
  650. 2,
  651. 3,
  652. 4,
  653. 5,
  654. #if LWIP_TCP
  655. 6,
  656. #endif
  657. 7,
  658. 11
  659. };
  660. struct mib_node* const mib2_nodes[MIB2_GROUPS] = {
  661. (struct mib_node*)&sys_tem,
  662. (struct mib_node*)&interfaces,
  663. (struct mib_node*)&at,
  664. (struct mib_node*)&mib2_ip,
  665. (struct mib_node*)&icmp,
  666. #if LWIP_TCP
  667. (struct mib_node*)&tcp,
  668. #endif
  669. (struct mib_node*)&udp,
  670. (struct mib_node*)&snmp
  671. };
  672. const struct mib_array_node mib2 = {
  673. &noleafs_get_object_def,
  674. &noleafs_get_value,
  675. &noleafs_set_test,
  676. &noleafs_set_value,
  677. MIB_NODE_AR,
  678. MIB2_GROUPS,
  679. mib2_ids,
  680. mib2_nodes
  681. };
  682. /* mgmt .1.3.6.1.2 */
  683. const s32_t mgmt_ids[1] = { 1 };
  684. struct mib_node* const mgmt_nodes[1] = { (struct mib_node*)&mib2 };
  685. const struct mib_array_node mgmt = {
  686. &noleafs_get_object_def,
  687. &noleafs_get_value,
  688. &noleafs_set_test,
  689. &noleafs_set_value,
  690. MIB_NODE_AR,
  691. 1,
  692. mgmt_ids,
  693. mgmt_nodes
  694. };
  695. /* internet .1.3.6.1 */
  696. #if SNMP_PRIVATE_MIB
  697. s32_t internet_ids[2] = { 2, 4 };
  698. struct mib_node* const internet_nodes[2] = { (struct mib_node*)&mgmt, (struct mib_node*)&mib_private };
  699. const struct mib_array_node internet = {
  700. &noleafs_get_object_def,
  701. &noleafs_get_value,
  702. &noleafs_set_test,
  703. &noleafs_set_value,
  704. MIB_NODE_AR,
  705. 2,
  706. internet_ids,
  707. internet_nodes
  708. };
  709. #else
  710. const s32_t internet_ids[1] = { 2 };
  711. struct mib_node* const internet_nodes[1] = { (struct mib_node*)&mgmt };
  712. const struct mib_array_node internet = {
  713. &noleafs_get_object_def,
  714. &noleafs_get_value,
  715. &noleafs_set_test,
  716. &noleafs_set_value,
  717. MIB_NODE_AR,
  718. 1,
  719. internet_ids,
  720. internet_nodes
  721. };
  722. #endif
  723. /** mib-2.system.sysObjectID */
  724. static struct snmp_obj_id sysobjid = {SNMP_SYSOBJID_LEN, SNMP_SYSOBJID};
  725. /** enterprise ID for generic TRAPs, .iso.org.dod.internet.mgmt.mib-2.snmp */
  726. static struct snmp_obj_id snmpgrp_id = {7,{1,3,6,1,2,1,11}};
  727. /** mib-2.system.sysServices */
  728. static const s32_t sysservices = SNMP_SYSSERVICES;
  729. /** mib-2.system.sysDescr */
  730. static const u8_t sysdescr_len_default = 4;
  731. static const u8_t sysdescr_default[] = "lwIP";
  732. static u8_t* sysdescr_len_ptr = (u8_t*)&sysdescr_len_default;
  733. static u8_t* sysdescr_ptr = (u8_t*)&sysdescr_default[0];
  734. /** mib-2.system.sysContact */
  735. static const u8_t syscontact_len_default = 0;
  736. static const u8_t syscontact_default[] = "";
  737. static u8_t* syscontact_len_ptr = (u8_t*)&syscontact_len_default;
  738. static u8_t* syscontact_ptr = (u8_t*)&syscontact_default[0];
  739. /** mib-2.system.sysName */
  740. static const u8_t sysname_len_default = 8;
  741. static const u8_t sysname_default[] = "FQDN-unk";
  742. static u8_t* sysname_len_ptr = (u8_t*)&sysname_len_default;
  743. static u8_t* sysname_ptr = (u8_t*)&sysname_default[0];
  744. /** mib-2.system.sysLocation */
  745. static const u8_t syslocation_len_default = 0;
  746. static const u8_t syslocation_default[] = "";
  747. static u8_t* syslocation_len_ptr = (u8_t*)&syslocation_len_default;
  748. static u8_t* syslocation_ptr = (u8_t*)&syslocation_default[0];
  749. /** mib-2.snmp.snmpEnableAuthenTraps */
  750. static const u8_t snmpenableauthentraps_default = 2; /* disabled */
  751. static u8_t* snmpenableauthentraps_ptr = (u8_t*)&snmpenableauthentraps_default;
  752. /** mib-2.interfaces.ifTable.ifEntry.ifSpecific (zeroDotZero) */
  753. static const struct snmp_obj_id ifspecific = {2, {0, 0}};
  754. /** mib-2.ip.ipRouteTable.ipRouteEntry.ipRouteInfo (zeroDotZero) */
  755. static const struct snmp_obj_id iprouteinfo = {2, {0, 0}};
  756. /* mib-2.system counter(s) */
  757. static u32_t sysuptime = 0;
  758. /* mib-2.ip counter(s) */
  759. static u32_t ipinreceives = 0,
  760. ipinhdrerrors = 0,
  761. ipinaddrerrors = 0,
  762. ipforwdatagrams = 0,
  763. ipinunknownprotos = 0,
  764. ipindiscards = 0,
  765. ipindelivers = 0,
  766. ipoutrequests = 0,
  767. ipoutdiscards = 0,
  768. ipoutnoroutes = 0,
  769. ipreasmreqds = 0,
  770. ipreasmoks = 0,
  771. ipreasmfails = 0,
  772. ipfragoks = 0,
  773. ipfragfails = 0,
  774. ipfragcreates = 0,
  775. iproutingdiscards = 0;
  776. /* mib-2.icmp counter(s) */
  777. static u32_t icmpinmsgs = 0,
  778. icmpinerrors = 0,
  779. icmpindestunreachs = 0,
  780. icmpintimeexcds = 0,
  781. icmpinparmprobs = 0,
  782. icmpinsrcquenchs = 0,
  783. icmpinredirects = 0,
  784. icmpinechos = 0,
  785. icmpinechoreps = 0,
  786. icmpintimestamps = 0,
  787. icmpintimestampreps = 0,
  788. icmpinaddrmasks = 0,
  789. icmpinaddrmaskreps = 0,
  790. icmpoutmsgs = 0,
  791. icmpouterrors = 0,
  792. icmpoutdestunreachs = 0,
  793. icmpouttimeexcds = 0,
  794. icmpoutparmprobs = 0,
  795. icmpoutsrcquenchs = 0,
  796. icmpoutredirects = 0,
  797. icmpoutechos = 0,
  798. icmpoutechoreps = 0,
  799. icmpouttimestamps = 0,
  800. icmpouttimestampreps = 0,
  801. icmpoutaddrmasks = 0,
  802. icmpoutaddrmaskreps = 0;
  803. /* mib-2.tcp counter(s) */
  804. static u32_t tcpactiveopens = 0,
  805. tcppassiveopens = 0,
  806. tcpattemptfails = 0,
  807. tcpestabresets = 0,
  808. tcpinsegs = 0,
  809. tcpoutsegs = 0,
  810. tcpretranssegs = 0,
  811. tcpinerrs = 0,
  812. tcpoutrsts = 0;
  813. /* mib-2.udp counter(s) */
  814. static u32_t udpindatagrams = 0,
  815. udpnoports = 0,
  816. udpinerrors = 0,
  817. udpoutdatagrams = 0;
  818. /* mib-2.snmp counter(s) */
  819. static u32_t snmpinpkts = 0,
  820. snmpoutpkts = 0,
  821. snmpinbadversions = 0,
  822. snmpinbadcommunitynames = 0,
  823. snmpinbadcommunityuses = 0,
  824. snmpinasnparseerrs = 0,
  825. snmpintoobigs = 0,
  826. snmpinnosuchnames = 0,
  827. snmpinbadvalues = 0,
  828. snmpinreadonlys = 0,
  829. snmpingenerrs = 0,
  830. snmpintotalreqvars = 0,
  831. snmpintotalsetvars = 0,
  832. snmpingetrequests = 0,
  833. snmpingetnexts = 0,
  834. snmpinsetrequests = 0,
  835. snmpingetresponses = 0,
  836. snmpintraps = 0,
  837. snmpouttoobigs = 0,
  838. snmpoutnosuchnames = 0,
  839. snmpoutbadvalues = 0,
  840. snmpoutgenerrs = 0,
  841. snmpoutgetrequests = 0,
  842. snmpoutgetnexts = 0,
  843. snmpoutsetrequests = 0,
  844. snmpoutgetresponses = 0,
  845. snmpouttraps = 0;
  846. /* prototypes of the following functions are in lwip/src/include/lwip/snmp.h */
  847. /**
  848. * Copy octet string.
  849. *
  850. * @param dst points to destination
  851. * @param src points to source
  852. * @param n number of octets to copy.
  853. */
  854. void ocstrncpy(u8_t *dst, u8_t *src, u8_t n)
  855. {
  856. while (n > 0)
  857. {
  858. n--;
  859. *dst++ = *src++;
  860. }
  861. }
  862. /**
  863. * Copy object identifier (s32_t) array.
  864. *
  865. * @param dst points to destination
  866. * @param src points to source
  867. * @param n number of sub identifiers to copy.
  868. */
  869. void objectidncpy(s32_t *dst, s32_t *src, u8_t n)
  870. {
  871. while(n > 0)
  872. {
  873. n--;
  874. *dst++ = *src++;
  875. }
  876. }
  877. /**
  878. * Initializes sysDescr pointers.
  879. *
  880. * @param str if non-NULL then copy str pointer
  881. * @param len points to string length, excluding zero terminator
  882. */
  883. void snmp_set_sysdesr(u8_t *str, u8_t *len)
  884. {
  885. if (str != NULL)
  886. {
  887. sysdescr_ptr = str;
  888. sysdescr_len_ptr = len;
  889. }
  890. }
  891. void snmp_get_sysobjid_ptr(struct snmp_obj_id **oid)
  892. {
  893. *oid = &sysobjid;
  894. }
  895. /**
  896. * Initializes sysObjectID value.
  897. *
  898. * @param oid points to stuct snmp_obj_id to copy
  899. */
  900. void snmp_set_sysobjid(struct snmp_obj_id *oid)
  901. {
  902. sysobjid = *oid;
  903. }
  904. /**
  905. * Must be called at regular 10 msec interval from a timer interrupt
  906. * or signal handler depending on your runtime environment.
  907. */
  908. void snmp_inc_sysuptime(void)
  909. {
  910. sysuptime++;
  911. }
  912. void snmp_add_sysuptime(u32_t value)
  913. {
  914. sysuptime+=value;
  915. }
  916. void snmp_get_sysuptime(u32_t *value)
  917. {
  918. SNMP_GET_SYSUPTIME(sysuptime);
  919. *value = sysuptime;
  920. }
  921. /**
  922. * Initializes sysContact pointers,
  923. * e.g. ptrs to non-volatile memory external to lwIP.
  924. *
  925. * @param ocstr if non-NULL then copy str pointer
  926. * @param ocstrlen points to string length, excluding zero terminator
  927. */
  928. void snmp_set_syscontact(u8_t *ocstr, u8_t *ocstrlen)
  929. {
  930. if (ocstr != NULL)
  931. {
  932. syscontact_ptr = ocstr;
  933. syscontact_len_ptr = ocstrlen;
  934. }
  935. }
  936. /**
  937. * Initializes sysName pointers,
  938. * e.g. ptrs to non-volatile memory external to lwIP.
  939. *
  940. * @param ocstr if non-NULL then copy str pointer
  941. * @param ocstrlen points to string length, excluding zero terminator
  942. */
  943. void snmp_set_sysname(u8_t *ocstr, u8_t *ocstrlen)
  944. {
  945. if (ocstr != NULL)
  946. {
  947. sysname_ptr = ocstr;
  948. sysname_len_ptr = ocstrlen;
  949. }
  950. }
  951. /**
  952. * Initializes sysLocation pointers,
  953. * e.g. ptrs to non-volatile memory external to lwIP.
  954. *
  955. * @param ocstr if non-NULL then copy str pointer
  956. * @param ocstrlen points to string length, excluding zero terminator
  957. */
  958. void snmp_set_syslocation(u8_t *ocstr, u8_t *ocstrlen)
  959. {
  960. if (ocstr != NULL)
  961. {
  962. syslocation_ptr = ocstr;
  963. syslocation_len_ptr = ocstrlen;
  964. }
  965. }
  966. void snmp_add_ifinoctets(struct netif *ni, u32_t value)
  967. {
  968. ni->ifinoctets += value;
  969. }
  970. void snmp_inc_ifinucastpkts(struct netif *ni)
  971. {
  972. (ni->ifinucastpkts)++;
  973. }
  974. void snmp_inc_ifinnucastpkts(struct netif *ni)
  975. {
  976. (ni->ifinnucastpkts)++;
  977. }
  978. void snmp_inc_ifindiscards(struct netif *ni)
  979. {
  980. (ni->ifindiscards)++;
  981. }
  982. void snmp_add_ifoutoctets(struct netif *ni, u32_t value)
  983. {
  984. ni->ifoutoctets += value;
  985. }
  986. void snmp_inc_ifoutucastpkts(struct netif *ni)
  987. {
  988. (ni->ifoutucastpkts)++;
  989. }
  990. void snmp_inc_ifoutnucastpkts(struct netif *ni)
  991. {
  992. (ni->ifoutnucastpkts)++;
  993. }
  994. void snmp_inc_ifoutdiscards(struct netif *ni)
  995. {
  996. (ni->ifoutdiscards)++;
  997. }
  998. void snmp_inc_iflist(void)
  999. {
  1000. struct mib_list_node *if_node = NULL;
  1001. snmp_mib_node_insert(&iflist_root, iflist_root.count + 1, &if_node);
  1002. /* enable getnext traversal on filled table */
  1003. iftable.maxlength = 1;
  1004. }
  1005. void snmp_dec_iflist(void)
  1006. {
  1007. snmp_mib_node_delete(&iflist_root, iflist_root.tail);
  1008. /* disable getnext traversal on empty table */
  1009. if(iflist_root.count == 0) iftable.maxlength = 0;
  1010. }
  1011. /**
  1012. * Inserts ARP table indexes (.xIfIndex.xNetAddress)
  1013. * into arp table index trees (both atTable and ipNetToMediaTable).
  1014. */
  1015. void snmp_insert_arpidx_tree(struct netif *ni, struct ip_addr *ip)
  1016. {
  1017. struct mib_list_rootnode *at_rn;
  1018. struct mib_list_node *at_node;
  1019. struct ip_addr hip;
  1020. s32_t arpidx[5];
  1021. u8_t level, tree;
  1022. LWIP_ASSERT("ni != NULL", ni != NULL);
  1023. snmp_netiftoifindex(ni, &arpidx[0]);
  1024. hip.addr = ntohl(ip->addr);
  1025. snmp_iptooid(&hip, &arpidx[1]);
  1026. for (tree = 0; tree < 2; tree++)
  1027. {
  1028. if (tree == 0)
  1029. {
  1030. at_rn = &arptree_root;
  1031. }
  1032. else
  1033. {
  1034. at_rn = &ipntomtree_root;
  1035. }
  1036. for (level = 0; level < 5; level++)
  1037. {
  1038. at_node = NULL;
  1039. snmp_mib_node_insert(at_rn, arpidx[level], &at_node);
  1040. if ((level != 4) && (at_node != NULL))
  1041. {
  1042. if (at_node->nptr == NULL)
  1043. {
  1044. at_rn = snmp_mib_lrn_alloc();
  1045. at_node->nptr = (struct mib_node*)at_rn;
  1046. if (at_rn != NULL)
  1047. {
  1048. if (level == 3)
  1049. {
  1050. if (tree == 0)
  1051. {
  1052. at_rn->get_object_def = atentry_get_object_def;
  1053. at_rn->get_value = atentry_get_value;
  1054. }
  1055. else
  1056. {
  1057. at_rn->get_object_def = ip_ntomentry_get_object_def;
  1058. at_rn->get_value = ip_ntomentry_get_value;
  1059. }
  1060. at_rn->set_test = noleafs_set_test;
  1061. at_rn->set_value = noleafs_set_value;
  1062. }
  1063. }
  1064. else
  1065. {
  1066. /* at_rn == NULL, malloc failure */
  1067. LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_arpidx_tree() insert failed, mem full"));
  1068. break;
  1069. }
  1070. }
  1071. else
  1072. {
  1073. at_rn = (struct mib_list_rootnode*)at_node->nptr;
  1074. }
  1075. }
  1076. }
  1077. }
  1078. /* enable getnext traversal on filled tables */
  1079. at.maxlength = 1;
  1080. ipntomtable.maxlength = 1;
  1081. }
  1082. /**
  1083. * Removes ARP table indexes (.xIfIndex.xNetAddress)
  1084. * from arp table index trees.
  1085. */
  1086. void snmp_delete_arpidx_tree(struct netif *ni, struct ip_addr *ip)
  1087. {
  1088. struct mib_list_rootnode *at_rn, *next, *del_rn[5];
  1089. struct mib_list_node *at_n, *del_n[5];
  1090. struct ip_addr hip;
  1091. s32_t arpidx[5];
  1092. u8_t fc, tree, level, del_cnt;
  1093. snmp_netiftoifindex(ni, &arpidx[0]);
  1094. hip.addr = ntohl(ip->addr);
  1095. snmp_iptooid(&hip, &arpidx[1]);
  1096. for (tree = 0; tree < 2; tree++)
  1097. {
  1098. /* mark nodes for deletion */
  1099. if (tree == 0)
  1100. {
  1101. at_rn = &arptree_root;
  1102. }
  1103. else
  1104. {
  1105. at_rn = &ipntomtree_root;
  1106. }
  1107. level = 0;
  1108. del_cnt = 0;
  1109. while ((level < 5) && (at_rn != NULL))
  1110. {
  1111. fc = snmp_mib_node_find(at_rn, arpidx[level], &at_n);
  1112. if (fc == 0)
  1113. {
  1114. /* arpidx[level] does not exist */
  1115. del_cnt = 0;
  1116. at_rn = NULL;
  1117. }
  1118. else if (fc == 1)
  1119. {
  1120. del_rn[del_cnt] = at_rn;
  1121. del_n[del_cnt] = at_n;
  1122. del_cnt++;
  1123. at_rn = (struct mib_list_rootnode*)(at_n->nptr);
  1124. }
  1125. else if (fc == 2)
  1126. {
  1127. /* reset delete (2 or more childs) */
  1128. del_cnt = 0;
  1129. at_rn = (struct mib_list_rootnode*)(at_n->nptr);
  1130. }
  1131. level++;
  1132. }
  1133. /* delete marked index nodes */
  1134. while (del_cnt > 0)
  1135. {
  1136. del_cnt--;
  1137. at_rn = del_rn[del_cnt];
  1138. at_n = del_n[del_cnt];
  1139. next = snmp_mib_node_delete(at_rn, at_n);
  1140. if (next != NULL)
  1141. {
  1142. LWIP_ASSERT("next_count == 0",next->count == 0);
  1143. snmp_mib_lrn_free(next);
  1144. }
  1145. }
  1146. }
  1147. /* disable getnext traversal on empty tables */
  1148. if(arptree_root.count == 0) at.maxlength = 0;
  1149. if(ipntomtree_root.count == 0) ipntomtable.maxlength = 0;
  1150. }
  1151. void snmp_inc_ipinreceives(void)
  1152. {
  1153. ipinreceives++;
  1154. }
  1155. void snmp_inc_ipinhdrerrors(void)
  1156. {
  1157. ipinhdrerrors++;
  1158. }
  1159. void snmp_inc_ipinaddrerrors(void)
  1160. {
  1161. ipinaddrerrors++;
  1162. }
  1163. void snmp_inc_ipforwdatagrams(void)
  1164. {
  1165. ipforwdatagrams++;
  1166. }
  1167. void snmp_inc_ipinunknownprotos(void)
  1168. {
  1169. ipinunknownprotos++;
  1170. }
  1171. void snmp_inc_ipindiscards(void)
  1172. {
  1173. ipindiscards++;
  1174. }
  1175. void snmp_inc_ipindelivers(void)
  1176. {
  1177. ipindelivers++;
  1178. }
  1179. void snmp_inc_ipoutrequests(void)
  1180. {
  1181. ipoutrequests++;
  1182. }
  1183. void snmp_inc_ipoutdiscards(void)
  1184. {
  1185. ipoutdiscards++;
  1186. }
  1187. void snmp_inc_ipoutnoroutes(void)
  1188. {
  1189. ipoutnoroutes++;
  1190. }
  1191. void snmp_inc_ipreasmreqds(void)
  1192. {
  1193. ipreasmreqds++;
  1194. }
  1195. void snmp_inc_ipreasmoks(void)
  1196. {
  1197. ipreasmoks++;
  1198. }
  1199. void snmp_inc_ipreasmfails(void)
  1200. {
  1201. ipreasmfails++;
  1202. }
  1203. void snmp_inc_ipfragoks(void)
  1204. {
  1205. ipfragoks++;
  1206. }
  1207. void snmp_inc_ipfragfails(void)
  1208. {
  1209. ipfragfails++;
  1210. }
  1211. void snmp_inc_ipfragcreates(void)
  1212. {
  1213. ipfragcreates++;
  1214. }
  1215. void snmp_inc_iproutingdiscards(void)
  1216. {
  1217. iproutingdiscards++;
  1218. }
  1219. /**
  1220. * Inserts ipAddrTable indexes (.ipAdEntAddr)
  1221. * into index tree.
  1222. */
  1223. void snmp_insert_ipaddridx_tree(struct netif *ni)
  1224. {
  1225. struct mib_list_rootnode *ipa_rn;
  1226. struct mib_list_node *ipa_node;
  1227. struct ip_addr ip;
  1228. s32_t ipaddridx[4];
  1229. u8_t level;
  1230. LWIP_ASSERT("ni != NULL", ni != NULL);
  1231. ip.addr = ntohl(ni->ip_addr.addr);
  1232. snmp_iptooid(&ip, &ipaddridx[0]);
  1233. level = 0;
  1234. ipa_rn = &ipaddrtree_root;
  1235. while (level < 4)
  1236. {
  1237. ipa_node = NULL;
  1238. snmp_mib_node_insert(ipa_rn, ipaddridx[level], &ipa_node);
  1239. if ((level != 3) && (ipa_node != NULL))
  1240. {
  1241. if (ipa_node->nptr == NULL)
  1242. {
  1243. ipa_rn = snmp_mib_lrn_alloc();
  1244. ipa_node->nptr = (struct mib_node*)ipa_rn;
  1245. if (ipa_rn != NULL)
  1246. {
  1247. if (level == 2)
  1248. {
  1249. ipa_rn->get_object_def = ip_addrentry_get_object_def;
  1250. ipa_rn->get_value = ip_addrentry_get_value;
  1251. ipa_rn->set_test = noleafs_set_test;
  1252. ipa_rn->set_value = noleafs_set_value;
  1253. }
  1254. }
  1255. else
  1256. {
  1257. /* ipa_rn == NULL, malloc failure */
  1258. LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_ipaddridx_tree() insert failed, mem full"));
  1259. break;
  1260. }
  1261. }
  1262. else
  1263. {
  1264. ipa_rn = (struct mib_list_rootnode*)ipa_node->nptr;
  1265. }
  1266. }
  1267. level++;
  1268. }
  1269. /* enable getnext traversal on filled table */
  1270. ipaddrtable.maxlength = 1;
  1271. }
  1272. /**
  1273. * Removes ipAddrTable indexes (.ipAdEntAddr)
  1274. * from index tree.
  1275. */
  1276. void snmp_delete_ipaddridx_tree(struct netif *ni)
  1277. {
  1278. struct mib_list_rootnode *ipa_rn, *next, *del_rn[4];
  1279. struct mib_list_node *ipa_n, *del_n[4];
  1280. struct ip_addr ip;
  1281. s32_t ipaddridx[4];
  1282. u8_t fc, level, del_cnt;
  1283. LWIP_ASSERT("ni != NULL", ni != NULL);
  1284. ip.addr = ntohl(ni->ip_addr.addr);
  1285. snmp_iptooid(&ip, &ipaddridx[0]);
  1286. /* mark nodes for deletion */
  1287. level = 0;
  1288. del_cnt = 0;
  1289. ipa_rn = &ipaddrtree_root;
  1290. while ((level < 4) && (ipa_rn != NULL))
  1291. {
  1292. fc = snmp_mib_node_find(ipa_rn, ipaddridx[level], &ipa_n);
  1293. if (fc == 0)
  1294. {
  1295. /* ipaddridx[level] does not exist */
  1296. del_cnt = 0;
  1297. ipa_rn = NULL;
  1298. }
  1299. else if (fc == 1)
  1300. {
  1301. del_rn[del_cnt] = ipa_rn;
  1302. del_n[del_cnt] = ipa_n;
  1303. del_cnt++;
  1304. ipa_rn = (struct mib_list_rootnode*)(ipa_n->nptr);
  1305. }
  1306. else if (fc == 2)
  1307. {
  1308. /* reset delete (2 or more childs) */
  1309. del_cnt = 0;
  1310. ipa_rn = (struct mib_list_rootnode*)(ipa_n->nptr);
  1311. }
  1312. level++;
  1313. }
  1314. /* delete marked index nodes */
  1315. while (del_cnt > 0)
  1316. {
  1317. del_cnt--;
  1318. ipa_rn = del_rn[del_cnt];
  1319. ipa_n = del_n[del_cnt];
  1320. next = snmp_mib_node_delete(ipa_rn, ipa_n);
  1321. if (next != NULL)
  1322. {
  1323. LWIP_ASSERT("next_count == 0",next->count == 0);
  1324. snmp_mib_lrn_free(next);
  1325. }
  1326. }
  1327. /* disable getnext traversal on empty table */
  1328. if (ipaddrtree_root.count == 0) ipaddrtable.maxlength = 0;
  1329. }
  1330. /**
  1331. * Inserts ipRouteTable indexes (.ipRouteDest)
  1332. * into index tree.
  1333. *
  1334. * @param dflt non-zero for the default rte, zero for network rte
  1335. * @param ni points to network interface for this rte
  1336. *
  1337. * @todo record sysuptime for _this_ route when it is installed
  1338. * (needed for ipRouteAge) in the netif.
  1339. */
  1340. void snmp_insert_iprteidx_tree(u8_t dflt, struct netif *ni)
  1341. {
  1342. u8_t insert = 0;
  1343. struct ip_addr dst;
  1344. if (dflt != 0)
  1345. {
  1346. /* the default route 0.0.0.0 */
  1347. dst.addr = 0;
  1348. insert = 1;
  1349. }
  1350. else
  1351. {
  1352. /* route to the network address */
  1353. dst.addr = ntohl(ni->ip_addr.addr & ni->netmask.addr);
  1354. /* exclude 0.0.0.0 network (reserved for default rte) */
  1355. if (dst.addr != 0) insert = 1;
  1356. }
  1357. if (insert)
  1358. {
  1359. struct mib_list_rootnode *iprte_rn;
  1360. struct mib_list_node *iprte_node;
  1361. s32_t iprteidx[4];
  1362. u8_t level;
  1363. snmp_iptooid(&dst, &iprteidx[0]);
  1364. level = 0;
  1365. iprte_rn = &iprtetree_root;
  1366. while (level < 4)
  1367. {
  1368. iprte_node = NULL;
  1369. snmp_mib_node_insert(iprte_rn, iprteidx[level], &iprte_node);
  1370. if ((level != 3) && (iprte_node != NULL))
  1371. {
  1372. if (iprte_node->nptr == NULL)
  1373. {
  1374. iprte_rn = snmp_mib_lrn_alloc();
  1375. iprte_node->nptr = (struct mib_node*)iprte_rn;
  1376. if (iprte_rn != NULL)
  1377. {
  1378. if (level == 2)
  1379. {
  1380. iprte_rn->get_object_def = ip_rteentry_get_object_def;
  1381. iprte_rn->get_value = ip_rteentry_get_value;
  1382. iprte_rn->set_test = noleafs_set_test;
  1383. iprte_rn->set_value = noleafs_set_value;
  1384. }
  1385. }
  1386. else
  1387. {
  1388. /* iprte_rn == NULL, malloc failure */
  1389. LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_iprteidx_tree() insert failed, mem full"));
  1390. break;
  1391. }
  1392. }
  1393. else
  1394. {
  1395. iprte_rn = (struct mib_list_rootnode*)iprte_node->nptr;
  1396. }
  1397. }
  1398. level++;
  1399. }
  1400. }
  1401. /* enable getnext traversal on filled table */
  1402. iprtetable.maxlength = 1;
  1403. }
  1404. /**
  1405. * Removes ipRouteTable indexes (.ipRouteDest)
  1406. * from index tree.
  1407. *
  1408. * @param dflt non-zero for the default rte, zero for network rte
  1409. * @param ni points to network interface for this rte or NULL
  1410. * for default route to be removed.
  1411. */
  1412. void snmp_delete_iprteidx_tree(u8_t dflt, struct netif *ni)
  1413. {
  1414. u8_t delete = 0;
  1415. struct ip_addr dst;
  1416. if (dflt != 0)
  1417. {
  1418. /* the default route 0.0.0.0 */
  1419. dst.addr = 0;
  1420. delete = 1;
  1421. }
  1422. else
  1423. {
  1424. /* route to the network address */
  1425. dst.addr = ntohl(ni->ip_addr.addr & ni->netmask.addr);
  1426. /* exclude 0.0.0.0 network (reserved for default rte) */
  1427. if (dst.addr != 0) delete = 1;
  1428. }
  1429. if (delete)
  1430. {
  1431. struct mib_list_rootnode *iprte_rn, *next, *del_rn[4];
  1432. struct mib_list_node *iprte_n, *del_n[4];
  1433. s32_t iprteidx[4];
  1434. u8_t fc, level, del_cnt;
  1435. snmp_iptooid(&dst, &iprteidx[0]);
  1436. /* mark nodes for deletion */
  1437. level = 0;
  1438. del_cnt = 0;
  1439. iprte_rn = &iprtetree_root;
  1440. while ((level < 4) && (iprte_rn != NULL))
  1441. {
  1442. fc = snmp_mib_node_find(iprte_rn, iprteidx[level], &iprte_n);
  1443. if (fc == 0)
  1444. {
  1445. /* iprteidx[level] does not exist */
  1446. del_cnt = 0;
  1447. iprte_rn = NULL;
  1448. }
  1449. else if (fc == 1)
  1450. {
  1451. del_rn[del_cnt] = iprte_rn;
  1452. del_n[del_cnt] = iprte_n;
  1453. del_cnt++;
  1454. iprte_rn = (struct mib_list_rootnode*)(iprte_n->nptr);
  1455. }
  1456. else if (fc == 2)
  1457. {
  1458. /* reset delete (2 or more childs) */
  1459. del_cnt = 0;
  1460. iprte_rn = (struct mib_list_rootnode*)(iprte_n->nptr);
  1461. }
  1462. level++;
  1463. }
  1464. /* delete marked index nodes */
  1465. while (del_cnt > 0)
  1466. {
  1467. del_cnt--;
  1468. iprte_rn = del_rn[del_cnt];
  1469. iprte_n = del_n[del_cnt];
  1470. next = snmp_mib_node_delete(iprte_rn, iprte_n);
  1471. if (next != NULL)
  1472. {
  1473. LWIP_ASSERT("next_count == 0",next->count == 0);
  1474. snmp_mib_lrn_free(next);
  1475. }
  1476. }
  1477. }
  1478. /* disable getnext traversal on empty table */
  1479. if (iprtetree_root.count == 0) iprtetable.maxlength = 0;
  1480. }
  1481. void snmp_inc_icmpinmsgs(void)
  1482. {
  1483. icmpinmsgs++;
  1484. }
  1485. void snmp_inc_icmpinerrors(void)
  1486. {
  1487. icmpinerrors++;
  1488. }
  1489. void snmp_inc_icmpindestunreachs(void)
  1490. {
  1491. icmpindestunreachs++;
  1492. }
  1493. void snmp_inc_icmpintimeexcds(void)
  1494. {
  1495. icmpintimeexcds++;
  1496. }
  1497. void snmp_inc_icmpinparmprobs(void)
  1498. {
  1499. icmpinparmprobs++;
  1500. }
  1501. void snmp_inc_icmpinsrcquenchs(void)
  1502. {
  1503. icmpinsrcquenchs++;
  1504. }
  1505. void snmp_inc_icmpinredirects(void)
  1506. {
  1507. icmpinredirects++;
  1508. }
  1509. void snmp_inc_icmpinechos(void)
  1510. {
  1511. icmpinechos++;
  1512. }
  1513. void snmp_inc_icmpinechoreps(void)
  1514. {
  1515. icmpinechoreps++;
  1516. }
  1517. void snmp_inc_icmpintimestamps(void)
  1518. {
  1519. icmpintimestamps++;
  1520. }
  1521. void snmp_inc_icmpintimestampreps(void)
  1522. {
  1523. icmpintimestampreps++;
  1524. }
  1525. void snmp_inc_icmpinaddrmasks(void)
  1526. {
  1527. icmpinaddrmasks++;
  1528. }
  1529. void snmp_inc_icmpinaddrmaskreps(void)
  1530. {
  1531. icmpinaddrmaskreps++;
  1532. }
  1533. void snmp_inc_icmpoutmsgs(void)
  1534. {
  1535. icmpoutmsgs++;
  1536. }
  1537. void snmp_inc_icmpouterrors(void)
  1538. {
  1539. icmpouterrors++;
  1540. }
  1541. void snmp_inc_icmpoutdestunreachs(void)
  1542. {
  1543. icmpoutdestunreachs++;
  1544. }
  1545. void snmp_inc_icmpouttimeexcds(void)
  1546. {
  1547. icmpouttimeexcds++;
  1548. }
  1549. void snmp_inc_icmpoutparmprobs(void)
  1550. {
  1551. icmpoutparmprobs++;
  1552. }
  1553. void snmp_inc_icmpoutsrcquenchs(void)
  1554. {
  1555. icmpoutsrcquenchs++;
  1556. }
  1557. void snmp_inc_icmpoutredirects(void)
  1558. {
  1559. icmpoutredirects++;
  1560. }
  1561. void snmp_inc_icmpoutechos(void)
  1562. {
  1563. icmpoutechos++;
  1564. }
  1565. void snmp_inc_icmpoutechoreps(void)
  1566. {
  1567. icmpoutechoreps++;
  1568. }
  1569. void snmp_inc_icmpouttimestamps(void)
  1570. {
  1571. icmpouttimestamps++;
  1572. }
  1573. void snmp_inc_icmpouttimestampreps(void)
  1574. {
  1575. icmpouttimestampreps++;
  1576. }
  1577. void snmp_inc_icmpoutaddrmasks(void)
  1578. {
  1579. icmpoutaddrmasks++;
  1580. }
  1581. void snmp_inc_icmpoutaddrmaskreps(void)
  1582. {
  1583. icmpoutaddrmaskreps++;
  1584. }
  1585. void snmp_inc_tcpactiveopens(void)
  1586. {
  1587. tcpactiveopens++;
  1588. }
  1589. void snmp_inc_tcppassiveopens(void)
  1590. {
  1591. tcppassiveopens++;
  1592. }
  1593. void snmp_inc_tcpattemptfails(void)
  1594. {
  1595. tcpattemptfails++;
  1596. }
  1597. void snmp_inc_tcpestabresets(void)
  1598. {
  1599. tcpestabresets++;
  1600. }
  1601. void snmp_inc_tcpinsegs(void)
  1602. {
  1603. tcpinsegs++;
  1604. }
  1605. void snmp_inc_tcpoutsegs(void)
  1606. {
  1607. tcpoutsegs++;
  1608. }
  1609. void snmp_inc_tcpretranssegs(void)
  1610. {
  1611. tcpretranssegs++;
  1612. }
  1613. void snmp_inc_tcpinerrs(void)
  1614. {
  1615. tcpinerrs++;
  1616. }
  1617. void snmp_inc_tcpoutrsts(void)
  1618. {
  1619. tcpoutrsts++;
  1620. }
  1621. void snmp_inc_udpindatagrams(void)
  1622. {
  1623. udpindatagrams++;
  1624. }
  1625. void snmp_inc_udpnoports(void)
  1626. {
  1627. udpnoports++;
  1628. }
  1629. void snmp_inc_udpinerrors(void)
  1630. {
  1631. udpinerrors++;
  1632. }
  1633. void snmp_inc_udpoutdatagrams(void)
  1634. {
  1635. udpoutdatagrams++;
  1636. }
  1637. /**
  1638. * Inserts udpTable indexes (.udpLocalAddress.udpLocalPort)
  1639. * into index tree.
  1640. */
  1641. void snmp_insert_udpidx_tree(struct udp_pcb *pcb)
  1642. {
  1643. struct mib_list_rootnode *udp_rn;
  1644. struct mib_list_node *udp_node;
  1645. struct ip_addr ip;
  1646. s32_t udpidx[5];
  1647. u8_t level;
  1648. LWIP_ASSERT("pcb != NULL", pcb != NULL);
  1649. ip.addr = ntohl(pcb->local_ip.addr);
  1650. snmp_iptooid(&ip, &udpidx[0]);
  1651. udpidx[4] = pcb->local_port;
  1652. udp_rn = &udp_root;
  1653. for (level = 0; level < 5; level++)
  1654. {
  1655. udp_node = NULL;
  1656. snmp_mib_node_insert(udp_rn, udpidx[level], &udp_node);
  1657. if ((level != 4) && (udp_node != NULL))
  1658. {
  1659. if (udp_node->nptr == NULL)
  1660. {
  1661. udp_rn = snmp_mib_lrn_alloc();
  1662. udp_node->nptr = (struct mib_node*)udp_rn;
  1663. if (udp_rn != NULL)
  1664. {
  1665. if (level == 3)
  1666. {
  1667. udp_rn->get_object_def = udpentry_get_object_def;
  1668. udp_rn->get_value = udpentry_get_value;
  1669. udp_rn->set_test = noleafs_set_test;
  1670. udp_rn->set_value = noleafs_set_value;
  1671. }
  1672. }
  1673. else
  1674. {
  1675. /* udp_rn == NULL, malloc failure */
  1676. LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_insert_udpidx_tree() insert failed, mem full"));
  1677. break;
  1678. }
  1679. }
  1680. else
  1681. {
  1682. udp_rn = (struct mib_list_rootnode*)udp_node->nptr;
  1683. }
  1684. }
  1685. }
  1686. udptable.maxlength = 1;
  1687. }
  1688. /**
  1689. * Removes udpTable indexes (.udpLocalAddress.udpLocalPort)
  1690. * from index tree.
  1691. */
  1692. void snmp_delete_udpidx_tree(struct udp_pcb *pcb)
  1693. {
  1694. struct mib_list_rootnode *udp_rn, *next, *del_rn[5];
  1695. struct mib_list_node *udp_n, *del_n[5];
  1696. struct ip_addr ip;
  1697. s32_t udpidx[5];
  1698. u8_t bindings, fc, level, del_cnt;
  1699. LWIP_ASSERT("pcb != NULL", pcb != NULL);
  1700. ip.addr = ntohl(pcb->local_ip.addr);
  1701. snmp_iptooid(&ip, &udpidx[0]);
  1702. udpidx[4] = pcb->local_port;
  1703. /* count PCBs for a given binding
  1704. (e.g. when reusing ports or for temp output PCBs) */
  1705. bindings = 0;
  1706. pcb = udp_pcbs;
  1707. while ((pcb != NULL))
  1708. {
  1709. if ((pcb->local_ip.addr == ip.addr) &&
  1710. (pcb->local_port == udpidx[4]))
  1711. {
  1712. bindings++;
  1713. }
  1714. pcb = pcb->next;
  1715. }
  1716. if (bindings == 1)
  1717. {
  1718. /* selectively remove */
  1719. /* mark nodes for deletion */
  1720. level = 0;
  1721. del_cnt = 0;
  1722. udp_rn = &udp_root;
  1723. while ((level < 5) && (udp_rn != NULL))
  1724. {
  1725. fc = snmp_mib_node_find(udp_rn, udpidx[level], &udp_n);
  1726. if (fc == 0)
  1727. {
  1728. /* udpidx[level] does not exist */
  1729. del_cnt = 0;
  1730. udp_rn = NULL;
  1731. }
  1732. else if (fc == 1)
  1733. {
  1734. del_rn[del_cnt] = udp_rn;
  1735. del_n[del_cnt] = udp_n;
  1736. del_cnt++;
  1737. udp_rn = (struct mib_list_rootnode*)(udp_n->nptr);
  1738. }
  1739. else if (fc == 2)
  1740. {
  1741. /* reset delete (2 or more childs) */
  1742. del_cnt = 0;
  1743. udp_rn = (struct mib_list_rootnode*)(udp_n->nptr);
  1744. }
  1745. level++;
  1746. }
  1747. /* delete marked index nodes */
  1748. while (del_cnt > 0)
  1749. {
  1750. del_cnt--;
  1751. udp_rn = del_rn[del_cnt];
  1752. udp_n = del_n[del_cnt];
  1753. next = snmp_mib_node_delete(udp_rn, udp_n);
  1754. if (next != NULL)
  1755. {
  1756. LWIP_ASSERT("next_count == 0",next->count == 0);
  1757. snmp_mib_lrn_free(next);
  1758. }
  1759. }
  1760. }
  1761. /* disable getnext traversal on empty table */
  1762. if (udp_root.count == 0) udptable.maxlength = 0;
  1763. }
  1764. void snmp_inc_snmpinpkts(void)
  1765. {
  1766. snmpinpkts++;
  1767. }
  1768. void snmp_inc_snmpoutpkts(void)
  1769. {
  1770. snmpoutpkts++;
  1771. }
  1772. void snmp_inc_snmpinbadversions(void)
  1773. {
  1774. snmpinbadversions++;
  1775. }
  1776. void snmp_inc_snmpinbadcommunitynames(void)
  1777. {
  1778. snmpinbadcommunitynames++;
  1779. }
  1780. void snmp_inc_snmpinbadcommunityuses(void)
  1781. {
  1782. snmpinbadcommunityuses++;
  1783. }
  1784. void snmp_inc_snmpinasnparseerrs(void)
  1785. {
  1786. snmpinasnparseerrs++;
  1787. }
  1788. void snmp_inc_snmpintoobigs(void)
  1789. {
  1790. snmpintoobigs++;
  1791. }
  1792. void snmp_inc_snmpinnosuchnames(void)
  1793. {
  1794. snmpinnosuchnames++;
  1795. }
  1796. void snmp_inc_snmpinbadvalues(void)
  1797. {
  1798. snmpinbadvalues++;
  1799. }
  1800. void snmp_inc_snmpinreadonlys(void)
  1801. {
  1802. snmpinreadonlys++;
  1803. }
  1804. void snmp_inc_snmpingenerrs(void)
  1805. {
  1806. snmpingenerrs++;
  1807. }
  1808. void snmp_add_snmpintotalreqvars(u8_t value)
  1809. {
  1810. snmpintotalreqvars += value;
  1811. }
  1812. void snmp_add_snmpintotalsetvars(u8_t value)
  1813. {
  1814. snmpintotalsetvars += value;
  1815. }
  1816. void snmp_inc_snmpingetrequests(void)
  1817. {
  1818. snmpingetrequests++;
  1819. }
  1820. void snmp_inc_snmpingetnexts(void)
  1821. {
  1822. snmpingetnexts++;
  1823. }
  1824. void snmp_inc_snmpinsetrequests(void)
  1825. {
  1826. snmpinsetrequests++;
  1827. }
  1828. void snmp_inc_snmpingetresponses(void)
  1829. {
  1830. snmpingetresponses++;
  1831. }
  1832. void snmp_inc_snmpintraps(void)
  1833. {
  1834. snmpintraps++;
  1835. }
  1836. void snmp_inc_snmpouttoobigs(void)
  1837. {
  1838. snmpouttoobigs++;
  1839. }
  1840. void snmp_inc_snmpoutnosuchnames(void)
  1841. {
  1842. snmpoutnosuchnames++;
  1843. }
  1844. void snmp_inc_snmpoutbadvalues(void)
  1845. {
  1846. snmpoutbadvalues++;
  1847. }
  1848. void snmp_inc_snmpoutgenerrs(void)
  1849. {
  1850. snmpoutgenerrs++;
  1851. }
  1852. void snmp_inc_snmpoutgetrequests(void)
  1853. {
  1854. snmpoutgetrequests++;
  1855. }
  1856. void snmp_inc_snmpoutgetnexts(void)
  1857. {
  1858. snmpoutgetnexts++;
  1859. }
  1860. void snmp_inc_snmpoutsetrequests(void)
  1861. {
  1862. snmpoutsetrequests++;
  1863. }
  1864. void snmp_inc_snmpoutgetresponses(void)
  1865. {
  1866. snmpoutgetresponses++;
  1867. }
  1868. void snmp_inc_snmpouttraps(void)
  1869. {
  1870. snmpouttraps++;
  1871. }
  1872. void snmp_get_snmpgrpid_ptr(struct snmp_obj_id **oid)
  1873. {
  1874. *oid = &snmpgrp_id;
  1875. }
  1876. void snmp_set_snmpenableauthentraps(u8_t *value)
  1877. {
  1878. if (value != NULL)
  1879. {
  1880. snmpenableauthentraps_ptr = value;
  1881. }
  1882. }
  1883. void snmp_get_snmpenableauthentraps(u8_t *value)
  1884. {
  1885. *value = *snmpenableauthentraps_ptr;
  1886. }
  1887. void
  1888. noleafs_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
  1889. {
  1890. LWIP_UNUSED_ARG(ident_len);
  1891. LWIP_UNUSED_ARG(ident);
  1892. od->instance = MIB_OBJECT_NONE;
  1893. }
  1894. void
  1895. noleafs_get_value(struct obj_def *od, u16_t len, void *value)
  1896. {
  1897. LWIP_UNUSED_ARG(od);
  1898. LWIP_UNUSED_ARG(len);
  1899. LWIP_UNUSED_ARG(value);
  1900. }
  1901. u8_t
  1902. noleafs_set_test(struct obj_def *od, u16_t len, void *value)
  1903. {
  1904. LWIP_UNUSED_ARG(od);
  1905. LWIP_UNUSED_ARG(len);
  1906. LWIP_UNUSED_ARG(value);
  1907. /* can't set */
  1908. return 0;
  1909. }
  1910. void
  1911. noleafs_set_value(struct obj_def *od, u16_t len, void *value)
  1912. {
  1913. LWIP_UNUSED_ARG(od);
  1914. LWIP_UNUSED_ARG(len);
  1915. LWIP_UNUSED_ARG(value);
  1916. }
  1917. /**
  1918. * Returns systems object definitions.
  1919. *
  1920. * @param ident_len the address length (2)
  1921. * @param ident points to objectname.0 (object id trailer)
  1922. * @param od points to object definition.
  1923. */
  1924. static void
  1925. system_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
  1926. {
  1927. u8_t id;
  1928. /* return to object name, adding index depth (1) */
  1929. ident_len += 1;
  1930. ident -= 1;
  1931. if (ident_len == 2)
  1932. {
  1933. od->id_inst_len = ident_len;
  1934. od->id_inst_ptr = ident;
  1935. id = ident[0];
  1936. LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def system.%"U16_F".0\n",(u16_t)id));
  1937. switch (id)
  1938. {
  1939. case 1: /* sysDescr */
  1940. od->instance = MIB_OBJECT_SCALAR;
  1941. od->access = MIB_OBJECT_READ_ONLY;
  1942. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
  1943. od->v_len = *sysdescr_len_ptr;
  1944. break;
  1945. case 2: /* sysObjectID */
  1946. od->instance = MIB_OBJECT_SCALAR;
  1947. od->access = MIB_OBJECT_READ_ONLY;
  1948. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID);
  1949. od->v_len = sysobjid.len * sizeof(s32_t);
  1950. break;
  1951. case 3: /* sysUpTime */
  1952. od->instance = MIB_OBJECT_SCALAR;
  1953. od->access = MIB_OBJECT_READ_ONLY;
  1954. od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS);
  1955. od->v_len = sizeof(u32_t);
  1956. break;
  1957. case 4: /* sysContact */
  1958. od->instance = MIB_OBJECT_SCALAR;
  1959. od->access = MIB_OBJECT_READ_WRITE;
  1960. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
  1961. od->v_len = *syscontact_len_ptr;
  1962. break;
  1963. case 5: /* sysName */
  1964. od->instance = MIB_OBJECT_SCALAR;
  1965. od->access = MIB_OBJECT_READ_WRITE;
  1966. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
  1967. od->v_len = *sysname_len_ptr;
  1968. break;
  1969. case 6: /* sysLocation */
  1970. od->instance = MIB_OBJECT_SCALAR;
  1971. od->access = MIB_OBJECT_READ_WRITE;
  1972. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
  1973. od->v_len = *syslocation_len_ptr;
  1974. break;
  1975. case 7: /* sysServices */
  1976. od->instance = MIB_OBJECT_SCALAR;
  1977. od->access = MIB_OBJECT_READ_ONLY;
  1978. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
  1979. od->v_len = sizeof(s32_t);
  1980. break;
  1981. default:
  1982. LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_object_def: no such object\n"));
  1983. od->instance = MIB_OBJECT_NONE;
  1984. break;
  1985. };
  1986. }
  1987. else
  1988. {
  1989. LWIP_DEBUGF(SNMP_MIB_DEBUG,("system_get_object_def: no scalar\n"));
  1990. od->instance = MIB_OBJECT_NONE;
  1991. }
  1992. }
  1993. /**
  1994. * Returns system object value.
  1995. *
  1996. * @param ident_len the address length (2)
  1997. * @param ident points to objectname.0 (object id trailer)
  1998. * @param len return value space (in bytes)
  1999. * @param value points to (varbind) space to copy value into.
  2000. */
  2001. static void
  2002. system_get_value(struct obj_def *od, u16_t len, void *value)
  2003. {
  2004. u8_t id;
  2005. id = od->id_inst_ptr[0];
  2006. switch (id)
  2007. {
  2008. case 1: /* sysDescr */
  2009. ocstrncpy(value,sysdescr_ptr, len);
  2010. break;
  2011. case 2: /* sysObjectID */
  2012. objectidncpy((s32_t*)value, (s32_t*)sysobjid.id, (u8_t)(len / sizeof(s32_t)));
  2013. break;
  2014. case 3: /* sysUpTime */
  2015. {
  2016. snmp_get_sysuptime(value);
  2017. }
  2018. break;
  2019. case 4: /* sysContact */
  2020. ocstrncpy(value,syscontact_ptr,len);
  2021. break;
  2022. case 5: /* sysName */
  2023. ocstrncpy(value,sysname_ptr,len);
  2024. break;
  2025. case 6: /* sysLocation */
  2026. ocstrncpy(value,syslocation_ptr,len);
  2027. break;
  2028. case 7: /* sysServices */
  2029. {
  2030. s32_t *sint_ptr = value;
  2031. *sint_ptr = sysservices;
  2032. }
  2033. break;
  2034. };
  2035. }
  2036. static u8_t
  2037. system_set_test(struct obj_def *od, u16_t len, void *value)
  2038. {
  2039. u8_t id, set_ok;
  2040. LWIP_UNUSED_ARG(value);
  2041. set_ok = 0;
  2042. id = od->id_inst_ptr[0];
  2043. switch (id)
  2044. {
  2045. case 4: /* sysContact */
  2046. if ((syscontact_ptr != syscontact_default) &&
  2047. (len <= 255))
  2048. {
  2049. set_ok = 1;
  2050. }
  2051. break;
  2052. case 5: /* sysName */
  2053. if ((sysname_ptr != sysname_default) &&
  2054. (len <= 255))
  2055. {
  2056. set_ok = 1;
  2057. }
  2058. break;
  2059. case 6: /* sysLocation */
  2060. if ((syslocation_ptr != syslocation_default) &&
  2061. (len <= 255))
  2062. {
  2063. set_ok = 1;
  2064. }
  2065. break;
  2066. };
  2067. return set_ok;
  2068. }
  2069. static void
  2070. system_set_value(struct obj_def *od, u16_t len, void *value)
  2071. {
  2072. u8_t id;
  2073. id = od->id_inst_ptr[0];
  2074. switch (id)
  2075. {
  2076. case 4: /* sysContact */
  2077. ocstrncpy(syscontact_ptr,value,len);
  2078. *syscontact_len_ptr = len;
  2079. break;
  2080. case 5: /* sysName */
  2081. ocstrncpy(sysname_ptr,value,len);
  2082. *sysname_len_ptr = len;
  2083. break;
  2084. case 6: /* sysLocation */
  2085. ocstrncpy(syslocation_ptr,value,len);
  2086. *syslocation_len_ptr = len;
  2087. break;
  2088. };
  2089. }
  2090. /**
  2091. * Returns interfaces.ifnumber object definition.
  2092. *
  2093. * @param ident_len the address length (2)
  2094. * @param ident points to objectname.index
  2095. * @param od points to object definition.
  2096. */
  2097. static void
  2098. interfaces_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
  2099. {
  2100. /* return to object name, adding index depth (1) */
  2101. ident_len += 1;
  2102. ident -= 1;
  2103. if (ident_len == 2)
  2104. {
  2105. od->id_inst_len = ident_len;
  2106. od->id_inst_ptr = ident;
  2107. od->instance = MIB_OBJECT_SCALAR;
  2108. od->access = MIB_OBJECT_READ_ONLY;
  2109. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
  2110. od->v_len = sizeof(s32_t);
  2111. }
  2112. else
  2113. {
  2114. LWIP_DEBUGF(SNMP_MIB_DEBUG,("interfaces_get_object_def: no scalar\n"));
  2115. od->instance = MIB_OBJECT_NONE;
  2116. }
  2117. }
  2118. /**
  2119. * Returns interfaces.ifnumber object value.
  2120. *
  2121. * @param ident_len the address length (2)
  2122. * @param ident points to objectname.0 (object id trailer)
  2123. * @param len return value space (in bytes)
  2124. * @param value points to (varbind) space to copy value into.
  2125. */
  2126. static void
  2127. interfaces_get_value(struct obj_def *od, u16_t len, void *value)
  2128. {
  2129. LWIP_UNUSED_ARG(len);
  2130. if (od->id_inst_ptr[0] == 1)
  2131. {
  2132. s32_t *sint_ptr = value;
  2133. *sint_ptr = iflist_root.count;
  2134. }
  2135. }
  2136. /**
  2137. * Returns ifentry object definitions.
  2138. *
  2139. * @param ident_len the address length (2)
  2140. * @param ident points to objectname.index
  2141. * @param od points to object definition.
  2142. */
  2143. static void
  2144. ifentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
  2145. {
  2146. u8_t id;
  2147. /* return to object name, adding index depth (1) */
  2148. ident_len += 1;
  2149. ident -= 1;
  2150. if (ident_len == 2)
  2151. {
  2152. od->id_inst_len = ident_len;
  2153. od->id_inst_ptr = ident;
  2154. id = ident[0];
  2155. LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def ifentry.%"U16_F"\n",(u16_t)id));
  2156. switch (id)
  2157. {
  2158. case 1: /* ifIndex */
  2159. case 3: /* ifType */
  2160. case 4: /* ifMtu */
  2161. case 8: /* ifOperStatus */
  2162. od->instance = MIB_OBJECT_TAB;
  2163. od->access = MIB_OBJECT_READ_ONLY;
  2164. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
  2165. od->v_len = sizeof(s32_t);
  2166. break;
  2167. case 2: /* ifDescr */
  2168. od->instance = MIB_OBJECT_TAB;
  2169. od->access = MIB_OBJECT_READ_ONLY;
  2170. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
  2171. /** @todo this should be some sort of sizeof(struct netif.name) */
  2172. od->v_len = 2;
  2173. break;
  2174. case 5: /* ifSpeed */
  2175. case 21: /* ifOutQLen */
  2176. od->instance = MIB_OBJECT_TAB;
  2177. od->access = MIB_OBJECT_READ_ONLY;
  2178. od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE);
  2179. od->v_len = sizeof(u32_t);
  2180. break;
  2181. case 6: /* ifPhysAddress */
  2182. {
  2183. struct netif *netif;
  2184. snmp_ifindextonetif(ident[1], &netif);
  2185. od->instance = MIB_OBJECT_TAB;
  2186. od->access = MIB_OBJECT_READ_ONLY;
  2187. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
  2188. od->v_len = netif->hwaddr_len;
  2189. }
  2190. break;
  2191. case 7: /* ifAdminStatus */
  2192. od->instance = MIB_OBJECT_TAB;
  2193. od->access = MIB_OBJECT_READ_WRITE;
  2194. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
  2195. od->v_len = sizeof(s32_t);
  2196. break;
  2197. case 9: /* ifLastChange */
  2198. od->instance = MIB_OBJECT_TAB;
  2199. od->access = MIB_OBJECT_READ_ONLY;
  2200. od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_TIMETICKS);
  2201. od->v_len = sizeof(u32_t);
  2202. break;
  2203. case 10: /* ifInOctets */
  2204. case 11: /* ifInUcastPkts */
  2205. case 12: /* ifInNUcastPkts */
  2206. case 13: /* ifInDiscarts */
  2207. case 14: /* ifInErrors */
  2208. case 15: /* ifInUnkownProtos */
  2209. case 16: /* ifOutOctets */
  2210. case 17: /* ifOutUcastPkts */
  2211. case 18: /* ifOutNUcastPkts */
  2212. case 19: /* ifOutDiscarts */
  2213. case 20: /* ifOutErrors */
  2214. od->instance = MIB_OBJECT_TAB;
  2215. od->access = MIB_OBJECT_READ_ONLY;
  2216. od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
  2217. od->v_len = sizeof(u32_t);
  2218. break;
  2219. case 22: /* ifSpecific */
  2220. /** @note returning zeroDotZero (0.0) no media specific MIB support */
  2221. od->instance = MIB_OBJECT_TAB;
  2222. od->access = MIB_OBJECT_READ_ONLY;
  2223. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID);
  2224. od->v_len = ifspecific.len * sizeof(s32_t);
  2225. break;
  2226. default:
  2227. LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_object_def: no such object\n"));
  2228. od->instance = MIB_OBJECT_NONE;
  2229. break;
  2230. };
  2231. }
  2232. else
  2233. {
  2234. LWIP_DEBUGF(SNMP_MIB_DEBUG,("ifentry_get_object_def: no scalar\n"));
  2235. od->instance = MIB_OBJECT_NONE;
  2236. }
  2237. }
  2238. /**
  2239. * Returns ifentry object value.
  2240. *
  2241. * @param ident_len the address length (2)
  2242. * @param ident points to objectname.0 (object id trailer)
  2243. * @param len return value space (in bytes)
  2244. * @param value points to (varbind) space to copy value into.
  2245. */
  2246. static void
  2247. ifentry_get_value(struct obj_def *od, u16_t len, void *value)
  2248. {
  2249. struct netif *netif;
  2250. u8_t id;
  2251. snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
  2252. id = od->id_inst_ptr[0];
  2253. switch (id)
  2254. {
  2255. case 1: /* ifIndex */
  2256. {
  2257. s32_t *sint_ptr = value;
  2258. *sint_ptr = od->id_inst_ptr[1];
  2259. }
  2260. break;
  2261. case 2: /* ifDescr */
  2262. ocstrncpy(value,(u8_t*)netif->name,len);
  2263. break;
  2264. case 3: /* ifType */
  2265. {
  2266. s32_t *sint_ptr = value;
  2267. *sint_ptr = netif->link_type;
  2268. }
  2269. break;
  2270. case 4: /* ifMtu */
  2271. {
  2272. s32_t *sint_ptr = value;
  2273. *sint_ptr = netif->mtu;
  2274. }
  2275. break;
  2276. case 5: /* ifSpeed */
  2277. {
  2278. u32_t *uint_ptr = value;
  2279. *uint_ptr = netif->link_speed;
  2280. }
  2281. break;
  2282. case 6: /* ifPhysAddress */
  2283. ocstrncpy(value,netif->hwaddr,len);
  2284. break;
  2285. case 7: /* ifAdminStatus */
  2286. #if LWIP_NETIF_LINK_CALLBACK
  2287. {
  2288. s32_t *sint_ptr = value;
  2289. if (netif_is_up(netif))
  2290. {
  2291. if (netif_is_link_up(netif))
  2292. {
  2293. *sint_ptr = 1; /* up */
  2294. }
  2295. else
  2296. {
  2297. *sint_ptr = 7; /* lowerLayerDown */
  2298. }
  2299. }
  2300. else
  2301. {
  2302. *sint_ptr = 2; /* down */
  2303. }
  2304. }
  2305. break;
  2306. #endif
  2307. case 8: /* ifOperStatus */
  2308. {
  2309. s32_t *sint_ptr = value;
  2310. if (netif_is_up(netif))
  2311. {
  2312. *sint_ptr = 1;
  2313. }
  2314. else
  2315. {
  2316. *sint_ptr = 2;
  2317. }
  2318. }
  2319. break;
  2320. case 9: /* ifLastChange */
  2321. {
  2322. u32_t *uint_ptr = value;
  2323. *uint_ptr = netif->ts;
  2324. }
  2325. break;
  2326. case 10: /* ifInOctets */
  2327. {
  2328. u32_t *uint_ptr = value;
  2329. *uint_ptr = netif->ifinoctets;
  2330. }
  2331. break;
  2332. case 11: /* ifInUcastPkts */
  2333. {
  2334. u32_t *uint_ptr = value;
  2335. *uint_ptr = netif->ifinucastpkts;
  2336. }
  2337. break;
  2338. case 12: /* ifInNUcastPkts */
  2339. {
  2340. u32_t *uint_ptr = value;
  2341. *uint_ptr = netif->ifinnucastpkts;
  2342. }
  2343. break;
  2344. case 13: /* ifInDiscarts */
  2345. {
  2346. u32_t *uint_ptr = value;
  2347. *uint_ptr = netif->ifindiscards;
  2348. }
  2349. break;
  2350. case 14: /* ifInErrors */
  2351. case 15: /* ifInUnkownProtos */
  2352. /** @todo add these counters! */
  2353. {
  2354. u32_t *uint_ptr = value;
  2355. *uint_ptr = 0;
  2356. }
  2357. break;
  2358. case 16: /* ifOutOctets */
  2359. {
  2360. u32_t *uint_ptr = value;
  2361. *uint_ptr = netif->ifoutoctets;
  2362. }
  2363. break;
  2364. case 17: /* ifOutUcastPkts */
  2365. {
  2366. u32_t *uint_ptr = value;
  2367. *uint_ptr = netif->ifoutucastpkts;
  2368. }
  2369. break;
  2370. case 18: /* ifOutNUcastPkts */
  2371. {
  2372. u32_t *uint_ptr = value;
  2373. *uint_ptr = netif->ifoutnucastpkts;
  2374. }
  2375. break;
  2376. case 19: /* ifOutDiscarts */
  2377. {
  2378. u32_t *uint_ptr = value;
  2379. *uint_ptr = netif->ifoutdiscards;
  2380. }
  2381. break;
  2382. case 20: /* ifOutErrors */
  2383. /** @todo add this counter! */
  2384. {
  2385. u32_t *uint_ptr = value;
  2386. *uint_ptr = 0;
  2387. }
  2388. break;
  2389. case 21: /* ifOutQLen */
  2390. /** @todo figure out if this must be 0 (no queue) or 1? */
  2391. {
  2392. u32_t *uint_ptr = value;
  2393. *uint_ptr = 0;
  2394. }
  2395. break;
  2396. case 22: /* ifSpecific */
  2397. objectidncpy((s32_t*)value, (s32_t*)ifspecific.id, (u8_t)(len / sizeof(s32_t)));
  2398. break;
  2399. };
  2400. }
  2401. #if !SNMP_SAFE_REQUESTS
  2402. static u8_t
  2403. ifentry_set_test (struct obj_def *od, u16_t len, void *value)
  2404. {
  2405. struct netif *netif;
  2406. u8_t id, set_ok;
  2407. set_ok = 0;
  2408. snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
  2409. id = od->id_inst_ptr[0];
  2410. switch (id)
  2411. {
  2412. case 7: /* ifAdminStatus */
  2413. {
  2414. s32_t *sint_ptr = value;
  2415. if (*sint_ptr == 1 || *sint_ptr == 2)
  2416. set_ok = 1;
  2417. }
  2418. break;
  2419. }
  2420. return set_ok;
  2421. }
  2422. static void
  2423. ifentry_set_value (struct obj_def *od, u16_t len, void *value)
  2424. {
  2425. struct netif *netif;
  2426. u8_t id;
  2427. snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
  2428. id = od->id_inst_ptr[0];
  2429. switch (id)
  2430. {
  2431. case 7: /* ifAdminStatus */
  2432. {
  2433. s32_t *sint_ptr = value;
  2434. if (*sint_ptr == 1)
  2435. {
  2436. netif_set_up(netif);
  2437. }
  2438. else if (*sint_ptr == 2)
  2439. {
  2440. netif_set_down(netif);
  2441. }
  2442. }
  2443. break;
  2444. }
  2445. }
  2446. #endif /* SNMP_SAFE_REQUESTS */
  2447. /**
  2448. * Returns atentry object definitions.
  2449. *
  2450. * @param ident_len the address length (6)
  2451. * @param ident points to objectname.atifindex.atnetaddress
  2452. * @param od points to object definition.
  2453. */
  2454. static void
  2455. atentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
  2456. {
  2457. /* return to object name, adding index depth (5) */
  2458. ident_len += 5;
  2459. ident -= 5;
  2460. if (ident_len == 6)
  2461. {
  2462. od->id_inst_len = ident_len;
  2463. od->id_inst_ptr = ident;
  2464. switch (ident[0])
  2465. {
  2466. case 1: /* atIfIndex */
  2467. od->instance = MIB_OBJECT_TAB;
  2468. od->access = MIB_OBJECT_READ_WRITE;
  2469. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
  2470. od->v_len = sizeof(s32_t);
  2471. break;
  2472. case 2: /* atPhysAddress */
  2473. od->instance = MIB_OBJECT_TAB;
  2474. od->access = MIB_OBJECT_READ_WRITE;
  2475. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
  2476. od->v_len = 6; /** @todo try to use netif::hwaddr_len */
  2477. break;
  2478. case 3: /* atNetAddress */
  2479. od->instance = MIB_OBJECT_TAB;
  2480. od->access = MIB_OBJECT_READ_WRITE;
  2481. od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
  2482. od->v_len = 4;
  2483. break;
  2484. default:
  2485. LWIP_DEBUGF(SNMP_MIB_DEBUG,("atentry_get_object_def: no such object\n"));
  2486. od->instance = MIB_OBJECT_NONE;
  2487. break;
  2488. }
  2489. }
  2490. else
  2491. {
  2492. LWIP_DEBUGF(SNMP_MIB_DEBUG,("atentry_get_object_def: no scalar\n"));
  2493. od->instance = MIB_OBJECT_NONE;
  2494. }
  2495. }
  2496. static void
  2497. atentry_get_value(struct obj_def *od, u16_t len, void *value)
  2498. {
  2499. #if LWIP_ARP
  2500. u8_t id;
  2501. struct eth_addr* ethaddr_ret;
  2502. struct ip_addr* ipaddr_ret;
  2503. #endif /* LWIP_ARP */
  2504. struct ip_addr ip;
  2505. struct netif *netif;
  2506. LWIP_UNUSED_ARG(len);
  2507. LWIP_UNUSED_ARG(value);/* if !LWIP_ARP */
  2508. snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
  2509. snmp_oidtoip(&od->id_inst_ptr[2], &ip);
  2510. ip.addr = htonl(ip.addr);
  2511. #if LWIP_ARP /** @todo implement a netif_find_addr */
  2512. if (etharp_find_addr(netif, &ip, &ethaddr_ret, &ipaddr_ret) > -1)
  2513. {
  2514. id = od->id_inst_ptr[0];
  2515. switch (id)
  2516. {
  2517. case 1: /* atIfIndex */
  2518. {
  2519. s32_t *sint_ptr = value;
  2520. *sint_ptr = od->id_inst_ptr[1];
  2521. }
  2522. break;
  2523. case 2: /* atPhysAddress */
  2524. {
  2525. struct eth_addr *dst = value;
  2526. *dst = *ethaddr_ret;
  2527. }
  2528. break;
  2529. case 3: /* atNetAddress */
  2530. {
  2531. struct ip_addr *dst = value;
  2532. *dst = *ipaddr_ret;
  2533. }
  2534. break;
  2535. }
  2536. }
  2537. #endif /* LWIP_ARP */
  2538. }
  2539. static void
  2540. ip_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
  2541. {
  2542. u8_t id;
  2543. /* return to object name, adding index depth (1) */
  2544. ident_len += 1;
  2545. ident -= 1;
  2546. if (ident_len == 2)
  2547. {
  2548. od->id_inst_len = ident_len;
  2549. od->id_inst_ptr = ident;
  2550. id = ident[0];
  2551. LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def ip.%"U16_F".0\n",(u16_t)id));
  2552. switch (id)
  2553. {
  2554. case 1: /* ipForwarding */
  2555. case 2: /* ipDefaultTTL */
  2556. od->instance = MIB_OBJECT_SCALAR;
  2557. od->access = MIB_OBJECT_READ_WRITE;
  2558. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
  2559. od->v_len = sizeof(s32_t);
  2560. break;
  2561. case 3: /* ipInReceives */
  2562. case 4: /* ipInHdrErrors */
  2563. case 5: /* ipInAddrErrors */
  2564. case 6: /* ipForwDatagrams */
  2565. case 7: /* ipInUnknownProtos */
  2566. case 8: /* ipInDiscards */
  2567. case 9: /* ipInDelivers */
  2568. case 10: /* ipOutRequests */
  2569. case 11: /* ipOutDiscards */
  2570. case 12: /* ipOutNoRoutes */
  2571. case 14: /* ipReasmReqds */
  2572. case 15: /* ipReasmOKs */
  2573. case 16: /* ipReasmFails */
  2574. case 17: /* ipFragOKs */
  2575. case 18: /* ipFragFails */
  2576. case 19: /* ipFragCreates */
  2577. case 23: /* ipRoutingDiscards */
  2578. od->instance = MIB_OBJECT_SCALAR;
  2579. od->access = MIB_OBJECT_READ_ONLY;
  2580. od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
  2581. od->v_len = sizeof(u32_t);
  2582. break;
  2583. case 13: /* ipReasmTimeout */
  2584. od->instance = MIB_OBJECT_SCALAR;
  2585. od->access = MIB_OBJECT_READ_ONLY;
  2586. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
  2587. od->v_len = sizeof(s32_t);
  2588. break;
  2589. default:
  2590. LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_object_def: no such object\n"));
  2591. od->instance = MIB_OBJECT_NONE;
  2592. break;
  2593. };
  2594. }
  2595. else
  2596. {
  2597. LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_get_object_def: no scalar\n"));
  2598. od->instance = MIB_OBJECT_NONE;
  2599. }
  2600. }
  2601. static void
  2602. ip_get_value(struct obj_def *od, u16_t len, void *value)
  2603. {
  2604. u8_t id;
  2605. LWIP_UNUSED_ARG(len);
  2606. id = od->id_inst_ptr[0];
  2607. switch (id)
  2608. {
  2609. case 1: /* ipForwarding */
  2610. {
  2611. s32_t *sint_ptr = value;
  2612. #if IP_FORWARD
  2613. /* forwarding */
  2614. *sint_ptr = 1;
  2615. #else
  2616. /* not-forwarding */
  2617. *sint_ptr = 2;
  2618. #endif
  2619. }
  2620. break;
  2621. case 2: /* ipDefaultTTL */
  2622. {
  2623. s32_t *sint_ptr = value;
  2624. *sint_ptr = IP_DEFAULT_TTL;
  2625. }
  2626. break;
  2627. case 3: /* ipInReceives */
  2628. {
  2629. u32_t *uint_ptr = value;
  2630. *uint_ptr = ipinreceives;
  2631. }
  2632. break;
  2633. case 4: /* ipInHdrErrors */
  2634. {
  2635. u32_t *uint_ptr = value;
  2636. *uint_ptr = ipinhdrerrors;
  2637. }
  2638. break;
  2639. case 5: /* ipInAddrErrors */
  2640. {
  2641. u32_t *uint_ptr = value;
  2642. *uint_ptr = ipinaddrerrors;
  2643. }
  2644. break;
  2645. case 6: /* ipForwDatagrams */
  2646. {
  2647. u32_t *uint_ptr = value;
  2648. *uint_ptr = ipforwdatagrams;
  2649. }
  2650. break;
  2651. case 7: /* ipInUnknownProtos */
  2652. {
  2653. u32_t *uint_ptr = value;
  2654. *uint_ptr = ipinunknownprotos;
  2655. }
  2656. break;
  2657. case 8: /* ipInDiscards */
  2658. {
  2659. u32_t *uint_ptr = value;
  2660. *uint_ptr = ipindiscards;
  2661. }
  2662. break;
  2663. case 9: /* ipInDelivers */
  2664. {
  2665. u32_t *uint_ptr = value;
  2666. *uint_ptr = ipindelivers;
  2667. }
  2668. break;
  2669. case 10: /* ipOutRequests */
  2670. {
  2671. u32_t *uint_ptr = value;
  2672. *uint_ptr = ipoutrequests;
  2673. }
  2674. break;
  2675. case 11: /* ipOutDiscards */
  2676. {
  2677. u32_t *uint_ptr = value;
  2678. *uint_ptr = ipoutdiscards;
  2679. }
  2680. break;
  2681. case 12: /* ipOutNoRoutes */
  2682. {
  2683. u32_t *uint_ptr = value;
  2684. *uint_ptr = ipoutnoroutes;
  2685. }
  2686. break;
  2687. case 13: /* ipReasmTimeout */
  2688. {
  2689. s32_t *sint_ptr = value;
  2690. #if IP_REASSEMBLY
  2691. *sint_ptr = IP_REASS_MAXAGE;
  2692. #else
  2693. *sint_ptr = 0;
  2694. #endif
  2695. }
  2696. break;
  2697. case 14: /* ipReasmReqds */
  2698. {
  2699. u32_t *uint_ptr = value;
  2700. *uint_ptr = ipreasmreqds;
  2701. }
  2702. break;
  2703. case 15: /* ipReasmOKs */
  2704. {
  2705. u32_t *uint_ptr = value;
  2706. *uint_ptr = ipreasmoks;
  2707. }
  2708. break;
  2709. case 16: /* ipReasmFails */
  2710. {
  2711. u32_t *uint_ptr = value;
  2712. *uint_ptr = ipreasmfails;
  2713. }
  2714. break;
  2715. case 17: /* ipFragOKs */
  2716. {
  2717. u32_t *uint_ptr = value;
  2718. *uint_ptr = ipfragoks;
  2719. }
  2720. break;
  2721. case 18: /* ipFragFails */
  2722. {
  2723. u32_t *uint_ptr = value;
  2724. *uint_ptr = ipfragfails;
  2725. }
  2726. break;
  2727. case 19: /* ipFragCreates */
  2728. {
  2729. u32_t *uint_ptr = value;
  2730. *uint_ptr = ipfragcreates;
  2731. }
  2732. break;
  2733. case 23: /* ipRoutingDiscards */
  2734. /** @todo can lwIP discard routes at all?? hardwire this to 0?? */
  2735. {
  2736. u32_t *uint_ptr = value;
  2737. *uint_ptr = iproutingdiscards;
  2738. }
  2739. break;
  2740. };
  2741. }
  2742. /**
  2743. * Test ip object value before setting.
  2744. *
  2745. * @param od is the object definition
  2746. * @param len return value space (in bytes)
  2747. * @param value points to (varbind) space to copy value from.
  2748. *
  2749. * @note we allow set if the value matches the hardwired value,
  2750. * otherwise return badvalue.
  2751. */
  2752. static u8_t
  2753. ip_set_test(struct obj_def *od, u16_t len, void *value)
  2754. {
  2755. u8_t id, set_ok;
  2756. s32_t *sint_ptr = value;
  2757. LWIP_UNUSED_ARG(len);
  2758. set_ok = 0;
  2759. id = od->id_inst_ptr[0];
  2760. switch (id)
  2761. {
  2762. case 1: /* ipForwarding */
  2763. #if IP_FORWARD
  2764. /* forwarding */
  2765. if (*sint_ptr == 1)
  2766. #else
  2767. /* not-forwarding */
  2768. if (*sint_ptr == 2)
  2769. #endif
  2770. {
  2771. set_ok = 1;
  2772. }
  2773. break;
  2774. case 2: /* ipDefaultTTL */
  2775. if (*sint_ptr == IP_DEFAULT_TTL)
  2776. {
  2777. set_ok = 1;
  2778. }
  2779. break;
  2780. };
  2781. return set_ok;
  2782. }
  2783. static void
  2784. ip_addrentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
  2785. {
  2786. /* return to object name, adding index depth (4) */
  2787. ident_len += 4;
  2788. ident -= 4;
  2789. if (ident_len == 5)
  2790. {
  2791. u8_t id;
  2792. od->id_inst_len = ident_len;
  2793. od->id_inst_ptr = ident;
  2794. id = ident[0];
  2795. switch (id)
  2796. {
  2797. case 1: /* ipAdEntAddr */
  2798. case 3: /* ipAdEntNetMask */
  2799. od->instance = MIB_OBJECT_TAB;
  2800. od->access = MIB_OBJECT_READ_ONLY;
  2801. od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
  2802. od->v_len = 4;
  2803. break;
  2804. case 2: /* ipAdEntIfIndex */
  2805. case 4: /* ipAdEntBcastAddr */
  2806. case 5: /* ipAdEntReasmMaxSize */
  2807. od->instance = MIB_OBJECT_TAB;
  2808. od->access = MIB_OBJECT_READ_ONLY;
  2809. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
  2810. od->v_len = sizeof(s32_t);
  2811. break;
  2812. default:
  2813. LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_addrentry_get_object_def: no such object\n"));
  2814. od->instance = MIB_OBJECT_NONE;
  2815. break;
  2816. }
  2817. }
  2818. else
  2819. {
  2820. LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_addrentry_get_object_def: no scalar\n"));
  2821. od->instance = MIB_OBJECT_NONE;
  2822. }
  2823. }
  2824. static void
  2825. ip_addrentry_get_value(struct obj_def *od, u16_t len, void *value)
  2826. {
  2827. u8_t id;
  2828. u16_t ifidx;
  2829. struct ip_addr ip;
  2830. struct netif *netif = netif_list;
  2831. LWIP_UNUSED_ARG(len);
  2832. snmp_oidtoip(&od->id_inst_ptr[1], &ip);
  2833. ip.addr = htonl(ip.addr);
  2834. ifidx = 0;
  2835. while ((netif != NULL) && !ip_addr_cmp(&ip, &netif->ip_addr))
  2836. {
  2837. netif = netif->next;
  2838. ifidx++;
  2839. }
  2840. if (netif != NULL)
  2841. {
  2842. id = od->id_inst_ptr[0];
  2843. switch (id)
  2844. {
  2845. case 1: /* ipAdEntAddr */
  2846. {
  2847. struct ip_addr *dst = value;
  2848. *dst = netif->ip_addr;
  2849. }
  2850. break;
  2851. case 2: /* ipAdEntIfIndex */
  2852. {
  2853. s32_t *sint_ptr = value;
  2854. *sint_ptr = ifidx + 1;
  2855. }
  2856. break;
  2857. case 3: /* ipAdEntNetMask */
  2858. {
  2859. struct ip_addr *dst = value;
  2860. *dst = netif->netmask;
  2861. }
  2862. break;
  2863. case 4: /* ipAdEntBcastAddr */
  2864. {
  2865. s32_t *sint_ptr = value;
  2866. /* lwIP oddity, there's no broadcast
  2867. address in the netif we can rely on */
  2868. *sint_ptr = ip_addr_broadcast.addr & 1;
  2869. }
  2870. break;
  2871. case 5: /* ipAdEntReasmMaxSize */
  2872. {
  2873. s32_t *sint_ptr = value;
  2874. #if IP_REASSEMBLY
  2875. /* @todo The theoretical maximum is IP_REASS_MAX_PBUFS * size of the pbufs,
  2876. * but only if receiving one fragmented packet at a time.
  2877. * The current solution is to calculate for 2 simultaneous packets...
  2878. */
  2879. *sint_ptr = (IP_HLEN + ((IP_REASS_MAX_PBUFS/2) *
  2880. (PBUF_POOL_BUFSIZE - PBUF_LINK_HLEN - IP_HLEN)));
  2881. #else
  2882. /** @todo returning MTU would be a bad thing and
  2883. returning a wild guess like '576' isn't good either */
  2884. *sint_ptr = 0;
  2885. #endif
  2886. }
  2887. break;
  2888. }
  2889. }
  2890. }
  2891. /**
  2892. * @note
  2893. * lwIP IP routing is currently using the network addresses in netif_list.
  2894. * if no suitable network IP is found in netif_list, the default_netif is used.
  2895. */
  2896. static void
  2897. ip_rteentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
  2898. {
  2899. u8_t id;
  2900. /* return to object name, adding index depth (4) */
  2901. ident_len += 4;
  2902. ident -= 4;
  2903. if (ident_len == 5)
  2904. {
  2905. od->id_inst_len = ident_len;
  2906. od->id_inst_ptr = ident;
  2907. id = ident[0];
  2908. switch (id)
  2909. {
  2910. case 1: /* ipRouteDest */
  2911. case 7: /* ipRouteNextHop */
  2912. case 11: /* ipRouteMask */
  2913. od->instance = MIB_OBJECT_TAB;
  2914. od->access = MIB_OBJECT_READ_WRITE;
  2915. od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
  2916. od->v_len = 4;
  2917. break;
  2918. case 2: /* ipRouteIfIndex */
  2919. case 3: /* ipRouteMetric1 */
  2920. case 4: /* ipRouteMetric2 */
  2921. case 5: /* ipRouteMetric3 */
  2922. case 6: /* ipRouteMetric4 */
  2923. case 8: /* ipRouteType */
  2924. case 10: /* ipRouteAge */
  2925. case 12: /* ipRouteMetric5 */
  2926. od->instance = MIB_OBJECT_TAB;
  2927. od->access = MIB_OBJECT_READ_WRITE;
  2928. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
  2929. od->v_len = sizeof(s32_t);
  2930. break;
  2931. case 9: /* ipRouteProto */
  2932. od->instance = MIB_OBJECT_TAB;
  2933. od->access = MIB_OBJECT_READ_ONLY;
  2934. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
  2935. od->v_len = sizeof(s32_t);
  2936. break;
  2937. case 13: /* ipRouteInfo */
  2938. /** @note returning zeroDotZero (0.0) no routing protocol specific MIB */
  2939. od->instance = MIB_OBJECT_TAB;
  2940. od->access = MIB_OBJECT_READ_ONLY;
  2941. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OBJ_ID);
  2942. od->v_len = iprouteinfo.len * sizeof(s32_t);
  2943. break;
  2944. default:
  2945. LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_rteentry_get_object_def: no such object\n"));
  2946. od->instance = MIB_OBJECT_NONE;
  2947. break;
  2948. }
  2949. }
  2950. else
  2951. {
  2952. LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_rteentry_get_object_def: no scalar\n"));
  2953. od->instance = MIB_OBJECT_NONE;
  2954. }
  2955. }
  2956. static void
  2957. ip_rteentry_get_value(struct obj_def *od, u16_t len, void *value)
  2958. {
  2959. struct netif *netif;
  2960. struct ip_addr dest;
  2961. s32_t *ident;
  2962. u8_t id;
  2963. ident = od->id_inst_ptr;
  2964. snmp_oidtoip(&ident[1], &dest);
  2965. dest.addr = htonl(dest.addr);
  2966. if (dest.addr == 0)
  2967. {
  2968. /* ip_route() uses default netif for default route */
  2969. netif = netif_default;
  2970. }
  2971. else
  2972. {
  2973. /* not using ip_route(), need exact match! */
  2974. netif = netif_list;
  2975. while ((netif != NULL) &&
  2976. !ip_addr_netcmp(&dest, &(netif->ip_addr), &(netif->netmask)) )
  2977. {
  2978. netif = netif->next;
  2979. }
  2980. }
  2981. if (netif != NULL)
  2982. {
  2983. id = ident[0];
  2984. switch (id)
  2985. {
  2986. case 1: /* ipRouteDest */
  2987. {
  2988. struct ip_addr *dst = value;
  2989. if (dest.addr == 0)
  2990. {
  2991. /* default rte has 0.0.0.0 dest */
  2992. dst->addr = 0;
  2993. }
  2994. else
  2995. {
  2996. /* netifs have netaddress dest */
  2997. dst->addr = netif->ip_addr.addr & netif->netmask.addr;
  2998. }
  2999. }
  3000. break;
  3001. case 2: /* ipRouteIfIndex */
  3002. {
  3003. s32_t *sint_ptr = value;
  3004. snmp_netiftoifindex(netif, sint_ptr);
  3005. }
  3006. break;
  3007. case 3: /* ipRouteMetric1 */
  3008. {
  3009. s32_t *sint_ptr = value;
  3010. if (dest.addr == 0)
  3011. {
  3012. /* default rte has metric 1 */
  3013. *sint_ptr = 1;
  3014. }
  3015. else
  3016. {
  3017. /* other rtes have metric 0 */
  3018. *sint_ptr = 0;
  3019. }
  3020. }
  3021. break;
  3022. case 4: /* ipRouteMetric2 */
  3023. case 5: /* ipRouteMetric3 */
  3024. case 6: /* ipRouteMetric4 */
  3025. case 12: /* ipRouteMetric5 */
  3026. {
  3027. s32_t *sint_ptr = value;
  3028. /* not used */
  3029. *sint_ptr = -1;
  3030. }
  3031. break;
  3032. case 7: /* ipRouteNextHop */
  3033. {
  3034. struct ip_addr *dst = value;
  3035. if (dest.addr == 0)
  3036. {
  3037. /* default rte: gateway */
  3038. *dst = netif->gw;
  3039. }
  3040. else
  3041. {
  3042. /* other rtes: netif ip_addr */
  3043. *dst = netif->ip_addr;
  3044. }
  3045. }
  3046. break;
  3047. case 8: /* ipRouteType */
  3048. {
  3049. s32_t *sint_ptr = value;
  3050. if (dest.addr == 0)
  3051. {
  3052. /* default rte is indirect */
  3053. *sint_ptr = 4;
  3054. }
  3055. else
  3056. {
  3057. /* other rtes are direct */
  3058. *sint_ptr = 3;
  3059. }
  3060. }
  3061. break;
  3062. case 9: /* ipRouteProto */
  3063. {
  3064. s32_t *sint_ptr = value;
  3065. /* locally defined routes */
  3066. *sint_ptr = 2;
  3067. }
  3068. break;
  3069. case 10: /* ipRouteAge */
  3070. {
  3071. s32_t *sint_ptr = value;
  3072. /** @todo (sysuptime - timestamp last change) / 100
  3073. @see snmp_insert_iprteidx_tree() */
  3074. *sint_ptr = 0;
  3075. }
  3076. break;
  3077. case 11: /* ipRouteMask */
  3078. {
  3079. struct ip_addr *dst = value;
  3080. if (dest.addr == 0)
  3081. {
  3082. /* default rte use 0.0.0.0 mask */
  3083. dst->addr = 0;
  3084. }
  3085. else
  3086. {
  3087. /* other rtes use netmask */
  3088. *dst = netif->netmask;
  3089. }
  3090. }
  3091. break;
  3092. case 13: /* ipRouteInfo */
  3093. objectidncpy((s32_t*)value, (s32_t*)iprouteinfo.id, (u8_t)(len / sizeof(s32_t)));
  3094. break;
  3095. }
  3096. }
  3097. }
  3098. static void
  3099. ip_ntomentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
  3100. {
  3101. /* return to object name, adding index depth (5) */
  3102. ident_len += 5;
  3103. ident -= 5;
  3104. if (ident_len == 6)
  3105. {
  3106. u8_t id;
  3107. od->id_inst_len = ident_len;
  3108. od->id_inst_ptr = ident;
  3109. id = ident[0];
  3110. switch (id)
  3111. {
  3112. case 1: /* ipNetToMediaIfIndex */
  3113. case 4: /* ipNetToMediaType */
  3114. od->instance = MIB_OBJECT_TAB;
  3115. od->access = MIB_OBJECT_READ_WRITE;
  3116. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
  3117. od->v_len = sizeof(s32_t);
  3118. break;
  3119. case 2: /* ipNetToMediaPhysAddress */
  3120. od->instance = MIB_OBJECT_TAB;
  3121. od->access = MIB_OBJECT_READ_WRITE;
  3122. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_OC_STR);
  3123. od->v_len = 6; /** @todo try to use netif::hwaddr_len */
  3124. break;
  3125. case 3: /* ipNetToMediaNetAddress */
  3126. od->instance = MIB_OBJECT_TAB;
  3127. od->access = MIB_OBJECT_READ_WRITE;
  3128. od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
  3129. od->v_len = 4;
  3130. break;
  3131. default:
  3132. LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_ntomentry_get_object_def: no such object\n"));
  3133. od->instance = MIB_OBJECT_NONE;
  3134. break;
  3135. }
  3136. }
  3137. else
  3138. {
  3139. LWIP_DEBUGF(SNMP_MIB_DEBUG,("ip_ntomentry_get_object_def: no scalar\n"));
  3140. od->instance = MIB_OBJECT_NONE;
  3141. }
  3142. }
  3143. static void
  3144. ip_ntomentry_get_value(struct obj_def *od, u16_t len, void *value)
  3145. {
  3146. #if LWIP_ARP
  3147. u8_t id;
  3148. struct eth_addr* ethaddr_ret;
  3149. struct ip_addr* ipaddr_ret;
  3150. #endif /* LWIP_ARP */
  3151. struct ip_addr ip;
  3152. struct netif *netif;
  3153. LWIP_UNUSED_ARG(len);
  3154. LWIP_UNUSED_ARG(value);/* if !LWIP_ARP */
  3155. snmp_ifindextonetif(od->id_inst_ptr[1], &netif);
  3156. snmp_oidtoip(&od->id_inst_ptr[2], &ip);
  3157. ip.addr = htonl(ip.addr);
  3158. #if LWIP_ARP /** @todo implement a netif_find_addr */
  3159. if (etharp_find_addr(netif, &ip, &ethaddr_ret, &ipaddr_ret) > -1)
  3160. {
  3161. id = od->id_inst_ptr[0];
  3162. switch (id)
  3163. {
  3164. case 1: /* ipNetToMediaIfIndex */
  3165. {
  3166. s32_t *sint_ptr = value;
  3167. *sint_ptr = od->id_inst_ptr[1];
  3168. }
  3169. break;
  3170. case 2: /* ipNetToMediaPhysAddress */
  3171. {
  3172. struct eth_addr *dst = value;
  3173. *dst = *ethaddr_ret;
  3174. }
  3175. break;
  3176. case 3: /* ipNetToMediaNetAddress */
  3177. {
  3178. struct ip_addr *dst = value;
  3179. *dst = *ipaddr_ret;
  3180. }
  3181. break;
  3182. case 4: /* ipNetToMediaType */
  3183. {
  3184. s32_t *sint_ptr = value;
  3185. /* dynamic (?) */
  3186. *sint_ptr = 3;
  3187. }
  3188. break;
  3189. }
  3190. }
  3191. #endif /* LWIP_ARP */
  3192. }
  3193. static void
  3194. icmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
  3195. {
  3196. /* return to object name, adding index depth (1) */
  3197. ident_len += 1;
  3198. ident -= 1;
  3199. if ((ident_len == 2) &&
  3200. (ident[0] > 0) && (ident[0] < 27))
  3201. {
  3202. od->id_inst_len = ident_len;
  3203. od->id_inst_ptr = ident;
  3204. od->instance = MIB_OBJECT_SCALAR;
  3205. od->access = MIB_OBJECT_READ_ONLY;
  3206. od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
  3207. od->v_len = sizeof(u32_t);
  3208. }
  3209. else
  3210. {
  3211. LWIP_DEBUGF(SNMP_MIB_DEBUG,("icmp_get_object_def: no scalar\n"));
  3212. od->instance = MIB_OBJECT_NONE;
  3213. }
  3214. }
  3215. static void
  3216. icmp_get_value(struct obj_def *od, u16_t len, void *value)
  3217. {
  3218. u32_t *uint_ptr = value;
  3219. u8_t id;
  3220. LWIP_UNUSED_ARG(len);
  3221. id = od->id_inst_ptr[0];
  3222. switch (id)
  3223. {
  3224. case 1: /* icmpInMsgs */
  3225. *uint_ptr = icmpinmsgs;
  3226. break;
  3227. case 2: /* icmpInErrors */
  3228. *uint_ptr = icmpinerrors;
  3229. break;
  3230. case 3: /* icmpInDestUnreachs */
  3231. *uint_ptr = icmpindestunreachs;
  3232. break;
  3233. case 4: /* icmpInTimeExcds */
  3234. *uint_ptr = icmpintimeexcds;
  3235. break;
  3236. case 5: /* icmpInParmProbs */
  3237. *uint_ptr = icmpinparmprobs;
  3238. break;
  3239. case 6: /* icmpInSrcQuenchs */
  3240. *uint_ptr = icmpinsrcquenchs;
  3241. break;
  3242. case 7: /* icmpInRedirects */
  3243. *uint_ptr = icmpinredirects;
  3244. break;
  3245. case 8: /* icmpInEchos */
  3246. *uint_ptr = icmpinechos;
  3247. break;
  3248. case 9: /* icmpInEchoReps */
  3249. *uint_ptr = icmpinechoreps;
  3250. break;
  3251. case 10: /* icmpInTimestamps */
  3252. *uint_ptr = icmpintimestamps;
  3253. break;
  3254. case 11: /* icmpInTimestampReps */
  3255. *uint_ptr = icmpintimestampreps;
  3256. break;
  3257. case 12: /* icmpInAddrMasks */
  3258. *uint_ptr = icmpinaddrmasks;
  3259. break;
  3260. case 13: /* icmpInAddrMaskReps */
  3261. *uint_ptr = icmpinaddrmaskreps;
  3262. break;
  3263. case 14: /* icmpOutMsgs */
  3264. *uint_ptr = icmpoutmsgs;
  3265. break;
  3266. case 15: /* icmpOutErrors */
  3267. *uint_ptr = icmpouterrors;
  3268. break;
  3269. case 16: /* icmpOutDestUnreachs */
  3270. *uint_ptr = icmpoutdestunreachs;
  3271. break;
  3272. case 17: /* icmpOutTimeExcds */
  3273. *uint_ptr = icmpouttimeexcds;
  3274. break;
  3275. case 18: /* icmpOutParmProbs */
  3276. *uint_ptr = icmpoutparmprobs;
  3277. break;
  3278. case 19: /* icmpOutSrcQuenchs */
  3279. *uint_ptr = icmpoutsrcquenchs;
  3280. break;
  3281. case 20: /* icmpOutRedirects */
  3282. *uint_ptr = icmpoutredirects;
  3283. break;
  3284. case 21: /* icmpOutEchos */
  3285. *uint_ptr = icmpoutechos;
  3286. break;
  3287. case 22: /* icmpOutEchoReps */
  3288. *uint_ptr = icmpoutechoreps;
  3289. break;
  3290. case 23: /* icmpOutTimestamps */
  3291. *uint_ptr = icmpouttimestamps;
  3292. break;
  3293. case 24: /* icmpOutTimestampReps */
  3294. *uint_ptr = icmpouttimestampreps;
  3295. break;
  3296. case 25: /* icmpOutAddrMasks */
  3297. *uint_ptr = icmpoutaddrmasks;
  3298. break;
  3299. case 26: /* icmpOutAddrMaskReps */
  3300. *uint_ptr = icmpoutaddrmaskreps;
  3301. break;
  3302. }
  3303. }
  3304. #if LWIP_TCP
  3305. /** @todo tcp grp */
  3306. static void
  3307. tcp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
  3308. {
  3309. u8_t id;
  3310. /* return to object name, adding index depth (1) */
  3311. ident_len += 1;
  3312. ident -= 1;
  3313. if (ident_len == 2)
  3314. {
  3315. od->id_inst_len = ident_len;
  3316. od->id_inst_ptr = ident;
  3317. id = ident[0];
  3318. LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def tcp.%"U16_F".0\n",(u16_t)id));
  3319. switch (id)
  3320. {
  3321. case 1: /* tcpRtoAlgorithm */
  3322. case 2: /* tcpRtoMin */
  3323. case 3: /* tcpRtoMax */
  3324. case 4: /* tcpMaxConn */
  3325. od->instance = MIB_OBJECT_SCALAR;
  3326. od->access = MIB_OBJECT_READ_ONLY;
  3327. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
  3328. od->v_len = sizeof(s32_t);
  3329. break;
  3330. case 5: /* tcpActiveOpens */
  3331. case 6: /* tcpPassiveOpens */
  3332. case 7: /* tcpAttemptFails */
  3333. case 8: /* tcpEstabResets */
  3334. case 10: /* tcpInSegs */
  3335. case 11: /* tcpOutSegs */
  3336. case 12: /* tcpRetransSegs */
  3337. case 14: /* tcpInErrs */
  3338. case 15: /* tcpOutRsts */
  3339. od->instance = MIB_OBJECT_SCALAR;
  3340. od->access = MIB_OBJECT_READ_ONLY;
  3341. od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
  3342. od->v_len = sizeof(u32_t);
  3343. break;
  3344. case 9: /* tcpCurrEstab */
  3345. od->instance = MIB_OBJECT_TAB;
  3346. od->access = MIB_OBJECT_READ_ONLY;
  3347. od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_GAUGE);
  3348. od->v_len = sizeof(u32_t);
  3349. break;
  3350. default:
  3351. LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_object_def: no such object\n"));
  3352. od->instance = MIB_OBJECT_NONE;
  3353. break;
  3354. };
  3355. }
  3356. else
  3357. {
  3358. LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcp_get_object_def: no scalar\n"));
  3359. od->instance = MIB_OBJECT_NONE;
  3360. }
  3361. }
  3362. static void
  3363. tcp_get_value(struct obj_def *od, u16_t len, void *value)
  3364. {
  3365. u32_t *uint_ptr = value;
  3366. s32_t *sint_ptr = value;
  3367. u8_t id;
  3368. LWIP_UNUSED_ARG(len);
  3369. id = od->id_inst_ptr[0];
  3370. switch (id)
  3371. {
  3372. case 1: /* tcpRtoAlgorithm, vanj(4) */
  3373. *sint_ptr = 4;
  3374. break;
  3375. case 2: /* tcpRtoMin */
  3376. /* @todo not the actual value, a guess,
  3377. needs to be calculated */
  3378. *sint_ptr = 1000;
  3379. break;
  3380. case 3: /* tcpRtoMax */
  3381. /* @todo not the actual value, a guess,
  3382. needs to be calculated */
  3383. *sint_ptr = 60000;
  3384. break;
  3385. case 4: /* tcpMaxConn */
  3386. *sint_ptr = MEMP_NUM_TCP_PCB;
  3387. break;
  3388. case 5: /* tcpActiveOpens */
  3389. *uint_ptr = tcpactiveopens;
  3390. break;
  3391. case 6: /* tcpPassiveOpens */
  3392. *uint_ptr = tcppassiveopens;
  3393. break;
  3394. case 7: /* tcpAttemptFails */
  3395. *uint_ptr = tcpattemptfails;
  3396. break;
  3397. case 8: /* tcpEstabResets */
  3398. *uint_ptr = tcpestabresets;
  3399. break;
  3400. case 9: /* tcpCurrEstab */
  3401. {
  3402. u16_t tcpcurrestab = 0;
  3403. struct tcp_pcb *pcb = tcp_active_pcbs;
  3404. while (pcb != NULL)
  3405. {
  3406. if ((pcb->state == ESTABLISHED) ||
  3407. (pcb->state == CLOSE_WAIT))
  3408. {
  3409. tcpcurrestab++;
  3410. }
  3411. pcb = pcb->next;
  3412. }
  3413. *uint_ptr = tcpcurrestab;
  3414. }
  3415. break;
  3416. case 10: /* tcpInSegs */
  3417. *uint_ptr = tcpinsegs;
  3418. break;
  3419. case 11: /* tcpOutSegs */
  3420. *uint_ptr = tcpoutsegs;
  3421. break;
  3422. case 12: /* tcpRetransSegs */
  3423. *uint_ptr = tcpretranssegs;
  3424. break;
  3425. case 14: /* tcpInErrs */
  3426. *uint_ptr = tcpinerrs;
  3427. break;
  3428. case 15: /* tcpOutRsts */
  3429. *uint_ptr = tcpoutrsts;
  3430. break;
  3431. }
  3432. }
  3433. #ifdef THIS_SEEMS_UNUSED
  3434. static void
  3435. tcpconnentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
  3436. {
  3437. /* return to object name, adding index depth (10) */
  3438. ident_len += 10;
  3439. ident -= 10;
  3440. if (ident_len == 11)
  3441. {
  3442. u8_t id;
  3443. od->id_inst_len = ident_len;
  3444. od->id_inst_ptr = ident;
  3445. id = ident[0];
  3446. LWIP_DEBUGF(SNMP_MIB_DEBUG,("get_object_def tcp.%"U16_F".0\n",(u16_t)id));
  3447. switch (id)
  3448. {
  3449. case 1: /* tcpConnState */
  3450. od->instance = MIB_OBJECT_TAB;
  3451. od->access = MIB_OBJECT_READ_WRITE;
  3452. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
  3453. od->v_len = sizeof(s32_t);
  3454. break;
  3455. case 2: /* tcpConnLocalAddress */
  3456. case 4: /* tcpConnRemAddress */
  3457. od->instance = MIB_OBJECT_TAB;
  3458. od->access = MIB_OBJECT_READ_ONLY;
  3459. od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
  3460. od->v_len = 4;
  3461. break;
  3462. case 3: /* tcpConnLocalPort */
  3463. case 5: /* tcpConnRemPort */
  3464. od->instance = MIB_OBJECT_TAB;
  3465. od->access = MIB_OBJECT_READ_ONLY;
  3466. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
  3467. od->v_len = sizeof(s32_t);
  3468. break;
  3469. default:
  3470. LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcpconnentry_get_object_def: no such object\n"));
  3471. od->instance = MIB_OBJECT_NONE;
  3472. break;
  3473. };
  3474. }
  3475. else
  3476. {
  3477. LWIP_DEBUGF(SNMP_MIB_DEBUG,("tcpconnentry_get_object_def: no such object\n"));
  3478. od->instance = MIB_OBJECT_NONE;
  3479. }
  3480. }
  3481. static void
  3482. tcpconnentry_get_value(struct obj_def *od, u16_t len, void *value)
  3483. {
  3484. struct ip_addr lip, rip;
  3485. u16_t lport, rport;
  3486. s32_t *ident;
  3487. ident = od->id_inst_ptr;
  3488. snmp_oidtoip(&ident[1], &lip);
  3489. lip.addr = htonl(lip.addr);
  3490. lport = ident[5];
  3491. snmp_oidtoip(&ident[6], &rip);
  3492. rip.addr = htonl(rip.addr);
  3493. rport = ident[10];
  3494. /** @todo find matching PCB */
  3495. }
  3496. #endif /* if 0 */
  3497. #endif
  3498. static void
  3499. udp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
  3500. {
  3501. /* return to object name, adding index depth (1) */
  3502. ident_len += 1;
  3503. ident -= 1;
  3504. if ((ident_len == 2) &&
  3505. (ident[0] > 0) && (ident[0] < 6))
  3506. {
  3507. od->id_inst_len = ident_len;
  3508. od->id_inst_ptr = ident;
  3509. od->instance = MIB_OBJECT_SCALAR;
  3510. od->access = MIB_OBJECT_READ_ONLY;
  3511. od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
  3512. od->v_len = sizeof(u32_t);
  3513. }
  3514. else
  3515. {
  3516. LWIP_DEBUGF(SNMP_MIB_DEBUG,("udp_get_object_def: no scalar\n"));
  3517. od->instance = MIB_OBJECT_NONE;
  3518. }
  3519. }
  3520. static void
  3521. udp_get_value(struct obj_def *od, u16_t len, void *value)
  3522. {
  3523. u32_t *uint_ptr = value;
  3524. u8_t id;
  3525. LWIP_UNUSED_ARG(len);
  3526. id = od->id_inst_ptr[0];
  3527. switch (id)
  3528. {
  3529. case 1: /* udpInDatagrams */
  3530. *uint_ptr = udpindatagrams;
  3531. break;
  3532. case 2: /* udpNoPorts */
  3533. *uint_ptr = udpnoports;
  3534. break;
  3535. case 3: /* udpInErrors */
  3536. *uint_ptr = udpinerrors;
  3537. break;
  3538. case 4: /* udpOutDatagrams */
  3539. *uint_ptr = udpoutdatagrams;
  3540. break;
  3541. }
  3542. }
  3543. static void
  3544. udpentry_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
  3545. {
  3546. /* return to object name, adding index depth (5) */
  3547. ident_len += 5;
  3548. ident -= 5;
  3549. if (ident_len == 6)
  3550. {
  3551. od->id_inst_len = ident_len;
  3552. od->id_inst_ptr = ident;
  3553. switch (ident[0])
  3554. {
  3555. case 1: /* udpLocalAddress */
  3556. od->instance = MIB_OBJECT_TAB;
  3557. od->access = MIB_OBJECT_READ_ONLY;
  3558. od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_IPADDR);
  3559. od->v_len = 4;
  3560. break;
  3561. case 2: /* udpLocalPort */
  3562. od->instance = MIB_OBJECT_TAB;
  3563. od->access = MIB_OBJECT_READ_ONLY;
  3564. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
  3565. od->v_len = sizeof(s32_t);
  3566. break;
  3567. default:
  3568. LWIP_DEBUGF(SNMP_MIB_DEBUG,("udpentry_get_object_def: no such object\n"));
  3569. od->instance = MIB_OBJECT_NONE;
  3570. break;
  3571. }
  3572. }
  3573. else
  3574. {
  3575. LWIP_DEBUGF(SNMP_MIB_DEBUG,("udpentry_get_object_def: no scalar\n"));
  3576. od->instance = MIB_OBJECT_NONE;
  3577. }
  3578. }
  3579. static void
  3580. udpentry_get_value(struct obj_def *od, u16_t len, void *value)
  3581. {
  3582. u8_t id;
  3583. struct udp_pcb *pcb;
  3584. struct ip_addr ip;
  3585. u16_t port;
  3586. LWIP_UNUSED_ARG(len);
  3587. snmp_oidtoip(&od->id_inst_ptr[1], &ip);
  3588. ip.addr = htonl(ip.addr);
  3589. port = od->id_inst_ptr[5];
  3590. pcb = udp_pcbs;
  3591. while ((pcb != NULL) &&
  3592. !((pcb->local_ip.addr == ip.addr) &&
  3593. (pcb->local_port == port)))
  3594. {
  3595. pcb = pcb->next;
  3596. }
  3597. if (pcb != NULL)
  3598. {
  3599. id = od->id_inst_ptr[0];
  3600. switch (id)
  3601. {
  3602. case 1: /* udpLocalAddress */
  3603. {
  3604. struct ip_addr *dst = value;
  3605. *dst = pcb->local_ip;
  3606. }
  3607. break;
  3608. case 2: /* udpLocalPort */
  3609. {
  3610. s32_t *sint_ptr = value;
  3611. *sint_ptr = pcb->local_port;
  3612. }
  3613. break;
  3614. }
  3615. }
  3616. }
  3617. static void
  3618. snmp_get_object_def(u8_t ident_len, s32_t *ident, struct obj_def *od)
  3619. {
  3620. /* return to object name, adding index depth (1) */
  3621. ident_len += 1;
  3622. ident -= 1;
  3623. if (ident_len == 2)
  3624. {
  3625. u8_t id;
  3626. od->id_inst_len = ident_len;
  3627. od->id_inst_ptr = ident;
  3628. id = ident[0];
  3629. switch (id)
  3630. {
  3631. case 1: /* snmpInPkts */
  3632. case 2: /* snmpOutPkts */
  3633. case 3: /* snmpInBadVersions */
  3634. case 4: /* snmpInBadCommunityNames */
  3635. case 5: /* snmpInBadCommunityUses */
  3636. case 6: /* snmpInASNParseErrs */
  3637. case 8: /* snmpInTooBigs */
  3638. case 9: /* snmpInNoSuchNames */
  3639. case 10: /* snmpInBadValues */
  3640. case 11: /* snmpInReadOnlys */
  3641. case 12: /* snmpInGenErrs */
  3642. case 13: /* snmpInTotalReqVars */
  3643. case 14: /* snmpInTotalSetVars */
  3644. case 15: /* snmpInGetRequests */
  3645. case 16: /* snmpInGetNexts */
  3646. case 17: /* snmpInSetRequests */
  3647. case 18: /* snmpInGetResponses */
  3648. case 19: /* snmpInTraps */
  3649. case 20: /* snmpOutTooBigs */
  3650. case 21: /* snmpOutNoSuchNames */
  3651. case 22: /* snmpOutBadValues */
  3652. case 24: /* snmpOutGenErrs */
  3653. case 25: /* snmpOutGetRequests */
  3654. case 26: /* snmpOutGetNexts */
  3655. case 27: /* snmpOutSetRequests */
  3656. case 28: /* snmpOutGetResponses */
  3657. case 29: /* snmpOutTraps */
  3658. od->instance = MIB_OBJECT_SCALAR;
  3659. od->access = MIB_OBJECT_READ_ONLY;
  3660. od->asn_type = (SNMP_ASN1_APPLIC | SNMP_ASN1_PRIMIT | SNMP_ASN1_COUNTER);
  3661. od->v_len = sizeof(u32_t);
  3662. break;
  3663. case 30: /* snmpEnableAuthenTraps */
  3664. od->instance = MIB_OBJECT_SCALAR;
  3665. od->access = MIB_OBJECT_READ_WRITE;
  3666. od->asn_type = (SNMP_ASN1_UNIV | SNMP_ASN1_PRIMIT | SNMP_ASN1_INTEG);
  3667. od->v_len = sizeof(s32_t);
  3668. break;
  3669. default:
  3670. LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_object_def: no such object\n"));
  3671. od->instance = MIB_OBJECT_NONE;
  3672. break;
  3673. };
  3674. }
  3675. else
  3676. {
  3677. LWIP_DEBUGF(SNMP_MIB_DEBUG,("snmp_get_object_def: no scalar\n"));
  3678. od->instance = MIB_OBJECT_NONE;
  3679. }
  3680. }
  3681. static void
  3682. snmp_get_value(struct obj_def *od, u16_t len, void *value)
  3683. {
  3684. u32_t *uint_ptr = value;
  3685. u8_t id;
  3686. LWIP_UNUSED_ARG(len);
  3687. id = od->id_inst_ptr[0];
  3688. switch (id)
  3689. {
  3690. case 1: /* snmpInPkts */
  3691. *uint_ptr = snmpinpkts;
  3692. break;
  3693. case 2: /* snmpOutPkts */
  3694. *uint_ptr = snmpoutpkts;
  3695. break;
  3696. case 3: /* snmpInBadVersions */
  3697. *uint_ptr = snmpinbadversions;
  3698. break;
  3699. case 4: /* snmpInBadCommunityNames */
  3700. *uint_ptr = snmpinbadcommunitynames;
  3701. break;
  3702. case 5: /* snmpInBadCommunityUses */
  3703. *uint_ptr = snmpinbadcommunityuses;
  3704. break;
  3705. case 6: /* snmpInASNParseErrs */
  3706. *uint_ptr = snmpinasnparseerrs;
  3707. break;
  3708. case 8: /* snmpInTooBigs */
  3709. *uint_ptr = snmpintoobigs;
  3710. break;
  3711. case 9: /* snmpInNoSuchNames */
  3712. *uint_ptr = snmpinnosuchnames;
  3713. break;
  3714. case 10: /* snmpInBadValues */
  3715. *uint_ptr = snmpinbadvalues;
  3716. break;
  3717. case 11: /* snmpInReadOnlys */
  3718. *uint_ptr = snmpinreadonlys;
  3719. break;
  3720. case 12: /* snmpInGenErrs */
  3721. *uint_ptr = snmpingenerrs;
  3722. break;
  3723. case 13: /* snmpInTotalReqVars */
  3724. *uint_ptr = snmpintotalreqvars;
  3725. break;
  3726. case 14: /* snmpInTotalSetVars */
  3727. *uint_ptr = snmpintotalsetvars;
  3728. break;
  3729. case 15: /* snmpInGetRequests */
  3730. *uint_ptr = snmpingetrequests;
  3731. break;
  3732. case 16: /* snmpInGetNexts */
  3733. *uint_ptr = snmpingetnexts;
  3734. break;
  3735. case 17: /* snmpInSetRequests */
  3736. *uint_ptr = snmpinsetrequests;
  3737. break;
  3738. case 18: /* snmpInGetResponses */
  3739. *uint_ptr = snmpingetresponses;
  3740. break;
  3741. case 19: /* snmpInTraps */
  3742. *uint_ptr = snmpintraps;
  3743. break;
  3744. case 20: /* snmpOutTooBigs */
  3745. *uint_ptr = snmpouttoobigs;
  3746. break;
  3747. case 21: /* snmpOutNoSuchNames */
  3748. *uint_ptr = snmpoutnosuchnames;
  3749. break;
  3750. case 22: /* snmpOutBadValues */
  3751. *uint_ptr = snmpoutbadvalues;
  3752. break;
  3753. case 24: /* snmpOutGenErrs */
  3754. *uint_ptr = snmpoutgenerrs;
  3755. break;
  3756. case 25: /* snmpOutGetRequests */
  3757. *uint_ptr = snmpoutgetrequests;
  3758. break;
  3759. case 26: /* snmpOutGetNexts */
  3760. *uint_ptr = snmpoutgetnexts;
  3761. break;
  3762. case 27: /* snmpOutSetRequests */
  3763. *uint_ptr = snmpoutsetrequests;
  3764. break;
  3765. case 28: /* snmpOutGetResponses */
  3766. *uint_ptr = snmpoutgetresponses;
  3767. break;
  3768. case 29: /* snmpOutTraps */
  3769. *uint_ptr = snmpouttraps;
  3770. break;
  3771. case 30: /* snmpEnableAuthenTraps */
  3772. *uint_ptr = *snmpenableauthentraps_ptr;
  3773. break;
  3774. };
  3775. }
  3776. /**
  3777. * Test snmp object value before setting.
  3778. *
  3779. * @param od is the object definition
  3780. * @param len return value space (in bytes)
  3781. * @param value points to (varbind) space to copy value from.
  3782. */
  3783. static u8_t
  3784. snmp_set_test(struct obj_def *od, u16_t len, void *value)
  3785. {
  3786. u8_t id, set_ok;
  3787. LWIP_UNUSED_ARG(len);
  3788. set_ok = 0;
  3789. id = od->id_inst_ptr[0];
  3790. if (id == 30)
  3791. {
  3792. /* snmpEnableAuthenTraps */
  3793. s32_t *sint_ptr = value;
  3794. if (snmpenableauthentraps_ptr != &snmpenableauthentraps_default)
  3795. {
  3796. /* we should have writable non-volatile mem here */
  3797. if ((*sint_ptr == 1) || (*sint_ptr == 2))
  3798. {
  3799. set_ok = 1;
  3800. }
  3801. }
  3802. else
  3803. {
  3804. /* const or hardwired value */
  3805. if (*sint_ptr == snmpenableauthentraps_default)
  3806. {
  3807. set_ok = 1;
  3808. }
  3809. }
  3810. }
  3811. return set_ok;
  3812. }
  3813. static void
  3814. snmp_set_value(struct obj_def *od, u16_t len, void *value)
  3815. {
  3816. u8_t id;
  3817. LWIP_UNUSED_ARG(len);
  3818. id = od->id_inst_ptr[0];
  3819. if (id == 30)
  3820. {
  3821. /* snmpEnableAuthenTraps */
  3822. s32_t *sint_ptr = value;
  3823. *snmpenableauthentraps_ptr = *sint_ptr;
  3824. }
  3825. }
  3826. #endif /* LWIP_SNMP */