ospf6_snmp.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179
  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. return SNMP_INTEGER (100000);
  460. case OSPFv3RESTARTSUPPORT:
  461. case OSPFv3RESTARTINTERVAL:
  462. case OSPFv3RESTARTSTRICTLSACHECKING:
  463. case OSPFv3RESTARTSTATUS:
  464. case OSPFv3RESTARTAGE:
  465. case OSPFv3RESTARTEXITREASON:
  466. case OSPFv3NOTIFICATIONENABLE:
  467. case OSPFv3STUBROUTERSUPPORT:
  468. case OSPFv3STUBROUTERADVERTISEMENT:
  469. case OSPFv3DISCONTINUITYTIME:
  470. case OSPFv3RESTARTTIME:
  471. /* TODO: Not implemented */
  472. return NULL;
  473. }
  474. return NULL;
  475. }
  476. static u_char *
  477. ospfv3AreaEntry (struct variable *v, oid *name, size_t *length,
  478. int exact, size_t *var_len, WriteMethod **write_method)
  479. {
  480. struct ospf6_area *oa, *area = NULL;
  481. struct ospf6_lsa *lsa = NULL;
  482. u_int32_t area_id = 0;
  483. u_int32_t count;
  484. u_int16_t sum;
  485. struct listnode *node;
  486. unsigned int len;
  487. char a[16];
  488. struct ospf6_route *ro;
  489. if (ospf6 == NULL)
  490. return NULL;
  491. if (smux_header_table(v, name, length, exact, var_len, write_method)
  492. == MATCH_FAILED)
  493. return NULL;
  494. len = *length - v->namelen;
  495. len = (len >= 1 ? sizeof 1 : 0);
  496. if (exact && len != 1)
  497. return NULL;
  498. if (len)
  499. area_id = htonl (name[v->namelen]);
  500. inet_ntop (AF_INET, &area_id, a, sizeof (a));
  501. zlog_debug ("SNMP access by area: %s, exact=%d len=%d length=%lu",
  502. a, exact, len, (u_long)*length);
  503. for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa))
  504. {
  505. if (area == NULL)
  506. {
  507. if (len == 0) /* return first area entry */
  508. area = oa;
  509. else if (exact && ntohl (oa->area_id) == ntohl (area_id))
  510. area = oa;
  511. else if (ntohl (oa->area_id) > ntohl (area_id))
  512. area = oa;
  513. }
  514. }
  515. if (area == NULL)
  516. return NULL;
  517. *length = v->namelen + 1;
  518. name[v->namelen] = ntohl (area->area_id);
  519. inet_ntop (AF_INET, &area->area_id, a, sizeof (a));
  520. zlog_debug ("SNMP found area: %s, exact=%d len=%d length=%lu",
  521. a, exact, len, (u_long)*length);
  522. switch (v->magic)
  523. {
  524. case OSPFv3IMPORTASEXTERN:
  525. /* No NSSA support */
  526. return SNMP_INTEGER (IS_AREA_STUB(area)?2:1);
  527. case OSPFv3AREASPFRUNS:
  528. return SNMP_INTEGER (area->spf_calculation);
  529. case OSPFv3AREABDRRTRCOUNT:
  530. case OSPFv3AREAASBDRRTRCOUNT:
  531. count = 0;
  532. for (ro = ospf6_route_head (ospf6->brouter_table); ro;
  533. ro = ospf6_route_next (ro))
  534. {
  535. if (ntohl (ro->path.area_id) != ntohl (area->area_id)) continue;
  536. if (v->magic == OSPFv3AREABDRRTRCOUNT &&
  537. CHECK_FLAG (ro->path.router_bits, OSPF6_ROUTER_BIT_B))
  538. count++;
  539. if (v->magic == OSPFv3AREAASBDRRTRCOUNT &&
  540. CHECK_FLAG (ro->path.router_bits, OSPF6_ROUTER_BIT_E))
  541. count++;
  542. }
  543. return SNMP_INTEGER (count);
  544. case OSPFv3AREASCOPELSACOUNT:
  545. return SNMP_INTEGER (area->lsdb->count);
  546. case OSPFv3AREASCOPELSACKSUMSUM:
  547. for (sum = 0, lsa = ospf6_lsdb_head (area->lsdb);
  548. lsa;
  549. lsa = ospf6_lsdb_next (lsa))
  550. sum += ntohs (lsa->header->checksum);
  551. return SNMP_INTEGER (sum);
  552. case OSPFv3AREASUMMARY:
  553. return SNMP_INTEGER (2); /* sendAreaSummary */
  554. case OSPFv3AREAROWSTATUS:
  555. return SNMP_INTEGER (1); /* Active */
  556. case OSPFv3AREASTUBMETRIC:
  557. case OSPFv3AREANSSATRANSLATORROLE:
  558. case OSPFv3AREANSSATRANSLATORSTATE:
  559. case OSPFv3AREANSSATRANSLATORSTABINTERVAL:
  560. case OSPFv3AREANSSATRANSLATOREVENTS:
  561. case OSPFv3AREASTUBMETRICTYPE:
  562. case OSPFv3AREATEENABLED:
  563. /* Not implemented. */
  564. return NULL;
  565. }
  566. return NULL;
  567. }
  568. static int
  569. if_icmp_func (struct interface *ifp1, struct interface *ifp2)
  570. {
  571. return (ifp1->ifindex - ifp2->ifindex);
  572. }
  573. static u_char *
  574. ospfv3WwLsdbEntry (struct variable *v, oid *name, size_t *length,
  575. int exact, size_t *var_len, WriteMethod **write_method)
  576. {
  577. struct ospf6_lsa *lsa = NULL;
  578. u_int32_t ifindex, area_id, id, instid, adv_router;
  579. u_int16_t type;
  580. int len;
  581. oid *offset;
  582. int offsetlen;
  583. char a[16], b[16], c[16];
  584. struct ospf6_area *oa;
  585. struct listnode *node;
  586. struct interface *iif;
  587. struct ospf6_interface *oi = NULL;
  588. struct list *ifslist;
  589. if (smux_header_table(v, name, length, exact, var_len, write_method)
  590. == MATCH_FAILED)
  591. return NULL;
  592. instid = ifindex = area_id = type = id = adv_router = 0;
  593. /* Check OSPFv3 instance. */
  594. if (ospf6 == NULL)
  595. return NULL;
  596. /* Get variable length. */
  597. offset = name + v->namelen;
  598. offsetlen = *length - v->namelen;
  599. if (exact && (v->magic & OSPFv3WWASTABLE) && offsetlen != 3)
  600. return NULL;
  601. if (exact && (v->magic & OSPFv3WWAREATABLE) && offsetlen != 4)
  602. return NULL;
  603. if (exact && (v->magic & OSPFv3WWLINKTABLE) && offsetlen != 5)
  604. return NULL;
  605. if (v->magic & OSPFv3WWLINKTABLE)
  606. {
  607. /* Parse ifindex */
  608. len = (offsetlen < 1 ? 0 : 1);
  609. if (len)
  610. ifindex = *offset;
  611. offset += len;
  612. offsetlen -= len;
  613. /* Parse instance ID */
  614. len = (offsetlen < 1 ? 0 : 1);
  615. if (len)
  616. instid = *offset;
  617. offset += len;
  618. offsetlen -= len;
  619. }
  620. else if (v->magic & OSPFv3WWAREATABLE)
  621. {
  622. /* Parse area-id */
  623. len = (offsetlen < 1 ? 0 : 1);
  624. if (len)
  625. area_id = htonl (*offset);
  626. offset += len;
  627. offsetlen -= len;
  628. }
  629. /* Parse type */
  630. len = (offsetlen < 1 ? 0 : 1);
  631. if (len)
  632. type = htons (*offset);
  633. offset += len;
  634. offsetlen -= len;
  635. /* Parse Router-ID */
  636. len = (offsetlen < 1 ? 0 : 1);
  637. if (len)
  638. adv_router = htonl (*offset);
  639. offset += len;
  640. offsetlen -= len;
  641. /* Parse LS-ID */
  642. len = (offsetlen < 1 ? 0 : 1);
  643. if (len)
  644. id = htonl (*offset);
  645. offset += len;
  646. offsetlen -= len;
  647. if (exact)
  648. {
  649. if (v->magic & OSPFv3WWASTABLE)
  650. {
  651. lsa = ospf6_lsdb_lookup (type, id, adv_router, ospf6->lsdb);
  652. }
  653. else if (v->magic & OSPFv3WWAREATABLE)
  654. {
  655. oa = ospf6_area_lookup (area_id, ospf6);
  656. lsa = ospf6_lsdb_lookup (type, id, adv_router, oa->lsdb);
  657. }
  658. else if (v->magic & OSPFv3WWLINKTABLE)
  659. {
  660. oi = ospf6_interface_lookup_by_ifindex (ifindex);
  661. if (oi->instance_id != instid) return NULL;
  662. lsa = ospf6_lsdb_lookup (type, id, adv_router, oi->lsdb);
  663. }
  664. }
  665. else
  666. {
  667. if (v->magic & OSPFv3WWASTABLE)
  668. {
  669. if (ospf6->lsdb->count)
  670. lsa = ospf6_lsdb_lookup_next (type, id, adv_router,
  671. ospf6->lsdb);
  672. }
  673. else if (v->magic & OSPFv3WWAREATABLE)
  674. for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa))
  675. {
  676. if (oa->area_id < area_id)
  677. continue;
  678. if (oa->lsdb->count)
  679. lsa = ospf6_lsdb_lookup_next (type, id, adv_router,
  680. oa->lsdb);
  681. if (lsa) break;
  682. type = 0;
  683. id = 0;
  684. adv_router = 0;
  685. }
  686. else if (v->magic & OSPFv3WWLINKTABLE)
  687. {
  688. /* We build a sorted list of interfaces */
  689. ifslist = list_new ();
  690. if (!ifslist) return NULL;
  691. ifslist->cmp = (int (*)(void *, void *))if_icmp_func;
  692. for (ALL_LIST_ELEMENTS_RO (iflist, node, iif))
  693. listnode_add_sort (ifslist, iif);
  694. for (ALL_LIST_ELEMENTS_RO (ifslist, node, iif))
  695. {
  696. if (!iif->ifindex) continue;
  697. oi = ospf6_interface_lookup_by_ifindex (iif->ifindex);
  698. if (!oi) continue;
  699. if (iif->ifindex < ifindex) continue;
  700. if (oi->instance_id < instid) continue;
  701. if (oi->lsdb->count)
  702. lsa = ospf6_lsdb_lookup_next (type, id, adv_router,
  703. oi->lsdb);
  704. if (lsa) break;
  705. type = 0;
  706. id = 0;
  707. adv_router = 0;
  708. oi = NULL;
  709. }
  710. list_delete_all_node (ifslist);
  711. }
  712. }
  713. if (! lsa)
  714. return NULL;
  715. /* Add indexes */
  716. if (v->magic & OSPFv3WWASTABLE)
  717. {
  718. *length = v->namelen + 3;
  719. offset = name + v->namelen;
  720. }
  721. else if (v->magic & OSPFv3WWAREATABLE)
  722. {
  723. *length = v->namelen + 4;
  724. offset = name + v->namelen;
  725. *offset = ntohl (oa->area_id);
  726. offset++;
  727. }
  728. else if (v->magic & OSPFv3WWLINKTABLE)
  729. {
  730. *length = v->namelen + 5;
  731. offset = name + v->namelen;
  732. *offset = oi->interface->ifindex;
  733. offset++;
  734. *offset = oi->instance_id;
  735. offset++;
  736. }
  737. *offset = ntohs (lsa->header->type);
  738. offset++;
  739. *offset = ntohl (lsa->header->adv_router);
  740. offset++;
  741. *offset = ntohl (lsa->header->id);
  742. offset++;
  743. /* Return the current value of the variable */
  744. switch (v->magic & OSPFv3WWCOLUMN)
  745. {
  746. case OSPFv3WWLSDBSEQUENCE:
  747. return SNMP_INTEGER (ntohl (lsa->header->seqnum));
  748. break;
  749. case OSPFv3WWLSDBAGE:
  750. ospf6_lsa_age_current (lsa);
  751. return SNMP_INTEGER (ntohs (lsa->header->age));
  752. break;
  753. case OSPFv3WWLSDBCHECKSUM:
  754. return SNMP_INTEGER (ntohs (lsa->header->checksum));
  755. break;
  756. case OSPFv3WWLSDBADVERTISEMENT:
  757. *var_len = ntohs (lsa->header->length);
  758. return (u_char *) lsa->header;
  759. break;
  760. case OSPFv3WWLSDBTYPEKNOWN:
  761. return SNMP_INTEGER (OSPF6_LSA_IS_KNOWN (lsa->header->type) ?
  762. SNMP_TRUE : SNMP_FALSE);
  763. break;
  764. }
  765. return NULL;
  766. }
  767. static u_char *
  768. ospfv3IfEntry (struct variable *v, oid *name, size_t *length,
  769. int exact, size_t *var_len, WriteMethod **write_method)
  770. {
  771. unsigned int ifindex, instid;
  772. struct ospf6_interface *oi = NULL;
  773. struct ospf6_lsa *lsa = NULL;
  774. struct interface *iif;
  775. struct listnode *i;
  776. struct list *ifslist;
  777. oid *offset;
  778. int offsetlen, len;
  779. u_int32_t sum;
  780. if (smux_header_table (v, name, length, exact, var_len, write_method)
  781. == MATCH_FAILED)
  782. return NULL;
  783. ifindex = instid = 0;
  784. /* Check OSPFv3 instance. */
  785. if (ospf6 == NULL)
  786. return NULL;
  787. /* Get variable length. */
  788. offset = name + v->namelen;
  789. offsetlen = *length - v->namelen;
  790. if (exact && offsetlen != 2)
  791. return NULL;
  792. /* Parse if index */
  793. len = (offsetlen < 1 ? 0 : 1);
  794. if (len)
  795. ifindex = *offset;
  796. offset += len;
  797. offsetlen -= len;
  798. /* Parse instance ID */
  799. len = (offsetlen < 1 ? 0 : 1);
  800. if (len)
  801. instid = *offset;
  802. offset += len;
  803. offsetlen -= len;
  804. if (exact)
  805. {
  806. oi = ospf6_interface_lookup_by_ifindex (ifindex);
  807. if (oi->instance_id != instid) return NULL;
  808. }
  809. else
  810. {
  811. /* We build a sorted list of interfaces */
  812. ifslist = list_new ();
  813. if (!ifslist) return NULL;
  814. ifslist->cmp = (int (*)(void *, void *))if_icmp_func;
  815. for (ALL_LIST_ELEMENTS_RO (iflist, i, iif))
  816. listnode_add_sort (ifslist, iif);
  817. for (ALL_LIST_ELEMENTS_RO (ifslist, i, iif))
  818. {
  819. if (!iif->ifindex) continue;
  820. oi = ospf6_interface_lookup_by_ifindex (iif->ifindex);
  821. if (!oi) continue;
  822. if (iif->ifindex > ifindex ||
  823. (iif->ifindex == ifindex &&
  824. (oi->instance_id > instid)))
  825. break;
  826. oi = NULL;
  827. }
  828. list_delete_all_node (ifslist);
  829. }
  830. if (!oi) return NULL;
  831. /* Add Index (IfIndex, IfInstId) */
  832. *length = v->namelen + 2;
  833. offset = name + v->namelen;
  834. *offset = oi->interface->ifindex;
  835. offset++;
  836. *offset = oi->instance_id;
  837. offset++;
  838. /* Return the current value of the variable */
  839. switch (v->magic)
  840. {
  841. case OSPFv3IFAREAID:
  842. if (oi->area)
  843. return SNMP_INTEGER (ntohl (oi->area->area_id));
  844. break;
  845. case OSPFv3IFTYPE:
  846. if (if_is_broadcast (oi->interface))
  847. return SNMP_INTEGER (1);
  848. else if (if_is_pointopoint (oi->interface))
  849. return SNMP_INTEGER (3);
  850. else break; /* Unknown, don't put anything */
  851. case OSPFv3IFADMINSTATUS:
  852. if (oi->area)
  853. return SNMP_INTEGER (OSPF_STATUS_ENABLED);
  854. return SNMP_INTEGER (OSPF_STATUS_DISABLED);
  855. case OSPFv3IFRTRPRIORITY:
  856. return SNMP_INTEGER (oi->priority);
  857. case OSPFv3IFTRANSITDELAY:
  858. return SNMP_INTEGER (oi->transdelay);
  859. case OSPFv3IFRETRANSINTERVAL:
  860. return SNMP_INTEGER (oi->rxmt_interval);
  861. case OSPFv3IFHELLOINTERVAL:
  862. return SNMP_INTEGER (oi->hello_interval);
  863. case OSPFv3IFRTRDEADINTERVAL:
  864. return SNMP_INTEGER (oi->dead_interval);
  865. case OSPFv3IFPOLLINTERVAL:
  866. /* No support for NBMA */
  867. break;
  868. case OSPFv3IFSTATE:
  869. return SNMP_INTEGER (oi->state);
  870. case OSPFv3IFDESIGNATEDROUTER:
  871. return SNMP_INTEGER (ntohl (oi->drouter));
  872. case OSPFv3IFBACKUPDESIGNATEDROUTER:
  873. return SNMP_INTEGER (ntohl (oi->bdrouter));
  874. case OSPFv3IFEVENTS:
  875. return SNMP_INTEGER (oi->state_change);
  876. case OSPFv3IFROWSTATUS:
  877. return SNMP_INTEGER (1);
  878. case OSPFv3IFDEMAND:
  879. return SNMP_INTEGER (SNMP_FALSE);
  880. case OSPFv3IFMETRICVALUE:
  881. return SNMP_INTEGER (oi->cost);
  882. case OSPFv3IFLINKSCOPELSACOUNT:
  883. return SNMP_INTEGER (oi->lsdb->count);
  884. case OSPFv3IFLINKLSACKSUMSUM:
  885. for (sum = 0, lsa = ospf6_lsdb_head (oi->lsdb);
  886. lsa;
  887. lsa = ospf6_lsdb_next (lsa))
  888. sum += ntohs (lsa->header->checksum);
  889. return SNMP_INTEGER (sum);
  890. case OSPFv3IFDEMANDNBRPROBE:
  891. case OSPFv3IFDEMANDNBRPROBERETRANSLIMIT:
  892. case OSPFv3IFDEMANDNBRPROBEINTERVAL:
  893. case OSPFv3IFTEDISABLED:
  894. case OSPFv3IFLINKLSASUPPRESSION:
  895. /* Not implemented. Only works if all the last ones are not
  896. implemented! */
  897. return NULL;
  898. }
  899. /* Try an internal getnext. Some columns are missing in this table. */
  900. if (!exact && (name[*length-1] < MAX_SUBID))
  901. return ospfv3IfEntry(v, name, length,
  902. exact, var_len, write_method);
  903. return NULL;
  904. }
  905. static u_char *
  906. ospfv3NbrEntry (struct variable *v, oid *name, size_t *length,
  907. int exact, size_t *var_len, WriteMethod **write_method)
  908. {
  909. unsigned int ifindex, instid, rtrid;
  910. struct ospf6_interface *oi = NULL;
  911. struct ospf6_neighbor *on = NULL;
  912. struct interface *iif;
  913. struct listnode *i, *j;
  914. struct list *ifslist;
  915. oid *offset;
  916. int offsetlen, len;
  917. if (smux_header_table (v, name, length, exact, var_len, write_method)
  918. == MATCH_FAILED)
  919. return NULL;
  920. ifindex = instid = rtrid = 0;
  921. /* Check OSPFv3 instance. */
  922. if (ospf6 == NULL)
  923. return NULL;
  924. /* Get variable length. */
  925. offset = name + v->namelen;
  926. offsetlen = *length - v->namelen;
  927. if (exact && offsetlen != 3)
  928. return NULL;
  929. /* Parse if index */
  930. len = (offsetlen < 1 ? 0 : 1);
  931. if (len)
  932. ifindex = *offset;
  933. offset += len;
  934. offsetlen -= len;
  935. /* Parse instance ID */
  936. len = (offsetlen < 1 ? 0 : 1);
  937. if (len)
  938. instid = *offset;
  939. offset += len;
  940. offsetlen -= len;
  941. /* Parse router ID */
  942. len = (offsetlen < 1 ? 0 : 1);
  943. if (len)
  944. rtrid = htonl (*offset);
  945. offset += len;
  946. offsetlen -= len;
  947. if (exact)
  948. {
  949. oi = ospf6_interface_lookup_by_ifindex (ifindex);
  950. on = ospf6_neighbor_lookup (rtrid, oi);
  951. if (oi->instance_id != instid) return NULL;
  952. }
  953. else
  954. {
  955. /* We build a sorted list of interfaces */
  956. ifslist = list_new ();
  957. if (!ifslist) return NULL;
  958. ifslist->cmp = (int (*)(void *, void *))if_icmp_func;
  959. for (ALL_LIST_ELEMENTS_RO (iflist, i, iif))
  960. listnode_add_sort (ifslist, iif);
  961. for (ALL_LIST_ELEMENTS_RO (ifslist, i, iif))
  962. {
  963. if (!iif->ifindex) continue;
  964. oi = ospf6_interface_lookup_by_ifindex (iif->ifindex);
  965. if (!oi) continue;
  966. for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, j, on)) {
  967. if (iif->ifindex > ifindex ||
  968. (iif->ifindex == ifindex &&
  969. (oi->instance_id > instid ||
  970. (oi->instance_id == instid &&
  971. ntohl (on->router_id) > ntohl (rtrid)))))
  972. break;
  973. }
  974. if (on) break;
  975. oi = on = NULL;
  976. }
  977. list_delete_all_node (ifslist);
  978. }
  979. if (!oi || !on) return NULL;
  980. /* Add Index (IfIndex, IfInstId, RtrId) */
  981. *length = v->namelen + 3;
  982. offset = name + v->namelen;
  983. *offset = oi->interface->ifindex;
  984. offset++;
  985. *offset = oi->instance_id;
  986. offset++;
  987. *offset = ntohl (on->router_id);
  988. offset++;
  989. /* Return the current value of the variable */
  990. switch (v->magic)
  991. {
  992. case OSPFv3NBRADDRESSTYPE:
  993. return SNMP_INTEGER (2); /* IPv6 only */
  994. case OSPFv3NBRADDRESS:
  995. *var_len = sizeof (struct in6_addr);
  996. return (u_char *) &on->linklocal_addr;
  997. case OSPFv3NBROPTIONS:
  998. return SNMP_INTEGER (on->options[2]);
  999. case OSPFv3NBRPRIORITY:
  1000. return SNMP_INTEGER (on->priority);
  1001. case OSPFv3NBRSTATE:
  1002. return SNMP_INTEGER (on->state);
  1003. case OSPFv3NBREVENTS:
  1004. return SNMP_INTEGER (on->state_change);
  1005. case OSPFv3NBRLSRETRANSQLEN:
  1006. return SNMP_INTEGER (on->retrans_list->count);
  1007. case OSPFv3NBRHELLOSUPPRESSED:
  1008. return SNMP_INTEGER (SNMP_FALSE);
  1009. case OSPFv3NBRIFID:
  1010. return SNMP_INTEGER (on->ifindex);
  1011. case OSPFv3NBRRESTARTHELPERSTATUS:
  1012. case OSPFv3NBRRESTARTHELPERAGE:
  1013. case OSPFv3NBRRESTARTHELPEREXITREASON:
  1014. /* Not implemented. Only works if all the last ones are not
  1015. implemented! */
  1016. return NULL;
  1017. }
  1018. return NULL;
  1019. }
  1020. /* OSPF Traps. */
  1021. #define NBRSTATECHANGE 2
  1022. #define IFSTATECHANGE 10
  1023. static struct trap_object ospf6NbrTrapList[] =
  1024. {
  1025. {-3, {1, 1, OSPFv3ROUTERID}},
  1026. {4, {1, 9, 1, OSPFv3NBRADDRESSTYPE}},
  1027. {4, {1, 9, 1, OSPFv3NBRADDRESS}},
  1028. {4, {1, 9, 1, OSPFv3NBRSTATE}}
  1029. };
  1030. static struct trap_object ospf6IfTrapList[] =
  1031. {
  1032. {-3, {1, 1, OSPFv3ROUTERID}},
  1033. {4, {1, 7, 1, OSPFv3IFSTATE}},
  1034. {4, {1, 7, 1, OSPFv3IFADMINSTATUS}},
  1035. {4, {1, 7, 1, OSPFv3IFAREAID}}
  1036. };
  1037. void
  1038. ospf6TrapNbrStateChange (struct ospf6_neighbor *on)
  1039. {
  1040. oid index[3];
  1041. index[0] = on->ospf6_if->interface->ifindex;
  1042. index[1] = on->ospf6_if->instance_id;
  1043. index[2] = ntohl (on->router_id);
  1044. smux_trap (ospfv3_variables, sizeof ospfv3_variables / sizeof (struct variable),
  1045. ospfv3_trap_oid, sizeof ospfv3_trap_oid / sizeof (oid),
  1046. ospfv3_oid, sizeof ospfv3_oid / sizeof (oid),
  1047. index, 3,
  1048. ospf6NbrTrapList,
  1049. sizeof ospf6NbrTrapList / sizeof (struct trap_object),
  1050. NBRSTATECHANGE);
  1051. }
  1052. void
  1053. ospf6TrapIfStateChange (struct ospf6_interface *oi)
  1054. {
  1055. oid index[2];
  1056. index[0] = oi->interface->ifindex;
  1057. index[1] = oi->instance_id;
  1058. smux_trap (ospfv3_variables, sizeof ospfv3_variables / sizeof (struct variable),
  1059. ospfv3_trap_oid, sizeof ospfv3_trap_oid / sizeof (oid),
  1060. ospfv3_oid, sizeof ospfv3_oid / sizeof (oid),
  1061. index, 2,
  1062. ospf6IfTrapList,
  1063. sizeof ospf6IfTrapList / sizeof (struct trap_object),
  1064. IFSTATECHANGE);
  1065. }
  1066. /* Register OSPFv3-MIB. */
  1067. void
  1068. ospf6_snmp_init (struct thread_master *master)
  1069. {
  1070. smux_init (master);
  1071. REGISTER_MIB ("OSPFv3MIB", ospfv3_variables, variable, ospfv3_oid);
  1072. }
  1073. #endif /* HAVE_SNMP */