1 // SPDX-License-Identifier: GPL-2.0-or-later
4 * Copyright (C) 2020 Volta Networks, Inc.
8 * This is minimal read-only implementations providing
9 * mplsLdpModuleReadOnlyCompliance as described in RFC 3815.
14 #include <net-snmp/net-snmp-config.h>
15 #include <net-snmp/net-snmp-includes.h>
26 #include "lib/version.h"
30 /* SNMP value hack. */
31 #define COUNTER32 ASN_COUNTER
32 #define INTEGER ASN_INTEGER
33 #define UNSIGNED32 ASN_GAUGE
34 #define TIMESTAMP ASN_TIMETICKS
35 #define TIMETICKS ASN_TIMETICKS
36 #define STRING ASN_OCTET_STR
37 #define IPADDRESS ASN_IPADDRESS
39 #define LDP_LSRID_IDX_LEN 6
40 #define LDP_ENTITY_IDX_LEN 1
41 #define LDP_ADJACENCY_IDX_LEN 1
43 /* MPLS-LDP-STD-MIB. */
44 #define MPLS_LDP_STD_MIB 1, 3, 6, 1, 2, 1, 10, 166, 4
46 #define MPLS_LDP_LSR_ID 0
47 #define MPLS_LDP_LSR_LOOP_DETECTION_CAPABLE 0
48 #define MPLS_LDP_ENTITY_LAST_CHANGE 0
49 #define MPLS_LDP_ENTITY_INDEX_NEXT 0
51 /* Declare static local variables for convenience. */
54 /* LDP-MIB instances. */
55 static oid ldp_oid
[] = {MPLS_LDP_STD_MIB
};
56 static oid ldp_trap_oid
[] = {MPLS_LDP_STD_MIB
, 0};
58 static uint8_t snmp_ldp_rtrid
[6] = {0, 0, 0, 0, 0};
60 #define LDP_DEFAULT_ENTITY_INDEX 1
62 #define MPLSLDPLSRLOOPDETECTIONCAPABLE_NONE 1
63 #define MPLSLDPLSRLOOPDETECTIONCAPABLE_OTHER 2
64 #define MPLSLDPLSRLOOPDETECTIONCAPABLE_HOPCOUNT 3
65 #define MPLSLDPLSRLOOPDETECTIONCAPABLE_PATHVECTOR 4
66 #define MPLSLDPLSRLOOPDETECTIONCAPABLE_HOPCOUNTANDPATHVECTOR 5
68 /* MPLS LDP mplsLdpHelloAdjacencyTable. */
69 #define MPLSLDPHELLOADJACENCYINDEX 1
70 #define MPLSLDPHELLOADJACENCYHOLDTIMEREM 2
71 #define MPLSLDPHELLOADJACENCYHOLDTIME 3
72 #define MPLSLDPHELLOADJACENCYTYPE 4
74 /* enums for column mplsLdpHelloAdjacencyType */
75 #define MPLSLDPHELLOADJACENCYTYPE_LINK 1
76 #define MPLSLDPHELLOADJACENCYTYPE_TARGETED 2
78 #define MPLSLDPPEERTRANSPORTADDRTYPE_UNKNOWN 0
79 #define MPLSLDPPEERTRANSPORTADDRTYPE_IPV4 1
80 #define MPLSLDPPEERTRANSPORTADDRTYPE_IPV6 2
81 #define MPLSLDPPEERTRANSPORTADDRTYPE_IPV4Z 3
82 #define MPLSLDPPEERTRANSPORTADDRTYPE_IPV6Z 4
83 #define MPLSLDPPEERTRANSPORTADDRTYPE_DNS 16
85 #define DOWNSTREAMONDEMAND 1
86 #define DOWNSTREAMUNSOLICITED 2
88 #define CONSERVATIVERETENTION 1
89 #define LIBERALRETENTION 2
91 #define TRANSPORTADDRINTERFACE 1
92 #define TRANSPORTADDRLOOPBACK 2
94 #define LABELTYPEGENERIC 1
96 #define STORAGETYPENONVOLATILE 3
98 #define ROWSTATUSACTIVE 4
100 #define ADMINSTATUSENABLED 1
102 #define OPERSTATUSENABLED 2
104 /* MPLS LDP mplsLdpPeerTable */
105 #define MPLSLDPPEERLDPID 1
106 #define MPLSLDPPEERLABELDISTMETHOD 2
107 #define MPLSLDPPEERPATHVECTORLIMIT 3
108 #define MPLSLDPPEERTRANSPORTADDRTYPE 4
109 #define MPLSLDPPEERTRANSPORTADDR 5
111 #define MPLSLDPSESSIONROLE_UNKNOWN 1
112 #define MPLSLDPSESSIONROLE_ACTIVE 2
113 #define MPLSLDPSESSIONROLE_PASSIVE 3
115 #define MPLSLDPSESSIONSTATE_NONEXISTENT 1
116 #define MPLSLDPSESSIONSTATE_INITIALIZED 2
117 #define MPLSLDPSESSIONSTATE_OPENREC 3
118 #define MPLSLDPSESSIONSTATE_OPENSENT 4
119 #define MPLSLDPSESSIONSTATE_OPERATIONAL 5
121 /* MPLS LDP mplsLdpSessionTable */
122 #define MPLSLDPSESSIONSTATELASTCHANGE 1
123 #define MPLSLDPSESSIONSTATE 2
124 #define MPLSLDPSESSIONROLE 3
125 #define MPLSLDPSESSIONPROTOCOLVERSION 4
126 #define MPLSLDPSESSIONKEEPALIVEHOLDTIMEREM 5
127 #define MPLSLDPSESSIONKEEPALIVETIME 6
128 #define MPLSLDPSESSIONMAXPDULENGTH 7
129 #define MPLSLDPSESSIONDISCONTINUITYTIME 8
131 /* MPLS LDP mplsLdpEntityTable */
132 #define MPLSLDPENTITYLDPID 1
133 #define MPLSLDPENTITYINDEX 2
134 #define MPLSLDPENTITYPROTOCOLVERSION 3
135 #define MPLSLDPENTITYADMINSTATUS 4
136 #define MPLSLDPENTITYOPERSTATUS 5
137 #define MPLSLDPENTITYTCPPORT 6
138 #define MPLSLDPENTITYUDPDSCPORT 7
139 #define MPLSLDPENTITYMAXPDULENGTH 8
140 #define MPLSLDPENTITYKEEPALIVEHOLDTIMER 9
141 #define MPLSLDPENTITYHELLOHOLDTIMER 10
142 #define MPLSLDPENTITYINITSESSIONTHRESHOLD 11
143 #define MPLSLDPENTITYLABELDISTMETHOD 12
144 #define MPLSLDPENTITYLABELRETENTIONMODE 13
145 #define MPLSLDPENTITYPATHVECTORLIMIT 14
146 #define MPLSLDPENTITYHOPCOUNTLIMIT 15
147 #define MPLSLDPENTITYTRANSPORTADDRKIND 16
148 #define MPLSLDPENTITYTARGETPEER 17
149 #define MPLSLDPENTITYTARGETPEERADDRTYPE 18
150 #define MPLSLDPENTITYTARGETPEERADDR 19
151 #define MPLSLDPENTITYLABELTYPE 20
152 #define MPLSLDPENTITYDISCONTINUITYTIME 21
153 #define MPLSLDPENTITYSTORAGETYPE 22
154 #define MPLSLDPENTITYROWSTATUS 23
156 /* MPLS LDP mplsLdpEntityStatsTable */
157 #define MPLSLDPENTITYSTATSSESSIONATTEMPTS 1
158 #define MPLSLDPENTITYSTATSSESSIONREJHELLO 2
159 #define MPLSLDPENTITYSTATSSESSIONREJAD 3
160 #define MPLSLDPENTITYSTATSSESSIONREJMAXPDU 4
161 #define MPLSLDPENTITYSTATSSESSIONREJLR 5
162 #define MPLSLDPENTITYSTATSBADLDPID 6
163 #define MPLSLDPENTITYSTATSBADPDULENGTH 7
164 #define MPLSLDPENTITYSTATSBADMSGLENGTH 8
165 #define MPLSLDPENTITYSTATSBADTLVLENGTH 9
166 #define MPLSLDPENTITYSTATSMALFORMEDTLV 10
167 #define MPLSLDPENTITYSTATSKEEPALIVEEXP 11
168 #define MPLSLDPENTITYSTATSSHUTDOWNRCVNOTIFY 12
169 #define MPLSLDPENTITYSTATSSHUTDOWNSENTNOTIFY 13
171 #define MPLSLDPSESSIONSTATSUNKNOWNMESTYPEERRORS 1
172 #define MPLSLDPSESSIONSTATSUNKNOWNTLVERRORS 2
174 static uint8_t *ldpLsrId(struct variable
*v
, oid name
[], size_t *length
,
175 int exact
, size_t *var_len
,
176 WriteMethod
**write_method
)
178 if (smux_header_generic(v
, name
, length
, exact
, var_len
, write_method
)
183 return (uint8_t *)&leconf
->rtr_id
.s_addr
;
186 static uint8_t *ldpLoopDetectCap(struct variable
*v
, oid name
[], size_t *length
,
187 int exact
, size_t *var_len
,
188 WriteMethod
**write_method
)
190 if (smux_header_generic(v
, name
, length
, exact
, var_len
, write_method
)
194 return SNMP_INTEGER(MPLSLDPLSRLOOPDETECTIONCAPABLE_NONE
);
197 extern uint32_t ldp_start_time
;
198 static uint8_t *ldpEntityLastChange(struct variable
*v
, oid name
[],
200 int exact
, size_t *var_len
,
201 WriteMethod
**write_method
)
203 if (smux_header_generic(v
, name
, length
, exact
, var_len
, write_method
)
207 *var_len
= sizeof(time_t);
208 return (uint8_t *) &(leconf
->config_change_time
);
212 static uint8_t *ldpEntityIndexNext(struct variable
*v
, oid name
[],
213 size_t *length
,int exact
, size_t *var_len
,
214 WriteMethod
**write_method
)
216 if (smux_header_generic(v
, name
, length
, exact
, var_len
, write_method
)
220 return SNMP_INTEGER(0);
223 #define LDP_ENTITY_TOTAL_LEN 21
224 #define LDP_ENTITY_MAX_IDX_LEN 6
226 static struct ldpd_af_conf
*ldpEntityTable_lookup(struct variable
*v
, oid
*name
,
227 size_t *length
, int exact
,
231 struct ldpd_af_conf
*af_v4
, *af_v6
;
233 af_v4
= &leconf
->ipv4
;
234 af_v6
= &leconf
->ipv6
;
237 if (*length
!= LDP_ENTITY_TOTAL_LEN
)
240 if (leconf
->trans_pref
== DUAL_STACK_LDPOV6
&&
241 af_v6
->flags
& F_LDPD_AF_ENABLED
) {
249 /* only support one router id so can just skip */
250 len
= *length
- v
->namelen
- LDP_ENTITY_MAX_IDX_LEN
;
252 if (leconf
->trans_pref
== DUAL_STACK_LDPOV6
&&
253 af_v6
->flags
& F_LDPD_AF_ENABLED
) {
265 static uint8_t *ldpEntityTable(struct variable
*v
, oid name
[], size_t *length
,
266 int exact
, size_t *var_len
,
267 WriteMethod
**write_method
)
269 struct ldpd_af_conf
*af
;
270 struct in_addr entityLdpId
= {.s_addr
= 0};
273 *write_method
= NULL
;
275 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
279 af
= ldpEntityTable_lookup(v
, name
, length
, exact
, &index
);
284 entityLdpId
.s_addr
= ldp_rtr_id_get(leconf
);
286 /* Copy the name out */
287 memcpy(name
, v
->name
, v
->namelen
* sizeof(oid
));
290 *length
= LDP_ENTITY_TOTAL_LEN
;
291 oid_copy_in_addr(name
+ v
->namelen
, &entityLdpId
);
292 name
[v
->namelen
+ 4] = 0;
293 name
[v
->namelen
+ 5] = 0;
294 name
[v
->namelen
+ 6] = LDP_DEFAULT_ENTITY_INDEX
;
297 /* Return the current value of the variable */
299 case MPLSLDPENTITYLDPID
:
301 memcpy (snmp_ldp_rtrid
, &entityLdpId
, IN_ADDR_SIZE
);
302 return (uint8_t *)snmp_ldp_rtrid
;
303 case MPLSLDPENTITYINDEX
:
304 return SNMP_INTEGER(LDP_DEFAULT_ENTITY_INDEX
);
305 case MPLSLDPENTITYPROTOCOLVERSION
:
306 return SNMP_INTEGER(LDP_VERSION
);
307 case MPLSLDPENTITYADMINSTATUS
:
308 return SNMP_INTEGER(ADMINSTATUSENABLED
);
309 case MPLSLDPENTITYOPERSTATUS
:
310 return SNMP_INTEGER(OPERSTATUSENABLED
);
311 case MPLSLDPENTITYTCPPORT
:
312 return SNMP_INTEGER(LDP_PORT
);
313 case MPLSLDPENTITYUDPDSCPORT
:
314 return SNMP_INTEGER(LDP_PORT
);
315 case MPLSLDPENTITYMAXPDULENGTH
:
316 return SNMP_INTEGER(LDP_MAX_LEN
);
317 case MPLSLDPENTITYKEEPALIVEHOLDTIMER
:
318 return SNMP_INTEGER(af
->keepalive
);
319 case MPLSLDPENTITYHELLOHOLDTIMER
:
320 return SNMP_INTEGER(af
->lhello_holdtime
);
321 case MPLSLDPENTITYINITSESSIONTHRESHOLD
:
322 return SNMP_INTEGER(0); /* not supported */
323 case MPLSLDPENTITYLABELDISTMETHOD
:
324 return SNMP_INTEGER(DOWNSTREAMUNSOLICITED
);
325 case MPLSLDPENTITYLABELRETENTIONMODE
:
326 return SNMP_INTEGER(LIBERALRETENTION
);
327 case MPLSLDPENTITYPATHVECTORLIMIT
:
328 return SNMP_INTEGER(0); /* not supported */
329 case MPLSLDPENTITYHOPCOUNTLIMIT
:
330 return SNMP_INTEGER(0);
331 case MPLSLDPENTITYTRANSPORTADDRKIND
:
332 return SNMP_INTEGER(TRANSPORTADDRLOOPBACK
);
333 case MPLSLDPENTITYTARGETPEER
:
334 return SNMP_INTEGER(1);
335 case MPLSLDPENTITYTARGETPEERADDRTYPE
:
337 return SNMP_INTEGER(MPLSLDPPEERTRANSPORTADDRTYPE_IPV4
);
339 return SNMP_INTEGER(MPLSLDPPEERTRANSPORTADDRTYPE_IPV6
);
340 case MPLSLDPENTITYTARGETPEERADDR
:
342 *var_len
= sizeof(af
->trans_addr
.v4
);
343 return ((uint8_t *)&af
->trans_addr
.v4
);
345 *var_len
= sizeof(af
->trans_addr
.v6
);
346 return ((uint8_t *)&af
->trans_addr
.v6
);
348 case MPLSLDPENTITYLABELTYPE
:
349 return SNMP_INTEGER(LABELTYPEGENERIC
);
350 case MPLSLDPENTITYDISCONTINUITYTIME
:
351 return SNMP_INTEGER(0);
352 case MPLSLDPENTITYSTORAGETYPE
:
353 return SNMP_INTEGER(STORAGETYPENONVOLATILE
);
354 case MPLSLDPENTITYROWSTATUS
:
355 return SNMP_INTEGER(ROWSTATUSACTIVE
);
363 static uint8_t *ldpEntityStatsTable(struct variable
*v
, oid name
[],
364 size_t *length
, int exact
, size_t *var_len
,
365 WriteMethod
**write_method
)
367 struct in_addr entityLdpId
= {.s_addr
= 0};
370 *write_method
= NULL
;
372 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
377 if (*length
!= LDP_ENTITY_TOTAL_LEN
)
380 len
= *length
- v
->namelen
- LDP_ENTITY_MAX_IDX_LEN
;
384 entityLdpId
.s_addr
= ldp_rtr_id_get(leconf
);
386 /* Copy the name out */
387 memcpy(name
, v
->name
, v
->namelen
* sizeof(oid
));
390 *length
= LDP_ENTITY_TOTAL_LEN
;
391 oid_copy_in_addr(name
+ v
->namelen
, &entityLdpId
);
392 name
[v
->namelen
+ 4] = 0;
393 name
[v
->namelen
+ 5] = 0;
394 name
[v
->namelen
+ 6] = LDP_DEFAULT_ENTITY_INDEX
;
397 /* Return the current value of the variable */
399 case MPLSLDPENTITYSTATSSESSIONATTEMPTS
:
400 return SNMP_INTEGER(leconf
->stats
.session_attempts
);
401 case MPLSLDPENTITYSTATSSESSIONREJHELLO
:
402 return SNMP_INTEGER(leconf
->stats
.session_rejects_hello
);
403 case MPLSLDPENTITYSTATSSESSIONREJAD
:
404 return SNMP_INTEGER(leconf
->stats
.session_rejects_ad
);
405 case MPLSLDPENTITYSTATSSESSIONREJMAXPDU
:
406 return SNMP_INTEGER(leconf
->stats
.session_rejects_max_pdu
);
407 case MPLSLDPENTITYSTATSSESSIONREJLR
:
408 return SNMP_INTEGER(leconf
->stats
.session_rejects_lr
);
409 case MPLSLDPENTITYSTATSBADLDPID
:
410 return SNMP_INTEGER(leconf
->stats
.bad_ldp_id
);
411 case MPLSLDPENTITYSTATSBADPDULENGTH
:
412 return SNMP_INTEGER(leconf
->stats
.bad_pdu_len
);
413 case MPLSLDPENTITYSTATSBADMSGLENGTH
:
414 return SNMP_INTEGER(leconf
->stats
.bad_msg_len
);
415 case MPLSLDPENTITYSTATSBADTLVLENGTH
:
416 return SNMP_INTEGER(leconf
->stats
.bad_tlv_len
);
417 case MPLSLDPENTITYSTATSMALFORMEDTLV
:
418 return SNMP_INTEGER(leconf
->stats
.malformed_tlv
);
419 case MPLSLDPENTITYSTATSKEEPALIVEEXP
:
420 return SNMP_INTEGER(leconf
->stats
.keepalive_timer_exp
);
421 case MPLSLDPENTITYSTATSSHUTDOWNRCVNOTIFY
:
422 return SNMP_INTEGER(leconf
->stats
.shutdown_rcv_notify
);
423 case MPLSLDPENTITYSTATSSHUTDOWNSENTNOTIFY
:
424 return SNMP_INTEGER(leconf
->stats
.shutdown_send_notify
);
432 #define LDP_ADJACENCY_ENTRY_MAX_IDX_LEN 14
434 static void ldpHelloAdjacencyTable_oid_to_index(
435 struct variable
*v
, oid name
[],
437 struct in_addr
*entityLdpId
,
438 uint32_t *entityIndex
,
439 struct in_addr
*peerLdpId
,
440 uint32_t *adjacencyIndex
)
442 oid
*offset
= name
+ v
->namelen
;
443 int offsetlen
= *length
- v
->namelen
;
446 if (len
> LDP_ADJACENCY_ENTRY_MAX_IDX_LEN
)
447 len
= LDP_ADJACENCY_ENTRY_MAX_IDX_LEN
;
449 if (len
>= LDP_LSRID_IDX_LEN
)
450 oid2in_addr(offset
, sizeof(struct in_addr
), entityLdpId
);
452 offset
+= LDP_LSRID_IDX_LEN
;
453 offsetlen
-= LDP_LSRID_IDX_LEN
;
456 if (len
> LDP_ENTITY_IDX_LEN
)
457 len
= LDP_ENTITY_IDX_LEN
;
459 if (len
>= LDP_ENTITY_IDX_LEN
)
460 *entityIndex
= offset
[0];
462 offset
+= LDP_ENTITY_IDX_LEN
;
463 offsetlen
-= LDP_ENTITY_IDX_LEN
;
466 if (len
> LDP_LSRID_IDX_LEN
)
467 len
= LDP_LSRID_IDX_LEN
;
469 if (len
>= LDP_LSRID_IDX_LEN
)
470 oid2in_addr(offset
, sizeof(struct in_addr
), peerLdpId
);
472 offset
+= LDP_LSRID_IDX_LEN
;
473 offsetlen
-= LDP_LSRID_IDX_LEN
;
476 if (len
> LDP_ADJACENCY_IDX_LEN
)
477 len
= LDP_ADJACENCY_IDX_LEN
;
479 if (len
>= LDP_ADJACENCY_IDX_LEN
)
480 *adjacencyIndex
= offset
[0];
484 nbr_get_adj_by_index(struct nbr
*nbr
, uint32_t adjacencyIndex
)
489 RB_FOREACH(adj
, nbr_adj_head
, &nbr
->adj_tree
)
490 if (++i
== adjacencyIndex
)
496 static struct ctl_adj
*
497 ldpHelloAdjacencyTable_lookup_helper(
498 struct in_addr
*entityLdpId
,
499 uint32_t *entityIndex
,
500 struct in_addr
*peerLdpId
,
501 uint32_t *adjacencyIndex
)
503 struct ctl_adj
*ctl_adj
= NULL
;
504 struct adj
*adj
= NULL
;
505 struct nbr
*cur_nbr
= nbr_find_ldpid(peerLdpId
->s_addr
);
508 /* If found nbr, then look to see if the
511 adj
= nbr_get_adj_by_index(cur_nbr
, *adjacencyIndex
);
514 ctl_adj
= adj_to_ctl(adj
);
519 static struct ctl_adj
*
520 ldpHelloAdjacencyTable_next_helper(
522 struct in_addr
*entityLdpId
,
523 uint32_t *entityIndex
,
524 struct in_addr
*peerLdpId
,
525 uint32_t *adjacencyIndex
)
527 struct ctl_adj
*ctl_adj
= NULL
;
528 struct nbr
*nbr
= NULL
;
529 struct adj
*adj
= NULL
;
532 nbr
= nbr_get_first_ldpid();
534 struct nbr
*cur_nbr
= nbr_find_ldpid(peerLdpId
->s_addr
);
536 /* If found nbr, then look to see if the
539 adj
= nbr_get_adj_by_index(cur_nbr
, *adjacencyIndex
+ 1);
541 *adjacencyIndex
+= 1;
543 nbr
= nbr_get_next_ldpid(peerLdpId
->s_addr
);
547 adj
= RB_MIN(nbr_adj_head
, &nbr
->adj_tree
);
552 ctl_adj
= adj_to_ctl(adj
);
557 #define HELLO_ADJ_MAX_IDX_LEN 14
559 static struct ctl_adj
*
560 ldpHelloAdjacencyTable_lookup(struct variable
*v
, oid name
[],
561 size_t *length
, int exact
,
562 struct in_addr
*entityLdpId
,
563 uint32_t *entityIndex
,
564 struct in_addr
*peerLdpId
,
565 uint32_t *adjacencyIndex
)
567 struct ctl_adj
*hello_adj
= NULL
;
570 if (*length
< HELLO_ADJ_MAX_IDX_LEN
)
573 ldpHelloAdjacencyTable_oid_to_index(
575 entityLdpId
, entityIndex
, peerLdpId
, adjacencyIndex
);
577 hello_adj
= ldpHelloAdjacencyTable_lookup_helper(
578 entityLdpId
, entityIndex
, peerLdpId
, adjacencyIndex
);
581 int offsetlen
= *length
- v
->namelen
;
583 if (offsetlen
< HELLO_ADJ_MAX_IDX_LEN
)
586 ldpHelloAdjacencyTable_oid_to_index(
588 entityLdpId
, entityIndex
, peerLdpId
, adjacencyIndex
);
590 hello_adj
= ldpHelloAdjacencyTable_next_helper(first
,
591 entityLdpId
, entityIndex
, peerLdpId
, adjacencyIndex
);
597 static uint8_t *ldpHelloAdjacencyTable(struct variable
*v
, oid name
[], size_t *length
,
598 int exact
, size_t *var_len
,
599 WriteMethod
**write_method
)
601 struct in_addr entityLdpId
= {.s_addr
= 0};
602 uint32_t entityIndex
= 0;
603 struct in_addr peerLdpId
= {.s_addr
= 0};
604 uint32_t adjacencyIndex
= 0;
606 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
610 struct ctl_adj
*ctl_adj
= ldpHelloAdjacencyTable_lookup(v
, name
,
612 &entityLdpId
, &entityIndex
, &peerLdpId
, &adjacencyIndex
);
619 /* Copy the name out */
620 memcpy(name
, v
->name
, v
->namelen
* sizeof(oid
));
623 struct in_addr entityLdpId
= {.s_addr
= 0};
624 entityLdpId
.s_addr
= ldp_rtr_id_get(leconf
);
626 struct in_addr peerLdpId
= ctl_adj
->id
;
628 oid_copy_in_addr(name
+ v
->namelen
, &entityLdpId
);
629 name
[v
->namelen
+ 4] = 0;
630 name
[v
->namelen
+ 5] = 0;
631 name
[v
->namelen
+ 6] = LDP_DEFAULT_ENTITY_INDEX
;
632 oid_copy_in_addr(name
+ v
->namelen
+ 7, &peerLdpId
);
633 name
[v
->namelen
+ 11] = 0;
634 name
[v
->namelen
+ 12] = 0;
635 name
[v
->namelen
+ 13] = adjacencyIndex
;
638 *length
= v
->namelen
+ HELLO_ADJ_MAX_IDX_LEN
;
642 case MPLSLDPHELLOADJACENCYINDEX
:
643 return SNMP_INTEGER(adjacencyIndex
);
644 case MPLSLDPHELLOADJACENCYHOLDTIMEREM
:
645 return SNMP_INTEGER(ctl_adj
->holdtime_remaining
);
646 case MPLSLDPHELLOADJACENCYHOLDTIME
:
647 return SNMP_INTEGER(ctl_adj
->holdtime
);
648 case MPLSLDPHELLOADJACENCYTYPE
:
649 if (ctl_adj
->type
== HELLO_LINK
)
650 return SNMP_INTEGER(MPLSLDPHELLOADJACENCYTYPE_LINK
);
651 return SNMP_INTEGER(MPLSLDPHELLOADJACENCYTYPE_TARGETED
);
659 #define LDP_LSRID_IDX_LEN 6
660 #define LDP_ENTITY_IDX_LEN 1
661 #define LDP_PEER_ENTRY_MAX_IDX_LEN 13
663 static void ldpPeerTable_oid_to_index(
664 struct variable
*v
, oid name
[],
666 struct in_addr
*entityLdpId
,
667 uint32_t *entityIndex
,
668 struct in_addr
*peerLdpId
)
670 oid
*offset
= name
+ v
->namelen
;
671 int offsetlen
= *length
- v
->namelen
;
674 if (len
> LDP_PEER_ENTRY_MAX_IDX_LEN
)
675 len
= LDP_PEER_ENTRY_MAX_IDX_LEN
;
677 if (len
>= LDP_LSRID_IDX_LEN
)
678 oid2in_addr(offset
, sizeof(struct in_addr
), entityLdpId
);
680 offset
+= LDP_LSRID_IDX_LEN
;
681 offsetlen
-= LDP_LSRID_IDX_LEN
;
684 if (len
> LDP_ENTITY_IDX_LEN
)
685 len
= LDP_ENTITY_IDX_LEN
;
687 if (len
>= LDP_ENTITY_IDX_LEN
)
688 *entityIndex
= offset
[0];
690 offset
+= LDP_ENTITY_IDX_LEN
;
691 offsetlen
-= LDP_ENTITY_IDX_LEN
;
694 if (len
> LDP_LSRID_IDX_LEN
)
695 len
= LDP_LSRID_IDX_LEN
;
697 if (len
>= LDP_LSRID_IDX_LEN
)
698 oid2in_addr(offset
, sizeof(struct in_addr
), peerLdpId
);
701 static struct ctl_nbr
*
702 ldpPeerTable_lookup_next(int first
,
703 struct in_addr peerLdpId
)
705 struct nbr
*nbr
= NULL
;
706 struct ctl_nbr
*ctl_nbr
= NULL
;;
709 nbr
= nbr_get_first_ldpid();
711 nbr
= nbr_get_next_ldpid(peerLdpId
.s_addr
);
714 ctl_nbr
= nbr_to_ctl(nbr
);
719 static struct ctl_nbr
*
720 ldpPeerTable_lookup(struct variable
*v
, oid name
[],
721 size_t *length
, int exact
,
722 struct in_addr
*entityLdpId
,
723 uint32_t *entityIndex
,
724 struct in_addr
*peerLdpId
)
726 struct ctl_nbr
*ctl_nbr
= NULL
;
727 struct nbr
*nbr
= NULL
;
731 if (*length
< (long unsigned int)v
->namelen
732 + LDP_PEER_ENTRY_MAX_IDX_LEN
)
735 ldpPeerTable_oid_to_index(
737 entityLdpId
, entityIndex
, peerLdpId
);
739 nbr
= nbr_find_ldpid(peerLdpId
->s_addr
);
741 ctl_nbr
= nbr_to_ctl(nbr
);
746 int offsetlen
= *length
- v
->namelen
;
747 if (offsetlen
< LDP_LSRID_IDX_LEN
)
750 ldpPeerTable_oid_to_index(
752 entityLdpId
, entityIndex
, peerLdpId
);
754 ctl_nbr
= ldpPeerTable_lookup_next(first
, *peerLdpId
);
760 static uint8_t *ldpPeerTable(struct variable
*v
, oid name
[], size_t *length
,
761 int exact
, size_t *var_len
,
762 WriteMethod
**write_method
)
764 struct in_addr entityLdpId
= {.s_addr
= 0};
765 uint32_t entityIndex
= 0;
766 struct in_addr peerLdpId
= {.s_addr
= 0};
767 struct ctl_nbr
*ctl_nbr
;
770 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
774 ctl_nbr
= ldpPeerTable_lookup(v
, name
, length
, exact
, &entityLdpId
,
775 &entityIndex
, &peerLdpId
);
782 entityLdpId
.s_addr
= ldp_rtr_id_get(leconf
);
783 entityIndex
= LDP_DEFAULT_ENTITY_INDEX
;
784 peerLdpId
= ctl_nbr
->id
;
786 /* Copy the name out */
787 memcpy(name
, v
->name
, v
->namelen
* sizeof(oid
));
790 oid_copy_in_addr(name
+ v
->namelen
, &entityLdpId
);
792 name
[v
->namelen
+ 4] = 0;
793 name
[v
->namelen
+ 5] = 0;
794 name
[v
->namelen
+ 6] = entityIndex
;
795 oid_copy_in_addr(name
+ v
->namelen
+ 7, &peerLdpId
);
796 name
[v
->namelen
+ 11] = 0;
797 name
[v
->namelen
+ 12] = 0;
800 *length
= v
->namelen
+ LDP_PEER_ENTRY_MAX_IDX_LEN
;
804 case MPLSLDPPEERLDPID
:
806 memcpy(snmp_ldp_rtrid
, &ctl_nbr
->id
, IN_ADDR_SIZE
);
807 return snmp_ldp_rtrid
;
808 case MPLSLDPPEERLABELDISTMETHOD
:
809 return SNMP_INTEGER(DOWNSTREAMUNSOLICITED
);
810 case MPLSLDPPEERPATHVECTORLIMIT
:
811 return SNMP_INTEGER(0);
812 case MPLSLDPPEERTRANSPORTADDRTYPE
:
813 if (ctl_nbr
->af
== AF_INET
)
814 return SNMP_INTEGER(MPLSLDPPEERTRANSPORTADDRTYPE_IPV4
);
816 return SNMP_INTEGER(MPLSLDPPEERTRANSPORTADDRTYPE_IPV6
);
817 case MPLSLDPPEERTRANSPORTADDR
:
818 if (ctl_nbr
->af
== AF_INET
) {
819 *var_len
= sizeof(ctl_nbr
->raddr
.v4
);
820 return ((uint8_t *)&ctl_nbr
->raddr
.v4
);
822 *var_len
= sizeof(ctl_nbr
->raddr
.v6
);
823 return ((uint8_t *)&ctl_nbr
->raddr
.v6
);
831 static uint8_t *ldpSessionTable(struct variable
*v
, oid name
[], size_t *length
,
832 int exact
, size_t *var_len
,
833 WriteMethod
**write_method
)
835 struct in_addr entityLdpId
= {.s_addr
= 0};
836 uint32_t entityIndex
= 0;
837 struct in_addr peerLdpId
= {.s_addr
= 0};
838 struct ctl_nbr
*ctl_nbr
;
840 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
844 ctl_nbr
= ldpPeerTable_lookup(v
, name
, length
, exact
, &entityLdpId
,
845 &entityIndex
, &peerLdpId
);
851 entityLdpId
.s_addr
= ldp_rtr_id_get(leconf
);
852 entityIndex
= LDP_DEFAULT_ENTITY_INDEX
;
853 peerLdpId
= ctl_nbr
->id
;
855 /* Copy the name out */
856 memcpy(name
, v
->name
, v
->namelen
* sizeof(oid
));
859 oid_copy_in_addr(name
+ v
->namelen
, &entityLdpId
);
861 name
[v
->namelen
+ 4] = 0;
862 name
[v
->namelen
+ 5] = 0;
863 name
[v
->namelen
+ 6] = entityIndex
;
864 oid_copy_in_addr(name
+ v
->namelen
+ 7, &peerLdpId
);
865 name
[v
->namelen
+ 11] = 0;
866 name
[v
->namelen
+ 12] = 0;
869 *length
= v
->namelen
+ LDP_PEER_ENTRY_MAX_IDX_LEN
;
873 case MPLSLDPSESSIONSTATELASTCHANGE
:
874 *var_len
= sizeof(time_t);
875 return (uint8_t *) &(ctl_nbr
->uptime
);
876 case MPLSLDPSESSIONSTATE
:
877 switch (ctl_nbr
->nbr_state
) {
878 case NBR_STA_INITIAL
:
879 return SNMP_INTEGER(MPLSLDPSESSIONSTATE_INITIALIZED
);
880 case NBR_STA_OPENREC
:
881 return SNMP_INTEGER(MPLSLDPSESSIONSTATE_OPENREC
);
882 case NBR_STA_OPENSENT
:
883 return SNMP_INTEGER(MPLSLDPSESSIONSTATE_OPENSENT
);
885 return SNMP_INTEGER(MPLSLDPSESSIONSTATE_OPERATIONAL
);
887 return SNMP_INTEGER(MPLSLDPSESSIONSTATE_NONEXISTENT
);
889 case MPLSLDPSESSIONROLE
:
890 if (ldp_addrcmp(ctl_nbr
->af
, &ctl_nbr
->laddr
, &ctl_nbr
->raddr
)
892 return SNMP_INTEGER(MPLSLDPSESSIONROLE_ACTIVE
);
894 return SNMP_INTEGER(MPLSLDPSESSIONROLE_PASSIVE
);
895 case MPLSLDPSESSIONPROTOCOLVERSION
:
896 return SNMP_INTEGER(LDP_VERSION
);
897 case MPLSLDPSESSIONKEEPALIVEHOLDTIMEREM
:
898 return SNMP_INTEGER(ctl_nbr
->hold_time_remaining
);
899 case MPLSLDPSESSIONKEEPALIVETIME
:
900 return SNMP_INTEGER(ctl_nbr
->holdtime
);
901 case MPLSLDPSESSIONMAXPDULENGTH
:
902 if (ctl_nbr
->nbr_state
== NBR_STA_OPER
)
903 return SNMP_INTEGER(ctl_nbr
->max_pdu_len
);
905 return SNMP_INTEGER(LDP_MAX_LEN
);
906 case MPLSLDPSESSIONDISCONTINUITYTIME
:
907 return SNMP_INTEGER(0); /* not supported */
915 static uint8_t *ldpSessionStatsTable(struct variable
*v
, oid name
[],
917 int exact
, size_t *var_len
,
918 WriteMethod
**write_method
)
920 struct in_addr entityLdpId
= {.s_addr
= 0};
921 uint32_t entityIndex
= 0;
922 struct in_addr peerLdpId
= {.s_addr
= 0};
924 if (smux_header_table(v
, name
, length
, exact
, var_len
, write_method
)
928 struct ctl_nbr
*ctl_nbr
= ldpPeerTable_lookup(v
, name
, length
, exact
,
929 &entityLdpId
, &entityIndex
, &peerLdpId
);
935 entityLdpId
.s_addr
= ldp_rtr_id_get(leconf
);
936 entityIndex
= LDP_DEFAULT_ENTITY_INDEX
;
937 peerLdpId
= ctl_nbr
->id
;
939 /* Copy the name out */
940 memcpy(name
, v
->name
, v
->namelen
* sizeof(oid
));
943 oid_copy_in_addr(name
+ v
->namelen
, &entityLdpId
);
944 name
[v
->namelen
+ 4] = 0;
945 name
[v
->namelen
+ 5] = 0;
946 name
[v
->namelen
+ 6] = entityIndex
;
947 oid_copy_in_addr(name
+ v
->namelen
+ 7, &peerLdpId
);
948 name
[v
->namelen
+ 11] = 0;
949 name
[v
->namelen
+ 12] = 0;
951 *length
= v
->namelen
+ LDP_PEER_ENTRY_MAX_IDX_LEN
;
955 case MPLSLDPSESSIONSTATSUNKNOWNMESTYPEERRORS
:
956 return SNMP_INTEGER(ctl_nbr
->stats
.unknown_msg
);
957 case MPLSLDPSESSIONSTATSUNKNOWNTLVERRORS
:
958 return SNMP_INTEGER(ctl_nbr
->stats
.unknown_tlv
);
966 static struct variable ldpe_variables
[] = {
967 {MPLS_LDP_LSR_ID
, STRING
, RONLY
, ldpLsrId
, 3, {1, 1, 1}},
968 {MPLS_LDP_LSR_LOOP_DETECTION_CAPABLE
, INTEGER
, RONLY
,
969 ldpLoopDetectCap
, 3, {1, 1, 2}},
970 {MPLS_LDP_ENTITY_LAST_CHANGE
, TIMESTAMP
, RONLY
, ldpEntityLastChange
,
972 {MPLS_LDP_ENTITY_INDEX_NEXT
, UNSIGNED32
, RONLY
, ldpEntityIndexNext
,
975 /* MPLS LDP mplsLdpEntityTable. */
976 {MPLSLDPENTITYLDPID
, STRING
, RONLY
, ldpEntityTable
,
978 {MPLSLDPENTITYINDEX
, UNSIGNED32
, RONLY
, ldpEntityTable
,
980 {MPLSLDPENTITYPROTOCOLVERSION
, UNSIGNED32
, RONLY
, ldpEntityTable
,
982 {MPLSLDPENTITYADMINSTATUS
, INTEGER
, RONLY
, ldpEntityTable
,
984 {MPLSLDPENTITYOPERSTATUS
, INTEGER
, RONLY
, ldpEntityTable
,
986 {MPLSLDPENTITYTCPPORT
, UNSIGNED32
, RONLY
, ldpEntityTable
,
988 {MPLSLDPENTITYUDPDSCPORT
, UNSIGNED32
, RONLY
, ldpEntityTable
,
990 {MPLSLDPENTITYMAXPDULENGTH
, UNSIGNED32
, RONLY
, ldpEntityTable
,
992 {MPLSLDPENTITYKEEPALIVEHOLDTIMER
, UNSIGNED32
, RONLY
, ldpEntityTable
,
994 {MPLSLDPENTITYHELLOHOLDTIMER
, UNSIGNED32
, RONLY
, ldpEntityTable
,
995 5, {1, 2, 3, 1, 10}},
996 {MPLSLDPENTITYINITSESSIONTHRESHOLD
, INTEGER
, RONLY
, ldpEntityTable
,
997 5, {1, 2, 3, 1, 11}},
998 {MPLSLDPENTITYLABELDISTMETHOD
, INTEGER
, RONLY
, ldpEntityTable
,
999 5, {1, 2, 3, 1, 12}},
1000 {MPLSLDPENTITYLABELRETENTIONMODE
, INTEGER
, RONLY
, ldpEntityTable
,
1001 5, {1, 2, 3, 1, 13}},
1002 {MPLSLDPENTITYPATHVECTORLIMIT
, INTEGER
, RONLY
, ldpEntityTable
,
1003 5, {1, 2, 3, 1, 14}},
1004 {MPLSLDPENTITYHOPCOUNTLIMIT
, INTEGER
, RONLY
, ldpEntityTable
,
1005 5, {1, 2, 3, 1, 15}},
1006 {MPLSLDPENTITYTRANSPORTADDRKIND
, INTEGER
, RONLY
, ldpEntityTable
,
1007 5, {1, 2, 3, 1, 16}},
1008 {MPLSLDPENTITYTARGETPEER
, INTEGER
, RONLY
, ldpEntityTable
,
1009 5, {1, 2, 3, 1, 17}},
1010 {MPLSLDPENTITYTARGETPEERADDRTYPE
, INTEGER
, RONLY
, ldpEntityTable
,
1011 5, {1, 2, 3, 1, 18}},
1012 {MPLSLDPENTITYTARGETPEERADDR
, STRING
, RONLY
, ldpEntityTable
,
1013 5, {1, 2, 3, 1, 19}},
1014 {MPLSLDPENTITYLABELTYPE
, INTEGER
, RONLY
, ldpEntityTable
,
1015 5, {1, 2, 3, 1, 20}},
1016 {MPLSLDPENTITYDISCONTINUITYTIME
, TIMESTAMP
, RONLY
, ldpEntityTable
,
1017 5, {1, 2, 3, 1, 21}},
1018 {MPLSLDPENTITYSTORAGETYPE
, INTEGER
, RONLY
, ldpEntityTable
,
1019 5, {1, 2, 3, 1, 22}},
1020 {MPLSLDPENTITYROWSTATUS
, INTEGER
, RONLY
, ldpEntityTable
,
1021 5, {1, 2, 3, 1, 23}},
1023 /* MPLS LDP mplsLdpEntityStatsTable. */
1024 { MPLSLDPENTITYSTATSSESSIONATTEMPTS
, COUNTER32
, RONLY
,
1025 ldpEntityStatsTable
, 5, {1, 2, 4, 1, 1}},
1026 { MPLSLDPENTITYSTATSSESSIONREJHELLO
, COUNTER32
, RONLY
,
1027 ldpEntityStatsTable
, 5, {1, 2, 4, 1, 2}},
1028 { MPLSLDPENTITYSTATSSESSIONREJAD
, COUNTER32
, RONLY
,
1029 ldpEntityStatsTable
, 5, {1, 2, 4, 1, 3}},
1030 { MPLSLDPENTITYSTATSSESSIONREJMAXPDU
, COUNTER32
, RONLY
,
1031 ldpEntityStatsTable
, 5, {1, 2, 4, 1, 4}},
1032 { MPLSLDPENTITYSTATSSESSIONREJLR
, COUNTER32
, RONLY
,
1033 ldpEntityStatsTable
, 5, {1, 2, 4, 1, 5}},
1034 { MPLSLDPENTITYSTATSBADLDPID
, COUNTER32
, RONLY
,
1035 ldpEntityStatsTable
, 5, {1, 2, 4, 1, 6}},
1036 { MPLSLDPENTITYSTATSBADPDULENGTH
, COUNTER32
, RONLY
,
1037 ldpEntityStatsTable
, 5, {1, 2, 4, 1, 7}},
1038 { MPLSLDPENTITYSTATSBADMSGLENGTH
, COUNTER32
, RONLY
,
1039 ldpEntityStatsTable
, 5, {1, 2, 4, 1, 8}},
1040 { MPLSLDPENTITYSTATSBADTLVLENGTH
, COUNTER32
, RONLY
,
1041 ldpEntityStatsTable
, 5, {1, 2, 4, 1, 9}},
1042 { MPLSLDPENTITYSTATSMALFORMEDTLV
, COUNTER32
, RONLY
,
1043 ldpEntityStatsTable
, 5, {1, 2, 4, 1, 10}},
1044 { MPLSLDPENTITYSTATSKEEPALIVEEXP
, COUNTER32
, RONLY
,
1045 ldpEntityStatsTable
, 5, {1, 2, 4, 1, 11}},
1046 { MPLSLDPENTITYSTATSSHUTDOWNRCVNOTIFY
, COUNTER32
, RONLY
,
1047 ldpEntityStatsTable
, 5, {1, 2, 4, 1, 12}},
1048 { MPLSLDPENTITYSTATSSHUTDOWNSENTNOTIFY
, COUNTER32
, RONLY
,
1049 ldpEntityStatsTable
, 5, {1, 2, 4, 1, 13}},
1051 /* MPLS LDP mplsLdpPeerTable */
1052 {MPLSLDPPEERLDPID
, STRING
, RONLY
, ldpPeerTable
, 5, {1, 3, 2, 1, 1}},
1053 {MPLSLDPPEERLABELDISTMETHOD
, INTEGER
, RONLY
, ldpPeerTable
,
1054 5, {1, 3, 2, 1, 2}},
1055 {MPLSLDPPEERPATHVECTORLIMIT
, INTEGER
, RONLY
, ldpPeerTable
,
1056 5, {1, 3, 2, 1, 3}},
1057 {MPLSLDPPEERTRANSPORTADDRTYPE
, INTEGER
, RONLY
, ldpPeerTable
,
1058 5, {1, 3, 2, 1, 4}},
1059 {MPLSLDPPEERTRANSPORTADDR
, STRING
, RONLY
, ldpPeerTable
,
1060 5, {1, 3, 2, 1, 5}},
1062 /* MPLS LDP mplsLdpSessionTable */
1063 {MPLSLDPSESSIONSTATELASTCHANGE
, TIMESTAMP
, RONLY
, ldpSessionTable
,
1064 5, {1, 3, 3, 1, 1}},
1065 {MPLSLDPSESSIONSTATE
, INTEGER
, RONLY
, ldpSessionTable
,
1066 5, {1, 3, 3, 1, 2}},
1067 {MPLSLDPSESSIONROLE
, INTEGER
, RONLY
, ldpSessionTable
,
1068 5, {1, 3, 3, 1, 3}},
1069 {MPLSLDPSESSIONPROTOCOLVERSION
, UNSIGNED32
, RONLY
, ldpSessionTable
,
1070 5, {1, 3, 3, 1, 4}},
1071 {MPLSLDPSESSIONKEEPALIVEHOLDTIMEREM
, INTEGER
, RONLY
, ldpSessionTable
,
1072 5, {1, 3, 3, 1, 5}},
1073 {MPLSLDPSESSIONKEEPALIVETIME
, UNSIGNED32
, RONLY
, ldpSessionTable
,
1074 5, {1, 3, 3, 1, 6}},
1075 {MPLSLDPSESSIONMAXPDULENGTH
, UNSIGNED32
, RONLY
, ldpSessionTable
,
1076 5, {1, 3, 3, 1, 7}},
1077 {MPLSLDPSESSIONDISCONTINUITYTIME
, TIMESTAMP
, RONLY
, ldpSessionTable
,
1078 5, {1, 3, 3, 1, 8}},
1080 /* MPLS LDP mplsLdpSessionStatsTable */
1081 {MPLSLDPSESSIONSTATSUNKNOWNMESTYPEERRORS
, COUNTER32
, RONLY
,
1082 ldpSessionStatsTable
, 5, {1, 3, 4, 1, 1}},
1083 {MPLSLDPSESSIONSTATSUNKNOWNTLVERRORS
, COUNTER32
, RONLY
,
1084 ldpSessionStatsTable
, 5, {1, 3, 4, 1, 2}},
1086 /* MPLS LDP mplsLdpHelloAdjacencyTable. */
1087 {MPLSLDPHELLOADJACENCYINDEX
, UNSIGNED32
, RONLY
,
1088 ldpHelloAdjacencyTable
, 6, {1, 3, 5, 1, 1, 1}},
1089 {MPLSLDPHELLOADJACENCYHOLDTIMEREM
, INTEGER
, RONLY
,
1090 ldpHelloAdjacencyTable
, 6, {1, 3, 5, 1, 1, 2}},
1091 {MPLSLDPHELLOADJACENCYHOLDTIME
, UNSIGNED32
, RONLY
,
1092 ldpHelloAdjacencyTable
, 6, {1, 3, 5, 1, 1, 3}},
1093 {MPLSLDPHELLOADJACENCYTYPE
, INTEGER
, RONLY
,
1094 ldpHelloAdjacencyTable
, 6, {1, 3, 5, 1, 1, 4}},
1097 static struct variable lde_variables
[] = {
1100 static struct trap_object ldpSessionTrapList
[] = {
1101 {5, {1, 3, 3, 1, MPLSLDPSESSIONSTATE
}},
1102 {5, {1, 3, 3, 1, MPLSLDPSESSIONDISCONTINUITYTIME
}},
1103 {5, {1, 3, 4, 1, MPLSLDPSESSIONSTATSUNKNOWNMESTYPEERRORS
}},
1104 {5, {1, 3, 4, 1, MPLSLDPSESSIONSTATSUNKNOWNTLVERRORS
}}};
1107 #define LDPINITSESSIONTHRESHOLDEXCEEDED 1
1108 #define LDPPATHVECTORLIMITMISMATCH 2
1109 #define LDPSESSIONUP 3
1110 #define LDPSESSIONDOWN 4
1113 ldpTrapSession(struct nbr
* nbr
, unsigned int sptrap
)
1115 oid index
[sizeof(oid
) * (LDP_PEER_ENTRY_MAX_IDX_LEN
+ 1)];
1117 struct in_addr entityLdpId
= {.s_addr
= 0};
1118 uint32_t entityIndex
= 0;
1119 struct in_addr peerLdpId
= {.s_addr
= 0};
1121 struct ctl_nbr
*ctl_nbr
= nbr_to_ctl(nbr
);
1123 entityLdpId
.s_addr
= ldp_rtr_id_get(leconf
);
1124 entityIndex
= LDP_DEFAULT_ENTITY_INDEX
;
1125 peerLdpId
= ctl_nbr
->id
;
1127 oid_copy_in_addr(index
, &entityLdpId
);
1130 index
[6] = entityIndex
;
1131 oid_copy_in_addr(&index
[7], &peerLdpId
);
1135 index
[LDP_PEER_ENTRY_MAX_IDX_LEN
] = 0;
1137 smux_trap(ldpe_variables
, array_size(ldpe_variables
), ldp_trap_oid
,
1138 array_size(ldp_trap_oid
), ldp_oid
,
1139 sizeof(ldp_oid
) / sizeof(oid
), index
,
1140 LDP_PEER_ENTRY_MAX_IDX_LEN
+ 1,
1141 ldpSessionTrapList
, array_size(ldpSessionTrapList
), sptrap
);
1145 ldpTrapSessionUp(struct nbr
* nbr
)
1147 ldpTrapSession(nbr
, LDPSESSIONUP
);
1151 ldpTrapSessionDown(struct nbr
* nbr
)
1153 ldpTrapSession(nbr
, LDPSESSIONDOWN
);
1156 static int ldp_snmp_agentx_enabled(void)
1158 main_imsg_compose_both(IMSG_AGENTX_ENABLED
, NULL
, 0);
1163 static int ldp_snmp_nbr_state_change(struct nbr
* nbr
, int old_state
)
1165 if (old_state
== nbr
->state
)
1168 if (nbr
->state
== NBR_STA_OPER
)
1169 ldpTrapSessionUp(nbr
);
1170 else if (old_state
== NBR_STA_OPER
)
1171 ldpTrapSessionDown(nbr
);
1176 static int ldp_snmp_init(struct thread_master
*tm
)
1178 hook_register(agentx_enabled
, ldp_snmp_agentx_enabled
);
1185 static int ldp_snmp_register_mib(struct thread_master
*tm
)
1187 static int registered
= 0;
1196 smux_agentx_enable();
1198 if (ldpd_process
== PROC_LDE_ENGINE
)
1199 REGISTER_MIB("mibII/ldp", lde_variables
, variable
, ldp_oid
);
1200 else if (ldpd_process
== PROC_LDP_ENGINE
) {
1201 REGISTER_MIB("mibII/ldp", ldpe_variables
, variable
, ldp_oid
);
1203 hook_register(ldp_nbr_state_change
, ldp_snmp_nbr_state_change
);
1209 static int ldp_snmp_module_init(void)
1211 if (ldpd_process
== PROC_MAIN
)
1212 hook_register(frr_late_init
, ldp_snmp_init
);
1214 hook_register(ldp_register_mib
, ldp_snmp_register_mib
);
1221 .version
= FRR_VERSION
,
1222 .description
= "ldp AgentX SNMP module",
1223 .init
= ldp_snmp_module_init
,