ospf_snmp.c 63 KB

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