ospf_snmp.c 70 KB

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