ospf_snmp.c 71 KB

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