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", 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. */
1011 if (len
> (int)IN_ADDR_SIZE
)
1014 oid2in_addr(offset
, len
, ls_id
);
1018 offset
+= IN_ADDR_SIZE
;
1019 offsetlen
-= IN_ADDR_SIZE
;
1026 if (len
> (int)IN_ADDR_SIZE
)
1029 oid2in_addr(offset
, len
, router_id
);
1032 lsa
= lsdb_lookup_next(area
, type
, type_next
, ls_id
,
1033 ls_id_next
, router_id
,
1037 /* Fill in length. */
1038 *length
= v
->namelen
+ OSPF_LSDB_ENTRY_OFFSET
;
1040 /* Fill in value. */
1041 offset
= name
+ v
->namelen
;
1042 oid_copy_addr(offset
, area_id
, IN_ADDR_SIZE
);
1043 offset
+= IN_ADDR_SIZE
;
1044 *offset
= lsa
->data
->type
;
1046 oid_copy_addr(offset
, &lsa
->data
->id
,
1048 offset
+= IN_ADDR_SIZE
;
1049 oid_copy_addr(offset
, &lsa
->data
->adv_router
,
1054 } while ((area
= ospf_area_lookup_next(ospf
, area_id
, 0))
1060 static uint8_t *ospfLsdbEntry(struct variable
*v
, oid
*name
, size_t *length
,
1061 int exact
, size_t *var_len
,
1062 WriteMethod
**write_method
)
1064 struct ospf_lsa
*lsa
;
1065 struct lsa_header
*lsah
;
1066 struct in_addr area_id
;
1068 struct in_addr ls_id
;
1069 struct in_addr router_id
;
1072 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
1076 /* INDEX { ospfLsdbAreaId, ospfLsdbType,
1077 ospfLsdbLsid, ospfLsdbRouterId } */
1079 memset(&area_id
, 0, sizeof(struct in_addr
));
1081 memset(&ls_id
, 0, sizeof(struct in_addr
));
1082 memset(&router_id
, 0, sizeof(struct in_addr
));
1084 /* Check OSPF instance. */
1085 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1089 lsa
= ospfLsdbLookup(v
, name
, length
, &area_id
, &type
, &ls_id
,
1096 /* Return the current value of the variable */
1098 case OSPFLSDBAREAID
: /* 1 */
1099 return SNMP_IPADDRESS(lsa
->area
->area_id
);
1101 case OSPFLSDBTYPE
: /* 2 */
1102 return SNMP_INTEGER(lsah
->type
);
1104 case OSPFLSDBLSID
: /* 3 */
1105 return SNMP_IPADDRESS(lsah
->id
);
1107 case OSPFLSDBROUTERID
: /* 4 */
1108 return SNMP_IPADDRESS(lsah
->adv_router
);
1110 case OSPFLSDBSEQUENCE
: /* 5 */
1111 return SNMP_INTEGER(lsah
->ls_seqnum
);
1113 case OSPFLSDBAGE
: /* 6 */
1114 return SNMP_INTEGER(lsah
->ls_age
);
1116 case OSPFLSDBCHECKSUM
: /* 7 */
1117 return SNMP_INTEGER(lsah
->checksum
);
1119 case OSPFLSDBADVERTISEMENT
: /* 8 */
1120 *var_len
= ntohs(lsah
->length
);
1121 return (uint8_t *)lsah
;
1130 static struct ospf_area_range
*ospfAreaRangeLookup(struct variable
*v
,
1131 oid
*name
, size_t *length
,
1132 struct in_addr
*area_id
,
1133 struct in_addr
*range_net
,
1140 struct ospf_area
*area
;
1141 struct ospf_area_range
*range
;
1142 struct prefix_ipv4 p
;
1144 p
.prefixlen
= IPV4_MAX_BITLEN
;
1146 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1149 /* Area ID + Range Network. */
1150 if (v
->namelen
+ IN_ADDR_SIZE
+ IN_ADDR_SIZE
!= *length
)
1153 /* Set OID offset for Area ID. */
1154 offset
= name
+ v
->namelen
;
1156 /* Lookup area first. */
1157 oid2in_addr(offset
, IN_ADDR_SIZE
, area_id
);
1159 area
= ospf_area_lookup_by_area_id(ospf
, *area_id
);
1163 offset
+= IN_ADDR_SIZE
;
1165 /* Lookup area range. */
1166 oid2in_addr(offset
, IN_ADDR_SIZE
, range_net
);
1167 p
.prefix
= *range_net
;
1169 return ospf_area_range_lookup(area
, &p
);
1171 /* Set OID offset for Area ID. */
1172 offset
= name
+ v
->namelen
;
1173 offsetlen
= *length
- v
->namelen
;
1176 if (len
> (int)IN_ADDR_SIZE
)
1179 oid2in_addr(offset
, len
, area_id
);
1181 /* First we search area. */
1182 if (len
== IN_ADDR_SIZE
)
1183 area
= ospf_area_lookup_by_area_id(ospf
, *area_id
);
1185 area
= ospf_area_lookup_next(ospf
, area_id
,
1192 offset
+= IN_ADDR_SIZE
;
1193 offsetlen
-= IN_ADDR_SIZE
;
1198 if (len
> (int)IN_ADDR_SIZE
)
1201 oid2in_addr(offset
, len
, range_net
);
1203 range
= ospf_area_range_lookup_next(area
, range_net
,
1207 /* Fill in length. */
1208 *length
= v
->namelen
+ IN_ADDR_SIZE
1211 /* Fill in value. */
1212 offset
= name
+ v
->namelen
;
1213 oid_copy_addr(offset
, area_id
, IN_ADDR_SIZE
);
1214 offset
+= IN_ADDR_SIZE
;
1215 oid_copy_addr(offset
, range_net
, IN_ADDR_SIZE
);
1219 } while ((area
= ospf_area_lookup_next(ospf
, area_id
, 0))
1225 static uint8_t *ospfAreaRangeEntry(struct variable
*v
, oid
*name
,
1226 size_t *length
, int exact
, size_t *var_len
,
1227 WriteMethod
**write_method
)
1229 struct ospf_area_range
*range
;
1230 struct in_addr area_id
;
1231 struct in_addr range_net
;
1232 struct in_addr mask
;
1235 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
1239 /* Check OSPF instance. */
1240 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1244 memset(&area_id
, 0, IN_ADDR_SIZE
);
1245 memset(&range_net
, 0, IN_ADDR_SIZE
);
1247 range
= ospfAreaRangeLookup(v
, name
, length
, &area_id
, &range_net
,
1252 /* Convert prefixlen to network mask format. */
1253 masklen2ip(range
->subst_masklen
, &mask
);
1255 /* Return the current value of the variable */
1257 case OSPFAREARANGEAREAID
: /* 1 */
1258 return SNMP_IPADDRESS(area_id
);
1260 case OSPFAREARANGENET
: /* 2 */
1261 return SNMP_IPADDRESS(range_net
);
1263 case OSPFAREARANGEMASK
: /* 3 */
1264 return SNMP_IPADDRESS(mask
);
1266 case OSPFAREARANGESTATUS
: /* 4 */
1267 return SNMP_INTEGER(SNMP_VALID
);
1269 case OSPFAREARANGEEFFECT
: /* 5 */
1270 #define OSPF_advertiseMatching 1
1271 #define OSPF_doNotAdvertiseMatching 2
1272 return SNMP_INTEGER(OSPF_advertiseMatching
);
1281 static struct ospf_nbr_nbma
*ospfHostLookup(struct variable
*v
, oid
*name
,
1283 struct in_addr
*addr
, int exact
)
1286 struct ospf_nbr_nbma
*nbr_nbma
;
1289 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1294 /* INDEX { ospfHostIpAddress, ospfHostTOS } */
1295 if (*length
!= v
->namelen
+ IN_ADDR_SIZE
+ 1)
1298 /* Check ospfHostTOS. */
1299 if (name
[*length
- 1] != 0)
1302 oid2in_addr(name
+ v
->namelen
, IN_ADDR_SIZE
, addr
);
1304 nbr_nbma
= ospf_nbr_nbma_lookup(ospf
, *addr
);
1308 len
= *length
- v
->namelen
;
1312 oid2in_addr(name
+ v
->namelen
, len
, addr
);
1315 ospf_nbr_nbma_lookup_next(ospf
, addr
, len
== 0 ? 1 : 0);
1317 if (nbr_nbma
== NULL
)
1320 oid_copy_addr(name
+ v
->namelen
, addr
, IN_ADDR_SIZE
);
1323 name
[v
->namelen
+ IN_ADDR_SIZE
] = 0;
1325 *length
= v
->namelen
+ IN_ADDR_SIZE
+ 1;
1332 static uint8_t *ospfHostEntry(struct variable
*v
, oid
*name
, size_t *length
,
1333 int exact
, size_t *var_len
,
1334 WriteMethod
**write_method
)
1336 struct ospf_nbr_nbma
*nbr_nbma
;
1337 struct ospf_interface
*oi
;
1338 struct in_addr addr
;
1341 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
1345 /* Check OSPF instance. */
1346 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1350 memset(&addr
, 0, sizeof(struct in_addr
));
1352 nbr_nbma
= ospfHostLookup(v
, name
, length
, &addr
, exact
);
1353 if (nbr_nbma
== NULL
)
1358 /* Return the current value of the variable */
1360 case OSPFHOSTIPADDRESS
: /* 1 */
1361 return SNMP_IPADDRESS(nbr_nbma
->addr
);
1363 case OSPFHOSTTOS
: /* 2 */
1364 return SNMP_INTEGER(0);
1366 case OSPFHOSTMETRIC
: /* 3 */
1368 return SNMP_INTEGER(oi
->output_cost
);
1370 return SNMP_INTEGER(1);
1372 case OSPFHOSTSTATUS
: /* 4 */
1373 return SNMP_INTEGER(SNMP_VALID
);
1375 case OSPFHOSTAREAID
: /* 5 */
1377 return SNMP_IPADDRESS(oi
->area
->area_id
);
1379 return SNMP_IPADDRESS(ospf_empty_addr
);
1388 static struct list
*ospf_snmp_iflist
;
1390 struct ospf_snmp_if
{
1391 struct in_addr addr
;
1393 struct interface
*ifp
;
1396 static struct ospf_snmp_if
*ospf_snmp_if_new(void)
1398 return XCALLOC(MTYPE_TMP
, sizeof(struct ospf_snmp_if
));
1401 static void ospf_snmp_if_free(struct ospf_snmp_if
*osif
)
1403 XFREE(MTYPE_TMP
, osif
);
1406 static int ospf_snmp_if_delete(struct interface
*ifp
)
1408 struct listnode
*node
, *nnode
;
1409 struct ospf_snmp_if
*osif
;
1411 for (ALL_LIST_ELEMENTS(ospf_snmp_iflist
, node
, nnode
, osif
)) {
1412 if (osif
->ifp
== ifp
) {
1413 list_delete_node(ospf_snmp_iflist
, node
);
1414 ospf_snmp_if_free(osif
);
1421 static int ospf_snmp_if_update(struct interface
*ifp
)
1423 struct listnode
*node
;
1424 struct listnode
*pn
;
1425 struct connected
*ifc
;
1427 struct ospf_snmp_if
*osif
;
1428 struct in_addr
*addr
;
1431 ospf_snmp_if_delete(ifp
);
1437 /* Lookup first IPv4 address entry. */
1438 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, node
, ifc
)) {
1439 p
= CONNECTED_ID(ifc
);
1441 if (p
->family
== AF_INET
) {
1442 addr
= &p
->u
.prefix4
;
1447 ifindex
= ifp
->ifindex
;
1449 /* Add interface to the list. */
1451 for (ALL_LIST_ELEMENTS_RO(ospf_snmp_iflist
, node
, osif
)) {
1453 /* Usual interfaces --> Sort them based on interface
1455 if (ntohl(osif
->addr
.s_addr
) > ntohl(addr
->s_addr
))
1458 /* Unnumbered interfaces --> Sort them based on
1459 * interface indexes */
1460 if (osif
->addr
.s_addr
!= 0 || osif
->ifindex
> ifindex
)
1466 osif
= ospf_snmp_if_new();
1467 if (addr
) /* Usual interface */
1471 /* This field is used for storing ospfAddressLessIf OID value,
1472 * conform to RFC1850 OSPF-MIB specification, it must be 0 for
1473 * usual interface */
1475 } else /* Unnumbered interface */
1476 osif
->ifindex
= ifindex
;
1479 listnode_add_after(ospf_snmp_iflist
, pn
, osif
);
1483 static int ospf_snmp_is_if_have_addr(struct interface
*ifp
)
1485 struct listnode
*nn
;
1486 struct connected
*ifc
;
1488 /* Is this interface having any connected IPv4 address ? */
1489 for (ALL_LIST_ELEMENTS_RO(ifp
->connected
, nn
, ifc
)) {
1490 if (CONNECTED_PREFIX(ifc
)->family
== AF_INET
)
1497 static struct ospf_interface
*ospf_snmp_if_lookup(struct in_addr
*ifaddr
,
1500 struct listnode
*node
;
1501 struct ospf_snmp_if
*osif
;
1502 struct ospf_interface
*oi
= NULL
;
1503 struct ospf
*ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1505 for (ALL_LIST_ELEMENTS_RO(ospf_snmp_iflist
, node
, osif
)) {
1506 if (ifaddr
->s_addr
) {
1507 if (IPV4_ADDR_SAME(&osif
->addr
, ifaddr
))
1508 oi
= ospf_if_lookup_by_local_addr(
1509 ospf
, osif
->ifp
, *ifaddr
);
1511 if (osif
->ifindex
== *ifindex
)
1512 oi
= ospf_if_lookup_by_local_addr(
1513 ospf
, osif
->ifp
, *ifaddr
);
1519 static struct ospf_interface
*ospf_snmp_if_lookup_next(struct in_addr
*ifaddr
,
1522 ifindex_t ifindex_next
)
1524 struct ospf_snmp_if
*osif
;
1525 struct listnode
*nn
;
1526 struct ospf
*ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1527 struct ospf_interface
*oi
= NULL
;
1532 /* No instance is specified --> Return the first OSPF interface */
1534 for (ALL_LIST_ELEMENTS_RO(ospf_snmp_iflist
, nn
, osif
)) {
1535 osif
= listgetdata(nn
);
1536 *ifaddr
= osif
->addr
;
1537 *ifindex
= osif
->ifindex
;
1538 /* Because no instance is specified, we don't care about
1540 * interface (usual or unnumbered), just returning the
1543 oi
= ospf_if_lookup_by_local_addr(ospf
, osif
->ifp
,
1551 /* An instance is specified --> Return the next OSPF interface */
1552 for (ALL_LIST_ELEMENTS_RO(ospf_snmp_iflist
, nn
, osif
)) {
1553 /* Usual interface */
1554 if (ifaddr
->s_addr
) {
1555 /* The interface must have valid AF_INET connected
1557 /* it must have lager IPv4 address value than the lookup
1559 if ((ospf_snmp_is_if_have_addr(osif
->ifp
))
1560 && (ntohl(osif
->addr
.s_addr
)
1561 > ntohl(ifaddr
->s_addr
))) {
1562 *ifaddr
= osif
->addr
;
1563 *ifindex
= osif
->ifindex
;
1565 /* and it must be an OSPF interface */
1566 oi
= ospf_if_lookup_by_local_addr(
1567 ospf
, osif
->ifp
, *ifaddr
);
1572 /* Unnumbered interface */
1574 /* The interface must NOT have valid AF_INET connected
1576 /* it must have lager interface index than the lookup
1578 if ((!ospf_snmp_is_if_have_addr(osif
->ifp
))
1579 && (osif
->ifindex
> *ifindex
)) {
1580 *ifaddr
= osif
->addr
;
1581 *ifindex
= osif
->ifindex
;
1583 /* and it must be an OSPF interface */
1584 oi
= ospf_if_lookup_by_local_addr(ospf
, osif
->ifp
,
1593 static int ospf_snmp_iftype(struct interface
*ifp
)
1595 #define ospf_snmp_iftype_broadcast 1
1596 #define ospf_snmp_iftype_nbma 2
1597 #define ospf_snmp_iftype_pointToPoint 3
1598 #define ospf_snmp_iftype_pointToMultipoint 5
1599 if (if_is_broadcast(ifp
))
1600 return ospf_snmp_iftype_broadcast
;
1601 if (if_is_pointopoint(ifp
))
1602 return ospf_snmp_iftype_pointToPoint
;
1603 return ospf_snmp_iftype_broadcast
;
1606 static struct ospf_interface
*ospfIfLookup(struct variable
*v
, oid
*name
,
1608 struct in_addr
*ifaddr
,
1609 ifindex_t
*ifindex
, int exact
)
1612 int ifaddr_next
= 0;
1613 ifindex_t ifindex_next
= 0;
1614 struct ospf_interface
*oi
;
1618 if (*length
!= v
->namelen
+ IN_ADDR_SIZE
+ 1)
1621 oid2in_addr(name
+ v
->namelen
, IN_ADDR_SIZE
, ifaddr
);
1622 *ifindex
= name
[v
->namelen
+ IN_ADDR_SIZE
];
1624 return ospf_snmp_if_lookup(ifaddr
, ifindex
);
1626 len
= *length
- v
->namelen
;
1627 if (len
>= IN_ADDR_SIZE
)
1632 oid2in_addr(name
+ v
->namelen
, len
, ifaddr
);
1634 len
= *length
- v
->namelen
- IN_ADDR_SIZE
;
1641 *ifindex
= name
[v
->namelen
+ IN_ADDR_SIZE
];
1643 oi
= ospf_snmp_if_lookup_next(ifaddr
, ifindex
, ifaddr_next
,
1646 *length
= v
->namelen
+ IN_ADDR_SIZE
+ 1;
1647 offset
= name
+ v
->namelen
;
1648 oid_copy_addr(offset
, ifaddr
, IN_ADDR_SIZE
);
1649 offset
+= IN_ADDR_SIZE
;
1657 static uint8_t *ospfIfEntry(struct variable
*v
, oid
*name
, size_t *length
,
1658 int exact
, size_t *var_len
,
1659 WriteMethod
**write_method
)
1662 struct in_addr ifaddr
;
1663 struct ospf_interface
*oi
;
1666 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
1671 memset(&ifaddr
, 0, sizeof(struct in_addr
));
1673 /* Check OSPF instance. */
1674 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1678 oi
= ospfIfLookup(v
, name
, length
, &ifaddr
, &ifindex
, exact
);
1682 /* Return the current value of the variable */
1684 case OSPFIFIPADDRESS
: /* 1 */
1685 return SNMP_IPADDRESS(ifaddr
);
1687 case OSPFADDRESSLESSIF
: /* 2 */
1688 return SNMP_INTEGER(ifindex
);
1690 case OSPFIFAREAID
: /* 3 */
1692 return SNMP_IPADDRESS(oi
->area
->area_id
);
1694 return SNMP_IPADDRESS(ospf_empty_addr
);
1696 case OSPFIFTYPE
: /* 4 */
1697 return SNMP_INTEGER(ospf_snmp_iftype(oi
->ifp
));
1699 case OSPFIFADMINSTAT
: /* 5 */
1701 return SNMP_INTEGER(OSPF_STATUS_ENABLED
);
1703 return SNMP_INTEGER(OSPF_STATUS_DISABLED
);
1705 case OSPFIFRTRPRIORITY
: /* 6 */
1706 return SNMP_INTEGER(PRIORITY(oi
));
1708 case OSPFIFTRANSITDELAY
: /* 7 */
1709 return SNMP_INTEGER(OSPF_IF_PARAM(oi
, transmit_delay
));
1711 case OSPFIFRETRANSINTERVAL
: /* 8 */
1712 return SNMP_INTEGER(OSPF_IF_PARAM(oi
, retransmit_interval
));
1714 case OSPFIFHELLOINTERVAL
: /* 9 */
1715 return SNMP_INTEGER(OSPF_IF_PARAM(oi
, v_hello
));
1717 case OSPFIFRTRDEADINTERVAL
: /* 10 */
1718 return SNMP_INTEGER(OSPF_IF_PARAM(oi
, v_wait
));
1720 case OSPFIFPOLLINTERVAL
: /* 11 */
1721 return SNMP_INTEGER(OSPF_POLL_INTERVAL_DEFAULT
);
1723 case OSPFIFSTATE
: /* 12 */
1724 return SNMP_INTEGER(ISM_SNMP(oi
->state
));
1726 case OSPFIFDESIGNATEDROUTER
: /* 13 */
1727 return SNMP_IPADDRESS(DR(oi
));
1729 case OSPFIFBACKUPDESIGNATEDROUTER
: /* 14 */
1730 return SNMP_IPADDRESS(BDR(oi
));
1732 case OSPFIFEVENTS
: /* 15 */
1733 return SNMP_INTEGER(oi
->state_change
);
1735 case OSPFIFAUTHKEY
: /* 16 */
1737 return (uint8_t *)OSPF_IF_PARAM(oi
, auth_simple
);
1739 case OSPFIFSTATUS
: /* 17 */
1740 return SNMP_INTEGER(SNMP_VALID
);
1742 case OSPFIFMULTICASTFORWARDING
: /* 18 */
1743 #define ospf_snmp_multiforward_blocked 1
1744 #define ospf_snmp_multiforward_multicast 2
1745 #define ospf_snmp_multiforward_unicast 3
1746 return SNMP_INTEGER(ospf_snmp_multiforward_blocked
);
1748 case OSPFIFDEMAND
: /* 19 */
1749 return SNMP_INTEGER(SNMP_FALSE
);
1751 case OSPFIFAUTHTYPE
: /* 20 */
1753 return SNMP_INTEGER(oi
->area
->auth_type
);
1755 return SNMP_INTEGER(0);
1764 #define OSPF_SNMP_METRIC_VALUE 1
1766 static struct ospf_interface
*ospfIfMetricLookup(struct variable
*v
, oid
*name
,
1768 struct in_addr
*ifaddr
,
1769 ifindex_t
*ifindex
, int exact
)
1772 int ifaddr_next
= 0;
1773 ifindex_t ifindex_next
= 0;
1774 struct ospf_interface
*oi
;
1779 if (*length
!= v
->namelen
+ IN_ADDR_SIZE
+ 1 + 1)
1782 oid2in_addr(name
+ v
->namelen
, IN_ADDR_SIZE
, ifaddr
);
1783 *ifindex
= name
[v
->namelen
+ IN_ADDR_SIZE
];
1784 metric
= name
[v
->namelen
+ IN_ADDR_SIZE
+ 1];
1786 if (metric
!= OSPF_SNMP_METRIC_VALUE
)
1789 return ospf_snmp_if_lookup(ifaddr
, ifindex
);
1791 len
= *length
- v
->namelen
;
1792 if (len
>= IN_ADDR_SIZE
)
1797 oid2in_addr(name
+ v
->namelen
, len
, ifaddr
);
1799 len
= *length
- v
->namelen
- IN_ADDR_SIZE
;
1806 *ifindex
= name
[v
->namelen
+ IN_ADDR_SIZE
];
1808 oi
= ospf_snmp_if_lookup_next(ifaddr
, ifindex
, ifaddr_next
,
1811 *length
= v
->namelen
+ IN_ADDR_SIZE
+ 1 + 1;
1812 offset
= name
+ v
->namelen
;
1813 oid_copy_addr(offset
, ifaddr
, IN_ADDR_SIZE
);
1814 offset
+= IN_ADDR_SIZE
;
1817 *offset
= OSPF_SNMP_METRIC_VALUE
;
1824 static uint8_t *ospfIfMetricEntry(struct variable
*v
, oid
*name
, size_t *length
,
1825 int exact
, size_t *var_len
,
1826 WriteMethod
**write_method
)
1828 /* Currently we support metric 1 only. */
1830 struct in_addr ifaddr
;
1831 struct ospf_interface
*oi
;
1834 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
1839 memset(&ifaddr
, 0, sizeof(struct in_addr
));
1841 /* Check OSPF instance. */
1842 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
1846 oi
= ospfIfMetricLookup(v
, name
, length
, &ifaddr
, &ifindex
, exact
);
1850 /* Return the current value of the variable */
1852 case OSPFIFMETRICIPADDRESS
:
1853 return SNMP_IPADDRESS(ifaddr
);
1855 case OSPFIFMETRICADDRESSLESSIF
:
1856 return SNMP_INTEGER(ifindex
);
1858 case OSPFIFMETRICTOS
:
1859 return SNMP_INTEGER(0);
1861 case OSPFIFMETRICVALUE
:
1862 return SNMP_INTEGER(OSPF_SNMP_METRIC_VALUE
);
1864 case OSPFIFMETRICSTATUS
:
1865 return SNMP_INTEGER(1);
1874 static struct route_table
*ospf_snmp_vl_table
;
1876 static int ospf_snmp_vl_add(struct ospf_vl_data
*vl_data
)
1878 struct prefix_ls lp
;
1879 struct route_node
*rn
;
1881 memset(&lp
, 0, sizeof(struct prefix_ls
));
1884 lp
.id
= vl_data
->vl_area_id
;
1885 lp
.adv_router
= vl_data
->vl_peer
;
1887 rn
= route_node_get(ospf_snmp_vl_table
, (struct prefix
*)&lp
);
1889 route_unlock_node(rn
);
1895 static int ospf_snmp_vl_delete(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_lookup(ospf_snmp_vl_table
, (struct prefix
*)&lp
);
1910 route_unlock_node(rn
);
1911 route_unlock_node(rn
);
1915 static struct ospf_vl_data
*ospf_snmp_vl_lookup(struct in_addr
*area_id
,
1916 struct in_addr
*neighbor
)
1918 struct prefix_ls lp
;
1919 struct route_node
*rn
;
1920 struct ospf_vl_data
*vl_data
;
1922 memset(&lp
, 0, sizeof(struct prefix_ls
));
1926 lp
.adv_router
= *neighbor
;
1928 rn
= route_node_lookup(ospf_snmp_vl_table
, (struct prefix
*)&lp
);
1931 route_unlock_node(rn
);
1937 static struct ospf_vl_data
*ospf_snmp_vl_lookup_next(struct in_addr
*area_id
,
1938 struct in_addr
*neighbor
,
1941 struct prefix_ls lp
;
1942 struct route_node
*rn
;
1943 struct ospf_vl_data
*vl_data
;
1945 memset(&lp
, 0, sizeof(struct prefix_ls
));
1949 lp
.adv_router
= *neighbor
;
1952 rn
= route_top(ospf_snmp_vl_table
);
1954 rn
= route_node_get(ospf_snmp_vl_table
, (struct prefix
*)&lp
);
1955 rn
= route_next(rn
);
1958 for (; rn
; rn
= route_next(rn
))
1962 if (rn
&& rn
->info
) {
1964 *area_id
= vl_data
->vl_area_id
;
1965 *neighbor
= vl_data
->vl_peer
;
1966 route_unlock_node(rn
);
1972 static struct ospf_vl_data
*
1973 ospfVirtIfLookup(struct variable
*v
, oid
*name
, size_t *length
,
1974 struct in_addr
*area_id
, struct in_addr
*neighbor
, int exact
)
1978 struct ospf_vl_data
*vl_data
;
1981 if (*length
!= v
->namelen
+ IN_ADDR_SIZE
+ IN_ADDR_SIZE
)
1984 oid2in_addr(name
+ v
->namelen
, IN_ADDR_SIZE
, area_id
);
1985 oid2in_addr(name
+ v
->namelen
+ IN_ADDR_SIZE
, IN_ADDR_SIZE
,
1988 return ospf_snmp_vl_lookup(area_id
, neighbor
);
1992 len
= *length
- v
->namelen
;
1995 if (len
> IN_ADDR_SIZE
)
1997 oid2in_addr(name
+ v
->namelen
, len
, area_id
);
1999 len
= *length
- v
->namelen
- IN_ADDR_SIZE
;
2000 if (len
> IN_ADDR_SIZE
)
2002 oid2in_addr(name
+ v
->namelen
+ IN_ADDR_SIZE
, len
, neighbor
);
2004 vl_data
= ospf_snmp_vl_lookup_next(area_id
, neighbor
, first
);
2007 *length
= v
->namelen
+ IN_ADDR_SIZE
+ IN_ADDR_SIZE
;
2008 oid_copy_addr(name
+ v
->namelen
, area_id
, IN_ADDR_SIZE
);
2009 oid_copy_addr(name
+ v
->namelen
+ IN_ADDR_SIZE
,
2010 neighbor
, IN_ADDR_SIZE
);
2017 static uint8_t *ospfVirtIfEntry(struct variable
*v
, oid
*name
, size_t *length
,
2018 int exact
, size_t *var_len
,
2019 WriteMethod
**write_method
)
2021 struct ospf_vl_data
*vl_data
;
2022 struct ospf_interface
*oi
;
2023 struct in_addr area_id
;
2024 struct in_addr neighbor
;
2026 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
2030 memset(&area_id
, 0, sizeof(struct in_addr
));
2031 memset(&neighbor
, 0, sizeof(struct in_addr
));
2033 vl_data
= ospfVirtIfLookup(v
, name
, length
, &area_id
, &neighbor
, exact
);
2036 oi
= vl_data
->vl_oi
;
2040 /* Return the current value of the variable */
2042 case OSPFVIRTIFAREAID
:
2043 return SNMP_IPADDRESS(area_id
);
2045 case OSPFVIRTIFNEIGHBOR
:
2046 return SNMP_IPADDRESS(neighbor
);
2048 case OSPFVIRTIFTRANSITDELAY
:
2049 return SNMP_INTEGER(OSPF_IF_PARAM(oi
, transmit_delay
));
2051 case OSPFVIRTIFRETRANSINTERVAL
:
2052 return SNMP_INTEGER(OSPF_IF_PARAM(oi
, retransmit_interval
));
2054 case OSPFVIRTIFHELLOINTERVAL
:
2055 return SNMP_INTEGER(OSPF_IF_PARAM(oi
, v_hello
));
2057 case OSPFVIRTIFRTRDEADINTERVAL
:
2058 return SNMP_INTEGER(OSPF_IF_PARAM(oi
, v_wait
));
2060 case OSPFVIRTIFSTATE
:
2061 return SNMP_INTEGER(oi
->state
);
2063 case OSPFVIRTIFEVENTS
:
2064 return SNMP_INTEGER(oi
->state_change
);
2066 case OSPFVIRTIFAUTHKEY
:
2068 return (uint8_t *)OSPF_IF_PARAM(oi
, auth_simple
);
2070 case OSPFVIRTIFSTATUS
:
2071 return SNMP_INTEGER(SNMP_VALID
);
2073 case OSPFVIRTIFAUTHTYPE
:
2075 return SNMP_INTEGER(oi
->area
->auth_type
);
2077 return SNMP_INTEGER(0);
2086 static struct ospf_neighbor
*ospf_snmp_nbr_lookup(struct ospf
*ospf
,
2087 struct in_addr
*nbr_addr
,
2090 struct listnode
*node
, *nnode
;
2091 struct ospf_interface
*oi
;
2092 struct ospf_neighbor
*nbr
;
2093 struct route_node
*rn
;
2095 for (ALL_LIST_ELEMENTS(ospf
->oiflist
, node
, nnode
, oi
)) {
2096 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
2097 if ((nbr
= rn
->info
) != NULL
&& nbr
!= oi
->nbr_self
2098 /* If EXACT match is needed, provide ALL entry found
2099 && nbr->state != NSM_Down
2101 && nbr
->src
.s_addr
!= 0) {
2102 if (IPV4_ADDR_SAME(&nbr
->src
, nbr_addr
)) {
2103 route_unlock_node(rn
);
2111 static struct ospf_neighbor
*ospf_snmp_nbr_lookup_next(struct in_addr
*nbr_addr
,
2115 struct listnode
*nn
;
2116 struct ospf_interface
*oi
;
2117 struct ospf_neighbor
*nbr
;
2118 struct route_node
*rn
;
2119 struct ospf_neighbor
*min
= NULL
;
2122 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
2124 for (ALL_LIST_ELEMENTS_RO(ospf
->oiflist
, nn
, oi
)) {
2125 for (rn
= route_top(oi
->nbrs
); rn
; rn
= route_next(rn
))
2126 if ((nbr
= rn
->info
) != NULL
&& nbr
!= oi
->nbr_self
2127 && nbr
->state
!= NSM_Down
&& nbr
->src
.s_addr
!= 0) {
2131 else if (ntohl(nbr
->src
.s_addr
)
2132 < ntohl(min
->src
.s_addr
))
2134 } else if (ntohl(nbr
->src
.s_addr
)
2135 > ntohl(nbr_addr
->s_addr
)) {
2138 else if (ntohl(nbr
->src
.s_addr
)
2139 < ntohl(min
->src
.s_addr
))
2145 *nbr_addr
= min
->src
;
2152 static struct ospf_neighbor
*ospfNbrLookup(struct variable
*v
, oid
*name
,
2154 struct in_addr
*nbr_addr
,
2155 ifindex_t
*ifindex
, int exact
)
2159 struct ospf_neighbor
*nbr
;
2162 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
2168 if (*length
!= v
->namelen
+ IN_ADDR_SIZE
+ 1)
2171 oid2in_addr(name
+ v
->namelen
, IN_ADDR_SIZE
, nbr_addr
);
2172 *ifindex
= name
[v
->namelen
+ IN_ADDR_SIZE
];
2174 return ospf_snmp_nbr_lookup(ospf
, nbr_addr
, ifindex
);
2177 len
= *length
- v
->namelen
;
2182 if (len
> IN_ADDR_SIZE
)
2185 oid2in_addr(name
+ v
->namelen
, len
, nbr_addr
);
2187 len
= *length
- v
->namelen
- IN_ADDR_SIZE
;
2189 *ifindex
= name
[v
->namelen
+ IN_ADDR_SIZE
];
2191 nbr
= ospf_snmp_nbr_lookup_next(nbr_addr
, ifindex
, first
);
2194 *length
= v
->namelen
+ IN_ADDR_SIZE
+ 1;
2195 oid_copy_addr(name
+ v
->namelen
, nbr_addr
,
2197 name
[v
->namelen
+ IN_ADDR_SIZE
] = *ifindex
;
2204 /* map internal quagga neighbor states to official MIB values:
2206 ospfNbrState OBJECT-TYPE
2218 static int32_t ospf_snmp_neighbor_state(uint8_t nst
)
2236 return 1; /* down */
2240 static uint8_t *ospfNbrEntry(struct variable
*v
, oid
*name
, size_t *length
,
2241 int exact
, size_t *var_len
,
2242 WriteMethod
**write_method
)
2244 struct in_addr nbr_addr
;
2246 struct ospf_neighbor
*nbr
;
2247 struct ospf_interface
*oi
;
2249 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
2253 memset(&nbr_addr
, 0, sizeof(struct in_addr
));
2256 nbr
= ospfNbrLookup(v
, name
, length
, &nbr_addr
, &ifindex
, exact
);
2263 /* Return the current value of the variable */
2266 return SNMP_IPADDRESS(nbr_addr
);
2268 case OSPFNBRADDRESSLESSINDEX
:
2269 return SNMP_INTEGER(ifindex
);
2272 return SNMP_IPADDRESS(nbr
->router_id
);
2274 case OSPFNBROPTIONS
:
2275 return SNMP_INTEGER(oi
->nbr_self
->options
);
2277 case OSPFNBRPRIORITY
:
2278 return SNMP_INTEGER(nbr
->priority
);
2281 return SNMP_INTEGER(ospf_snmp_neighbor_state(nbr
->state
));
2284 return SNMP_INTEGER(nbr
->state_change
);
2286 case OSPFNBRLSRETRANSQLEN
:
2287 return SNMP_INTEGER(ospf_ls_retransmit_count(nbr
));
2289 case OSPFNBMANBRSTATUS
:
2290 return SNMP_INTEGER(SNMP_VALID
);
2292 case OSPFNBMANBRPERMANENCE
:
2293 return SNMP_INTEGER(2);
2295 case OSPFNBRHELLOSUPPRESSED
:
2296 return SNMP_INTEGER(SNMP_FALSE
);
2305 static uint8_t *ospfVirtNbrEntry(struct variable
*v
, oid
*name
, size_t *length
,
2306 int exact
, size_t *var_len
,
2307 WriteMethod
**write_method
)
2309 struct ospf_vl_data
*vl_data
;
2310 struct in_addr area_id
;
2311 struct in_addr neighbor
;
2314 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
2318 memset(&area_id
, 0, sizeof(struct in_addr
));
2319 memset(&neighbor
, 0, sizeof(struct in_addr
));
2321 /* Check OSPF instance. */
2322 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
2326 vl_data
= ospfVirtIfLookup(v
, name
, length
, &area_id
, &neighbor
, exact
);
2330 /* Return the current value of the variable */
2332 case OSPFVIRTNBRAREA
:
2333 return (uint8_t *)NULL
;
2335 case OSPFVIRTNBRRTRID
:
2336 return (uint8_t *)NULL
;
2338 case OSPFVIRTNBRIPADDR
:
2339 return (uint8_t *)NULL
;
2341 case OSPFVIRTNBROPTIONS
:
2342 return (uint8_t *)NULL
;
2344 case OSPFVIRTNBRSTATE
:
2345 return (uint8_t *)NULL
;
2347 case OSPFVIRTNBREVENTS
:
2348 return (uint8_t *)NULL
;
2350 case OSPFVIRTNBRLSRETRANSQLEN
:
2351 return (uint8_t *)NULL
;
2353 case OSPFVIRTNBRHELLOSUPPRESSED
:
2354 return (uint8_t *)NULL
;
2363 static struct ospf_lsa
*ospfExtLsdbLookup(struct variable
*v
, oid
*name
,
2364 size_t *length
, uint8_t *type
,
2365 struct in_addr
*ls_id
,
2366 struct in_addr
*router_id
, int exact
)
2373 struct ospf_lsa
*lsa
;
2376 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
2378 if (*length
!= v
->namelen
+ 1 + IN_ADDR_SIZE
+ IN_ADDR_SIZE
)
2381 offset
= name
+ v
->namelen
;
2383 /* Make it sure given value match to type. */
2387 if (lsa_type
!= *type
)
2391 oid2in_addr(offset
, IN_ADDR_SIZE
, ls_id
);
2392 offset
+= IN_ADDR_SIZE
;
2395 oid2in_addr(offset
, IN_ADDR_SIZE
, router_id
);
2397 return ospf_lsdb_lookup_by_id(ospf
->lsdb
, *type
, *ls_id
,
2400 /* Get variable length. */
2402 offset
= name
+ v
->namelen
;
2403 offsetlen
= *length
- v
->namelen
;
2405 /* LSA type value. */
2410 if (offsetlen
<= 0 || lsa_type
< OSPF_AS_EXTERNAL_LSA
)
2415 if (len
> IN_ADDR_SIZE
)
2418 oid2in_addr(offset
, len
, ls_id
);
2420 offset
+= IN_ADDR_SIZE
;
2421 offsetlen
-= IN_ADDR_SIZE
;
2425 if (len
> IN_ADDR_SIZE
)
2428 oid2in_addr(offset
, len
, router_id
);
2430 lsa
= ospf_lsdb_lookup_by_id_next(ospf
->lsdb
, *type
, *ls_id
,
2434 /* Fill in length. */
2435 *length
= v
->namelen
+ 1 + IN_ADDR_SIZE
+ IN_ADDR_SIZE
;
2437 /* Fill in value. */
2438 offset
= name
+ v
->namelen
;
2440 *offset
= OSPF_AS_EXTERNAL_LSA
;
2442 oid_copy_addr(offset
, &lsa
->data
->id
, IN_ADDR_SIZE
);
2443 offset
+= IN_ADDR_SIZE
;
2444 oid_copy_addr(offset
, &lsa
->data
->adv_router
,
2453 static uint8_t *ospfExtLsdbEntry(struct variable
*v
, oid
*name
, size_t *length
,
2454 int exact
, size_t *var_len
,
2455 WriteMethod
**write_method
)
2457 struct ospf_lsa
*lsa
;
2458 struct lsa_header
*lsah
;
2460 struct in_addr ls_id
;
2461 struct in_addr router_id
;
2464 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
2468 type
= OSPF_AS_EXTERNAL_LSA
;
2469 memset(&ls_id
, 0, sizeof(struct in_addr
));
2470 memset(&router_id
, 0, sizeof(struct in_addr
));
2472 /* Check OSPF instance. */
2473 ospf
= ospf_lookup_by_vrf_id(VRF_DEFAULT
);
2477 lsa
= ospfExtLsdbLookup(v
, name
, length
, &type
, &ls_id
, &router_id
,
2484 /* Return the current value of the variable */
2486 case OSPFEXTLSDBTYPE
:
2487 return SNMP_INTEGER(OSPF_AS_EXTERNAL_LSA
);
2489 case OSPFEXTLSDBLSID
:
2490 return SNMP_IPADDRESS(lsah
->id
);
2492 case OSPFEXTLSDBROUTERID
:
2493 return SNMP_IPADDRESS(lsah
->adv_router
);
2495 case OSPFEXTLSDBSEQUENCE
:
2496 return SNMP_INTEGER(lsah
->ls_seqnum
);
2498 case OSPFEXTLSDBAGE
:
2499 return SNMP_INTEGER(lsah
->ls_age
);
2501 case OSPFEXTLSDBCHECKSUM
:
2502 return SNMP_INTEGER(lsah
->checksum
);
2504 case OSPFEXTLSDBADVERTISEMENT
:
2505 *var_len
= ntohs(lsah
->length
);
2506 return (uint8_t *)lsah
;
2515 static uint8_t *ospfAreaAggregateEntry(struct variable
*v
, oid
*name
,
2516 size_t *length
, int exact
,
2518 WriteMethod
**write_method
)
2520 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
2524 /* Return the current value of the variable */
2526 case OSPFAREAAGGREGATEAREAID
:
2527 return (uint8_t *)NULL
;
2529 case OSPFAREAAGGREGATELSDBTYPE
:
2530 return (uint8_t *)NULL
;
2532 case OSPFAREAAGGREGATENET
:
2533 return (uint8_t *)NULL
;
2535 case OSPFAREAAGGREGATEMASK
:
2536 return (uint8_t *)NULL
;
2538 case OSPFAREAAGGREGATESTATUS
:
2539 return (uint8_t *)NULL
;
2541 case OSPFAREAAGGREGATEEFFECT
:
2542 return (uint8_t *)NULL
;
2552 #define IFSTATECHANGE 16
2553 #define VIRTIFSTATECHANGE 1
2554 #define NBRSTATECHANGE 2
2555 #define VIRTNBRSTATECHANGE 3
2557 static struct trap_object ospfNbrTrapList
[] = {{-2, {1, OSPFROUTERID
}},
2558 {3, {10, 1, OSPFNBRIPADDR
}},
2559 {3, {10, 1, OSPFNBRRTRID
}},
2560 {3, {10, 1, OSPFNBRSTATE
}}};
2563 static struct trap_object ospfVirtNbrTrapList
[] = {
2565 {3, {11, 1, OSPFVIRTNBRAREA
}},
2566 {3, {11, 1, OSPFVIRTNBRRTRID
}},
2567 {3, {11, 1, OSPFVIRTNBRSTATE
}}};
2569 static struct trap_object ospfIfTrapList
[] = {{-2, {1, OSPFROUTERID
}},
2570 {3, {7, 1, OSPFIFIPADDRESS
}},
2571 {3, {7, 1, OSPFADDRESSLESSIF
}},
2572 {3, {7, 1, OSPFIFSTATE
}}};
2574 static struct trap_object ospfVirtIfTrapList
[] = {
2575 {-2, {1, OSPFROUTERID
}},
2576 {3, {9, 1, OSPFVIRTIFAREAID
}},
2577 {3, {9, 1, OSPFVIRTIFNEIGHBOR
}},
2578 {3, {9, 1, OSPFVIRTIFSTATE
}}};
2580 static void ospfTrapNbrStateChange(struct ospf_neighbor
*on
)
2582 oid index
[sizeof(oid
) * (IN_ADDR_SIZE
+ 1)];
2585 ospf_nbr_state_message(on
, msgbuf
, sizeof(msgbuf
));
2586 if (IS_DEBUG_OSPF_EVENT
)
2587 zlog_info("%s: trap sent: %s now %s", __PRETTY_FUNCTION__
,
2588 inet_ntoa(on
->address
.u
.prefix4
), msgbuf
);
2590 oid_copy_addr(index
, &(on
->address
.u
.prefix4
), IN_ADDR_SIZE
);
2591 index
[IN_ADDR_SIZE
] = 0;
2593 smux_trap(ospf_variables
, array_size(ospf_variables
), ospf_trap_oid
,
2594 array_size(ospf_trap_oid
), ospf_oid
,
2595 sizeof ospf_oid
/ sizeof(oid
), index
, IN_ADDR_SIZE
+ 1,
2596 ospfNbrTrapList
, array_size(ospfNbrTrapList
), NBRSTATECHANGE
);
2599 static void ospfTrapVirtNbrStateChange(struct ospf_neighbor
*on
)
2601 oid index
[sizeof(oid
) * (IN_ADDR_SIZE
+ 1)];
2603 zlog_info("ospfTrapVirtNbrStateChange trap sent");
2605 oid_copy_addr(index
, &(on
->address
.u
.prefix4
), IN_ADDR_SIZE
);
2606 index
[IN_ADDR_SIZE
] = 0;
2608 smux_trap(ospf_variables
, array_size(ospf_variables
), ospf_trap_oid
,
2609 array_size(ospf_trap_oid
), ospf_oid
,
2610 sizeof ospf_oid
/ sizeof(oid
), index
, IN_ADDR_SIZE
+ 1,
2611 ospfVirtNbrTrapList
, array_size(ospfVirtNbrTrapList
),
2612 VIRTNBRSTATECHANGE
);
2615 static int ospf_snmp_nsm_change(struct ospf_neighbor
*nbr
, int next_state
,
2618 /* Terminal state or regression */
2619 if ((next_state
== NSM_Full
) || (next_state
== NSM_TwoWay
)
2620 || (next_state
< old_state
)) {
2621 /* ospfVirtNbrStateChange */
2622 if (nbr
->oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
2623 ospfTrapVirtNbrStateChange(nbr
);
2624 /* ospfNbrStateChange trap */
2626 /* To/From FULL, only managed by DR */
2627 if (((next_state
!= NSM_Full
)
2628 && (nbr
->state
!= NSM_Full
))
2629 || (nbr
->oi
->state
== ISM_DR
))
2630 ospfTrapNbrStateChange(nbr
);
2635 static void ospfTrapIfStateChange(struct ospf_interface
*oi
)
2637 oid index
[sizeof(oid
) * (IN_ADDR_SIZE
+ 1)];
2639 if (IS_DEBUG_OSPF_EVENT
)
2640 zlog_info("%s: trap sent: %s now %s", __PRETTY_FUNCTION__
,
2641 inet_ntoa(oi
->address
->u
.prefix4
),
2642 lookup_msg(ospf_ism_state_msg
, oi
->state
, NULL
));
2644 oid_copy_addr(index
, &(oi
->address
->u
.prefix4
), IN_ADDR_SIZE
);
2645 index
[IN_ADDR_SIZE
] = 0;
2647 smux_trap(ospf_variables
, array_size(ospf_variables
), ospf_trap_oid
,
2648 array_size(ospf_trap_oid
), ospf_oid
,
2649 sizeof ospf_oid
/ sizeof(oid
), index
, IN_ADDR_SIZE
+ 1,
2650 ospfIfTrapList
, array_size(ospfIfTrapList
), IFSTATECHANGE
);
2653 static void ospfTrapVirtIfStateChange(struct ospf_interface
*oi
)
2655 oid index
[sizeof(oid
) * (IN_ADDR_SIZE
+ 1)];
2657 zlog_info("ospfTrapVirtIfStateChange trap sent");
2659 oid_copy_addr(index
, &(oi
->address
->u
.prefix4
), IN_ADDR_SIZE
);
2660 index
[IN_ADDR_SIZE
] = 0;
2662 smux_trap(ospf_variables
, array_size(ospf_variables
), ospf_trap_oid
,
2663 array_size(ospf_trap_oid
), ospf_oid
,
2664 sizeof ospf_oid
/ sizeof(oid
), index
, IN_ADDR_SIZE
+ 1,
2665 ospfVirtIfTrapList
, array_size(ospfVirtIfTrapList
),
2669 static int ospf_snmp_ism_change(struct ospf_interface
*oi
, int state
,
2672 /* Terminal state or regression */
2673 if ((state
== ISM_DR
) || (state
== ISM_Backup
) || (state
== ISM_DROther
)
2674 || (state
== ISM_PointToPoint
) || (state
< old_state
)) {
2675 /* ospfVirtIfStateChange */
2676 if (oi
->type
== OSPF_IFTYPE_VIRTUALLINK
)
2677 ospfTrapVirtIfStateChange(oi
);
2678 /* ospfIfStateChange */
2680 ospfTrapIfStateChange(oi
);
2685 /* Register OSPF2-MIB. */
2686 static int ospf_snmp_init(struct thread_master
*tm
)
2688 ospf_snmp_iflist
= list_new();
2689 ospf_snmp_vl_table
= route_table_init();
2691 REGISTER_MIB("mibII/ospf", ospf_variables
, variable
, ospf_oid
);
2695 static int ospf_snmp_module_init(void)
2697 hook_register(ospf_if_update
, ospf_snmp_if_update
);
2698 hook_register(ospf_if_delete
, ospf_snmp_if_delete
);
2699 hook_register(ospf_vl_add
, ospf_snmp_vl_add
);
2700 hook_register(ospf_vl_delete
, ospf_snmp_vl_delete
);
2701 hook_register(ospf_ism_change
, ospf_snmp_ism_change
);
2702 hook_register(ospf_nsm_change
, ospf_snmp_nsm_change
);
2704 hook_register(frr_late_init
, ospf_snmp_init
);
2708 FRR_MODULE_SETUP(.name
= "ospfd_snmp", .version
= FRR_VERSION
,
2709 .description
= "ospfd AgentX SNMP module",
2710 .init
= ospf_snmp_module_init
, )