ospf_snmp.c 68 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637
  1. /* OSPFv2 SNMP support
  2. * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com>
  3. * Copyright (C) 2000 IP Infusion Inc.
  4. *
  5. * Written by Kunihiro Ishiguro <kunihiro@zebra.org>
  6. *
  7. * This file is part of GNU Zebra.
  8. *
  9. * GNU Zebra is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2, or (at your option) any
  12. * later version.
  13. *
  14. * GNU Zebra is distributed in the hope that it will be useful, but
  15. * WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with GNU Zebra; see the file COPYING. If not, write to the Free
  21. * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
  22. * 02111-1307, USA.
  23. */
  24. #include <zebra.h>
  25. #ifdef HAVE_SNMP
  26. #ifdef HAVE_NETSNMP
  27. #include <net-snmp/net-snmp-config.h>
  28. #endif
  29. #include <asn1.h>
  30. #include <snmp.h>
  31. #include <snmp_impl.h>
  32. #include "if.h"
  33. #include "log.h"
  34. #include "prefix.h"
  35. #include "table.h"
  36. #include "command.h"
  37. #include "memory.h"
  38. #include "smux.h"
  39. #include "ospfd/ospfd.h"
  40. #include "ospfd/ospf_interface.h"
  41. #include "ospfd/ospf_asbr.h"
  42. #include "ospfd/ospf_lsa.h"
  43. #include "ospfd/ospf_lsdb.h"
  44. #include "ospfd/ospf_abr.h"
  45. #include "ospfd/ospf_neighbor.h"
  46. #include "ospfd/ospf_nsm.h"
  47. #include "ospfd/ospf_flood.h"
  48. #include "ospfd/ospf_ism.h"
  49. #include "ospfd/ospf_dump.h"
  50. /* OSPF2-MIB. */
  51. #define OSPF2MIB 1,3,6,1,2,1,14
  52. /* OSPF MIB General Group values. */
  53. #define OSPFROUTERID 1
  54. #define OSPFADMINSTAT 2
  55. #define OSPFVERSIONNUMBER 3
  56. #define OSPFAREABDRRTRSTATUS 4
  57. #define OSPFASBDRRTRSTATUS 5
  58. #define OSPFEXTERNLSACOUNT 6
  59. #define OSPFEXTERNLSACKSUMSUM 7
  60. #define OSPFTOSSUPPORT 8
  61. #define OSPFORIGINATENEWLSAS 9
  62. #define OSPFRXNEWLSAS 10
  63. #define OSPFEXTLSDBLIMIT 11
  64. #define OSPFMULTICASTEXTENSIONS 12
  65. #define OSPFEXITOVERFLOWINTERVAL 13
  66. #define OSPFDEMANDEXTENSIONS 14
  67. /* OSPF MIB ospfAreaTable. */
  68. #define OSPFAREAID 1
  69. #define OSPFAUTHTYPE 2
  70. #define OSPFIMPORTASEXTERN 3
  71. #define OSPFSPFRUNS 4
  72. #define OSPFAREABDRRTRCOUNT 5
  73. #define OSPFASBDRRTRCOUNT 6
  74. #define OSPFAREALSACOUNT 7
  75. #define OSPFAREALSACKSUMSUM 8
  76. #define OSPFAREASUMMARY 9
  77. #define OSPFAREASTATUS 10
  78. /* OSPF MIB ospfStubAreaTable. */
  79. #define OSPFSTUBAREAID 1
  80. #define OSPFSTUBTOS 2
  81. #define OSPFSTUBMETRIC 3
  82. #define OSPFSTUBSTATUS 4
  83. #define OSPFSTUBMETRICTYPE 5
  84. /* OSPF MIB ospfLsdbTable. */
  85. #define OSPFLSDBAREAID 1
  86. #define OSPFLSDBTYPE 2
  87. #define OSPFLSDBLSID 3
  88. #define OSPFLSDBROUTERID 4
  89. #define OSPFLSDBSEQUENCE 5
  90. #define OSPFLSDBAGE 6
  91. #define OSPFLSDBCHECKSUM 7
  92. #define OSPFLSDBADVERTISEMENT 8
  93. /* OSPF MIB ospfAreaRangeTable. */
  94. #define OSPFAREARANGEAREAID 1
  95. #define OSPFAREARANGENET 2
  96. #define OSPFAREARANGEMASK 3
  97. #define OSPFAREARANGESTATUS 4
  98. #define OSPFAREARANGEEFFECT 5
  99. /* OSPF MIB ospfHostTable. */
  100. #define OSPFHOSTIPADDRESS 1
  101. #define OSPFHOSTTOS 2
  102. #define OSPFHOSTMETRIC 3
  103. #define OSPFHOSTSTATUS 4
  104. #define OSPFHOSTAREAID 5
  105. /* OSPF MIB ospfIfTable. */
  106. #define OSPFIFIPADDRESS 1
  107. #define OSPFADDRESSLESSIF 2
  108. #define OSPFIFAREAID 3
  109. #define OSPFIFTYPE 4
  110. #define OSPFIFADMINSTAT 5
  111. #define OSPFIFRTRPRIORITY 6
  112. #define OSPFIFTRANSITDELAY 7
  113. #define OSPFIFRETRANSINTERVAL 8
  114. #define OSPFIFHELLOINTERVAL 9
  115. #define OSPFIFRTRDEADINTERVAL 10
  116. #define OSPFIFPOLLINTERVAL 11
  117. #define OSPFIFSTATE 12
  118. #define OSPFIFDESIGNATEDROUTER 13
  119. #define OSPFIFBACKUPDESIGNATEDROUTER 14
  120. #define OSPFIFEVENTS 15
  121. #define OSPFIFAUTHKEY 16
  122. #define OSPFIFSTATUS 17
  123. #define OSPFIFMULTICASTFORWARDING 18
  124. #define OSPFIFDEMAND 19
  125. #define OSPFIFAUTHTYPE 20
  126. /* OSPF MIB ospfIfMetricTable. */
  127. #define OSPFIFMETRICIPADDRESS 1
  128. #define OSPFIFMETRICADDRESSLESSIF 2
  129. #define OSPFIFMETRICTOS 3
  130. #define OSPFIFMETRICVALUE 4
  131. #define OSPFIFMETRICSTATUS 5
  132. /* OSPF MIB ospfVirtIfTable. */
  133. #define OSPFVIRTIFAREAID 1
  134. #define OSPFVIRTIFNEIGHBOR 2
  135. #define OSPFVIRTIFTRANSITDELAY 3
  136. #define OSPFVIRTIFRETRANSINTERVAL 4
  137. #define OSPFVIRTIFHELLOINTERVAL 5
  138. #define OSPFVIRTIFRTRDEADINTERVAL 6
  139. #define OSPFVIRTIFSTATE 7
  140. #define OSPFVIRTIFEVENTS 8
  141. #define OSPFVIRTIFAUTHKEY 9
  142. #define OSPFVIRTIFSTATUS 10
  143. #define OSPFVIRTIFAUTHTYPE 11
  144. /* OSPF MIB ospfNbrTable. */
  145. #define OSPFNBRIPADDR 1
  146. #define OSPFNBRADDRESSLESSINDEX 2
  147. #define OSPFNBRRTRID 3
  148. #define OSPFNBROPTIONS 4
  149. #define OSPFNBRPRIORITY 5
  150. #define OSPFNBRSTATE 6
  151. #define OSPFNBREVENTS 7
  152. #define OSPFNBRLSRETRANSQLEN 8
  153. #define OSPFNBMANBRSTATUS 9
  154. #define OSPFNBMANBRPERMANENCE 10
  155. #define OSPFNBRHELLOSUPPRESSED 11
  156. /* OSPF MIB ospfVirtNbrTable. */
  157. #define OSPFVIRTNBRAREA 1
  158. #define OSPFVIRTNBRRTRID 2
  159. #define OSPFVIRTNBRIPADDR 3
  160. #define OSPFVIRTNBROPTIONS 4
  161. #define OSPFVIRTNBRSTATE 5
  162. #define OSPFVIRTNBREVENTS 6
  163. #define OSPFVIRTNBRLSRETRANSQLEN 7
  164. #define OSPFVIRTNBRHELLOSUPPRESSED 8
  165. /* OSPF MIB ospfExtLsdbTable. */
  166. #define OSPFEXTLSDBTYPE 1
  167. #define OSPFEXTLSDBLSID 2
  168. #define OSPFEXTLSDBROUTERID 3
  169. #define OSPFEXTLSDBSEQUENCE 4
  170. #define OSPFEXTLSDBAGE 5
  171. #define OSPFEXTLSDBCHECKSUM 6
  172. #define OSPFEXTLSDBADVERTISEMENT 7
  173. /* OSPF MIB ospfAreaAggregateTable. */
  174. #define OSPFAREAAGGREGATEAREAID 1
  175. #define OSPFAREAAGGREGATELSDBTYPE 2
  176. #define OSPFAREAAGGREGATENET 3
  177. #define OSPFAREAAGGREGATEMASK 4
  178. #define OSPFAREAAGGREGATESTATUS 5
  179. #define OSPFAREAAGGREGATEEFFECT 6
  180. /* SYNTAX Status from OSPF-MIB. */
  181. #define OSPF_STATUS_ENABLED 1
  182. #define OSPF_STATUS_DISABLED 2
  183. /* SNMP value hack. */
  184. #define COUNTER ASN_COUNTER
  185. #define INTEGER ASN_INTEGER
  186. #define GAUGE ASN_GAUGE
  187. #define TIMETICKS ASN_TIMETICKS
  188. #define IPADDRESS ASN_IPADDRESS
  189. #define STRING ASN_OCTET_STR
  190. /* Declare static local variables for convenience. */
  191. SNMP_LOCAL_VARIABLES
  192. /* OSPF-MIB instances. */
  193. oid ospf_oid [] = { OSPF2MIB };
  194. /* IP address 0.0.0.0. */
  195. static struct in_addr ospf_empty_addr = {0};
  196. /* Hook functions. */
  197. static u_char *ospfGeneralGroup ();
  198. static u_char *ospfAreaEntry ();
  199. static u_char *ospfStubAreaEntry ();
  200. static u_char *ospfLsdbEntry ();
  201. static u_char *ospfAreaRangeEntry ();
  202. static u_char *ospfHostEntry ();
  203. static u_char *ospfIfEntry ();
  204. static u_char *ospfIfMetricEntry ();
  205. static u_char *ospfVirtIfEntry ();
  206. static u_char *ospfNbrEntry ();
  207. static u_char *ospfVirtNbrEntry ();
  208. static u_char *ospfExtLsdbEntry ();
  209. static u_char *ospfAreaAggregateEntry ();
  210. struct variable ospf_variables[] =
  211. {
  212. /* OSPF general variables */
  213. {OSPFROUTERID, IPADDRESS, RWRITE, ospfGeneralGroup,
  214. 2, {1, 1}},
  215. {OSPFADMINSTAT, INTEGER, RWRITE, ospfGeneralGroup,
  216. 2, {1, 2}},
  217. {OSPFVERSIONNUMBER, INTEGER, RONLY, ospfGeneralGroup,
  218. 2, {1, 3}},
  219. {OSPFAREABDRRTRSTATUS, INTEGER, RONLY, ospfGeneralGroup,
  220. 2, {1, 4}},
  221. {OSPFASBDRRTRSTATUS, INTEGER, RWRITE, ospfGeneralGroup,
  222. 2, {1, 5}},
  223. {OSPFEXTERNLSACOUNT, GAUGE, RONLY, ospfGeneralGroup,
  224. 2, {1, 6}},
  225. {OSPFEXTERNLSACKSUMSUM, INTEGER, RONLY, ospfGeneralGroup,
  226. 2, {1, 7}},
  227. {OSPFTOSSUPPORT, INTEGER, RWRITE, ospfGeneralGroup,
  228. 2, {1, 8}},
  229. {OSPFORIGINATENEWLSAS, COUNTER, RONLY, ospfGeneralGroup,
  230. 2, {1, 9}},
  231. {OSPFRXNEWLSAS, COUNTER, RONLY, ospfGeneralGroup,
  232. 2, {1, 10}},
  233. {OSPFEXTLSDBLIMIT, INTEGER, RWRITE, ospfGeneralGroup,
  234. 2, {1, 11}},
  235. {OSPFMULTICASTEXTENSIONS, INTEGER, RWRITE, ospfGeneralGroup,
  236. 2, {1, 12}},
  237. {OSPFEXITOVERFLOWINTERVAL, INTEGER, RWRITE, ospfGeneralGroup,
  238. 2, {1, 13}},
  239. {OSPFDEMANDEXTENSIONS, INTEGER, RWRITE, ospfGeneralGroup,
  240. 2, {1, 14}},
  241. /* OSPF area data structure. */
  242. {OSPFAREAID, IPADDRESS, RONLY, ospfAreaEntry,
  243. 3, {2, 1, 1}},
  244. {OSPFAUTHTYPE, INTEGER, RWRITE, ospfAreaEntry,
  245. 3, {2, 1, 2}},
  246. {OSPFIMPORTASEXTERN, INTEGER, RWRITE, ospfAreaEntry,
  247. 3, {2, 1, 3}},
  248. {OSPFSPFRUNS, COUNTER, RONLY, ospfAreaEntry,
  249. 3, {2, 1, 4}},
  250. {OSPFAREABDRRTRCOUNT, GAUGE, RONLY, ospfAreaEntry,
  251. 3, {2, 1, 5}},
  252. {OSPFASBDRRTRCOUNT, GAUGE, RONLY, ospfAreaEntry,
  253. 3, {2, 1, 6}},
  254. {OSPFAREALSACOUNT, GAUGE, RONLY, ospfAreaEntry,
  255. 3, {2, 1, 7}},
  256. {OSPFAREALSACKSUMSUM, INTEGER, RONLY, ospfAreaEntry,
  257. 3, {2, 1, 8}},
  258. {OSPFAREASUMMARY, INTEGER, RWRITE, ospfAreaEntry,
  259. 3, {2, 1, 9}},
  260. {OSPFAREASTATUS, INTEGER, RWRITE, ospfAreaEntry,
  261. 3, {2, 1, 10}},
  262. /* OSPF stub area information. */
  263. {OSPFSTUBAREAID, IPADDRESS, RONLY, ospfStubAreaEntry,
  264. 3, {3, 1, 1}},
  265. {OSPFSTUBTOS, INTEGER, RONLY, ospfStubAreaEntry,
  266. 3, {3, 1, 2}},
  267. {OSPFSTUBMETRIC, INTEGER, RWRITE, ospfStubAreaEntry,
  268. 3, {3, 1, 3}},
  269. {OSPFSTUBSTATUS, INTEGER, RWRITE, ospfStubAreaEntry,
  270. 3, {3, 1, 4}},
  271. {OSPFSTUBMETRICTYPE, INTEGER, RWRITE, ospfStubAreaEntry,
  272. 3, {3, 1, 5}},
  273. /* OSPF link state database. */
  274. {OSPFLSDBAREAID, IPADDRESS, RONLY, ospfLsdbEntry,
  275. 3, {4, 1, 1}},
  276. {OSPFLSDBTYPE, INTEGER, RONLY, ospfLsdbEntry,
  277. 3, {4, 1, 2}},
  278. {OSPFLSDBLSID, IPADDRESS, RONLY, ospfLsdbEntry,
  279. 3, {4, 1, 3}},
  280. {OSPFLSDBROUTERID, IPADDRESS, RONLY, ospfLsdbEntry,
  281. 3, {4, 1, 4}},
  282. {OSPFLSDBSEQUENCE, INTEGER, RONLY, ospfLsdbEntry,
  283. 3, {4, 1, 5}},
  284. {OSPFLSDBAGE, INTEGER, RONLY, ospfLsdbEntry,
  285. 3, {4, 1, 6}},
  286. {OSPFLSDBCHECKSUM, INTEGER, RONLY, ospfLsdbEntry,
  287. 3, {4, 1, 7}},
  288. {OSPFLSDBADVERTISEMENT, STRING, RONLY, ospfLsdbEntry,
  289. 3, {4, 1, 8}},
  290. /* Area range table. */
  291. {OSPFAREARANGEAREAID, IPADDRESS, RONLY, ospfAreaRangeEntry,
  292. 3, {5, 1, 1}},
  293. {OSPFAREARANGENET, IPADDRESS, RONLY, ospfAreaRangeEntry,
  294. 3, {5, 1, 2}},
  295. {OSPFAREARANGEMASK, IPADDRESS, RWRITE, ospfAreaRangeEntry,
  296. 3, {5, 1, 3}},
  297. {OSPFAREARANGESTATUS, INTEGER, RWRITE, ospfAreaRangeEntry,
  298. 3, {5, 1, 4}},
  299. {OSPFAREARANGEEFFECT, INTEGER, RWRITE, ospfAreaRangeEntry,
  300. 3, {5, 1, 5}},
  301. /* OSPF host table. */
  302. {OSPFHOSTIPADDRESS, IPADDRESS, RONLY, ospfHostEntry,
  303. 3, {6, 1, 1}},
  304. {OSPFHOSTTOS, INTEGER, RONLY, ospfHostEntry,
  305. 3, {6, 1, 2}},
  306. {OSPFHOSTMETRIC, INTEGER, RWRITE, ospfHostEntry,
  307. 3, {6, 1, 3}},
  308. {OSPFHOSTSTATUS, INTEGER, RWRITE, ospfHostEntry,
  309. 3, {6, 1, 4}},
  310. {OSPFHOSTAREAID, IPADDRESS, RONLY, ospfHostEntry,
  311. 3, {6, 1, 5}},
  312. /* OSPF interface table. */
  313. {OSPFIFIPADDRESS, IPADDRESS, RONLY, ospfIfEntry,
  314. 3, {7, 1, 1}},
  315. {OSPFADDRESSLESSIF, INTEGER, RONLY, ospfIfEntry,
  316. 3, {7, 1, 2}},
  317. {OSPFIFAREAID, IPADDRESS, RWRITE, ospfIfEntry,
  318. 3, {7, 1, 3}},
  319. {OSPFIFTYPE, INTEGER, RWRITE, ospfIfEntry,
  320. 3, {7, 1, 4}},
  321. {OSPFIFADMINSTAT, INTEGER, RWRITE, ospfIfEntry,
  322. 3, {7, 1, 5}},
  323. {OSPFIFRTRPRIORITY, INTEGER, RWRITE, ospfIfEntry,
  324. 3, {7, 1, 6}},
  325. {OSPFIFTRANSITDELAY, INTEGER, RWRITE, ospfIfEntry,
  326. 3, {7, 1, 7}},
  327. {OSPFIFRETRANSINTERVAL, INTEGER, RWRITE, ospfIfEntry,
  328. 3, {7, 1, 8}},
  329. {OSPFIFHELLOINTERVAL, INTEGER, RWRITE, ospfIfEntry,
  330. 3, {7, 1, 9}},
  331. {OSPFIFRTRDEADINTERVAL, INTEGER, RWRITE, ospfIfEntry,
  332. 3, {7, 1, 10}},
  333. {OSPFIFPOLLINTERVAL, INTEGER, RWRITE, ospfIfEntry,
  334. 3, {7, 1, 11}},
  335. {OSPFIFSTATE, INTEGER, RONLY, ospfIfEntry,
  336. 3, {7, 1, 12}},
  337. {OSPFIFDESIGNATEDROUTER, IPADDRESS, RONLY, ospfIfEntry,
  338. 3, {7, 1, 13}},
  339. {OSPFIFBACKUPDESIGNATEDROUTER, IPADDRESS, RONLY, ospfIfEntry,
  340. 3, {7, 1, 14}},
  341. {OSPFIFEVENTS, COUNTER, RONLY, ospfIfEntry,
  342. 3, {7, 1, 15}},
  343. {OSPFIFAUTHKEY, STRING, RWRITE, ospfIfEntry,
  344. 3, {7, 1, 16}},
  345. {OSPFIFSTATUS, INTEGER, RWRITE, ospfIfEntry,
  346. 3, {7, 1, 17}},
  347. {OSPFIFMULTICASTFORWARDING, INTEGER, RWRITE, ospfIfEntry,
  348. 3, {7, 1, 18}},
  349. {OSPFIFDEMAND, INTEGER, RWRITE, ospfIfEntry,
  350. 3, {7, 1, 19}},
  351. {OSPFIFAUTHTYPE, INTEGER, RWRITE, ospfIfEntry,
  352. 3, {7, 1, 20}},
  353. /* OSPF interface metric table. */
  354. {OSPFIFMETRICIPADDRESS, IPADDRESS, RONLY, ospfIfMetricEntry,
  355. 3, {8, 1, 1}},
  356. {OSPFIFMETRICADDRESSLESSIF, INTEGER, RONLY, ospfIfMetricEntry,
  357. 3, {8, 1, 2}},
  358. {OSPFIFMETRICTOS, INTEGER, RONLY, ospfIfMetricEntry,
  359. 3, {8, 1, 3}},
  360. {OSPFIFMETRICVALUE, INTEGER, RWRITE, ospfIfMetricEntry,
  361. 3, {8, 1, 4}},
  362. {OSPFIFMETRICSTATUS, INTEGER, RWRITE, ospfIfMetricEntry,
  363. 3, {8, 1, 5}},
  364. /* OSPF virtual interface table. */
  365. {OSPFVIRTIFAREAID, IPADDRESS, RONLY, ospfVirtIfEntry,
  366. 3, {9, 1, 1}},
  367. {OSPFVIRTIFNEIGHBOR, IPADDRESS, RONLY, ospfVirtIfEntry,
  368. 3, {9, 1, 2}},
  369. {OSPFVIRTIFTRANSITDELAY, INTEGER, RWRITE, ospfVirtIfEntry,
  370. 3, {9, 1, 3}},
  371. {OSPFVIRTIFRETRANSINTERVAL, INTEGER, RWRITE, ospfVirtIfEntry,
  372. 3, {9, 1, 4}},
  373. {OSPFVIRTIFHELLOINTERVAL, INTEGER, RWRITE, ospfVirtIfEntry,
  374. 3, {9, 1, 5}},
  375. {OSPFVIRTIFRTRDEADINTERVAL, INTEGER, RWRITE, ospfVirtIfEntry,
  376. 3, {9, 1, 6}},
  377. {OSPFVIRTIFSTATE, INTEGER, RONLY, ospfVirtIfEntry,
  378. 3, {9, 1, 7}},
  379. {OSPFVIRTIFEVENTS, COUNTER, RONLY, ospfVirtIfEntry,
  380. 3, {9, 1, 8}},
  381. {OSPFVIRTIFAUTHKEY, STRING, RWRITE, ospfVirtIfEntry,
  382. 3, {9, 1, 9}},
  383. {OSPFVIRTIFSTATUS, INTEGER, RWRITE, ospfVirtIfEntry,
  384. 3, {9, 1, 10}},
  385. {OSPFVIRTIFAUTHTYPE, INTEGER, RWRITE, ospfVirtIfEntry,
  386. 3, {9, 1, 11}},
  387. /* OSPF neighbor table. */
  388. {OSPFNBRIPADDR, IPADDRESS, RONLY, ospfNbrEntry,
  389. 3, {10, 1, 1}},
  390. {OSPFNBRADDRESSLESSINDEX, INTEGER, RONLY, ospfNbrEntry,
  391. 3, {10, 1, 2}},
  392. {OSPFNBRRTRID, IPADDRESS, RONLY, ospfNbrEntry,
  393. 3, {10, 1, 3}},
  394. {OSPFNBROPTIONS, INTEGER, RONLY, ospfNbrEntry,
  395. 3, {10, 1, 4}},
  396. {OSPFNBRPRIORITY, INTEGER, RWRITE, ospfNbrEntry,
  397. 3, {10, 1, 5}},
  398. {OSPFNBRSTATE, INTEGER, RONLY, ospfNbrEntry,
  399. 3, {10, 1, 6}},
  400. {OSPFNBREVENTS, COUNTER, RONLY, ospfNbrEntry,
  401. 3, {10, 1, 7}},
  402. {OSPFNBRLSRETRANSQLEN, GAUGE, RONLY, ospfNbrEntry,
  403. 3, {10, 1, 8}},
  404. {OSPFNBMANBRSTATUS, INTEGER, RWRITE, ospfNbrEntry,
  405. 3, {10, 1, 9}},
  406. {OSPFNBMANBRPERMANENCE, INTEGER, RONLY, ospfNbrEntry,
  407. 3, {10, 1, 10}},
  408. {OSPFNBRHELLOSUPPRESSED, INTEGER, RONLY, ospfNbrEntry,
  409. 3, {10, 1, 11}},
  410. /* OSPF virtual neighbor table. */
  411. {OSPFVIRTNBRAREA, IPADDRESS, RONLY, ospfVirtNbrEntry,
  412. 3, {11, 1, 1}},
  413. {OSPFVIRTNBRRTRID, IPADDRESS, RONLY, ospfVirtNbrEntry,
  414. 3, {11, 1, 2}},
  415. {OSPFVIRTNBRIPADDR, IPADDRESS, RONLY, ospfVirtNbrEntry,
  416. 3, {11, 1, 3}},
  417. {OSPFVIRTNBROPTIONS, INTEGER, RONLY, ospfVirtNbrEntry,
  418. 3, {11, 1, 4}},
  419. {OSPFVIRTNBRSTATE, INTEGER, RONLY, ospfVirtNbrEntry,
  420. 3, {11, 1, 5}},
  421. {OSPFVIRTNBREVENTS, COUNTER, RONLY, ospfVirtNbrEntry,
  422. 3, {11, 1, 6}},
  423. {OSPFVIRTNBRLSRETRANSQLEN, INTEGER, RONLY, ospfVirtNbrEntry,
  424. 3, {11, 1, 7}},
  425. {OSPFVIRTNBRHELLOSUPPRESSED, INTEGER, RONLY, ospfVirtNbrEntry,
  426. 3, {11, 1, 8}},
  427. /* OSPF link state database, external. */
  428. {OSPFEXTLSDBTYPE, INTEGER, RONLY, ospfExtLsdbEntry,
  429. 3, {12, 1, 1}},
  430. {OSPFEXTLSDBLSID, IPADDRESS, RONLY, ospfExtLsdbEntry,
  431. 3, {12, 1, 2}},
  432. {OSPFEXTLSDBROUTERID, IPADDRESS, RONLY, ospfExtLsdbEntry,
  433. 3, {12, 1, 3}},
  434. {OSPFEXTLSDBSEQUENCE, INTEGER, RONLY, ospfExtLsdbEntry,
  435. 3, {12, 1, 4}},
  436. {OSPFEXTLSDBAGE, INTEGER, RONLY, ospfExtLsdbEntry,
  437. 3, {12, 1, 5}},
  438. {OSPFEXTLSDBCHECKSUM, INTEGER, RONLY, ospfExtLsdbEntry,
  439. 3, {12, 1, 6}},
  440. {OSPFEXTLSDBADVERTISEMENT, STRING, RONLY, ospfExtLsdbEntry,
  441. 3, {12, 1, 7}},
  442. /* OSPF area aggregate table. */
  443. {OSPFAREAAGGREGATEAREAID, IPADDRESS, RONLY, ospfAreaAggregateEntry,
  444. 3, {14, 1, 1}},
  445. {OSPFAREAAGGREGATELSDBTYPE, INTEGER, RONLY, ospfAreaAggregateEntry,
  446. 3, {14, 1, 2}},
  447. {OSPFAREAAGGREGATENET, IPADDRESS, RONLY, ospfAreaAggregateEntry,
  448. 3, {14, 1, 3}},
  449. {OSPFAREAAGGREGATEMASK, IPADDRESS, RONLY, ospfAreaAggregateEntry,
  450. 3, {14, 1, 4}},
  451. {OSPFAREAAGGREGATESTATUS, INTEGER, RWRITE, ospfAreaAggregateEntry,
  452. 3, {14, 1, 5}},
  453. {OSPFAREAAGGREGATEEFFECT, INTEGER, RWRITE, ospfAreaAggregateEntry,
  454. 3, {14, 1, 6}}
  455. };
  456. /* The administrative status of OSPF. When OSPF is enbled on at least
  457. one interface return 1. */
  458. int
  459. ospf_admin_stat (struct ospf *ospf)
  460. {
  461. struct listnode *node;
  462. struct ospf_interface *oi;
  463. if (ospf == NULL)
  464. return 0;
  465. for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, node, oi))
  466. if (oi && oi->address)
  467. return 1;
  468. return 0;
  469. }
  470. static u_char *
  471. ospfGeneralGroup (struct variable *v, oid *name, size_t *length,
  472. int exact, size_t *var_len, WriteMethod **write_method)
  473. {
  474. struct ospf *ospf;
  475. ospf = ospf_lookup ();
  476. /* Check whether the instance identifier is valid */
  477. if (smux_header_generic (v, name, length, exact, var_len, write_method)
  478. == MATCH_FAILED)
  479. return NULL;
  480. /* Return the current value of the variable */
  481. switch (v->magic)
  482. {
  483. case OSPFROUTERID: /* 1 */
  484. /* Router-ID of this OSPF instance. */
  485. if (ospf)
  486. return SNMP_IPADDRESS (ospf->router_id);
  487. else
  488. return SNMP_IPADDRESS (ospf_empty_addr);
  489. break;
  490. case OSPFADMINSTAT: /* 2 */
  491. /* The administrative status of OSPF in the router. */
  492. if (ospf_admin_stat (ospf))
  493. return SNMP_INTEGER (OSPF_STATUS_ENABLED);
  494. else
  495. return SNMP_INTEGER (OSPF_STATUS_DISABLED);
  496. break;
  497. case OSPFVERSIONNUMBER: /* 3 */
  498. /* OSPF version 2. */
  499. return SNMP_INTEGER (OSPF_VERSION);
  500. break;
  501. case OSPFAREABDRRTRSTATUS: /* 4 */
  502. /* Area Border router status. */
  503. if (ospf && CHECK_FLAG (ospf->flags, OSPF_FLAG_ABR))
  504. return SNMP_INTEGER (SNMP_TRUE);
  505. else
  506. return SNMP_INTEGER (SNMP_FALSE);
  507. break;
  508. case OSPFASBDRRTRSTATUS: /* 5 */
  509. /* AS Border router status. */
  510. if (ospf && CHECK_FLAG (ospf->flags, OSPF_FLAG_ASBR))
  511. return SNMP_INTEGER (SNMP_TRUE);
  512. else
  513. return SNMP_INTEGER (SNMP_FALSE);
  514. break;
  515. case OSPFEXTERNLSACOUNT: /* 6 */
  516. /* External LSA counts. */
  517. if (ospf)
  518. return SNMP_INTEGER (ospf_lsdb_count_all (ospf->lsdb));
  519. else
  520. return SNMP_INTEGER (0);
  521. break;
  522. case OSPFEXTERNLSACKSUMSUM: /* 7 */
  523. /* External LSA checksum. */
  524. return SNMP_INTEGER (0);
  525. break;
  526. case OSPFTOSSUPPORT: /* 8 */
  527. /* TOS is not supported. */
  528. return SNMP_INTEGER (SNMP_FALSE);
  529. break;
  530. case OSPFORIGINATENEWLSAS: /* 9 */
  531. /* The number of new link-state advertisements. */
  532. if (ospf)
  533. return SNMP_INTEGER (ospf->lsa_originate_count);
  534. else
  535. return SNMP_INTEGER (0);
  536. break;
  537. case OSPFRXNEWLSAS: /* 10 */
  538. /* The number of link-state advertisements received determined
  539. to be new instantiations. */
  540. if (ospf)
  541. return SNMP_INTEGER (ospf->rx_lsa_count);
  542. else
  543. return SNMP_INTEGER (0);
  544. break;
  545. case OSPFEXTLSDBLIMIT: /* 11 */
  546. /* There is no limit for the number of non-default
  547. AS-external-LSAs. */
  548. return SNMP_INTEGER (-1);
  549. break;
  550. case OSPFMULTICASTEXTENSIONS: /* 12 */
  551. /* Multicast Extensions to OSPF is not supported. */
  552. return SNMP_INTEGER (0);
  553. break;
  554. case OSPFEXITOVERFLOWINTERVAL: /* 13 */
  555. /* Overflow is not supported. */
  556. return SNMP_INTEGER (0);
  557. break;
  558. case OSPFDEMANDEXTENSIONS: /* 14 */
  559. /* Demand routing is not supported. */
  560. return SNMP_INTEGER (SNMP_FALSE);
  561. break;
  562. default:
  563. return NULL;
  564. }
  565. return NULL;
  566. }
  567. struct ospf_area *
  568. ospf_area_lookup_next (struct ospf *ospf, struct in_addr *area_id, int first)
  569. {
  570. struct ospf_area *area;
  571. struct listnode *node;
  572. if (ospf == NULL)
  573. return NULL;
  574. if (first)
  575. {
  576. node = listhead (ospf->areas);
  577. if (node)
  578. {
  579. area = listgetdata (node);
  580. *area_id = area->area_id;
  581. return area;
  582. }
  583. return NULL;
  584. }
  585. for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
  586. {
  587. if (ntohl (area->area_id.s_addr) > ntohl (area_id->s_addr))
  588. {
  589. *area_id = area->area_id;
  590. return area;
  591. }
  592. }
  593. return NULL;
  594. }
  595. struct ospf_area *
  596. ospfAreaLookup (struct variable *v, oid name[], size_t *length,
  597. struct in_addr *addr, int exact)
  598. {
  599. struct ospf *ospf;
  600. struct ospf_area *area;
  601. int len;
  602. ospf = ospf_lookup ();
  603. if (ospf == NULL)
  604. return NULL;
  605. if (exact)
  606. {
  607. /* Length is insufficient to lookup OSPF area. */
  608. if (*length - v->namelen != sizeof (struct in_addr))
  609. return NULL;
  610. oid2in_addr (name + v->namelen, sizeof (struct in_addr), addr);
  611. area = ospf_area_lookup_by_area_id (ospf, *addr);
  612. return area;
  613. }
  614. else
  615. {
  616. len = *length - v->namelen;
  617. if (len > 4)
  618. len = 4;
  619. oid2in_addr (name + v->namelen, len, addr);
  620. area = ospf_area_lookup_next (ospf, addr, len == 0 ? 1 : 0);
  621. if (area == NULL)
  622. return NULL;
  623. oid_copy_addr (name + v->namelen, addr, sizeof (struct in_addr));
  624. *length = sizeof (struct in_addr) + v->namelen;
  625. return area;
  626. }
  627. return NULL;
  628. }
  629. static u_char *
  630. ospfAreaEntry (struct variable *v, oid *name, size_t *length, int exact,
  631. size_t *var_len, WriteMethod **write_method)
  632. {
  633. struct ospf_area *area;
  634. struct in_addr addr;
  635. memset (&addr, 0, sizeof (struct in_addr));
  636. area = ospfAreaLookup (v, name, length, &addr, exact);
  637. if (! area)
  638. return NULL;
  639. /* Return the current value of the variable */
  640. switch (v->magic)
  641. {
  642. case OSPFAREAID: /* 1 */
  643. return SNMP_IPADDRESS (area->area_id);
  644. break;
  645. case OSPFAUTHTYPE: /* 2 */
  646. return SNMP_INTEGER (area->auth_type);
  647. break;
  648. case OSPFIMPORTASEXTERN: /* 3 */
  649. return SNMP_INTEGER (area->external_routing + 1);
  650. break;
  651. case OSPFSPFRUNS: /* 4 */
  652. return SNMP_INTEGER (area->spf_calculation);
  653. break;
  654. case OSPFAREABDRRTRCOUNT: /* 5 */
  655. return SNMP_INTEGER (area->abr_count);
  656. break;
  657. case OSPFASBDRRTRCOUNT: /* 6 */
  658. return SNMP_INTEGER (area->asbr_count);
  659. break;
  660. case OSPFAREALSACOUNT: /* 7 */
  661. return SNMP_INTEGER (area->lsdb->total);
  662. break;
  663. case OSPFAREALSACKSUMSUM: /* 8 */
  664. return SNMP_INTEGER (0);
  665. break;
  666. case OSPFAREASUMMARY: /* 9 */
  667. #define OSPF_noAreaSummary 1
  668. #define OSPF_sendAreaSummary 2
  669. if (area->no_summary)
  670. return SNMP_INTEGER (OSPF_noAreaSummary);
  671. else
  672. return SNMP_INTEGER (OSPF_sendAreaSummary);
  673. break;
  674. case OSPFAREASTATUS: /* 10 */
  675. return SNMP_INTEGER (SNMP_VALID);
  676. break;
  677. default:
  678. return NULL;
  679. break;
  680. }
  681. return NULL;
  682. }
  683. struct ospf_area *
  684. ospf_stub_area_lookup_next (struct in_addr *area_id, int first)
  685. {
  686. struct ospf_area *area;
  687. struct listnode *node;
  688. struct ospf *ospf;
  689. ospf = ospf_lookup ();
  690. if (ospf == NULL)
  691. return NULL;
  692. for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area))
  693. {
  694. if (area->external_routing == OSPF_AREA_STUB)
  695. {
  696. if (first)
  697. {
  698. *area_id = area->area_id;
  699. return area;
  700. }
  701. else if (ntohl (area->area_id.s_addr) > ntohl (area_id->s_addr))
  702. {
  703. *area_id = area->area_id;
  704. return area;
  705. }
  706. }
  707. }
  708. return NULL;
  709. }
  710. struct ospf_area *
  711. ospfStubAreaLookup (struct variable *v, oid name[], size_t *length,
  712. struct in_addr *addr, int exact)
  713. {
  714. struct ospf *ospf;
  715. struct ospf_area *area;
  716. int len;
  717. ospf = ospf_lookup ();
  718. if (ospf == NULL)
  719. return NULL;
  720. /* Exact lookup. */
  721. if (exact)
  722. {
  723. /* ospfStubAreaID + ospfStubTOS. */
  724. if (*length != v->namelen + sizeof (struct in_addr) + 1)
  725. return NULL;
  726. /* Check ospfStubTOS is zero. */
  727. if (name[*length - 1] != 0)
  728. return NULL;
  729. oid2in_addr (name + v->namelen, sizeof (struct in_addr), addr);
  730. area = ospf_area_lookup_by_area_id (ospf, *addr);
  731. if (area->external_routing == OSPF_AREA_STUB)
  732. return area;
  733. else
  734. return NULL;
  735. }
  736. else
  737. {
  738. len = *length - v->namelen;
  739. if (len > 4)
  740. len = 4;
  741. oid2in_addr (name + v->namelen, len, addr);
  742. area = ospf_stub_area_lookup_next (addr, len == 0 ? 1 : 0);
  743. if (area == NULL)
  744. return NULL;
  745. oid_copy_addr (name + v->namelen, addr, sizeof (struct in_addr));
  746. /* Set TOS 0. */
  747. name[v->namelen + sizeof (struct in_addr)] = 0;
  748. *length = v->namelen + sizeof (struct in_addr) + 1;
  749. return area;
  750. }
  751. return NULL;
  752. }
  753. static u_char *
  754. ospfStubAreaEntry (struct variable *v, oid *name, size_t *length,
  755. int exact, size_t *var_len, WriteMethod **write_method)
  756. {
  757. struct ospf_area *area;
  758. struct in_addr addr;
  759. memset (&addr, 0, sizeof (struct in_addr));
  760. area = ospfStubAreaLookup (v, name, length, &addr, exact);
  761. if (! area)
  762. return NULL;
  763. /* Return the current value of the variable */
  764. switch (v->magic)
  765. {
  766. case OSPFSTUBAREAID: /* 1 */
  767. /* OSPF stub area id. */
  768. return SNMP_IPADDRESS (area->area_id);
  769. break;
  770. case OSPFSTUBTOS: /* 2 */
  771. /* TOS value is not supported. */
  772. return SNMP_INTEGER (0);
  773. break;
  774. case OSPFSTUBMETRIC: /* 3 */
  775. /* Default cost to stub area. */
  776. return SNMP_INTEGER (area->default_cost);
  777. break;
  778. case OSPFSTUBSTATUS: /* 4 */
  779. /* Status of the stub area. */
  780. return SNMP_INTEGER (SNMP_VALID);
  781. break;
  782. case OSPFSTUBMETRICTYPE: /* 5 */
  783. /* OSPF Metric type. */
  784. #define OSPF_ospfMetric 1
  785. #define OSPF_comparableCost 2
  786. #define OSPF_nonComparable 3
  787. return SNMP_INTEGER (OSPF_ospfMetric);
  788. break;
  789. default:
  790. return NULL;
  791. break;
  792. }
  793. return NULL;
  794. }
  795. struct ospf_lsa *
  796. lsdb_lookup_next (struct ospf_area *area, u_char *type, int type_next,
  797. struct in_addr *ls_id, int ls_id_next,
  798. struct in_addr *router_id, int router_id_next)
  799. {
  800. struct ospf_lsa *lsa;
  801. int i;
  802. if (type_next)
  803. i = OSPF_MIN_LSA;
  804. else
  805. i = *type;
  806. /* Sanity check, if LSA type unknwon
  807. merley skip any LSA */
  808. if ((i < OSPF_MIN_LSA) || (i >= OSPF_MAX_LSA))
  809. {
  810. zlog_debug("Strange request with LSA type %d\n", i);
  811. return NULL;
  812. }
  813. for (; i < OSPF_MAX_LSA; i++)
  814. {
  815. *type = i;
  816. lsa = ospf_lsdb_lookup_by_id_next (area->lsdb, *type, *ls_id, *router_id,
  817. ls_id_next);
  818. if (lsa)
  819. return lsa;
  820. ls_id_next = 1;
  821. }
  822. return NULL;
  823. }
  824. struct ospf_lsa *
  825. ospfLsdbLookup (struct variable *v, oid *name, size_t *length,
  826. struct in_addr *area_id, u_char *type,
  827. struct in_addr *ls_id, struct in_addr *router_id, int exact)
  828. {
  829. struct ospf *ospf;
  830. struct ospf_area *area;
  831. struct ospf_lsa *lsa;
  832. unsigned int len;
  833. int type_next;
  834. int ls_id_next;
  835. int router_id_next;
  836. oid *offset;
  837. int offsetlen;
  838. ospf = ospf_lookup ();
  839. #define OSPF_LSDB_ENTRY_OFFSET \
  840. (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE)
  841. if (exact)
  842. {
  843. /* Area ID + Type + LS ID + Router ID. */
  844. if (*length - v->namelen != OSPF_LSDB_ENTRY_OFFSET)
  845. return NULL;
  846. /* Set OID offset for Area ID. */
  847. offset = name + v->namelen;
  848. /* Lookup area first. */
  849. oid2in_addr (offset, IN_ADDR_SIZE, area_id);
  850. area = ospf_area_lookup_by_area_id (ospf, *area_id);
  851. if (! area)
  852. return NULL;
  853. offset += IN_ADDR_SIZE;
  854. /* Type. */
  855. *type = *offset;
  856. offset++;
  857. /* LS ID. */
  858. oid2in_addr (offset, IN_ADDR_SIZE, ls_id);
  859. offset += IN_ADDR_SIZE;
  860. /* Router ID. */
  861. oid2in_addr (offset, IN_ADDR_SIZE, router_id);
  862. /* Lookup LSDB. */
  863. return ospf_lsdb_lookup_by_id (area->lsdb, *type, *ls_id, *router_id);
  864. }
  865. else
  866. {
  867. /* Get variable length. */
  868. offset = name + v->namelen;
  869. offsetlen = *length - v->namelen;
  870. len = offsetlen;
  871. if (len > IN_ADDR_SIZE)
  872. len = IN_ADDR_SIZE;
  873. oid2in_addr (offset, len, area_id);
  874. /* First we search area. */
  875. if (len == IN_ADDR_SIZE)
  876. area = ospf_area_lookup_by_area_id (ospf, *area_id);
  877. else
  878. area = ospf_area_lookup_next (ospf, area_id, len == 0 ? 1 : 0);
  879. if (area == NULL)
  880. return NULL;
  881. do
  882. {
  883. /* Next we lookup type. */
  884. offset += IN_ADDR_SIZE;
  885. offsetlen -= IN_ADDR_SIZE;
  886. len = offsetlen;
  887. if (len <= 0)
  888. type_next = 1;
  889. else
  890. {
  891. len = 1;
  892. type_next = 0;
  893. *type = *offset;
  894. }
  895. /* LS ID. */
  896. offset++;
  897. offsetlen--;
  898. len = offsetlen;
  899. if (len <= 0)
  900. ls_id_next = 1;
  901. else
  902. {
  903. ls_id_next = 0;
  904. if (len > IN_ADDR_SIZE)
  905. len = IN_ADDR_SIZE;
  906. oid2in_addr (offset, len, ls_id);
  907. }
  908. /* Router ID. */
  909. offset += IN_ADDR_SIZE;
  910. offsetlen -= IN_ADDR_SIZE;
  911. len = offsetlen;
  912. if (len <= 0)
  913. router_id_next = 1;
  914. else
  915. {
  916. router_id_next = 0;
  917. if (len > IN_ADDR_SIZE)
  918. len = IN_ADDR_SIZE;
  919. oid2in_addr (offset, len, router_id);
  920. }
  921. lsa = lsdb_lookup_next (area, type, type_next, ls_id, ls_id_next,
  922. router_id, router_id_next);
  923. if (lsa)
  924. {
  925. /* Fill in length. */
  926. *length = v->namelen + OSPF_LSDB_ENTRY_OFFSET;
  927. /* Fill in value. */
  928. offset = name + v->namelen;
  929. oid_copy_addr (offset, area_id, IN_ADDR_SIZE);
  930. offset += IN_ADDR_SIZE;
  931. *offset = lsa->data->type;
  932. offset++;
  933. oid_copy_addr (offset, &lsa->data->id, IN_ADDR_SIZE);
  934. offset += IN_ADDR_SIZE;
  935. oid_copy_addr (offset, &lsa->data->adv_router, IN_ADDR_SIZE);
  936. return lsa;
  937. }
  938. }
  939. while ((area = ospf_area_lookup_next (ospf, area_id, 0)) != NULL);
  940. }
  941. return NULL;
  942. }
  943. static u_char *
  944. ospfLsdbEntry (struct variable *v, oid *name, size_t *length, int exact,
  945. size_t *var_len, WriteMethod **write_method)
  946. {
  947. struct ospf_lsa *lsa;
  948. struct lsa_header *lsah;
  949. struct in_addr area_id;
  950. u_char type;
  951. struct in_addr ls_id;
  952. struct in_addr router_id;
  953. struct ospf *ospf;
  954. /* INDEX { ospfLsdbAreaId, ospfLsdbType,
  955. ospfLsdbLsid, ospfLsdbRouterId } */
  956. memset (&area_id, 0, sizeof (struct in_addr));
  957. type = 0;
  958. memset (&ls_id, 0, sizeof (struct in_addr));
  959. memset (&router_id, 0, sizeof (struct in_addr));
  960. /* Check OSPF instance. */
  961. ospf = ospf_lookup ();
  962. if (ospf == NULL)
  963. return NULL;
  964. lsa = ospfLsdbLookup (v, name, length, &area_id, &type, &ls_id, &router_id,
  965. exact);
  966. if (! lsa)
  967. return NULL;
  968. lsah = lsa->data;
  969. /* Return the current value of the variable */
  970. switch (v->magic)
  971. {
  972. case OSPFLSDBAREAID: /* 1 */
  973. return SNMP_IPADDRESS (lsa->area->area_id);
  974. break;
  975. case OSPFLSDBTYPE: /* 2 */
  976. return SNMP_INTEGER (lsah->type);
  977. break;
  978. case OSPFLSDBLSID: /* 3 */
  979. return SNMP_IPADDRESS (lsah->id);
  980. break;
  981. case OSPFLSDBROUTERID: /* 4 */
  982. return SNMP_IPADDRESS (lsah->adv_router);
  983. break;
  984. case OSPFLSDBSEQUENCE: /* 5 */
  985. return SNMP_INTEGER (lsah->ls_seqnum);
  986. break;
  987. case OSPFLSDBAGE: /* 6 */
  988. return SNMP_INTEGER (lsah->ls_age);
  989. break;
  990. case OSPFLSDBCHECKSUM: /* 7 */
  991. return SNMP_INTEGER (lsah->checksum);
  992. break;
  993. case OSPFLSDBADVERTISEMENT: /* 8 */
  994. *var_len = ntohs (lsah->length);
  995. return (u_char *) lsah;
  996. break;
  997. default:
  998. return NULL;
  999. break;
  1000. }
  1001. return NULL;
  1002. }
  1003. struct ospf_area_range *
  1004. ospfAreaRangeLookup (struct variable *v, oid *name, size_t *length,
  1005. struct in_addr *area_id, struct in_addr *range_net,
  1006. int exact)
  1007. {
  1008. oid *offset;
  1009. int offsetlen;
  1010. unsigned int len;
  1011. struct ospf *ospf;
  1012. struct ospf_area *area;
  1013. struct ospf_area_range *range;
  1014. struct prefix_ipv4 p;
  1015. p.family = AF_INET;
  1016. p.prefixlen = IPV4_MAX_BITLEN;
  1017. ospf = ospf_lookup ();
  1018. if (exact)
  1019. {
  1020. /* Area ID + Range Network. */
  1021. if (v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE != *length)
  1022. return NULL;
  1023. /* Set OID offset for Area ID. */
  1024. offset = name + v->namelen;
  1025. /* Lookup area first. */
  1026. oid2in_addr (offset, IN_ADDR_SIZE, area_id);
  1027. area = ospf_area_lookup_by_area_id (ospf, *area_id);
  1028. if (! area)
  1029. return NULL;
  1030. offset += IN_ADDR_SIZE;
  1031. /* Lookup area range. */
  1032. oid2in_addr (offset, IN_ADDR_SIZE, range_net);
  1033. p.prefix = *range_net;
  1034. return ospf_area_range_lookup (area, &p);
  1035. }
  1036. else
  1037. {
  1038. /* Set OID offset for Area ID. */
  1039. offset = name + v->namelen;
  1040. offsetlen = *length - v->namelen;
  1041. len = offsetlen;
  1042. if (len > IN_ADDR_SIZE)
  1043. len = IN_ADDR_SIZE;
  1044. oid2in_addr (offset, len, area_id);
  1045. /* First we search area. */
  1046. if (len == IN_ADDR_SIZE)
  1047. area = ospf_area_lookup_by_area_id (ospf,*area_id);
  1048. else
  1049. area = ospf_area_lookup_next (ospf, area_id, len == 0 ? 1 : 0);
  1050. if (area == NULL)
  1051. return NULL;
  1052. do
  1053. {
  1054. offset += IN_ADDR_SIZE;
  1055. offsetlen -= IN_ADDR_SIZE;
  1056. len = offsetlen;
  1057. if (len < 0)
  1058. len = 0;
  1059. if (len > IN_ADDR_SIZE)
  1060. len = IN_ADDR_SIZE;
  1061. oid2in_addr (offset, len, range_net);
  1062. range = ospf_area_range_lookup_next (area, range_net,
  1063. len == 0 ? 1 : 0);
  1064. if (range)
  1065. {
  1066. /* Fill in length. */
  1067. *length = v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE;
  1068. /* Fill in value. */
  1069. offset = name + v->namelen;
  1070. oid_copy_addr (offset, area_id, IN_ADDR_SIZE);
  1071. offset += IN_ADDR_SIZE;
  1072. oid_copy_addr (offset, range_net, IN_ADDR_SIZE);
  1073. return range;
  1074. }
  1075. }
  1076. while ((area = ospf_area_lookup_next (ospf, area_id, 0)) != NULL);
  1077. }
  1078. return NULL;
  1079. }
  1080. static u_char *
  1081. ospfAreaRangeEntry (struct variable *v, oid *name, size_t *length, int exact,
  1082. size_t *var_len, WriteMethod **write_method)
  1083. {
  1084. struct ospf_area_range *range;
  1085. struct in_addr area_id;
  1086. struct in_addr range_net;
  1087. struct in_addr mask;
  1088. struct ospf *ospf;
  1089. /* Check OSPF instance. */
  1090. ospf = ospf_lookup ();
  1091. if (ospf == NULL)
  1092. return NULL;
  1093. memset (&area_id, 0, IN_ADDR_SIZE);
  1094. memset (&range_net, 0, IN_ADDR_SIZE);
  1095. range = ospfAreaRangeLookup (v, name, length, &area_id, &range_net, exact);
  1096. if (! range)
  1097. return NULL;
  1098. /* Convert prefixlen to network mask format. */
  1099. masklen2ip (range->subst_masklen, &mask);
  1100. /* Return the current value of the variable */
  1101. switch (v->magic)
  1102. {
  1103. case OSPFAREARANGEAREAID: /* 1 */
  1104. return SNMP_IPADDRESS (area_id);
  1105. break;
  1106. case OSPFAREARANGENET: /* 2 */
  1107. return SNMP_IPADDRESS (range_net);
  1108. break;
  1109. case OSPFAREARANGEMASK: /* 3 */
  1110. return SNMP_IPADDRESS (mask);
  1111. break;
  1112. case OSPFAREARANGESTATUS: /* 4 */
  1113. return SNMP_INTEGER (SNMP_VALID);
  1114. break;
  1115. case OSPFAREARANGEEFFECT: /* 5 */
  1116. #define OSPF_advertiseMatching 1
  1117. #define OSPF_doNotAdvertiseMatching 2
  1118. return SNMP_INTEGER (OSPF_advertiseMatching);
  1119. break;
  1120. default:
  1121. return NULL;
  1122. break;
  1123. }
  1124. return NULL;
  1125. }
  1126. struct ospf_nbr_nbma *
  1127. ospfHostLookup (struct variable *v, oid *name, size_t *length,
  1128. struct in_addr *addr, int exact)
  1129. {
  1130. int len;
  1131. struct ospf_nbr_nbma *nbr_nbma;
  1132. struct ospf *ospf;
  1133. ospf = ospf_lookup ();
  1134. if (ospf == NULL)
  1135. return NULL;
  1136. if (exact)
  1137. {
  1138. /* INDEX { ospfHostIpAddress, ospfHostTOS } */
  1139. if (*length != v->namelen + IN_ADDR_SIZE + 1)
  1140. return NULL;
  1141. /* Check ospfHostTOS. */
  1142. if (name[*length - 1] != 0)
  1143. return NULL;
  1144. oid2in_addr (name + v->namelen, IN_ADDR_SIZE, addr);
  1145. nbr_nbma = ospf_nbr_nbma_lookup (ospf, *addr);
  1146. return nbr_nbma;
  1147. }
  1148. else
  1149. {
  1150. len = *length - v->namelen;
  1151. if (len > 4)
  1152. len = 4;
  1153. oid2in_addr (name + v->namelen, len, addr);
  1154. nbr_nbma = ospf_nbr_nbma_lookup_next (ospf, addr, len == 0 ? 1 : 0);
  1155. if (nbr_nbma == NULL)
  1156. return NULL;
  1157. oid_copy_addr (name + v->namelen, addr, IN_ADDR_SIZE);
  1158. /* Set TOS 0. */
  1159. name[v->namelen + IN_ADDR_SIZE] = 0;
  1160. *length = v->namelen + IN_ADDR_SIZE + 1;
  1161. return nbr_nbma;
  1162. }
  1163. return NULL;
  1164. }
  1165. static u_char *
  1166. ospfHostEntry (struct variable *v, oid *name, size_t *length, int exact,
  1167. size_t *var_len, WriteMethod **write_method)
  1168. {
  1169. struct ospf_nbr_nbma *nbr_nbma;
  1170. struct ospf_interface *oi;
  1171. struct in_addr addr;
  1172. struct ospf *ospf;
  1173. /* Check OSPF instance. */
  1174. ospf = ospf_lookup ();
  1175. if (ospf == NULL)
  1176. return NULL;
  1177. memset (&addr, 0, sizeof (struct in_addr));
  1178. nbr_nbma = ospfHostLookup (v, name, length, &addr, exact);
  1179. if (nbr_nbma == NULL)
  1180. return NULL;
  1181. oi = nbr_nbma->oi;
  1182. /* Return the current value of the variable */
  1183. switch (v->magic)
  1184. {
  1185. case OSPFHOSTIPADDRESS: /* 1 */
  1186. return SNMP_IPADDRESS (nbr_nbma->addr);
  1187. break;
  1188. case OSPFHOSTTOS: /* 2 */
  1189. return SNMP_INTEGER (0);
  1190. break;
  1191. case OSPFHOSTMETRIC: /* 3 */
  1192. if (oi)
  1193. return SNMP_INTEGER (oi->output_cost);
  1194. else
  1195. return SNMP_INTEGER (1);
  1196. break;
  1197. case OSPFHOSTSTATUS: /* 4 */
  1198. return SNMP_INTEGER (SNMP_VALID);
  1199. break;
  1200. case OSPFHOSTAREAID: /* 5 */
  1201. if (oi && oi->area)
  1202. return SNMP_IPADDRESS (oi->area->area_id);
  1203. else
  1204. return SNMP_IPADDRESS (ospf_empty_addr);
  1205. break;
  1206. default:
  1207. return NULL;
  1208. break;
  1209. }
  1210. return NULL;
  1211. }
  1212. struct list *ospf_snmp_iflist;
  1213. struct ospf_snmp_if
  1214. {
  1215. struct in_addr addr;
  1216. unsigned int ifindex;
  1217. struct interface *ifp;
  1218. };
  1219. struct ospf_snmp_if *
  1220. ospf_snmp_if_new ()
  1221. {
  1222. struct ospf_snmp_if *osif;
  1223. osif = XMALLOC (0, sizeof (struct ospf_snmp_if));
  1224. memset (osif, 0, sizeof (struct ospf_snmp_if));
  1225. return osif;
  1226. }
  1227. void
  1228. ospf_snmp_if_free (struct ospf_snmp_if *osif)
  1229. {
  1230. XFREE (0, osif);
  1231. }
  1232. void
  1233. ospf_snmp_if_delete (struct interface *ifp)
  1234. {
  1235. struct listnode *node, *nnode;
  1236. struct ospf_snmp_if *osif;
  1237. for (ALL_LIST_ELEMENTS (ospf_snmp_iflist, node, nnode, osif))
  1238. {
  1239. if (osif->ifp == ifp)
  1240. {
  1241. list_delete_node (ospf_snmp_iflist, node);
  1242. ospf_snmp_if_free (osif);
  1243. return;
  1244. }
  1245. }
  1246. }
  1247. void
  1248. ospf_snmp_if_update (struct interface *ifp)
  1249. {
  1250. struct listnode *node;
  1251. struct listnode *pn;
  1252. struct connected *ifc;
  1253. struct prefix *p;
  1254. struct ospf_snmp_if *osif;
  1255. struct in_addr *addr;
  1256. unsigned int ifindex;
  1257. ospf_snmp_if_delete (ifp);
  1258. p = NULL;
  1259. addr = NULL;
  1260. ifindex = 0;
  1261. /* Lookup first IPv4 address entry. */
  1262. for (ALL_LIST_ELEMENTS_RO (ifp->connected, node, ifc))
  1263. {
  1264. p = CONNECTED_ID(ifc);
  1265. if (p->family == AF_INET)
  1266. {
  1267. addr = &p->u.prefix4;
  1268. break;
  1269. }
  1270. }
  1271. if (! addr)
  1272. ifindex = ifp->ifindex;
  1273. /* Add interface to the list. */
  1274. pn = NULL;
  1275. for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist, node, osif))
  1276. {
  1277. if (addr)
  1278. {
  1279. /* Usual interfaces --> Sort them based on interface IPv4 addresses */
  1280. if (ntohl (osif->addr.s_addr) > ntohl (addr->s_addr))
  1281. break;
  1282. }
  1283. else
  1284. {
  1285. /* Unnumbered interfaces --> Sort them based on interface indexes */
  1286. if (osif->addr.s_addr != 0 || osif->ifindex > ifindex)
  1287. break;
  1288. }
  1289. pn = node;
  1290. }
  1291. osif = ospf_snmp_if_new ();
  1292. if (addr) /* Usual interface */
  1293. {
  1294. osif->addr = *addr;
  1295. /* This field is used for storing ospfAddressLessIf OID value,
  1296. * conform to RFC1850 OSPF-MIB specification, it must be 0 for
  1297. * usual interface */
  1298. osif->ifindex = 0;
  1299. }
  1300. else /* Unnumbered interface */
  1301. osif->ifindex = ifindex;
  1302. osif->ifp = ifp;
  1303. listnode_add_after (ospf_snmp_iflist, pn, osif);
  1304. }
  1305. int
  1306. ospf_snmp_is_if_have_addr (struct interface *ifp)
  1307. {
  1308. struct listnode *nn;
  1309. struct connected *ifc;
  1310. /* Is this interface having any connected IPv4 address ? */
  1311. for (ALL_LIST_ELEMENTS_RO (ifp->connected, nn, ifc))
  1312. {
  1313. if (CONNECTED_PREFIX(ifc)->family == AF_INET)
  1314. return 1;
  1315. }
  1316. return 0;
  1317. }
  1318. struct ospf_interface *
  1319. ospf_snmp_if_lookup (struct in_addr *ifaddr, unsigned int *ifindex)
  1320. {
  1321. struct listnode *node;
  1322. struct ospf_snmp_if *osif;
  1323. struct ospf_interface *oi = NULL;
  1324. struct ospf *ospf = ospf_lookup ();
  1325. for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist, node, osif))
  1326. {
  1327. if (ifaddr->s_addr)
  1328. {
  1329. if (IPV4_ADDR_SAME (&osif->addr, ifaddr))
  1330. oi = ospf_if_lookup_by_local_addr (ospf, osif->ifp, *ifaddr);
  1331. }
  1332. else
  1333. {
  1334. if (osif->ifindex == *ifindex)
  1335. oi = ospf_if_lookup_by_local_addr (ospf, osif->ifp, *ifaddr);
  1336. }
  1337. }
  1338. return oi;
  1339. }
  1340. struct ospf_interface *
  1341. ospf_snmp_if_lookup_next (struct in_addr *ifaddr, unsigned int *ifindex,
  1342. int ifaddr_next, int ifindex_next)
  1343. {
  1344. struct ospf_snmp_if *osif;
  1345. struct listnode *nn;
  1346. struct ospf *ospf = ospf_lookup ();
  1347. struct ospf_interface *oi = NULL;
  1348. if (ospf == NULL)
  1349. return NULL;
  1350. /* No instance is specified --> Return the first OSPF interface */
  1351. if (ifaddr_next)
  1352. {
  1353. for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist, nn, osif))
  1354. {
  1355. osif = listgetdata (nn);
  1356. *ifaddr = osif->addr;
  1357. *ifindex = osif->ifindex;
  1358. /* Because no instance is specified, we don't care about the kind of
  1359. * interface (usual or unnumbered), just returning the first valid
  1360. * OSPF interface */
  1361. oi = ospf_if_lookup_by_local_addr (ospf, osif->ifp, *ifaddr);
  1362. if (oi)
  1363. return (oi);
  1364. }
  1365. return NULL;
  1366. }
  1367. /* An instance is specified --> Return the next OSPF interface */
  1368. for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist, nn, osif))
  1369. {
  1370. /* Usual interface */
  1371. if (ifaddr->s_addr)
  1372. /* The interface must have valid AF_INET connected address */
  1373. /* it must have lager IPv4 address value than the lookup entry */
  1374. if ((ospf_snmp_is_if_have_addr(osif->ifp)) &&
  1375. (ntohl (osif->addr.s_addr) > ntohl (ifaddr->s_addr)))
  1376. {
  1377. *ifaddr = osif->addr;
  1378. *ifindex = osif->ifindex;
  1379. /* and it must be an OSPF interface */
  1380. oi = ospf_if_lookup_by_local_addr (ospf, osif->ifp, *ifaddr);
  1381. if (oi)
  1382. return oi;
  1383. }
  1384. /* Unnumbered interface */
  1385. else
  1386. /* The interface must NOT have valid AF_INET connected address */
  1387. /* it must have lager interface index than the lookup entry */
  1388. if ((!ospf_snmp_is_if_have_addr(osif->ifp)) &&
  1389. (osif->ifindex > *ifindex))
  1390. {
  1391. *ifaddr = osif->addr;
  1392. *ifindex = osif->ifindex;
  1393. /* and it must be an OSPF interface */
  1394. oi = ospf_if_lookup_by_local_addr (ospf, osif->ifp, *ifaddr);
  1395. if (oi)
  1396. return oi;
  1397. }
  1398. }
  1399. return NULL;
  1400. }
  1401. int
  1402. ospf_snmp_iftype (struct interface *ifp)
  1403. {
  1404. #define ospf_snmp_iftype_broadcast 1
  1405. #define ospf_snmp_iftype_nbma 2
  1406. #define ospf_snmp_iftype_pointToPoint 3
  1407. #define ospf_snmp_iftype_pointToMultipoint 5
  1408. if (if_is_broadcast (ifp))
  1409. return ospf_snmp_iftype_broadcast;
  1410. if (if_is_pointopoint (ifp))
  1411. return ospf_snmp_iftype_pointToPoint;
  1412. return ospf_snmp_iftype_broadcast;
  1413. }
  1414. struct ospf_interface *
  1415. ospfIfLookup (struct variable *v, oid *name, size_t *length,
  1416. struct in_addr *ifaddr, unsigned int *ifindex, int exact)
  1417. {
  1418. unsigned int len;
  1419. int ifaddr_next = 0;
  1420. int ifindex_next = 0;
  1421. struct ospf_interface *oi;
  1422. oid *offset;
  1423. if (exact)
  1424. {
  1425. if (*length != v->namelen + IN_ADDR_SIZE + 1)
  1426. return NULL;
  1427. oid2in_addr (name + v->namelen, IN_ADDR_SIZE, ifaddr);
  1428. *ifindex = name[v->namelen + IN_ADDR_SIZE];
  1429. return ospf_snmp_if_lookup (ifaddr, ifindex);
  1430. }
  1431. else
  1432. {
  1433. len = *length - v->namelen;
  1434. if (len >= IN_ADDR_SIZE)
  1435. len = IN_ADDR_SIZE;
  1436. if (len <= 0)
  1437. ifaddr_next = 1;
  1438. oid2in_addr (name + v->namelen, len, ifaddr);
  1439. len = *length - v->namelen - IN_ADDR_SIZE;
  1440. if (len >= 1)
  1441. len = 1;
  1442. else
  1443. ifindex_next = 1;
  1444. if (len == 1)
  1445. *ifindex = name[v->namelen + IN_ADDR_SIZE];
  1446. oi = ospf_snmp_if_lookup_next (ifaddr, ifindex, ifaddr_next,
  1447. ifindex_next);
  1448. if (oi)
  1449. {
  1450. *length = v->namelen + IN_ADDR_SIZE + 1;
  1451. offset = name + v->namelen;
  1452. oid_copy_addr (offset, ifaddr, IN_ADDR_SIZE);
  1453. offset += IN_ADDR_SIZE;
  1454. *offset = *ifindex;
  1455. return oi;
  1456. }
  1457. }
  1458. return NULL;
  1459. }
  1460. static u_char *
  1461. ospfIfEntry (struct variable *v, oid *name, size_t *length, int exact,
  1462. size_t *var_len, WriteMethod **write_method)
  1463. {
  1464. unsigned int ifindex;
  1465. struct in_addr ifaddr;
  1466. struct ospf_interface *oi;
  1467. struct ospf *ospf;
  1468. ifindex = 0;
  1469. memset (&ifaddr, 0, sizeof (struct in_addr));
  1470. /* Check OSPF instance. */
  1471. ospf = ospf_lookup ();
  1472. if (ospf == NULL)
  1473. return NULL;
  1474. oi = ospfIfLookup (v, name, length, &ifaddr, &ifindex, exact);
  1475. if (oi == NULL)
  1476. return NULL;
  1477. /* Return the current value of the variable */
  1478. switch (v->magic)
  1479. {
  1480. case OSPFIFIPADDRESS: /* 1 */
  1481. return SNMP_IPADDRESS (ifaddr);
  1482. break;
  1483. case OSPFADDRESSLESSIF: /* 2 */
  1484. return SNMP_INTEGER (ifindex);
  1485. break;
  1486. case OSPFIFAREAID: /* 3 */
  1487. if (oi->area)
  1488. return SNMP_IPADDRESS (oi->area->area_id);
  1489. else
  1490. return SNMP_IPADDRESS (ospf_empty_addr);
  1491. break;
  1492. case OSPFIFTYPE: /* 4 */
  1493. return SNMP_INTEGER (ospf_snmp_iftype (oi->ifp));
  1494. break;
  1495. case OSPFIFADMINSTAT: /* 5 */
  1496. if (oi)
  1497. return SNMP_INTEGER (OSPF_STATUS_ENABLED);
  1498. else
  1499. return SNMP_INTEGER (OSPF_STATUS_DISABLED);
  1500. break;
  1501. case OSPFIFRTRPRIORITY: /* 6 */
  1502. return SNMP_INTEGER (PRIORITY (oi));
  1503. break;
  1504. case OSPFIFTRANSITDELAY: /* 7 */
  1505. return SNMP_INTEGER (OSPF_IF_PARAM (oi, transmit_delay));
  1506. break;
  1507. case OSPFIFRETRANSINTERVAL: /* 8 */
  1508. return SNMP_INTEGER (OSPF_IF_PARAM (oi, retransmit_interval));
  1509. break;
  1510. case OSPFIFHELLOINTERVAL: /* 9 */
  1511. return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_hello));
  1512. break;
  1513. case OSPFIFRTRDEADINTERVAL: /* 10 */
  1514. return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_wait));
  1515. break;
  1516. case OSPFIFPOLLINTERVAL: /* 11 */
  1517. return SNMP_INTEGER (OSPF_POLL_INTERVAL_DEFAULT);
  1518. break;
  1519. case OSPFIFSTATE: /* 12 */
  1520. return SNMP_INTEGER (ISM_SNMP(oi->state));
  1521. break;
  1522. case OSPFIFDESIGNATEDROUTER: /* 13 */
  1523. return SNMP_IPADDRESS (DR (oi));
  1524. break;
  1525. case OSPFIFBACKUPDESIGNATEDROUTER: /* 14 */
  1526. return SNMP_IPADDRESS (BDR (oi));
  1527. break;
  1528. case OSPFIFEVENTS: /* 15 */
  1529. return SNMP_INTEGER (oi->state_change);
  1530. break;
  1531. case OSPFIFAUTHKEY: /* 16 */
  1532. *var_len = 0;
  1533. return (u_char *) OSPF_IF_PARAM (oi, auth_simple);
  1534. break;
  1535. case OSPFIFSTATUS: /* 17 */
  1536. return SNMP_INTEGER (SNMP_VALID);
  1537. break;
  1538. case OSPFIFMULTICASTFORWARDING: /* 18 */
  1539. #define ospf_snmp_multiforward_blocked 1
  1540. #define ospf_snmp_multiforward_multicast 2
  1541. #define ospf_snmp_multiforward_unicast 3
  1542. return SNMP_INTEGER (ospf_snmp_multiforward_blocked);
  1543. break;
  1544. case OSPFIFDEMAND: /* 19 */
  1545. return SNMP_INTEGER (SNMP_FALSE);
  1546. break;
  1547. case OSPFIFAUTHTYPE: /* 20 */
  1548. if (oi->area)
  1549. return SNMP_INTEGER (oi->area->auth_type);
  1550. else
  1551. return SNMP_INTEGER (0);
  1552. break;
  1553. default:
  1554. return NULL;
  1555. break;
  1556. }
  1557. return NULL;
  1558. }
  1559. #define OSPF_SNMP_METRIC_VALUE 1
  1560. struct ospf_interface *
  1561. ospfIfMetricLookup (struct variable *v, oid *name, size_t *length,
  1562. struct in_addr *ifaddr, unsigned int *ifindex, int exact)
  1563. {
  1564. unsigned int len;
  1565. int ifaddr_next = 0;
  1566. int ifindex_next = 0;
  1567. struct ospf_interface *oi;
  1568. oid *offset;
  1569. int metric;
  1570. if (exact)
  1571. {
  1572. if (*length != v->namelen + IN_ADDR_SIZE + 1 + 1)
  1573. return NULL;
  1574. oid2in_addr (name + v->namelen, IN_ADDR_SIZE, ifaddr);
  1575. *ifindex = name[v->namelen + IN_ADDR_SIZE];
  1576. metric = name[v->namelen + IN_ADDR_SIZE + 1];
  1577. if (metric != OSPF_SNMP_METRIC_VALUE)
  1578. return NULL;
  1579. return ospf_snmp_if_lookup (ifaddr, ifindex);
  1580. }
  1581. else
  1582. {
  1583. len = *length - v->namelen;
  1584. if (len >= IN_ADDR_SIZE)
  1585. len = IN_ADDR_SIZE;
  1586. else
  1587. ifaddr_next = 1;
  1588. oid2in_addr (name + v->namelen, len, ifaddr);
  1589. len = *length - v->namelen - IN_ADDR_SIZE;
  1590. if (len >= 1)
  1591. len = 1;
  1592. else
  1593. ifindex_next = 1;
  1594. if (len == 1)
  1595. *ifindex = name[v->namelen + IN_ADDR_SIZE];
  1596. oi = ospf_snmp_if_lookup_next (ifaddr, ifindex, ifaddr_next,
  1597. ifindex_next);
  1598. if (oi)
  1599. {
  1600. *length = v->namelen + IN_ADDR_SIZE + 1 + 1;
  1601. offset = name + v->namelen;
  1602. oid_copy_addr (offset, ifaddr, IN_ADDR_SIZE);
  1603. offset += IN_ADDR_SIZE;
  1604. *offset = *ifindex;
  1605. offset++;
  1606. *offset = OSPF_SNMP_METRIC_VALUE;
  1607. return oi;
  1608. }
  1609. }
  1610. return NULL;
  1611. }
  1612. static u_char *
  1613. ospfIfMetricEntry (struct variable *v, oid *name, size_t *length, int exact,
  1614. size_t *var_len, WriteMethod **write_method)
  1615. {
  1616. /* Currently we support metric 1 only. */
  1617. unsigned int ifindex;
  1618. struct in_addr ifaddr;
  1619. struct ospf_interface *oi;
  1620. struct ospf *ospf;
  1621. ifindex = 0;
  1622. memset (&ifaddr, 0, sizeof (struct in_addr));
  1623. /* Check OSPF instance. */
  1624. ospf = ospf_lookup ();
  1625. if (ospf == NULL)
  1626. return NULL;
  1627. oi = ospfIfMetricLookup (v, name, length, &ifaddr, &ifindex, exact);
  1628. if (oi == NULL)
  1629. return NULL;
  1630. /* Return the current value of the variable */
  1631. switch (v->magic)
  1632. {
  1633. case OSPFIFMETRICIPADDRESS:
  1634. return SNMP_IPADDRESS (ifaddr);
  1635. break;
  1636. case OSPFIFMETRICADDRESSLESSIF:
  1637. return SNMP_INTEGER (ifindex);
  1638. break;
  1639. case OSPFIFMETRICTOS:
  1640. return SNMP_INTEGER (0);
  1641. break;
  1642. case OSPFIFMETRICVALUE:
  1643. return SNMP_INTEGER (OSPF_SNMP_METRIC_VALUE);
  1644. break;
  1645. case OSPFIFMETRICSTATUS:
  1646. return SNMP_INTEGER (1);
  1647. break;
  1648. default:
  1649. return NULL;
  1650. break;
  1651. }
  1652. return NULL;
  1653. }
  1654. struct route_table *ospf_snmp_vl_table;
  1655. void
  1656. ospf_snmp_vl_add (struct ospf_vl_data *vl_data)
  1657. {
  1658. struct prefix_ls lp;
  1659. struct route_node *rn;
  1660. memset (&lp, 0, sizeof (struct prefix_ls));
  1661. lp.family = 0;
  1662. lp.prefixlen = 64;
  1663. lp.id = vl_data->vl_area_id;
  1664. lp.adv_router = vl_data->vl_peer;
  1665. rn = route_node_get (ospf_snmp_vl_table, (struct prefix *) &lp);
  1666. rn->info = vl_data;
  1667. }
  1668. void
  1669. ospf_snmp_vl_delete (struct ospf_vl_data *vl_data)
  1670. {
  1671. struct prefix_ls lp;
  1672. struct route_node *rn;
  1673. memset (&lp, 0, sizeof (struct prefix_ls));
  1674. lp.family = 0;
  1675. lp.prefixlen = 64;
  1676. lp.id = vl_data->vl_area_id;
  1677. lp.adv_router = vl_data->vl_peer;
  1678. rn = route_node_lookup (ospf_snmp_vl_table, (struct prefix *) &lp);
  1679. if (! rn)
  1680. return;
  1681. rn->info = NULL;
  1682. route_unlock_node (rn);
  1683. route_unlock_node (rn);
  1684. }
  1685. struct ospf_vl_data *
  1686. ospf_snmp_vl_lookup (struct in_addr *area_id, struct in_addr *neighbor)
  1687. {
  1688. struct prefix_ls lp;
  1689. struct route_node *rn;
  1690. struct ospf_vl_data *vl_data;
  1691. memset (&lp, 0, sizeof (struct prefix_ls));
  1692. lp.family = 0;
  1693. lp.prefixlen = 64;
  1694. lp.id = *area_id;
  1695. lp.adv_router = *neighbor;
  1696. rn = route_node_lookup (ospf_snmp_vl_table, (struct prefix *) &lp);
  1697. if (rn)
  1698. {
  1699. vl_data = rn->info;
  1700. route_unlock_node (rn);
  1701. return vl_data;
  1702. }
  1703. return NULL;
  1704. }
  1705. struct ospf_vl_data *
  1706. ospf_snmp_vl_lookup_next (struct in_addr *area_id, struct in_addr *neighbor,
  1707. int first)
  1708. {
  1709. struct prefix_ls lp;
  1710. struct route_node *rn;
  1711. struct ospf_vl_data *vl_data;
  1712. memset (&lp, 0, sizeof (struct prefix_ls));
  1713. lp.family = 0;
  1714. lp.prefixlen = 64;
  1715. lp.id = *area_id;
  1716. lp.adv_router = *neighbor;
  1717. if (first)
  1718. rn = route_top (ospf_snmp_vl_table);
  1719. else
  1720. {
  1721. rn = route_node_get (ospf_snmp_vl_table, (struct prefix *) &lp);
  1722. rn = route_next (rn);
  1723. }
  1724. for (; rn; rn = route_next (rn))
  1725. if (rn->info)
  1726. break;
  1727. if (rn && rn->info)
  1728. {
  1729. vl_data = rn->info;
  1730. *area_id = vl_data->vl_area_id;
  1731. *neighbor = vl_data->vl_peer;
  1732. route_unlock_node (rn);
  1733. return vl_data;
  1734. }
  1735. return NULL;
  1736. }
  1737. struct ospf_vl_data *
  1738. ospfVirtIfLookup (struct variable *v, oid *name, size_t *length,
  1739. struct in_addr *area_id, struct in_addr *neighbor, int exact)
  1740. {
  1741. int first;
  1742. unsigned int len;
  1743. struct ospf_vl_data *vl_data;
  1744. if (exact)
  1745. {
  1746. if (*length != v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE)
  1747. return NULL;
  1748. oid2in_addr (name + v->namelen, IN_ADDR_SIZE, area_id);
  1749. oid2in_addr (name + v->namelen + IN_ADDR_SIZE, IN_ADDR_SIZE, neighbor);
  1750. return ospf_snmp_vl_lookup (area_id, neighbor);
  1751. }
  1752. else
  1753. {
  1754. first = 0;
  1755. len = *length - v->namelen;
  1756. if (len <= 0)
  1757. first = 1;
  1758. if (len > IN_ADDR_SIZE)
  1759. len = IN_ADDR_SIZE;
  1760. oid2in_addr (name + v->namelen, len, area_id);
  1761. len = *length - v->namelen - IN_ADDR_SIZE;
  1762. if (len > IN_ADDR_SIZE)
  1763. len = IN_ADDR_SIZE;
  1764. oid2in_addr (name + v->namelen + IN_ADDR_SIZE, len, neighbor);
  1765. vl_data = ospf_snmp_vl_lookup_next (area_id, neighbor, first);
  1766. if (vl_data)
  1767. {
  1768. *length = v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE;
  1769. oid_copy_addr (name + v->namelen, area_id, IN_ADDR_SIZE);
  1770. oid_copy_addr (name + v->namelen + IN_ADDR_SIZE, neighbor,
  1771. IN_ADDR_SIZE);
  1772. return vl_data;
  1773. }
  1774. }
  1775. return NULL;
  1776. }
  1777. static u_char *
  1778. ospfVirtIfEntry (struct variable *v, oid *name, size_t *length, int exact,
  1779. size_t *var_len, WriteMethod **write_method)
  1780. {
  1781. struct ospf_vl_data *vl_data;
  1782. struct ospf_interface *oi;
  1783. struct in_addr area_id;
  1784. struct in_addr neighbor;
  1785. memset (&area_id, 0, sizeof (struct in_addr));
  1786. memset (&neighbor, 0, sizeof (struct in_addr));
  1787. vl_data = ospfVirtIfLookup (v, name, length, &area_id, &neighbor, exact);
  1788. if (! vl_data)
  1789. return NULL;
  1790. oi = vl_data->vl_oi;
  1791. if (! oi)
  1792. return NULL;
  1793. /* Return the current value of the variable */
  1794. switch (v->magic)
  1795. {
  1796. case OSPFVIRTIFAREAID:
  1797. return SNMP_IPADDRESS (area_id);
  1798. break;
  1799. case OSPFVIRTIFNEIGHBOR:
  1800. return SNMP_IPADDRESS (neighbor);
  1801. break;
  1802. case OSPFVIRTIFTRANSITDELAY:
  1803. return SNMP_INTEGER (OSPF_IF_PARAM (oi, transmit_delay));
  1804. break;
  1805. case OSPFVIRTIFRETRANSINTERVAL:
  1806. return SNMP_INTEGER (OSPF_IF_PARAM (oi, retransmit_interval));
  1807. break;
  1808. case OSPFVIRTIFHELLOINTERVAL:
  1809. return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_hello));
  1810. break;
  1811. case OSPFVIRTIFRTRDEADINTERVAL:
  1812. return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_wait));
  1813. break;
  1814. case OSPFVIRTIFSTATE:
  1815. return SNMP_INTEGER (oi->state);
  1816. break;
  1817. case OSPFVIRTIFEVENTS:
  1818. return SNMP_INTEGER (oi->state_change);
  1819. break;
  1820. case OSPFVIRTIFAUTHKEY:
  1821. *var_len = 0;
  1822. return (u_char *) OSPF_IF_PARAM (oi, auth_simple);
  1823. break;
  1824. case OSPFVIRTIFSTATUS:
  1825. return SNMP_INTEGER (SNMP_VALID);
  1826. break;
  1827. case OSPFVIRTIFAUTHTYPE:
  1828. if (oi->area)
  1829. return SNMP_INTEGER (oi->area->auth_type);
  1830. else
  1831. return SNMP_INTEGER (0);
  1832. break;
  1833. default:
  1834. return NULL;
  1835. break;
  1836. }
  1837. return NULL;
  1838. }
  1839. struct ospf_neighbor *
  1840. ospf_snmp_nbr_lookup (struct ospf *ospf, struct in_addr *nbr_addr,
  1841. unsigned int *ifindex)
  1842. {
  1843. struct listnode *node, *nnode;
  1844. struct ospf_interface *oi;
  1845. struct ospf_neighbor *nbr;
  1846. struct route_node *rn;
  1847. for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
  1848. {
  1849. for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
  1850. if ((nbr = rn->info) != NULL
  1851. && nbr != oi->nbr_self
  1852. /* If EXACT match is needed, provide ALL entry found
  1853. && nbr->state != NSM_Down
  1854. */
  1855. && nbr->src.s_addr != 0)
  1856. {
  1857. if (IPV4_ADDR_SAME (&nbr->src, nbr_addr))
  1858. {
  1859. route_unlock_node (rn);
  1860. return nbr;
  1861. }
  1862. }
  1863. }
  1864. return NULL;
  1865. }
  1866. struct ospf_neighbor *
  1867. ospf_snmp_nbr_lookup_next (struct in_addr *nbr_addr, unsigned int *ifindex,
  1868. int first)
  1869. {
  1870. struct listnode *nn;
  1871. struct ospf_interface *oi;
  1872. struct ospf_neighbor *nbr;
  1873. struct route_node *rn;
  1874. struct ospf_neighbor *min = NULL;
  1875. struct ospf *ospf = ospf;
  1876. ospf = ospf_lookup ();
  1877. for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, nn, oi))
  1878. {
  1879. for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
  1880. if ((nbr = rn->info) != NULL
  1881. && nbr != oi->nbr_self
  1882. && nbr->state != NSM_Down
  1883. && nbr->src.s_addr != 0)
  1884. {
  1885. if (first)
  1886. {
  1887. if (! min)
  1888. min = nbr;
  1889. else if (ntohl (nbr->src.s_addr) < ntohl (min->src.s_addr))
  1890. min = nbr;
  1891. }
  1892. else if (ntohl (nbr->src.s_addr) > ntohl (nbr_addr->s_addr))
  1893. {
  1894. if (! min)
  1895. min = nbr;
  1896. else if (ntohl (nbr->src.s_addr) < ntohl (min->src.s_addr))
  1897. min = nbr;
  1898. }
  1899. }
  1900. }
  1901. if (min)
  1902. {
  1903. *nbr_addr = min->src;
  1904. *ifindex = 0;
  1905. return min;
  1906. }
  1907. return NULL;
  1908. }
  1909. struct ospf_neighbor *
  1910. ospfNbrLookup (struct variable *v, oid *name, size_t *length,
  1911. struct in_addr *nbr_addr, unsigned int *ifindex, int exact)
  1912. {
  1913. unsigned int len;
  1914. int first;
  1915. struct ospf_neighbor *nbr;
  1916. struct ospf *ospf;
  1917. ospf = ospf_lookup ();
  1918. if (! ospf)
  1919. return NULL;
  1920. if (exact)
  1921. {
  1922. if (*length != v->namelen + IN_ADDR_SIZE + 1)
  1923. return NULL;
  1924. oid2in_addr (name + v->namelen, IN_ADDR_SIZE, nbr_addr);
  1925. *ifindex = name[v->namelen + IN_ADDR_SIZE];
  1926. return ospf_snmp_nbr_lookup (ospf, nbr_addr, ifindex);
  1927. }
  1928. else
  1929. {
  1930. first = 0;
  1931. len = *length - v->namelen;
  1932. if (len <= 0)
  1933. first = 1;
  1934. if (len > IN_ADDR_SIZE)
  1935. len = IN_ADDR_SIZE;
  1936. oid2in_addr (name + v->namelen, len, nbr_addr);
  1937. len = *length - v->namelen - IN_ADDR_SIZE;
  1938. if (len >= 1)
  1939. *ifindex = name[v->namelen + IN_ADDR_SIZE];
  1940. nbr = ospf_snmp_nbr_lookup_next (nbr_addr, ifindex, first);
  1941. if (nbr)
  1942. {
  1943. *length = v->namelen + IN_ADDR_SIZE + 1;
  1944. oid_copy_addr (name + v->namelen, nbr_addr, IN_ADDR_SIZE);
  1945. name[v->namelen + IN_ADDR_SIZE] = *ifindex;
  1946. return nbr;
  1947. }
  1948. }
  1949. return NULL;
  1950. }
  1951. static u_char *
  1952. ospfNbrEntry (struct variable *v, oid *name, size_t *length, int exact,
  1953. size_t *var_len, WriteMethod **write_method)
  1954. {
  1955. struct in_addr nbr_addr;
  1956. unsigned int ifindex;
  1957. struct ospf_neighbor *nbr;
  1958. struct ospf_interface *oi;
  1959. memset (&nbr_addr, 0, sizeof (struct in_addr));
  1960. ifindex = 0;
  1961. nbr = ospfNbrLookup (v, name, length, &nbr_addr, &ifindex, exact);
  1962. if (! nbr)
  1963. return NULL;
  1964. oi = nbr->oi;
  1965. if (! oi)
  1966. return NULL;
  1967. /* Return the current value of the variable */
  1968. switch (v->magic)
  1969. {
  1970. case OSPFNBRIPADDR:
  1971. return SNMP_IPADDRESS (nbr_addr);
  1972. break;
  1973. case OSPFNBRADDRESSLESSINDEX:
  1974. return SNMP_INTEGER (ifindex);
  1975. break;
  1976. case OSPFNBRRTRID:
  1977. return SNMP_IPADDRESS (nbr->router_id);
  1978. break;
  1979. case OSPFNBROPTIONS:
  1980. return SNMP_INTEGER (oi->nbr_self->options);
  1981. break;
  1982. case OSPFNBRPRIORITY:
  1983. return SNMP_INTEGER (nbr->priority);
  1984. break;
  1985. case OSPFNBRSTATE:
  1986. return SNMP_INTEGER (nbr->state);
  1987. break;
  1988. case OSPFNBREVENTS:
  1989. return SNMP_INTEGER (nbr->state_change);
  1990. break;
  1991. case OSPFNBRLSRETRANSQLEN:
  1992. return SNMP_INTEGER (ospf_ls_retransmit_count (nbr));
  1993. break;
  1994. case OSPFNBMANBRSTATUS:
  1995. return SNMP_INTEGER (SNMP_VALID);
  1996. break;
  1997. case OSPFNBMANBRPERMANENCE:
  1998. return SNMP_INTEGER (2);
  1999. break;
  2000. case OSPFNBRHELLOSUPPRESSED:
  2001. return SNMP_INTEGER (SNMP_FALSE);
  2002. break;
  2003. default:
  2004. return NULL;
  2005. break;
  2006. }
  2007. return NULL;
  2008. }
  2009. static u_char *
  2010. ospfVirtNbrEntry (struct variable *v, oid *name, size_t *length, int exact,
  2011. size_t *var_len, WriteMethod **write_method)
  2012. {
  2013. struct ospf_vl_data *vl_data;
  2014. struct in_addr area_id;
  2015. struct in_addr neighbor;
  2016. struct ospf *ospf;
  2017. memset (&area_id, 0, sizeof (struct in_addr));
  2018. memset (&neighbor, 0, sizeof (struct in_addr));
  2019. /* Check OSPF instance. */
  2020. ospf = ospf_lookup ();
  2021. if (ospf == NULL)
  2022. return NULL;
  2023. vl_data = ospfVirtIfLookup (v, name, length, &area_id, &neighbor, exact);
  2024. if (! vl_data)
  2025. return NULL;
  2026. /* Return the current value of the variable */
  2027. switch (v->magic)
  2028. {
  2029. case OSPFVIRTNBRAREA:
  2030. return (u_char *) NULL;
  2031. break;
  2032. case OSPFVIRTNBRRTRID:
  2033. return (u_char *) NULL;
  2034. break;
  2035. case OSPFVIRTNBRIPADDR:
  2036. return (u_char *) NULL;
  2037. break;
  2038. case OSPFVIRTNBROPTIONS:
  2039. return (u_char *) NULL;
  2040. break;
  2041. case OSPFVIRTNBRSTATE:
  2042. return (u_char *) NULL;
  2043. break;
  2044. case OSPFVIRTNBREVENTS:
  2045. return (u_char *) NULL;
  2046. break;
  2047. case OSPFVIRTNBRLSRETRANSQLEN:
  2048. return (u_char *) NULL;
  2049. break;
  2050. case OSPFVIRTNBRHELLOSUPPRESSED:
  2051. return (u_char *) NULL;
  2052. break;
  2053. default:
  2054. return NULL;
  2055. break;
  2056. }
  2057. return NULL;
  2058. }
  2059. struct ospf_lsa *
  2060. ospfExtLsdbLookup (struct variable *v, oid *name, size_t *length, u_char *type,
  2061. struct in_addr *ls_id, struct in_addr *router_id, int exact)
  2062. {
  2063. int first;
  2064. oid *offset;
  2065. int offsetlen;
  2066. u_char lsa_type;
  2067. unsigned int len;
  2068. struct ospf_lsa *lsa;
  2069. struct ospf *ospf;
  2070. ospf = ospf_lookup ();
  2071. if (exact)
  2072. {
  2073. if (*length != v->namelen + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE)
  2074. return NULL;
  2075. offset = name + v->namelen;
  2076. /* Make it sure given value match to type. */
  2077. lsa_type = *offset;
  2078. offset++;
  2079. if (lsa_type != *type)
  2080. return NULL;
  2081. /* LS ID. */
  2082. oid2in_addr (offset, IN_ADDR_SIZE, ls_id);
  2083. offset += IN_ADDR_SIZE;
  2084. /* Router ID. */
  2085. oid2in_addr (offset, IN_ADDR_SIZE, router_id);
  2086. return ospf_lsdb_lookup_by_id (ospf->lsdb, *type, *ls_id, *router_id);
  2087. }
  2088. else
  2089. {
  2090. /* Get variable length. */
  2091. first = 0;
  2092. offset = name + v->namelen;
  2093. offsetlen = *length - v->namelen;
  2094. /* LSA type value. */
  2095. lsa_type = *offset;
  2096. offset++;
  2097. offsetlen--;
  2098. if (offsetlen <= 0 || lsa_type < OSPF_AS_EXTERNAL_LSA)
  2099. first = 1;
  2100. /* LS ID. */
  2101. len = offsetlen;
  2102. if (len > IN_ADDR_SIZE)
  2103. len = IN_ADDR_SIZE;
  2104. oid2in_addr (offset, len, ls_id);
  2105. offset += IN_ADDR_SIZE;
  2106. offsetlen -= IN_ADDR_SIZE;
  2107. /* Router ID. */
  2108. len = offsetlen;
  2109. if (len > IN_ADDR_SIZE)
  2110. len = IN_ADDR_SIZE;
  2111. oid2in_addr (offset, len, router_id);
  2112. lsa = ospf_lsdb_lookup_by_id_next (ospf->lsdb, *type, *ls_id,
  2113. *router_id, first);
  2114. if (lsa)
  2115. {
  2116. /* Fill in length. */
  2117. *length = v->namelen + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE;
  2118. /* Fill in value. */
  2119. offset = name + v->namelen;
  2120. *offset = OSPF_AS_EXTERNAL_LSA;
  2121. offset++;
  2122. oid_copy_addr (offset, &lsa->data->id, IN_ADDR_SIZE);
  2123. offset += IN_ADDR_SIZE;
  2124. oid_copy_addr (offset, &lsa->data->adv_router, IN_ADDR_SIZE);
  2125. return lsa;
  2126. }
  2127. }
  2128. return NULL;
  2129. }
  2130. static u_char *
  2131. ospfExtLsdbEntry (struct variable *v, oid *name, size_t *length, int exact,
  2132. size_t *var_len, WriteMethod **write_method)
  2133. {
  2134. struct ospf_lsa *lsa;
  2135. struct lsa_header *lsah;
  2136. u_char type;
  2137. struct in_addr ls_id;
  2138. struct in_addr router_id;
  2139. struct ospf *ospf;
  2140. type = OSPF_AS_EXTERNAL_LSA;
  2141. memset (&ls_id, 0, sizeof (struct in_addr));
  2142. memset (&router_id, 0, sizeof (struct in_addr));
  2143. /* Check OSPF instance. */
  2144. ospf = ospf_lookup ();
  2145. if (ospf == NULL)
  2146. return NULL;
  2147. lsa = ospfExtLsdbLookup (v, name, length, &type, &ls_id, &router_id, exact);
  2148. if (! lsa)
  2149. return NULL;
  2150. lsah = lsa->data;
  2151. /* Return the current value of the variable */
  2152. switch (v->magic)
  2153. {
  2154. case OSPFEXTLSDBTYPE:
  2155. return SNMP_INTEGER (OSPF_AS_EXTERNAL_LSA);
  2156. break;
  2157. case OSPFEXTLSDBLSID:
  2158. return SNMP_IPADDRESS (lsah->id);
  2159. break;
  2160. case OSPFEXTLSDBROUTERID:
  2161. return SNMP_IPADDRESS (lsah->adv_router);
  2162. break;
  2163. case OSPFEXTLSDBSEQUENCE:
  2164. return SNMP_INTEGER (lsah->ls_seqnum);
  2165. break;
  2166. case OSPFEXTLSDBAGE:
  2167. return SNMP_INTEGER (lsah->ls_age);
  2168. break;
  2169. case OSPFEXTLSDBCHECKSUM:
  2170. return SNMP_INTEGER (lsah->checksum);
  2171. break;
  2172. case OSPFEXTLSDBADVERTISEMENT:
  2173. *var_len = ntohs (lsah->length);
  2174. return (u_char *) lsah;
  2175. break;
  2176. default:
  2177. return NULL;
  2178. break;
  2179. }
  2180. return NULL;
  2181. }
  2182. static u_char *
  2183. ospfAreaAggregateEntry (struct variable *v, oid *name, size_t *length,
  2184. int exact, size_t *var_len, WriteMethod **write_method)
  2185. {
  2186. /* Return the current value of the variable */
  2187. switch (v->magic)
  2188. {
  2189. case OSPFAREAAGGREGATEAREAID:
  2190. return (u_char *) NULL;
  2191. break;
  2192. case OSPFAREAAGGREGATELSDBTYPE:
  2193. return (u_char *) NULL;
  2194. break;
  2195. case OSPFAREAAGGREGATENET:
  2196. return (u_char *) NULL;
  2197. break;
  2198. case OSPFAREAAGGREGATEMASK:
  2199. return (u_char *) NULL;
  2200. break;
  2201. case OSPFAREAAGGREGATESTATUS:
  2202. return (u_char *) NULL;
  2203. break;
  2204. case OSPFAREAAGGREGATEEFFECT:
  2205. return (u_char *) NULL;
  2206. break;
  2207. default:
  2208. return NULL;
  2209. break;
  2210. }
  2211. return NULL;
  2212. }
  2213. /* OSPF Traps. */
  2214. #define IFSTATECHANGE 16
  2215. #define VIRTIFSTATECHANGE 1
  2216. #define NBRSTATECHANGE 2
  2217. #define VIRTNBRSTATECHANGE 3
  2218. struct trap_object ospfNbrTrapList[] =
  2219. {
  2220. {ospfGeneralGroup, -2, {1, OSPFROUTERID}},
  2221. {ospfNbrEntry, 3, {10, 1, OSPFNBRIPADDR}},
  2222. {ospfNbrEntry, 3, {10, 1, OSPFNBRRTRID}},
  2223. {ospfNbrEntry, 3, {10, 1, OSPFNBRSTATE}}
  2224. };
  2225. struct trap_object ospfVirtNbrTrapList[] =
  2226. {
  2227. {ospfGeneralGroup, -2, {1, 1}},
  2228. {ospfVirtNbrEntry, 3, {11, 1, OSPFVIRTNBRAREA}},
  2229. {ospfVirtNbrEntry, 3, {11, 1, OSPFVIRTNBRRTRID}},
  2230. {ospfVirtNbrEntry, 3, {11, 1, OSPFVIRTNBRSTATE}}
  2231. };
  2232. struct trap_object ospfIfTrapList[] =
  2233. {
  2234. {ospfGeneralGroup, -2, {1, OSPFROUTERID}},
  2235. {ospfIfEntry, 3, {7, 1, OSPFIFIPADDRESS}},
  2236. {ospfIfEntry, 3, {7, 1, OSPFADDRESSLESSIF}},
  2237. {ospfIfEntry, 3, {7, 1, OSPFIFSTATE}}
  2238. };
  2239. struct trap_object ospfVirtIfTrapList[] =
  2240. {
  2241. {ospfGeneralGroup, -2, {1, OSPFROUTERID}},
  2242. {ospfVirtIfEntry, 3, {9, 1, OSPFVIRTIFAREAID}},
  2243. {ospfVirtIfEntry, 3, {9, 1, OSPFVIRTIFNEIGHBOR}},
  2244. {ospfVirtIfEntry, 3, {9, 1, OSPFVIRTIFSTATE}}
  2245. };
  2246. void
  2247. ospfTrapNbrStateChange (struct ospf_neighbor *on)
  2248. {
  2249. oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
  2250. char msgbuf[16];
  2251. ospf_nbr_state_message(on, msgbuf, sizeof(msgbuf));
  2252. zlog (NULL, LOG_INFO, "ospfTrapNbrStateChange trap sent: %s now %s",
  2253. inet_ntoa(on->address.u.prefix4), msgbuf);
  2254. oid_copy_addr (index, &(on->address.u.prefix4), IN_ADDR_SIZE);
  2255. index[IN_ADDR_SIZE] = 0;
  2256. smux_trap (ospf_oid, sizeof ospf_oid / sizeof (oid),
  2257. index, IN_ADDR_SIZE + 1,
  2258. ospfNbrTrapList,
  2259. sizeof ospfNbrTrapList / sizeof (struct trap_object),
  2260. time (NULL), NBRSTATECHANGE);
  2261. }
  2262. void
  2263. ospfTrapVirtNbrStateChange (struct ospf_neighbor *on)
  2264. {
  2265. oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
  2266. zlog (NULL, LOG_INFO, "ospfTrapVirtNbrStateChange trap sent");
  2267. oid_copy_addr (index, &(on->address.u.prefix4), IN_ADDR_SIZE);
  2268. index[IN_ADDR_SIZE] = 0;
  2269. smux_trap (ospf_oid, sizeof ospf_oid / sizeof (oid),
  2270. index, IN_ADDR_SIZE + 1,
  2271. ospfVirtNbrTrapList,
  2272. sizeof ospfVirtNbrTrapList / sizeof (struct trap_object),
  2273. time (NULL), VIRTNBRSTATECHANGE);
  2274. }
  2275. void
  2276. ospfTrapIfStateChange (struct ospf_interface *oi)
  2277. {
  2278. oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
  2279. zlog (NULL, LOG_INFO, "ospfTrapIfStateChange trap sent: %s now %s",
  2280. inet_ntoa(oi->address->u.prefix4),
  2281. LOOKUP(ospf_ism_state_msg, oi->state));
  2282. oid_copy_addr (index, &(oi->address->u.prefix4), IN_ADDR_SIZE);
  2283. index[IN_ADDR_SIZE] = 0;
  2284. smux_trap (ospf_oid, sizeof ospf_oid / sizeof (oid),
  2285. index, IN_ADDR_SIZE + 1,
  2286. ospfIfTrapList,
  2287. sizeof ospfIfTrapList / sizeof (struct trap_object),
  2288. time (NULL), IFSTATECHANGE);
  2289. }
  2290. void
  2291. ospfTrapVirtIfStateChange (struct ospf_interface *oi)
  2292. {
  2293. oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
  2294. zlog (NULL, LOG_INFO, "ospfTrapVirtIfStateChange trap sent");
  2295. oid_copy_addr (index, &(oi->address->u.prefix4), IN_ADDR_SIZE);
  2296. index[IN_ADDR_SIZE] = 0;
  2297. smux_trap (ospf_oid, sizeof ospf_oid / sizeof (oid),
  2298. index, IN_ADDR_SIZE + 1,
  2299. ospfVirtIfTrapList,
  2300. sizeof ospfVirtIfTrapList / sizeof (struct trap_object),
  2301. time (NULL), VIRTIFSTATECHANGE);
  2302. }
  2303. /* Register OSPF2-MIB. */
  2304. void
  2305. ospf_snmp_init ()
  2306. {
  2307. ospf_snmp_iflist = list_new ();
  2308. ospf_snmp_vl_table = route_table_init ();
  2309. smux_init (om->master);
  2310. REGISTER_MIB("mibII/ospf", ospf_variables, variable, ospf_oid);
  2311. }
  2312. #endif /* HAVE_SNMP */