hasso | ef1bbf5 | 2004-10-08 12:04:21 +0000 | [diff] [blame] | 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 | |
| 22 | #include <zebra.h> |
| 23 | |
| 24 | #ifdef HAVE_SNMP |
| 25 | |
| 26 | #ifdef HAVE_NETSNMP |
| 27 | #include <net-snmp/net-snmp-config.h> |
| 28 | #endif /*HAVE_NETSNMP*/ |
| 29 | |
| 30 | #include <asn1.h> |
| 31 | #include <snmp.h> |
| 32 | #include <snmp_impl.h> |
| 33 | |
| 34 | #include "log.h" |
| 35 | #include "vty.h" |
| 36 | #include "linklist.h" |
| 37 | #include "smux.h" |
| 38 | |
| 39 | #include "ospf6_proto.h" |
| 40 | #include "ospf6_lsa.h" |
| 41 | #include "ospf6_lsdb.h" |
| 42 | #include "ospf6_route.h" |
| 43 | #include "ospf6_top.h" |
| 44 | #include "ospf6_area.h" |
| 45 | #include "ospf6_interface.h" |
| 46 | #include "ospf6_message.h" |
| 47 | #include "ospf6_neighbor.h" |
| 48 | #include "ospf6d.h" |
| 49 | |
| 50 | /* OSPFv3-MIB */ |
| 51 | #define OSPFv3MIB 1,3,6,1,3,102 |
| 52 | |
hasso | ef1bbf5 | 2004-10-08 12:04:21 +0000 | [diff] [blame] | 53 | /* OSPFv3 MIB General Group values. */ |
| 54 | #define OSPFv3ROUTERID 1 |
| 55 | #define OSPFv3ADMINSTAT 2 |
| 56 | #define OSPFv3VERSIONNUMBER 3 |
| 57 | #define OSPFv3AREABDRRTRSTATUS 4 |
| 58 | #define OSPFv3ASBDRRTRSTATUS 5 |
| 59 | #define OSPFv3ASSCOPELSACOUNT 6 |
| 60 | #define OSPFv3ASSCOPELSACHECKSUMSUM 7 |
| 61 | #define OSPFv3ORIGINATENEWLSAS 8 |
| 62 | #define OSPFv3RXNEWLSAS 9 |
| 63 | #define OSPFv3EXTLSACOUNT 10 |
| 64 | #define OSPFv3EXTAREALSDBLIMIT 11 |
| 65 | #define OSPFv3MULTICASTEXTENSIONS 12 |
| 66 | #define OSPFv3EXITOVERFLOWINTERVAL 13 |
| 67 | #define OSPFv3DEMANDEXTENSIONS 14 |
| 68 | #define OSPFv3TRAFFICENGINEERINGSUPPORT 15 |
| 69 | #define OSPFv3REFERENCEBANDWIDTH 16 |
| 70 | #define OSPFv3RESTARTSUPPORT 17 |
| 71 | #define OSPFv3RESTARTINTERVAL 18 |
| 72 | #define OSPFv3RESTARTSTATUS 19 |
| 73 | #define OSPFv3RESTARTAGE 20 |
| 74 | #define OSPFv3RESTARTEXITREASON 21 |
| 75 | |
| 76 | /* OSPFv3 MIB Area Table values. */ |
| 77 | #define OSPFv3AREAID 1 |
| 78 | #define OSPFv3IMPORTASEXTERN 2 |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 79 | #define OSPFv3AREASPFRUNS 3 |
| 80 | #define OSPFv3AREABDRRTRCOUNT 4 |
| 81 | #define OSPFv3AREAASBDRRTRCOUNT 5 |
| 82 | #define OSPFv3AREASCOPELSACOUNT 6 |
| 83 | #define OSPFv3AREASCOPELSACKSUMSUM 7 |
| 84 | #define OSPFv3AREASUMMARY 8 |
| 85 | #define OSPFv3AREASTATUS 9 |
| 86 | #define OSPFv3STUBMETRIC 10 |
| 87 | #define OSPFv3AREANSSATRANSLATORROLE 11 |
| 88 | #define OSPFv3AREANSSATRANSLATORSTATE 12 |
| 89 | #define OSPFv3AREANSSATRANSLATORSTABILITYINTERVAL 13 |
| 90 | #define OSPFv3AREANSSATRANSLATOREVENTS 14 |
| 91 | #define OSPFv3AREASTUBMETRICTYPE 15 |
| 92 | |
| 93 | /* OSPFv3 MIB Area Lsdb Table values. */ |
| 94 | #define OSPFv3AREALSDBAREAID 1 |
| 95 | #define OSPFv3AREALSDBTYPE 2 |
| 96 | #define OSPFv3AREALSDBROUTERID 3 |
| 97 | #define OSPFv3AREALSDBLSID 4 |
| 98 | #define OSPFv3AREALSDBSEQUENCE 5 |
| 99 | #define OSPFv3AREALSDBAGE 6 |
| 100 | #define OSPFv3AREALSDBCHECKSUM 7 |
| 101 | #define OSPFv3AREALSDBADVERTISEMENT 8 |
| 102 | #define OSPFv3AREALSDBTYPEKNOWN 9 |
hasso | ef1bbf5 | 2004-10-08 12:04:21 +0000 | [diff] [blame] | 103 | |
| 104 | /* SYNTAX Status from OSPF-MIB. */ |
| 105 | #define OSPF_STATUS_ENABLED 1 |
| 106 | #define OSPF_STATUS_DISABLED 2 |
| 107 | |
| 108 | /* SNMP value hack. */ |
| 109 | #define COUNTER ASN_COUNTER |
| 110 | #define INTEGER ASN_INTEGER |
| 111 | #define GAUGE ASN_GAUGE |
| 112 | #define TIMETICKS ASN_TIMETICKS |
| 113 | #define IPADDRESS ASN_IPADDRESS |
| 114 | #define STRING ASN_OCTET_STR |
| 115 | |
| 116 | /* For return values e.g. SNMP_INTEGER macro */ |
| 117 | SNMP_LOCAL_VARIABLES |
| 118 | |
| 119 | static struct in_addr tmp; |
| 120 | #define INT32_INADDR(x) \ |
| 121 | (tmp.s_addr = (x), tmp) |
| 122 | |
| 123 | /* OSPFv3-MIB instances. */ |
| 124 | oid ospfv3_oid [] = { OSPFv3MIB }; |
hasso | ef1bbf5 | 2004-10-08 12:04:21 +0000 | [diff] [blame] | 125 | |
| 126 | /* empty ID 0.0.0.0 e.g. empty router-id */ |
| 127 | static struct in_addr ospf6_empty_id = {0}; |
| 128 | |
| 129 | /* Hook functions. */ |
| 130 | static u_char *ospfv3GeneralGroup (); |
| 131 | static u_char *ospfv3AreaEntry (); |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 132 | static u_char *ospfv3AreaLsdbEntry (); |
hasso | ef1bbf5 | 2004-10-08 12:04:21 +0000 | [diff] [blame] | 133 | |
| 134 | struct variable ospfv3_variables[] = |
| 135 | { |
| 136 | /* OSPF general variables */ |
| 137 | {OSPFv3ROUTERID, IPADDRESS, RWRITE, ospfv3GeneralGroup, |
| 138 | 3, {1, 1, 1}}, |
| 139 | {OSPFv3ADMINSTAT, INTEGER, RWRITE, ospfv3GeneralGroup, |
| 140 | 3, {1, 1, 2}}, |
| 141 | {OSPFv3VERSIONNUMBER, INTEGER, RONLY, ospfv3GeneralGroup, |
| 142 | 3, {1, 1, 3}}, |
| 143 | {OSPFv3AREABDRRTRSTATUS, INTEGER, RONLY, ospfv3GeneralGroup, |
| 144 | 3, {1, 1, 4}}, |
| 145 | {OSPFv3ASBDRRTRSTATUS, INTEGER, RWRITE, ospfv3GeneralGroup, |
| 146 | 3, {1, 1, 5}}, |
| 147 | {OSPFv3ASSCOPELSACOUNT, GAUGE, RONLY, ospfv3GeneralGroup, |
| 148 | 3, {1, 1, 6}}, |
| 149 | {OSPFv3ASSCOPELSACHECKSUMSUM, INTEGER, RONLY, ospfv3GeneralGroup, |
| 150 | 3, {1, 1, 7}}, |
| 151 | {OSPFv3ORIGINATENEWLSAS, COUNTER, RONLY, ospfv3GeneralGroup, |
| 152 | 3, {1, 1, 8}}, |
| 153 | {OSPFv3RXNEWLSAS, COUNTER, RONLY, ospfv3GeneralGroup, |
| 154 | 3, {1, 1, 9}}, |
| 155 | {OSPFv3EXTLSACOUNT, GAUGE, RONLY, ospfv3GeneralGroup, |
| 156 | 3, {1, 1, 10}}, |
| 157 | {OSPFv3EXTAREALSDBLIMIT, INTEGER, RWRITE, ospfv3GeneralGroup, |
| 158 | 3, {1, 1, 11}}, |
| 159 | {OSPFv3MULTICASTEXTENSIONS, INTEGER, RWRITE, ospfv3GeneralGroup, |
| 160 | 3, {1, 1, 12}}, |
| 161 | {OSPFv3EXITOVERFLOWINTERVAL, INTEGER, RWRITE, ospfv3GeneralGroup, |
| 162 | 3, {1, 1, 13}}, |
| 163 | {OSPFv3DEMANDEXTENSIONS, INTEGER, RWRITE, ospfv3GeneralGroup, |
| 164 | 3, {1, 1, 14}}, |
| 165 | {OSPFv3TRAFFICENGINEERINGSUPPORT, INTEGER, RWRITE, ospfv3GeneralGroup, |
| 166 | 3, {1, 1, 15}}, |
| 167 | {OSPFv3REFERENCEBANDWIDTH, INTEGER, RWRITE, ospfv3GeneralGroup, |
| 168 | 3, {1, 1, 16}}, |
| 169 | {OSPFv3RESTARTSUPPORT, INTEGER, RWRITE, ospfv3GeneralGroup, |
| 170 | 3, {1, 1, 17}}, |
| 171 | {OSPFv3RESTARTINTERVAL, INTEGER, RWRITE, ospfv3GeneralGroup, |
| 172 | 3, {1, 1, 18}}, |
| 173 | {OSPFv3RESTARTSTATUS, INTEGER, RONLY, ospfv3GeneralGroup, |
| 174 | 3, {1, 1, 19}}, |
| 175 | {OSPFv3RESTARTAGE, INTEGER, RONLY, ospfv3GeneralGroup, |
| 176 | 3, {1, 1, 20}}, |
| 177 | {OSPFv3RESTARTEXITREASON, INTEGER, RONLY, ospfv3GeneralGroup, |
| 178 | 3, {1, 1, 21}}, |
| 179 | |
| 180 | /* OSPFv3 Area Data Structure */ |
| 181 | {OSPFv3AREAID, IPADDRESS, RONLY, ospfv3AreaEntry, |
| 182 | 4, {1, 2, 1, 1}}, |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 183 | {OSPFv3IMPORTASEXTERN, INTEGER, RWRITE, ospfv3AreaEntry, |
hasso | ef1bbf5 | 2004-10-08 12:04:21 +0000 | [diff] [blame] | 184 | 4, {1, 2, 1, 2}}, |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 185 | {OSPFv3AREASPFRUNS, COUNTER, RONLY, ospfv3AreaEntry, |
| 186 | 4, {1, 2, 1, 3}}, |
| 187 | {OSPFv3AREABDRRTRCOUNT, GAUGE, RONLY, ospfv3AreaEntry, |
| 188 | 4, {1, 2, 1, 4}}, |
| 189 | {OSPFv3AREAASBDRRTRCOUNT, GAUGE, RONLY, ospfv3AreaEntry, |
| 190 | 4, {1, 2, 1, 5}}, |
| 191 | {OSPFv3AREASCOPELSACOUNT, GAUGE, RONLY, ospfv3AreaEntry, |
| 192 | 4, {1, 2, 1, 6}}, |
| 193 | {OSPFv3AREASCOPELSACKSUMSUM, INTEGER, RONLY, ospfv3AreaEntry, |
| 194 | 4, {1, 2, 1, 7}}, |
| 195 | {OSPFv3AREASUMMARY, INTEGER, RWRITE, ospfv3AreaEntry, |
| 196 | 4, {1, 2, 1, 8}}, |
| 197 | {OSPFv3AREASTATUS, INTEGER, RWRITE, ospfv3AreaEntry, |
| 198 | 4, {1, 2, 1, 9}}, |
| 199 | {OSPFv3STUBMETRIC, INTEGER, RWRITE, ospfv3AreaEntry, |
| 200 | 4, {1, 2, 1, 10}}, |
| 201 | {OSPFv3AREANSSATRANSLATORROLE, INTEGER, RWRITE, ospfv3AreaEntry, |
| 202 | 4, {1, 2, 1, 11}}, |
| 203 | {OSPFv3AREANSSATRANSLATORSTATE, INTEGER, RONLY, ospfv3AreaEntry, |
| 204 | 4, {1, 2, 1, 12}}, |
| 205 | {OSPFv3AREANSSATRANSLATORSTABILITYINTERVAL, INTEGER, RWRITE, ospfv3AreaEntry, |
| 206 | 4, {1, 2, 1, 13}}, |
| 207 | {OSPFv3AREANSSATRANSLATOREVENTS, COUNTER, RONLY, ospfv3AreaEntry, |
| 208 | 4, {1, 2, 1, 14}}, |
| 209 | {OSPFv3AREASTUBMETRICTYPE, INTEGER, RWRITE, ospfv3AreaEntry, |
| 210 | 4, {1, 2, 1, 15}}, |
| 211 | |
| 212 | {OSPFv3AREALSDBAREAID, IPADDRESS, RONLY, ospfv3AreaLsdbEntry, |
| 213 | 4, {1, 4, 1, 1}}, |
| 214 | {OSPFv3AREALSDBTYPE, GAUGE, RONLY, ospfv3AreaLsdbEntry, |
| 215 | 4, {1, 4, 1, 2}}, |
| 216 | {OSPFv3AREALSDBROUTERID, IPADDRESS, RONLY, ospfv3AreaLsdbEntry, |
| 217 | 4, {1, 4, 1, 3}}, |
| 218 | {OSPFv3AREALSDBLSID, IPADDRESS, RONLY, ospfv3AreaLsdbEntry, |
| 219 | 4, {1, 4, 1, 4}}, |
| 220 | {OSPFv3AREALSDBSEQUENCE, INTEGER, RONLY, ospfv3AreaLsdbEntry, |
| 221 | 4, {1, 4, 1, 5}}, |
| 222 | {OSPFv3AREALSDBAGE, INTEGER, RONLY, ospfv3AreaLsdbEntry, |
| 223 | 4, {1, 4, 1, 6}}, |
| 224 | {OSPFv3AREALSDBCHECKSUM, INTEGER, RONLY, ospfv3AreaLsdbEntry, |
| 225 | 4, {1, 4, 1, 7}}, |
| 226 | {OSPFv3AREALSDBADVERTISEMENT, STRING, RONLY, ospfv3AreaLsdbEntry, |
| 227 | 4, {1, 4, 1, 8}}, |
| 228 | {OSPFv3AREALSDBTYPEKNOWN, INTEGER, RONLY, ospfv3AreaLsdbEntry, |
| 229 | 4, {1, 4, 1, 9}}, |
| 230 | |
hasso | ef1bbf5 | 2004-10-08 12:04:21 +0000 | [diff] [blame] | 231 | }; |
| 232 | |
| 233 | static u_char * |
| 234 | ospfv3GeneralGroup (struct variable *v, oid *name, size_t *length, |
| 235 | int exact, size_t *var_len, WriteMethod **write_method) |
| 236 | { |
| 237 | /* Check whether the instance identifier is valid */ |
| 238 | if (smux_header_generic (v, name, length, exact, var_len, write_method) |
| 239 | == MATCH_FAILED) |
| 240 | return NULL; |
| 241 | |
| 242 | /* Return the current value of the variable */ |
| 243 | switch (v->magic) |
| 244 | { |
| 245 | case OSPFv3ROUTERID: /* 1*/ |
| 246 | /* Router-ID of this OSPF instance. */ |
| 247 | if (ospf6) |
| 248 | return SNMP_IPADDRESS (INT32_INADDR (ospf6->router_id)); |
| 249 | else |
| 250 | return SNMP_IPADDRESS (ospf6_empty_id); |
| 251 | break; |
| 252 | case OSPFv3ADMINSTAT: /* 2*/ |
| 253 | break; |
| 254 | case OSPFv3VERSIONNUMBER: /* 3*/ |
| 255 | break; |
| 256 | case OSPFv3AREABDRRTRSTATUS: /* 4*/ |
| 257 | break; |
| 258 | case OSPFv3ASBDRRTRSTATUS: /* 5*/ |
| 259 | break; |
| 260 | case OSPFv3ASSCOPELSACOUNT: /* 6*/ |
| 261 | break; |
| 262 | case OSPFv3ASSCOPELSACHECKSUMSUM: /* 7*/ |
| 263 | break; |
| 264 | case OSPFv3ORIGINATENEWLSAS: /* 8*/ |
| 265 | break; |
| 266 | case OSPFv3RXNEWLSAS: /* 9*/ |
| 267 | break; |
| 268 | case OSPFv3EXTLSACOUNT: /*10*/ |
| 269 | break; |
| 270 | case OSPFv3EXTAREALSDBLIMIT: /*11*/ |
| 271 | break; |
| 272 | case OSPFv3MULTICASTEXTENSIONS: /*12*/ |
| 273 | break; |
| 274 | case OSPFv3EXITOVERFLOWINTERVAL: /*13*/ |
| 275 | break; |
| 276 | case OSPFv3DEMANDEXTENSIONS: /*14*/ |
| 277 | break; |
| 278 | case OSPFv3TRAFFICENGINEERINGSUPPORT: /*15*/ |
| 279 | break; |
| 280 | case OSPFv3REFERENCEBANDWIDTH: /*16*/ |
| 281 | break; |
| 282 | case OSPFv3RESTARTSUPPORT: /*17*/ |
| 283 | break; |
| 284 | case OSPFv3RESTARTINTERVAL: /*18*/ |
| 285 | break; |
| 286 | case OSPFv3RESTARTSTATUS: /*19*/ |
| 287 | break; |
| 288 | case OSPFv3RESTARTAGE: /*20*/ |
| 289 | break; |
| 290 | case OSPFv3RESTARTEXITREASON: /*21*/ |
| 291 | break; |
| 292 | default: |
| 293 | return NULL; |
| 294 | } |
| 295 | return NULL; |
| 296 | } |
| 297 | |
| 298 | static u_char * |
| 299 | ospfv3AreaEntry (struct variable *v, oid *name, size_t *length, |
| 300 | int exact, size_t *var_len, WriteMethod **write_method) |
| 301 | { |
| 302 | struct ospf6_area *oa, *area = NULL; |
| 303 | u_int32_t area_id = 0; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 304 | struct listnode *node; |
| 305 | unsigned int len; |
hasso | ef1bbf5 | 2004-10-08 12:04:21 +0000 | [diff] [blame] | 306 | |
| 307 | if (ospf6 == NULL) |
| 308 | return NULL; |
| 309 | |
| 310 | len = *length - v->namelen; |
| 311 | len = (len >= sizeof (u_int32_t) ? sizeof (u_int32_t) : 0); |
| 312 | if (exact && len != sizeof (u_int32_t)) |
| 313 | return NULL; |
| 314 | if (len) |
| 315 | oid2in_addr (name + v->namelen, len, (struct in_addr *) &area_id); |
| 316 | |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 317 | zlog_debug ("SNMP access by area: %s, exact=%d len=%d length=%d", |
| 318 | inet_ntoa (* (struct in_addr *) &area_id), |
| 319 | exact, len, *length); |
hasso | ef1bbf5 | 2004-10-08 12:04:21 +0000 | [diff] [blame] | 320 | |
| 321 | for (node = listhead (ospf6->area_list); node; nextnode (node)) |
| 322 | { |
| 323 | oa = (struct ospf6_area *) getdata (node); |
| 324 | if (area == NULL) |
| 325 | { |
| 326 | if (len == 0) /* return first area entry */ |
| 327 | area = oa; |
| 328 | else if (exact && ntohl (oa->area_id) == ntohl (area_id)) |
| 329 | area = oa; |
| 330 | else if (ntohl (oa->area_id) > ntohl (area_id)) |
| 331 | area = oa; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | if (area == NULL) |
| 336 | return NULL; |
| 337 | |
| 338 | *length = v->namelen + sizeof (u_int32_t); |
| 339 | oid_copy_addr (name + v->namelen, (struct in_addr *) &area->area_id, |
| 340 | sizeof (u_int32_t)); |
| 341 | |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 342 | zlog_debug ("SNMP found area: %s, exact=%d len=%d length=%d", |
| 343 | inet_ntoa (* (struct in_addr *) &area->area_id), |
| 344 | exact, len, *length); |
hasso | ef1bbf5 | 2004-10-08 12:04:21 +0000 | [diff] [blame] | 345 | |
| 346 | switch (v->magic) |
| 347 | { |
| 348 | case OSPFv3AREAID: /* 1*/ |
| 349 | return SNMP_IPADDRESS (INT32_INADDR (area->area_id)); |
| 350 | break; |
| 351 | case OSPFv3IMPORTASEXTERN: /* 2*/ |
| 352 | return SNMP_INTEGER (ospf6->external_table->count); |
| 353 | break; |
| 354 | default: |
| 355 | return NULL; |
| 356 | break; |
| 357 | } |
| 358 | return NULL; |
| 359 | } |
| 360 | |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 361 | static u_char * |
| 362 | ospfv3AreaLsdbEntry (struct variable *v, oid *name, size_t *length, |
| 363 | int exact, size_t *var_len, WriteMethod **write_method) |
| 364 | { |
| 365 | struct ospf6_lsa *lsa = NULL; |
| 366 | struct in_addr area_id; |
| 367 | u_int16_t type; |
| 368 | struct in_addr id; |
| 369 | struct in_addr adv_router; |
| 370 | int len; |
| 371 | oid *offset; |
| 372 | int offsetlen; |
| 373 | char a[16], b[16], c[16]; |
| 374 | struct ospf6_area *oa; |
hasso | b3c8c46 | 2004-11-26 12:55:51 +0000 | [diff] [blame] | 375 | struct listnode *node; |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 376 | |
| 377 | memset (&area_id, 0, sizeof (struct in_addr)); |
| 378 | type = 0; |
| 379 | memset (&id, 0, sizeof (struct in_addr)); |
| 380 | memset (&adv_router, 0, sizeof (struct in_addr)); |
| 381 | |
| 382 | /* Check OSPFv3 instance. */ |
| 383 | if (ospf6 == NULL) |
| 384 | return NULL; |
| 385 | |
| 386 | /* Get variable length. */ |
| 387 | offset = name + v->namelen; |
| 388 | offsetlen = *length - v->namelen; |
| 389 | |
| 390 | #define OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET \ |
| 391 | (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE) |
| 392 | |
| 393 | if (exact && offsetlen != OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET) |
| 394 | return NULL; |
| 395 | |
| 396 | /* Parse area-id */ |
| 397 | len = (offsetlen < IN_ADDR_SIZE ? offsetlen : IN_ADDR_SIZE); |
| 398 | if (len) |
| 399 | oid2in_addr (offset, len, &area_id); |
| 400 | offset += len; |
| 401 | offsetlen -= len; |
| 402 | |
| 403 | /* Parse type */ |
| 404 | len = (offsetlen < 1 ? offsetlen : 1); |
| 405 | if (len) |
| 406 | type = htons (*offset); |
| 407 | offset += len; |
| 408 | offsetlen -= len; |
| 409 | |
| 410 | /* Parse Router-ID */ |
| 411 | len = (offsetlen < IN_ADDR_SIZE ? offsetlen : IN_ADDR_SIZE); |
| 412 | if (len) |
| 413 | oid2in_addr (offset, len, &adv_router); |
| 414 | offset += len; |
| 415 | offsetlen -= len; |
| 416 | |
| 417 | /* Parse LS-ID */ |
| 418 | len = (offsetlen < IN_ADDR_SIZE ? offsetlen : IN_ADDR_SIZE); |
| 419 | if (len) |
| 420 | oid2in_addr (offset, len, &id); |
| 421 | offset += len; |
| 422 | offsetlen -= len; |
| 423 | |
| 424 | inet_ntop (AF_INET, &area_id, a, sizeof (a)); |
| 425 | inet_ntop (AF_INET, &adv_router, b, sizeof (b)); |
| 426 | inet_ntop (AF_INET, &id, c, sizeof (c)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 427 | zlog_debug ("SNMP access by lsdb: area=%s exact=%d length=%d magic=%d" |
| 428 | " type=%#x adv_router=%s id=%s", |
| 429 | a, exact, *length, v->magic, ntohs (type), b, c); |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 430 | |
| 431 | if (exact) |
| 432 | { |
| 433 | oa = ospf6_area_lookup (area_id.s_addr, ospf6); |
| 434 | lsa = ospf6_lsdb_lookup (type, id.s_addr, adv_router.s_addr, oa->lsdb); |
| 435 | } |
| 436 | else |
| 437 | { |
| 438 | for (node = listhead (ospf6->area_list); node; nextnode (node)) |
| 439 | { |
| 440 | oa = (struct ospf6_area *) getdata (node); |
| 441 | |
| 442 | if (lsa) |
| 443 | continue; |
| 444 | if (ntohl (oa->area_id) < ntohl (area_id.s_addr)) |
| 445 | continue; |
| 446 | |
| 447 | lsa = ospf6_lsdb_lookup_next (type, id.s_addr, adv_router.s_addr, |
| 448 | oa->lsdb); |
| 449 | if (! lsa) |
| 450 | { |
| 451 | type = 0; |
| 452 | memset (&id, 0, sizeof (struct in_addr)); |
| 453 | memset (&adv_router, 0, sizeof (struct in_addr)); |
| 454 | } |
| 455 | } |
| 456 | } |
| 457 | |
| 458 | if (! lsa) |
| 459 | { |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 460 | zlog_debug ("SNMP respond: No LSA to return"); |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 461 | return NULL; |
| 462 | } |
| 463 | oa = OSPF6_AREA (lsa->lsdb->data); |
| 464 | |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 465 | zlog_debug ("SNMP respond: area: %s lsa: %s", oa->name, lsa->name); |
hasso | 2680aa2 | 2004-11-25 20:54:46 +0000 | [diff] [blame] | 466 | |
| 467 | /* Add Index (AreaId, Type, RouterId, Lsid) */ |
| 468 | *length = v->namelen + OSPFV3_AREA_LSDB_ENTRY_EXACT_OFFSET; |
| 469 | offset = name + v->namelen; |
| 470 | oid_copy_addr (offset, (struct in_addr *) &oa->area_id, IN_ADDR_SIZE); |
| 471 | offset += IN_ADDR_SIZE; |
| 472 | *offset = ntohs (lsa->header->type); |
| 473 | offset++; |
| 474 | oid_copy_addr (offset, (struct in_addr *) &lsa->header->adv_router, |
| 475 | IN_ADDR_SIZE); |
| 476 | offset += IN_ADDR_SIZE; |
| 477 | oid_copy_addr (offset, (struct in_addr *) &lsa->header->id, IN_ADDR_SIZE); |
| 478 | offset += IN_ADDR_SIZE; |
| 479 | |
| 480 | /* Return the current value of the variable */ |
| 481 | switch (v->magic) |
| 482 | { |
| 483 | case OSPFv3AREALSDBAREAID: /* 1 */ |
| 484 | area_id.s_addr = OSPF6_AREA (lsa->lsdb->data)->area_id; |
| 485 | return SNMP_IPADDRESS (area_id); |
| 486 | break; |
| 487 | case OSPFv3AREALSDBTYPE: /* 2 */ |
| 488 | return SNMP_INTEGER (ntohs (lsa->header->type)); |
| 489 | break; |
| 490 | case OSPFv3AREALSDBROUTERID: /* 3 */ |
| 491 | adv_router.s_addr = lsa->header->adv_router; |
| 492 | return SNMP_IPADDRESS (adv_router); |
| 493 | break; |
| 494 | case OSPFv3AREALSDBLSID: /* 4 */ |
| 495 | id.s_addr = lsa->header->id; |
| 496 | return SNMP_IPADDRESS (id); |
| 497 | break; |
| 498 | case OSPFv3AREALSDBSEQUENCE: /* 5 */ |
| 499 | return SNMP_INTEGER (lsa->header->seqnum); |
| 500 | break; |
| 501 | case OSPFv3AREALSDBAGE: /* 6 */ |
| 502 | ospf6_lsa_age_current (lsa); |
| 503 | return SNMP_INTEGER (lsa->header->age); |
| 504 | break; |
| 505 | case OSPFv3AREALSDBCHECKSUM: /* 7 */ |
| 506 | return SNMP_INTEGER (lsa->header->checksum); |
| 507 | break; |
| 508 | case OSPFv3AREALSDBADVERTISEMENT: /* 8 */ |
| 509 | *var_len = ntohs (lsa->header->length); |
| 510 | return (u_char *) lsa->header; |
| 511 | break; |
| 512 | case OSPFv3AREALSDBTYPEKNOWN: /* 9 */ |
| 513 | return SNMP_INTEGER (OSPF6_LSA_IS_KNOWN (lsa->header->type) ? |
| 514 | SNMP_TRUE : SNMP_FALSE); |
| 515 | break; |
| 516 | default: |
| 517 | return NULL; |
| 518 | break; |
| 519 | } |
| 520 | return NULL; |
| 521 | } |
| 522 | |
| 523 | |
hasso | ef1bbf5 | 2004-10-08 12:04:21 +0000 | [diff] [blame] | 524 | /* Register OSPFv3-MIB. */ |
| 525 | void |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 526 | ospf6_snmp_init (struct thread_master *master) |
hasso | ef1bbf5 | 2004-10-08 12:04:21 +0000 | [diff] [blame] | 527 | { |
hasso | c75105a | 2004-10-13 10:33:26 +0000 | [diff] [blame] | 528 | smux_init (master); |
hasso | ef1bbf5 | 2004-10-08 12:04:21 +0000 | [diff] [blame] | 529 | REGISTER_MIB ("OSPFv3MIB", ospfv3_variables, variable, ospfv3_oid); |
hasso | ef1bbf5 | 2004-10-08 12:04:21 +0000 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | #endif /* HAVE_SNMP */ |
| 533 | |