ospf_snmp.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740
  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 = {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 > 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 > 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 > 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. unsigned 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 > 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 > 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. unsigned int ifindex;
  1243. struct interface *ifp;
  1244. };
  1245. static struct ospf_snmp_if *
  1246. ospf_snmp_if_new (void)
  1247. {
  1248. return XCALLOC (0, sizeof (struct ospf_snmp_if));
  1249. }
  1250. static void
  1251. ospf_snmp_if_free (struct ospf_snmp_if *osif)
  1252. {
  1253. XFREE (0, 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. unsigned int 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, unsigned int *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, unsigned int *ifindex,
  1365. int ifaddr_next, int 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, unsigned int *ifindex, int exact)
  1442. {
  1443. unsigned int len;
  1444. int ifaddr_next = 0;
  1445. int 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. unsigned int 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, unsigned int *ifindex, int exact)
  1591. {
  1592. unsigned int len;
  1593. int ifaddr_next = 0;
  1594. int 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. unsigned int 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. rn->info = vl_data;
  1698. }
  1699. void
  1700. ospf_snmp_vl_delete (struct ospf_vl_data *vl_data)
  1701. {
  1702. struct prefix_ls lp;
  1703. struct route_node *rn;
  1704. memset (&lp, 0, sizeof (struct prefix_ls));
  1705. lp.family = 0;
  1706. lp.prefixlen = 64;
  1707. lp.id = vl_data->vl_area_id;
  1708. lp.adv_router = vl_data->vl_peer;
  1709. rn = route_node_lookup (ospf_snmp_vl_table, (struct prefix *) &lp);
  1710. if (! rn)
  1711. return;
  1712. rn->info = NULL;
  1713. route_unlock_node (rn);
  1714. route_unlock_node (rn);
  1715. }
  1716. static struct ospf_vl_data *
  1717. ospf_snmp_vl_lookup (struct in_addr *area_id, struct in_addr *neighbor)
  1718. {
  1719. struct prefix_ls lp;
  1720. struct route_node *rn;
  1721. struct ospf_vl_data *vl_data;
  1722. memset (&lp, 0, sizeof (struct prefix_ls));
  1723. lp.family = 0;
  1724. lp.prefixlen = 64;
  1725. lp.id = *area_id;
  1726. lp.adv_router = *neighbor;
  1727. rn = route_node_lookup (ospf_snmp_vl_table, (struct prefix *) &lp);
  1728. if (rn)
  1729. {
  1730. vl_data = rn->info;
  1731. route_unlock_node (rn);
  1732. return vl_data;
  1733. }
  1734. return NULL;
  1735. }
  1736. static struct ospf_vl_data *
  1737. ospf_snmp_vl_lookup_next (struct in_addr *area_id, struct in_addr *neighbor,
  1738. int first)
  1739. {
  1740. struct prefix_ls lp;
  1741. struct route_node *rn;
  1742. struct ospf_vl_data *vl_data;
  1743. memset (&lp, 0, sizeof (struct prefix_ls));
  1744. lp.family = 0;
  1745. lp.prefixlen = 64;
  1746. lp.id = *area_id;
  1747. lp.adv_router = *neighbor;
  1748. if (first)
  1749. rn = route_top (ospf_snmp_vl_table);
  1750. else
  1751. {
  1752. rn = route_node_get (ospf_snmp_vl_table, (struct prefix *) &lp);
  1753. rn = route_next (rn);
  1754. }
  1755. for (; rn; rn = route_next (rn))
  1756. if (rn->info)
  1757. break;
  1758. if (rn && rn->info)
  1759. {
  1760. vl_data = rn->info;
  1761. *area_id = vl_data->vl_area_id;
  1762. *neighbor = vl_data->vl_peer;
  1763. route_unlock_node (rn);
  1764. return vl_data;
  1765. }
  1766. return NULL;
  1767. }
  1768. static struct ospf_vl_data *
  1769. ospfVirtIfLookup (struct variable *v, oid *name, size_t *length,
  1770. struct in_addr *area_id, struct in_addr *neighbor, int exact)
  1771. {
  1772. int first;
  1773. unsigned int len;
  1774. struct ospf_vl_data *vl_data;
  1775. if (exact)
  1776. {
  1777. if (*length != v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE)
  1778. return NULL;
  1779. oid2in_addr (name + v->namelen, IN_ADDR_SIZE, area_id);
  1780. oid2in_addr (name + v->namelen + IN_ADDR_SIZE, IN_ADDR_SIZE, neighbor);
  1781. return ospf_snmp_vl_lookup (area_id, neighbor);
  1782. }
  1783. else
  1784. {
  1785. first = 0;
  1786. len = *length - v->namelen;
  1787. if (len <= 0)
  1788. first = 1;
  1789. if (len > IN_ADDR_SIZE)
  1790. len = IN_ADDR_SIZE;
  1791. oid2in_addr (name + v->namelen, len, area_id);
  1792. len = *length - v->namelen - IN_ADDR_SIZE;
  1793. if (len > IN_ADDR_SIZE)
  1794. len = IN_ADDR_SIZE;
  1795. oid2in_addr (name + v->namelen + IN_ADDR_SIZE, len, neighbor);
  1796. vl_data = ospf_snmp_vl_lookup_next (area_id, neighbor, first);
  1797. if (vl_data)
  1798. {
  1799. *length = v->namelen + IN_ADDR_SIZE + IN_ADDR_SIZE;
  1800. oid_copy_addr (name + v->namelen, area_id, IN_ADDR_SIZE);
  1801. oid_copy_addr (name + v->namelen + IN_ADDR_SIZE, neighbor,
  1802. IN_ADDR_SIZE);
  1803. return vl_data;
  1804. }
  1805. }
  1806. return NULL;
  1807. }
  1808. static u_char *
  1809. ospfVirtIfEntry (struct variable *v, oid *name, size_t *length, int exact,
  1810. size_t *var_len, WriteMethod **write_method)
  1811. {
  1812. struct ospf_vl_data *vl_data;
  1813. struct ospf_interface *oi;
  1814. struct in_addr area_id;
  1815. struct in_addr neighbor;
  1816. if (smux_header_table(v, name, length, exact, var_len, write_method)
  1817. == MATCH_FAILED)
  1818. return NULL;
  1819. memset (&area_id, 0, sizeof (struct in_addr));
  1820. memset (&neighbor, 0, sizeof (struct in_addr));
  1821. vl_data = ospfVirtIfLookup (v, name, length, &area_id, &neighbor, exact);
  1822. if (! vl_data)
  1823. return NULL;
  1824. oi = vl_data->vl_oi;
  1825. if (! oi)
  1826. return NULL;
  1827. /* Return the current value of the variable */
  1828. switch (v->magic)
  1829. {
  1830. case OSPFVIRTIFAREAID:
  1831. return SNMP_IPADDRESS (area_id);
  1832. break;
  1833. case OSPFVIRTIFNEIGHBOR:
  1834. return SNMP_IPADDRESS (neighbor);
  1835. break;
  1836. case OSPFVIRTIFTRANSITDELAY:
  1837. return SNMP_INTEGER (OSPF_IF_PARAM (oi, transmit_delay));
  1838. break;
  1839. case OSPFVIRTIFRETRANSINTERVAL:
  1840. return SNMP_INTEGER (OSPF_IF_PARAM (oi, retransmit_interval));
  1841. break;
  1842. case OSPFVIRTIFHELLOINTERVAL:
  1843. return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_hello));
  1844. break;
  1845. case OSPFVIRTIFRTRDEADINTERVAL:
  1846. return SNMP_INTEGER (OSPF_IF_PARAM (oi, v_wait));
  1847. break;
  1848. case OSPFVIRTIFSTATE:
  1849. return SNMP_INTEGER (oi->state);
  1850. break;
  1851. case OSPFVIRTIFEVENTS:
  1852. return SNMP_INTEGER (oi->state_change);
  1853. break;
  1854. case OSPFVIRTIFAUTHKEY:
  1855. *var_len = 0;
  1856. return (u_char *) OSPF_IF_PARAM (oi, auth_simple);
  1857. break;
  1858. case OSPFVIRTIFSTATUS:
  1859. return SNMP_INTEGER (SNMP_VALID);
  1860. break;
  1861. case OSPFVIRTIFAUTHTYPE:
  1862. if (oi->area)
  1863. return SNMP_INTEGER (oi->area->auth_type);
  1864. else
  1865. return SNMP_INTEGER (0);
  1866. break;
  1867. default:
  1868. return NULL;
  1869. break;
  1870. }
  1871. return NULL;
  1872. }
  1873. static struct ospf_neighbor *
  1874. ospf_snmp_nbr_lookup (struct ospf *ospf, struct in_addr *nbr_addr,
  1875. unsigned int *ifindex)
  1876. {
  1877. struct listnode *node, *nnode;
  1878. struct ospf_interface *oi;
  1879. struct ospf_neighbor *nbr;
  1880. struct route_node *rn;
  1881. for (ALL_LIST_ELEMENTS (ospf->oiflist, node, nnode, oi))
  1882. {
  1883. for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
  1884. if ((nbr = rn->info) != NULL
  1885. && nbr != oi->nbr_self
  1886. /* If EXACT match is needed, provide ALL entry found
  1887. && nbr->state != NSM_Down
  1888. */
  1889. && nbr->src.s_addr != 0)
  1890. {
  1891. if (IPV4_ADDR_SAME (&nbr->src, nbr_addr))
  1892. {
  1893. route_unlock_node (rn);
  1894. return nbr;
  1895. }
  1896. }
  1897. }
  1898. return NULL;
  1899. }
  1900. static struct ospf_neighbor *
  1901. ospf_snmp_nbr_lookup_next (struct in_addr *nbr_addr, unsigned int *ifindex,
  1902. int first)
  1903. {
  1904. struct listnode *nn;
  1905. struct ospf_interface *oi;
  1906. struct ospf_neighbor *nbr;
  1907. struct route_node *rn;
  1908. struct ospf_neighbor *min = NULL;
  1909. struct ospf *ospf = ospf;
  1910. ospf = ospf_lookup ();
  1911. for (ALL_LIST_ELEMENTS_RO (ospf->oiflist, nn, oi))
  1912. {
  1913. for (rn = route_top (oi->nbrs); rn; rn = route_next (rn))
  1914. if ((nbr = rn->info) != NULL
  1915. && nbr != oi->nbr_self
  1916. && nbr->state != NSM_Down
  1917. && nbr->src.s_addr != 0)
  1918. {
  1919. if (first)
  1920. {
  1921. if (! min)
  1922. min = nbr;
  1923. else if (ntohl (nbr->src.s_addr) < ntohl (min->src.s_addr))
  1924. min = nbr;
  1925. }
  1926. else if (ntohl (nbr->src.s_addr) > ntohl (nbr_addr->s_addr))
  1927. {
  1928. if (! min)
  1929. min = nbr;
  1930. else if (ntohl (nbr->src.s_addr) < ntohl (min->src.s_addr))
  1931. min = nbr;
  1932. }
  1933. }
  1934. }
  1935. if (min)
  1936. {
  1937. *nbr_addr = min->src;
  1938. *ifindex = 0;
  1939. return min;
  1940. }
  1941. return NULL;
  1942. }
  1943. static struct ospf_neighbor *
  1944. ospfNbrLookup (struct variable *v, oid *name, size_t *length,
  1945. struct in_addr *nbr_addr, unsigned int *ifindex, int exact)
  1946. {
  1947. unsigned int len;
  1948. int first;
  1949. struct ospf_neighbor *nbr;
  1950. struct ospf *ospf;
  1951. ospf = ospf_lookup ();
  1952. if (! ospf)
  1953. return NULL;
  1954. if (exact)
  1955. {
  1956. if (*length != v->namelen + IN_ADDR_SIZE + 1)
  1957. return NULL;
  1958. oid2in_addr (name + v->namelen, IN_ADDR_SIZE, nbr_addr);
  1959. *ifindex = name[v->namelen + IN_ADDR_SIZE];
  1960. return ospf_snmp_nbr_lookup (ospf, nbr_addr, ifindex);
  1961. }
  1962. else
  1963. {
  1964. first = 0;
  1965. len = *length - v->namelen;
  1966. if (len <= 0)
  1967. first = 1;
  1968. if (len > IN_ADDR_SIZE)
  1969. len = IN_ADDR_SIZE;
  1970. oid2in_addr (name + v->namelen, len, nbr_addr);
  1971. len = *length - v->namelen - IN_ADDR_SIZE;
  1972. if (len >= 1)
  1973. *ifindex = name[v->namelen + IN_ADDR_SIZE];
  1974. nbr = ospf_snmp_nbr_lookup_next (nbr_addr, ifindex, first);
  1975. if (nbr)
  1976. {
  1977. *length = v->namelen + IN_ADDR_SIZE + 1;
  1978. oid_copy_addr (name + v->namelen, nbr_addr, IN_ADDR_SIZE);
  1979. name[v->namelen + IN_ADDR_SIZE] = *ifindex;
  1980. return nbr;
  1981. }
  1982. }
  1983. return NULL;
  1984. }
  1985. /* map internal quagga neighbor states to official MIB values:
  1986. ospfNbrState OBJECT-TYPE
  1987. SYNTAX INTEGER {
  1988. down (1),
  1989. attempt (2),
  1990. init (3),
  1991. twoWay (4),
  1992. exchangeStart (5),
  1993. exchange (6),
  1994. loading (7),
  1995. full (8)
  1996. }
  1997. */
  1998. static int32_t
  1999. ospf_snmp_neighbor_state(u_char nst)
  2000. {
  2001. switch (nst)
  2002. {
  2003. case NSM_Attempt:
  2004. return 2;
  2005. case NSM_Init:
  2006. return 3;
  2007. case NSM_TwoWay:
  2008. return 4;
  2009. case NSM_ExStart:
  2010. return 5;
  2011. case NSM_Exchange:
  2012. return 6;
  2013. case NSM_Loading:
  2014. return 7;
  2015. case NSM_Full:
  2016. return 8;
  2017. default:
  2018. return 1; /* down */
  2019. }
  2020. }
  2021. static u_char *
  2022. ospfNbrEntry (struct variable *v, oid *name, size_t *length, int exact,
  2023. size_t *var_len, WriteMethod **write_method)
  2024. {
  2025. struct in_addr nbr_addr;
  2026. unsigned int ifindex;
  2027. struct ospf_neighbor *nbr;
  2028. struct ospf_interface *oi;
  2029. if (smux_header_table(v, name, length, exact, var_len, write_method)
  2030. == MATCH_FAILED)
  2031. return NULL;
  2032. memset (&nbr_addr, 0, sizeof (struct in_addr));
  2033. ifindex = 0;
  2034. nbr = ospfNbrLookup (v, name, length, &nbr_addr, &ifindex, exact);
  2035. if (! nbr)
  2036. return NULL;
  2037. oi = nbr->oi;
  2038. if (! oi)
  2039. return NULL;
  2040. /* Return the current value of the variable */
  2041. switch (v->magic)
  2042. {
  2043. case OSPFNBRIPADDR:
  2044. return SNMP_IPADDRESS (nbr_addr);
  2045. break;
  2046. case OSPFNBRADDRESSLESSINDEX:
  2047. return SNMP_INTEGER (ifindex);
  2048. break;
  2049. case OSPFNBRRTRID:
  2050. return SNMP_IPADDRESS (nbr->router_id);
  2051. break;
  2052. case OSPFNBROPTIONS:
  2053. return SNMP_INTEGER (oi->nbr_self->options);
  2054. break;
  2055. case OSPFNBRPRIORITY:
  2056. return SNMP_INTEGER (nbr->priority);
  2057. break;
  2058. case OSPFNBRSTATE:
  2059. return SNMP_INTEGER (ospf_snmp_neighbor_state(nbr->state));
  2060. break;
  2061. case OSPFNBREVENTS:
  2062. return SNMP_INTEGER (nbr->state_change);
  2063. break;
  2064. case OSPFNBRLSRETRANSQLEN:
  2065. return SNMP_INTEGER (ospf_ls_retransmit_count (nbr));
  2066. break;
  2067. case OSPFNBMANBRSTATUS:
  2068. return SNMP_INTEGER (SNMP_VALID);
  2069. break;
  2070. case OSPFNBMANBRPERMANENCE:
  2071. return SNMP_INTEGER (2);
  2072. break;
  2073. case OSPFNBRHELLOSUPPRESSED:
  2074. return SNMP_INTEGER (SNMP_FALSE);
  2075. break;
  2076. default:
  2077. return NULL;
  2078. break;
  2079. }
  2080. return NULL;
  2081. }
  2082. static u_char *
  2083. ospfVirtNbrEntry (struct variable *v, oid *name, size_t *length, int exact,
  2084. size_t *var_len, WriteMethod **write_method)
  2085. {
  2086. struct ospf_vl_data *vl_data;
  2087. struct in_addr area_id;
  2088. struct in_addr neighbor;
  2089. struct ospf *ospf;
  2090. if (smux_header_table(v, name, length, exact, var_len, write_method)
  2091. == MATCH_FAILED)
  2092. return NULL;
  2093. memset (&area_id, 0, sizeof (struct in_addr));
  2094. memset (&neighbor, 0, sizeof (struct in_addr));
  2095. /* Check OSPF instance. */
  2096. ospf = ospf_lookup ();
  2097. if (ospf == NULL)
  2098. return NULL;
  2099. vl_data = ospfVirtIfLookup (v, name, length, &area_id, &neighbor, exact);
  2100. if (! vl_data)
  2101. return NULL;
  2102. /* Return the current value of the variable */
  2103. switch (v->magic)
  2104. {
  2105. case OSPFVIRTNBRAREA:
  2106. return (u_char *) NULL;
  2107. break;
  2108. case OSPFVIRTNBRRTRID:
  2109. return (u_char *) NULL;
  2110. break;
  2111. case OSPFVIRTNBRIPADDR:
  2112. return (u_char *) NULL;
  2113. break;
  2114. case OSPFVIRTNBROPTIONS:
  2115. return (u_char *) NULL;
  2116. break;
  2117. case OSPFVIRTNBRSTATE:
  2118. return (u_char *) NULL;
  2119. break;
  2120. case OSPFVIRTNBREVENTS:
  2121. return (u_char *) NULL;
  2122. break;
  2123. case OSPFVIRTNBRLSRETRANSQLEN:
  2124. return (u_char *) NULL;
  2125. break;
  2126. case OSPFVIRTNBRHELLOSUPPRESSED:
  2127. return (u_char *) NULL;
  2128. break;
  2129. default:
  2130. return NULL;
  2131. break;
  2132. }
  2133. return NULL;
  2134. }
  2135. static struct ospf_lsa *
  2136. ospfExtLsdbLookup (struct variable *v, oid *name, size_t *length, u_char *type,
  2137. struct in_addr *ls_id, struct in_addr *router_id, int exact)
  2138. {
  2139. int first;
  2140. oid *offset;
  2141. int offsetlen;
  2142. u_char lsa_type;
  2143. unsigned int len;
  2144. struct ospf_lsa *lsa;
  2145. struct ospf *ospf;
  2146. ospf = ospf_lookup ();
  2147. if (exact)
  2148. {
  2149. if (*length != v->namelen + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE)
  2150. return NULL;
  2151. offset = name + v->namelen;
  2152. /* Make it sure given value match to type. */
  2153. lsa_type = *offset;
  2154. offset++;
  2155. if (lsa_type != *type)
  2156. return NULL;
  2157. /* LS ID. */
  2158. oid2in_addr (offset, IN_ADDR_SIZE, ls_id);
  2159. offset += IN_ADDR_SIZE;
  2160. /* Router ID. */
  2161. oid2in_addr (offset, IN_ADDR_SIZE, router_id);
  2162. return ospf_lsdb_lookup_by_id (ospf->lsdb, *type, *ls_id, *router_id);
  2163. }
  2164. else
  2165. {
  2166. /* Get variable length. */
  2167. first = 0;
  2168. offset = name + v->namelen;
  2169. offsetlen = *length - v->namelen;
  2170. /* LSA type value. */
  2171. lsa_type = *offset;
  2172. offset++;
  2173. offsetlen--;
  2174. if (offsetlen <= 0 || lsa_type < OSPF_AS_EXTERNAL_LSA)
  2175. first = 1;
  2176. /* LS ID. */
  2177. len = offsetlen;
  2178. if (len > IN_ADDR_SIZE)
  2179. len = IN_ADDR_SIZE;
  2180. oid2in_addr (offset, len, ls_id);
  2181. offset += IN_ADDR_SIZE;
  2182. offsetlen -= IN_ADDR_SIZE;
  2183. /* Router ID. */
  2184. len = offsetlen;
  2185. if (len > IN_ADDR_SIZE)
  2186. len = IN_ADDR_SIZE;
  2187. oid2in_addr (offset, len, router_id);
  2188. lsa = ospf_lsdb_lookup_by_id_next (ospf->lsdb, *type, *ls_id,
  2189. *router_id, first);
  2190. if (lsa)
  2191. {
  2192. /* Fill in length. */
  2193. *length = v->namelen + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE;
  2194. /* Fill in value. */
  2195. offset = name + v->namelen;
  2196. *offset = OSPF_AS_EXTERNAL_LSA;
  2197. offset++;
  2198. oid_copy_addr (offset, &lsa->data->id, IN_ADDR_SIZE);
  2199. offset += IN_ADDR_SIZE;
  2200. oid_copy_addr (offset, &lsa->data->adv_router, IN_ADDR_SIZE);
  2201. return lsa;
  2202. }
  2203. }
  2204. return NULL;
  2205. }
  2206. static u_char *
  2207. ospfExtLsdbEntry (struct variable *v, oid *name, size_t *length, int exact,
  2208. size_t *var_len, WriteMethod **write_method)
  2209. {
  2210. struct ospf_lsa *lsa;
  2211. struct lsa_header *lsah;
  2212. u_char type;
  2213. struct in_addr ls_id;
  2214. struct in_addr router_id;
  2215. struct ospf *ospf;
  2216. if (smux_header_table(v, name, length, exact, var_len, write_method)
  2217. == MATCH_FAILED)
  2218. return NULL;
  2219. type = OSPF_AS_EXTERNAL_LSA;
  2220. memset (&ls_id, 0, sizeof (struct in_addr));
  2221. memset (&router_id, 0, sizeof (struct in_addr));
  2222. /* Check OSPF instance. */
  2223. ospf = ospf_lookup ();
  2224. if (ospf == NULL)
  2225. return NULL;
  2226. lsa = ospfExtLsdbLookup (v, name, length, &type, &ls_id, &router_id, exact);
  2227. if (! lsa)
  2228. return NULL;
  2229. lsah = lsa->data;
  2230. /* Return the current value of the variable */
  2231. switch (v->magic)
  2232. {
  2233. case OSPFEXTLSDBTYPE:
  2234. return SNMP_INTEGER (OSPF_AS_EXTERNAL_LSA);
  2235. break;
  2236. case OSPFEXTLSDBLSID:
  2237. return SNMP_IPADDRESS (lsah->id);
  2238. break;
  2239. case OSPFEXTLSDBROUTERID:
  2240. return SNMP_IPADDRESS (lsah->adv_router);
  2241. break;
  2242. case OSPFEXTLSDBSEQUENCE:
  2243. return SNMP_INTEGER (lsah->ls_seqnum);
  2244. break;
  2245. case OSPFEXTLSDBAGE:
  2246. return SNMP_INTEGER (lsah->ls_age);
  2247. break;
  2248. case OSPFEXTLSDBCHECKSUM:
  2249. return SNMP_INTEGER (lsah->checksum);
  2250. break;
  2251. case OSPFEXTLSDBADVERTISEMENT:
  2252. *var_len = ntohs (lsah->length);
  2253. return (u_char *) lsah;
  2254. break;
  2255. default:
  2256. return NULL;
  2257. break;
  2258. }
  2259. return NULL;
  2260. }
  2261. static u_char *
  2262. ospfAreaAggregateEntry (struct variable *v, oid *name, size_t *length,
  2263. int exact, size_t *var_len, WriteMethod **write_method)
  2264. {
  2265. if (smux_header_table(v, name, length, exact, var_len, write_method)
  2266. == MATCH_FAILED)
  2267. return NULL;
  2268. /* Return the current value of the variable */
  2269. switch (v->magic)
  2270. {
  2271. case OSPFAREAAGGREGATEAREAID:
  2272. return (u_char *) NULL;
  2273. break;
  2274. case OSPFAREAAGGREGATELSDBTYPE:
  2275. return (u_char *) NULL;
  2276. break;
  2277. case OSPFAREAAGGREGATENET:
  2278. return (u_char *) NULL;
  2279. break;
  2280. case OSPFAREAAGGREGATEMASK:
  2281. return (u_char *) NULL;
  2282. break;
  2283. case OSPFAREAAGGREGATESTATUS:
  2284. return (u_char *) NULL;
  2285. break;
  2286. case OSPFAREAAGGREGATEEFFECT:
  2287. return (u_char *) NULL;
  2288. break;
  2289. default:
  2290. return NULL;
  2291. break;
  2292. }
  2293. return NULL;
  2294. }
  2295. /* OSPF Traps. */
  2296. #define IFSTATECHANGE 16
  2297. #define VIRTIFSTATECHANGE 1
  2298. #define NBRSTATECHANGE 2
  2299. #define VIRTNBRSTATECHANGE 3
  2300. struct trap_object ospfNbrTrapList[] =
  2301. {
  2302. {-2, {1, OSPFROUTERID}},
  2303. {3, {10, 1, OSPFNBRIPADDR}},
  2304. {3, {10, 1, OSPFNBRRTRID}},
  2305. {3, {10, 1, OSPFNBRSTATE}}
  2306. };
  2307. struct trap_object ospfVirtNbrTrapList[] =
  2308. {
  2309. {-2, {1, 1}},
  2310. {3, {11, 1, OSPFVIRTNBRAREA}},
  2311. {3, {11, 1, OSPFVIRTNBRRTRID}},
  2312. {3, {11, 1, OSPFVIRTNBRSTATE}}
  2313. };
  2314. struct trap_object ospfIfTrapList[] =
  2315. {
  2316. {-2, {1, OSPFROUTERID}},
  2317. {3, {7, 1, OSPFIFIPADDRESS}},
  2318. {3, {7, 1, OSPFADDRESSLESSIF}},
  2319. {3, {7, 1, OSPFIFSTATE}}
  2320. };
  2321. struct trap_object ospfVirtIfTrapList[] =
  2322. {
  2323. {-2, {1, OSPFROUTERID}},
  2324. {3, {9, 1, OSPFVIRTIFAREAID}},
  2325. {3, {9, 1, OSPFVIRTIFNEIGHBOR}},
  2326. {3, {9, 1, OSPFVIRTIFSTATE}}
  2327. };
  2328. void
  2329. ospfTrapNbrStateChange (struct ospf_neighbor *on)
  2330. {
  2331. oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
  2332. char msgbuf[16];
  2333. ospf_nbr_state_message(on, msgbuf, sizeof(msgbuf));
  2334. zlog (NULL, LOG_INFO, "ospfTrapNbrStateChange trap sent: %s now %s",
  2335. inet_ntoa(on->address.u.prefix4), msgbuf);
  2336. oid_copy_addr (index, &(on->address.u.prefix4), IN_ADDR_SIZE);
  2337. index[IN_ADDR_SIZE] = 0;
  2338. smux_trap (ospf_variables, sizeof ospf_variables / sizeof (struct variable),
  2339. ospf_trap_oid, sizeof ospf_trap_oid / sizeof (oid),
  2340. ospf_oid, sizeof ospf_oid / sizeof (oid),
  2341. index, IN_ADDR_SIZE + 1,
  2342. ospfNbrTrapList,
  2343. sizeof ospfNbrTrapList / sizeof (struct trap_object),
  2344. NBRSTATECHANGE);
  2345. }
  2346. void
  2347. ospfTrapVirtNbrStateChange (struct ospf_neighbor *on)
  2348. {
  2349. oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
  2350. zlog (NULL, LOG_INFO, "ospfTrapVirtNbrStateChange trap sent");
  2351. oid_copy_addr (index, &(on->address.u.prefix4), IN_ADDR_SIZE);
  2352. index[IN_ADDR_SIZE] = 0;
  2353. smux_trap (ospf_variables, sizeof ospf_variables / sizeof (struct variable),
  2354. ospf_trap_oid, sizeof ospf_trap_oid / sizeof (oid),
  2355. ospf_oid, sizeof ospf_oid / sizeof (oid),
  2356. index, IN_ADDR_SIZE + 1,
  2357. ospfVirtNbrTrapList,
  2358. sizeof ospfVirtNbrTrapList / sizeof (struct trap_object),
  2359. VIRTNBRSTATECHANGE);
  2360. }
  2361. void
  2362. ospfTrapIfStateChange (struct ospf_interface *oi)
  2363. {
  2364. oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
  2365. zlog (NULL, LOG_INFO, "ospfTrapIfStateChange trap sent: %s now %s",
  2366. inet_ntoa(oi->address->u.prefix4),
  2367. LOOKUP(ospf_ism_state_msg, oi->state));
  2368. oid_copy_addr (index, &(oi->address->u.prefix4), IN_ADDR_SIZE);
  2369. index[IN_ADDR_SIZE] = 0;
  2370. smux_trap (ospf_variables, sizeof ospf_variables / sizeof (struct variable),
  2371. ospf_trap_oid, sizeof ospf_trap_oid / sizeof (oid),
  2372. ospf_oid, sizeof ospf_oid / sizeof (oid),
  2373. index, IN_ADDR_SIZE + 1,
  2374. ospfIfTrapList,
  2375. sizeof ospfIfTrapList / sizeof (struct trap_object),
  2376. IFSTATECHANGE);
  2377. }
  2378. void
  2379. ospfTrapVirtIfStateChange (struct ospf_interface *oi)
  2380. {
  2381. oid index[sizeof (oid) * (IN_ADDR_SIZE + 1)];
  2382. zlog (NULL, LOG_INFO, "ospfTrapVirtIfStateChange trap sent");
  2383. oid_copy_addr (index, &(oi->address->u.prefix4), IN_ADDR_SIZE);
  2384. index[IN_ADDR_SIZE] = 0;
  2385. smux_trap (ospf_variables, sizeof ospf_variables / sizeof (struct variable),
  2386. ospf_trap_oid, sizeof ospf_trap_oid / sizeof (oid),
  2387. ospf_oid, sizeof ospf_oid / sizeof (oid),
  2388. index, IN_ADDR_SIZE + 1,
  2389. ospfVirtIfTrapList,
  2390. sizeof ospfVirtIfTrapList / sizeof (struct trap_object),
  2391. VIRTIFSTATECHANGE);
  2392. }
  2393. /* Register OSPF2-MIB. */
  2394. void
  2395. ospf_snmp_init ()
  2396. {
  2397. ospf_snmp_iflist = list_new ();
  2398. ospf_snmp_vl_table = route_table_init ();
  2399. smux_init (om->master);
  2400. REGISTER_MIB("mibII/ospf", ospf_variables, variable, ospf_oid);
  2401. }
  2402. #endif /* HAVE_SNMP */