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 along
20 * with this program; see the file COPYING; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
26 #include <net-snmp/net-snmp-config.h>
27 #include <net-snmp/net-snmp-includes.h>
39 #include "ospfd/ospfd.h"
40 #include "ospfd/ospf_interface.h"
41 #include "ospfd/ospf_asbr.h"
42 #include "ospfd/ospf_lsa.h"
43 #include "ospfd/ospf_lsdb.h"
44 #include "ospfd/ospf_abr.h"
45 #include "ospfd/ospf_neighbor.h"
46 #include "ospfd/ospf_nsm.h"
47 #include "ospfd/ospf_flood.h"
48 #include "ospfd/ospf_ism.h"
49 #include "ospfd/ospf_dump.h"
50 #include "ospfd/ospf_route.h"
51 #include "ospfd/ospf_zebra.h"
54 #define OSPF2MIB 1,3,6,1,2,1,14
56 /* OSPF MIB General Group values. */
57 #define OSPFROUTERID 1
58 #define OSPFADMINSTAT 2
59 #define OSPFVERSIONNUMBER 3
60 #define OSPFAREABDRRTRSTATUS 4
61 #define OSPFASBDRRTRSTATUS 5
62 #define OSPFEXTERNLSACOUNT 6
63 #define OSPFEXTERNLSACKSUMSUM 7
64 #define OSPFTOSSUPPORT 8
65 #define OSPFORIGINATENEWLSAS 9
66 #define OSPFRXNEWLSAS 10
67 #define OSPFEXTLSDBLIMIT 11
68 #define OSPFMULTICASTEXTENSIONS 12
69 #define OSPFEXITOVERFLOWINTERVAL 13
70 #define OSPFDEMANDEXTENSIONS 14
72 /* OSPF MIB ospfAreaTable. */
74 #define OSPFAUTHTYPE 2
75 #define OSPFIMPORTASEXTERN 3
77 #define OSPFAREABDRRTRCOUNT 5
78 #define OSPFASBDRRTRCOUNT 6
79 #define OSPFAREALSACOUNT 7
80 #define OSPFAREALSACKSUMSUM 8
81 #define OSPFAREASUMMARY 9
82 #define OSPFAREASTATUS 10
84 /* OSPF MIB ospfStubAreaTable. */
85 #define OSPFSTUBAREAID 1
87 #define OSPFSTUBMETRIC 3
88 #define OSPFSTUBSTATUS 4
89 #define OSPFSTUBMETRICTYPE 5
91 /* OSPF MIB ospfLsdbTable. */
92 #define OSPFLSDBAREAID 1
93 #define OSPFLSDBTYPE 2
94 #define OSPFLSDBLSID 3
95 #define OSPFLSDBROUTERID 4
96 #define OSPFLSDBSEQUENCE 5
98 #define OSPFLSDBCHECKSUM 7
99 #define OSPFLSDBADVERTISEMENT 8
101 /* OSPF MIB ospfAreaRangeTable. */
102 #define OSPFAREARANGEAREAID 1
103 #define OSPFAREARANGENET 2
104 #define OSPFAREARANGEMASK 3
105 #define OSPFAREARANGESTATUS 4
106 #define OSPFAREARANGEEFFECT 5
108 /* OSPF MIB ospfHostTable. */
109 #define OSPFHOSTIPADDRESS 1
110 #define OSPFHOSTTOS 2
111 #define OSPFHOSTMETRIC 3
112 #define OSPFHOSTSTATUS 4
113 #define OSPFHOSTAREAID 5
115 /* OSPF MIB ospfIfTable. */
116 #define OSPFIFIPADDRESS 1
117 #define OSPFADDRESSLESSIF 2
118 #define OSPFIFAREAID 3
120 #define OSPFIFADMINSTAT 5
121 #define OSPFIFRTRPRIORITY 6
122 #define OSPFIFTRANSITDELAY 7
123 #define OSPFIFRETRANSINTERVAL 8
124 #define OSPFIFHELLOINTERVAL 9
125 #define OSPFIFRTRDEADINTERVAL 10
126 #define OSPFIFPOLLINTERVAL 11
127 #define OSPFIFSTATE 12
128 #define OSPFIFDESIGNATEDROUTER 13
129 #define OSPFIFBACKUPDESIGNATEDROUTER 14
130 #define OSPFIFEVENTS 15
131 #define OSPFIFAUTHKEY 16
132 #define OSPFIFSTATUS 17
133 #define OSPFIFMULTICASTFORWARDING 18
134 #define OSPFIFDEMAND 19
135 #define OSPFIFAUTHTYPE 20
137 /* OSPF MIB ospfIfMetricTable. */
138 #define OSPFIFMETRICIPADDRESS 1
139 #define OSPFIFMETRICADDRESSLESSIF 2
140 #define OSPFIFMETRICTOS 3
141 #define OSPFIFMETRICVALUE 4
142 #define OSPFIFMETRICSTATUS 5
144 /* OSPF MIB ospfVirtIfTable. */
145 #define OSPFVIRTIFAREAID 1
146 #define OSPFVIRTIFNEIGHBOR 2
147 #define OSPFVIRTIFTRANSITDELAY 3
148 #define OSPFVIRTIFRETRANSINTERVAL 4
149 #define OSPFVIRTIFHELLOINTERVAL 5
150 #define OSPFVIRTIFRTRDEADINTERVAL 6
151 #define OSPFVIRTIFSTATE 7
152 #define OSPFVIRTIFEVENTS 8
153 #define OSPFVIRTIFAUTHKEY 9
154 #define OSPFVIRTIFSTATUS 10
155 #define OSPFVIRTIFAUTHTYPE 11
157 /* OSPF MIB ospfNbrTable. */
158 #define OSPFNBRIPADDR 1
159 #define OSPFNBRADDRESSLESSINDEX 2
160 #define OSPFNBRRTRID 3
161 #define OSPFNBROPTIONS 4
162 #define OSPFNBRPRIORITY 5
163 #define OSPFNBRSTATE 6
164 #define OSPFNBREVENTS 7
165 #define OSPFNBRLSRETRANSQLEN 8
166 #define OSPFNBMANBRSTATUS 9
167 #define OSPFNBMANBRPERMANENCE 10
168 #define OSPFNBRHELLOSUPPRESSED 11
170 /* OSPF MIB ospfVirtNbrTable. */
171 #define OSPFVIRTNBRAREA 1
172 #define OSPFVIRTNBRRTRID 2
173 #define OSPFVIRTNBRIPADDR 3
174 #define OSPFVIRTNBROPTIONS 4
175 #define OSPFVIRTNBRSTATE 5
176 #define OSPFVIRTNBREVENTS 6
177 #define OSPFVIRTNBRLSRETRANSQLEN 7
178 #define OSPFVIRTNBRHELLOSUPPRESSED 8
180 /* OSPF MIB ospfExtLsdbTable. */
181 #define OSPFEXTLSDBTYPE 1
182 #define OSPFEXTLSDBLSID 2
183 #define OSPFEXTLSDBROUTERID 3
184 #define OSPFEXTLSDBSEQUENCE 4
185 #define OSPFEXTLSDBAGE 5
186 #define OSPFEXTLSDBCHECKSUM 6
187 #define OSPFEXTLSDBADVERTISEMENT 7
189 /* OSPF MIB ospfAreaAggregateTable. */
190 #define OSPFAREAAGGREGATEAREAID 1
191 #define OSPFAREAAGGREGATELSDBTYPE 2
192 #define OSPFAREAAGGREGATENET 3
193 #define OSPFAREAAGGREGATEMASK 4
194 #define OSPFAREAAGGREGATESTATUS 5
195 #define OSPFAREAAGGREGATEEFFECT 6
197 /* SYNTAX Status from OSPF-MIB. */
198 #define OSPF_STATUS_ENABLED 1
199 #define OSPF_STATUS_DISABLED 2
201 /* SNMP value hack. */
202 #define COUNTER ASN_COUNTER
203 #define INTEGER ASN_INTEGER
204 #define GAUGE ASN_GAUGE
205 #define TIMETICKS ASN_TIMETICKS
206 #define IPADDRESS ASN_IPADDRESS
207 #define STRING ASN_OCTET_STR
209 /* Because DR/DROther values are exhanged wrt RFC */
210 #define ISM_SNMP(x) \
211 (((x) == ISM_DROther) ? ISM_DR : ((x) == ISM_DR) ? ISM_DROther : (x))
213 /* Declare static local variables for convenience. */
216 /* OSPF-MIB instances. */
217 static oid ospf_oid
[] = {OSPF2MIB
};
218 static oid ospf_trap_oid
[] = {OSPF2MIB
, 16, 2}; /* Not reverse mappable! */
220 /* IP address 0.0.0.0. */
221 static struct in_addr ospf_empty_addr
= {.s_addr
= 0};
223 /* Hook functions. */
224 static uint8_t *ospfGeneralGroup(struct variable
*, oid
*, size_t *, int,
225 size_t *, WriteMethod
**);
226 static uint8_t *ospfAreaEntry(struct variable
*, oid
*, size_t *, int, size_t *,
228 static uint8_t *ospfStubAreaEntry(struct variable
*, oid
*, size_t *, int,
229 size_t *, WriteMethod
**);
230 static uint8_t *ospfLsdbEntry(struct variable
*, oid
*, size_t *, int, size_t *,
232 static uint8_t *ospfAreaRangeEntry(struct variable
*, oid
*, size_t *, int,
233 size_t *, WriteMethod
**);
234 static uint8_t *ospfHostEntry(struct variable
*, oid
*, size_t *, int, size_t *,
236 static uint8_t *ospfIfEntry(struct variable
*, oid
*, size_t *, int, size_t *,
238 static uint8_t *ospfIfMetricEntry(struct variable
*, oid
*, size_t *, int,
239 size_t *, WriteMethod
**);
240 static uint8_t *ospfVirtIfEntry(struct variable
*, oid
*, size_t *, int,
241 size_t *, WriteMethod
**);
242 static uint8_t *ospfNbrEntry(struct variable
*, oid
*, size_t *, int, size_t *,
244 static uint8_t *ospfVirtNbrEntry(struct variable
*, oid
*, size_t *, int,
245 size_t *, WriteMethod
**);
246 static uint8_t *ospfExtLsdbEntry(struct variable
*, oid
*, size_t *, int,
247 size_t *, WriteMethod
**);
248 static uint8_t *ospfAreaAggregateEntry(struct variable
*, oid
*, size_t *, int,
249 size_t *, WriteMethod
**);
251 static struct variable ospf_variables
[] = {
252 /* OSPF general variables */
253 {OSPFROUTERID
, IPADDRESS
, RWRITE
, ospfGeneralGroup
, 2, {1, 1}},
254 {OSPFADMINSTAT
, INTEGER
, RWRITE
, ospfGeneralGroup
, 2, {1, 2}},
255 {OSPFVERSIONNUMBER
, INTEGER
, RONLY
, ospfGeneralGroup
, 2, {1, 3}},
256 {OSPFAREABDRRTRSTATUS
, INTEGER
, RONLY
, ospfGeneralGroup
, 2, {1, 4}},
257 {OSPFASBDRRTRSTATUS
, INTEGER
, RWRITE
, ospfGeneralGroup
, 2, {1, 5}},
258 {OSPFEXTERNLSACOUNT
, GAUGE
, RONLY
, ospfGeneralGroup
, 2, {1, 6}},
259 {OSPFEXTERNLSACKSUMSUM
, INTEGER
, RONLY
, ospfGeneralGroup
, 2, {1, 7}},
260 {OSPFTOSSUPPORT
, INTEGER
, RWRITE
, ospfGeneralGroup
, 2, {1, 8}},
261 {OSPFORIGINATENEWLSAS
, COUNTER
, RONLY
, ospfGeneralGroup
, 2, {1, 9}},
262 {OSPFRXNEWLSAS
, COUNTER
, RONLY
, ospfGeneralGroup
, 2, {1, 10}},
263 {OSPFEXTLSDBLIMIT
, INTEGER
, RWRITE
, ospfGeneralGroup
, 2, {1, 11}},
264 {OSPFMULTICASTEXTENSIONS
,
270 {OSPFEXITOVERFLOWINTERVAL
,
276 {OSPFDEMANDEXTENSIONS
, INTEGER
, RWRITE
, ospfGeneralGroup
, 2, {1, 14}},
278 /* OSPF area data structure. */
279 {OSPFAREAID
, IPADDRESS
, RONLY
, ospfAreaEntry
, 3, {2, 1, 1}},
280 {OSPFAUTHTYPE
, INTEGER
, RWRITE
, ospfAreaEntry
, 3, {2, 1, 2}},
281 {OSPFIMPORTASEXTERN
, INTEGER
, RWRITE
, ospfAreaEntry
, 3, {2, 1, 3}},
282 {OSPFSPFRUNS
, COUNTER
, RONLY
, ospfAreaEntry
, 3, {2, 1, 4}},
283 {OSPFAREABDRRTRCOUNT
, GAUGE
, RONLY
, ospfAreaEntry
, 3, {2, 1, 5}},
284 {OSPFASBDRRTRCOUNT
, GAUGE
, RONLY
, ospfAreaEntry
, 3, {2, 1, 6}},
285 {OSPFAREALSACOUNT
, GAUGE
, RONLY
, ospfAreaEntry
, 3, {2, 1, 7}},
286 {OSPFAREALSACKSUMSUM
, INTEGER
, RONLY
, ospfAreaEntry
, 3, {2, 1, 8}},
287 {OSPFAREASUMMARY
, INTEGER
, RWRITE
, ospfAreaEntry
, 3, {2, 1, 9}},
288 {OSPFAREASTATUS
, INTEGER
, RWRITE
, ospfAreaEntry
, 3, {2, 1, 10}},
290 /* OSPF stub area information. */
291 {OSPFSTUBAREAID
, IPADDRESS
, RONLY
, ospfStubAreaEntry
, 3, {3, 1, 1}},
292 {OSPFSTUBTOS
, INTEGER
, RONLY
, ospfStubAreaEntry
, 3, {3, 1, 2}},
293 {OSPFSTUBMETRIC
, INTEGER
, RWRITE
, ospfStubAreaEntry
, 3, {3, 1, 3}},
294 {OSPFSTUBSTATUS
, INTEGER
, RWRITE
, ospfStubAreaEntry
, 3, {3, 1, 4}},
295 {OSPFSTUBMETRICTYPE
, INTEGER
, RWRITE
, ospfStubAreaEntry
, 3, {3, 1, 5}},
297 /* OSPF link state database. */
298 {OSPFLSDBAREAID
, IPADDRESS
, RONLY
, ospfLsdbEntry
, 3, {4, 1, 1}},
299 {OSPFLSDBTYPE
, INTEGER
, RONLY
, ospfLsdbEntry
, 3, {4, 1, 2}},
300 {OSPFLSDBLSID
, IPADDRESS
, RONLY
, ospfLsdbEntry
, 3, {4, 1, 3}},
301 {OSPFLSDBROUTERID
, IPADDRESS
, RONLY
, ospfLsdbEntry
, 3, {4, 1, 4}},
302 {OSPFLSDBSEQUENCE
, INTEGER
, RONLY
, ospfLsdbEntry
, 3, {4, 1, 5}},
303 {OSPFLSDBAGE
, INTEGER
, RONLY
, ospfLsdbEntry
, 3, {4, 1, 6}},
304 {OSPFLSDBCHECKSUM
, INTEGER
, RONLY
, ospfLsdbEntry
, 3, {4, 1, 7}},
305 {OSPFLSDBADVERTISEMENT
, STRING
, RONLY
, ospfLsdbEntry
, 3, {4, 1, 8}},
307 /* Area range table. */
308 {OSPFAREARANGEAREAID
,
314 {OSPFAREARANGENET
, IPADDRESS
, RONLY
, ospfAreaRangeEntry
, 3, {5, 1, 2}},
321 {OSPFAREARANGESTATUS
,
327 {OSPFAREARANGEEFFECT
,
334 /* OSPF host table. */
335 {OSPFHOSTIPADDRESS
, IPADDRESS
, RONLY
, ospfHostEntry
, 3, {6, 1, 1}},
336 {OSPFHOSTTOS
, INTEGER
, RONLY
, ospfHostEntry
, 3, {6, 1, 2}},
337 {OSPFHOSTMETRIC
, INTEGER
, RWRITE
, ospfHostEntry
, 3, {6, 1, 3}},
338 {OSPFHOSTSTATUS
, INTEGER
, RWRITE
, ospfHostEntry
, 3, {6, 1, 4}},
339 {OSPFHOSTAREAID
, IPADDRESS
, RONLY
, ospfHostEntry
, 3, {6, 1, 5}},
341 /* OSPF interface table. */
342 {OSPFIFIPADDRESS
, IPADDRESS
, RONLY
, ospfIfEntry
, 3, {7, 1, 1}},
343 {OSPFADDRESSLESSIF
, INTEGER
, RONLY
, ospfIfEntry
, 3, {7, 1, 2}},
344 {OSPFIFAREAID
, IPADDRESS
, RWRITE
, ospfIfEntry
, 3, {7, 1, 3}},
345 {OSPFIFTYPE
, INTEGER
, RWRITE
, ospfIfEntry
, 3, {7, 1, 4}},
346 {OSPFIFADMINSTAT
, INTEGER
, RWRITE
, ospfIfEntry
, 3, {7, 1, 5}},
347 {OSPFIFRTRPRIORITY
, INTEGER
, RWRITE
, ospfIfEntry
, 3, {7, 1, 6}},
348 {OSPFIFTRANSITDELAY
, INTEGER
, RWRITE
, ospfIfEntry
, 3, {7, 1, 7}},
349 {OSPFIFRETRANSINTERVAL
, INTEGER
, RWRITE
, ospfIfEntry
, 3, {7, 1, 8}},
350 {OSPFIFHELLOINTERVAL
, INTEGER
, RWRITE
, ospfIfEntry
, 3, {7, 1, 9}},
351 {OSPFIFRTRDEADINTERVAL
, INTEGER
, RWRITE
, ospfIfEntry
, 3, {7, 1, 10}},
352 {OSPFIFPOLLINTERVAL
, INTEGER
, RWRITE
, ospfIfEntry
, 3, {7, 1, 11}},
353 {OSPFIFSTATE
, INTEGER
, RONLY
, ospfIfEntry
, 3, {7, 1, 12}},
354 {OSPFIFDESIGNATEDROUTER
, IPADDRESS
, RONLY
, ospfIfEntry
, 3, {7, 1, 13}},
355 {OSPFIFBACKUPDESIGNATEDROUTER
,
361 {OSPFIFEVENTS
, COUNTER
, RONLY
, ospfIfEntry
, 3, {7, 1, 15}},
362 {OSPFIFAUTHKEY
, STRING
, RWRITE
, ospfIfEntry
, 3, {7, 1, 16}},
363 {OSPFIFSTATUS
, INTEGER
, RWRITE
, ospfIfEntry
, 3, {7, 1, 17}},
364 {OSPFIFMULTICASTFORWARDING
,
370 {OSPFIFDEMAND
, INTEGER
, RWRITE
, ospfIfEntry
, 3, {7, 1, 19}},
371 {OSPFIFAUTHTYPE
, INTEGER
, RWRITE
, ospfIfEntry
, 3, {7, 1, 20}},
373 /* OSPF interface metric table. */
374 {OSPFIFMETRICIPADDRESS
,
380 {OSPFIFMETRICADDRESSLESSIF
,
386 {OSPFIFMETRICTOS
, INTEGER
, RONLY
, ospfIfMetricEntry
, 3, {8, 1, 3}},
387 {OSPFIFMETRICVALUE
, INTEGER
, RWRITE
, ospfIfMetricEntry
, 3, {8, 1, 4}},
388 {OSPFIFMETRICSTATUS
, INTEGER
, RWRITE
, ospfIfMetricEntry
, 3, {8, 1, 5}},
390 /* OSPF virtual interface table. */
391 {OSPFVIRTIFAREAID
, IPADDRESS
, RONLY
, ospfVirtIfEntry
, 3, {9, 1, 1}},
392 {OSPFVIRTIFNEIGHBOR
, IPADDRESS
, RONLY
, ospfVirtIfEntry
, 3, {9, 1, 2}},
393 {OSPFVIRTIFTRANSITDELAY
,
399 {OSPFVIRTIFRETRANSINTERVAL
,
405 {OSPFVIRTIFHELLOINTERVAL
,
411 {OSPFVIRTIFRTRDEADINTERVAL
,
417 {OSPFVIRTIFSTATE
, INTEGER
, RONLY
, ospfVirtIfEntry
, 3, {9, 1, 7}},
418 {OSPFVIRTIFEVENTS
, COUNTER
, RONLY
, ospfVirtIfEntry
, 3, {9, 1, 8}},
419 {OSPFVIRTIFAUTHKEY
, STRING
, RWRITE
, ospfVirtIfEntry
, 3, {9, 1, 9}},
420 {OSPFVIRTIFSTATUS
, INTEGER
, RWRITE
, ospfVirtIfEntry
, 3, {9, 1, 10}},
421 {OSPFVIRTIFAUTHTYPE
, INTEGER
, RWRITE
, ospfVirtIfEntry
, 3, {9, 1, 11}},
423 /* OSPF neighbor table. */
424 {OSPFNBRIPADDR
, IPADDRESS
, RONLY
, ospfNbrEntry
, 3, {10, 1, 1}},
425 {OSPFNBRADDRESSLESSINDEX
, INTEGER
, RONLY
, ospfNbrEntry
, 3, {10, 1, 2}},
426 {OSPFNBRRTRID
, IPADDRESS
, RONLY
, ospfNbrEntry
, 3, {10, 1, 3}},
427 {OSPFNBROPTIONS
, INTEGER
, RONLY
, ospfNbrEntry
, 3, {10, 1, 4}},
428 {OSPFNBRPRIORITY
, INTEGER
, RWRITE
, ospfNbrEntry
, 3, {10, 1, 5}},
429 {OSPFNBRSTATE
, INTEGER
, RONLY
, ospfNbrEntry
, 3, {10, 1, 6}},
430 {OSPFNBREVENTS
, COUNTER
, RONLY
, ospfNbrEntry
, 3, {10, 1, 7}},
431 {OSPFNBRLSRETRANSQLEN
, GAUGE
, RONLY
, ospfNbrEntry
, 3, {10, 1, 8}},
432 {OSPFNBMANBRSTATUS
, INTEGER
, RWRITE
, ospfNbrEntry
, 3, {10, 1, 9}},
433 {OSPFNBMANBRPERMANENCE
, INTEGER
, RONLY
, ospfNbrEntry
, 3, {10, 1, 10}},
434 {OSPFNBRHELLOSUPPRESSED
, INTEGER
, RONLY
, ospfNbrEntry
, 3, {10, 1, 11}},
436 /* OSPF virtual neighbor table. */
437 {OSPFVIRTNBRAREA
, IPADDRESS
, RONLY
, ospfVirtNbrEntry
, 3, {11, 1, 1}},
438 {OSPFVIRTNBRRTRID
, IPADDRESS
, RONLY
, ospfVirtNbrEntry
, 3, {11, 1, 2}},
439 {OSPFVIRTNBRIPADDR
, IPADDRESS
, RONLY
, ospfVirtNbrEntry
, 3, {11, 1, 3}},
440 {OSPFVIRTNBROPTIONS
, INTEGER
, RONLY
, ospfVirtNbrEntry
, 3, {11, 1, 4}},
441 {OSPFVIRTNBRSTATE
, INTEGER
, RONLY
, ospfVirtNbrEntry
, 3, {11, 1, 5}},
442 {OSPFVIRTNBREVENTS
, COUNTER
, RONLY
, ospfVirtNbrEntry
, 3, {11, 1, 6}},
443 {OSPFVIRTNBRLSRETRANSQLEN
,
449 {OSPFVIRTNBRHELLOSUPPRESSED
,
456 /* OSPF link state database, external. */
457 {OSPFEXTLSDBTYPE
, INTEGER
, RONLY
, ospfExtLsdbEntry
, 3, {12, 1, 1}},
458 {OSPFEXTLSDBLSID
, IPADDRESS
, RONLY
, ospfExtLsdbEntry
, 3, {12, 1, 2}},
459 {OSPFEXTLSDBROUTERID
,
465 {OSPFEXTLSDBSEQUENCE
, INTEGER
, RONLY
, ospfExtLsdbEntry
, 3, {12, 1, 4}},
466 {OSPFEXTLSDBAGE
, INTEGER
, RONLY
, ospfExtLsdbEntry
, 3, {12, 1, 5}},
467 {OSPFEXTLSDBCHECKSUM
, INTEGER
, RONLY
, ospfExtLsdbEntry
, 3, {12, 1, 6}},
468 {OSPFEXTLSDBADVERTISEMENT
,
475 /* OSPF area aggregate table. */
476 {OSPFAREAAGGREGATEAREAID
,
479 ospfAreaAggregateEntry
,
482 {OSPFAREAAGGREGATELSDBTYPE
,
485 ospfAreaAggregateEntry
,
488 {OSPFAREAAGGREGATENET
,
491 ospfAreaAggregateEntry
,
494 {OSPFAREAAGGREGATEMASK
,
497 ospfAreaAggregateEntry
,
500 {OSPFAREAAGGREGATESTATUS
,
503 ospfAreaAggregateEntry
,
506 {OSPFAREAAGGREGATEEFFECT
,
509 ospfAreaAggregateEntry
,
513 /* The administrative status of OSPF. When OSPF is enbled on at least
514 one interface return 1. */
515 static int ospf_admin_stat(struct ospf
*ospf
)
517 struct listnode
*node
;
518 struct ospf_interface
*oi
;
523 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, node
, oi
))
524 if (oi
&& oi
->address
)
530 static uint8_t *ospfGeneralGroup(struct variable
*v
, oid
*name
, size_t *length
,
531 int exact
, size_t *var_len
,
532 WriteMethod
**write_method
)
536 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
538 /* Check whether the instance identifier is valid */
539 if (smux_header_generic(v
, name
, length
, exact
, var_len
, write_method
)
543 /* Return the current value of the variable */
545 case OSPFROUTERID
: /* 1 */
546 /* Router-ID of this OSPF instance. */
548 return SNMP_IPADDRESS(ospf
->router_id
);
550 return SNMP_IPADDRESS(ospf_empty_addr
);
552 case OSPFADMINSTAT
: /* 2 */
553 /* The administrative status of OSPF in the router. */
554 if (ospf_admin_stat(ospf
))
555 return SNMP_INTEGER(OSPF_STATUS_ENABLED
);
557 return SNMP_INTEGER(OSPF_STATUS_DISABLED
);
559 case OSPFVERSIONNUMBER
: /* 3 */
560 /* OSPF version 2. */
561 return SNMP_INTEGER(OSPF_VERSION
);
563 case OSPFAREABDRRTRSTATUS
: /* 4 */
564 /* Area Border router status. */
565 if (ospf
&& CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ABR
))
566 return SNMP_INTEGER(SNMP_TRUE
);
568 return SNMP_INTEGER(SNMP_FALSE
);
570 case OSPFASBDRRTRSTATUS
: /* 5 */
571 /* AS Border router status. */
572 if (ospf
&& CHECK_FLAG(ospf
->flags
, OSPF_FLAG_ASBR
))
573 return SNMP_INTEGER(SNMP_TRUE
);
575 return SNMP_INTEGER(SNMP_FALSE
);
577 case OSPFEXTERNLSACOUNT
: /* 6 */
578 /* External LSA counts. */
580 return SNMP_INTEGER(ospf_lsdb_count_all(ospf
->lsdb
));
582 return SNMP_INTEGER(0);
584 case OSPFEXTERNLSACKSUMSUM
: /* 7 */
585 /* External LSA checksum. */
586 return SNMP_INTEGER(0);
588 case OSPFTOSSUPPORT
: /* 8 */
589 /* TOS is not supported. */
590 return SNMP_INTEGER(SNMP_FALSE
);
592 case OSPFORIGINATENEWLSAS
: /* 9 */
593 /* The number of new link-state advertisements. */
595 return SNMP_INTEGER(ospf
->lsa_originate_count
);
597 return SNMP_INTEGER(0);
599 case OSPFRXNEWLSAS
: /* 10 */
600 /* The number of link-state advertisements received determined
601 to be new instantiations. */
603 return SNMP_INTEGER(ospf
->rx_lsa_count
);
605 return SNMP_INTEGER(0);
607 case OSPFEXTLSDBLIMIT
: /* 11 */
608 /* There is no limit for the number of non-default
610 return SNMP_INTEGER(-1);
612 case OSPFMULTICASTEXTENSIONS
: /* 12 */
613 /* Multicast Extensions to OSPF is not supported. */
614 return SNMP_INTEGER(0);
616 case OSPFEXITOVERFLOWINTERVAL
: /* 13 */
617 /* Overflow is not supported. */
618 return SNMP_INTEGER(0);
620 case OSPFDEMANDEXTENSIONS
: /* 14 */
621 /* Demand routing is not supported. */
622 return SNMP_INTEGER(SNMP_FALSE
);
630 static struct ospf_area
*
631 ospf_area_lookup_next(struct ospf
*ospf
, struct in_addr
*area_id
, int first
)
633 struct ospf_area
*area
;
634 struct listnode
*node
;
640 node
= listhead(ospf
->areas
);
642 area
= listgetdata(node
);
643 *area_id
= area
->area_id
;
648 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
649 if (ntohl(area
->area_id
.s_addr
) > ntohl(area_id
->s_addr
)) {
650 *area_id
= area
->area_id
;
657 static struct ospf_area
*ospfAreaLookup(struct variable
*v
, oid name
[],
658 size_t *length
, struct in_addr
*addr
,
662 struct ospf_area
*area
;
665 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
670 /* Length is insufficient to lookup OSPF area. */
671 if (*length
- v
->namelen
!= sizeof(struct in_addr
))
674 oid2in_addr(name
+ v
->namelen
, sizeof(struct in_addr
), addr
);
676 area
= ospf_area_lookup_by_area_id(ospf
, *addr
);
680 len
= *length
- v
->namelen
;
684 oid2in_addr(name
+ v
->namelen
, len
, addr
);
686 area
= ospf_area_lookup_next(ospf
, addr
, len
== 0 ? 1 : 0);
691 oid_copy_addr(name
+ v
->namelen
, addr
, sizeof(struct in_addr
));
692 *length
= sizeof(struct in_addr
) + v
->namelen
;
699 static uint8_t *ospfAreaEntry(struct variable
*v
, oid
*name
, size_t *length
,
700 int exact
, size_t *var_len
,
701 WriteMethod
**write_method
)
703 struct ospf_area
*area
;
706 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
710 memset(&addr
, 0, sizeof(struct in_addr
));
712 area
= ospfAreaLookup(v
, name
, length
, &addr
, exact
);
716 /* Return the current value of the variable */
718 case OSPFAREAID
: /* 1 */
719 return SNMP_IPADDRESS(area
->area_id
);
721 case OSPFAUTHTYPE
: /* 2 */
722 return SNMP_INTEGER(area
->auth_type
);
724 case OSPFIMPORTASEXTERN
: /* 3 */
725 return SNMP_INTEGER(area
->external_routing
+ 1);
727 case OSPFSPFRUNS
: /* 4 */
728 return SNMP_INTEGER(area
->spf_calculation
);
730 case OSPFAREABDRRTRCOUNT
: /* 5 */
731 return SNMP_INTEGER(area
->abr_count
);
733 case OSPFASBDRRTRCOUNT
: /* 6 */
734 return SNMP_INTEGER(area
->asbr_count
);
736 case OSPFAREALSACOUNT
: /* 7 */
737 return SNMP_INTEGER(area
->lsdb
->total
);
739 case OSPFAREALSACKSUMSUM
: /* 8 */
740 return SNMP_INTEGER(0);
742 case OSPFAREASUMMARY
: /* 9 */
743 #define OSPF_noAreaSummary 1
744 #define OSPF_sendAreaSummary 2
745 if (area
->no_summary
)
746 return SNMP_INTEGER(OSPF_noAreaSummary
);
748 return SNMP_INTEGER(OSPF_sendAreaSummary
);
750 case OSPFAREASTATUS
: /* 10 */
751 return SNMP_INTEGER(SNMP_VALID
);
760 static struct ospf_area
*ospf_stub_area_lookup_next(struct in_addr
*area_id
,
763 struct ospf_area
*area
;
764 struct listnode
*node
;
767 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
771 for (ALL_LIST_ELEMENTS_RO(ospf
->areas
, node
, area
)) {
772 if (area
->external_routing
== OSPF_AREA_STUB
) {
774 *area_id
= area
->area_id
;
776 } else if (ntohl(area
->area_id
.s_addr
)
777 > ntohl(area_id
->s_addr
)) {
778 *area_id
= area
->area_id
;
786 static struct ospf_area
*ospfStubAreaLookup(struct variable
*v
, oid name
[],
788 struct in_addr
*addr
, int exact
)
791 struct ospf_area
*area
;
794 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
800 /* ospfStubAreaID + ospfStubTOS. */
801 if (*length
!= v
->namelen
+ sizeof(struct in_addr
) + 1)
804 /* Check ospfStubTOS is zero. */
805 if (name
[*length
- 1] != 0)
808 oid2in_addr(name
+ v
->namelen
, sizeof(struct in_addr
), addr
);
810 area
= ospf_area_lookup_by_area_id(ospf
, *addr
);
812 if (area
->external_routing
== OSPF_AREA_STUB
)
817 len
= *length
- v
->namelen
;
821 oid2in_addr(name
+ v
->namelen
, len
, addr
);
823 area
= ospf_stub_area_lookup_next(addr
, len
== 0 ? 1 : 0);
828 oid_copy_addr(name
+ v
->namelen
, addr
, sizeof(struct in_addr
));
830 name
[v
->namelen
+ sizeof(struct in_addr
)] = 0;
831 *length
= v
->namelen
+ sizeof(struct in_addr
) + 1;
838 static uint8_t *ospfStubAreaEntry(struct variable
*v
, oid
*name
, size_t *length
,
839 int exact
, size_t *var_len
,
840 WriteMethod
**write_method
)
842 struct ospf_area
*area
;
845 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
849 memset(&addr
, 0, sizeof(struct in_addr
));
851 area
= ospfStubAreaLookup(v
, name
, length
, &addr
, exact
);
855 /* Return the current value of the variable */
857 case OSPFSTUBAREAID
: /* 1 */
858 /* OSPF stub area id. */
859 return SNMP_IPADDRESS(area
->area_id
);
861 case OSPFSTUBTOS
: /* 2 */
862 /* TOS value is not supported. */
863 return SNMP_INTEGER(0);
865 case OSPFSTUBMETRIC
: /* 3 */
866 /* Default cost to stub area. */
867 return SNMP_INTEGER(area
->default_cost
);
869 case OSPFSTUBSTATUS
: /* 4 */
870 /* Status of the stub area. */
871 return SNMP_INTEGER(SNMP_VALID
);
873 case OSPFSTUBMETRICTYPE
: /* 5 */
874 /* OSPF Metric type. */
875 #define OSPF_ospfMetric 1
876 #define OSPF_comparableCost 2
877 #define OSPF_nonComparable 3
878 return SNMP_INTEGER(OSPF_ospfMetric
);
887 static struct ospf_lsa
*lsdb_lookup_next(struct ospf_area
*area
, uint8_t *type
,
888 int type_next
, struct in_addr
*ls_id
,
890 struct in_addr
*router_id
,
893 struct ospf_lsa
*lsa
;
901 /* Sanity check, if LSA type unknwon
902 merley skip any LSA */
903 if ((i
< OSPF_MIN_LSA
) || (i
>= OSPF_MAX_LSA
)) {
904 zlog_debug("Strange request with LSA type %d\n", i
);
908 for (; i
< OSPF_MAX_LSA
; i
++) {
911 lsa
= ospf_lsdb_lookup_by_id_next(area
->lsdb
, *type
, *ls_id
,
912 *router_id
, ls_id_next
);
921 static struct ospf_lsa
*ospfLsdbLookup(struct variable
*v
, oid
*name
,
922 size_t *length
, struct in_addr
*area_id
,
923 uint8_t *type
, struct in_addr
*ls_id
,
924 struct in_addr
*router_id
, int exact
)
927 struct ospf_area
*area
;
928 struct ospf_lsa
*lsa
;
936 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
938 #define OSPF_LSDB_ENTRY_OFFSET (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE + IN_ADDR_SIZE)
941 /* Area ID + Type + LS ID + Router ID. */
942 if (*length
- v
->namelen
!= OSPF_LSDB_ENTRY_OFFSET
)
945 /* Set OID offset for Area ID. */
946 offset
= name
+ v
->namelen
;
948 /* Lookup area first. */
949 oid2in_addr(offset
, IN_ADDR_SIZE
, area_id
);
950 area
= ospf_area_lookup_by_area_id(ospf
, *area_id
);
953 offset
+= IN_ADDR_SIZE
;
960 oid2in_addr(offset
, IN_ADDR_SIZE
, ls_id
);
961 offset
+= IN_ADDR_SIZE
;
964 oid2in_addr(offset
, IN_ADDR_SIZE
, router_id
);
967 return ospf_lsdb_lookup_by_id(area
->lsdb
, *type
, *ls_id
,
970 /* Get variable length. */
971 offset
= name
+ v
->namelen
;
972 offsetlen
= *length
- v
->namelen
;
975 if (len
> (int)IN_ADDR_SIZE
)
978 oid2in_addr(offset
, len
, area_id
);
980 /* First we search area. */
981 if (len
== IN_ADDR_SIZE
)
982 area
= ospf_area_lookup_by_area_id(ospf
, *area_id
);
984 area
= ospf_area_lookup_next(ospf
, area_id
, 1);
990 /* Next we lookup type. */
1012 if (len
> (int)IN_ADDR_SIZE
)
1015 oid2in_addr(offset
, len
, ls_id
);
1019 offset
+= IN_ADDR_SIZE
;
1020 offsetlen
-= IN_ADDR_SIZE
;
1027 if (len
> (int)IN_ADDR_SIZE
)
1030 oid2in_addr(offset
, len
, router_id
);
1033 lsa
= lsdb_lookup_next(area
, type
, type_next
, ls_id
,
1034 ls_id_next
, router_id
,
1038 /* Fill in length. */
1039 *length
= v
->namelen
+ OSPF_LSDB_ENTRY_OFFSET
;
1041 /* Fill in value. */
1042 offset
= name
+ v
->namelen
;
1043 oid_copy_addr(offset
, area_id
, IN_ADDR_SIZE
);
1044 offset
+= IN_ADDR_SIZE
;
1045 *offset
= lsa
->data
->type
;
1047 oid_copy_addr(offset
, &lsa
->data
->id
,
1049 offset
+= IN_ADDR_SIZE
;
1050 oid_copy_addr(offset
, &lsa
->data
->adv_router
,
1055 } while ((area
= ospf_area_lookup_next(ospf
, area_id
, 0))
1061 static uint8_t *ospfLsdbEntry(struct variable
*v
, oid
*name
, size_t *length
,
1062 int exact
, size_t *var_len
,
1063 WriteMethod
**write_method
)
1065 struct ospf_lsa
*lsa
;
1066 struct lsa_header
*lsah
;
1067 struct in_addr area_id
;
1069 struct in_addr ls_id
;
1070 struct in_addr router_id
;
1073 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
1077 /* INDEX { ospfLsdbAreaId, ospfLsdbType,
1078 ospfLsdbLsid, ospfLsdbRouterId } */
1080 memset(&area_id
, 0, sizeof(struct in_addr
));
1082 memset(&ls_id
, 0, sizeof(struct in_addr
));
1083 memset(&router_id
, 0, sizeof(struct in_addr
));
1085 /* Check OSPF instance. */
1086 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1090 lsa
= ospfLsdbLookup(v
, name
, length
, &area_id
, &type
, &ls_id
,
1097 /* Return the current value of the variable */
1099 case OSPFLSDBAREAID
: /* 1 */
1100 return SNMP_IPADDRESS(lsa
->area
->area_id
);
1102 case OSPFLSDBTYPE
: /* 2 */
1103 return SNMP_INTEGER(lsah
->type
);
1105 case OSPFLSDBLSID
: /* 3 */
1106 return SNMP_IPADDRESS(lsah
->id
);
1108 case OSPFLSDBROUTERID
: /* 4 */
1109 return SNMP_IPADDRESS(lsah
->adv_router
);
1111 case OSPFLSDBSEQUENCE
: /* 5 */
1112 return SNMP_INTEGER(lsah
->ls_seqnum
);
1114 case OSPFLSDBAGE
: /* 6 */
1115 return SNMP_INTEGER(lsah
->ls_age
);
1117 case OSPFLSDBCHECKSUM
: /* 7 */
1118 return SNMP_INTEGER(lsah
->checksum
);
1120 case OSPFLSDBADVERTISEMENT
: /* 8 */
1121 *var_len
= ntohs(lsah
->length
);
1122 return (uint8_t *)lsah
;
1131 static struct ospf_area_range
*ospfAreaRangeLookup(struct variable
*v
,
1132 oid
*name
, size_t *length
,
1133 struct in_addr
*area_id
,
1134 struct in_addr
*range_net
,
1141 struct ospf_area
*area
;
1142 struct ospf_area_range
*range
;
1143 struct prefix_ipv4 p
;
1145 p
.prefixlen
= IPV4_MAX_BITLEN
;
1147 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1150 /* Area ID + Range Network. */
1151 if (v
->namelen
+ IN_ADDR_SIZE
+ IN_ADDR_SIZE
!= *length
)
1154 /* Set OID offset for Area ID. */
1155 offset
= name
+ v
->namelen
;
1157 /* Lookup area first. */
1158 oid2in_addr(offset
, IN_ADDR_SIZE
, area_id
);
1160 area
= ospf_area_lookup_by_area_id(ospf
, *area_id
);
1164 offset
+= IN_ADDR_SIZE
;
1166 /* Lookup area range. */
1167 oid2in_addr(offset
, IN_ADDR_SIZE
, range_net
);
1168 p
.prefix
= *range_net
;
1170 return ospf_area_range_lookup(area
, &p
);
1172 /* Set OID offset for Area ID. */
1173 offset
= name
+ v
->namelen
;
1174 offsetlen
= *length
- v
->namelen
;
1177 if (len
> (int)IN_ADDR_SIZE
)
1180 oid2in_addr(offset
, len
, area_id
);
1182 /* First we search area. */
1183 if (len
== IN_ADDR_SIZE
)
1184 area
= ospf_area_lookup_by_area_id(ospf
, *area_id
);
1186 area
= ospf_area_lookup_next(ospf
, area_id
,
1193 offset
+= IN_ADDR_SIZE
;
1194 offsetlen
-= IN_ADDR_SIZE
;
1199 if (len
> (int)IN_ADDR_SIZE
)
1202 oid2in_addr(offset
, len
, range_net
);
1204 range
= ospf_area_range_lookup_next(area
, range_net
,
1208 /* Fill in length. */
1209 *length
= v
->namelen
+ IN_ADDR_SIZE
1212 /* Fill in value. */
1213 offset
= name
+ v
->namelen
;
1214 oid_copy_addr(offset
, area_id
, IN_ADDR_SIZE
);
1215 offset
+= IN_ADDR_SIZE
;
1216 oid_copy_addr(offset
, range_net
, IN_ADDR_SIZE
);
1220 } while ((area
= ospf_area_lookup_next(ospf
, area_id
, 0))
1226 static uint8_t *ospfAreaRangeEntry(struct variable
*v
, oid
*name
,
1227 size_t *length
, int exact
, size_t *var_len
,
1228 WriteMethod
**write_method
)
1230 struct ospf_area_range
*range
;
1231 struct in_addr area_id
;
1232 struct in_addr range_net
;
1233 struct in_addr mask
;
1236 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
1240 /* Check OSPF instance. */
1241 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1245 memset(&area_id
, 0, IN_ADDR_SIZE
);
1246 memset(&range_net
, 0, IN_ADDR_SIZE
);
1248 range
= ospfAreaRangeLookup(v
, name
, length
, &area_id
, &range_net
,
1253 /* Convert prefixlen to network mask format. */
1254 masklen2ip(range
->subst_masklen
, &mask
);
1256 /* Return the current value of the variable */
1258 case OSPFAREARANGEAREAID
: /* 1 */
1259 return SNMP_IPADDRESS(area_id
);
1261 case OSPFAREARANGENET
: /* 2 */
1262 return SNMP_IPADDRESS(range_net
);
1264 case OSPFAREARANGEMASK
: /* 3 */
1265 return SNMP_IPADDRESS(mask
);
1267 case OSPFAREARANGESTATUS
: /* 4 */
1268 return SNMP_INTEGER(SNMP_VALID
);
1270 case OSPFAREARANGEEFFECT
: /* 5 */
1271 #define OSPF_advertiseMatching 1
1272 #define OSPF_doNotAdvertiseMatching 2
1273 return SNMP_INTEGER(OSPF_advertiseMatching
);
1282 static struct ospf_nbr_nbma
*ospfHostLookup(struct variable
*v
, oid
*name
,
1284 struct in_addr
*addr
, int exact
)
1287 struct ospf_nbr_nbma
*nbr_nbma
;
1290 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1295 /* INDEX { ospfHostIpAddress, ospfHostTOS } */
1296 if (*length
!= v
->namelen
+ IN_ADDR_SIZE
+ 1)
1299 /* Check ospfHostTOS. */
1300 if (name
[*length
- 1] != 0)
1303 oid2in_addr(name
+ v
->namelen
, IN_ADDR_SIZE
, addr
);
1305 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, *addr
);
1309 len
= *length
- v
->namelen
;
1313 oid2in_addr(name
+ v
->namelen
, len
, addr
);
1316 ospf_nbr_nbma_lookup_next(ospf
, addr
, len
== 0 ? 1 : 0);
1318 if (nbr_nbma
== NULL
)
1321 oid_copy_addr(name
+ v
->namelen
, addr
, IN_ADDR_SIZE
);
1324 name
[v
->namelen
+ IN_ADDR_SIZE
] = 0;
1326 *length
= v
->namelen
+ IN_ADDR_SIZE
+ 1;
1333 static uint8_t *ospfHostEntry(struct variable
*v
, oid
*name
, size_t *length
,
1334 int exact
, size_t *var_len
,
1335 WriteMethod
**write_method
)
1337 struct ospf_nbr_nbma
*nbr_nbma
;
1338 struct ospf_interface
*oi
;
1339 struct in_addr addr
;
1342 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
1346 /* Check OSPF instance. */
1347 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1351 memset(&addr
, 0, sizeof(struct in_addr
));
1353 nbr_nbma
= ospfHostLookup(v
, name
, length
, &addr
, exact
);
1354 if (nbr_nbma
== NULL
)
1359 /* Return the current value of the variable */
1361 case OSPFHOSTIPADDRESS
: /* 1 */
1362 return SNMP_IPADDRESS(nbr_nbma
->addr
);
1364 case OSPFHOSTTOS
: /* 2 */
1365 return SNMP_INTEGER(0);
1367 case OSPFHOSTMETRIC
: /* 3 */
1369 return SNMP_INTEGER(oi
->output_cost
);
1371 return SNMP_INTEGER(1);
1373 case OSPFHOSTSTATUS
: /* 4 */
1374 return SNMP_INTEGER(SNMP_VALID
);
1376 case OSPFHOSTAREAID
: /* 5 */
1378 return SNMP_IPADDRESS(oi
->area
->area_id
);
1380 return SNMP_IPADDRESS(ospf_empty_addr
);
1389 static struct list
*ospf_snmp_iflist
;
1391 struct ospf_snmp_if
{
1392 struct in_addr addr
;
1394 struct interface
*ifp
;
1397 static struct ospf_snmp_if
*ospf_snmp_if_new(void)
1399 return XCALLOC(MTYPE_TMP
, sizeof(struct ospf_snmp_if
));
1402 static void ospf_snmp_if_free(struct ospf_snmp_if
*osif
)
1404 XFREE(MTYPE_TMP
, osif
);
1407 static int ospf_snmp_if_delete(struct interface
*ifp
)
1409 struct listnode
*node
, *nnode
;
1410 struct ospf_snmp_if
*osif
;
1412 for (ALL_LIST_ELEMENTS(ospf_snmp_iflist
, node
, nnode
, osif
)) {
1413 if (osif
->ifp
== ifp
) {
1414 list_delete_node(ospf_snmp_iflist
, node
);
1415 ospf_snmp_if_free(osif
);
1422 static int ospf_snmp_if_update(struct interface
*ifp
)
1424 struct listnode
*node
;
1425 struct listnode
*pn
;
1426 struct connected
*ifc
;
1428 struct ospf_snmp_if
*osif
;
1429 struct in_addr
*addr
;
1432 ospf_snmp_if_delete(ifp
);
1438 /* Lookup first IPv4 address entry. */
1439 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, ifc
)) {
1440 p
= CONNECTED_ID(ifc
);
1442 if (p
->family
== AF_INET
) {
1443 addr
= &p
->u
.prefix4
;
1448 ifindex
= ifp
->ifindex
;
1450 /* Add interface to the list. */
1452 for (ALL_LIST_ELEMENTS_RO(ospf_snmp_iflist
, node
, osif
)) {
1454 /* Usual interfaces --> Sort them based on interface
1456 if (ntohl(osif
->addr
.s_addr
) > ntohl(addr
->s_addr
))
1459 /* Unnumbered interfaces --> Sort them based on
1460 * interface indexes */
1461 if (osif
->addr
.s_addr
!= 0 || osif
->ifindex
> ifindex
)
1467 osif
= ospf_snmp_if_new();
1468 if (addr
) /* Usual interface */
1472 /* This field is used for storing ospfAddressLessIf OID value,
1473 * conform to RFC1850 OSPF-MIB specification, it must be 0 for
1474 * usual interface */
1476 } else /* Unnumbered interface */
1477 osif
->ifindex
= ifindex
;
1480 listnode_add_after(ospf_snmp_iflist
, pn
, osif
);
1484 static int ospf_snmp_is_if_have_addr(struct interface
*ifp
)
1486 struct listnode
*nn
;
1487 struct connected
*ifc
;
1489 /* Is this interface having any connected IPv4 address ? */
1490 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, nn
, ifc
)) {
1491 if (CONNECTED_PREFIX(ifc
)->family
== AF_INET
)
1498 static struct ospf_interface
*ospf_snmp_if_lookup(struct in_addr
*ifaddr
,
1501 struct listnode
*node
;
1502 struct ospf_snmp_if
*osif
;
1503 struct ospf_interface
*oi
= NULL
;
1504 struct ospf
*ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1506 for (ALL_LIST_ELEMENTS_RO(ospf_snmp_iflist
, node
, osif
)) {
1507 if (ifaddr
->s_addr
) {
1508 if (IPV4_ADDR_SAME(&osif
->addr
, ifaddr
))
1509 oi
= ospf_if_lookup_by_local_addr(
1510 ospf
, osif
->ifp
, *ifaddr
);
1512 if (osif
->ifindex
== *ifindex
)
1513 oi
= ospf_if_lookup_by_local_addr(
1514 ospf
, osif
->ifp
, *ifaddr
);
1520 static struct ospf_interface
*ospf_snmp_if_lookup_next(struct in_addr
*ifaddr
,
1523 ifindex_t ifindex_next
)
1525 struct ospf_snmp_if
*osif
;
1526 struct listnode
*nn
;
1527 struct ospf
*ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1528 struct ospf_interface
*oi
= NULL
;
1533 /* No instance is specified --> Return the first OSPF interface */
1535 for (ALL_LIST_ELEMENTS_RO(ospf_snmp_iflist
, nn
, osif
)) {
1536 osif
= listgetdata(nn
);
1537 *ifaddr
= osif
->addr
;
1538 *ifindex
= osif
->ifindex
;
1539 /* Because no instance is specified, we don't care about
1541 * interface (usual or unnumbered), just returning the
1544 oi
= ospf_if_lookup_by_local_addr(ospf
, osif
->ifp
,
1552 /* An instance is specified --> Return the next OSPF interface */
1553 for (ALL_LIST_ELEMENTS_RO(ospf_snmp_iflist
, nn
, osif
)) {
1554 /* Usual interface */
1555 if (ifaddr
->s_addr
) {
1556 /* The interface must have valid AF_INET connected
1558 /* it must have lager IPv4 address value than the lookup
1560 if ((ospf_snmp_is_if_have_addr(osif
->ifp
))
1561 && (ntohl(osif
->addr
.s_addr
)
1562 > ntohl(ifaddr
->s_addr
))) {
1563 *ifaddr
= osif
->addr
;
1564 *ifindex
= osif
->ifindex
;
1566 /* and it must be an OSPF interface */
1567 oi
= ospf_if_lookup_by_local_addr(
1568 ospf
, osif
->ifp
, *ifaddr
);
1573 /* Unnumbered interface */
1575 /* The interface must NOT have valid AF_INET connected
1577 /* it must have lager interface index than the lookup
1579 if ((!ospf_snmp_is_if_have_addr(osif
->ifp
))
1580 && (osif
->ifindex
> *ifindex
)) {
1581 *ifaddr
= osif
->addr
;
1582 *ifindex
= osif
->ifindex
;
1584 /* and it must be an OSPF interface */
1585 oi
= ospf_if_lookup_by_local_addr(ospf
, osif
->ifp
,
1594 static int ospf_snmp_iftype(struct interface
*ifp
)
1596 #define ospf_snmp_iftype_broadcast 1
1597 #define ospf_snmp_iftype_nbma 2
1598 #define ospf_snmp_iftype_pointToPoint 3
1599 #define ospf_snmp_iftype_pointToMultipoint 5
1600 if (if_is_broadcast(ifp
))
1601 return ospf_snmp_iftype_broadcast
;
1602 if (if_is_pointopoint(ifp
))
1603 return ospf_snmp_iftype_pointToPoint
;
1604 return ospf_snmp_iftype_broadcast
;
1607 static struct ospf_interface
*ospfIfLookup(struct variable
*v
, oid
*name
,
1609 struct in_addr
*ifaddr
,
1610 ifindex_t
*ifindex
, int exact
)
1613 int ifaddr_next
= 0;
1614 ifindex_t ifindex_next
= 0;
1615 struct ospf_interface
*oi
;
1619 if (*length
!= v
->namelen
+ IN_ADDR_SIZE
+ 1)
1622 oid2in_addr(name
+ v
->namelen
, IN_ADDR_SIZE
, ifaddr
);
1623 *ifindex
= name
[v
->namelen
+ IN_ADDR_SIZE
];
1625 return ospf_snmp_if_lookup(ifaddr
, ifindex
);
1627 len
= *length
- v
->namelen
;
1628 if (len
>= IN_ADDR_SIZE
)
1633 oid2in_addr(name
+ v
->namelen
, len
, ifaddr
);
1635 len
= *length
- v
->namelen
- IN_ADDR_SIZE
;
1642 *ifindex
= name
[v
->namelen
+ IN_ADDR_SIZE
];
1644 oi
= ospf_snmp_if_lookup_next(ifaddr
, ifindex
, ifaddr_next
,
1647 *length
= v
->namelen
+ IN_ADDR_SIZE
+ 1;
1648 offset
= name
+ v
->namelen
;
1649 oid_copy_addr(offset
, ifaddr
, IN_ADDR_SIZE
);
1650 offset
+= IN_ADDR_SIZE
;
1658 static uint8_t *ospfIfEntry(struct variable
*v
, oid
*name
, size_t *length
,
1659 int exact
, size_t *var_len
,
1660 WriteMethod
**write_method
)
1663 struct in_addr ifaddr
;
1664 struct ospf_interface
*oi
;
1667 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
1672 memset(&ifaddr
, 0, sizeof(struct in_addr
));
1674 /* Check OSPF instance. */
1675 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1679 oi
= ospfIfLookup(v
, name
, length
, &ifaddr
, &ifindex
, exact
);
1683 /* Return the current value of the variable */
1685 case OSPFIFIPADDRESS
: /* 1 */
1686 return SNMP_IPADDRESS(ifaddr
);
1688 case OSPFADDRESSLESSIF
: /* 2 */
1689 return SNMP_INTEGER(ifindex
);
1691 case OSPFIFAREAID
: /* 3 */
1693 return SNMP_IPADDRESS(oi
->area
->area_id
);
1695 return SNMP_IPADDRESS(ospf_empty_addr
);
1697 case OSPFIFTYPE
: /* 4 */
1698 return SNMP_INTEGER(ospf_snmp_iftype(oi
->ifp
));
1700 case OSPFIFADMINSTAT
: /* 5 */
1702 return SNMP_INTEGER(OSPF_STATUS_ENABLED
);
1704 return SNMP_INTEGER(OSPF_STATUS_DISABLED
);
1706 case OSPFIFRTRPRIORITY
: /* 6 */
1707 return SNMP_INTEGER(PRIORITY(oi
));
1709 case OSPFIFTRANSITDELAY
: /* 7 */
1710 return SNMP_INTEGER(OSPF_IF_PARAM(oi
, transmit_delay
));
1712 case OSPFIFRETRANSINTERVAL
: /* 8 */
1713 return SNMP_INTEGER(OSPF_IF_PARAM(oi
, retransmit_interval
));
1715 case OSPFIFHELLOINTERVAL
: /* 9 */
1716 return SNMP_INTEGER(OSPF_IF_PARAM(oi
, v_hello
));
1718 case OSPFIFRTRDEADINTERVAL
: /* 10 */
1719 return SNMP_INTEGER(OSPF_IF_PARAM(oi
, v_wait
));
1721 case OSPFIFPOLLINTERVAL
: /* 11 */
1722 return SNMP_INTEGER(OSPF_POLL_INTERVAL_DEFAULT
);
1724 case OSPFIFSTATE
: /* 12 */
1725 return SNMP_INTEGER(ISM_SNMP(oi
->state
));
1727 case OSPFIFDESIGNATEDROUTER
: /* 13 */
1728 return SNMP_IPADDRESS(DR(oi
));
1730 case OSPFIFBACKUPDESIGNATEDROUTER
: /* 14 */
1731 return SNMP_IPADDRESS(BDR(oi
));
1733 case OSPFIFEVENTS
: /* 15 */
1734 return SNMP_INTEGER(oi
->state_change
);
1736 case OSPFIFAUTHKEY
: /* 16 */
1738 return (uint8_t *)OSPF_IF_PARAM(oi
, auth_simple
);
1740 case OSPFIFSTATUS
: /* 17 */
1741 return SNMP_INTEGER(SNMP_VALID
);
1743 case OSPFIFMULTICASTFORWARDING
: /* 18 */
1744 #define ospf_snmp_multiforward_blocked 1
1745 #define ospf_snmp_multiforward_multicast 2
1746 #define ospf_snmp_multiforward_unicast 3
1747 return SNMP_INTEGER(ospf_snmp_multiforward_blocked
);
1749 case OSPFIFDEMAND
: /* 19 */
1750 return SNMP_INTEGER(SNMP_FALSE
);
1752 case OSPFIFAUTHTYPE
: /* 20 */
1754 return SNMP_INTEGER(oi
->area
->auth_type
);
1756 return SNMP_INTEGER(0);
1765 #define OSPF_SNMP_METRIC_VALUE 1
1767 static struct ospf_interface
*ospfIfMetricLookup(struct variable
*v
, oid
*name
,
1769 struct in_addr
*ifaddr
,
1770 ifindex_t
*ifindex
, int exact
)
1773 int ifaddr_next
= 0;
1774 ifindex_t ifindex_next
= 0;
1775 struct ospf_interface
*oi
;
1780 if (*length
!= v
->namelen
+ IN_ADDR_SIZE
+ 1 + 1)
1783 oid2in_addr(name
+ v
->namelen
, IN_ADDR_SIZE
, ifaddr
);
1784 *ifindex
= name
[v
->namelen
+ IN_ADDR_SIZE
];
1785 metric
= name
[v
->namelen
+ IN_ADDR_SIZE
+ 1];
1787 if (metric
!= OSPF_SNMP_METRIC_VALUE
)
1790 return ospf_snmp_if_lookup(ifaddr
, ifindex
);
1792 len
= *length
- v
->namelen
;
1793 if (len
>= IN_ADDR_SIZE
)
1798 oid2in_addr(name
+ v
->namelen
, len
, ifaddr
);
1800 len
= *length
- v
->namelen
- IN_ADDR_SIZE
;
1807 *ifindex
= name
[v
->namelen
+ IN_ADDR_SIZE
];
1809 oi
= ospf_snmp_if_lookup_next(ifaddr
, ifindex
, ifaddr_next
,
1812 *length
= v
->namelen
+ IN_ADDR_SIZE
+ 1 + 1;
1813 offset
= name
+ v
->namelen
;
1814 oid_copy_addr(offset
, ifaddr
, IN_ADDR_SIZE
);
1815 offset
+= IN_ADDR_SIZE
;
1818 *offset
= OSPF_SNMP_METRIC_VALUE
;
1825 static uint8_t *ospfIfMetricEntry(struct variable
*v
, oid
*name
, size_t *length
,
1826 int exact
, size_t *var_len
,
1827 WriteMethod
**write_method
)
1829 /* Currently we support metric 1 only. */
1831 struct in_addr ifaddr
;
1832 struct ospf_interface
*oi
;
1835 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
1840 memset(&ifaddr
, 0, sizeof(struct in_addr
));
1842 /* Check OSPF instance. */
1843 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1847 oi
= ospfIfMetricLookup(v
, name
, length
, &ifaddr
, &ifindex
, exact
);
1851 /* Return the current value of the variable */
1853 case OSPFIFMETRICIPADDRESS
:
1854 return SNMP_IPADDRESS(ifaddr
);
1856 case OSPFIFMETRICADDRESSLESSIF
:
1857 return SNMP_INTEGER(ifindex
);
1859 case OSPFIFMETRICTOS
:
1860 return SNMP_INTEGER(0);
1862 case OSPFIFMETRICVALUE
:
1863 return SNMP_INTEGER(OSPF_SNMP_METRIC_VALUE
);
1865 case OSPFIFMETRICSTATUS
:
1866 return SNMP_INTEGER(1);
1875 static struct route_table
*ospf_snmp_vl_table
;
1877 static int ospf_snmp_vl_add(struct ospf_vl_data
*vl_data
)
1879 struct prefix_ls lp
;
1880 struct route_node
*rn
;
1882 memset(&lp
, 0, sizeof(struct prefix_ls
));
1885 lp
.id
= vl_data
->vl_area_id
;
1886 lp
.adv_router
= vl_data
->vl_peer
;
1888 rn
= route_node_get(ospf_snmp_vl_table
, (struct prefix
*)&lp
);
1890 route_unlock_node(rn
);
1896 static int ospf_snmp_vl_delete(struct ospf_vl_data
*vl_data
)
1898 struct prefix_ls lp
;
1899 struct route_node
*rn
;
1901 memset(&lp
, 0, sizeof(struct prefix_ls
));
1904 lp
.id
= vl_data
->vl_area_id
;
1905 lp
.adv_router
= vl_data
->vl_peer
;
1907 rn
= route_node_lookup(ospf_snmp_vl_table
, (struct prefix
*)&lp
);
1911 route_unlock_node(rn
);
1912 route_unlock_node(rn
);
1916 static struct ospf_vl_data
*ospf_snmp_vl_lookup(struct in_addr
*area_id
,
1917 struct in_addr
*neighbor
)
1919 struct prefix_ls lp
;
1920 struct route_node
*rn
;
1921 struct ospf_vl_data
*vl_data
;
1923 memset(&lp
, 0, sizeof(struct prefix_ls
));
1927 lp
.adv_router
= *neighbor
;
1929 rn
= route_node_lookup(ospf_snmp_vl_table
, (struct prefix
*)&lp
);
1932 route_unlock_node(rn
);
1938 static struct ospf_vl_data
*ospf_snmp_vl_lookup_next(struct in_addr
*area_id
,
1939 struct in_addr
*neighbor
,
1942 struct prefix_ls lp
;
1943 struct route_node
*rn
;
1944 struct ospf_vl_data
*vl_data
;
1946 memset(&lp
, 0, sizeof(struct prefix_ls
));
1950 lp
.adv_router
= *neighbor
;
1953 rn
= route_top(ospf_snmp_vl_table
);
1955 rn
= route_node_get(ospf_snmp_vl_table
, (struct prefix
*)&lp
);
1956 rn
= route_next(rn
);
1959 for (; rn
; rn
= route_next(rn
))
1963 if (rn
&& rn
->info
) {
1965 *area_id
= vl_data
->vl_area_id
;
1966 *neighbor
= vl_data
->vl_peer
;
1967 route_unlock_node(rn
);
1973 static struct ospf_vl_data
*
1974 ospfVirtIfLookup(struct variable
*v
, oid
*name
, size_t *length
,
1975 struct in_addr
*area_id
, struct in_addr
*neighbor
, int exact
)
1979 struct ospf_vl_data
*vl_data
;
1982 if (*length
!= v
->namelen
+ IN_ADDR_SIZE
+ IN_ADDR_SIZE
)
1985 oid2in_addr(name
+ v
->namelen
, IN_ADDR_SIZE
, area_id
);
1986 oid2in_addr(name
+ v
->namelen
+ IN_ADDR_SIZE
, IN_ADDR_SIZE
,
1989 return ospf_snmp_vl_lookup(area_id
, neighbor
);
1993 len
= *length
- v
->namelen
;
1996 if (len
> IN_ADDR_SIZE
)
1998 oid2in_addr(name
+ v
->namelen
, len
, area_id
);
2000 len
= *length
- v
->namelen
- IN_ADDR_SIZE
;
2001 if (len
> IN_ADDR_SIZE
)
2003 oid2in_addr(name
+ v
->namelen
+ IN_ADDR_SIZE
, len
, neighbor
);
2005 vl_data
= ospf_snmp_vl_lookup_next(area_id
, neighbor
, first
);
2008 *length
= v
->namelen
+ IN_ADDR_SIZE
+ IN_ADDR_SIZE
;
2009 oid_copy_addr(name
+ v
->namelen
, area_id
, IN_ADDR_SIZE
);
2010 oid_copy_addr(name
+ v
->namelen
+ IN_ADDR_SIZE
,
2011 neighbor
, IN_ADDR_SIZE
);
2018 static uint8_t *ospfVirtIfEntry(struct variable
*v
, oid
*name
, size_t *length
,
2019 int exact
, size_t *var_len
,
2020 WriteMethod
**write_method
)
2022 struct ospf_vl_data
*vl_data
;
2023 struct ospf_interface
*oi
;
2024 struct in_addr area_id
;
2025 struct in_addr neighbor
;
2027 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
2031 memset(&area_id
, 0, sizeof(struct in_addr
));
2032 memset(&neighbor
, 0, sizeof(struct in_addr
));
2034 vl_data
= ospfVirtIfLookup(v
, name
, length
, &area_id
, &neighbor
, exact
);
2037 oi
= vl_data
->vl_oi
;
2041 /* Return the current value of the variable */
2043 case OSPFVIRTIFAREAID
:
2044 return SNMP_IPADDRESS(area_id
);
2046 case OSPFVIRTIFNEIGHBOR
:
2047 return SNMP_IPADDRESS(neighbor
);
2049 case OSPFVIRTIFTRANSITDELAY
:
2050 return SNMP_INTEGER(OSPF_IF_PARAM(oi
, transmit_delay
));
2052 case OSPFVIRTIFRETRANSINTERVAL
:
2053 return SNMP_INTEGER(OSPF_IF_PARAM(oi
, retransmit_interval
));
2055 case OSPFVIRTIFHELLOINTERVAL
:
2056 return SNMP_INTEGER(OSPF_IF_PARAM(oi
, v_hello
));
2058 case OSPFVIRTIFRTRDEADINTERVAL
:
2059 return SNMP_INTEGER(OSPF_IF_PARAM(oi
, v_wait
));
2061 case OSPFVIRTIFSTATE
:
2062 return SNMP_INTEGER(oi
->state
);
2064 case OSPFVIRTIFEVENTS
:
2065 return SNMP_INTEGER(oi
->state_change
);
2067 case OSPFVIRTIFAUTHKEY
:
2069 return (uint8_t *)OSPF_IF_PARAM(oi
, auth_simple
);
2071 case OSPFVIRTIFSTATUS
:
2072 return SNMP_INTEGER(SNMP_VALID
);
2074 case OSPFVIRTIFAUTHTYPE
:
2076 return SNMP_INTEGER(oi
->area
->auth_type
);
2078 return SNMP_INTEGER(0);
2087 static struct ospf_neighbor
*ospf_snmp_nbr_lookup(struct ospf
*ospf
,
2088 struct in_addr
*nbr_addr
,
2091 struct listnode
*node
, *nnode
;
2092 struct ospf_interface
*oi
;
2093 struct ospf_neighbor
*nbr
;
2094 struct route_node
*rn
;
2096 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
)) {
2097 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
2098 if ((nbr
= rn
->info
) != NULL
&& nbr
!= oi
->nbr_self
2099 /* If EXACT match is needed, provide ALL entry found
2100 && nbr->state != NSM_Down
2102 && nbr
->src
.s_addr
!= 0) {
2103 if (IPV4_ADDR_SAME(&nbr
->src
, nbr_addr
)) {
2104 route_unlock_node(rn
);
2112 static struct ospf_neighbor
*ospf_snmp_nbr_lookup_next(struct in_addr
*nbr_addr
,
2116 struct listnode
*nn
;
2117 struct ospf_interface
*oi
;
2118 struct ospf_neighbor
*nbr
;
2119 struct route_node
*rn
;
2120 struct ospf_neighbor
*min
= NULL
;
2123 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
2125 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, nn
, oi
)) {
2126 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
2127 if ((nbr
= rn
->info
) != NULL
&& nbr
!= oi
->nbr_self
2128 && nbr
->state
!= NSM_Down
&& nbr
->src
.s_addr
!= 0) {
2132 else if (ntohl(nbr
->src
.s_addr
)
2133 < ntohl(min
->src
.s_addr
))
2135 } else if (ntohl(nbr
->src
.s_addr
)
2136 > ntohl(nbr_addr
->s_addr
)) {
2139 else if (ntohl(nbr
->src
.s_addr
)
2140 < ntohl(min
->src
.s_addr
))
2146 *nbr_addr
= min
->src
;
2153 static struct ospf_neighbor
*ospfNbrLookup(struct variable
*v
, oid
*name
,
2155 struct in_addr
*nbr_addr
,
2156 ifindex_t
*ifindex
, int exact
)
2160 struct ospf_neighbor
*nbr
;
2163 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
2169 if (*length
!= v
->namelen
+ IN_ADDR_SIZE
+ 1)
2172 oid2in_addr(name
+ v
->namelen
, IN_ADDR_SIZE
, nbr_addr
);
2173 *ifindex
= name
[v
->namelen
+ IN_ADDR_SIZE
];
2175 return ospf_snmp_nbr_lookup(ospf
, nbr_addr
, ifindex
);
2178 len
= *length
- v
->namelen
;
2183 if (len
> IN_ADDR_SIZE
)
2186 oid2in_addr(name
+ v
->namelen
, len
, nbr_addr
);
2188 len
= *length
- v
->namelen
- IN_ADDR_SIZE
;
2190 *ifindex
= name
[v
->namelen
+ IN_ADDR_SIZE
];
2192 nbr
= ospf_snmp_nbr_lookup_next(nbr_addr
, ifindex
, first
);
2195 *length
= v
->namelen
+ IN_ADDR_SIZE
+ 1;
2196 oid_copy_addr(name
+ v
->namelen
, nbr_addr
,
2198 name
[v
->namelen
+ IN_ADDR_SIZE
] = *ifindex
;
2205 /* map internal quagga neighbor states to official MIB values:
2207 ospfNbrState OBJECT-TYPE
2219 static int32_t ospf_snmp_neighbor_state(uint8_t nst
)
2237 return 1; /* down */
2241 static uint8_t *ospfNbrEntry(struct variable
*v
, oid
*name
, size_t *length
,
2242 int exact
, size_t *var_len
,
2243 WriteMethod
**write_method
)
2245 struct in_addr nbr_addr
;
2247 struct ospf_neighbor
*nbr
;
2248 struct ospf_interface
*oi
;
2250 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
2254 memset(&nbr_addr
, 0, sizeof(struct in_addr
));
2257 nbr
= ospfNbrLookup(v
, name
, length
, &nbr_addr
, &ifindex
, exact
);
2264 /* Return the current value of the variable */
2267 return SNMP_IPADDRESS(nbr_addr
);
2269 case OSPFNBRADDRESSLESSINDEX
:
2270 return SNMP_INTEGER(ifindex
);
2273 return SNMP_IPADDRESS(nbr
->router_id
);
2275 case OSPFNBROPTIONS
:
2276 return SNMP_INTEGER(oi
->nbr_self
->options
);
2278 case OSPFNBRPRIORITY
:
2279 return SNMP_INTEGER(nbr
->priority
);
2282 return SNMP_INTEGER(ospf_snmp_neighbor_state(nbr
->state
));
2285 return SNMP_INTEGER(nbr
->state_change
);
2287 case OSPFNBRLSRETRANSQLEN
:
2288 return SNMP_INTEGER(ospf_ls_retransmit_count(nbr
));
2290 case OSPFNBMANBRSTATUS
:
2291 return SNMP_INTEGER(SNMP_VALID
);
2293 case OSPFNBMANBRPERMANENCE
:
2294 return SNMP_INTEGER(2);
2296 case OSPFNBRHELLOSUPPRESSED
:
2297 return SNMP_INTEGER(SNMP_FALSE
);
2306 static uint8_t *ospfVirtNbrEntry(struct variable
*v
, oid
*name
, size_t *length
,
2307 int exact
, size_t *var_len
,
2308 WriteMethod
**write_method
)
2310 struct ospf_vl_data
*vl_data
;
2311 struct in_addr area_id
;
2312 struct in_addr neighbor
;
2315 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
2319 memset(&area_id
, 0, sizeof(struct in_addr
));
2320 memset(&neighbor
, 0, sizeof(struct in_addr
));
2322 /* Check OSPF instance. */
2323 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
2327 vl_data
= ospfVirtIfLookup(v
, name
, length
, &area_id
, &neighbor
, exact
);
2331 /* Return the current value of the variable */
2333 case OSPFVIRTNBRAREA
:
2334 return (uint8_t *)NULL
;
2336 case OSPFVIRTNBRRTRID
:
2337 return (uint8_t *)NULL
;
2339 case OSPFVIRTNBRIPADDR
:
2340 return (uint8_t *)NULL
;
2342 case OSPFVIRTNBROPTIONS
:
2343 return (uint8_t *)NULL
;
2345 case OSPFVIRTNBRSTATE
:
2346 return (uint8_t *)NULL
;
2348 case OSPFVIRTNBREVENTS
:
2349 return (uint8_t *)NULL
;
2351 case OSPFVIRTNBRLSRETRANSQLEN
:
2352 return (uint8_t *)NULL
;
2354 case OSPFVIRTNBRHELLOSUPPRESSED
:
2355 return (uint8_t *)NULL
;
2364 static struct ospf_lsa
*ospfExtLsdbLookup(struct variable
*v
, oid
*name
,
2365 size_t *length
, uint8_t *type
,
2366 struct in_addr
*ls_id
,
2367 struct in_addr
*router_id
, int exact
)
2374 struct ospf_lsa
*lsa
;
2377 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
2379 if (*length
!= v
->namelen
+ 1 + IN_ADDR_SIZE
+ IN_ADDR_SIZE
)
2382 offset
= name
+ v
->namelen
;
2384 /* Make it sure given value match to type. */
2388 if (lsa_type
!= *type
)
2392 oid2in_addr(offset
, IN_ADDR_SIZE
, ls_id
);
2393 offset
+= IN_ADDR_SIZE
;
2396 oid2in_addr(offset
, IN_ADDR_SIZE
, router_id
);
2398 return ospf_lsdb_lookup_by_id(ospf
->lsdb
, *type
, *ls_id
,
2401 /* Get variable length. */
2403 offset
= name
+ v
->namelen
;
2404 offsetlen
= *length
- v
->namelen
;
2406 /* LSA type value. */
2411 if (offsetlen
<= 0 || lsa_type
< OSPF_AS_EXTERNAL_LSA
)
2416 if (len
> IN_ADDR_SIZE
)
2419 oid2in_addr(offset
, len
, ls_id
);
2421 offset
+= IN_ADDR_SIZE
;
2422 offsetlen
-= IN_ADDR_SIZE
;
2426 if (len
> IN_ADDR_SIZE
)
2429 oid2in_addr(offset
, len
, router_id
);
2431 lsa
= ospf_lsdb_lookup_by_id_next(ospf
->lsdb
, *type
, *ls_id
,
2435 /* Fill in length. */
2436 *length
= v
->namelen
+ 1 + IN_ADDR_SIZE
+ IN_ADDR_SIZE
;
2438 /* Fill in value. */
2439 offset
= name
+ v
->namelen
;
2441 *offset
= OSPF_AS_EXTERNAL_LSA
;
2443 oid_copy_addr(offset
, &lsa
->data
->id
, IN_ADDR_SIZE
);
2444 offset
+= IN_ADDR_SIZE
;
2445 oid_copy_addr(offset
, &lsa
->data
->adv_router
,
2454 static uint8_t *ospfExtLsdbEntry(struct variable
*v
, oid
*name
, size_t *length
,
2455 int exact
, size_t *var_len
,
2456 WriteMethod
**write_method
)
2458 struct ospf_lsa
*lsa
;
2459 struct lsa_header
*lsah
;
2461 struct in_addr ls_id
;
2462 struct in_addr router_id
;
2465 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
2469 type
= OSPF_AS_EXTERNAL_LSA
;
2470 memset(&ls_id
, 0, sizeof(struct in_addr
));
2471 memset(&router_id
, 0, sizeof(struct in_addr
));
2473 /* Check OSPF instance. */
2474 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
2478 lsa
= ospfExtLsdbLookup(v
, name
, length
, &type
, &ls_id
, &router_id
,
2485 /* Return the current value of the variable */
2487 case OSPFEXTLSDBTYPE
:
2488 return SNMP_INTEGER(OSPF_AS_EXTERNAL_LSA
);
2490 case OSPFEXTLSDBLSID
:
2491 return SNMP_IPADDRESS(lsah
->id
);
2493 case OSPFEXTLSDBROUTERID
:
2494 return SNMP_IPADDRESS(lsah
->adv_router
);
2496 case OSPFEXTLSDBSEQUENCE
:
2497 return SNMP_INTEGER(lsah
->ls_seqnum
);
2499 case OSPFEXTLSDBAGE
:
2500 return SNMP_INTEGER(lsah
->ls_age
);
2502 case OSPFEXTLSDBCHECKSUM
:
2503 return SNMP_INTEGER(lsah
->checksum
);
2505 case OSPFEXTLSDBADVERTISEMENT
:
2506 *var_len
= ntohs(lsah
->length
);
2507 return (uint8_t *)lsah
;
2516 static uint8_t *ospfAreaAggregateEntry(struct variable
*v
, oid
*name
,
2517 size_t *length
, int exact
,
2519 WriteMethod
**write_method
)
2521 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
2525 /* Return the current value of the variable */
2527 case OSPFAREAAGGREGATEAREAID
:
2528 return (uint8_t *)NULL
;
2530 case OSPFAREAAGGREGATELSDBTYPE
:
2531 return (uint8_t *)NULL
;
2533 case OSPFAREAAGGREGATENET
:
2534 return (uint8_t *)NULL
;
2536 case OSPFAREAAGGREGATEMASK
:
2537 return (uint8_t *)NULL
;
2539 case OSPFAREAAGGREGATESTATUS
:
2540 return (uint8_t *)NULL
;
2542 case OSPFAREAAGGREGATEEFFECT
:
2543 return (uint8_t *)NULL
;
2553 #define IFSTATECHANGE 16
2554 #define VIRTIFSTATECHANGE 1
2555 #define NBRSTATECHANGE 2
2556 #define VIRTNBRSTATECHANGE 3
2558 static struct trap_object ospfNbrTrapList
[] = {{-2, {1, OSPFROUTERID
}},
2559 {3, {10, 1, OSPFNBRIPADDR
}},
2560 {3, {10, 1, OSPFNBRRTRID
}},
2561 {3, {10, 1, OSPFNBRSTATE
}}};
2564 static struct trap_object ospfVirtNbrTrapList
[] = {
2566 {3, {11, 1, OSPFVIRTNBRAREA
}},
2567 {3, {11, 1, OSPFVIRTNBRRTRID
}},
2568 {3, {11, 1, OSPFVIRTNBRSTATE
}}};
2570 static struct trap_object ospfIfTrapList
[] = {{-2, {1, OSPFROUTERID
}},
2571 {3, {7, 1, OSPFIFIPADDRESS
}},
2572 {3, {7, 1, OSPFADDRESSLESSIF
}},
2573 {3, {7, 1, OSPFIFSTATE
}}};
2575 static struct trap_object ospfVirtIfTrapList
[] = {
2576 {-2, {1, OSPFROUTERID
}},
2577 {3, {9, 1, OSPFVIRTIFAREAID
}},
2578 {3, {9, 1, OSPFVIRTIFNEIGHBOR
}},
2579 {3, {9, 1, OSPFVIRTIFSTATE
}}};
2581 static void ospfTrapNbrStateChange(struct ospf_neighbor
*on
)
2583 oid index
[sizeof(oid
) * (IN_ADDR_SIZE
+ 1)];
2586 ospf_nbr_state_message(on
, msgbuf
, sizeof(msgbuf
));
2587 if (IS_DEBUG_OSPF_EVENT
)
2588 zlog_info("%s: trap sent: %s now %s", __PRETTY_FUNCTION__
,
2589 inet_ntoa(on
->address
.u
.prefix4
), msgbuf
);
2591 oid_copy_addr(index
, &(on
->address
.u
.prefix4
), IN_ADDR_SIZE
);
2592 index
[IN_ADDR_SIZE
] = 0;
2594 smux_trap(ospf_variables
,
2595 sizeof ospf_variables
/ sizeof(struct variable
),
2596 ospf_trap_oid
, sizeof ospf_trap_oid
/ sizeof(oid
), ospf_oid
,
2597 sizeof ospf_oid
/ sizeof(oid
), index
, IN_ADDR_SIZE
+ 1,
2599 sizeof ospfNbrTrapList
/ sizeof(struct trap_object
),
2603 static void ospfTrapVirtNbrStateChange(struct ospf_neighbor
*on
)
2605 oid index
[sizeof(oid
) * (IN_ADDR_SIZE
+ 1)];
2607 zlog_info("ospfTrapVirtNbrStateChange trap sent");
2609 oid_copy_addr(index
, &(on
->address
.u
.prefix4
), IN_ADDR_SIZE
);
2610 index
[IN_ADDR_SIZE
] = 0;
2612 smux_trap(ospf_variables
,
2613 sizeof ospf_variables
/ sizeof(struct variable
),
2614 ospf_trap_oid
, sizeof ospf_trap_oid
/ sizeof(oid
), ospf_oid
,
2615 sizeof ospf_oid
/ sizeof(oid
), index
, IN_ADDR_SIZE
+ 1,
2616 ospfVirtNbrTrapList
,
2617 sizeof ospfVirtNbrTrapList
/ sizeof(struct trap_object
),
2618 VIRTNBRSTATECHANGE
);
2621 static int ospf_snmp_nsm_change(struct ospf_neighbor
*nbr
, int next_state
,
2624 /* Terminal state or regression */
2625 if ((next_state
== NSM_Full
) || (next_state
== NSM_TwoWay
)
2626 || (next_state
< old_state
)) {
2627 /* ospfVirtNbrStateChange */
2628 if (nbr
->oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
2629 ospfTrapVirtNbrStateChange(nbr
);
2630 /* ospfNbrStateChange trap */
2632 /* To/From FULL, only managed by DR */
2633 if (((next_state
!= NSM_Full
)
2634 && (nbr
->state
!= NSM_Full
))
2635 || (nbr
->oi
->state
== ISM_DR
))
2636 ospfTrapNbrStateChange(nbr
);
2641 static void ospfTrapIfStateChange(struct ospf_interface
*oi
)
2643 oid index
[sizeof(oid
) * (IN_ADDR_SIZE
+ 1)];
2645 if (IS_DEBUG_OSPF_EVENT
)
2646 zlog_info("%s: trap sent: %s now %s", __PRETTY_FUNCTION__
,
2647 inet_ntoa(oi
->address
->u
.prefix4
),
2648 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
));
2650 oid_copy_addr(index
, &(oi
->address
->u
.prefix4
), IN_ADDR_SIZE
);
2651 index
[IN_ADDR_SIZE
] = 0;
2653 smux_trap(ospf_variables
,
2654 sizeof ospf_variables
/ sizeof(struct variable
),
2655 ospf_trap_oid
, sizeof ospf_trap_oid
/ sizeof(oid
), ospf_oid
,
2656 sizeof ospf_oid
/ sizeof(oid
), index
, IN_ADDR_SIZE
+ 1,
2658 sizeof ospfIfTrapList
/ sizeof(struct trap_object
),
2662 static void ospfTrapVirtIfStateChange(struct ospf_interface
*oi
)
2664 oid index
[sizeof(oid
) * (IN_ADDR_SIZE
+ 1)];
2666 zlog_info("ospfTrapVirtIfStateChange trap sent");
2668 oid_copy_addr(index
, &(oi
->address
->u
.prefix4
), IN_ADDR_SIZE
);
2669 index
[IN_ADDR_SIZE
] = 0;
2671 smux_trap(ospf_variables
,
2672 sizeof ospf_variables
/ sizeof(struct variable
),
2673 ospf_trap_oid
, sizeof ospf_trap_oid
/ sizeof(oid
), ospf_oid
,
2674 sizeof ospf_oid
/ sizeof(oid
), index
, IN_ADDR_SIZE
+ 1,
2676 sizeof ospfVirtIfTrapList
/ sizeof(struct trap_object
),
2680 static int ospf_snmp_ism_change(struct ospf_interface
*oi
, int state
,
2683 /* Terminal state or regression */
2684 if ((state
== ISM_DR
) || (state
== ISM_Backup
) || (state
== ISM_DROther
)
2685 || (state
== ISM_PointToPoint
) || (state
< old_state
)) {
2686 /* ospfVirtIfStateChange */
2687 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
2688 ospfTrapVirtIfStateChange(oi
);
2689 /* ospfIfStateChange */
2691 ospfTrapIfStateChange(oi
);
2696 /* Register OSPF2-MIB. */
2697 static int ospf_snmp_init(struct thread_master
*tm
)
2699 ospf_snmp_iflist
= list_new();
2700 ospf_snmp_vl_table
= route_table_init();
2702 REGISTER_MIB("mibII/ospf", ospf_variables
, variable
, ospf_oid
);
2706 static int ospf_snmp_module_init(void)
2708 hook_register(ospf_if_update
, ospf_snmp_if_update
);
2709 hook_register(ospf_if_delete
, ospf_snmp_if_delete
);
2710 hook_register(ospf_vl_add
, ospf_snmp_vl_add
);
2711 hook_register(ospf_vl_delete
, ospf_snmp_vl_delete
);
2712 hook_register(ospf_ism_change
, ospf_snmp_ism_change
);
2713 hook_register(ospf_nsm_change
, ospf_snmp_nsm_change
);
2715 hook_register(frr_late_init
, ospf_snmp_init
);
2719 FRR_MODULE_SETUP(.name
= "ospfd_snmp", .version
= FRR_VERSION
,
2720 .description
= "ospfd AgentX SNMP module",
2721 .init
= ospf_snmp_module_init
, )