ospf6_snmp.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183
  1. /* OSPFv3 SNMP support
  2. * Copyright (C) 2004 Yasuhiro Ohara
  3. *
  4. * This file is part of GNU Zebra.
  5. *
  6. * GNU Zebra is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License as published by the
  8. * Free Software Foundation; either version 2, or (at your option) any
  9. * later version.
  10. *
  11. * GNU Zebra is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GNU Zebra; see the file COPYING. If not, write to the
  18. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. */
  21. #include <zebra.h>
  22. #ifdef HAVE_SNMP
  23. #include <net-snmp/net-snmp-config.h>
  24. #include <net-snmp/net-snmp-includes.h>
  25. #include "log.h"
  26. #include "vty.h"
  27. #include "linklist.h"
  28. #include "smux.h"
  29. #include "ospf6_proto.h"
  30. #include "ospf6_lsa.h"
  31. #include "ospf6_lsdb.h"
  32. #include "ospf6_route.h"
  33. #include "ospf6_top.h"
  34. #include "ospf6_area.h"
  35. #include "ospf6_interface.h"
  36. #include "ospf6_message.h"
  37. #include "ospf6_neighbor.h"
  38. #include "ospf6_abr.h"
  39. #include "ospf6_asbr.h"
  40. #include "ospf6d.h"
  41. #include "ospf6_snmp.h"
  42. /* OSPFv3-MIB */
  43. #define OSPFv3MIB 1,3,6,1,2,1,191
  44. /* OSPFv3 MIB General Group values. */
  45. #define OSPFv3ROUTERID 1
  46. #define OSPFv3ADMINSTAT 2
  47. #define OSPFv3VERSIONNUMBER 3
  48. #define OSPFv3AREABDRRTRSTATUS 4
  49. #define OSPFv3ASBDRRTRSTATUS 5
  50. #define OSPFv3ASSCOPELSACOUNT 6
  51. #define OSPFv3ASSCOPELSACHECKSUMSUM 7
  52. #define OSPFv3ORIGINATENEWLSAS 8
  53. #define OSPFv3RXNEWLSAS 9
  54. #define OSPFv3EXTLSACOUNT 10
  55. #define OSPFv3EXTAREALSDBLIMIT 11
  56. #define OSPFv3EXITOVERFLOWINTERVAL 12
  57. #define OSPFv3DEMANDEXTENSIONS 13
  58. #define OSPFv3REFERENCEBANDWIDTH 14
  59. #define OSPFv3RESTARTSUPPORT 15
  60. #define OSPFv3RESTARTINTERVAL 16
  61. #define OSPFv3RESTARTSTRICTLSACHECKING 17
  62. #define OSPFv3RESTARTSTATUS 18
  63. #define OSPFv3RESTARTAGE 19
  64. #define OSPFv3RESTARTEXITREASON 20
  65. #define OSPFv3NOTIFICATIONENABLE 21
  66. #define OSPFv3STUBROUTERSUPPORT 22
  67. #define OSPFv3STUBROUTERADVERTISEMENT 23
  68. #define OSPFv3DISCONTINUITYTIME 24
  69. #define OSPFv3RESTARTTIME 25
  70. /* OSPFv3 MIB Area Table values: ospfv3AreaTable */
  71. #define OSPFv3IMPORTASEXTERN 2
  72. #define OSPFv3AREASPFRUNS 3
  73. #define OSPFv3AREABDRRTRCOUNT 4
  74. #define OSPFv3AREAASBDRRTRCOUNT 5
  75. #define OSPFv3AREASCOPELSACOUNT 6
  76. #define OSPFv3AREASCOPELSACKSUMSUM 7
  77. #define OSPFv3AREASUMMARY 8
  78. #define OSPFv3AREAROWSTATUS 9
  79. #define OSPFv3AREASTUBMETRIC 10
  80. #define OSPFv3AREANSSATRANSLATORROLE 11
  81. #define OSPFv3AREANSSATRANSLATORSTATE 12
  82. #define OSPFv3AREANSSATRANSLATORSTABINTERVAL 13
  83. #define OSPFv3AREANSSATRANSLATOREVENTS 14
  84. #define OSPFv3AREASTUBMETRICTYPE 15
  85. #define OSPFv3AREATEENABLED 16
  86. /* OSPFv3 MIB * Lsdb Table values: ospfv3*LsdbTable */
  87. #define OSPFv3WWLSDBSEQUENCE 1
  88. #define OSPFv3WWLSDBAGE 2
  89. #define OSPFv3WWLSDBCHECKSUM 3
  90. #define OSPFv3WWLSDBADVERTISEMENT 4
  91. #define OSPFv3WWLSDBTYPEKNOWN 5
  92. /* Three first bits are to identify column */
  93. #define OSPFv3WWCOLUMN 0x7
  94. /* Then we use other bits to identify table */
  95. #define OSPFv3WWASTABLE (1 << 3)
  96. #define OSPFv3WWAREATABLE (1 << 4)
  97. #define OSPFv3WWLINKTABLE (1 << 5)
  98. #define OSPFv3WWVIRTLINKTABLE (1 << 6)
  99. /* OSPFv3 MIB Host Table values: ospfv3HostTable */
  100. #define OSPFv3HOSTMETRIC 3
  101. #define OSPFv3HOSTROWSTATUS 4
  102. #define OSPFv3HOSTAREAID 5
  103. /* OSPFv3 MIB Interface Table values: ospfv3IfTable */
  104. #define OSPFv3IFAREAID 3
  105. #define OSPFv3IFTYPE 4
  106. #define OSPFv3IFADMINSTATUS 5
  107. #define OSPFv3IFRTRPRIORITY 6
  108. #define OSPFv3IFTRANSITDELAY 7
  109. #define OSPFv3IFRETRANSINTERVAL 8
  110. #define OSPFv3IFHELLOINTERVAL 9
  111. #define OSPFv3IFRTRDEADINTERVAL 10
  112. #define OSPFv3IFPOLLINTERVAL 11
  113. #define OSPFv3IFSTATE 12
  114. #define OSPFv3IFDESIGNATEDROUTER 13
  115. #define OSPFv3IFBACKUPDESIGNATEDROUTER 14
  116. #define OSPFv3IFEVENTS 15
  117. #define OSPFv3IFROWSTATUS 16
  118. #define OSPFv3IFDEMAND 17
  119. #define OSPFv3IFMETRICVALUE 18
  120. #define OSPFv3IFLINKSCOPELSACOUNT 19
  121. #define OSPFv3IFLINKLSACKSUMSUM 20
  122. #define OSPFv3IFDEMANDNBRPROBE 21
  123. #define OSPFv3IFDEMANDNBRPROBERETRANSLIMIT 22
  124. #define OSPFv3IFDEMANDNBRPROBEINTERVAL 23
  125. #define OSPFv3IFTEDISABLED 24
  126. #define OSPFv3IFLINKLSASUPPRESSION 25
  127. /* OSPFv3 MIB Virtual Interface Table values: ospfv3VirtIfTable */
  128. #define OSPFv3VIRTIFINDEX 3
  129. #define OSPFv3VIRTIFINSTID 4
  130. #define OSPFv3VIRTIFTRANSITDELAY 5
  131. #define OSPFv3VIRTIFRETRANSINTERVAL 6
  132. #define OSPFv3VIRTIFHELLOINTERVAL 7
  133. #define OSPFv3VIRTIFRTRDEADINTERVAL 8
  134. #define OSPFv3VIRTIFSTATE 9
  135. #define OSPFv3VIRTIFEVENTS 10
  136. #define OSPFv3VIRTIFROWSTATUS 11
  137. #define OSPFv3VIRTIFLINKSCOPELSACOUNT 12
  138. #define OSPFv3VIRTIFLINKLSACKSUMSUM 13
  139. /* OSPFv3 MIB Neighbors Table values: ospfv3NbrTable */
  140. #define OSPFv3NBRADDRESSTYPE 4
  141. #define OSPFv3NBRADDRESS 5
  142. #define OSPFv3NBROPTIONS 6
  143. #define OSPFv3NBRPRIORITY 7
  144. #define OSPFv3NBRSTATE 8
  145. #define OSPFv3NBREVENTS 9
  146. #define OSPFv3NBRLSRETRANSQLEN 10
  147. #define OSPFv3NBRHELLOSUPPRESSED 11
  148. #define OSPFv3NBRIFID 12
  149. #define OSPFv3NBRRESTARTHELPERSTATUS 13
  150. #define OSPFv3NBRRESTARTHELPERAGE 14
  151. #define OSPFv3NBRRESTARTHELPEREXITREASON 15
  152. /* OSPFv3 MIB Configured Neighbors Table values: ospfv3CfgNbrTable */
  153. #define OSPFv3CFGNBRPRIORITY 5
  154. #define OSPFv3CFGNBRROWSTATUS 6
  155. /* OSPFv3 MIB Virtual Neighbors Table values: ospfv3VirtNbrTable */
  156. #define OSPFv3VIRTNBRIFINDEX 3
  157. #define OSPFv3VIRTNBRIFINSTID 4
  158. #define OSPFv3VIRTNBRADDRESSTYPE 5
  159. #define OSPFv3VIRTNBRADDRESS 6
  160. #define OSPFv3VIRTNBROPTIONS 7
  161. #define OSPFv3VIRTNBRSTATE 8
  162. #define OSPFv3VIRTNBREVENTS 9
  163. #define OSPFv3VIRTNBRLSRETRANSQLEN 10
  164. #define OSPFv3VIRTNBRHELLOSUPPRESSED 11
  165. #define OSPFv3VIRTNBRIFID 12
  166. #define OSPFv3VIRTNBRRESTARTHELPERSTATUS 13
  167. #define OSPFv3VIRTNBRRESTARTHELPERAGE 14
  168. #define OSPFv3VIRTNBRRESTARTHELPEREXITREASON 15
  169. /* OSPFv3 MIB Area Aggregate Table values: ospfv3AreaAggregateTable */
  170. #define OSPFv3AREAAGGREGATEROWSTATUS 6
  171. #define OSPFv3AREAAGGREGATEEFFECT 7
  172. #define OSPFv3AREAAGGREGATEROUTETAG 8
  173. /* SYNTAX Status from OSPF-MIB. */
  174. #define OSPF_STATUS_ENABLED 1
  175. #define OSPF_STATUS_DISABLED 2
  176. /* SNMP value hack. */
  177. #define COUNTER ASN_COUNTER
  178. #define INTEGER ASN_INTEGER
  179. #define GAUGE ASN_GAUGE
  180. #define UNSIGNED ASN_UNSIGNED
  181. #define TIMETICKS ASN_TIMETICKS
  182. #define IPADDRESS ASN_IPADDRESS
  183. #define STRING ASN_OCTET_STR
  184. /* For return values e.g. SNMP_INTEGER macro */
  185. SNMP_LOCAL_VARIABLES
  186. /* OSPFv3-MIB instances. */
  187. oid ospfv3_oid [] = { OSPFv3MIB };
  188. oid ospfv3_trap_oid [] = { OSPFv3MIB, 0 };
  189. /* Hook functions. */
  190. static u_char *ospfv3GeneralGroup (struct variable *, oid *, size_t *,
  191. int, size_t *, WriteMethod **);
  192. static u_char *ospfv3AreaEntry (struct variable *, oid *, size_t *,
  193. int, size_t *, WriteMethod **);
  194. static u_char *ospfv3WwLsdbEntry (struct variable *, oid *, size_t *,
  195. int, size_t *, WriteMethod **);
  196. static u_char *ospfv3NbrEntry (struct variable *, oid *, size_t *,
  197. int, size_t *, WriteMethod **);
  198. static u_char *ospfv3IfEntry (struct variable *, oid *, size_t *,
  199. int, size_t *, WriteMethod **);
  200. struct variable ospfv3_variables[] =
  201. {
  202. /* OSPF general variables */
  203. {OSPFv3ROUTERID, UNSIGNED, RWRITE, ospfv3GeneralGroup,
  204. 3, {1, 1, 1}},
  205. {OSPFv3ADMINSTAT, INTEGER, RWRITE, ospfv3GeneralGroup,
  206. 3, {1, 1, 2}},
  207. {OSPFv3VERSIONNUMBER, INTEGER, RONLY, ospfv3GeneralGroup,
  208. 3, {1, 1, 3}},
  209. {OSPFv3AREABDRRTRSTATUS, INTEGER, RONLY, ospfv3GeneralGroup,
  210. 3, {1, 1, 4}},
  211. {OSPFv3ASBDRRTRSTATUS, INTEGER, RWRITE, ospfv3GeneralGroup,
  212. 3, {1, 1, 5}},
  213. {OSPFv3ASSCOPELSACOUNT, GAUGE, RONLY, ospfv3GeneralGroup,
  214. 3, {1, 1, 6}},
  215. {OSPFv3ASSCOPELSACHECKSUMSUM,UNSIGNED, RONLY, ospfv3GeneralGroup,
  216. 3, {1, 1, 7}},
  217. {OSPFv3ORIGINATENEWLSAS, COUNTER, RONLY, ospfv3GeneralGroup,
  218. 3, {1, 1, 8}},
  219. {OSPFv3RXNEWLSAS, COUNTER, RONLY, ospfv3GeneralGroup,
  220. 3, {1, 1, 9}},
  221. {OSPFv3EXTLSACOUNT, GAUGE, RONLY, ospfv3GeneralGroup,
  222. 3, {1, 1, 10}},
  223. {OSPFv3EXTAREALSDBLIMIT, INTEGER, RWRITE, ospfv3GeneralGroup,
  224. 3, {1, 1, 11}},
  225. {OSPFv3EXITOVERFLOWINTERVAL, UNSIGNED, RWRITE, ospfv3GeneralGroup,
  226. 3, {1, 1, 12}},
  227. {OSPFv3DEMANDEXTENSIONS, INTEGER, RWRITE, ospfv3GeneralGroup,
  228. 3, {1, 1, 13}},
  229. {OSPFv3REFERENCEBANDWIDTH, UNSIGNED, RWRITE, ospfv3GeneralGroup,
  230. 3, {1, 1, 14}},
  231. {OSPFv3RESTARTSUPPORT, INTEGER, RWRITE, ospfv3GeneralGroup,
  232. 3, {1, 1, 15}},
  233. {OSPFv3RESTARTINTERVAL, UNSIGNED, RWRITE, ospfv3GeneralGroup,
  234. 3, {1, 1, 16}},
  235. {OSPFv3RESTARTSTRICTLSACHECKING, INTEGER, RWRITE, ospfv3GeneralGroup,
  236. 3, {1, 1, 17}},
  237. {OSPFv3RESTARTSTATUS, INTEGER, RONLY, ospfv3GeneralGroup,
  238. 3, {1, 1, 18}},
  239. {OSPFv3RESTARTAGE, UNSIGNED, RONLY, ospfv3GeneralGroup,
  240. 3, {1, 1, 19}},
  241. {OSPFv3RESTARTEXITREASON, INTEGER, RONLY, ospfv3GeneralGroup,
  242. 3, {1, 1, 20}},
  243. {OSPFv3NOTIFICATIONENABLE, INTEGER, RWRITE, ospfv3GeneralGroup,
  244. 3, {1, 1, 21}},
  245. {OSPFv3STUBROUTERSUPPORT, INTEGER, RONLY, ospfv3GeneralGroup,
  246. 3, {1, 1, 22}},
  247. {OSPFv3STUBROUTERADVERTISEMENT, INTEGER, RWRITE, ospfv3GeneralGroup,
  248. 3, {1, 1, 23}},
  249. {OSPFv3DISCONTINUITYTIME, TIMETICKS, RONLY, ospfv3GeneralGroup,
  250. 3, {1, 1, 24}},
  251. {OSPFv3RESTARTTIME, TIMETICKS, RONLY, ospfv3GeneralGroup,
  252. 3, {1, 1, 25}},
  253. /* OSPFv3 Area Data Structure */
  254. {OSPFv3IMPORTASEXTERN, INTEGER, RWRITE, ospfv3AreaEntry,
  255. 4, {1, 2, 1, 2}},
  256. {OSPFv3AREASPFRUNS, COUNTER, RONLY, ospfv3AreaEntry,
  257. 4, {1, 2, 1, 3}},
  258. {OSPFv3AREABDRRTRCOUNT, GAUGE, RONLY, ospfv3AreaEntry,
  259. 4, {1, 2, 1, 4}},
  260. {OSPFv3AREAASBDRRTRCOUNT, GAUGE, RONLY, ospfv3AreaEntry,
  261. 4, {1, 2, 1, 5}},
  262. {OSPFv3AREASCOPELSACOUNT, GAUGE, RONLY, ospfv3AreaEntry,
  263. 4, {1, 2, 1, 6}},
  264. {OSPFv3AREASCOPELSACKSUMSUM, UNSIGNED, RONLY, ospfv3AreaEntry,
  265. 4, {1, 2, 1, 7}},
  266. {OSPFv3AREASUMMARY, INTEGER, RWRITE, ospfv3AreaEntry,
  267. 4, {1, 2, 1, 8}},
  268. {OSPFv3AREAROWSTATUS, INTEGER, RWRITE, ospfv3AreaEntry,
  269. 4, {1, 2, 1, 9}},
  270. {OSPFv3AREASTUBMETRIC, INTEGER, RWRITE, ospfv3AreaEntry,
  271. 4, {1, 2, 1, 10}},
  272. {OSPFv3AREANSSATRANSLATORROLE, INTEGER, RWRITE, ospfv3AreaEntry,
  273. 4, {1, 2, 1, 11}},
  274. {OSPFv3AREANSSATRANSLATORSTATE, INTEGER, RONLY, ospfv3AreaEntry,
  275. 4, {1, 2, 1, 12}},
  276. {OSPFv3AREANSSATRANSLATORSTABINTERVAL, UNSIGNED, RWRITE, ospfv3AreaEntry,
  277. 4, {1, 2, 1, 13}},
  278. {OSPFv3AREANSSATRANSLATOREVENTS, COUNTER, RONLY, ospfv3AreaEntry,
  279. 4, {1, 2, 1, 14}},
  280. {OSPFv3AREASTUBMETRICTYPE, INTEGER, RWRITE, ospfv3AreaEntry,
  281. 4, {1, 2, 1, 15}},
  282. {OSPFv3AREATEENABLED, INTEGER, RWRITE, ospfv3AreaEntry,
  283. 4, {1, 2, 1, 16}},
  284. /* OSPFv3 AS LSDB */
  285. {OSPFv3WWLSDBSEQUENCE | OSPFv3WWASTABLE, INTEGER, RONLY, ospfv3WwLsdbEntry,
  286. 4, {1, 3, 1, 4}},
  287. {OSPFv3WWLSDBAGE | OSPFv3WWASTABLE, UNSIGNED, RONLY, ospfv3WwLsdbEntry,
  288. 4, {1, 3, 1, 5}},
  289. {OSPFv3WWLSDBCHECKSUM | OSPFv3WWASTABLE, INTEGER, RONLY, ospfv3WwLsdbEntry,
  290. 4, {1, 3, 1, 6}},
  291. {OSPFv3WWLSDBADVERTISEMENT | OSPFv3WWASTABLE, STRING, RONLY, ospfv3WwLsdbEntry,
  292. 4, {1, 3, 1, 7}},
  293. {OSPFv3WWLSDBTYPEKNOWN | OSPFv3WWASTABLE, INTEGER, RONLY, ospfv3WwLsdbEntry,
  294. 4, {1, 3, 1, 8}},
  295. /* OSPFv3 Area LSDB */
  296. {OSPFv3WWLSDBSEQUENCE | OSPFv3WWAREATABLE, INTEGER, RONLY, ospfv3WwLsdbEntry,
  297. 4, {1, 4, 1, 5}},
  298. {OSPFv3WWLSDBAGE | OSPFv3WWAREATABLE, UNSIGNED, RONLY, ospfv3WwLsdbEntry,
  299. 4, {1, 4, 1, 6}},
  300. {OSPFv3WWLSDBCHECKSUM | OSPFv3WWAREATABLE, INTEGER, RONLY, ospfv3WwLsdbEntry,
  301. 4, {1, 4, 1, 7}},
  302. {OSPFv3WWLSDBADVERTISEMENT | OSPFv3WWAREATABLE, STRING, RONLY, ospfv3WwLsdbEntry,
  303. 4, {1, 4, 1, 8}},
  304. {OSPFv3WWLSDBTYPEKNOWN | OSPFv3WWAREATABLE, INTEGER, RONLY, ospfv3WwLsdbEntry,
  305. 4, {1, 4, 1, 9}},
  306. /* OSPFv3 Link LSDB */
  307. {OSPFv3WWLSDBSEQUENCE | OSPFv3WWLINKTABLE, INTEGER, RONLY, ospfv3WwLsdbEntry,
  308. 4, {1, 5, 1, 6}},
  309. {OSPFv3WWLSDBAGE | OSPFv3WWLINKTABLE, UNSIGNED, RONLY, ospfv3WwLsdbEntry,
  310. 4, {1, 5, 1, 7}},
  311. {OSPFv3WWLSDBCHECKSUM | OSPFv3WWLINKTABLE, INTEGER, RONLY, ospfv3WwLsdbEntry,
  312. 4, {1, 5, 1, 8}},
  313. {OSPFv3WWLSDBADVERTISEMENT | OSPFv3WWLINKTABLE, STRING, RONLY, ospfv3WwLsdbEntry,
  314. 4, {1, 5, 1, 9}},
  315. {OSPFv3WWLSDBTYPEKNOWN | OSPFv3WWLINKTABLE, INTEGER, RONLY, ospfv3WwLsdbEntry,
  316. 4, {1, 5, 1, 10}},
  317. /* OSPFv3 interfaces */
  318. {OSPFv3IFAREAID, UNSIGNED, RONLY, ospfv3IfEntry,
  319. 4, {1, 7, 1, 3}},
  320. {OSPFv3IFTYPE, INTEGER, RONLY, ospfv3IfEntry,
  321. 4, {1, 7, 1, 4}},
  322. {OSPFv3IFADMINSTATUS, INTEGER, RONLY, ospfv3IfEntry,
  323. 4, {1, 7, 1, 5}},
  324. {OSPFv3IFRTRPRIORITY, INTEGER, RONLY, ospfv3IfEntry,
  325. 4, {1, 7, 1, 6}},
  326. {OSPFv3IFTRANSITDELAY, UNSIGNED, RONLY, ospfv3IfEntry,
  327. 4, {1, 7, 1, 7}},
  328. {OSPFv3IFRETRANSINTERVAL, UNSIGNED, RONLY, ospfv3IfEntry,
  329. 4, {1, 7, 1, 8}},
  330. {OSPFv3IFHELLOINTERVAL, INTEGER, RONLY, ospfv3IfEntry,
  331. 4, {1, 7, 1, 9}},
  332. {OSPFv3IFRTRDEADINTERVAL, UNSIGNED, RONLY, ospfv3IfEntry,
  333. 4, {1, 7, 1, 10}},
  334. {OSPFv3IFPOLLINTERVAL, UNSIGNED, RONLY, ospfv3IfEntry,
  335. 4, {1, 7, 1, 11}},
  336. {OSPFv3IFSTATE, INTEGER, RONLY, ospfv3IfEntry,
  337. 4, {1, 7, 1, 12}},
  338. {OSPFv3IFDESIGNATEDROUTER, UNSIGNED, RONLY, ospfv3IfEntry,
  339. 4, {1, 7, 1, 13}},
  340. {OSPFv3IFBACKUPDESIGNATEDROUTER, UNSIGNED, RONLY, ospfv3IfEntry,
  341. 4, {1, 7, 1, 14}},
  342. {OSPFv3IFEVENTS, COUNTER, RONLY, ospfv3IfEntry,
  343. 4, {1, 7, 1, 15}},
  344. {OSPFv3IFROWSTATUS, INTEGER, RONLY, ospfv3IfEntry,
  345. 4, {1, 7, 1, 16}},
  346. {OSPFv3IFDEMAND, INTEGER, RONLY, ospfv3IfEntry,
  347. 4, {1, 7, 1, 17}},
  348. {OSPFv3IFMETRICVALUE, INTEGER, RONLY, ospfv3IfEntry,
  349. 4, {1, 7, 1, 18}},
  350. {OSPFv3IFLINKSCOPELSACOUNT, GAUGE, RONLY, ospfv3IfEntry,
  351. 4, {1, 7, 1, 19}},
  352. {OSPFv3IFLINKLSACKSUMSUM, UNSIGNED, RONLY, ospfv3IfEntry,
  353. 4, {1, 7, 1, 20}},
  354. {OSPFv3IFDEMANDNBRPROBE, INTEGER, RONLY, ospfv3IfEntry,
  355. 4, {1, 7, 1, 21}},
  356. {OSPFv3IFDEMANDNBRPROBERETRANSLIMIT, UNSIGNED, RONLY, ospfv3IfEntry,
  357. 4, {1, 7, 1, 22}},
  358. {OSPFv3IFDEMANDNBRPROBEINTERVAL, UNSIGNED, RONLY, ospfv3IfEntry,
  359. 4, {1, 7, 1, 23}},
  360. {OSPFv3IFTEDISABLED, INTEGER, RONLY, ospfv3IfEntry,
  361. 4, {1, 7, 1, 24}},
  362. {OSPFv3IFLINKLSASUPPRESSION, INTEGER, RONLY, ospfv3IfEntry,
  363. 4, {1, 7, 1, 25}},
  364. /* OSPFv3 neighbors */
  365. {OSPFv3NBRADDRESSTYPE, INTEGER, RONLY, ospfv3NbrEntry,
  366. 4, {1, 9, 1, 4}},
  367. {OSPFv3NBRADDRESS, STRING, RONLY, ospfv3NbrEntry,
  368. 4, {1, 9, 1, 5}},
  369. {OSPFv3NBROPTIONS, INTEGER, RONLY, ospfv3NbrEntry,
  370. 4, {1, 9, 1, 6}},
  371. {OSPFv3NBRPRIORITY, INTEGER, RONLY, ospfv3NbrEntry,
  372. 4, {1, 9, 1, 7}},
  373. {OSPFv3NBRSTATE, INTEGER, RONLY, ospfv3NbrEntry,
  374. 4, {1, 9, 1, 8}},
  375. {OSPFv3NBREVENTS, COUNTER, RONLY, ospfv3NbrEntry,
  376. 4, {1, 9, 1, 9}},
  377. {OSPFv3NBRLSRETRANSQLEN, GAUGE, RONLY, ospfv3NbrEntry,
  378. 4, {1, 9, 1, 10}},
  379. {OSPFv3NBRHELLOSUPPRESSED, INTEGER, RONLY, ospfv3NbrEntry,
  380. 4, {1, 9, 1, 11}},
  381. {OSPFv3NBRIFID, INTEGER, RONLY, ospfv3NbrEntry,
  382. 4, {1, 9, 1, 12}},
  383. {OSPFv3NBRRESTARTHELPERSTATUS, INTEGER, RONLY, ospfv3NbrEntry,
  384. 4, {1, 9, 1, 13}},
  385. {OSPFv3NBRRESTARTHELPERAGE, UNSIGNED, RONLY, ospfv3NbrEntry,
  386. 4, {1, 9, 1, 14}},
  387. {OSPFv3NBRRESTARTHELPEREXITREASON, INTEGER, RONLY, ospfv3NbrEntry,
  388. 4, {1, 9, 1, 15}},
  389. };
  390. static u_char *
  391. ospfv3GeneralGroup (struct variable *v, oid *name, size_t *length,
  392. int exact, size_t *var_len, WriteMethod **write_method)
  393. {
  394. u_int16_t sum;
  395. u_int32_t count;
  396. struct ospf6_lsa *lsa = NULL;
  397. /* Check whether the instance identifier is valid */
  398. if (smux_header_generic (v, name, length, exact, var_len, write_method)
  399. == MATCH_FAILED)
  400. return NULL;
  401. /* Return the current value of the variable */
  402. switch (v->magic)
  403. {
  404. case OSPFv3ROUTERID:
  405. /* Router-ID of this OSPF instance. */
  406. if (ospf6)
  407. return SNMP_INTEGER (ntohl (ospf6->router_id));
  408. return SNMP_INTEGER (0);
  409. case OSPFv3ADMINSTAT:
  410. if (ospf6)
  411. return SNMP_INTEGER (CHECK_FLAG (ospf6->flag, OSPF6_DISABLED)?
  412. OSPF_STATUS_DISABLED:OSPF_STATUS_ENABLED);
  413. return SNMP_INTEGER (OSPF_STATUS_DISABLED);
  414. case OSPFv3VERSIONNUMBER:
  415. return SNMP_INTEGER (3);
  416. case OSPFv3AREABDRRTRSTATUS:
  417. if (ospf6)
  418. return SNMP_INTEGER (ospf6_is_router_abr (ospf6)?SNMP_TRUE:SNMP_FALSE);
  419. return SNMP_INTEGER (SNMP_FALSE);
  420. case OSPFv3ASBDRRTRSTATUS:
  421. if (ospf6)
  422. return SNMP_INTEGER (ospf6_asbr_is_asbr (ospf6)?SNMP_TRUE:SNMP_FALSE);
  423. return SNMP_INTEGER (SNMP_FALSE);
  424. case OSPFv3ASSCOPELSACOUNT:
  425. if (ospf6)
  426. return SNMP_INTEGER (ospf6->lsdb->count);
  427. return SNMP_INTEGER (0);
  428. case OSPFv3ASSCOPELSACHECKSUMSUM:
  429. if (ospf6)
  430. {
  431. for (sum = 0, lsa = ospf6_lsdb_head (ospf6->lsdb);
  432. lsa;
  433. lsa = ospf6_lsdb_next (lsa))
  434. sum += ntohs (lsa->header->checksum);
  435. return SNMP_INTEGER (sum);
  436. }
  437. return SNMP_INTEGER (0);
  438. case OSPFv3ORIGINATENEWLSAS:
  439. return SNMP_INTEGER (0); /* Don't know where to get this value... */
  440. case OSPFv3RXNEWLSAS:
  441. return SNMP_INTEGER (0); /* Don't know where to get this value... */
  442. case OSPFv3EXTLSACOUNT:
  443. if (ospf6)
  444. {
  445. for (count = 0, lsa = ospf6_lsdb_type_head (htons (OSPF6_LSTYPE_AS_EXTERNAL),
  446. ospf6->lsdb);
  447. lsa;
  448. lsa = ospf6_lsdb_type_next (htons (OSPF6_LSTYPE_AS_EXTERNAL),
  449. lsa))
  450. count += 1;
  451. return SNMP_INTEGER (count);
  452. }
  453. return SNMP_INTEGER (0);
  454. case OSPFv3EXTAREALSDBLIMIT:
  455. return SNMP_INTEGER (-1);
  456. case OSPFv3EXITOVERFLOWINTERVAL:
  457. return SNMP_INTEGER (0); /* Not supported */
  458. case OSPFv3DEMANDEXTENSIONS:
  459. return SNMP_INTEGER (0); /* Not supported */
  460. case OSPFv3REFERENCEBANDWIDTH:
  461. if (ospf6)
  462. return SNMP_INTEGER (ospf6->ref_bandwidth);
  463. /* Otherwise, like for "not implemented". */
  464. case OSPFv3RESTARTSUPPORT:
  465. case OSPFv3RESTARTINTERVAL:
  466. case OSPFv3RESTARTSTRICTLSACHECKING:
  467. case OSPFv3RESTARTSTATUS:
  468. case OSPFv3RESTARTAGE:
  469. case OSPFv3RESTARTEXITREASON:
  470. case OSPFv3NOTIFICATIONENABLE:
  471. case OSPFv3STUBROUTERSUPPORT:
  472. case OSPFv3STUBROUTERADVERTISEMENT:
  473. case OSPFv3DISCONTINUITYTIME:
  474. case OSPFv3RESTARTTIME:
  475. /* TODO: Not implemented */
  476. return NULL;
  477. }
  478. return NULL;
  479. }
  480. static u_char *
  481. ospfv3AreaEntry (struct variable *v, oid *name, size_t *length,
  482. int exact, size_t *var_len, WriteMethod **write_method)
  483. {
  484. struct ospf6_area *oa, *area = NULL;
  485. struct ospf6_lsa *lsa = NULL;
  486. u_int32_t area_id = 0;
  487. u_int32_t count;
  488. u_int16_t sum;
  489. struct listnode *node;
  490. unsigned int len;
  491. char a[16];
  492. struct ospf6_route *ro;
  493. if (ospf6 == NULL)
  494. return NULL;
  495. if (smux_header_table(v, name, length, exact, var_len, write_method)
  496. == MATCH_FAILED)
  497. return NULL;
  498. len = *length - v->namelen;
  499. len = (len >= 1 ? 1 : 0);
  500. if (exact && len != 1)
  501. return NULL;
  502. if (len)
  503. area_id = htonl (name[v->namelen]);
  504. inet_ntop (AF_INET, &area_id, a, sizeof (a));
  505. zlog_debug ("SNMP access by area: %s, exact=%d len=%d length=%lu",
  506. a, exact, len, (u_long)*length);
  507. for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa))
  508. {
  509. if (area == NULL)
  510. {
  511. if (len == 0) /* return first area entry */
  512. area = oa;
  513. else if (exact && ntohl (oa->area_id) == ntohl (area_id))
  514. area = oa;
  515. else if (ntohl (oa->area_id) > ntohl (area_id))
  516. area = oa;
  517. }
  518. }
  519. if (area == NULL)
  520. return NULL;
  521. *length = v->namelen + 1;
  522. name[v->namelen] = ntohl (area->area_id);
  523. inet_ntop (AF_INET, &area->area_id, a, sizeof (a));
  524. zlog_debug ("SNMP found area: %s, exact=%d len=%d length=%lu",
  525. a, exact, len, (u_long)*length);
  526. switch (v->magic)
  527. {
  528. case OSPFv3IMPORTASEXTERN:
  529. /* No NSSA support */
  530. return SNMP_INTEGER (IS_AREA_STUB(area)?2:1);
  531. case OSPFv3AREASPFRUNS:
  532. return SNMP_INTEGER (area->spf_calculation);
  533. case OSPFv3AREABDRRTRCOUNT:
  534. case OSPFv3AREAASBDRRTRCOUNT:
  535. count = 0;
  536. for (ro = ospf6_route_head (ospf6->brouter_table); ro;
  537. ro = ospf6_route_next (ro))
  538. {
  539. if (ntohl (ro->path.area_id) != ntohl (area->area_id)) continue;
  540. if (v->magic == OSPFv3AREABDRRTRCOUNT &&
  541. CHECK_FLAG (ro->path.router_bits, OSPF6_ROUTER_BIT_B))
  542. count++;
  543. if (v->magic == OSPFv3AREAASBDRRTRCOUNT &&
  544. CHECK_FLAG (ro->path.router_bits, OSPF6_ROUTER_BIT_E))
  545. count++;
  546. }
  547. return SNMP_INTEGER (count);
  548. case OSPFv3AREASCOPELSACOUNT:
  549. return SNMP_INTEGER (area->lsdb->count);
  550. case OSPFv3AREASCOPELSACKSUMSUM:
  551. for (sum = 0, lsa = ospf6_lsdb_head (area->lsdb);
  552. lsa;
  553. lsa = ospf6_lsdb_next (lsa))
  554. sum += ntohs (lsa->header->checksum);
  555. return SNMP_INTEGER (sum);
  556. case OSPFv3AREASUMMARY:
  557. return SNMP_INTEGER (2); /* sendAreaSummary */
  558. case OSPFv3AREAROWSTATUS:
  559. return SNMP_INTEGER (1); /* Active */
  560. case OSPFv3AREASTUBMETRIC:
  561. case OSPFv3AREANSSATRANSLATORROLE:
  562. case OSPFv3AREANSSATRANSLATORSTATE:
  563. case OSPFv3AREANSSATRANSLATORSTABINTERVAL:
  564. case OSPFv3AREANSSATRANSLATOREVENTS:
  565. case OSPFv3AREASTUBMETRICTYPE:
  566. case OSPFv3AREATEENABLED:
  567. /* Not implemented. */
  568. return NULL;
  569. }
  570. return NULL;
  571. }
  572. static int
  573. if_icmp_func (struct interface *ifp1, struct interface *ifp2)
  574. {
  575. return (ifp1->ifindex - ifp2->ifindex);
  576. }
  577. static u_char *
  578. ospfv3WwLsdbEntry (struct variable *v, oid *name, size_t *length,
  579. int exact, size_t *var_len, WriteMethod **write_method)
  580. {
  581. struct ospf6_lsa *lsa = NULL;
  582. ifindex_t ifindex, area_id, id, instid, adv_router;
  583. u_int16_t type;
  584. int len;
  585. oid *offset;
  586. int offsetlen;
  587. struct ospf6_area *oa = NULL;
  588. struct listnode *node;
  589. struct interface *iif;
  590. struct ospf6_interface *oi = NULL;
  591. struct list *ifslist;
  592. if (smux_header_table(v, name, length, exact, var_len, write_method)
  593. == MATCH_FAILED)
  594. return NULL;
  595. instid = ifindex = area_id = type = id = adv_router = 0;
  596. /* Check OSPFv3 instance. */
  597. if (ospf6 == NULL)
  598. return NULL;
  599. /* Get variable length. */
  600. offset = name + v->namelen;
  601. offsetlen = *length - v->namelen;
  602. if (exact && (v->magic & OSPFv3WWASTABLE) && offsetlen != 3)
  603. return NULL;
  604. if (exact && (v->magic & OSPFv3WWAREATABLE) && offsetlen != 4)
  605. return NULL;
  606. if (exact && (v->magic & OSPFv3WWLINKTABLE) && offsetlen != 5)
  607. return NULL;
  608. if (v->magic & OSPFv3WWLINKTABLE)
  609. {
  610. /* Parse ifindex */
  611. len = (offsetlen < 1 ? 0 : 1);
  612. if (len)
  613. ifindex = *offset;
  614. offset += len;
  615. offsetlen -= len;
  616. /* Parse instance ID */
  617. len = (offsetlen < 1 ? 0 : 1);
  618. if (len)
  619. instid = *offset;
  620. offset += len;
  621. offsetlen -= len;
  622. }
  623. else if (v->magic & OSPFv3WWAREATABLE)
  624. {
  625. /* Parse area-id */
  626. len = (offsetlen < 1 ? 0 : 1);
  627. if (len)
  628. area_id = htonl (*offset);
  629. offset += len;
  630. offsetlen -= len;
  631. }
  632. /* Parse type */
  633. len = (offsetlen < 1 ? 0 : 1);
  634. if (len)
  635. type = htons (*offset);
  636. offset += len;
  637. offsetlen -= len;
  638. /* Parse Router-ID */
  639. len = (offsetlen < 1 ? 0 : 1);
  640. if (len)
  641. adv_router = htonl (*offset);
  642. offset += len;
  643. offsetlen -= len;
  644. /* Parse LS-ID */
  645. len = (offsetlen < 1 ? 0 : 1);
  646. if (len)
  647. id = htonl (*offset);
  648. offset += len;
  649. offsetlen -= len;
  650. if (exact)
  651. {
  652. if (v->magic & OSPFv3WWASTABLE)
  653. {
  654. lsa = ospf6_lsdb_lookup (type, id, adv_router, ospf6->lsdb);
  655. }
  656. else if (v->magic & OSPFv3WWAREATABLE)
  657. {
  658. oa = ospf6_area_lookup (area_id, ospf6);
  659. if (!oa) return NULL;
  660. lsa = ospf6_lsdb_lookup (type, id, adv_router, oa->lsdb);
  661. }
  662. else if (v->magic & OSPFv3WWLINKTABLE)
  663. {
  664. oi = ospf6_interface_lookup_by_ifindex (ifindex);
  665. if (!oi || oi->instance_id != instid) return NULL;
  666. lsa = ospf6_lsdb_lookup (type, id, adv_router, oi->lsdb);
  667. }
  668. }
  669. else
  670. {
  671. if (v->magic & OSPFv3WWASTABLE)
  672. {
  673. if (ospf6->lsdb->count)
  674. lsa = ospf6_lsdb_lookup_next (type, id, adv_router,
  675. ospf6->lsdb);
  676. }
  677. else if (v->magic & OSPFv3WWAREATABLE)
  678. for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa))
  679. {
  680. if (oa->area_id < area_id)
  681. continue;
  682. if (oa->lsdb->count)
  683. lsa = ospf6_lsdb_lookup_next (type, id, adv_router,
  684. oa->lsdb);
  685. if (lsa) break;
  686. type = 0;
  687. id = 0;
  688. adv_router = 0;
  689. }
  690. else if (v->magic & OSPFv3WWLINKTABLE)
  691. {
  692. /* We build a sorted list of interfaces */
  693. ifslist = list_new ();
  694. if (!ifslist) return NULL;
  695. ifslist->cmp = (int (*)(void *, void *))if_icmp_func;
  696. for (ALL_LIST_ELEMENTS_RO (iflist, node, iif))
  697. listnode_add_sort (ifslist, iif);
  698. for (ALL_LIST_ELEMENTS_RO (ifslist, node, iif))
  699. {
  700. if (!iif->ifindex) continue;
  701. oi = ospf6_interface_lookup_by_ifindex (iif->ifindex);
  702. if (!oi) continue;
  703. if (iif->ifindex < ifindex) continue;
  704. if (oi->instance_id < instid) continue;
  705. if (oi->lsdb->count)
  706. lsa = ospf6_lsdb_lookup_next (type, id, adv_router,
  707. oi->lsdb);
  708. if (lsa) break;
  709. type = 0;
  710. id = 0;
  711. adv_router = 0;
  712. oi = NULL;
  713. }
  714. list_delete_all_node (ifslist);
  715. }
  716. }
  717. if (! lsa)
  718. return NULL;
  719. /* Add indexes */
  720. if (v->magic & OSPFv3WWASTABLE)
  721. {
  722. *length = v->namelen + 3;
  723. offset = name + v->namelen;
  724. }
  725. else if (v->magic & OSPFv3WWAREATABLE)
  726. {
  727. *length = v->namelen + 4;
  728. offset = name + v->namelen;
  729. *offset = ntohl (oa->area_id);
  730. offset++;
  731. }
  732. else if (v->magic & OSPFv3WWLINKTABLE)
  733. {
  734. *length = v->namelen + 5;
  735. offset = name + v->namelen;
  736. *offset = oi->interface->ifindex;
  737. offset++;
  738. *offset = oi->instance_id;
  739. offset++;
  740. }
  741. *offset = ntohs (lsa->header->type);
  742. offset++;
  743. *offset = ntohl (lsa->header->adv_router);
  744. offset++;
  745. *offset = ntohl (lsa->header->id);
  746. offset++;
  747. /* Return the current value of the variable */
  748. switch (v->magic & OSPFv3WWCOLUMN)
  749. {
  750. case OSPFv3WWLSDBSEQUENCE:
  751. return SNMP_INTEGER (ntohl (lsa->header->seqnum));
  752. break;
  753. case OSPFv3WWLSDBAGE:
  754. ospf6_lsa_age_current (lsa);
  755. return SNMP_INTEGER (ntohs (lsa->header->age));
  756. break;
  757. case OSPFv3WWLSDBCHECKSUM:
  758. return SNMP_INTEGER (ntohs (lsa->header->checksum));
  759. break;
  760. case OSPFv3WWLSDBADVERTISEMENT:
  761. *var_len = ntohs (lsa->header->length);
  762. return (u_char *) lsa->header;
  763. break;
  764. case OSPFv3WWLSDBTYPEKNOWN:
  765. return SNMP_INTEGER (OSPF6_LSA_IS_KNOWN (lsa->header->type) ?
  766. SNMP_TRUE : SNMP_FALSE);
  767. break;
  768. }
  769. return NULL;
  770. }
  771. static u_char *
  772. ospfv3IfEntry (struct variable *v, oid *name, size_t *length,
  773. int exact, size_t *var_len, WriteMethod **write_method)
  774. {
  775. ifindex_t ifindex = 0;
  776. unsigned int instid = 0;
  777. struct ospf6_interface *oi = NULL;
  778. struct ospf6_lsa *lsa = NULL;
  779. struct interface *iif;
  780. struct listnode *i;
  781. struct list *ifslist;
  782. oid *offset;
  783. int offsetlen, len;
  784. u_int32_t sum;
  785. if (smux_header_table (v, name, length, exact, var_len, write_method)
  786. == MATCH_FAILED)
  787. return NULL;
  788. /* Check OSPFv3 instance. */
  789. if (ospf6 == NULL)
  790. return NULL;
  791. /* Get variable length. */
  792. offset = name + v->namelen;
  793. offsetlen = *length - v->namelen;
  794. if (exact && offsetlen != 2)
  795. return NULL;
  796. /* Parse if index */
  797. len = (offsetlen < 1 ? 0 : 1);
  798. if (len)
  799. ifindex = *offset;
  800. offset += len;
  801. offsetlen -= len;
  802. /* Parse instance ID */
  803. len = (offsetlen < 1 ? 0 : 1);
  804. if (len)
  805. instid = *offset;
  806. offset += len;
  807. offsetlen -= len;
  808. if (exact)
  809. {
  810. oi = ospf6_interface_lookup_by_ifindex (ifindex);
  811. if (!oi || oi->instance_id != instid) return NULL;
  812. }
  813. else
  814. {
  815. /* We build a sorted list of interfaces */
  816. ifslist = list_new ();
  817. if (!ifslist) return NULL;
  818. ifslist->cmp = (int (*)(void *, void *))if_icmp_func;
  819. for (ALL_LIST_ELEMENTS_RO (iflist, i, iif))
  820. listnode_add_sort (ifslist, iif);
  821. for (ALL_LIST_ELEMENTS_RO (ifslist, i, iif))
  822. {
  823. if (!iif->ifindex) continue;
  824. oi = ospf6_interface_lookup_by_ifindex (iif->ifindex);
  825. if (!oi) continue;
  826. if (iif->ifindex > ifindex ||
  827. (iif->ifindex == ifindex &&
  828. (oi->instance_id > instid)))
  829. break;
  830. oi = NULL;
  831. }
  832. list_delete_all_node (ifslist);
  833. }
  834. if (!oi) return NULL;
  835. /* Add Index (IfIndex, IfInstId) */
  836. *length = v->namelen + 2;
  837. offset = name + v->namelen;
  838. *offset = oi->interface->ifindex;
  839. offset++;
  840. *offset = oi->instance_id;
  841. offset++;
  842. /* Return the current value of the variable */
  843. switch (v->magic)
  844. {
  845. case OSPFv3IFAREAID:
  846. if (oi->area)
  847. return SNMP_INTEGER (ntohl (oi->area->area_id));
  848. break;
  849. case OSPFv3IFTYPE:
  850. if (if_is_broadcast (oi->interface))
  851. return SNMP_INTEGER (1);
  852. else if (if_is_pointopoint (oi->interface))
  853. return SNMP_INTEGER (3);
  854. else break; /* Unknown, don't put anything */
  855. case OSPFv3IFADMINSTATUS:
  856. if (oi->area)
  857. return SNMP_INTEGER (OSPF_STATUS_ENABLED);
  858. return SNMP_INTEGER (OSPF_STATUS_DISABLED);
  859. case OSPFv3IFRTRPRIORITY:
  860. return SNMP_INTEGER (oi->priority);
  861. case OSPFv3IFTRANSITDELAY:
  862. return SNMP_INTEGER (oi->transdelay);
  863. case OSPFv3IFRETRANSINTERVAL:
  864. return SNMP_INTEGER (oi->rxmt_interval);
  865. case OSPFv3IFHELLOINTERVAL:
  866. return SNMP_INTEGER (oi->hello_interval);
  867. case OSPFv3IFRTRDEADINTERVAL:
  868. return SNMP_INTEGER (oi->dead_interval);
  869. case OSPFv3IFPOLLINTERVAL:
  870. /* No support for NBMA */
  871. break;
  872. case OSPFv3IFSTATE:
  873. return SNMP_INTEGER (oi->state);
  874. case OSPFv3IFDESIGNATEDROUTER:
  875. return SNMP_INTEGER (ntohl (oi->drouter));
  876. case OSPFv3IFBACKUPDESIGNATEDROUTER:
  877. return SNMP_INTEGER (ntohl (oi->bdrouter));
  878. case OSPFv3IFEVENTS:
  879. return SNMP_INTEGER (oi->state_change);
  880. case OSPFv3IFROWSTATUS:
  881. return SNMP_INTEGER (1);
  882. case OSPFv3IFDEMAND:
  883. return SNMP_INTEGER (SNMP_FALSE);
  884. case OSPFv3IFMETRICVALUE:
  885. return SNMP_INTEGER (oi->cost);
  886. case OSPFv3IFLINKSCOPELSACOUNT:
  887. return SNMP_INTEGER (oi->lsdb->count);
  888. case OSPFv3IFLINKLSACKSUMSUM:
  889. for (sum = 0, lsa = ospf6_lsdb_head (oi->lsdb);
  890. lsa;
  891. lsa = ospf6_lsdb_next (lsa))
  892. sum += ntohs (lsa->header->checksum);
  893. return SNMP_INTEGER (sum);
  894. case OSPFv3IFDEMANDNBRPROBE:
  895. case OSPFv3IFDEMANDNBRPROBERETRANSLIMIT:
  896. case OSPFv3IFDEMANDNBRPROBEINTERVAL:
  897. case OSPFv3IFTEDISABLED:
  898. case OSPFv3IFLINKLSASUPPRESSION:
  899. /* Not implemented. Only works if all the last ones are not
  900. implemented! */
  901. return NULL;
  902. }
  903. /* Try an internal getnext. Some columns are missing in this table. */
  904. if (!exact && (name[*length-1] < MAX_SUBID))
  905. return ospfv3IfEntry(v, name, length,
  906. exact, var_len, write_method);
  907. return NULL;
  908. }
  909. static u_char *
  910. ospfv3NbrEntry (struct variable *v, oid *name, size_t *length,
  911. int exact, size_t *var_len, WriteMethod **write_method)
  912. {
  913. ifindex_t ifindex = 0;
  914. unsigned int instid, rtrid;
  915. struct ospf6_interface *oi = NULL;
  916. struct ospf6_neighbor *on = NULL;
  917. struct interface *iif;
  918. struct listnode *i, *j;
  919. struct list *ifslist;
  920. oid *offset;
  921. int offsetlen, len;
  922. if (smux_header_table (v, name, length, exact, var_len, write_method)
  923. == MATCH_FAILED)
  924. return NULL;
  925. instid = rtrid = 0;
  926. /* Check OSPFv3 instance. */
  927. if (ospf6 == NULL)
  928. return NULL;
  929. /* Get variable length. */
  930. offset = name + v->namelen;
  931. offsetlen = *length - v->namelen;
  932. if (exact && offsetlen != 3)
  933. return NULL;
  934. /* Parse if index */
  935. len = (offsetlen < 1 ? 0 : 1);
  936. if (len)
  937. ifindex = *offset;
  938. offset += len;
  939. offsetlen -= len;
  940. /* Parse instance ID */
  941. len = (offsetlen < 1 ? 0 : 1);
  942. if (len)
  943. instid = *offset;
  944. offset += len;
  945. offsetlen -= len;
  946. /* Parse router ID */
  947. len = (offsetlen < 1 ? 0 : 1);
  948. if (len)
  949. rtrid = htonl (*offset);
  950. offset += len;
  951. offsetlen -= len;
  952. if (exact)
  953. {
  954. oi = ospf6_interface_lookup_by_ifindex (ifindex);
  955. if (!oi || oi->instance_id != instid) return NULL;
  956. on = ospf6_neighbor_lookup (rtrid, oi);
  957. }
  958. else
  959. {
  960. /* We build a sorted list of interfaces */
  961. ifslist = list_new ();
  962. if (!ifslist) return NULL;
  963. ifslist->cmp = (int (*)(void *, void *))if_icmp_func;
  964. for (ALL_LIST_ELEMENTS_RO (iflist, i, iif))
  965. listnode_add_sort (ifslist, iif);
  966. for (ALL_LIST_ELEMENTS_RO (ifslist, i, iif))
  967. {
  968. if (!iif->ifindex) continue;
  969. oi = ospf6_interface_lookup_by_ifindex (iif->ifindex);
  970. if (!oi) continue;
  971. for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, j, on)) {
  972. if (iif->ifindex > ifindex ||
  973. (iif->ifindex == ifindex &&
  974. (oi->instance_id > instid ||
  975. (oi->instance_id == instid &&
  976. ntohl (on->router_id) > ntohl (rtrid)))))
  977. break;
  978. }
  979. if (on) break;
  980. oi = NULL;
  981. on = NULL;
  982. }
  983. list_delete_all_node (ifslist);
  984. }
  985. if (!oi || !on) return NULL;
  986. /* Add Index (IfIndex, IfInstId, RtrId) */
  987. *length = v->namelen + 3;
  988. offset = name + v->namelen;
  989. *offset = oi->interface->ifindex;
  990. offset++;
  991. *offset = oi->instance_id;
  992. offset++;
  993. *offset = ntohl (on->router_id);
  994. offset++;
  995. /* Return the current value of the variable */
  996. switch (v->magic)
  997. {
  998. case OSPFv3NBRADDRESSTYPE:
  999. return SNMP_INTEGER (2); /* IPv6 only */
  1000. case OSPFv3NBRADDRESS:
  1001. *var_len = sizeof (struct in6_addr);
  1002. return (u_char *) &on->linklocal_addr;
  1003. case OSPFv3NBROPTIONS:
  1004. return SNMP_INTEGER (on->options[2]);
  1005. case OSPFv3NBRPRIORITY:
  1006. return SNMP_INTEGER (on->priority);
  1007. case OSPFv3NBRSTATE:
  1008. return SNMP_INTEGER (on->state);
  1009. case OSPFv3NBREVENTS:
  1010. return SNMP_INTEGER (on->state_change);
  1011. case OSPFv3NBRLSRETRANSQLEN:
  1012. return SNMP_INTEGER (on->retrans_list->count);
  1013. case OSPFv3NBRHELLOSUPPRESSED:
  1014. return SNMP_INTEGER (SNMP_FALSE);
  1015. case OSPFv3NBRIFID:
  1016. return SNMP_INTEGER (on->ifindex);
  1017. case OSPFv3NBRRESTARTHELPERSTATUS:
  1018. case OSPFv3NBRRESTARTHELPERAGE:
  1019. case OSPFv3NBRRESTARTHELPEREXITREASON:
  1020. /* Not implemented. Only works if all the last ones are not
  1021. implemented! */
  1022. return NULL;
  1023. }
  1024. return NULL;
  1025. }
  1026. /* OSPF Traps. */
  1027. #define NBRSTATECHANGE 2
  1028. #define IFSTATECHANGE 10
  1029. static struct trap_object ospf6NbrTrapList[] =
  1030. {
  1031. {-3, {1, 1, OSPFv3ROUTERID}},
  1032. {4, {1, 9, 1, OSPFv3NBRADDRESSTYPE}},
  1033. {4, {1, 9, 1, OSPFv3NBRADDRESS}},
  1034. {4, {1, 9, 1, OSPFv3NBRSTATE}}
  1035. };
  1036. static struct trap_object ospf6IfTrapList[] =
  1037. {
  1038. {-3, {1, 1, OSPFv3ROUTERID}},
  1039. {4, {1, 7, 1, OSPFv3IFSTATE}},
  1040. {4, {1, 7, 1, OSPFv3IFADMINSTATUS}},
  1041. {4, {1, 7, 1, OSPFv3IFAREAID}}
  1042. };
  1043. void
  1044. ospf6TrapNbrStateChange (struct ospf6_neighbor *on)
  1045. {
  1046. oid index[3];
  1047. index[0] = on->ospf6_if->interface->ifindex;
  1048. index[1] = on->ospf6_if->instance_id;
  1049. index[2] = ntohl (on->router_id);
  1050. smux_trap (ospfv3_variables, sizeof ospfv3_variables / sizeof (struct variable),
  1051. ospfv3_trap_oid, sizeof ospfv3_trap_oid / sizeof (oid),
  1052. ospfv3_oid, sizeof ospfv3_oid / sizeof (oid),
  1053. index, 3,
  1054. ospf6NbrTrapList,
  1055. sizeof ospf6NbrTrapList / sizeof (struct trap_object),
  1056. NBRSTATECHANGE);
  1057. }
  1058. void
  1059. ospf6TrapIfStateChange (struct ospf6_interface *oi)
  1060. {
  1061. oid index[2];
  1062. index[0] = oi->interface->ifindex;
  1063. index[1] = oi->instance_id;
  1064. smux_trap (ospfv3_variables, sizeof ospfv3_variables / sizeof (struct variable),
  1065. ospfv3_trap_oid, sizeof ospfv3_trap_oid / sizeof (oid),
  1066. ospfv3_oid, sizeof ospfv3_oid / sizeof (oid),
  1067. index, 2,
  1068. ospf6IfTrapList,
  1069. sizeof ospf6IfTrapList / sizeof (struct trap_object),
  1070. IFSTATECHANGE);
  1071. }
  1072. /* Register OSPFv3-MIB. */
  1073. void
  1074. ospf6_snmp_init (struct thread_master *master)
  1075. {
  1076. smux_init (master);
  1077. REGISTER_MIB ("OSPFv3MIB", ospfv3_variables, variable, ospfv3_oid);
  1078. }
  1079. #endif /* HAVE_SNMP */