2 * Copyright (C) 2005 6WIND <alain.ritoux@6wind.com>
3 * Copyright (C) 2000 IP Infusion Inc.
5 * Written by Kunihiro Ishiguro <kunihiro@zebra.org>
7 * This file is part of GNU Zebra.
9 * GNU Zebra is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation; either version 2, or (at your option) any
14 * GNU Zebra is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with GNU Zebra; see the file COPYING. If not, write to the Free
21 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
29 #include <net-snmp/net-snmp-config.h>
30 #include <net-snmp/net-snmp-includes.h>
34 #include <snmp_impl.h>
45 #include "ospfd/ospfd.h"
46 #include "ospfd/ospf_interface.h"
47 #include "ospfd/ospf_asbr.h"
48 #include "ospfd/ospf_lsa.h"
49 #include "ospfd/ospf_lsdb.h"
50 #include "ospfd/ospf_abr.h"
51 #include "ospfd/ospf_neighbor.h"
52 #include "ospfd/ospf_nsm.h"
53 #include "ospfd/ospf_flood.h"
54 #include "ospfd/ospf_ism.h"
55 #include "ospfd/ospf_dump.h"
56 #include "ospfd/ospf_snmp.h"
59 #define OSPF2MIB 1,3,6,1,2,1,14
61 /* OSPF MIB General Group values. */
62 #define OSPFROUTERID 1
63 #define OSPFADMINSTAT 2
64 #define OSPFVERSIONNUMBER 3
65 #define OSPFAREABDRRTRSTATUS 4
66 #define OSPFASBDRRTRSTATUS 5
67 #define OSPFEXTERNLSACOUNT 6
68 #define OSPFEXTERNLSACKSUMSUM 7
69 #define OSPFTOSSUPPORT 8
70 #define OSPFORIGINATENEWLSAS 9
71 #define OSPFRXNEWLSAS 10
72 #define OSPFEXTLSDBLIMIT 11
73 #define OSPFMULTICASTEXTENSIONS 12
74 #define OSPFEXITOVERFLOWINTERVAL 13
75 #define OSPFDEMANDEXTENSIONS 14
77 /* OSPF MIB ospfAreaTable. */
79 #define OSPFAUTHTYPE 2
80 #define OSPFIMPORTASEXTERN 3
82 #define OSPFAREABDRRTRCOUNT 5
83 #define OSPFASBDRRTRCOUNT 6
84 #define OSPFAREALSACOUNT 7
85 #define OSPFAREALSACKSUMSUM 8
86 #define OSPFAREASUMMARY 9
87 #define OSPFAREASTATUS 10
89 /* OSPF MIB ospfStubAreaTable. */
90 #define OSPFSTUBAREAID 1
92 #define OSPFSTUBMETRIC 3
93 #define OSPFSTUBSTATUS 4
94 #define OSPFSTUBMETRICTYPE 5
96 /* OSPF MIB ospfLsdbTable. */
97 #define OSPFLSDBAREAID 1
98 #define OSPFLSDBTYPE 2
99 #define OSPFLSDBLSID 3
100 #define OSPFLSDBROUTERID 4
101 #define OSPFLSDBSEQUENCE 5
102 #define OSPFLSDBAGE 6
103 #define OSPFLSDBCHECKSUM 7
104 #define OSPFLSDBADVERTISEMENT 8
106 /* OSPF MIB ospfAreaRangeTable. */
107 #define OSPFAREARANGEAREAID 1
108 #define OSPFAREARANGENET 2
109 #define OSPFAREARANGEMASK 3
110 #define OSPFAREARANGESTATUS 4
111 #define OSPFAREARANGEEFFECT 5
113 /* OSPF MIB ospfHostTable. */
114 #define OSPFHOSTIPADDRESS 1
115 #define OSPFHOSTTOS 2
116 #define OSPFHOSTMETRIC 3
117 #define OSPFHOSTSTATUS 4
118 #define OSPFHOSTAREAID 5
120 /* OSPF MIB ospfIfTable. */
121 #define OSPFIFIPADDRESS 1
122 #define OSPFADDRESSLESSIF 2
123 #define OSPFIFAREAID 3
125 #define OSPFIFADMINSTAT 5
126 #define OSPFIFRTRPRIORITY 6
127 #define OSPFIFTRANSITDELAY 7
128 #define OSPFIFRETRANSINTERVAL 8
129 #define OSPFIFHELLOINTERVAL 9
130 #define OSPFIFRTRDEADINTERVAL 10
131 #define OSPFIFPOLLINTERVAL 11
132 #define OSPFIFSTATE 12
133 #define OSPFIFDESIGNATEDROUTER 13
134 #define OSPFIFBACKUPDESIGNATEDROUTER 14
135 #define OSPFIFEVENTS 15
136 #define OSPFIFAUTHKEY 16
137 #define OSPFIFSTATUS 17
138 #define OSPFIFMULTICASTFORWARDING 18
139 #define OSPFIFDEMAND 19
140 #define OSPFIFAUTHTYPE 20
142 /* OSPF MIB ospfIfMetricTable. */
143 #define OSPFIFMETRICIPADDRESS 1
144 #define OSPFIFMETRICADDRESSLESSIF 2
145 #define OSPFIFMETRICTOS 3
146 #define OSPFIFMETRICVALUE 4
147 #define OSPFIFMETRICSTATUS 5
149 /* OSPF MIB ospfVirtIfTable. */
150 #define OSPFVIRTIFAREAID 1
151 #define OSPFVIRTIFNEIGHBOR 2
152 #define OSPFVIRTIFTRANSITDELAY 3
153 #define OSPFVIRTIFRETRANSINTERVAL 4
154 #define OSPFVIRTIFHELLOINTERVAL 5
155 #define OSPFVIRTIFRTRDEADINTERVAL 6
156 #define OSPFVIRTIFSTATE 7
157 #define OSPFVIRTIFEVENTS 8
158 #define OSPFVIRTIFAUTHKEY 9
159 #define OSPFVIRTIFSTATUS 10
160 #define OSPFVIRTIFAUTHTYPE 11
162 /* OSPF MIB ospfNbrTable. */
163 #define OSPFNBRIPADDR 1
164 #define OSPFNBRADDRESSLESSINDEX 2
165 #define OSPFNBRRTRID 3
166 #define OSPFNBROPTIONS 4
167 #define OSPFNBRPRIORITY 5
168 #define OSPFNBRSTATE 6
169 #define OSPFNBREVENTS 7
170 #define OSPFNBRLSRETRANSQLEN 8
171 #define OSPFNBMANBRSTATUS 9
172 #define OSPFNBMANBRPERMANENCE 10
173 #define OSPFNBRHELLOSUPPRESSED 11
175 /* OSPF MIB ospfVirtNbrTable. */
176 #define OSPFVIRTNBRAREA 1
177 #define OSPFVIRTNBRRTRID 2
178 #define OSPFVIRTNBRIPADDR 3
179 #define OSPFVIRTNBROPTIONS 4
180 #define OSPFVIRTNBRSTATE 5
181 #define OSPFVIRTNBREVENTS 6
182 #define OSPFVIRTNBRLSRETRANSQLEN 7
183 #define OSPFVIRTNBRHELLOSUPPRESSED 8
185 /* OSPF MIB ospfExtLsdbTable. */
186 #define OSPFEXTLSDBTYPE 1
187 #define OSPFEXTLSDBLSID 2
188 #define OSPFEXTLSDBROUTERID 3
189 #define OSPFEXTLSDBSEQUENCE 4
190 #define OSPFEXTLSDBAGE 5
191 #define OSPFEXTLSDBCHECKSUM 6
192 #define OSPFEXTLSDBADVERTISEMENT 7
194 /* OSPF MIB ospfAreaAggregateTable. */
195 #define OSPFAREAAGGREGATEAREAID 1
196 #define OSPFAREAAGGREGATELSDBTYPE 2
197 #define OSPFAREAAGGREGATENET 3
198 #define OSPFAREAAGGREGATEMASK 4
199 #define OSPFAREAAGGREGATESTATUS 5
200 #define OSPFAREAAGGREGATEEFFECT 6
202 /* SYNTAX Status from OSPF-MIB. */
203 #define OSPF_STATUS_ENABLED 1
204 #define OSPF_STATUS_DISABLED 2
206 /* SNMP value hack. */
207 #define COUNTER ASN_COUNTER
208 #define INTEGER ASN_INTEGER
209 #define GAUGE ASN_GAUGE
210 #define TIMETICKS ASN_TIMETICKS
211 #define IPADDRESS ASN_IPADDRESS
212 #define STRING ASN_OCTET_STR
214 /* Declare static local variables for convenience. */
217 /* OSPF-MIB instances. */
218 oid ospf_oid
[] = { OSPF2MIB
};
220 /* IP address 0.0.0.0. */
221 static struct in_addr ospf_empty_addr
= {0};
223 /* Hook functions. */
224 static u_char
*ospfGeneralGroup (struct variable
*, oid
*, size_t *,
225 int, size_t *, WriteMethod
**);
226 static u_char
*ospfAreaEntry (struct variable
*, oid
*, size_t *, int,
227 size_t *, WriteMethod
**);
228 static u_char
*ospfStubAreaEntry (struct variable
*, oid
*, size_t *,
229 int, size_t *, WriteMethod
**);
230 static u_char
*ospfLsdbEntry (struct variable
*, oid
*, size_t *, int,
231 size_t *, WriteMethod
**);
232 static u_char
*ospfAreaRangeEntry (struct variable
*, oid
*, size_t *, int,
233 size_t *, WriteMethod
**);
234 static u_char
*ospfHostEntry (struct variable
*, oid
*, size_t *, int,
235 size_t *, WriteMethod
**);
236 static u_char
*ospfIfEntry (struct variable
*, oid
*, size_t *, int,
237 size_t *, WriteMethod
**);
238 static u_char
*ospfIfMetricEntry (struct variable
*, oid
*, size_t *, int,
239 size_t *, WriteMethod
**);
240 static u_char
*ospfVirtIfEntry (struct variable
*, oid
*, size_t *, int,
241 size_t *, WriteMethod
**);
242 static u_char
*ospfNbrEntry (struct variable
*, oid
*, size_t *, int,
243 size_t *, WriteMethod
**);
244 static u_char
*ospfVirtNbrEntry (struct variable
*, oid
*, size_t *, int,
245 size_t *, WriteMethod
**);
246 static u_char
*ospfExtLsdbEntry (struct variable
*, oid
*, size_t *, int,
247 size_t *, WriteMethod
**);
248 static u_char
*ospfAreaAggregateEntry (struct variable
*, oid
*, size_t *,
249 int, size_t *, WriteMethod
**);
251 struct variable ospf_variables
[] =
253 /* OSPF general variables */
254 {OSPFROUTERID
, IPADDRESS
, RWRITE
, ospfGeneralGroup
,
256 {OSPFADMINSTAT
, INTEGER
, RWRITE
, ospfGeneralGroup
,
258 {OSPFVERSIONNUMBER
, INTEGER
, RONLY
, ospfGeneralGroup
,
260 {OSPFAREABDRRTRSTATUS
, INTEGER
, RONLY
, ospfGeneralGroup
,
262 {OSPFASBDRRTRSTATUS
, INTEGER
, RWRITE
, ospfGeneralGroup
,
264 {OSPFEXTERNLSACOUNT
, GAUGE
, RONLY
, ospfGeneralGroup
,
266 {OSPFEXTERNLSACKSUMSUM
, INTEGER
, RONLY
, ospfGeneralGroup
,
268 {OSPFTOSSUPPORT
, INTEGER
, RWRITE
, ospfGeneralGroup
,
270 {OSPFORIGINATENEWLSAS
, COUNTER
, RONLY
, ospfGeneralGroup
,
272 {OSPFRXNEWLSAS
, COUNTER
, RONLY
, ospfGeneralGroup
,
274 {OSPFEXTLSDBLIMIT
, INTEGER
, RWRITE
, ospfGeneralGroup
,
276 {OSPFMULTICASTEXTENSIONS
, INTEGER
, RWRITE
, ospfGeneralGroup
,
278 {OSPFEXITOVERFLOWINTERVAL
, INTEGER
, RWRITE
, ospfGeneralGroup
,
280 {OSPFDEMANDEXTENSIONS
, INTEGER
, RWRITE
, ospfGeneralGroup
,
283 /* OSPF area data structure. */
284 {OSPFAREAID
, IPADDRESS
, RONLY
, ospfAreaEntry
,
286 {OSPFAUTHTYPE
, INTEGER
, RWRITE
, ospfAreaEntry
,
288 {OSPFIMPORTASEXTERN
, INTEGER
, RWRITE
, ospfAreaEntry
,
290 {OSPFSPFRUNS
, COUNTER
, RONLY
, ospfAreaEntry
,
292 {OSPFAREABDRRTRCOUNT
, GAUGE
, RONLY
, ospfAreaEntry
,
294 {OSPFASBDRRTRCOUNT
, GAUGE
, RONLY
, ospfAreaEntry
,
296 {OSPFAREALSACOUNT
, GAUGE
, RONLY
, ospfAreaEntry
,
298 {OSPFAREALSACKSUMSUM
, INTEGER
, RONLY
, ospfAreaEntry
,
300 {OSPFAREASUMMARY
, INTEGER
, RWRITE
, ospfAreaEntry
,
302 {OSPFAREASTATUS
, INTEGER
, RWRITE
, ospfAreaEntry
,
305 /* OSPF stub area information. */
306 {OSPFSTUBAREAID
, IPADDRESS
, RONLY
, ospfStubAreaEntry
,
308 {OSPFSTUBTOS
, INTEGER
, RONLY
, ospfStubAreaEntry
,
310 {OSPFSTUBMETRIC
, INTEGER
, RWRITE
, ospfStubAreaEntry
,
312 {OSPFSTUBSTATUS
, INTEGER
, RWRITE
, ospfStubAreaEntry
,
314 {OSPFSTUBMETRICTYPE
, INTEGER
, RWRITE
, ospfStubAreaEntry
,
317 /* OSPF link state database. */
318 {OSPFLSDBAREAID
, IPADDRESS
, RONLY
, ospfLsdbEntry
,
320 {OSPFLSDBTYPE
, INTEGER
, RONLY
, ospfLsdbEntry
,
322 {OSPFLSDBLSID
, IPADDRESS
, RONLY
, ospfLsdbEntry
,
324 {OSPFLSDBROUTERID
, IPADDRESS
, RONLY
, ospfLsdbEntry
,
326 {OSPFLSDBSEQUENCE
, INTEGER
, RONLY
, ospfLsdbEntry
,
328 {OSPFLSDBAGE
, INTEGER
, RONLY
, ospfLsdbEntry
,
330 {OSPFLSDBCHECKSUM
, INTEGER
, RONLY
, ospfLsdbEntry
,
332 {OSPFLSDBADVERTISEMENT
, STRING
, RONLY
, ospfLsdbEntry
,
335 /* Area range table. */
336 {OSPFAREARANGEAREAID
, IPADDRESS
, RONLY
, ospfAreaRangeEntry
,
338 {OSPFAREARANGENET
, IPADDRESS
, RONLY
, ospfAreaRangeEntry
,
340 {OSPFAREARANGEMASK
, IPADDRESS
, RWRITE
, ospfAreaRangeEntry
,
342 {OSPFAREARANGESTATUS
, INTEGER
, RWRITE
, ospfAreaRangeEntry
,
344 {OSPFAREARANGEEFFECT
, INTEGER
, RWRITE
, ospfAreaRangeEntry
,
347 /* OSPF host table. */
348 {OSPFHOSTIPADDRESS
, IPADDRESS
, RONLY
, ospfHostEntry
,
350 {OSPFHOSTTOS
, INTEGER
, RONLY
, ospfHostEntry
,
352 {OSPFHOSTMETRIC
, INTEGER
, RWRITE
, ospfHostEntry
,
354 {OSPFHOSTSTATUS
, INTEGER
, RWRITE
, ospfHostEntry
,
356 {OSPFHOSTAREAID
, IPADDRESS
, RONLY
, ospfHostEntry
,
359 /* OSPF interface table. */
360 {OSPFIFIPADDRESS
, IPADDRESS
, RONLY
, ospfIfEntry
,
362 {OSPFADDRESSLESSIF
, INTEGER
, RONLY
, ospfIfEntry
,
364 {OSPFIFAREAID
, IPADDRESS
, RWRITE
, ospfIfEntry
,
366 {OSPFIFTYPE
, INTEGER
, RWRITE
, ospfIfEntry
,
368 {OSPFIFADMINSTAT
, INTEGER
, RWRITE
, ospfIfEntry
,
370 {OSPFIFRTRPRIORITY
, INTEGER
, RWRITE
, ospfIfEntry
,
372 {OSPFIFTRANSITDELAY
, INTEGER
, RWRITE
, ospfIfEntry
,
374 {OSPFIFRETRANSINTERVAL
, INTEGER
, RWRITE
, ospfIfEntry
,
376 {OSPFIFHELLOINTERVAL
, INTEGER
, RWRITE
, ospfIfEntry
,
378 {OSPFIFRTRDEADINTERVAL
, INTEGER
, RWRITE
, ospfIfEntry
,
380 {OSPFIFPOLLINTERVAL
, INTEGER
, RWRITE
, ospfIfEntry
,
382 {OSPFIFSTATE
, INTEGER
, RONLY
, ospfIfEntry
,
384 {OSPFIFDESIGNATEDROUTER
, IPADDRESS
, RONLY
, ospfIfEntry
,
386 {OSPFIFBACKUPDESIGNATEDROUTER
, IPADDRESS
, RONLY
, ospfIfEntry
,
388 {OSPFIFEVENTS
, COUNTER
, RONLY
, ospfIfEntry
,
390 {OSPFIFAUTHKEY
, STRING
, RWRITE
, ospfIfEntry
,
392 {OSPFIFSTATUS
, INTEGER
, RWRITE
, ospfIfEntry
,
394 {OSPFIFMULTICASTFORWARDING
, INTEGER
, RWRITE
, ospfIfEntry
,
396 {OSPFIFDEMAND
, INTEGER
, RWRITE
, ospfIfEntry
,
398 {OSPFIFAUTHTYPE
, INTEGER
, RWRITE
, ospfIfEntry
,
401 /* OSPF interface metric table. */
402 {OSPFIFMETRICIPADDRESS
, IPADDRESS
, RONLY
, ospfIfMetricEntry
,
404 {OSPFIFMETRICADDRESSLESSIF
, INTEGER
, RONLY
, ospfIfMetricEntry
,
406 {OSPFIFMETRICTOS
, INTEGER
, RONLY
, ospfIfMetricEntry
,
408 {OSPFIFMETRICVALUE
, INTEGER
, RWRITE
, ospfIfMetricEntry
,
410 {OSPFIFMETRICSTATUS
, INTEGER
, RWRITE
, ospfIfMetricEntry
,
413 /* OSPF virtual interface table. */
414 {OSPFVIRTIFAREAID
, IPADDRESS
, RONLY
, ospfVirtIfEntry
,
416 {OSPFVIRTIFNEIGHBOR
, IPADDRESS
, RONLY
, ospfVirtIfEntry
,
418 {OSPFVIRTIFTRANSITDELAY
, INTEGER
, RWRITE
, ospfVirtIfEntry
,
420 {OSPFVIRTIFRETRANSINTERVAL
, INTEGER
, RWRITE
, ospfVirtIfEntry
,
422 {OSPFVIRTIFHELLOINTERVAL
, INTEGER
, RWRITE
, ospfVirtIfEntry
,
424 {OSPFVIRTIFRTRDEADINTERVAL
, INTEGER
, RWRITE
, ospfVirtIfEntry
,
426 {OSPFVIRTIFSTATE
, INTEGER
, RONLY
, ospfVirtIfEntry
,
428 {OSPFVIRTIFEVENTS
, COUNTER
, RONLY
, ospfVirtIfEntry
,
430 {OSPFVIRTIFAUTHKEY
, STRING
, RWRITE
, ospfVirtIfEntry
,
432 {OSPFVIRTIFSTATUS
, INTEGER
, RWRITE
, ospfVirtIfEntry
,
434 {OSPFVIRTIFAUTHTYPE
, INTEGER
, RWRITE
, ospfVirtIfEntry
,
437 /* OSPF neighbor table. */
438 {OSPFNBRIPADDR
, IPADDRESS
, RONLY
, ospfNbrEntry
,
440 {OSPFNBRADDRESSLESSINDEX
, INTEGER
, RONLY
, ospfNbrEntry
,
442 {OSPFNBRRTRID
, IPADDRESS
, RONLY
, ospfNbrEntry
,
444 {OSPFNBROPTIONS
, INTEGER
, RONLY
, ospfNbrEntry
,
446 {OSPFNBRPRIORITY
, INTEGER
, RWRITE
, ospfNbrEntry
,
448 {OSPFNBRSTATE
, INTEGER
, RONLY
, ospfNbrEntry
,
450 {OSPFNBREVENTS
, COUNTER
, RONLY
, ospfNbrEntry
,
452 {OSPFNBRLSRETRANSQLEN
, GAUGE
, RONLY
, ospfNbrEntry
,
454 {OSPFNBMANBRSTATUS
, INTEGER
, RWRITE
, ospfNbrEntry
,
456 {OSPFNBMANBRPERMANENCE
, INTEGER
, RONLY
, ospfNbrEntry
,
458 {OSPFNBRHELLOSUPPRESSED
, INTEGER
, RONLY
, ospfNbrEntry
,
461 /* OSPF virtual neighbor table. */
462 {OSPFVIRTNBRAREA
, IPADDRESS
, RONLY
, ospfVirtNbrEntry
,
464 {OSPFVIRTNBRRTRID
, IPADDRESS
, RONLY
, ospfVirtNbrEntry
,
466 {OSPFVIRTNBRIPADDR
, IPADDRESS
, RONLY
, ospfVirtNbrEntry
,
468 {OSPFVIRTNBROPTIONS
, INTEGER
, RONLY
, ospfVirtNbrEntry
,
470 {OSPFVIRTNBRSTATE
, INTEGER
, RONLY
, ospfVirtNbrEntry
,
472 {OSPFVIRTNBREVENTS
, COUNTER
, RONLY
, ospfVirtNbrEntry
,
474 {OSPFVIRTNBRLSRETRANSQLEN
, INTEGER
, RONLY
, ospfVirtNbrEntry
,
476 {OSPFVIRTNBRHELLOSUPPRESSED
, INTEGER
, RONLY
, ospfVirtNbrEntry
,
479 /* OSPF link state database, external. */
480 {OSPFEXTLSDBTYPE
, INTEGER
, RONLY
, ospfExtLsdbEntry
,
482 {OSPFEXTLSDBLSID
, IPADDRESS
, RONLY
, ospfExtLsdbEntry
,
484 {OSPFEXTLSDBROUTERID
, IPADDRESS
, RONLY
, ospfExtLsdbEntry
,
486 {OSPFEXTLSDBSEQUENCE
, INTEGER
, RONLY
, ospfExtLsdbEntry
,
488 {OSPFEXTLSDBAGE
, INTEGER
, RONLY
, ospfExtLsdbEntry
,
490 {OSPFEXTLSDBCHECKSUM
, INTEGER
, RONLY
, ospfExtLsdbEntry
,
492 {OSPFEXTLSDBADVERTISEMENT
, STRING
, RONLY
, ospfExtLsdbEntry
,
495 /* OSPF area aggregate table. */
496 {OSPFAREAAGGREGATEAREAID
, IPADDRESS
, RONLY
, ospfAreaAggregateEntry
,
498 {OSPFAREAAGGREGATELSDBTYPE
, INTEGER
, RONLY
, ospfAreaAggregateEntry
,
500 {OSPFAREAAGGREGATENET
, IPADDRESS
, RONLY
, ospfAreaAggregateEntry
,
502 {OSPFAREAAGGREGATEMASK
, IPADDRESS
, RONLY
, ospfAreaAggregateEntry
,
504 {OSPFAREAAGGREGATESTATUS
, INTEGER
, RWRITE
, ospfAreaAggregateEntry
,
506 {OSPFAREAAGGREGATEEFFECT
, INTEGER
, RWRITE
, ospfAreaAggregateEntry
,
510 /* The administrative status of OSPF. When OSPF is enbled on at least
511 one interface return 1. */
513 ospf_admin_stat (struct ospf
*ospf
)
515 struct listnode
*node
;
516 struct ospf_interface
*oi
;
521 for (ALL_LIST_ELEMENTS_RO (ospf
->oiflist
, node
, oi
))
522 if (oi
&& oi
->address
)
529 ospfGeneralGroup (struct variable
*v
, oid
*name
, size_t *length
,
530 int exact
, size_t *var_len
, WriteMethod
**write_method
)
534 ospf
= ospf_lookup ();
536 /* Check whether the instance identifier is valid */
537 if (smux_header_generic (v
, name
, length
, exact
, var_len
, write_method
)
541 /* Return the current value of the variable */
544 case OSPFROUTERID
: /* 1 */
545 /* Router-ID of this OSPF instance. */
547 return SNMP_IPADDRESS (ospf
->router_id
);
549 return SNMP_IPADDRESS (ospf_empty_addr
);
551 case OSPFADMINSTAT
: /* 2 */
552 /* The administrative status of OSPF in the router. */
553 if (ospf_admin_stat (ospf
))
554 return SNMP_INTEGER (OSPF_STATUS_ENABLED
);
556 return SNMP_INTEGER (OSPF_STATUS_DISABLED
);
558 case OSPFVERSIONNUMBER
: /* 3 */
559 /* OSPF version 2. */
560 return SNMP_INTEGER (OSPF_VERSION
);
562 case OSPFAREABDRRTRSTATUS
: /* 4 */
563 /* Area Border router status. */
564 if (ospf
&& CHECK_FLAG (ospf
->flags
, OSPF_FLAG_ABR
))
565 return SNMP_INTEGER (SNMP_TRUE
);
567 return SNMP_INTEGER (SNMP_FALSE
);
569 case OSPFASBDRRTRSTATUS
: /* 5 */
570 /* AS Border router status. */
571 if (ospf
&& CHECK_FLAG (ospf
->flags
, OSPF_FLAG_ASBR
))
572 return SNMP_INTEGER (SNMP_TRUE
);
574 return SNMP_INTEGER (SNMP_FALSE
);
576 case OSPFEXTERNLSACOUNT
: /* 6 */
577 /* External LSA counts. */
579 return SNMP_INTEGER (ospf_lsdb_count_all (ospf
->lsdb
));
581 return SNMP_INTEGER (0);
583 case OSPFEXTERNLSACKSUMSUM
: /* 7 */
584 /* External LSA checksum. */
585 return SNMP_INTEGER (0);
587 case OSPFTOSSUPPORT
: /* 8 */
588 /* TOS is not supported. */
589 return SNMP_INTEGER (SNMP_FALSE
);
591 case OSPFORIGINATENEWLSAS
: /* 9 */
592 /* The number of new link-state advertisements. */
594 return SNMP_INTEGER (ospf
->lsa_originate_count
);
596 return SNMP_INTEGER (0);
598 case OSPFRXNEWLSAS
: /* 10 */
599 /* The number of link-state advertisements received determined
600 to be new instantiations. */
602 return SNMP_INTEGER (ospf
->rx_lsa_count
);
604 return SNMP_INTEGER (0);
606 case OSPFEXTLSDBLIMIT
: /* 11 */
607 /* There is no limit for the number of non-default
609 return SNMP_INTEGER (-1);
611 case OSPFMULTICASTEXTENSIONS
: /* 12 */
612 /* Multicast Extensions to OSPF is not supported. */
613 return SNMP_INTEGER (0);
615 case OSPFEXITOVERFLOWINTERVAL
: /* 13 */
616 /* Overflow is not supported. */
617 return SNMP_INTEGER (0);
619 case OSPFDEMANDEXTENSIONS
: /* 14 */
620 /* Demand routing is not supported. */
621 return SNMP_INTEGER (SNMP_FALSE
);
629 static struct ospf_area
*
630 ospf_area_lookup_next (struct ospf
*ospf
, struct in_addr
*area_id
, int first
)
632 struct ospf_area
*area
;
633 struct listnode
*node
;
640 node
= listhead (ospf
->areas
);
643 area
= listgetdata (node
);
644 *area_id
= area
->area_id
;
649 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
651 if (ntohl (area
->area_id
.s_addr
) > ntohl (area_id
->s_addr
))
653 *area_id
= area
->area_id
;
660 static struct ospf_area
*
661 ospfAreaLookup (struct variable
*v
, oid name
[], size_t *length
,
662 struct in_addr
*addr
, int exact
)
665 struct ospf_area
*area
;
668 ospf
= ospf_lookup ();
674 /* Length is insufficient to lookup OSPF area. */
675 if (*length
- v
->namelen
!= sizeof (struct in_addr
))
678 oid2in_addr (name
+ v
->namelen
, sizeof (struct in_addr
), addr
);
680 area
= ospf_area_lookup_by_area_id (ospf
, *addr
);
686 len
= *length
- v
->namelen
;
690 oid2in_addr (name
+ v
->namelen
, len
, addr
);
692 area
= ospf_area_lookup_next (ospf
, addr
, len
== 0 ? 1 : 0);
697 oid_copy_addr (name
+ v
->namelen
, addr
, sizeof (struct in_addr
));
698 *length
= sizeof (struct in_addr
) + v
->namelen
;
706 ospfAreaEntry (struct variable
*v
, oid
*name
, size_t *length
, int exact
,
707 size_t *var_len
, WriteMethod
**write_method
)
709 struct ospf_area
*area
;
712 memset (&addr
, 0, sizeof (struct in_addr
));
714 area
= ospfAreaLookup (v
, name
, length
, &addr
, exact
);
718 /* Return the current value of the variable */
721 case OSPFAREAID
: /* 1 */
722 return SNMP_IPADDRESS (area
->area_id
);
724 case OSPFAUTHTYPE
: /* 2 */
725 return SNMP_INTEGER (area
->auth_type
);
727 case OSPFIMPORTASEXTERN
: /* 3 */
728 return SNMP_INTEGER (area
->external_routing
+ 1);
730 case OSPFSPFRUNS
: /* 4 */
731 return SNMP_INTEGER (area
->spf_calculation
);
733 case OSPFAREABDRRTRCOUNT
: /* 5 */
734 return SNMP_INTEGER (area
->abr_count
);
736 case OSPFASBDRRTRCOUNT
: /* 6 */
737 return SNMP_INTEGER (area
->asbr_count
);
739 case OSPFAREALSACOUNT
: /* 7 */
740 return SNMP_INTEGER (area
->lsdb
->total
);
742 case OSPFAREALSACKSUMSUM
: /* 8 */
743 return SNMP_INTEGER (0);
745 case OSPFAREASUMMARY
: /* 9 */
746 #define OSPF_noAreaSummary 1
747 #define OSPF_sendAreaSummary 2
748 if (area
->no_summary
)
749 return SNMP_INTEGER (OSPF_noAreaSummary
);
751 return SNMP_INTEGER (OSPF_sendAreaSummary
);
753 case OSPFAREASTATUS
: /* 10 */
754 return SNMP_INTEGER (SNMP_VALID
);
763 static struct ospf_area
*
764 ospf_stub_area_lookup_next (struct in_addr
*area_id
, int first
)
766 struct ospf_area
*area
;
767 struct listnode
*node
;
770 ospf
= ospf_lookup ();
774 for (ALL_LIST_ELEMENTS_RO (ospf
->areas
, node
, area
))
776 if (area
->external_routing
== OSPF_AREA_STUB
)
780 *area_id
= area
->area_id
;
783 else if (ntohl (area
->area_id
.s_addr
) > ntohl (area_id
->s_addr
))
785 *area_id
= area
->area_id
;
793 static struct ospf_area
*
794 ospfStubAreaLookup (struct variable
*v
, oid name
[], size_t *length
,
795 struct in_addr
*addr
, int exact
)
798 struct ospf_area
*area
;
801 ospf
= ospf_lookup ();
808 /* ospfStubAreaID + ospfStubTOS. */
809 if (*length
!= v
->namelen
+ sizeof (struct in_addr
) + 1)
812 /* Check ospfStubTOS is zero. */
813 if (name
[*length
- 1] != 0)
816 oid2in_addr (name
+ v
->namelen
, sizeof (struct in_addr
), addr
);
818 area
= ospf_area_lookup_by_area_id (ospf
, *addr
);
820 if (area
->external_routing
== OSPF_AREA_STUB
)
827 len
= *length
- v
->namelen
;
831 oid2in_addr (name
+ v
->namelen
, len
, addr
);
833 area
= ospf_stub_area_lookup_next (addr
, len
== 0 ? 1 : 0);
838 oid_copy_addr (name
+ v
->namelen
, addr
, sizeof (struct in_addr
));
840 name
[v
->namelen
+ sizeof (struct in_addr
)] = 0;
841 *length
= v
->namelen
+ sizeof (struct in_addr
) + 1;
849 ospfStubAreaEntry (struct variable
*v
, oid
*name
, size_t *length
,
850 int exact
, size_t *var_len
, WriteMethod
**write_method
)
852 struct ospf_area
*area
;
855 memset (&addr
, 0, sizeof (struct in_addr
));
857 area
= ospfStubAreaLookup (v
, name
, length
, &addr
, exact
);
861 /* Return the current value of the variable */
864 case OSPFSTUBAREAID
: /* 1 */
865 /* OSPF stub area id. */
866 return SNMP_IPADDRESS (area
->area_id
);
868 case OSPFSTUBTOS
: /* 2 */
869 /* TOS value is not supported. */
870 return SNMP_INTEGER (0);
872 case OSPFSTUBMETRIC
: /* 3 */
873 /* Default cost to stub area. */
874 return SNMP_INTEGER (area
->default_cost
);
876 case OSPFSTUBSTATUS
: /* 4 */
877 /* Status of the stub area. */
878 return SNMP_INTEGER (SNMP_VALID
);
880 case OSPFSTUBMETRICTYPE
: /* 5 */
881 /* OSPF Metric type. */
882 #define OSPF_ospfMetric 1
883 #define OSPF_comparableCost 2
884 #define OSPF_nonComparable 3
885 return SNMP_INTEGER (OSPF_ospfMetric
);
894 static struct ospf_lsa
*
895 lsdb_lookup_next (struct ospf_area
*area
, u_char
*type
, int type_next
,
896 struct in_addr
*ls_id
, int ls_id_next
,
897 struct in_addr
*router_id
, int router_id_next
)
899 struct ospf_lsa
*lsa
;
907 /* Sanity check, if LSA type unknwon
908 merley skip any LSA */
909 if ((i
< OSPF_MIN_LSA
) || (i
>= OSPF_MAX_LSA
))
911 zlog_debug("Strange request with LSA type %d\n", i
);
915 for (; i
< OSPF_MAX_LSA
; i
++)
919 lsa
= ospf_lsdb_lookup_by_id_next (area
->lsdb
, *type
, *ls_id
, *router_id
,
929 static struct ospf_lsa
*
930 ospfLsdbLookup (struct variable
*v
, oid
*name
, size_t *length
,
931 struct in_addr
*area_id
, u_char
*type
,
932 struct in_addr
*ls_id
, struct in_addr
*router_id
, int exact
)
935 struct ospf_area
*area
;
936 struct ospf_lsa
*lsa
;
944 ospf
= ospf_lookup ();
946 #define OSPF_LSDB_ENTRY_OFFSET \
947 (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE)
951 /* Area ID + Type + LS ID + Router ID. */
952 if (*length
- v
->namelen
!= OSPF_LSDB_ENTRY_OFFSET
)
955 /* Set OID offset for Area ID. */
956 offset
= name
+ v
->namelen
;
958 /* Lookup area first. */
959 oid2in_addr (offset
, IN_ADDR_SIZE
, area_id
);
960 area
= ospf_area_lookup_by_area_id (ospf
, *area_id
);
963 offset
+= IN_ADDR_SIZE
;
970 oid2in_addr (offset
, IN_ADDR_SIZE
, ls_id
);
971 offset
+= IN_ADDR_SIZE
;
974 oid2in_addr (offset
, IN_ADDR_SIZE
, router_id
);
977 return ospf_lsdb_lookup_by_id (area
->lsdb
, *type
, *ls_id
, *router_id
);
981 /* Get variable length. */
982 offset
= name
+ v
->namelen
;
983 offsetlen
= *length
- v
->namelen
;
986 if (len
> IN_ADDR_SIZE
)
989 oid2in_addr (offset
, len
, area_id
);
991 /* First we search area. */
992 if (len
== IN_ADDR_SIZE
)
993 area
= ospf_area_lookup_by_area_id (ospf
, *area_id
);
995 area
= ospf_area_lookup_next (ospf
, area_id
, len
== 0 ? 1 : 0);
1002 /* Next we lookup type. */
1003 offset
+= IN_ADDR_SIZE
;
1004 offsetlen
-= IN_ADDR_SIZE
;
1026 if (len
> IN_ADDR_SIZE
)
1029 oid2in_addr (offset
, len
, ls_id
);
1033 offset
+= IN_ADDR_SIZE
;
1034 offsetlen
-= IN_ADDR_SIZE
;
1042 if (len
> IN_ADDR_SIZE
)
1045 oid2in_addr (offset
, len
, router_id
);
1048 lsa
= lsdb_lookup_next (area
, type
, type_next
, ls_id
, ls_id_next
,
1049 router_id
, router_id_next
);
1053 /* Fill in length. */
1054 *length
= v
->namelen
+ OSPF_LSDB_ENTRY_OFFSET
;
1056 /* Fill in value. */
1057 offset
= name
+ v
->namelen
;
1058 oid_copy_addr (offset
, area_id
, IN_ADDR_SIZE
);
1059 offset
+= IN_ADDR_SIZE
;
1060 *offset
= lsa
->data
->type
;
1062 oid_copy_addr (offset
, &lsa
->data
->id
, IN_ADDR_SIZE
);
1063 offset
+= IN_ADDR_SIZE
;
1064 oid_copy_addr (offset
, &lsa
->data
->adv_router
, IN_ADDR_SIZE
);
1069 while ((area
= ospf_area_lookup_next (ospf
, area_id
, 0)) != NULL
);
1075 ospfLsdbEntry (struct variable
*v
, oid
*name
, size_t *length
, int exact
,
1076 size_t *var_len
, WriteMethod
**write_method
)
1078 struct ospf_lsa
*lsa
;
1079 struct lsa_header
*lsah
;
1080 struct in_addr area_id
;
1082 struct in_addr ls_id
;
1083 struct in_addr router_id
;
1086 /* INDEX { ospfLsdbAreaId, ospfLsdbType,
1087 ospfLsdbLsid, ospfLsdbRouterId } */
1089 memset (&area_id
, 0, sizeof (struct in_addr
));
1091 memset (&ls_id
, 0, sizeof (struct in_addr
));
1092 memset (&router_id
, 0, sizeof (struct in_addr
));
1094 /* Check OSPF instance. */
1095 ospf
= ospf_lookup ();
1099 lsa
= ospfLsdbLookup (v
, name
, length
, &area_id
, &type
, &ls_id
, &router_id
,
1106 /* Return the current value of the variable */
1109 case OSPFLSDBAREAID
: /* 1 */
1110 return SNMP_IPADDRESS (lsa
->area
->area_id
);
1112 case OSPFLSDBTYPE
: /* 2 */
1113 return SNMP_INTEGER (lsah
->type
);
1115 case OSPFLSDBLSID
: /* 3 */
1116 return SNMP_IPADDRESS (lsah
->id
);
1118 case OSPFLSDBROUTERID
: /* 4 */
1119 return SNMP_IPADDRESS (lsah
->adv_router
);
1121 case OSPFLSDBSEQUENCE
: /* 5 */
1122 return SNMP_INTEGER (lsah
->ls_seqnum
);
1124 case OSPFLSDBAGE
: /* 6 */
1125 return SNMP_INTEGER (lsah
->ls_age
);
1127 case OSPFLSDBCHECKSUM
: /* 7 */
1128 return SNMP_INTEGER (lsah
->checksum
);
1130 case OSPFLSDBADVERTISEMENT
: /* 8 */
1131 *var_len
= ntohs (lsah
->length
);
1132 return (u_char
*) lsah
;
1141 static struct ospf_area_range
*
1142 ospfAreaRangeLookup (struct variable
*v
, oid
*name
, size_t *length
,
1143 struct in_addr
*area_id
, struct in_addr
*range_net
,
1150 struct ospf_area
*area
;
1151 struct ospf_area_range
*range
;
1152 struct prefix_ipv4 p
;
1154 p
.prefixlen
= IPV4_MAX_BITLEN
;
1156 ospf
= ospf_lookup ();
1160 /* Area ID + Range Network. */
1161 if (v
->namelen
+ IN_ADDR_SIZE
+ IN_ADDR_SIZE
!= *length
)
1164 /* Set OID offset for Area ID. */
1165 offset
= name
+ v
->namelen
;
1167 /* Lookup area first. */
1168 oid2in_addr (offset
, IN_ADDR_SIZE
, area_id
);
1170 area
= ospf_area_lookup_by_area_id (ospf
, *area_id
);
1174 offset
+= IN_ADDR_SIZE
;
1176 /* Lookup area range. */
1177 oid2in_addr (offset
, IN_ADDR_SIZE
, range_net
);
1178 p
.prefix
= *range_net
;
1180 return ospf_area_range_lookup (area
, &p
);
1184 /* Set OID offset for Area ID. */
1185 offset
= name
+ v
->namelen
;
1186 offsetlen
= *length
- v
->namelen
;
1189 if (len
> IN_ADDR_SIZE
)
1192 oid2in_addr (offset
, len
, area_id
);
1194 /* First we search area. */
1195 if (len
== IN_ADDR_SIZE
)
1196 area
= ospf_area_lookup_by_area_id (ospf
,*area_id
);
1198 area
= ospf_area_lookup_next (ospf
, area_id
, len
== 0 ? 1 : 0);
1205 offset
+= IN_ADDR_SIZE
;
1206 offsetlen
-= IN_ADDR_SIZE
;
1211 if (len
> IN_ADDR_SIZE
)
1214 oid2in_addr (offset
, len
, range_net
);
1216 range
= ospf_area_range_lookup_next (area
, range_net
,
1221 /* Fill in length. */
1222 *length
= v
->namelen
+ IN_ADDR_SIZE
+ IN_ADDR_SIZE
;
1224 /* Fill in value. */
1225 offset
= name
+ v
->namelen
;
1226 oid_copy_addr (offset
, area_id
, IN_ADDR_SIZE
);
1227 offset
+= IN_ADDR_SIZE
;
1228 oid_copy_addr (offset
, range_net
, IN_ADDR_SIZE
);
1233 while ((area
= ospf_area_lookup_next (ospf
, area_id
, 0)) != NULL
);
1239 ospfAreaRangeEntry (struct variable
*v
, oid
*name
, size_t *length
, int exact
,
1240 size_t *var_len
, WriteMethod
**write_method
)
1242 struct ospf_area_range
*range
;
1243 struct in_addr area_id
;
1244 struct in_addr range_net
;
1245 struct in_addr mask
;
1248 /* Check OSPF instance. */
1249 ospf
= ospf_lookup ();
1253 memset (&area_id
, 0, IN_ADDR_SIZE
);
1254 memset (&range_net
, 0, IN_ADDR_SIZE
);
1256 range
= ospfAreaRangeLookup (v
, name
, length
, &area_id
, &range_net
, exact
);
1260 /* Convert prefixlen to network mask format. */
1261 masklen2ip (range
->subst_masklen
, &mask
);
1263 /* Return the current value of the variable */
1266 case OSPFAREARANGEAREAID
: /* 1 */
1267 return SNMP_IPADDRESS (area_id
);
1269 case OSPFAREARANGENET
: /* 2 */
1270 return SNMP_IPADDRESS (range_net
);
1272 case OSPFAREARANGEMASK
: /* 3 */
1273 return SNMP_IPADDRESS (mask
);
1275 case OSPFAREARANGESTATUS
: /* 4 */
1276 return SNMP_INTEGER (SNMP_VALID
);
1278 case OSPFAREARANGEEFFECT
: /* 5 */
1279 #define OSPF_advertiseMatching 1
1280 #define OSPF_doNotAdvertiseMatching 2
1281 return SNMP_INTEGER (OSPF_advertiseMatching
);
1290 static struct ospf_nbr_nbma
*
1291 ospfHostLookup (struct variable
*v
, oid
*name
, size_t *length
,
1292 struct in_addr
*addr
, int exact
)
1295 struct ospf_nbr_nbma
*nbr_nbma
;
1298 ospf
= ospf_lookup ();
1304 /* INDEX { ospfHostIpAddress, ospfHostTOS } */
1305 if (*length
!= v
->namelen
+ IN_ADDR_SIZE
+ 1)
1308 /* Check ospfHostTOS. */
1309 if (name
[*length
- 1] != 0)
1312 oid2in_addr (name
+ v
->namelen
, IN_ADDR_SIZE
, addr
);
1314 nbr_nbma
= ospf_nbr_nbma_lookup (ospf
, *addr
);
1320 len
= *length
- v
->namelen
;
1324 oid2in_addr (name
+ v
->namelen
, len
, addr
);
1326 nbr_nbma
= ospf_nbr_nbma_lookup_next (ospf
, addr
, len
== 0 ? 1 : 0);
1328 if (nbr_nbma
== NULL
)
1331 oid_copy_addr (name
+ v
->namelen
, addr
, IN_ADDR_SIZE
);
1334 name
[v
->namelen
+ IN_ADDR_SIZE
] = 0;
1336 *length
= v
->namelen
+ IN_ADDR_SIZE
+ 1;
1344 ospfHostEntry (struct variable
*v
, oid
*name
, size_t *length
, int exact
,
1345 size_t *var_len
, WriteMethod
**write_method
)
1347 struct ospf_nbr_nbma
*nbr_nbma
;
1348 struct ospf_interface
*oi
;
1349 struct in_addr addr
;
1352 /* Check OSPF instance. */
1353 ospf
= ospf_lookup ();
1357 memset (&addr
, 0, sizeof (struct in_addr
));
1359 nbr_nbma
= ospfHostLookup (v
, name
, length
, &addr
, exact
);
1360 if (nbr_nbma
== NULL
)
1365 /* Return the current value of the variable */
1368 case OSPFHOSTIPADDRESS
: /* 1 */
1369 return SNMP_IPADDRESS (nbr_nbma
->addr
);
1371 case OSPFHOSTTOS
: /* 2 */
1372 return SNMP_INTEGER (0);
1374 case OSPFHOSTMETRIC
: /* 3 */
1376 return SNMP_INTEGER (oi
->output_cost
);
1378 return SNMP_INTEGER (1);
1380 case OSPFHOSTSTATUS
: /* 4 */
1381 return SNMP_INTEGER (SNMP_VALID
);
1383 case OSPFHOSTAREAID
: /* 5 */
1385 return SNMP_IPADDRESS (oi
->area
->area_id
);
1387 return SNMP_IPADDRESS (ospf_empty_addr
);
1396 struct list
*ospf_snmp_iflist
;
1400 struct in_addr addr
;
1401 unsigned int ifindex
;
1402 struct interface
*ifp
;
1405 static struct ospf_snmp_if
*
1406 ospf_snmp_if_new (void)
1408 return XCALLOC (0, sizeof (struct ospf_snmp_if
));
1412 ospf_snmp_if_free (struct ospf_snmp_if
*osif
)
1418 ospf_snmp_if_delete (struct interface
*ifp
)
1420 struct listnode
*node
, *nnode
;
1421 struct ospf_snmp_if
*osif
;
1423 for (ALL_LIST_ELEMENTS (ospf_snmp_iflist
, node
, nnode
, osif
))
1425 if (osif
->ifp
== ifp
)
1427 list_delete_node (ospf_snmp_iflist
, node
);
1428 ospf_snmp_if_free (osif
);
1435 ospf_snmp_if_update (struct interface
*ifp
)
1437 struct listnode
*node
;
1438 struct listnode
*pn
;
1439 struct connected
*ifc
;
1441 struct ospf_snmp_if
*osif
;
1442 struct in_addr
*addr
;
1443 unsigned int ifindex
;
1445 ospf_snmp_if_delete (ifp
);
1451 /* Lookup first IPv4 address entry. */
1452 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, node
, ifc
))
1454 p
= CONNECTED_ID(ifc
);
1456 if (p
->family
== AF_INET
)
1458 addr
= &p
->u
.prefix4
;
1463 ifindex
= ifp
->ifindex
;
1465 /* Add interface to the list. */
1467 for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist
, node
, osif
))
1471 /* Usual interfaces --> Sort them based on interface IPv4 addresses */
1472 if (ntohl (osif
->addr
.s_addr
) > ntohl (addr
->s_addr
))
1477 /* Unnumbered interfaces --> Sort them based on interface indexes */
1478 if (osif
->addr
.s_addr
!= 0 || osif
->ifindex
> ifindex
)
1484 osif
= ospf_snmp_if_new ();
1485 if (addr
) /* Usual interface */
1489 /* This field is used for storing ospfAddressLessIf OID value,
1490 * conform to RFC1850 OSPF-MIB specification, it must be 0 for
1491 * usual interface */
1494 else /* Unnumbered interface */
1495 osif
->ifindex
= ifindex
;
1498 listnode_add_after (ospf_snmp_iflist
, pn
, osif
);
1502 ospf_snmp_is_if_have_addr (struct interface
*ifp
)
1504 struct listnode
*nn
;
1505 struct connected
*ifc
;
1507 /* Is this interface having any connected IPv4 address ? */
1508 for (ALL_LIST_ELEMENTS_RO (ifp
->connected
, nn
, ifc
))
1510 if (CONNECTED_PREFIX(ifc
)->family
== AF_INET
)
1517 static struct ospf_interface
*
1518 ospf_snmp_if_lookup (struct in_addr
*ifaddr
, unsigned int *ifindex
)
1520 struct listnode
*node
;
1521 struct ospf_snmp_if
*osif
;
1522 struct ospf_interface
*oi
= NULL
;
1523 struct ospf
*ospf
= ospf_lookup ();
1525 for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist
, node
, osif
))
1529 if (IPV4_ADDR_SAME (&osif
->addr
, ifaddr
))
1530 oi
= ospf_if_lookup_by_local_addr (ospf
, osif
->ifp
, *ifaddr
);
1534 if (osif
->ifindex
== *ifindex
)
1535 oi
= ospf_if_lookup_by_local_addr (ospf
, osif
->ifp
, *ifaddr
);
1541 static struct ospf_interface
*
1542 ospf_snmp_if_lookup_next (struct in_addr
*ifaddr
, unsigned int *ifindex
,
1543 int ifaddr_next
, int ifindex_next
)
1545 struct ospf_snmp_if
*osif
;
1546 struct listnode
*nn
;
1547 struct ospf
*ospf
= ospf_lookup ();
1548 struct ospf_interface
*oi
= NULL
;
1553 /* No instance is specified --> Return the first OSPF interface */
1556 for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist
, nn
, osif
))
1558 osif
= listgetdata (nn
);
1559 *ifaddr
= osif
->addr
;
1560 *ifindex
= osif
->ifindex
;
1561 /* Because no instance is specified, we don't care about the kind of
1562 * interface (usual or unnumbered), just returning the first valid
1564 oi
= ospf_if_lookup_by_local_addr (ospf
, osif
->ifp
, *ifaddr
);
1571 /* An instance is specified --> Return the next OSPF interface */
1572 for (ALL_LIST_ELEMENTS_RO (ospf_snmp_iflist
, nn
, osif
))
1574 /* Usual interface */
1577 /* The interface must have valid AF_INET connected address */
1578 /* it must have lager IPv4 address value than the lookup entry */
1579 if ((ospf_snmp_is_if_have_addr(osif
->ifp
)) &&
1580 (ntohl (osif
->addr
.s_addr
) > ntohl (ifaddr
->s_addr
)))
1582 *ifaddr
= osif
->addr
;
1583 *ifindex
= osif
->ifindex
;
1585 /* and it must be an OSPF interface */
1586 oi
= ospf_if_lookup_by_local_addr (ospf
, osif
->ifp
, *ifaddr
);
1591 /* Unnumbered interface */
1593 /* The interface must NOT have valid AF_INET connected address */
1594 /* it must have lager interface index than the lookup entry */
1595 if ((!ospf_snmp_is_if_have_addr(osif
->ifp
)) &&
1596 (osif
->ifindex
> *ifindex
))
1598 *ifaddr
= osif
->addr
;
1599 *ifindex
= osif
->ifindex
;
1601 /* and it must be an OSPF interface */
1602 oi
= ospf_if_lookup_by_local_addr (ospf
, osif
->ifp
, *ifaddr
);
1611 ospf_snmp_iftype (struct interface
*ifp
)
1613 #define ospf_snmp_iftype_broadcast 1
1614 #define ospf_snmp_iftype_nbma 2
1615 #define ospf_snmp_iftype_pointToPoint 3
1616 #define ospf_snmp_iftype_pointToMultipoint 5
1617 if (if_is_broadcast (ifp
))
1618 return ospf_snmp_iftype_broadcast
;
1619 if (if_is_pointopoint (ifp
))
1620 return ospf_snmp_iftype_pointToPoint
;
1621 return ospf_snmp_iftype_broadcast
;
1624 static struct ospf_interface
*
1625 ospfIfLookup (struct variable
*v
, oid
*name
, size_t *length
,
1626 struct in_addr
*ifaddr
, unsigned int *ifindex
, int exact
)
1629 int ifaddr_next
= 0;
1630 int ifindex_next
= 0;
1631 struct ospf_interface
*oi
;
1636 if (*length
!= v
->namelen
+ IN_ADDR_SIZE
+ 1)
1639 oid2in_addr (name
+ v
->namelen
, IN_ADDR_SIZE
, ifaddr
);
1640 *ifindex
= name
[v
->namelen
+ IN_ADDR_SIZE
];
1642 return ospf_snmp_if_lookup (ifaddr
, ifindex
);
1646 len
= *length
- v
->namelen
;
1647 if (len
>= IN_ADDR_SIZE
)
1652 oid2in_addr (name
+ v
->namelen
, len
, ifaddr
);
1654 len
= *length
- v
->namelen
- IN_ADDR_SIZE
;
1661 *ifindex
= name
[v
->namelen
+ IN_ADDR_SIZE
];
1663 oi
= ospf_snmp_if_lookup_next (ifaddr
, ifindex
, ifaddr_next
,
1667 *length
= v
->namelen
+ IN_ADDR_SIZE
+ 1;
1668 offset
= name
+ v
->namelen
;
1669 oid_copy_addr (offset
, ifaddr
, IN_ADDR_SIZE
);
1670 offset
+= IN_ADDR_SIZE
;
1679 ospfIfEntry (struct variable
*v
, oid
*name
, size_t *length
, int exact
,
1680 size_t *var_len
, WriteMethod
**write_method
)
1682 unsigned int ifindex
;
1683 struct in_addr ifaddr
;
1684 struct ospf_interface
*oi
;
1688 memset (&ifaddr
, 0, sizeof (struct in_addr
));
1690 /* Check OSPF instance. */
1691 ospf
= ospf_lookup ();
1695 oi
= ospfIfLookup (v
, name
, length
, &ifaddr
, &ifindex
, exact
);
1699 /* Return the current value of the variable */
1702 case OSPFIFIPADDRESS
: /* 1 */
1703 return SNMP_IPADDRESS (ifaddr
);
1705 case OSPFADDRESSLESSIF
: /* 2 */
1706 return SNMP_INTEGER (ifindex
);
1708 case OSPFIFAREAID
: /* 3 */
1710 return SNMP_IPADDRESS (oi
->area
->area_id
);
1712 return SNMP_IPADDRESS (ospf_empty_addr
);
1714 case OSPFIFTYPE
: /* 4 */
1715 return SNMP_INTEGER (ospf_snmp_iftype (oi
->ifp
));
1717 case OSPFIFADMINSTAT
: /* 5 */
1719 return SNMP_INTEGER (OSPF_STATUS_ENABLED
);
1721 return SNMP_INTEGER (OSPF_STATUS_DISABLED
);
1723 case OSPFIFRTRPRIORITY
: /* 6 */
1724 return SNMP_INTEGER (PRIORITY (oi
));
1726 case OSPFIFTRANSITDELAY
: /* 7 */
1727 return SNMP_INTEGER (OSPF_IF_PARAM (oi
, transmit_delay
));
1729 case OSPFIFRETRANSINTERVAL
: /* 8 */
1730 return SNMP_INTEGER (OSPF_IF_PARAM (oi
, retransmit_interval
));
1732 case OSPFIFHELLOINTERVAL
: /* 9 */
1733 return SNMP_INTEGER (OSPF_IF_PARAM (oi
, v_hello
));
1735 case OSPFIFRTRDEADINTERVAL
: /* 10 */
1736 return SNMP_INTEGER (OSPF_IF_PARAM (oi
, v_wait
));
1738 case OSPFIFPOLLINTERVAL
: /* 11 */
1739 return SNMP_INTEGER (OSPF_POLL_INTERVAL_DEFAULT
);
1741 case OSPFIFSTATE
: /* 12 */
1742 return SNMP_INTEGER (ISM_SNMP(oi
->state
));
1744 case OSPFIFDESIGNATEDROUTER
: /* 13 */
1745 return SNMP_IPADDRESS (DR (oi
));
1747 case OSPFIFBACKUPDESIGNATEDROUTER
: /* 14 */
1748 return SNMP_IPADDRESS (BDR (oi
));
1750 case OSPFIFEVENTS
: /* 15 */
1751 return SNMP_INTEGER (oi
->state_change
);
1753 case OSPFIFAUTHKEY
: /* 16 */
1755 return (u_char
*) OSPF_IF_PARAM (oi
, auth_simple
);
1757 case OSPFIFSTATUS
: /* 17 */
1758 return SNMP_INTEGER (SNMP_VALID
);
1760 case OSPFIFMULTICASTFORWARDING
: /* 18 */
1761 #define ospf_snmp_multiforward_blocked 1
1762 #define ospf_snmp_multiforward_multicast 2
1763 #define ospf_snmp_multiforward_unicast 3
1764 return SNMP_INTEGER (ospf_snmp_multiforward_blocked
);
1766 case OSPFIFDEMAND
: /* 19 */
1767 return SNMP_INTEGER (SNMP_FALSE
);
1769 case OSPFIFAUTHTYPE
: /* 20 */
1771 return SNMP_INTEGER (oi
->area
->auth_type
);
1773 return SNMP_INTEGER (0);
1782 #define OSPF_SNMP_METRIC_VALUE 1
1784 static struct ospf_interface
*
1785 ospfIfMetricLookup (struct variable
*v
, oid
*name
, size_t *length
,
1786 struct in_addr
*ifaddr
, unsigned int *ifindex
, int exact
)
1789 int ifaddr_next
= 0;
1790 int ifindex_next
= 0;
1791 struct ospf_interface
*oi
;
1797 if (*length
!= v
->namelen
+ IN_ADDR_SIZE
+ 1 + 1)
1800 oid2in_addr (name
+ v
->namelen
, IN_ADDR_SIZE
, ifaddr
);
1801 *ifindex
= name
[v
->namelen
+ IN_ADDR_SIZE
];
1802 metric
= name
[v
->namelen
+ IN_ADDR_SIZE
+ 1];
1804 if (metric
!= OSPF_SNMP_METRIC_VALUE
)
1807 return ospf_snmp_if_lookup (ifaddr
, ifindex
);
1811 len
= *length
- v
->namelen
;
1812 if (len
>= IN_ADDR_SIZE
)
1817 oid2in_addr (name
+ v
->namelen
, len
, ifaddr
);
1819 len
= *length
- v
->namelen
- IN_ADDR_SIZE
;
1826 *ifindex
= name
[v
->namelen
+ IN_ADDR_SIZE
];
1828 oi
= ospf_snmp_if_lookup_next (ifaddr
, ifindex
, ifaddr_next
,
1832 *length
= v
->namelen
+ IN_ADDR_SIZE
+ 1 + 1;
1833 offset
= name
+ v
->namelen
;
1834 oid_copy_addr (offset
, ifaddr
, IN_ADDR_SIZE
);
1835 offset
+= IN_ADDR_SIZE
;
1838 *offset
= OSPF_SNMP_METRIC_VALUE
;
1846 ospfIfMetricEntry (struct variable
*v
, oid
*name
, size_t *length
, int exact
,
1847 size_t *var_len
, WriteMethod
**write_method
)
1849 /* Currently we support metric 1 only. */
1850 unsigned int ifindex
;
1851 struct in_addr ifaddr
;
1852 struct ospf_interface
*oi
;
1856 memset (&ifaddr
, 0, sizeof (struct in_addr
));
1858 /* Check OSPF instance. */
1859 ospf
= ospf_lookup ();
1863 oi
= ospfIfMetricLookup (v
, name
, length
, &ifaddr
, &ifindex
, exact
);
1867 /* Return the current value of the variable */
1870 case OSPFIFMETRICIPADDRESS
:
1871 return SNMP_IPADDRESS (ifaddr
);
1873 case OSPFIFMETRICADDRESSLESSIF
:
1874 return SNMP_INTEGER (ifindex
);
1876 case OSPFIFMETRICTOS
:
1877 return SNMP_INTEGER (0);
1879 case OSPFIFMETRICVALUE
:
1880 return SNMP_INTEGER (OSPF_SNMP_METRIC_VALUE
);
1882 case OSPFIFMETRICSTATUS
:
1883 return SNMP_INTEGER (1);
1892 struct route_table
*ospf_snmp_vl_table
;
1895 ospf_snmp_vl_add (struct ospf_vl_data
*vl_data
)
1897 struct prefix_ls lp
;
1898 struct route_node
*rn
;
1900 memset (&lp
, 0, sizeof (struct prefix_ls
));
1903 lp
.id
= vl_data
->vl_area_id
;
1904 lp
.adv_router
= vl_data
->vl_peer
;
1906 rn
= route_node_get (ospf_snmp_vl_table
, (struct prefix
*) &lp
);
1911 ospf_snmp_vl_delete (struct ospf_vl_data
*vl_data
)
1913 struct prefix_ls lp
;
1914 struct route_node
*rn
;
1916 memset (&lp
, 0, sizeof (struct prefix_ls
));
1919 lp
.id
= vl_data
->vl_area_id
;
1920 lp
.adv_router
= vl_data
->vl_peer
;
1922 rn
= route_node_lookup (ospf_snmp_vl_table
, (struct prefix
*) &lp
);
1926 route_unlock_node (rn
);
1927 route_unlock_node (rn
);
1930 static struct ospf_vl_data
*
1931 ospf_snmp_vl_lookup (struct in_addr
*area_id
, struct in_addr
*neighbor
)
1933 struct prefix_ls lp
;
1934 struct route_node
*rn
;
1935 struct ospf_vl_data
*vl_data
;
1937 memset (&lp
, 0, sizeof (struct prefix_ls
));
1941 lp
.adv_router
= *neighbor
;
1943 rn
= route_node_lookup (ospf_snmp_vl_table
, (struct prefix
*) &lp
);
1947 route_unlock_node (rn
);
1953 static struct ospf_vl_data
*
1954 ospf_snmp_vl_lookup_next (struct in_addr
*area_id
, struct in_addr
*neighbor
,
1957 struct prefix_ls lp
;
1958 struct route_node
*rn
;
1959 struct ospf_vl_data
*vl_data
;
1961 memset (&lp
, 0, sizeof (struct prefix_ls
));
1965 lp
.adv_router
= *neighbor
;
1968 rn
= route_top (ospf_snmp_vl_table
);
1971 rn
= route_node_get (ospf_snmp_vl_table
, (struct prefix
*) &lp
);
1972 rn
= route_next (rn
);
1975 for (; rn
; rn
= route_next (rn
))
1982 *area_id
= vl_data
->vl_area_id
;
1983 *neighbor
= vl_data
->vl_peer
;
1984 route_unlock_node (rn
);
1990 static struct ospf_vl_data
*
1991 ospfVirtIfLookup (struct variable
*v
, oid
*name
, size_t *length
,
1992 struct in_addr
*area_id
, struct in_addr
*neighbor
, int exact
)
1996 struct ospf_vl_data
*vl_data
;
2000 if (*length
!= v
->namelen
+ IN_ADDR_SIZE
+ IN_ADDR_SIZE
)
2003 oid2in_addr (name
+ v
->namelen
, IN_ADDR_SIZE
, area_id
);
2004 oid2in_addr (name
+ v
->namelen
+ IN_ADDR_SIZE
, IN_ADDR_SIZE
, neighbor
);
2006 return ospf_snmp_vl_lookup (area_id
, neighbor
);
2012 len
= *length
- v
->namelen
;
2015 if (len
> IN_ADDR_SIZE
)
2017 oid2in_addr (name
+ v
->namelen
, len
, area_id
);
2019 len
= *length
- v
->namelen
- IN_ADDR_SIZE
;
2020 if (len
> IN_ADDR_SIZE
)
2022 oid2in_addr (name
+ v
->namelen
+ IN_ADDR_SIZE
, len
, neighbor
);
2024 vl_data
= ospf_snmp_vl_lookup_next (area_id
, neighbor
, first
);
2028 *length
= v
->namelen
+ IN_ADDR_SIZE
+ IN_ADDR_SIZE
;
2029 oid_copy_addr (name
+ v
->namelen
, area_id
, IN_ADDR_SIZE
);
2030 oid_copy_addr (name
+ v
->namelen
+ IN_ADDR_SIZE
, neighbor
,
2039 ospfVirtIfEntry (struct variable
*v
, oid
*name
, size_t *length
, int exact
,
2040 size_t *var_len
, WriteMethod
**write_method
)
2042 struct ospf_vl_data
*vl_data
;
2043 struct ospf_interface
*oi
;
2044 struct in_addr area_id
;
2045 struct in_addr neighbor
;
2047 memset (&area_id
, 0, sizeof (struct in_addr
));
2048 memset (&neighbor
, 0, sizeof (struct in_addr
));
2050 vl_data
= ospfVirtIfLookup (v
, name
, length
, &area_id
, &neighbor
, exact
);
2053 oi
= vl_data
->vl_oi
;
2057 /* Return the current value of the variable */
2060 case OSPFVIRTIFAREAID
:
2061 return SNMP_IPADDRESS (area_id
);
2063 case OSPFVIRTIFNEIGHBOR
:
2064 return SNMP_IPADDRESS (neighbor
);
2066 case OSPFVIRTIFTRANSITDELAY
:
2067 return SNMP_INTEGER (OSPF_IF_PARAM (oi
, transmit_delay
));
2069 case OSPFVIRTIFRETRANSINTERVAL
:
2070 return SNMP_INTEGER (OSPF_IF_PARAM (oi
, retransmit_interval
));
2072 case OSPFVIRTIFHELLOINTERVAL
:
2073 return SNMP_INTEGER (OSPF_IF_PARAM (oi
, v_hello
));
2075 case OSPFVIRTIFRTRDEADINTERVAL
:
2076 return SNMP_INTEGER (OSPF_IF_PARAM (oi
, v_wait
));
2078 case OSPFVIRTIFSTATE
:
2079 return SNMP_INTEGER (oi
->state
);
2081 case OSPFVIRTIFEVENTS
:
2082 return SNMP_INTEGER (oi
->state_change
);
2084 case OSPFVIRTIFAUTHKEY
:
2086 return (u_char
*) OSPF_IF_PARAM (oi
, auth_simple
);
2088 case OSPFVIRTIFSTATUS
:
2089 return SNMP_INTEGER (SNMP_VALID
);
2091 case OSPFVIRTIFAUTHTYPE
:
2093 return SNMP_INTEGER (oi
->area
->auth_type
);
2095 return SNMP_INTEGER (0);
2104 static struct ospf_neighbor
*
2105 ospf_snmp_nbr_lookup (struct ospf
*ospf
, struct in_addr
*nbr_addr
,
2106 unsigned int *ifindex
)
2108 struct listnode
*node
, *nnode
;
2109 struct ospf_interface
*oi
;
2110 struct ospf_neighbor
*nbr
;
2111 struct route_node
*rn
;
2113 for (ALL_LIST_ELEMENTS (ospf
->oiflist
, node
, nnode
, oi
))
2115 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
2116 if ((nbr
= rn
->info
) != NULL
2117 && nbr
!= oi
->nbr_self
2118 /* If EXACT match is needed, provide ALL entry found
2119 && nbr->state != NSM_Down
2121 && nbr
->src
.s_addr
!= 0)
2123 if (IPV4_ADDR_SAME (&nbr
->src
, nbr_addr
))
2125 route_unlock_node (rn
);
2133 static struct ospf_neighbor
*
2134 ospf_snmp_nbr_lookup_next (struct in_addr
*nbr_addr
, unsigned int *ifindex
,
2137 struct listnode
*nn
;
2138 struct ospf_interface
*oi
;
2139 struct ospf_neighbor
*nbr
;
2140 struct route_node
*rn
;
2141 struct ospf_neighbor
*min
= NULL
;
2142 struct ospf
*ospf
= ospf
;
2144 ospf
= ospf_lookup ();
2146 for (ALL_LIST_ELEMENTS_RO (ospf
->oiflist
, nn
, oi
))
2148 for (rn
= route_top (oi
->nbrs
); rn
; rn
= route_next (rn
))
2149 if ((nbr
= rn
->info
) != NULL
2150 && nbr
!= oi
->nbr_self
2151 && nbr
->state
!= NSM_Down
2152 && nbr
->src
.s_addr
!= 0)
2158 else if (ntohl (nbr
->src
.s_addr
) < ntohl (min
->src
.s_addr
))
2161 else if (ntohl (nbr
->src
.s_addr
) > ntohl (nbr_addr
->s_addr
))
2165 else if (ntohl (nbr
->src
.s_addr
) < ntohl (min
->src
.s_addr
))
2172 *nbr_addr
= min
->src
;
2179 static struct ospf_neighbor
*
2180 ospfNbrLookup (struct variable
*v
, oid
*name
, size_t *length
,
2181 struct in_addr
*nbr_addr
, unsigned int *ifindex
, int exact
)
2185 struct ospf_neighbor
*nbr
;
2188 ospf
= ospf_lookup ();
2195 if (*length
!= v
->namelen
+ IN_ADDR_SIZE
+ 1)
2198 oid2in_addr (name
+ v
->namelen
, IN_ADDR_SIZE
, nbr_addr
);
2199 *ifindex
= name
[v
->namelen
+ IN_ADDR_SIZE
];
2201 return ospf_snmp_nbr_lookup (ospf
, nbr_addr
, ifindex
);
2206 len
= *length
- v
->namelen
;
2211 if (len
> IN_ADDR_SIZE
)
2214 oid2in_addr (name
+ v
->namelen
, len
, nbr_addr
);
2216 len
= *length
- v
->namelen
- IN_ADDR_SIZE
;
2218 *ifindex
= name
[v
->namelen
+ IN_ADDR_SIZE
];
2220 nbr
= ospf_snmp_nbr_lookup_next (nbr_addr
, ifindex
, first
);
2224 *length
= v
->namelen
+ IN_ADDR_SIZE
+ 1;
2225 oid_copy_addr (name
+ v
->namelen
, nbr_addr
, IN_ADDR_SIZE
);
2226 name
[v
->namelen
+ IN_ADDR_SIZE
] = *ifindex
;
2233 /* map internal quagga neighbor states to official MIB values:
2235 ospfNbrState OBJECT-TYPE
2248 ospf_snmp_neighbor_state(u_char nst
)
2267 return 1; /* down */
2272 ospfNbrEntry (struct variable
*v
, oid
*name
, size_t *length
, int exact
,
2273 size_t *var_len
, WriteMethod
**write_method
)
2275 struct in_addr nbr_addr
;
2276 unsigned int ifindex
;
2277 struct ospf_neighbor
*nbr
;
2278 struct ospf_interface
*oi
;
2280 memset (&nbr_addr
, 0, sizeof (struct in_addr
));
2283 nbr
= ospfNbrLookup (v
, name
, length
, &nbr_addr
, &ifindex
, exact
);
2290 /* Return the current value of the variable */
2294 return SNMP_IPADDRESS (nbr_addr
);
2296 case OSPFNBRADDRESSLESSINDEX
:
2297 return SNMP_INTEGER (ifindex
);
2300 return SNMP_IPADDRESS (nbr
->router_id
);
2302 case OSPFNBROPTIONS
:
2303 return SNMP_INTEGER (oi
->nbr_self
->options
);
2305 case OSPFNBRPRIORITY
:
2306 return SNMP_INTEGER (nbr
->priority
);
2309 return SNMP_INTEGER (ospf_snmp_neighbor_state(nbr
->state
));
2312 return SNMP_INTEGER (nbr
->state_change
);
2314 case OSPFNBRLSRETRANSQLEN
:
2315 return SNMP_INTEGER (ospf_ls_retransmit_count (nbr
));
2317 case OSPFNBMANBRSTATUS
:
2318 return SNMP_INTEGER (SNMP_VALID
);
2320 case OSPFNBMANBRPERMANENCE
:
2321 return SNMP_INTEGER (2);
2323 case OSPFNBRHELLOSUPPRESSED
:
2324 return SNMP_INTEGER (SNMP_FALSE
);
2334 ospfVirtNbrEntry (struct variable
*v
, oid
*name
, size_t *length
, int exact
,
2335 size_t *var_len
, WriteMethod
**write_method
)
2337 struct ospf_vl_data
*vl_data
;
2338 struct in_addr area_id
;
2339 struct in_addr neighbor
;
2342 memset (&area_id
, 0, sizeof (struct in_addr
));
2343 memset (&neighbor
, 0, sizeof (struct in_addr
));
2345 /* Check OSPF instance. */
2346 ospf
= ospf_lookup ();
2350 vl_data
= ospfVirtIfLookup (v
, name
, length
, &area_id
, &neighbor
, exact
);
2354 /* Return the current value of the variable */
2357 case OSPFVIRTNBRAREA
:
2358 return (u_char
*) NULL
;
2360 case OSPFVIRTNBRRTRID
:
2361 return (u_char
*) NULL
;
2363 case OSPFVIRTNBRIPADDR
:
2364 return (u_char
*) NULL
;
2366 case OSPFVIRTNBROPTIONS
:
2367 return (u_char
*) NULL
;
2369 case OSPFVIRTNBRSTATE
:
2370 return (u_char
*) NULL
;
2372 case OSPFVIRTNBREVENTS
:
2373 return (u_char
*) NULL
;
2375 case OSPFVIRTNBRLSRETRANSQLEN
:
2376 return (u_char
*) NULL
;
2378 case OSPFVIRTNBRHELLOSUPPRESSED
:
2379 return (u_char
*) NULL
;
2388 static struct ospf_lsa
*
2389 ospfExtLsdbLookup (struct variable
*v
, oid
*name
, size_t *length
, u_char
*type
,
2390 struct in_addr
*ls_id
, struct in_addr
*router_id
, int exact
)
2397 struct ospf_lsa
*lsa
;
2400 ospf
= ospf_lookup ();
2403 if (*length
!= v
->namelen
+ 1 + IN_ADDR_SIZE
+ IN_ADDR_SIZE
)
2406 offset
= name
+ v
->namelen
;
2408 /* Make it sure given value match to type. */
2412 if (lsa_type
!= *type
)
2416 oid2in_addr (offset
, IN_ADDR_SIZE
, ls_id
);
2417 offset
+= IN_ADDR_SIZE
;
2420 oid2in_addr (offset
, IN_ADDR_SIZE
, router_id
);
2422 return ospf_lsdb_lookup_by_id (ospf
->lsdb
, *type
, *ls_id
, *router_id
);
2426 /* Get variable length. */
2428 offset
= name
+ v
->namelen
;
2429 offsetlen
= *length
- v
->namelen
;
2431 /* LSA type value. */
2436 if (offsetlen
<= 0 || lsa_type
< OSPF_AS_EXTERNAL_LSA
)
2441 if (len
> IN_ADDR_SIZE
)
2444 oid2in_addr (offset
, len
, ls_id
);
2446 offset
+= IN_ADDR_SIZE
;
2447 offsetlen
-= IN_ADDR_SIZE
;
2451 if (len
> IN_ADDR_SIZE
)
2454 oid2in_addr (offset
, len
, router_id
);
2456 lsa
= ospf_lsdb_lookup_by_id_next (ospf
->lsdb
, *type
, *ls_id
,
2461 /* Fill in length. */
2462 *length
= v
->namelen
+ 1 + IN_ADDR_SIZE
+ IN_ADDR_SIZE
;
2464 /* Fill in value. */
2465 offset
= name
+ v
->namelen
;
2467 *offset
= OSPF_AS_EXTERNAL_LSA
;
2469 oid_copy_addr (offset
, &lsa
->data
->id
, IN_ADDR_SIZE
);
2470 offset
+= IN_ADDR_SIZE
;
2471 oid_copy_addr (offset
, &lsa
->data
->adv_router
, IN_ADDR_SIZE
);
2480 ospfExtLsdbEntry (struct variable
*v
, oid
*name
, size_t *length
, int exact
,
2481 size_t *var_len
, WriteMethod
**write_method
)
2483 struct ospf_lsa
*lsa
;
2484 struct lsa_header
*lsah
;
2486 struct in_addr ls_id
;
2487 struct in_addr router_id
;
2490 type
= OSPF_AS_EXTERNAL_LSA
;
2491 memset (&ls_id
, 0, sizeof (struct in_addr
));
2492 memset (&router_id
, 0, sizeof (struct in_addr
));
2494 /* Check OSPF instance. */
2495 ospf
= ospf_lookup ();
2499 lsa
= ospfExtLsdbLookup (v
, name
, length
, &type
, &ls_id
, &router_id
, exact
);
2505 /* Return the current value of the variable */
2508 case OSPFEXTLSDBTYPE
:
2509 return SNMP_INTEGER (OSPF_AS_EXTERNAL_LSA
);
2511 case OSPFEXTLSDBLSID
:
2512 return SNMP_IPADDRESS (lsah
->id
);
2514 case OSPFEXTLSDBROUTERID
:
2515 return SNMP_IPADDRESS (lsah
->adv_router
);
2517 case OSPFEXTLSDBSEQUENCE
:
2518 return SNMP_INTEGER (lsah
->ls_seqnum
);
2520 case OSPFEXTLSDBAGE
:
2521 return SNMP_INTEGER (lsah
->ls_age
);
2523 case OSPFEXTLSDBCHECKSUM
:
2524 return SNMP_INTEGER (lsah
->checksum
);
2526 case OSPFEXTLSDBADVERTISEMENT
:
2527 *var_len
= ntohs (lsah
->length
);
2528 return (u_char
*) lsah
;
2538 ospfAreaAggregateEntry (struct variable
*v
, oid
*name
, size_t *length
,
2539 int exact
, size_t *var_len
, WriteMethod
**write_method
)
2541 /* Return the current value of the variable */
2544 case OSPFAREAAGGREGATEAREAID
:
2545 return (u_char
*) NULL
;
2547 case OSPFAREAAGGREGATELSDBTYPE
:
2548 return (u_char
*) NULL
;
2550 case OSPFAREAAGGREGATENET
:
2551 return (u_char
*) NULL
;
2553 case OSPFAREAAGGREGATEMASK
:
2554 return (u_char
*) NULL
;
2556 case OSPFAREAAGGREGATESTATUS
:
2557 return (u_char
*) NULL
;
2559 case OSPFAREAAGGREGATEEFFECT
:
2560 return (u_char
*) NULL
;
2570 #define IFSTATECHANGE 16
2571 #define VIRTIFSTATECHANGE 1
2572 #define NBRSTATECHANGE 2
2573 #define VIRTNBRSTATECHANGE 3
2575 struct trap_object ospfNbrTrapList
[] =
2577 {ospfGeneralGroup
, -2, {1, OSPFROUTERID
}},
2578 {ospfNbrEntry
, 3, {10, 1, OSPFNBRIPADDR
}},
2579 {ospfNbrEntry
, 3, {10, 1, OSPFNBRRTRID
}},
2580 {ospfNbrEntry
, 3, {10, 1, OSPFNBRSTATE
}}
2584 struct trap_object ospfVirtNbrTrapList
[] =
2586 {ospfGeneralGroup
, -2, {1, 1}},
2587 {ospfVirtNbrEntry
, 3, {11, 1, OSPFVIRTNBRAREA
}},
2588 {ospfVirtNbrEntry
, 3, {11, 1, OSPFVIRTNBRRTRID
}},
2589 {ospfVirtNbrEntry
, 3, {11, 1, OSPFVIRTNBRSTATE
}}
2592 struct trap_object ospfIfTrapList
[] =
2594 {ospfGeneralGroup
, -2, {1, OSPFROUTERID
}},
2595 {ospfIfEntry
, 3, {7, 1, OSPFIFIPADDRESS
}},
2596 {ospfIfEntry
, 3, {7, 1, OSPFADDRESSLESSIF
}},
2597 {ospfIfEntry
, 3, {7, 1, OSPFIFSTATE
}}
2600 struct trap_object ospfVirtIfTrapList
[] =
2602 {ospfGeneralGroup
, -2, {1, OSPFROUTERID
}},
2603 {ospfVirtIfEntry
, 3, {9, 1, OSPFVIRTIFAREAID
}},
2604 {ospfVirtIfEntry
, 3, {9, 1, OSPFVIRTIFNEIGHBOR
}},
2605 {ospfVirtIfEntry
, 3, {9, 1, OSPFVIRTIFSTATE
}}
2609 ospfTrapNbrStateChange (struct ospf_neighbor
*on
)
2611 oid index
[sizeof (oid
) * (IN_ADDR_SIZE
+ 1)];
2614 ospf_nbr_state_message(on
, msgbuf
, sizeof(msgbuf
));
2615 zlog (NULL
, LOG_INFO
, "ospfTrapNbrStateChange trap sent: %s now %s",
2616 inet_ntoa(on
->address
.u
.prefix4
), msgbuf
);
2618 oid_copy_addr (index
, &(on
->address
.u
.prefix4
), IN_ADDR_SIZE
);
2619 index
[IN_ADDR_SIZE
] = 0;
2621 smux_trap (ospf_oid
, sizeof ospf_oid
/ sizeof (oid
),
2622 index
, IN_ADDR_SIZE
+ 1,
2624 sizeof ospfNbrTrapList
/ sizeof (struct trap_object
),
2625 time (NULL
), NBRSTATECHANGE
);
2629 ospfTrapVirtNbrStateChange (struct ospf_neighbor
*on
)
2631 oid index
[sizeof (oid
) * (IN_ADDR_SIZE
+ 1)];
2633 zlog (NULL
, LOG_INFO
, "ospfTrapVirtNbrStateChange trap sent");
2635 oid_copy_addr (index
, &(on
->address
.u
.prefix4
), IN_ADDR_SIZE
);
2636 index
[IN_ADDR_SIZE
] = 0;
2638 smux_trap (ospf_oid
, sizeof ospf_oid
/ sizeof (oid
),
2639 index
, IN_ADDR_SIZE
+ 1,
2640 ospfVirtNbrTrapList
,
2641 sizeof ospfVirtNbrTrapList
/ sizeof (struct trap_object
),
2642 time (NULL
), VIRTNBRSTATECHANGE
);
2646 ospfTrapIfStateChange (struct ospf_interface
*oi
)
2648 oid index
[sizeof (oid
) * (IN_ADDR_SIZE
+ 1)];
2650 zlog (NULL
, LOG_INFO
, "ospfTrapIfStateChange trap sent: %s now %s",
2651 inet_ntoa(oi
->address
->u
.prefix4
),
2652 LOOKUP(ospf_ism_state_msg
, oi
->state
));
2654 oid_copy_addr (index
, &(oi
->address
->u
.prefix4
), IN_ADDR_SIZE
);
2655 index
[IN_ADDR_SIZE
] = 0;
2657 smux_trap (ospf_oid
, sizeof ospf_oid
/ sizeof (oid
),
2658 index
, IN_ADDR_SIZE
+ 1,
2660 sizeof ospfIfTrapList
/ sizeof (struct trap_object
),
2661 time (NULL
), IFSTATECHANGE
);
2665 ospfTrapVirtIfStateChange (struct ospf_interface
*oi
)
2667 oid index
[sizeof (oid
) * (IN_ADDR_SIZE
+ 1)];
2669 zlog (NULL
, LOG_INFO
, "ospfTrapVirtIfStateChange trap sent");
2671 oid_copy_addr (index
, &(oi
->address
->u
.prefix4
), IN_ADDR_SIZE
);
2672 index
[IN_ADDR_SIZE
] = 0;
2674 smux_trap (ospf_oid
, sizeof ospf_oid
/ sizeof (oid
),
2675 index
, IN_ADDR_SIZE
+ 1,
2677 sizeof ospfVirtIfTrapList
/ sizeof (struct trap_object
),
2678 time (NULL
), VIRTIFSTATECHANGE
);
2680 /* Register OSPF2-MIB. */
2684 ospf_snmp_iflist
= list_new ();
2685 ospf_snmp_vl_table
= route_table_init ();
2686 smux_init (om
->master
);
2687 REGISTER_MIB("mibII/ospf", ospf_variables
, variable
, ospf_oid
);
2689 #endif /* HAVE_SNMP */