2 * Copyright (C) 2004 Yasuhiro Ohara
4 * This file is part of GNU Zebra.
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <net-snmp/net-snmp-config.h>
24 #include <net-snmp/net-snmp-includes.h>
35 #include "ospf6_proto.h"
36 #include "ospf6_lsa.h"
37 #include "ospf6_lsdb.h"
38 #include "ospf6_route.h"
39 #include "ospf6_top.h"
40 #include "ospf6_area.h"
41 #include "ospf6_interface.h"
42 #include "ospf6_message.h"
43 #include "ospf6_neighbor.h"
44 #include "ospf6_abr.h"
45 #include "ospf6_asbr.h"
49 #define OSPFv3MIB 1,3,6,1,2,1,191
51 /* OSPFv3 MIB General Group values. */
52 #define OSPFv3ROUTERID 1
53 #define OSPFv3ADMINSTAT 2
54 #define OSPFv3VERSIONNUMBER 3
55 #define OSPFv3AREABDRRTRSTATUS 4
56 #define OSPFv3ASBDRRTRSTATUS 5
57 #define OSPFv3ASSCOPELSACOUNT 6
58 #define OSPFv3ASSCOPELSACHECKSUMSUM 7
59 #define OSPFv3ORIGINATENEWLSAS 8
60 #define OSPFv3RXNEWLSAS 9
61 #define OSPFv3EXTLSACOUNT 10
62 #define OSPFv3EXTAREALSDBLIMIT 11
63 #define OSPFv3EXITOVERFLOWINTERVAL 12
64 #define OSPFv3DEMANDEXTENSIONS 13
65 #define OSPFv3REFERENCEBANDWIDTH 14
66 #define OSPFv3RESTARTSUPPORT 15
67 #define OSPFv3RESTARTINTERVAL 16
68 #define OSPFv3RESTARTSTRICTLSACHECKING 17
69 #define OSPFv3RESTARTSTATUS 18
70 #define OSPFv3RESTARTAGE 19
71 #define OSPFv3RESTARTEXITREASON 20
72 #define OSPFv3NOTIFICATIONENABLE 21
73 #define OSPFv3STUBROUTERSUPPORT 22
74 #define OSPFv3STUBROUTERADVERTISEMENT 23
75 #define OSPFv3DISCONTINUITYTIME 24
76 #define OSPFv3RESTARTTIME 25
78 /* OSPFv3 MIB Area Table values: ospfv3AreaTable */
79 #define OSPFv3IMPORTASEXTERN 2
80 #define OSPFv3AREASPFRUNS 3
81 #define OSPFv3AREABDRRTRCOUNT 4
82 #define OSPFv3AREAASBDRRTRCOUNT 5
83 #define OSPFv3AREASCOPELSACOUNT 6
84 #define OSPFv3AREASCOPELSACKSUMSUM 7
85 #define OSPFv3AREASUMMARY 8
86 #define OSPFv3AREAROWSTATUS 9
87 #define OSPFv3AREASTUBMETRIC 10
88 #define OSPFv3AREANSSATRANSLATORROLE 11
89 #define OSPFv3AREANSSATRANSLATORSTATE 12
90 #define OSPFv3AREANSSATRANSLATORSTABINTERVAL 13
91 #define OSPFv3AREANSSATRANSLATOREVENTS 14
92 #define OSPFv3AREASTUBMETRICTYPE 15
93 #define OSPFv3AREATEENABLED 16
95 /* OSPFv3 MIB * Lsdb Table values: ospfv3*LsdbTable */
96 #define OSPFv3WWLSDBSEQUENCE 1
97 #define OSPFv3WWLSDBAGE 2
98 #define OSPFv3WWLSDBCHECKSUM 3
99 #define OSPFv3WWLSDBADVERTISEMENT 4
100 #define OSPFv3WWLSDBTYPEKNOWN 5
102 /* Three first bits are to identify column */
103 #define OSPFv3WWCOLUMN 0x7
104 /* Then we use other bits to identify table */
105 #define OSPFv3WWASTABLE (1 << 3)
106 #define OSPFv3WWAREATABLE (1 << 4)
107 #define OSPFv3WWLINKTABLE (1 << 5)
108 #define OSPFv3WWVIRTLINKTABLE (1 << 6)
110 /* OSPFv3 MIB Host Table values: ospfv3HostTable */
111 #define OSPFv3HOSTMETRIC 3
112 #define OSPFv3HOSTROWSTATUS 4
113 #define OSPFv3HOSTAREAID 5
115 /* OSPFv3 MIB Interface Table values: ospfv3IfTable */
116 #define OSPFv3IFAREAID 3
117 #define OSPFv3IFTYPE 4
118 #define OSPFv3IFADMINSTATUS 5
119 #define OSPFv3IFRTRPRIORITY 6
120 #define OSPFv3IFTRANSITDELAY 7
121 #define OSPFv3IFRETRANSINTERVAL 8
122 #define OSPFv3IFHELLOINTERVAL 9
123 #define OSPFv3IFRTRDEADINTERVAL 10
124 #define OSPFv3IFPOLLINTERVAL 11
125 #define OSPFv3IFSTATE 12
126 #define OSPFv3IFDESIGNATEDROUTER 13
127 #define OSPFv3IFBACKUPDESIGNATEDROUTER 14
128 #define OSPFv3IFEVENTS 15
129 #define OSPFv3IFROWSTATUS 16
130 #define OSPFv3IFDEMAND 17
131 #define OSPFv3IFMETRICVALUE 18
132 #define OSPFv3IFLINKSCOPELSACOUNT 19
133 #define OSPFv3IFLINKLSACKSUMSUM 20
134 #define OSPFv3IFDEMANDNBRPROBE 21
135 #define OSPFv3IFDEMANDNBRPROBERETRANSLIMIT 22
136 #define OSPFv3IFDEMANDNBRPROBEINTERVAL 23
137 #define OSPFv3IFTEDISABLED 24
138 #define OSPFv3IFLINKLSASUPPRESSION 25
140 /* OSPFv3 MIB Virtual Interface Table values: ospfv3VirtIfTable */
141 #define OSPFv3VIRTIFINDEX 3
142 #define OSPFv3VIRTIFINSTID 4
143 #define OSPFv3VIRTIFTRANSITDELAY 5
144 #define OSPFv3VIRTIFRETRANSINTERVAL 6
145 #define OSPFv3VIRTIFHELLOINTERVAL 7
146 #define OSPFv3VIRTIFRTRDEADINTERVAL 8
147 #define OSPFv3VIRTIFSTATE 9
148 #define OSPFv3VIRTIFEVENTS 10
149 #define OSPFv3VIRTIFROWSTATUS 11
150 #define OSPFv3VIRTIFLINKSCOPELSACOUNT 12
151 #define OSPFv3VIRTIFLINKLSACKSUMSUM 13
153 /* OSPFv3 MIB Neighbors Table values: ospfv3NbrTable */
154 #define OSPFv3NBRADDRESSTYPE 4
155 #define OSPFv3NBRADDRESS 5
156 #define OSPFv3NBROPTIONS 6
157 #define OSPFv3NBRPRIORITY 7
158 #define OSPFv3NBRSTATE 8
159 #define OSPFv3NBREVENTS 9
160 #define OSPFv3NBRLSRETRANSQLEN 10
161 #define OSPFv3NBRHELLOSUPPRESSED 11
162 #define OSPFv3NBRIFID 12
163 #define OSPFv3NBRRESTARTHELPERSTATUS 13
164 #define OSPFv3NBRRESTARTHELPERAGE 14
165 #define OSPFv3NBRRESTARTHELPEREXITREASON 15
167 /* OSPFv3 MIB Configured Neighbors Table values: ospfv3CfgNbrTable */
168 #define OSPFv3CFGNBRPRIORITY 5
169 #define OSPFv3CFGNBRROWSTATUS 6
171 /* OSPFv3 MIB Virtual Neighbors Table values: ospfv3VirtNbrTable */
172 #define OSPFv3VIRTNBRIFINDEX 3
173 #define OSPFv3VIRTNBRIFINSTID 4
174 #define OSPFv3VIRTNBRADDRESSTYPE 5
175 #define OSPFv3VIRTNBRADDRESS 6
176 #define OSPFv3VIRTNBROPTIONS 7
177 #define OSPFv3VIRTNBRSTATE 8
178 #define OSPFv3VIRTNBREVENTS 9
179 #define OSPFv3VIRTNBRLSRETRANSQLEN 10
180 #define OSPFv3VIRTNBRHELLOSUPPRESSED 11
181 #define OSPFv3VIRTNBRIFID 12
182 #define OSPFv3VIRTNBRRESTARTHELPERSTATUS 13
183 #define OSPFv3VIRTNBRRESTARTHELPERAGE 14
184 #define OSPFv3VIRTNBRRESTARTHELPEREXITREASON 15
186 /* OSPFv3 MIB Area Aggregate Table values: ospfv3AreaAggregateTable */
187 #define OSPFv3AREAAGGREGATEROWSTATUS 6
188 #define OSPFv3AREAAGGREGATEEFFECT 7
189 #define OSPFv3AREAAGGREGATEROUTETAG 8
191 /* SYNTAX Status from OSPF-MIB. */
192 #define OSPF_STATUS_ENABLED 1
193 #define OSPF_STATUS_DISABLED 2
195 /* SNMP value hack. */
196 #define COUNTER ASN_COUNTER
197 #define INTEGER ASN_INTEGER
198 #define GAUGE ASN_GAUGE
199 #define UNSIGNED ASN_UNSIGNED
200 #define TIMETICKS ASN_TIMETICKS
201 #define IPADDRESS ASN_IPADDRESS
202 #define STRING ASN_OCTET_STR
204 /* For return values e.g. SNMP_INTEGER macro */
207 /* OSPFv3-MIB instances. */
208 static oid ospfv3_oid
[] = {OSPFv3MIB
};
209 static oid ospfv3_trap_oid
[] = {OSPFv3MIB
, 0};
211 /* Hook functions. */
212 static uint8_t *ospfv3GeneralGroup(struct variable
*, oid
*, size_t *, int,
213 size_t *, WriteMethod
**);
214 static uint8_t *ospfv3AreaEntry(struct variable
*, oid
*, size_t *, int,
215 size_t *, WriteMethod
**);
216 static uint8_t *ospfv3WwLsdbEntry(struct variable
*, oid
*, size_t *, int,
217 size_t *, WriteMethod
**);
218 static uint8_t *ospfv3NbrEntry(struct variable
*, oid
*, size_t *, int,
219 size_t *, WriteMethod
**);
220 static uint8_t *ospfv3IfEntry(struct variable
*, oid
*, size_t *, int, size_t *,
223 static struct variable ospfv3_variables
[] = {
224 /* OSPF general variables */
225 {OSPFv3ROUTERID
, UNSIGNED
, RWRITE
, ospfv3GeneralGroup
, 3, {1, 1, 1}},
226 {OSPFv3ADMINSTAT
, INTEGER
, RWRITE
, ospfv3GeneralGroup
, 3, {1, 1, 2}},
227 {OSPFv3VERSIONNUMBER
, INTEGER
, RONLY
, ospfv3GeneralGroup
, 3, {1, 1, 3}},
228 {OSPFv3AREABDRRTRSTATUS
,
234 {OSPFv3ASBDRRTRSTATUS
,
240 {OSPFv3ASSCOPELSACOUNT
, GAUGE
, RONLY
, ospfv3GeneralGroup
, 3, {1, 1, 6}},
241 {OSPFv3ASSCOPELSACHECKSUMSUM
,
247 {OSPFv3ORIGINATENEWLSAS
,
253 {OSPFv3RXNEWLSAS
, COUNTER
, RONLY
, ospfv3GeneralGroup
, 3, {1, 1, 9}},
254 {OSPFv3EXTLSACOUNT
, GAUGE
, RONLY
, ospfv3GeneralGroup
, 3, {1, 1, 10}},
255 {OSPFv3EXTAREALSDBLIMIT
,
261 {OSPFv3EXITOVERFLOWINTERVAL
,
267 {OSPFv3DEMANDEXTENSIONS
,
273 {OSPFv3REFERENCEBANDWIDTH
,
279 {OSPFv3RESTARTSUPPORT
,
285 {OSPFv3RESTARTINTERVAL
,
291 {OSPFv3RESTARTSTRICTLSACHECKING
,
297 {OSPFv3RESTARTSTATUS
,
303 {OSPFv3RESTARTAGE
, UNSIGNED
, RONLY
, ospfv3GeneralGroup
, 3, {1, 1, 19}},
304 {OSPFv3RESTARTEXITREASON
,
310 {OSPFv3NOTIFICATIONENABLE
,
316 {OSPFv3STUBROUTERSUPPORT
,
322 {OSPFv3STUBROUTERADVERTISEMENT
,
328 {OSPFv3DISCONTINUITYTIME
,
341 /* OSPFv3 Area Data Structure */
342 {OSPFv3IMPORTASEXTERN
,
348 {OSPFv3AREASPFRUNS
, COUNTER
, RONLY
, ospfv3AreaEntry
, 4, {1, 2, 1, 3}},
349 {OSPFv3AREABDRRTRCOUNT
, GAUGE
, RONLY
, ospfv3AreaEntry
, 4, {1, 2, 1, 4}},
350 {OSPFv3AREAASBDRRTRCOUNT
,
356 {OSPFv3AREASCOPELSACOUNT
,
362 {OSPFv3AREASCOPELSACKSUMSUM
,
368 {OSPFv3AREASUMMARY
, INTEGER
, RWRITE
, ospfv3AreaEntry
, 4, {1, 2, 1, 8}},
369 {OSPFv3AREAROWSTATUS
,
375 {OSPFv3AREASTUBMETRIC
,
381 {OSPFv3AREANSSATRANSLATORROLE
,
387 {OSPFv3AREANSSATRANSLATORSTATE
,
393 {OSPFv3AREANSSATRANSLATORSTABINTERVAL
,
399 {OSPFv3AREANSSATRANSLATOREVENTS
,
405 {OSPFv3AREASTUBMETRICTYPE
,
411 {OSPFv3AREATEENABLED
,
419 {OSPFv3WWLSDBSEQUENCE
| OSPFv3WWASTABLE
,
425 {OSPFv3WWLSDBAGE
| OSPFv3WWASTABLE
,
431 {OSPFv3WWLSDBCHECKSUM
| OSPFv3WWASTABLE
,
437 {OSPFv3WWLSDBADVERTISEMENT
| OSPFv3WWASTABLE
,
443 {OSPFv3WWLSDBTYPEKNOWN
| OSPFv3WWASTABLE
,
450 /* OSPFv3 Area LSDB */
451 {OSPFv3WWLSDBSEQUENCE
| OSPFv3WWAREATABLE
,
457 {OSPFv3WWLSDBAGE
| OSPFv3WWAREATABLE
,
463 {OSPFv3WWLSDBCHECKSUM
| OSPFv3WWAREATABLE
,
469 {OSPFv3WWLSDBADVERTISEMENT
| OSPFv3WWAREATABLE
,
475 {OSPFv3WWLSDBTYPEKNOWN
| OSPFv3WWAREATABLE
,
482 /* OSPFv3 Link LSDB */
483 {OSPFv3WWLSDBSEQUENCE
| OSPFv3WWLINKTABLE
,
489 {OSPFv3WWLSDBAGE
| OSPFv3WWLINKTABLE
,
495 {OSPFv3WWLSDBCHECKSUM
| OSPFv3WWLINKTABLE
,
501 {OSPFv3WWLSDBADVERTISEMENT
| OSPFv3WWLINKTABLE
,
507 {OSPFv3WWLSDBTYPEKNOWN
| OSPFv3WWLINKTABLE
,
514 /* OSPFv3 interfaces */
515 {OSPFv3IFAREAID
, UNSIGNED
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 3}},
516 {OSPFv3IFTYPE
, INTEGER
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 4}},
517 {OSPFv3IFADMINSTATUS
, INTEGER
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 5}},
518 {OSPFv3IFRTRPRIORITY
, INTEGER
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 6}},
519 {OSPFv3IFTRANSITDELAY
, UNSIGNED
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 7}},
520 {OSPFv3IFRETRANSINTERVAL
,
526 {OSPFv3IFHELLOINTERVAL
, INTEGER
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 9}},
527 {OSPFv3IFRTRDEADINTERVAL
,
533 {OSPFv3IFPOLLINTERVAL
,
539 {OSPFv3IFSTATE
, INTEGER
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 12}},
540 {OSPFv3IFDESIGNATEDROUTER
,
546 {OSPFv3IFBACKUPDESIGNATEDROUTER
,
552 {OSPFv3IFEVENTS
, COUNTER
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 15}},
553 {OSPFv3IFROWSTATUS
, INTEGER
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 16}},
554 {OSPFv3IFDEMAND
, INTEGER
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 17}},
555 {OSPFv3IFMETRICVALUE
, INTEGER
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 18}},
556 {OSPFv3IFLINKSCOPELSACOUNT
,
562 {OSPFv3IFLINKLSACKSUMSUM
,
568 {OSPFv3IFDEMANDNBRPROBE
,
574 {OSPFv3IFDEMANDNBRPROBERETRANSLIMIT
,
580 {OSPFv3IFDEMANDNBRPROBEINTERVAL
,
586 {OSPFv3IFTEDISABLED
, INTEGER
, RONLY
, ospfv3IfEntry
, 4, {1, 7, 1, 24}},
587 {OSPFv3IFLINKLSASUPPRESSION
,
594 /* OSPFv3 neighbors */
595 {OSPFv3NBRADDRESSTYPE
, INTEGER
, RONLY
, ospfv3NbrEntry
, 4, {1, 9, 1, 4}},
596 {OSPFv3NBRADDRESS
, STRING
, RONLY
, ospfv3NbrEntry
, 4, {1, 9, 1, 5}},
597 {OSPFv3NBROPTIONS
, INTEGER
, RONLY
, ospfv3NbrEntry
, 4, {1, 9, 1, 6}},
598 {OSPFv3NBRPRIORITY
, INTEGER
, RONLY
, ospfv3NbrEntry
, 4, {1, 9, 1, 7}},
599 {OSPFv3NBRSTATE
, INTEGER
, RONLY
, ospfv3NbrEntry
, 4, {1, 9, 1, 8}},
600 {OSPFv3NBREVENTS
, COUNTER
, RONLY
, ospfv3NbrEntry
, 4, {1, 9, 1, 9}},
601 {OSPFv3NBRLSRETRANSQLEN
,
607 {OSPFv3NBRHELLOSUPPRESSED
,
613 {OSPFv3NBRIFID
, INTEGER
, RONLY
, ospfv3NbrEntry
, 4, {1, 9, 1, 12}},
614 {OSPFv3NBRRESTARTHELPERSTATUS
,
620 {OSPFv3NBRRESTARTHELPERAGE
,
626 {OSPFv3NBRRESTARTHELPEREXITREASON
,
634 static uint8_t *ospfv3GeneralGroup(struct variable
*v
, oid
*name
,
635 size_t *length
, int exact
, size_t *var_len
,
636 WriteMethod
**write_method
)
640 struct ospf6_lsa
*lsa
= NULL
;
642 /* Check whether the instance identifier is valid */
643 if (smux_header_generic(v
, name
, length
, exact
, var_len
, write_method
)
647 /* Return the current value of the variable */
650 /* Router-ID of this OSPF instance. */
652 return SNMP_INTEGER(ntohl(ospf6
->router_id
));
653 return SNMP_INTEGER(0);
654 case OSPFv3ADMINSTAT
:
657 CHECK_FLAG(ospf6
->flag
, OSPF6_DISABLED
)
658 ? OSPF_STATUS_DISABLED
659 : OSPF_STATUS_ENABLED
);
660 return SNMP_INTEGER(OSPF_STATUS_DISABLED
);
661 case OSPFv3VERSIONNUMBER
:
662 return SNMP_INTEGER(3);
663 case OSPFv3AREABDRRTRSTATUS
:
665 return SNMP_INTEGER(ospf6_is_router_abr(ospf6
)
668 return SNMP_INTEGER(SNMP_FALSE
);
669 case OSPFv3ASBDRRTRSTATUS
:
671 return SNMP_INTEGER(ospf6_asbr_is_asbr(ospf6
)
674 return SNMP_INTEGER(SNMP_FALSE
);
675 case OSPFv3ASSCOPELSACOUNT
:
677 return SNMP_INTEGER(ospf6
->lsdb
->count
);
678 return SNMP_INTEGER(0);
679 case OSPFv3ASSCOPELSACHECKSUMSUM
:
682 for (ALL_LSDB(ospf6
->lsdb
, lsa
))
683 sum
+= ntohs(lsa
->header
->checksum
);
684 return SNMP_INTEGER(sum
);
686 return SNMP_INTEGER(0);
687 case OSPFv3ORIGINATENEWLSAS
:
689 0); /* Don't know where to get this value... */
690 case OSPFv3RXNEWLSAS
:
692 0); /* Don't know where to get this value... */
693 case OSPFv3EXTLSACOUNT
:
696 for (ALL_LSDB_TYPED(ospf6
->lsdb
,
697 htons(OSPF6_LSTYPE_AS_EXTERNAL
),
700 return SNMP_INTEGER(count
);
702 return SNMP_INTEGER(0);
703 case OSPFv3EXTAREALSDBLIMIT
:
704 return SNMP_INTEGER(-1);
705 case OSPFv3EXITOVERFLOWINTERVAL
:
706 return SNMP_INTEGER(0); /* Not supported */
707 case OSPFv3DEMANDEXTENSIONS
:
708 return SNMP_INTEGER(0); /* Not supported */
709 case OSPFv3REFERENCEBANDWIDTH
:
711 return SNMP_INTEGER(ospf6
->ref_bandwidth
);
712 /* Otherwise, like for "not implemented". */
714 case OSPFv3RESTARTSUPPORT
:
715 case OSPFv3RESTARTINTERVAL
:
716 case OSPFv3RESTARTSTRICTLSACHECKING
:
717 case OSPFv3RESTARTSTATUS
:
718 case OSPFv3RESTARTAGE
:
719 case OSPFv3RESTARTEXITREASON
:
720 case OSPFv3NOTIFICATIONENABLE
:
721 case OSPFv3STUBROUTERSUPPORT
:
722 case OSPFv3STUBROUTERADVERTISEMENT
:
723 case OSPFv3DISCONTINUITYTIME
:
724 case OSPFv3RESTARTTIME
:
725 /* TODO: Not implemented */
731 static uint8_t *ospfv3AreaEntry(struct variable
*v
, oid
*name
, size_t *length
,
732 int exact
, size_t *var_len
,
733 WriteMethod
**write_method
)
735 struct ospf6_area
*oa
, *area
= NULL
;
736 struct ospf6_lsa
*lsa
= NULL
;
737 uint32_t area_id
= 0;
740 struct listnode
*node
;
743 struct ospf6_route
*ro
;
748 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
752 len
= *length
- v
->namelen
;
753 len
= (len
>= 1 ? 1 : 0);
754 if (exact
&& len
!= 1)
757 area_id
= htonl(name
[v
->namelen
]);
759 inet_ntop(AF_INET
, &area_id
, a
, sizeof(a
));
760 zlog_debug("SNMP access by area: %s, exact=%d len=%d length=%lu", a
,
761 exact
, len
, (unsigned long)*length
);
763 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, node
, oa
)) {
765 if (len
== 0) /* return first area entry */
767 else if (exact
&& ntohl(oa
->area_id
) == ntohl(area_id
))
769 else if (ntohl(oa
->area_id
) > ntohl(area_id
))
777 *length
= v
->namelen
+ 1;
778 name
[v
->namelen
] = ntohl(area
->area_id
);
780 inet_ntop(AF_INET
, &area
->area_id
, a
, sizeof(a
));
781 zlog_debug("SNMP found area: %s, exact=%d len=%d length=%lu", a
, exact
,
782 len
, (unsigned long)*length
);
785 case OSPFv3IMPORTASEXTERN
:
786 /* No NSSA support */
787 return SNMP_INTEGER(IS_AREA_STUB(area
) ? 2 : 1);
788 case OSPFv3AREASPFRUNS
:
789 return SNMP_INTEGER(area
->spf_calculation
);
790 case OSPFv3AREABDRRTRCOUNT
:
791 case OSPFv3AREAASBDRRTRCOUNT
:
793 for (ro
= ospf6_route_head(ospf6
->brouter_table
); ro
;
794 ro
= ospf6_route_next(ro
)) {
795 if (ntohl(ro
->path
.area_id
) != ntohl(area
->area_id
))
797 if (v
->magic
== OSPFv3AREABDRRTRCOUNT
798 && CHECK_FLAG(ro
->path
.router_bits
,
801 if (v
->magic
== OSPFv3AREAASBDRRTRCOUNT
802 && CHECK_FLAG(ro
->path
.router_bits
,
806 return SNMP_INTEGER(count
);
807 case OSPFv3AREASCOPELSACOUNT
:
808 return SNMP_INTEGER(area
->lsdb
->count
);
809 case OSPFv3AREASCOPELSACKSUMSUM
:
811 for (ALL_LSDB(area
->lsdb
, lsa
))
812 sum
+= ntohs(lsa
->header
->checksum
);
813 return SNMP_INTEGER(sum
);
814 case OSPFv3AREASUMMARY
:
815 return SNMP_INTEGER(2); /* sendAreaSummary */
816 case OSPFv3AREAROWSTATUS
:
817 return SNMP_INTEGER(1); /* Active */
818 case OSPFv3AREASTUBMETRIC
:
819 case OSPFv3AREANSSATRANSLATORROLE
:
820 case OSPFv3AREANSSATRANSLATORSTATE
:
821 case OSPFv3AREANSSATRANSLATORSTABINTERVAL
:
822 case OSPFv3AREANSSATRANSLATOREVENTS
:
823 case OSPFv3AREASTUBMETRICTYPE
:
824 case OSPFv3AREATEENABLED
:
825 /* Not implemented. */
831 static int if_icmp_func(struct interface
*ifp1
, struct interface
*ifp2
)
833 return (ifp1
->ifindex
- ifp2
->ifindex
);
836 static uint8_t *ospfv3WwLsdbEntry(struct variable
*v
, oid
*name
, size_t *length
,
837 int exact
, size_t *var_len
,
838 WriteMethod
**write_method
)
840 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
841 struct ospf6_lsa
*lsa
= NULL
;
843 uint32_t area_id
, id
, instid
, adv_router
;
848 struct ospf6_area
*oa
= NULL
;
849 struct listnode
*node
;
850 struct interface
*iif
;
851 struct ospf6_interface
*oi
= NULL
;
852 struct list
*ifslist
;
854 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
858 instid
= ifindex
= area_id
= type
= id
= adv_router
= 0;
860 /* Check OSPFv3 instance. */
864 /* Get variable length. */
865 offset
= name
+ v
->namelen
;
866 offsetlen
= *length
- v
->namelen
;
868 if (exact
&& (v
->magic
& OSPFv3WWASTABLE
) && offsetlen
!= 3)
870 if (exact
&& (v
->magic
& OSPFv3WWAREATABLE
) && offsetlen
!= 4)
872 if (exact
&& (v
->magic
& OSPFv3WWLINKTABLE
) && offsetlen
!= 5)
875 if (v
->magic
& OSPFv3WWLINKTABLE
) {
877 len
= (offsetlen
< 1 ? 0 : 1);
883 /* Parse instance ID */
884 len
= (offsetlen
< 1 ? 0 : 1);
889 } else if (v
->magic
& OSPFv3WWAREATABLE
) {
891 len
= (offsetlen
< 1 ? 0 : 1);
893 area_id
= htonl(*offset
);
899 len
= (offsetlen
< 1 ? 0 : 1);
901 type
= htons(*offset
);
905 /* Parse Router-ID */
906 len
= (offsetlen
< 1 ? 0 : 1);
908 adv_router
= htonl(*offset
);
913 len
= (offsetlen
< 1 ? 0 : 1);
917 // offsetlen -= len; // Add back in if we need it again
920 if (v
->magic
& OSPFv3WWASTABLE
) {
921 lsa
= ospf6_lsdb_lookup(type
, id
, adv_router
,
923 } else if (v
->magic
& OSPFv3WWAREATABLE
) {
924 oa
= ospf6_area_lookup(area_id
, ospf6
);
927 lsa
= ospf6_lsdb_lookup(type
, id
, adv_router
, oa
->lsdb
);
928 } else if (v
->magic
& OSPFv3WWLINKTABLE
) {
929 oi
= ospf6_interface_lookup_by_ifindex(ifindex
);
930 if (!oi
|| oi
->instance_id
!= instid
)
932 lsa
= ospf6_lsdb_lookup(type
, id
, adv_router
, oi
->lsdb
);
935 if (v
->magic
& OSPFv3WWASTABLE
) {
936 if (ospf6
->lsdb
->count
)
937 lsa
= ospf6_lsdb_lookup_next(
938 type
, id
, adv_router
, ospf6
->lsdb
);
939 } else if (v
->magic
& OSPFv3WWAREATABLE
)
940 for (ALL_LIST_ELEMENTS_RO(ospf6
->area_list
, node
, oa
)) {
941 if (oa
->area_id
< area_id
)
945 lsa
= ospf6_lsdb_lookup_next(
946 type
, id
, adv_router
, oa
->lsdb
);
953 else if (v
->magic
& OSPFv3WWLINKTABLE
) {
954 /* We build a sorted list of interfaces */
955 ifslist
= list_new();
958 ifslist
->cmp
= (int (*)(void *, void *))if_icmp_func
;
959 FOR_ALL_INTERFACES (vrf
, iif
)
960 listnode_add_sort(ifslist
, iif
);
962 for (ALL_LIST_ELEMENTS_RO(ifslist
, node
, iif
)) {
965 oi
= ospf6_interface_lookup_by_ifindex(
969 if (iif
->ifindex
< ifindex
)
971 if (oi
->instance_id
< instid
)
975 lsa
= ospf6_lsdb_lookup_next(
976 type
, id
, adv_router
, oi
->lsdb
);
985 list_delete_all_node(ifslist
);
993 if (v
->magic
& OSPFv3WWASTABLE
) {
994 *length
= v
->namelen
+ 3;
995 offset
= name
+ v
->namelen
;
996 } else if (v
->magic
& OSPFv3WWAREATABLE
) {
997 *length
= v
->namelen
+ 4;
998 offset
= name
+ v
->namelen
;
999 *offset
= ntohl(oa
->area_id
);
1001 } else if (v
->magic
& OSPFv3WWLINKTABLE
) {
1002 *length
= v
->namelen
+ 5;
1003 offset
= name
+ v
->namelen
;
1004 *offset
= oi
->interface
->ifindex
;
1006 *offset
= oi
->instance_id
;
1009 *offset
= ntohs(lsa
->header
->type
);
1011 *offset
= ntohl(lsa
->header
->adv_router
);
1013 *offset
= ntohl(lsa
->header
->id
);
1016 /* Return the current value of the variable */
1017 switch (v
->magic
& OSPFv3WWCOLUMN
) {
1018 case OSPFv3WWLSDBSEQUENCE
:
1019 return SNMP_INTEGER(ntohl(lsa
->header
->seqnum
));
1021 case OSPFv3WWLSDBAGE
:
1022 ospf6_lsa_age_current(lsa
);
1023 return SNMP_INTEGER(ntohs(lsa
->header
->age
));
1025 case OSPFv3WWLSDBCHECKSUM
:
1026 return SNMP_INTEGER(ntohs(lsa
->header
->checksum
));
1028 case OSPFv3WWLSDBADVERTISEMENT
:
1029 *var_len
= ntohs(lsa
->header
->length
);
1030 return (uint8_t *)lsa
->header
;
1032 case OSPFv3WWLSDBTYPEKNOWN
:
1033 return SNMP_INTEGER(OSPF6_LSA_IS_KNOWN(lsa
->header
->type
)
1041 static uint8_t *ospfv3IfEntry(struct variable
*v
, oid
*name
, size_t *length
,
1042 int exact
, size_t *var_len
,
1043 WriteMethod
**write_method
)
1045 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1046 ifindex_t ifindex
= 0;
1047 unsigned int instid
= 0;
1048 struct ospf6_interface
*oi
= NULL
;
1049 struct ospf6_lsa
*lsa
= NULL
;
1050 struct interface
*iif
;
1052 struct list
*ifslist
;
1057 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
1061 /* Check OSPFv3 instance. */
1065 /* Get variable length. */
1066 offset
= name
+ v
->namelen
;
1067 offsetlen
= *length
- v
->namelen
;
1069 if (exact
&& offsetlen
!= 2)
1072 /* Parse if index */
1073 len
= (offsetlen
< 1 ? 0 : 1);
1079 /* Parse instance ID */
1080 len
= (offsetlen
< 1 ? 0 : 1);
1083 // offset += len; // Add back in if we ever start using again
1084 // offsetlen -= len;
1087 oi
= ospf6_interface_lookup_by_ifindex(ifindex
);
1088 if (!oi
|| oi
->instance_id
!= instid
)
1091 /* We build a sorted list of interfaces */
1092 ifslist
= list_new();
1095 ifslist
->cmp
= (int (*)(void *, void *))if_icmp_func
;
1096 FOR_ALL_INTERFACES (vrf
, iif
)
1097 listnode_add_sort(ifslist
, iif
);
1099 for (ALL_LIST_ELEMENTS_RO(ifslist
, i
, iif
)) {
1102 oi
= ospf6_interface_lookup_by_ifindex(iif
->ifindex
);
1105 if (iif
->ifindex
> ifindex
1106 || (iif
->ifindex
== ifindex
1107 && (oi
->instance_id
> instid
)))
1112 list_delete_all_node(ifslist
);
1118 /* Add Index (IfIndex, IfInstId) */
1119 *length
= v
->namelen
+ 2;
1120 offset
= name
+ v
->namelen
;
1121 *offset
= oi
->interface
->ifindex
;
1123 *offset
= oi
->instance_id
;
1126 /* Return the current value of the variable */
1128 case OSPFv3IFAREAID
:
1130 return SNMP_INTEGER(ntohl(oi
->area
->area_id
));
1133 if (oi
->type
== OSPF_IFTYPE_BROADCAST
)
1134 return SNMP_INTEGER(1);
1135 else if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
)
1136 return SNMP_INTEGER(3);
1138 break; /* Unknown, don't put anything */
1139 case OSPFv3IFADMINSTATUS
:
1141 return SNMP_INTEGER(OSPF_STATUS_ENABLED
);
1142 return SNMP_INTEGER(OSPF_STATUS_DISABLED
);
1143 case OSPFv3IFRTRPRIORITY
:
1144 return SNMP_INTEGER(oi
->priority
);
1145 case OSPFv3IFTRANSITDELAY
:
1146 return SNMP_INTEGER(oi
->transdelay
);
1147 case OSPFv3IFRETRANSINTERVAL
:
1148 return SNMP_INTEGER(oi
->rxmt_interval
);
1149 case OSPFv3IFHELLOINTERVAL
:
1150 return SNMP_INTEGER(oi
->hello_interval
);
1151 case OSPFv3IFRTRDEADINTERVAL
:
1152 return SNMP_INTEGER(oi
->dead_interval
);
1153 case OSPFv3IFPOLLINTERVAL
:
1154 /* No support for NBMA */
1157 return SNMP_INTEGER(oi
->state
);
1158 case OSPFv3IFDESIGNATEDROUTER
:
1159 return SNMP_INTEGER(ntohl(oi
->drouter
));
1160 case OSPFv3IFBACKUPDESIGNATEDROUTER
:
1161 return SNMP_INTEGER(ntohl(oi
->bdrouter
));
1162 case OSPFv3IFEVENTS
:
1163 return SNMP_INTEGER(oi
->state_change
);
1164 case OSPFv3IFROWSTATUS
:
1165 return SNMP_INTEGER(1);
1166 case OSPFv3IFDEMAND
:
1167 return SNMP_INTEGER(SNMP_FALSE
);
1168 case OSPFv3IFMETRICVALUE
:
1169 return SNMP_INTEGER(oi
->cost
);
1170 case OSPFv3IFLINKSCOPELSACOUNT
:
1171 return SNMP_INTEGER(oi
->lsdb
->count
);
1172 case OSPFv3IFLINKLSACKSUMSUM
:
1174 for (ALL_LSDB(oi
->lsdb
, lsa
))
1175 sum
+= ntohs(lsa
->header
->checksum
);
1176 return SNMP_INTEGER(sum
);
1177 case OSPFv3IFDEMANDNBRPROBE
:
1178 case OSPFv3IFDEMANDNBRPROBERETRANSLIMIT
:
1179 case OSPFv3IFDEMANDNBRPROBEINTERVAL
:
1180 case OSPFv3IFTEDISABLED
:
1181 case OSPFv3IFLINKLSASUPPRESSION
:
1182 /* Not implemented. Only works if all the last ones are not
1187 /* Try an internal getnext. Some columns are missing in this table. */
1188 if (!exact
&& (name
[*length
- 1] < MAX_SUBID
))
1189 return ospfv3IfEntry(v
, name
, length
, exact
, var_len
,
1194 static uint8_t *ospfv3NbrEntry(struct variable
*v
, oid
*name
, size_t *length
,
1195 int exact
, size_t *var_len
,
1196 WriteMethod
**write_method
)
1198 struct vrf
*vrf
= vrf_lookup_by_id(VRF_DEFAULT
);
1199 ifindex_t ifindex
= 0;
1200 unsigned int instid
, rtrid
;
1201 struct ospf6_interface
*oi
= NULL
;
1202 struct ospf6_neighbor
*on
= NULL
;
1203 struct interface
*iif
;
1204 struct listnode
*i
, *j
;
1205 struct list
*ifslist
;
1209 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
1215 /* Check OSPFv3 instance. */
1219 /* Get variable length. */
1220 offset
= name
+ v
->namelen
;
1221 offsetlen
= *length
- v
->namelen
;
1223 if (exact
&& offsetlen
!= 3)
1226 /* Parse if index */
1227 len
= (offsetlen
< 1 ? 0 : 1);
1233 /* Parse instance ID */
1234 len
= (offsetlen
< 1 ? 0 : 1);
1240 /* Parse router ID */
1241 len
= (offsetlen
< 1 ? 0 : 1);
1243 rtrid
= htonl(*offset
);
1244 // offset += len; // Add back in if we ever start looking at data
1245 // offsetlen -= len;
1248 oi
= ospf6_interface_lookup_by_ifindex(ifindex
);
1249 if (!oi
|| oi
->instance_id
!= instid
)
1251 on
= ospf6_neighbor_lookup(rtrid
, oi
);
1253 /* We build a sorted list of interfaces */
1254 ifslist
= list_new();
1257 ifslist
->cmp
= (int (*)(void *, void *))if_icmp_func
;
1258 FOR_ALL_INTERFACES (vrf
, iif
)
1259 listnode_add_sort(ifslist
, iif
);
1261 for (ALL_LIST_ELEMENTS_RO(ifslist
, i
, iif
)) {
1264 oi
= ospf6_interface_lookup_by_ifindex(iif
->ifindex
);
1267 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, j
, on
)) {
1268 if (iif
->ifindex
> ifindex
1269 || (iif
->ifindex
== ifindex
1270 && (oi
->instance_id
> instid
1271 || (oi
->instance_id
== instid
1272 && ntohl(on
->router_id
)
1282 list_delete_all_node(ifslist
);
1288 /* Add Index (IfIndex, IfInstId, RtrId) */
1289 *length
= v
->namelen
+ 3;
1290 offset
= name
+ v
->namelen
;
1291 *offset
= oi
->interface
->ifindex
;
1293 *offset
= oi
->instance_id
;
1295 *offset
= ntohl(on
->router_id
);
1298 /* Return the current value of the variable */
1300 case OSPFv3NBRADDRESSTYPE
:
1301 return SNMP_INTEGER(2); /* IPv6 only */
1302 case OSPFv3NBRADDRESS
:
1303 *var_len
= sizeof(struct in6_addr
);
1304 return (uint8_t *)&on
->linklocal_addr
;
1305 case OSPFv3NBROPTIONS
:
1306 return SNMP_INTEGER(on
->options
[2]);
1307 case OSPFv3NBRPRIORITY
:
1308 return SNMP_INTEGER(on
->priority
);
1309 case OSPFv3NBRSTATE
:
1310 return SNMP_INTEGER(on
->state
);
1311 case OSPFv3NBREVENTS
:
1312 return SNMP_INTEGER(on
->state_change
);
1313 case OSPFv3NBRLSRETRANSQLEN
:
1314 return SNMP_INTEGER(on
->retrans_list
->count
);
1315 case OSPFv3NBRHELLOSUPPRESSED
:
1316 return SNMP_INTEGER(SNMP_FALSE
);
1318 return SNMP_INTEGER(on
->ifindex
);
1319 case OSPFv3NBRRESTARTHELPERSTATUS
:
1320 case OSPFv3NBRRESTARTHELPERAGE
:
1321 case OSPFv3NBRRESTARTHELPEREXITREASON
:
1322 /* Not implemented. Only works if all the last ones are not
1331 #define NBRSTATECHANGE 2
1332 #define IFSTATECHANGE 10
1334 static struct trap_object ospf6NbrTrapList
[] = {
1335 {-3, {1, 1, OSPFv3ROUTERID
}},
1336 {4, {1, 9, 1, OSPFv3NBRADDRESSTYPE
}},
1337 {4, {1, 9, 1, OSPFv3NBRADDRESS
}},
1338 {4, {1, 9, 1, OSPFv3NBRSTATE
}}};
1340 static struct trap_object ospf6IfTrapList
[] = {
1341 {-3, {1, 1, OSPFv3ROUTERID
}},
1342 {4, {1, 7, 1, OSPFv3IFSTATE
}},
1343 {4, {1, 7, 1, OSPFv3IFADMINSTATUS
}},
1344 {4, {1, 7, 1, OSPFv3IFAREAID
}}};
1346 static int ospf6TrapNbrStateChange(struct ospf6_neighbor
*on
, int next_state
,
1351 /* Terminal state or regression */
1352 if ((next_state
!= OSPF6_NEIGHBOR_FULL
)
1353 && (next_state
!= OSPF6_NEIGHBOR_TWOWAY
)
1354 && (next_state
>= prev_state
))
1357 index
[0] = on
->ospf6_if
->interface
->ifindex
;
1358 index
[1] = on
->ospf6_if
->instance_id
;
1359 index
[2] = ntohl(on
->router_id
);
1361 smux_trap(ospfv3_variables
, array_size(ospfv3_variables
),
1362 ospfv3_trap_oid
, array_size(ospfv3_trap_oid
), ospfv3_oid
,
1363 sizeof ospfv3_oid
/ sizeof(oid
), index
, 3, ospf6NbrTrapList
,
1364 array_size(ospf6NbrTrapList
), NBRSTATECHANGE
);
1368 static int ospf6TrapIfStateChange(struct ospf6_interface
*oi
, int next_state
,
1373 /* Terminal state or regression */
1374 if ((next_state
!= OSPF6_INTERFACE_POINTTOPOINT
)
1375 && (next_state
!= OSPF6_INTERFACE_DROTHER
)
1376 && (next_state
!= OSPF6_INTERFACE_BDR
)
1377 && (next_state
!= OSPF6_INTERFACE_DR
) && (next_state
>= prev_state
))
1380 index
[0] = oi
->interface
->ifindex
;
1381 index
[1] = oi
->instance_id
;
1383 smux_trap(ospfv3_variables
, array_size(ospfv3_variables
),
1384 ospfv3_trap_oid
, array_size(ospfv3_trap_oid
), ospfv3_oid
,
1385 sizeof ospfv3_oid
/ sizeof(oid
), index
, 2, ospf6IfTrapList
,
1386 array_size(ospf6IfTrapList
), IFSTATECHANGE
);
1390 /* Register OSPFv3-MIB. */
1391 static int ospf6_snmp_init(struct thread_master
*master
)
1394 REGISTER_MIB("OSPFv3MIB", ospfv3_variables
, variable
, ospfv3_oid
);
1398 static int ospf6_snmp_module_init(void)
1400 hook_register(ospf6_interface_change
, ospf6TrapIfStateChange
);
1401 hook_register(ospf6_neighbor_change
, ospf6TrapNbrStateChange
);
1402 hook_register(frr_late_init
, ospf6_snmp_init
);
1406 FRR_MODULE_SETUP(.name
= "ospf6d_snmp", .version
= FRR_VERSION
,
1407 .description
= "ospf6d AgentX SNMP module",
1408 .init
= ospf6_snmp_module_init
, )