ospf6_snmp.c 37 KB

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