2 Copyright (C) 1999, 2000 Kunihiro Ishiguro
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
17 along with GNU Zebra; see the file COPYING. If not, write to the Free
18 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
25 #include <net-snmp/net-snmp-config.h>
29 #include <snmp_impl.h>
38 #include "bgpd/bgpd.h"
39 #include "bgpd/bgp_table.h"
40 #include "bgpd/bgp_aspath.h"
41 #include "bgpd/bgp_attr.h"
42 #include "bgpd/bgp_route.h"
43 #include "bgpd/bgp_fsm.h"
45 /* BGP4-MIB described in RFC1657. */
46 #define BGP4MIB 1,3,6,1,2,1,15
49 #define BGPESTABLISHED 1
50 #define BGPBACKWARDTRANSITION 2
52 /* BGP MIB bgpVersion. */
55 /* BGP MIB bgpLocalAs. */
58 /* BGP MIB bgpPeerTable. */
59 #define BGPPEERIDENTIFIER 1
60 #define BGPPEERSTATE 2
61 #define BGPPEERADMINSTATUS 3
62 #define BGPPEERNEGOTIATEDVERSION 4
63 #define BGPPEERLOCALADDR 5
64 #define BGPPEERLOCALPORT 6
65 #define BGPPEERREMOTEADDR 7
66 #define BGPPEERREMOTEPORT 8
67 #define BGPPEERREMOTEAS 9
68 #define BGPPEERINUPDATES 10
69 #define BGPPEEROUTUPDATES 11
70 #define BGPPEERINTOTALMESSAGES 12
71 #define BGPPEEROUTTOTALMESSAGES 13
72 #define BGPPEERLASTERROR 14
73 #define BGPPEERFSMESTABLISHEDTRANSITIONS 15
74 #define BGPPEERFSMESTABLISHEDTIME 16
75 #define BGPPEERCONNECTRETRYINTERVAL 17
76 #define BGPPEERHOLDTIME 18
77 #define BGPPEERKEEPALIVE 19
78 #define BGPPEERHOLDTIMECONFIGURED 20
79 #define BGPPEERKEEPALIVECONFIGURED 21
80 #define BGPPEERMINASORIGINATIONINTERVAL 22
81 #define BGPPEERMINROUTEADVERTISEMENTINTERVAL 23
82 #define BGPPEERINUPDATEELAPSEDTIME 24
84 /* BGP MIB bgpIdentifier. */
85 #define BGPIDENTIFIER 0
87 /* BGP MIB bgpRcvdPathAttrTable */
88 #define BGPPATHATTRPEER 1
89 #define BGPPATHATTRDESTNETWORK 2
90 #define BGPPATHATTRORIGIN 3
91 #define BGPPATHATTRASPATH 4
92 #define BGPPATHATTRNEXTHOP 5
93 #define BGPPATHATTRINTERASMETRIC 6
95 /* BGP MIB bgp4PathAttrTable. */
96 #define BGP4PATHATTRPEER 1
97 #define BGP4PATHATTRIPADDRPREFIXLEN 2
98 #define BGP4PATHATTRIPADDRPREFIX 3
99 #define BGP4PATHATTRORIGIN 4
100 #define BGP4PATHATTRASPATHSEGMENT 5
101 #define BGP4PATHATTRNEXTHOP 6
102 #define BGP4PATHATTRMULTIEXITDISC 7
103 #define BGP4PATHATTRLOCALPREF 8
104 #define BGP4PATHATTRATOMICAGGREGATE 9
105 #define BGP4PATHATTRAGGREGATORAS 10
106 #define BGP4PATHATTRAGGREGATORADDR 11
107 #define BGP4PATHATTRCALCLOCALPREF 12
108 #define BGP4PATHATTRBEST 13
109 #define BGP4PATHATTRUNKNOWN 14
111 /* SNMP value hack. */
112 #define INTEGER ASN_INTEGER
113 #define INTEGER32 ASN_INTEGER
114 #define COUNTER32 ASN_COUNTER
115 #define OCTET_STRING ASN_OCTET_STR
116 #define IPADDRESS ASN_IPADDRESS
117 #define GAUGE32 ASN_UNSIGNED
119 /* Declare static local variables for convenience. */
122 /* BGP-MIB instances. */
123 oid bgp_oid
[] = { BGP4MIB
};
125 /* IP address 0.0.0.0. */
126 static struct in_addr bgp_empty_addr
= {0};
128 /* Hook functions. */
129 static u_char
*bgpVersion ();
130 static u_char
*bgpLocalAs ();
131 static u_char
*bgpPeerTable ();
132 static u_char
*bgpRcvdPathAttrTable ();
133 static u_char
*bgpIdentifier ();
134 static u_char
*bgp4PathAttrTable ();
135 /* static u_char *bgpTraps (); */
137 struct variable bgp_variables
[] =
140 {BGPVERSION
, OCTET_STRING
, RONLY
, bgpVersion
,
143 {BGPLOCALAS
, INTEGER
, RONLY
, bgpLocalAs
,
145 /* BGP peer table. */
146 {BGPPEERIDENTIFIER
, IPADDRESS
, RONLY
, bgpPeerTable
,
148 {BGPPEERSTATE
, INTEGER
, RONLY
, bgpPeerTable
,
150 {BGPPEERADMINSTATUS
, INTEGER
, RWRITE
, bgpPeerTable
,
152 {BGPPEERNEGOTIATEDVERSION
, INTEGER32
, RONLY
, bgpPeerTable
,
154 {BGPPEERLOCALADDR
, IPADDRESS
, RONLY
, bgpPeerTable
,
156 {BGPPEERLOCALPORT
, INTEGER
, RONLY
, bgpPeerTable
,
158 {BGPPEERREMOTEADDR
, IPADDRESS
, RONLY
, bgpPeerTable
,
160 {BGPPEERREMOTEPORT
, INTEGER
, RONLY
, bgpPeerTable
,
162 {BGPPEERREMOTEAS
, INTEGER
, RONLY
, bgpPeerTable
,
164 {BGPPEERINUPDATES
, COUNTER32
, RONLY
, bgpPeerTable
,
166 {BGPPEEROUTUPDATES
, COUNTER32
, RONLY
, bgpPeerTable
,
168 {BGPPEERINTOTALMESSAGES
, COUNTER32
, RONLY
, bgpPeerTable
,
170 {BGPPEEROUTTOTALMESSAGES
, COUNTER32
, RONLY
, bgpPeerTable
,
172 {BGPPEERLASTERROR
, OCTET_STRING
, RONLY
, bgpPeerTable
,
174 {BGPPEERFSMESTABLISHEDTRANSITIONS
, COUNTER32
, RONLY
, bgpPeerTable
,
176 {BGPPEERFSMESTABLISHEDTIME
, GAUGE32
, RONLY
, bgpPeerTable
,
178 {BGPPEERCONNECTRETRYINTERVAL
, INTEGER
, RWRITE
, bgpPeerTable
,
180 {BGPPEERHOLDTIME
, INTEGER
, RONLY
, bgpPeerTable
,
182 {BGPPEERKEEPALIVE
, INTEGER
, RONLY
, bgpPeerTable
,
184 {BGPPEERHOLDTIMECONFIGURED
, INTEGER
, RWRITE
, bgpPeerTable
,
186 {BGPPEERKEEPALIVECONFIGURED
, INTEGER
, RWRITE
, bgpPeerTable
,
188 {BGPPEERMINASORIGINATIONINTERVAL
, INTEGER
, RWRITE
, bgpPeerTable
,
190 {BGPPEERMINROUTEADVERTISEMENTINTERVAL
, INTEGER
, RWRITE
, bgpPeerTable
,
192 {BGPPEERINUPDATEELAPSEDTIME
, GAUGE32
, RONLY
, bgpPeerTable
,
194 /* BGP identifier. */
195 {BGPIDENTIFIER
, IPADDRESS
, RONLY
, bgpIdentifier
,
197 /* BGP received path attribute table. */
198 {BGPPATHATTRPEER
, IPADDRESS
, RONLY
, bgpRcvdPathAttrTable
,
200 {BGPPATHATTRDESTNETWORK
, IPADDRESS
, RONLY
, bgpRcvdPathAttrTable
,
202 {BGPPATHATTRORIGIN
, INTEGER
, RONLY
, bgpRcvdPathAttrTable
,
204 {BGPPATHATTRASPATH
, OCTET_STRING
, RONLY
, bgpRcvdPathAttrTable
,
206 {BGPPATHATTRNEXTHOP
, IPADDRESS
, RONLY
, bgpRcvdPathAttrTable
,
208 {BGPPATHATTRINTERASMETRIC
, INTEGER32
, RONLY
, bgpRcvdPathAttrTable
,
210 /* BGP-4 received path attribute table. */
211 {BGP4PATHATTRPEER
, IPADDRESS
, RONLY
, bgp4PathAttrTable
,
213 {BGP4PATHATTRIPADDRPREFIXLEN
, INTEGER
, RONLY
, bgp4PathAttrTable
,
215 {BGP4PATHATTRIPADDRPREFIX
, IPADDRESS
, RONLY
, bgp4PathAttrTable
,
217 {BGP4PATHATTRORIGIN
, INTEGER
, RONLY
, bgp4PathAttrTable
,
219 {BGP4PATHATTRASPATHSEGMENT
, OCTET_STRING
, RONLY
, bgp4PathAttrTable
,
221 {BGP4PATHATTRNEXTHOP
, IPADDRESS
, RONLY
, bgp4PathAttrTable
,
223 {BGP4PATHATTRMULTIEXITDISC
, INTEGER
, RONLY
, bgp4PathAttrTable
,
225 {BGP4PATHATTRLOCALPREF
, INTEGER
, RONLY
, bgp4PathAttrTable
,
227 {BGP4PATHATTRATOMICAGGREGATE
, INTEGER
, RONLY
, bgp4PathAttrTable
,
229 {BGP4PATHATTRAGGREGATORAS
, INTEGER
, RONLY
, bgp4PathAttrTable
,
231 {BGP4PATHATTRAGGREGATORADDR
, IPADDRESS
, RONLY
, bgp4PathAttrTable
,
233 {BGP4PATHATTRCALCLOCALPREF
, INTEGER
, RONLY
, bgp4PathAttrTable
,
235 {BGP4PATHATTRBEST
, INTEGER
, RONLY
, bgp4PathAttrTable
,
237 {BGP4PATHATTRUNKNOWN
, OCTET_STRING
, RONLY
, bgp4PathAttrTable
,
243 bgpVersion (struct variable
*v
, oid name
[], size_t *length
, int exact
,
244 size_t *var_len
, WriteMethod
**write_method
)
246 static u_char version
;
248 if (smux_header_generic(v
, name
, length
, exact
, var_len
, write_method
)
252 /* Retrun BGP version. Zebra bgpd only support version 4. */
253 version
= (0x80 >> (BGP_VERSION_4
- 1));
255 /* Return octet string length 1. */
257 return (u_char
*)&version
;
261 bgpLocalAs (struct variable
*v
, oid name
[], size_t *length
,
262 int exact
, size_t *var_len
, WriteMethod
**write_method
)
266 if (smux_header_generic(v
, name
, length
, exact
, var_len
, write_method
)
270 /* Get BGP structure. */
271 bgp
= bgp_get_default ();
275 return SNMP_INTEGER (bgp
->as
);
279 peer_lookup_addr_ipv4 (struct in_addr
*src
)
283 struct listnode
*node
;
287 bgp
= bgp_get_default ();
291 for (ALL_LIST_ELEMENTS_RO (bgp
->peer
, node
, peer
))
293 ret
= inet_pton (AF_INET
, peer
->host
, &addr
);
296 if (IPV4_ADDR_SAME (&addr
, src
))
304 bgp_peer_lookup_next (struct in_addr
*src
)
308 struct listnode
*node
;
313 memset (&su
, 0, sizeof (union sockunion
));
315 bgp
= bgp_get_default ();
319 for (ALL_LIST_ELEMENTS_RO (bgp
->peer
, node
, peer
))
321 ret
= inet_pton (AF_INET
, peer
->host
, &su
.sin
.sin_addr
);
324 p
= &su
.sin
.sin_addr
;
326 if (ntohl (p
->s_addr
) > ntohl (src
->s_addr
))
328 src
->s_addr
= p
->s_addr
;
337 bgpPeerTable_lookup (struct variable
*v
, oid name
[], size_t *length
,
338 struct in_addr
*addr
, int exact
)
340 struct peer
*peer
= NULL
;
345 /* Check the length. */
346 if (*length
- v
->namelen
!= sizeof (struct in_addr
))
349 oid2in_addr (name
+ v
->namelen
, IN_ADDR_SIZE
, addr
);
351 peer
= peer_lookup_addr_ipv4 (addr
);
356 len
= *length
- v
->namelen
;
357 if (len
> 4) len
= 4;
359 oid2in_addr (name
+ v
->namelen
, len
, addr
);
361 peer
= bgp_peer_lookup_next (addr
);
366 oid_copy_addr (name
+ v
->namelen
, addr
, sizeof (struct in_addr
));
367 *length
= sizeof (struct in_addr
) + v
->namelen
;
374 /* BGP write methods. */
376 write_bgpPeerTable (int action
, u_char
*var_val
,
377 u_char var_val_type
, size_t var_val_len
,
378 u_char
*statP
, oid
*name
, size_t length
,
384 int bigsize
= SNMP_MAX_LEN
;
386 if (var_val_type
!= ASN_INTEGER
)
388 return SNMP_ERR_WRONGTYPE
;
390 if (var_val_len
!= sizeof (long))
392 return SNMP_ERR_WRONGLENGTH
;
395 if (! asn_parse_int(var_val
, &bigsize
, &var_val_type
,
396 &intval
, sizeof(long)))
398 return SNMP_ERR_WRONGENCODING
;
401 memset (&addr
, 0, sizeof (struct in_addr
));
403 peer
= bgpPeerTable_lookup (v
, name
, &length
, &addr
, 1);
405 return SNMP_ERR_NOSUCHNAME
;
407 printf ("val: %ld\n", intval
);
411 case BGPPEERADMINSTATUS
:
412 #define BGP_PeerAdmin_stop 1
413 #define BGP_PeerAdmin_start 2
414 /* When the peer is established, */
415 if (intval
== BGP_PeerAdmin_stop
)
416 BGP_EVENT_ADD (peer
, BGP_Stop
);
417 else if (intval
== BGP_PeerAdmin_start
)
420 return SNMP_ERR_NOSUCHNAME
;
422 case BGPPEERCONNECTRETRYINTERVAL
:
423 SET_FLAG (peer
->config
, PEER_CONFIG_CONNECT
);
424 peer
->connect
= intval
;
425 peer
->v_connect
= intval
;
427 case BGPPEERHOLDTIMECONFIGURED
:
428 SET_FLAG (peer
->config
, PEER_CONFIG_TIMER
);
429 peer
->holdtime
= intval
;
430 peer
->v_holdtime
= intval
;
432 case BGPPEERKEEPALIVECONFIGURED
:
433 SET_FLAG (peer
->config
, PEER_CONFIG_TIMER
);
434 peer
->keepalive
= intval
;
435 peer
->v_keepalive
= intval
;
437 case BGPPEERMINASORIGINATIONINTERVAL
:
438 peer
->v_asorig
= intval
;
440 case BGPPEERMINROUTEADVERTISEMENTINTERVAL
:
441 peer
->v_routeadv
= intval
;
444 return SNMP_ERR_NOERROR
;
448 bgpPeerTable (struct variable
*v
, oid name
[], size_t *length
,
449 int exact
, size_t *var_len
, WriteMethod
**write_method
)
451 static struct in_addr addr
;
454 *write_method
= NULL
;
455 memset (&addr
, 0, sizeof (struct in_addr
));
457 peer
= bgpPeerTable_lookup (v
, name
, length
, &addr
, exact
);
463 case BGPPEERIDENTIFIER
:
464 return SNMP_IPADDRESS (peer
->remote_id
);
467 return SNMP_INTEGER (peer
->status
);
469 case BGPPEERADMINSTATUS
:
470 *write_method
= write_bgpPeerTable
;
471 #define BGP_PeerAdmin_stop 1
472 #define BGP_PeerAdmin_start 2
473 if (CHECK_FLAG (peer
->flags
, PEER_FLAG_SHUTDOWN
))
474 return SNMP_INTEGER (BGP_PeerAdmin_stop
);
476 return SNMP_INTEGER (BGP_PeerAdmin_start
);
478 case BGPPEERNEGOTIATEDVERSION
:
479 return SNMP_INTEGER (BGP_VERSION_4
);
481 case BGPPEERLOCALADDR
:
483 return SNMP_IPADDRESS (peer
->su_local
->sin
.sin_addr
);
485 return SNMP_IPADDRESS (bgp_empty_addr
);
487 case BGPPEERLOCALPORT
:
489 return SNMP_INTEGER (ntohs (peer
->su_local
->sin
.sin_port
));
491 return SNMP_INTEGER (0);
493 case BGPPEERREMOTEADDR
:
495 return SNMP_IPADDRESS (peer
->su_remote
->sin
.sin_addr
);
497 return SNMP_IPADDRESS (bgp_empty_addr
);
499 case BGPPEERREMOTEPORT
:
501 return SNMP_INTEGER (ntohs (peer
->su_remote
->sin
.sin_port
));
503 return SNMP_INTEGER (0);
505 case BGPPEERREMOTEAS
:
506 return SNMP_INTEGER (peer
->as
);
508 case BGPPEERINUPDATES
:
509 return SNMP_INTEGER (peer
->update_in
);
511 case BGPPEEROUTUPDATES
:
512 return SNMP_INTEGER (peer
->update_out
);
514 case BGPPEERINTOTALMESSAGES
:
515 return SNMP_INTEGER (peer
->open_in
+ peer
->update_in
516 + peer
->keepalive_in
+ peer
->notify_in
517 + peer
->refresh_in
+ peer
->dynamic_cap_in
);
519 case BGPPEEROUTTOTALMESSAGES
:
520 return SNMP_INTEGER (peer
->open_out
+ peer
->update_out
521 + peer
->keepalive_out
+ peer
->notify_out
522 + peer
->refresh_out
+ peer
->dynamic_cap_out
);
524 case BGPPEERLASTERROR
:
526 static u_char lasterror
[2];
527 lasterror
[0] = peer
->notify
.code
;
528 lasterror
[1] = peer
->notify
.subcode
;
530 return (u_char
*)&lasterror
;
533 case BGPPEERFSMESTABLISHEDTRANSITIONS
:
534 return SNMP_INTEGER (peer
->established
);
536 case BGPPEERFSMESTABLISHEDTIME
:
537 if (peer
->uptime
== 0)
538 return SNMP_INTEGER (0);
540 return SNMP_INTEGER (time (NULL
) - peer
->uptime
);
542 case BGPPEERCONNECTRETRYINTERVAL
:
543 *write_method
= write_bgpPeerTable
;
544 return SNMP_INTEGER (peer
->v_connect
);
546 case BGPPEERHOLDTIME
:
547 return SNMP_INTEGER (peer
->v_holdtime
);
549 case BGPPEERKEEPALIVE
:
550 return SNMP_INTEGER (peer
->v_keepalive
);
552 case BGPPEERHOLDTIMECONFIGURED
:
553 *write_method
= write_bgpPeerTable
;
554 if (CHECK_FLAG (peer
->config
, PEER_CONFIG_TIMER
))
555 return SNMP_INTEGER (peer
->holdtime
);
557 return SNMP_INTEGER (peer
->v_holdtime
);
559 case BGPPEERKEEPALIVECONFIGURED
:
560 *write_method
= write_bgpPeerTable
;
561 if (CHECK_FLAG (peer
->config
, PEER_CONFIG_TIMER
))
562 return SNMP_INTEGER (peer
->keepalive
);
564 return SNMP_INTEGER (peer
->v_keepalive
);
566 case BGPPEERMINASORIGINATIONINTERVAL
:
567 *write_method
= write_bgpPeerTable
;
568 return SNMP_INTEGER (peer
->v_asorig
);
570 case BGPPEERMINROUTEADVERTISEMENTINTERVAL
:
571 *write_method
= write_bgpPeerTable
;
572 return SNMP_INTEGER (peer
->v_routeadv
);
574 case BGPPEERINUPDATEELAPSEDTIME
:
575 if (peer
->update_time
== 0)
576 return SNMP_INTEGER (0);
578 return SNMP_INTEGER (time (NULL
) - peer
->update_time
);
588 bgpIdentifier (struct variable
*v
, oid name
[], size_t *length
,
589 int exact
, size_t *var_len
, WriteMethod
**write_method
)
593 if (smux_header_generic(v
, name
, length
, exact
, var_len
, write_method
)
597 bgp
= bgp_get_default ();
601 return SNMP_IPADDRESS (bgp
->router_id
);
605 bgpRcvdPathAttrTable (struct variable
*v
, oid name
[], size_t *length
,
606 int exact
, size_t *var_len
, WriteMethod
**write_method
)
608 /* Received Path Attribute Table. This table contains, one entry
609 per path to a network, path attributes received from all peers
610 running BGP version 3 or less. This table is obsolete, having
611 been replaced in functionality with the bgp4PathAttrTable. */
616 bgp4PathAttrLookup (struct variable
*v
, oid name
[], size_t *length
,
617 struct bgp
*bgp
, struct prefix_ipv4
*addr
, int exact
)
621 struct bgp_info
*binfo
;
622 struct bgp_info
*min
;
626 struct in_addr paddr
;
628 #define BGP_PATHATTR_ENTRY_OFFSET \
629 (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE)
633 if (*length
- v
->namelen
!= BGP_PATHATTR_ENTRY_OFFSET
)
636 /* Set OID offset for prefix. */
637 offset
= name
+ v
->namelen
;
638 oid2in_addr (offset
, IN_ADDR_SIZE
, &addr
->prefix
);
639 offset
+= IN_ADDR_SIZE
;
642 addr
->prefixlen
= *offset
;
646 su
.sin
.sin_family
= AF_INET
;
647 oid2in_addr (offset
, IN_ADDR_SIZE
, &su
.sin
.sin_addr
);
650 rn
= bgp_node_lookup (bgp
->rib
[AFI_IP
][SAFI_UNICAST
],
651 (struct prefix
*) addr
);
654 bgp_unlock_node (rn
);
656 for (binfo
= rn
->info
; binfo
; binfo
= binfo
->next
)
657 if (sockunion_same (&binfo
->peer
->su
, &su
))
663 offset
= name
+ v
->namelen
;
664 offsetlen
= *length
- v
->namelen
;
668 rn
= bgp_table_top (bgp
->rib
[AFI_IP
][SAFI_UNICAST
]);
671 if (len
> IN_ADDR_SIZE
)
674 oid2in_addr (offset
, len
, &addr
->prefix
);
676 offset
+= IN_ADDR_SIZE
;
677 offsetlen
-= IN_ADDR_SIZE
;
680 addr
->prefixlen
= *offset
;
682 addr
->prefixlen
= len
* 8;
684 rn
= bgp_node_get (bgp
->rib
[AFI_IP
][SAFI_UNICAST
],
685 (struct prefix
*) addr
);
694 if (len
> IN_ADDR_SIZE
)
697 oid2in_addr (offset
, len
, &paddr
);
709 for (binfo
= rn
->info
; binfo
; binfo
= binfo
->next
)
711 if (binfo
->peer
->su
.sin
.sin_family
== AF_INET
712 && ntohl (paddr
.s_addr
)
713 < ntohl (binfo
->peer
->su
.sin
.sin_addr
.s_addr
))
717 if (ntohl (binfo
->peer
->su
.sin
.sin_addr
.s_addr
)
718 < ntohl (min
->peer
->su
.sin
.sin_addr
.s_addr
))
728 *length
= v
->namelen
+ BGP_PATHATTR_ENTRY_OFFSET
;
730 offset
= name
+ v
->namelen
;
731 oid_copy_addr (offset
, &rn
->p
.u
.prefix4
, IN_ADDR_SIZE
);
732 offset
+= IN_ADDR_SIZE
;
733 *offset
= rn
->p
.prefixlen
;
735 oid_copy_addr (offset
, &min
->peer
->su
.sin
.sin_addr
,
737 addr
->prefix
= rn
->p
.u
.prefix4
;
738 addr
->prefixlen
= rn
->p
.prefixlen
;
740 bgp_unlock_node (rn
);
747 while ((rn
= bgp_route_next (rn
)) != NULL
);
753 bgp4PathAttrTable (struct variable
*v
, oid name
[], size_t *length
,
754 int exact
, size_t *var_len
, WriteMethod
**write_method
)
757 struct bgp_info
*binfo
;
758 struct prefix_ipv4 addr
;
760 bgp
= bgp_get_default ();
764 memset (&addr
, 0, sizeof (struct prefix_ipv4
));
766 binfo
= bgp4PathAttrLookup (v
, name
, length
, bgp
, &addr
, exact
);
772 case BGP4PATHATTRPEER
: /* 1 */
773 return SNMP_IPADDRESS (binfo
->peer
->su
.sin
.sin_addr
);
775 case BGP4PATHATTRIPADDRPREFIXLEN
: /* 2 */
776 return SNMP_INTEGER (addr
.prefixlen
);
778 case BGP4PATHATTRIPADDRPREFIX
: /* 3 */
779 return SNMP_IPADDRESS (addr
.prefix
);
781 case BGP4PATHATTRORIGIN
: /* 4 */
782 return SNMP_INTEGER (binfo
->attr
->origin
);
784 case BGP4PATHATTRASPATHSEGMENT
: /* 5 */
785 return aspath_snmp_pathseg (binfo
->attr
->aspath
, var_len
);
787 case BGP4PATHATTRNEXTHOP
: /* 6 */
788 return SNMP_IPADDRESS (binfo
->attr
->nexthop
);
790 case BGP4PATHATTRMULTIEXITDISC
: /* 7 */
791 return SNMP_INTEGER (binfo
->attr
->med
);
793 case BGP4PATHATTRLOCALPREF
: /* 8 */
794 return SNMP_INTEGER (binfo
->attr
->local_pref
);
796 case BGP4PATHATTRATOMICAGGREGATE
: /* 9 */
797 return SNMP_INTEGER (1);
799 case BGP4PATHATTRAGGREGATORAS
: /* 10 */
800 if (binfo
->attr
->extra
)
801 return SNMP_INTEGER (binfo
->attr
->extra
->aggregator_as
);
803 return SNMP_INTEGER (0);
805 case BGP4PATHATTRAGGREGATORADDR
: /* 11 */
806 if (binfo
->attr
->extra
)
807 return SNMP_IPADDRESS (binfo
->attr
->extra
->aggregator_addr
);
809 return SNMP_INTEGER (0);
811 case BGP4PATHATTRCALCLOCALPREF
: /* 12 */
812 return SNMP_INTEGER (-1);
814 case BGP4PATHATTRBEST
: /* 13 */
815 #define BGP4_PathAttrBest_false 1
816 #define BGP4_PathAttrBest_true 2
817 if (CHECK_FLAG (binfo
->flags
, BGP_INFO_SELECTED
))
818 return SNMP_INTEGER (BGP4_PathAttrBest_true
);
820 return SNMP_INTEGER (BGP4_PathAttrBest_false
);
822 case BGP4PATHATTRUNKNOWN
: /* 14 */
831 struct trap_object bgpTrapList
[] =
833 {bgpPeerTable
, 3, {3, 1, BGPPEERLASTERROR
}},
834 {bgpPeerTable
, 3, {3, 1, BGPPEERSTATE
}}
838 bgpTrapEstablished (struct peer
*peer
)
842 oid index
[sizeof (oid
) * IN_ADDR_SIZE
];
844 ret
= inet_aton (peer
->host
, &addr
);
848 oid_copy_addr (index
, &addr
, IN_ADDR_SIZE
);
850 smux_trap (bgp_oid
, sizeof bgp_oid
/ sizeof (oid
),
852 bgpTrapList
, sizeof bgpTrapList
/ sizeof (struct trap_object
),
853 bm
->start_time
- time (NULL
), BGPESTABLISHED
);
857 bgpTrapBackwardTransition (struct peer
*peer
)
861 oid index
[sizeof (oid
) * IN_ADDR_SIZE
];
863 ret
= inet_aton (peer
->host
, &addr
);
867 oid_copy_addr (index
, &addr
, IN_ADDR_SIZE
);
869 smux_trap (bgp_oid
, sizeof bgp_oid
/ sizeof (oid
),
871 bgpTrapList
, sizeof bgpTrapList
/ sizeof (struct trap_object
),
872 bm
->start_time
- time (NULL
), BGPBACKWARDTRANSITION
);
878 smux_init (bm
->master
);
879 REGISTER_MIB("mibII/bgp", bgp_variables
, variable
, bgp_oid
);
881 #endif /* HAVE_SNMP */