ospf6_snmp.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  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 AS Lsdb Table values: ospfv3AsLsdbTable */
  85. #define OSPFv3ASLSDBSEQUENCE 4
  86. #define OSPFv3ASLSDBAGE 5
  87. #define OSPFv3ASLSDBCHECKSUM 6
  88. #define OSPFv3ASLSDBADVERTISEMENT 7
  89. #define OSPFv3ASLSDBTYPEKNOWN 8
  90. /* OSPFv3 MIB Area Lsdb Table values: ospfv3AreaLsdbTable */
  91. #define OSPFv3AREALSDBSEQUENCE 5
  92. #define OSPFv3AREALSDBAGE 6
  93. #define OSPFv3AREALSDBCHECKSUM 7
  94. #define OSPFv3AREALSDBADVERTISEMENT 8
  95. #define OSPFv3AREALSDBTYPEKNOWN 9
  96. /* OSPFv3 MIB Link Lsdb Table values: ospfv3LinkLsdbTable */
  97. #define OSPFv3LINKLSDBSEQUENCE 6
  98. #define OSPFv3LINKLSDBAGE 7
  99. #define OSPFv3LINKLSDBCHECKSUM 8
  100. #define OSPFv3LINKLSDBADVERTISEMENT 9
  101. #define OSPFv3LINKLSDBTYPEKNOWN 10
  102. /* OSPFv3 MIB Host Table values: ospfv3HostTable */
  103. #define OSPFv3HOSTMETRIC 3
  104. #define OSPFv3HOSTROWSTATUS 4
  105. #define OSPFv3HOSTAREAID 5
  106. /* OSPFv3 MIB Interface Table values: ospfv3IfTable */
  107. #define OSPFv3IFAREAID 3
  108. #define OSPFv3IFTYPE 4
  109. #define OSPFv3IFADMINSTATUS 5
  110. #define OSPFv3IFRTRPRIORITY 6
  111. #define OSPFv3IFTRANSITDELAY 7
  112. #define OSPFv3IFRETRANSINTERVAL 8
  113. #define OSPFv3IFHELLOINTERVAL 9
  114. #define OSPFv3IFRTRDEADINTERVAL 10
  115. #define OSPFv3IFPOLLINTERVAL 11
  116. #define OSPFv3IFSTATE 12
  117. #define OSPFv3IFDESIGNATEDROUTER 13
  118. #define OSPFv3IFBACKUPDESIGNATEDROUTER 14
  119. #define OSPFv3IFEVENTS 15
  120. #define OSPFv3IFROWSTATUS 16
  121. #define OSPFv3IFDEMAND 17
  122. #define OSPFv3IFMETRICVALUE 18
  123. #define OSPFv3IFLINKSCOPELSACOUNT 19
  124. #define OSPFv3IFLINKLSACKSUMSUM 20
  125. #define OSPFv3IFDEMANDNBRPROBE 21
  126. #define OSPFv3IFDEMANDNBRPROBERETRANSLIMIT 22
  127. #define OSPFv3IFDEMANDNBRPROBEINTERVAL 23
  128. #define OSPFv3IFTEDISABLED 24
  129. #define OSPFv3IFLINKLSASUPPRESSION 25
  130. /* OSPFv3 MIB Virtual Interface Table values: ospfv3VirtIfTable */
  131. #define OSPFv3VIRTIFINDEX 3
  132. #define OSPFv3VIRTIFINSTID 4
  133. #define OSPFv3VIRTIFTRANSITDELAY 5
  134. #define OSPFv3VIRTIFRETRANSINTERVAL 6
  135. #define OSPFv3VIRTIFHELLOINTERVAL 7
  136. #define OSPFv3VIRTIFRTRDEADINTERVAL 8
  137. #define OSPFv3VIRTIFSTATE 9
  138. #define OSPFv3VIRTIFEVENTS 10
  139. #define OSPFv3VIRTIFROWSTATUS 11
  140. #define OSPFv3VIRTIFLINKSCOPELSACOUNT 12
  141. #define OSPFv3VIRTIFLINKLSACKSUMSUM 13
  142. /* OSPFv3 MIB Neighbors Table values: ospfv3NbrTable */
  143. #define OSPFv3NBRADDRESSTYPE 4
  144. #define OSPFv3NBRADDRESS 5
  145. #define OSPFv3NBROPTIONS 6
  146. #define OSPFv3NBRPRIORITY 7
  147. #define OSPFv3NBRSTATE 8
  148. #define OSPFv3NBREVENTS 9
  149. #define OSPFv3NBRLSRETRANSQLEN 10
  150. #define OSPFv3NBRHELLOSUPPRESSED 11
  151. #define OSPFv3NBRIFID 12
  152. #define OSPFv3NBRRESTARTHELPERSTATUS 13
  153. #define OSPFv3NBRRESTARTHELPERAGE 14
  154. #define OSPFv3NBRRESTARTHELPEREXITREASON 15
  155. /* OSPFv3 MIB Configured Neighbors Table values: ospfv3CfgNbrTable */
  156. #define OSPFv3CFGNBRPRIORITY 5
  157. #define OSPFv3CFGNBRROWSTATUS 6
  158. /* OSPFv3 MIB Virtual Neighbors Table values: ospfv3VirtNbrTable */
  159. #define OSPFv3VIRTNBRIFINDEX 3
  160. #define OSPFv3VIRTNBRIFINSTID 4
  161. #define OSPFv3VIRTNBRADDRESSTYPE 5
  162. #define OSPFv3VIRTNBRADDRESS 6
  163. #define OSPFv3VIRTNBROPTIONS 7
  164. #define OSPFv3VIRTNBRSTATE 8
  165. #define OSPFv3VIRTNBREVENTS 9
  166. #define OSPFv3VIRTNBRLSRETRANSQLEN 10
  167. #define OSPFv3VIRTNBRHELLOSUPPRESSED 11
  168. #define OSPFv3VIRTNBRIFID 12
  169. #define OSPFv3VIRTNBRRESTARTHELPERSTATUS 13
  170. #define OSPFv3VIRTNBRRESTARTHELPERAGE 14
  171. #define OSPFv3VIRTNBRRESTARTHELPEREXITREASON 15
  172. /* OSPFv3 MIB Area Aggregate Table values: ospfv3AreaAggregateTable */
  173. #define OSPFv3AREAAGGREGATEROWSTATUS 6
  174. #define OSPFv3AREAAGGREGATEEFFECT 7
  175. #define OSPFv3AREAAGGREGATEROUTETAG 8
  176. /* OSPFv3 MIB Virtual Link Lsdb Table values: ospfv3VirtLinkLsdbTable */
  177. #define OSPFv3VIRTLINKLSDBSEQUENCE 6
  178. #define OSPFv3VIRTLINKLSDBAGE 7
  179. #define OSPFv3VIRTLINKLSDBCHECKSUM 8
  180. #define OSPFv3VIRTLINKLSDBADVERTISEMENT 9
  181. #define OSPFv3VIRTLINKLSDBTYPEKNOWN 10
  182. /* SYNTAX Status from OSPF-MIB. */
  183. #define OSPF_STATUS_ENABLED 1
  184. #define OSPF_STATUS_DISABLED 2
  185. /* SNMP value hack. */
  186. #define COUNTER ASN_COUNTER
  187. #define INTEGER ASN_INTEGER
  188. #define GAUGE ASN_GAUGE
  189. #define UNSIGNED ASN_UNSIGNED
  190. #define TIMETICKS ASN_TIMETICKS
  191. #define IPADDRESS ASN_IPADDRESS
  192. #define STRING ASN_OCTET_STR
  193. /* For return values e.g. SNMP_INTEGER macro */
  194. SNMP_LOCAL_VARIABLES
  195. /* OSPFv3-MIB instances. */
  196. oid ospfv3_oid [] = { OSPFv3MIB };
  197. /* Hook functions. */
  198. static u_char *ospfv3GeneralGroup (struct variable *, oid *, size_t *,
  199. int, size_t *, WriteMethod **);
  200. static u_char *ospfv3AreaEntry (struct variable *, oid *, size_t *,
  201. int, size_t *, WriteMethod **);
  202. static u_char *ospfv3AreaLsdbEntry (struct variable *, oid *, size_t *,
  203. int, size_t *, WriteMethod **);
  204. struct variable ospfv3_variables[] =
  205. {
  206. /* OSPF general variables */
  207. {OSPFv3ROUTERID, UNSIGNED, RWRITE, ospfv3GeneralGroup,
  208. 3, {1, 1, 1}},
  209. {OSPFv3ADMINSTAT, INTEGER, RWRITE, ospfv3GeneralGroup,
  210. 3, {1, 1, 2}},
  211. {OSPFv3VERSIONNUMBER, INTEGER, RONLY, ospfv3GeneralGroup,
  212. 3, {1, 1, 3}},
  213. {OSPFv3AREABDRRTRSTATUS, INTEGER, RONLY, ospfv3GeneralGroup,
  214. 3, {1, 1, 4}},
  215. {OSPFv3ASBDRRTRSTATUS, INTEGER, RWRITE, ospfv3GeneralGroup,
  216. 3, {1, 1, 5}},
  217. {OSPFv3ASSCOPELSACOUNT, GAUGE, RONLY, ospfv3GeneralGroup,
  218. 3, {1, 1, 6}},
  219. {OSPFv3ASSCOPELSACHECKSUMSUM,UNSIGNED, RONLY, ospfv3GeneralGroup,
  220. 3, {1, 1, 7}},
  221. {OSPFv3ORIGINATENEWLSAS, COUNTER, RONLY, ospfv3GeneralGroup,
  222. 3, {1, 1, 8}},
  223. {OSPFv3RXNEWLSAS, COUNTER, RONLY, ospfv3GeneralGroup,
  224. 3, {1, 1, 9}},
  225. {OSPFv3EXTLSACOUNT, GAUGE, RONLY, ospfv3GeneralGroup,
  226. 3, {1, 1, 10}},
  227. {OSPFv3EXTAREALSDBLIMIT, INTEGER, RWRITE, ospfv3GeneralGroup,
  228. 3, {1, 1, 11}},
  229. {OSPFv3EXITOVERFLOWINTERVAL, UNSIGNED, RWRITE, ospfv3GeneralGroup,
  230. 3, {1, 1, 12}},
  231. {OSPFv3DEMANDEXTENSIONS, INTEGER, RWRITE, ospfv3GeneralGroup,
  232. 3, {1, 1, 13}},
  233. {OSPFv3REFERENCEBANDWIDTH, UNSIGNED, RWRITE, ospfv3GeneralGroup,
  234. 3, {1, 1, 14}},
  235. {OSPFv3RESTARTSUPPORT, INTEGER, RWRITE, ospfv3GeneralGroup,
  236. 3, {1, 1, 15}},
  237. {OSPFv3RESTARTINTERVAL, UNSIGNED, RWRITE, ospfv3GeneralGroup,
  238. 3, {1, 1, 16}},
  239. {OSPFv3RESTARTSTRICTLSACHECKING, INTEGER, RWRITE, ospfv3GeneralGroup,
  240. 3, {1, 1, 17}},
  241. {OSPFv3RESTARTSTATUS, INTEGER, RONLY, ospfv3GeneralGroup,
  242. 3, {1, 1, 18}},
  243. {OSPFv3RESTARTAGE, UNSIGNED, RONLY, ospfv3GeneralGroup,
  244. 3, {1, 1, 19}},
  245. {OSPFv3RESTARTEXITREASON, INTEGER, RONLY, ospfv3GeneralGroup,
  246. 3, {1, 1, 20}},
  247. {OSPFv3NOTIFICATIONENABLE, INTEGER, RWRITE, ospfv3GeneralGroup,
  248. 3, {1, 1, 21}},
  249. {OSPFv3STUBROUTERSUPPORT, INTEGER, RONLY, ospfv3GeneralGroup,
  250. 3, {1, 1, 22}},
  251. {OSPFv3STUBROUTERADVERTISEMENT, INTEGER, RWRITE, ospfv3GeneralGroup,
  252. 3, {1, 1, 23}},
  253. {OSPFv3DISCONTINUITYTIME, TIMETICKS, RONLY, ospfv3GeneralGroup,
  254. 3, {1, 1, 24}},
  255. {OSPFv3RESTARTTIME, TIMETICKS, RONLY, ospfv3GeneralGroup,
  256. 3, {1, 1, 25}},
  257. /* OSPFv3 Area Data Structure */
  258. {OSPFv3IMPORTASEXTERN, INTEGER, RWRITE, ospfv3AreaEntry,
  259. 4, {1, 2, 1, 2}},
  260. {OSPFv3AREASPFRUNS, COUNTER, RONLY, ospfv3AreaEntry,
  261. 4, {1, 2, 1, 3}},
  262. {OSPFv3AREABDRRTRCOUNT, GAUGE, RONLY, ospfv3AreaEntry,
  263. 4, {1, 2, 1, 4}},
  264. {OSPFv3AREAASBDRRTRCOUNT, GAUGE, RONLY, ospfv3AreaEntry,
  265. 4, {1, 2, 1, 5}},
  266. {OSPFv3AREASCOPELSACOUNT, GAUGE, RONLY, ospfv3AreaEntry,
  267. 4, {1, 2, 1, 6}},
  268. {OSPFv3AREASCOPELSACKSUMSUM, UNSIGNED, RONLY, ospfv3AreaEntry,
  269. 4, {1, 2, 1, 7}},
  270. {OSPFv3AREASUMMARY, INTEGER, RWRITE, ospfv3AreaEntry,
  271. 4, {1, 2, 1, 8}},
  272. {OSPFv3AREAROWSTATUS, INTEGER, RWRITE, ospfv3AreaEntry,
  273. 4, {1, 2, 1, 9}},
  274. {OSPFv3AREASTUBMETRIC, INTEGER, RWRITE, ospfv3AreaEntry,
  275. 4, {1, 2, 1, 10}},
  276. {OSPFv3AREANSSATRANSLATORROLE, INTEGER, RWRITE, ospfv3AreaEntry,
  277. 4, {1, 2, 1, 11}},
  278. {OSPFv3AREANSSATRANSLATORSTATE, INTEGER, RONLY, ospfv3AreaEntry,
  279. 4, {1, 2, 1, 12}},
  280. {OSPFv3AREANSSATRANSLATORSTABINTERVAL, UNSIGNED, RWRITE, ospfv3AreaEntry,
  281. 4, {1, 2, 1, 13}},
  282. {OSPFv3AREANSSATRANSLATOREVENTS, COUNTER, RONLY, ospfv3AreaEntry,
  283. 4, {1, 2, 1, 14}},
  284. {OSPFv3AREASTUBMETRICTYPE, INTEGER, RWRITE, ospfv3AreaEntry,
  285. 4, {1, 2, 1, 15}},
  286. {OSPFv3AREATEENABLED, INTEGER, RWRITE, ospfv3AreaEntry,
  287. 4, {1, 2, 1, 16}},
  288. /* OSPFv3 Area LSDB */
  289. {OSPFv3AREALSDBSEQUENCE, INTEGER, RONLY, ospfv3AreaLsdbEntry,
  290. 4, {1, 4, 1, 5}},
  291. {OSPFv3AREALSDBAGE, UNSIGNED, RONLY, ospfv3AreaLsdbEntry,
  292. 4, {1, 4, 1, 6}},
  293. {OSPFv3AREALSDBCHECKSUM, INTEGER, RONLY, ospfv3AreaLsdbEntry,
  294. 4, {1, 4, 1, 7}},
  295. {OSPFv3AREALSDBADVERTISEMENT, STRING, RONLY, ospfv3AreaLsdbEntry,
  296. 4, {1, 4, 1, 8}},
  297. {OSPFv3AREALSDBTYPEKNOWN, INTEGER, RONLY, ospfv3AreaLsdbEntry,
  298. 4, {1, 4, 1, 9}},
  299. };
  300. static u_char *
  301. ospfv3GeneralGroup (struct variable *v, oid *name, size_t *length,
  302. int exact, size_t *var_len, WriteMethod **write_method)
  303. {
  304. /* Check whether the instance identifier is valid */
  305. if (smux_header_generic (v, name, length, exact, var_len, write_method)
  306. == MATCH_FAILED)
  307. return NULL;
  308. /* Return the current value of the variable */
  309. switch (v->magic)
  310. {
  311. case OSPFv3ROUTERID:
  312. /* Router-ID of this OSPF instance. */
  313. if (ospf6)
  314. return SNMP_INTEGER (ntohl (ospf6->router_id));
  315. return SNMP_INTEGER (0);
  316. case OSPFv3ADMINSTAT:
  317. case OSPFv3VERSIONNUMBER:
  318. case OSPFv3AREABDRRTRSTATUS:
  319. case OSPFv3ASBDRRTRSTATUS:
  320. case OSPFv3ASSCOPELSACOUNT:
  321. case OSPFv3ASSCOPELSACHECKSUMSUM:
  322. case OSPFv3ORIGINATENEWLSAS:
  323. case OSPFv3RXNEWLSAS:
  324. case OSPFv3EXTLSACOUNT:
  325. case OSPFv3EXTAREALSDBLIMIT:
  326. case OSPFv3EXITOVERFLOWINTERVAL:
  327. case OSPFv3DEMANDEXTENSIONS:
  328. case OSPFv3REFERENCEBANDWIDTH:
  329. case OSPFv3RESTARTSUPPORT:
  330. case OSPFv3RESTARTINTERVAL:
  331. case OSPFv3RESTARTSTRICTLSACHECKING:
  332. case OSPFv3RESTARTSTATUS:
  333. case OSPFv3RESTARTAGE:
  334. case OSPFv3RESTARTEXITREASON:
  335. case OSPFv3NOTIFICATIONENABLE:
  336. case OSPFv3STUBROUTERSUPPORT:
  337. case OSPFv3STUBROUTERADVERTISEMENT:
  338. case OSPFv3DISCONTINUITYTIME:
  339. case OSPFv3RESTARTTIME:
  340. /* TODO: Not implemented */
  341. return NULL;
  342. }
  343. return NULL;
  344. }
  345. static u_char *
  346. ospfv3AreaEntry (struct variable *v, oid *name, size_t *length,
  347. int exact, size_t *var_len, WriteMethod **write_method)
  348. {
  349. struct ospf6_area *oa, *area = NULL;
  350. u_int32_t area_id = 0;
  351. struct listnode *node;
  352. unsigned int len;
  353. char a[16];
  354. if (ospf6 == NULL)
  355. return NULL;
  356. if (smux_header_table(v, name, length, exact, var_len, write_method)
  357. == MATCH_FAILED)
  358. return NULL;
  359. len = *length - v->namelen;
  360. len = (len >= 1 ? sizeof 1 : 0);
  361. if (exact && len != 1)
  362. return NULL;
  363. if (len)
  364. area_id = htonl (name[v->namelen]);
  365. inet_ntop (AF_INET, &area_id, a, sizeof (a));
  366. zlog_debug ("SNMP access by area: %s, exact=%d len=%d length=%lu",
  367. a, exact, len, (u_long)*length);
  368. for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa))
  369. {
  370. if (area == NULL)
  371. {
  372. if (len == 0) /* return first area entry */
  373. area = oa;
  374. else if (exact && ntohl (oa->area_id) == ntohl (area_id))
  375. area = oa;
  376. else if (ntohl (oa->area_id) > ntohl (area_id))
  377. area = oa;
  378. }
  379. }
  380. if (area == NULL)
  381. return NULL;
  382. *length = v->namelen + 1;
  383. name[v->namelen] = ntohl (area->area_id);
  384. inet_ntop (AF_INET, &area->area_id, a, sizeof (a));
  385. zlog_debug ("SNMP found area: %s, exact=%d len=%d length=%lu",
  386. a, exact, len, (u_long)*length);
  387. switch (v->magic)
  388. {
  389. case OSPFv3IMPORTASEXTERN:
  390. return SNMP_INTEGER (ospf6->external_table->count);
  391. break;
  392. case OSPFv3AREASPFRUNS:
  393. case OSPFv3AREABDRRTRCOUNT:
  394. case OSPFv3AREAASBDRRTRCOUNT:
  395. case OSPFv3AREASCOPELSACOUNT:
  396. case OSPFv3AREASCOPELSACKSUMSUM:
  397. case OSPFv3AREASUMMARY:
  398. case OSPFv3AREAROWSTATUS:
  399. case OSPFv3AREASTUBMETRIC:
  400. case OSPFv3AREANSSATRANSLATORROLE:
  401. case OSPFv3AREANSSATRANSLATORSTATE:
  402. case OSPFv3AREANSSATRANSLATORSTABINTERVAL:
  403. case OSPFv3AREANSSATRANSLATOREVENTS:
  404. case OSPFv3AREASTUBMETRICTYPE:
  405. case OSPFv3AREATEENABLED:
  406. /* Not implemented. */
  407. return NULL;
  408. }
  409. return NULL;
  410. }
  411. static u_char *
  412. ospfv3AreaLsdbEntry (struct variable *v, oid *name, size_t *length,
  413. int exact, size_t *var_len, WriteMethod **write_method)
  414. {
  415. struct ospf6_lsa *lsa = NULL;
  416. u_int32_t area_id, id, adv_router;
  417. u_int16_t type;
  418. int len;
  419. oid *offset;
  420. int offsetlen;
  421. char a[16], b[16], c[16];
  422. struct ospf6_area *oa;
  423. struct listnode *node;
  424. if (smux_header_table(v, name, length, exact, var_len, write_method)
  425. == MATCH_FAILED)
  426. return NULL;
  427. area_id = type = id = adv_router = 0;
  428. /* Check OSPFv3 instance. */
  429. if (ospf6 == NULL)
  430. return NULL;
  431. /* Get variable length. */
  432. offset = name + v->namelen;
  433. offsetlen = *length - v->namelen;
  434. #define OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET 4
  435. if (exact && offsetlen != OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET)
  436. return NULL;
  437. /* Parse area-id */
  438. len = (offsetlen < 1 ? 0 : 1);
  439. if (len)
  440. area_id = htonl (*offset);
  441. offset += len;
  442. offsetlen -= len;
  443. /* Parse type */
  444. len = (offsetlen < 1 ? 0 : 1);
  445. if (len)
  446. type = htons (*offset);
  447. offset += len;
  448. offsetlen -= len;
  449. /* Parse Router-ID */
  450. len = (offsetlen < 1 ? 0 : 1);
  451. if (len)
  452. adv_router = htonl (*offset);
  453. offset += len;
  454. offsetlen -= len;
  455. /* Parse LS-ID */
  456. len = (offsetlen < 1 ? 0 : 1);
  457. if (len)
  458. id = htonl (*offset);
  459. offset += len;
  460. offsetlen -= len;
  461. inet_ntop (AF_INET, &area_id, a, sizeof (a));
  462. inet_ntop (AF_INET, &adv_router, b, sizeof (b));
  463. inet_ntop (AF_INET, &id, c, sizeof (c));
  464. zlog_debug ("SNMP access by lsdb: area=%s exact=%d length=%lu magic=%d"
  465. " type=%#x adv_router=%s id=%s",
  466. a, exact, (u_long)*length, v->magic, ntohs (type), b, c);
  467. if (exact)
  468. {
  469. oa = ospf6_area_lookup (area_id, ospf6);
  470. lsa = ospf6_lsdb_lookup (type, id, adv_router, oa->lsdb);
  471. }
  472. else
  473. {
  474. for (ALL_LIST_ELEMENTS_RO (ospf6->area_list, node, oa))
  475. {
  476. if (lsa)
  477. continue;
  478. if (oa->area_id < area_id)
  479. continue;
  480. lsa = ospf6_lsdb_lookup_next (type, id, adv_router,
  481. oa->lsdb);
  482. if (! lsa)
  483. {
  484. type = 0;
  485. id = 0;
  486. adv_router = 0;
  487. }
  488. }
  489. }
  490. if (! lsa)
  491. {
  492. zlog_debug ("SNMP respond: No LSA to return");
  493. return NULL;
  494. }
  495. oa = OSPF6_AREA (lsa->lsdb->data);
  496. zlog_debug ("SNMP respond: area: %s lsa: %s", oa->name, lsa->name);
  497. /* Add Index (AreaId, Type, RouterId, Lsid) */
  498. *length = v->namelen + OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET;
  499. offset = name + v->namelen;
  500. *offset = ntohl (oa->area_id);
  501. offset++;
  502. *offset = ntohs (lsa->header->type);
  503. offset++;
  504. *offset = ntohl (lsa->header->adv_router);
  505. offset++;
  506. *offset = ntohl (lsa->header->id);
  507. offset++;
  508. /* Return the current value of the variable */
  509. switch (v->magic)
  510. {
  511. case OSPFv3AREALSDBSEQUENCE:
  512. return SNMP_INTEGER (ntohl (lsa->header->seqnum));
  513. break;
  514. case OSPFv3AREALSDBAGE:
  515. ospf6_lsa_age_current (lsa);
  516. return SNMP_INTEGER (ntohs (lsa->header->age));
  517. break;
  518. case OSPFv3AREALSDBCHECKSUM:
  519. return SNMP_INTEGER (ntohs (lsa->header->checksum));
  520. break;
  521. case OSPFv3AREALSDBADVERTISEMENT:
  522. *var_len = ntohs (lsa->header->length);
  523. return (u_char *) lsa->header;
  524. break;
  525. case OSPFv3AREALSDBTYPEKNOWN:
  526. return SNMP_INTEGER (OSPF6_LSA_IS_KNOWN (lsa->header->type) ?
  527. SNMP_TRUE : SNMP_FALSE);
  528. break;
  529. }
  530. return NULL;
  531. }
  532. /* Register OSPFv3-MIB. */
  533. void
  534. ospf6_snmp_init (struct thread_master *master)
  535. {
  536. smux_init (master);
  537. REGISTER_MIB ("OSPFv3MIB", ospfv3_variables, variable, ospfv3_oid);
  538. }
  539. #endif /* HAVE_SNMP */