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
24 #include <net-snmp/net-snmp-config.h>
25 #include <net-snmp/net-snmp-includes.h>
35 #include "bgpd/bgpd.h"
36 #include "bgpd/bgp_table.h"
37 #include "bgpd/bgp_aspath.h"
38 #include "bgpd/bgp_attr.h"
39 #include "bgpd/bgp_route.h"
40 #include "bgpd/bgp_fsm.h"
41 #include "bgpd/bgp_snmp.h"
43 /* BGP4-MIB described in RFC1657. */
44 #define BGP4MIB 1,3,6,1,2,1,15
47 #define BGPESTABLISHED 1
48 #define BGPBACKWARDTRANSITION 2
50 /* BGP MIB bgpVersion. */
53 /* BGP MIB bgpLocalAs. */
56 /* BGP MIB bgpPeerTable. */
57 #define BGPPEERIDENTIFIER 1
58 #define BGPPEERSTATE 2
59 #define BGPPEERADMINSTATUS 3
60 #define BGPPEERNEGOTIATEDVERSION 4
61 #define BGPPEERLOCALADDR 5
62 #define BGPPEERLOCALPORT 6
63 #define BGPPEERREMOTEADDR 7
64 #define BGPPEERREMOTEPORT 8
65 #define BGPPEERREMOTEAS 9
66 #define BGPPEERINUPDATES 10
67 #define BGPPEEROUTUPDATES 11
68 #define BGPPEERINTOTALMESSAGES 12
69 #define BGPPEEROUTTOTALMESSAGES 13
70 #define BGPPEERLASTERROR 14
71 #define BGPPEERFSMESTABLISHEDTRANSITIONS 15
72 #define BGPPEERFSMESTABLISHEDTIME 16
73 #define BGPPEERCONNECTRETRYINTERVAL 17
74 #define BGPPEERHOLDTIME 18
75 #define BGPPEERKEEPALIVE 19
76 #define BGPPEERHOLDTIMECONFIGURED 20
77 #define BGPPEERKEEPALIVECONFIGURED 21
78 #define BGPPEERMINROUTEADVERTISEMENTINTERVAL 22
79 #define BGPPEERINUPDATEELAPSEDTIME 23
81 /* BGP MIB bgpIdentifier. */
82 #define BGPIDENTIFIER 0
84 /* BGP MIB bgpRcvdPathAttrTable */
85 #define BGPPATHATTRPEER 1
86 #define BGPPATHATTRDESTNETWORK 2
87 #define BGPPATHATTRORIGIN 3
88 #define BGPPATHATTRASPATH 4
89 #define BGPPATHATTRNEXTHOP 5
90 #define BGPPATHATTRINTERASMETRIC 6
92 /* BGP MIB bgp4PathAttrTable. */
93 #define BGP4PATHATTRPEER 1
94 #define BGP4PATHATTRIPADDRPREFIXLEN 2
95 #define BGP4PATHATTRIPADDRPREFIX 3
96 #define BGP4PATHATTRORIGIN 4
97 #define BGP4PATHATTRASPATHSEGMENT 5
98 #define BGP4PATHATTRNEXTHOP 6
99 #define BGP4PATHATTRMULTIEXITDISC 7
100 #define BGP4PATHATTRLOCALPREF 8
101 #define BGP4PATHATTRATOMICAGGREGATE 9
102 #define BGP4PATHATTRAGGREGATORAS 10
103 #define BGP4PATHATTRAGGREGATORADDR 11
104 #define BGP4PATHATTRCALCLOCALPREF 12
105 #define BGP4PATHATTRBEST 13
106 #define BGP4PATHATTRUNKNOWN 14
108 /* SNMP value hack. */
109 #define INTEGER ASN_INTEGER
110 #define INTEGER32 ASN_INTEGER
111 #define COUNTER32 ASN_COUNTER
112 #define OCTET_STRING ASN_OCTET_STR
113 #define IPADDRESS ASN_IPADDRESS
114 #define GAUGE32 ASN_UNSIGNED
116 /* Declare static local variables for convenience. */
119 /* BGP-MIB instances. */
120 oid bgp_oid [] = { BGP4MIB };
121 oid bgp_trap_oid [] = { BGP4MIB, 0 };
123 /* IP address 0.0.0.0. */
124 static struct in_addr bgp_empty_addr = { .s_addr = 0 };
126 /* Hook functions. */
127 static u_char *bgpVersion (struct variable *, oid [], size_t *, int,
128 size_t *, WriteMethod **);
129 static u_char *bgpLocalAs (struct variable *, oid [], size_t *,
130 int, size_t *, WriteMethod **);
131 static u_char *bgpPeerTable (struct variable *, oid [], size_t *,
132 int, size_t *, WriteMethod **);
133 static u_char *bgpRcvdPathAttrTable (struct variable *, oid [], size_t *,
134 int, size_t *, WriteMethod **);
135 static u_char *bgpIdentifier (struct variable *, oid [], size_t *,
136 int, size_t *, WriteMethod **);
137 static u_char *bgp4PathAttrTable (struct variable *, oid [], size_t *,
138 int, size_t *, WriteMethod **);
139 /* static u_char *bgpTraps (); */
141 struct variable bgp_variables[] =
144 {BGPVERSION, OCTET_STRING, RONLY, bgpVersion,
147 {BGPLOCALAS, INTEGER, RONLY, bgpLocalAs,
149 /* BGP peer table. */
150 {BGPPEERIDENTIFIER, IPADDRESS, RONLY, bgpPeerTable,
152 {BGPPEERSTATE, INTEGER, RONLY, bgpPeerTable,
154 {BGPPEERADMINSTATUS, INTEGER, RWRITE, bgpPeerTable,
156 {BGPPEERNEGOTIATEDVERSION, INTEGER32, RONLY, bgpPeerTable,
158 {BGPPEERLOCALADDR, IPADDRESS, RONLY, bgpPeerTable,
160 {BGPPEERLOCALPORT, INTEGER, RONLY, bgpPeerTable,
162 {BGPPEERREMOTEADDR, IPADDRESS, RONLY, bgpPeerTable,
164 {BGPPEERREMOTEPORT, INTEGER, RONLY, bgpPeerTable,
166 {BGPPEERREMOTEAS, INTEGER, RONLY, bgpPeerTable,
168 {BGPPEERINUPDATES, COUNTER32, RONLY, bgpPeerTable,
170 {BGPPEEROUTUPDATES, COUNTER32, RONLY, bgpPeerTable,
172 {BGPPEERINTOTALMESSAGES, COUNTER32, RONLY, bgpPeerTable,
174 {BGPPEEROUTTOTALMESSAGES, COUNTER32, RONLY, bgpPeerTable,
176 {BGPPEERLASTERROR, OCTET_STRING, RONLY, bgpPeerTable,
178 {BGPPEERFSMESTABLISHEDTRANSITIONS, COUNTER32, RONLY, bgpPeerTable,
180 {BGPPEERFSMESTABLISHEDTIME, GAUGE32, RONLY, bgpPeerTable,
182 {BGPPEERCONNECTRETRYINTERVAL, INTEGER, RWRITE, bgpPeerTable,
184 {BGPPEERHOLDTIME, INTEGER, RONLY, bgpPeerTable,
186 {BGPPEERKEEPALIVE, INTEGER, RONLY, bgpPeerTable,
188 {BGPPEERHOLDTIMECONFIGURED, INTEGER, RWRITE, bgpPeerTable,
190 {BGPPEERKEEPALIVECONFIGURED, INTEGER, RWRITE, bgpPeerTable,
192 {BGPPEERMINROUTEADVERTISEMENTINTERVAL, INTEGER, RWRITE, bgpPeerTable,
194 {BGPPEERINUPDATEELAPSEDTIME, GAUGE32, RONLY, bgpPeerTable,
196 /* BGP identifier. */
197 {BGPIDENTIFIER, IPADDRESS, RONLY, bgpIdentifier,
199 /* BGP received path attribute table. */
200 {BGPPATHATTRPEER, IPADDRESS, RONLY, bgpRcvdPathAttrTable,
202 {BGPPATHATTRDESTNETWORK, IPADDRESS, RONLY, bgpRcvdPathAttrTable,
204 {BGPPATHATTRORIGIN, INTEGER, RONLY, bgpRcvdPathAttrTable,
206 {BGPPATHATTRASPATH, OCTET_STRING, RONLY, bgpRcvdPathAttrTable,
208 {BGPPATHATTRNEXTHOP, IPADDRESS, RONLY, bgpRcvdPathAttrTable,
210 {BGPPATHATTRINTERASMETRIC, INTEGER32, RONLY, bgpRcvdPathAttrTable,
212 /* BGP-4 received path attribute table. */
213 {BGP4PATHATTRPEER, IPADDRESS, RONLY, bgp4PathAttrTable,
215 {BGP4PATHATTRIPADDRPREFIXLEN, INTEGER, RONLY, bgp4PathAttrTable,
217 {BGP4PATHATTRIPADDRPREFIX, IPADDRESS, RONLY, bgp4PathAttrTable,
219 {BGP4PATHATTRORIGIN, INTEGER, RONLY, bgp4PathAttrTable,
221 {BGP4PATHATTRASPATHSEGMENT, OCTET_STRING, RONLY, bgp4PathAttrTable,
223 {BGP4PATHATTRNEXTHOP, IPADDRESS, RONLY, bgp4PathAttrTable,
225 {BGP4PATHATTRMULTIEXITDISC, INTEGER, RONLY, bgp4PathAttrTable,
227 {BGP4PATHATTRLOCALPREF, INTEGER, RONLY, bgp4PathAttrTable,
229 {BGP4PATHATTRATOMICAGGREGATE, INTEGER, RONLY, bgp4PathAttrTable,
231 {BGP4PATHATTRAGGREGATORAS, INTEGER, RONLY, bgp4PathAttrTable,
233 {BGP4PATHATTRAGGREGATORADDR, IPADDRESS, RONLY, bgp4PathAttrTable,
235 {BGP4PATHATTRCALCLOCALPREF, INTEGER, RONLY, bgp4PathAttrTable,
237 {BGP4PATHATTRBEST, INTEGER, RONLY, bgp4PathAttrTable,
239 {BGP4PATHATTRUNKNOWN, OCTET_STRING, RONLY, bgp4PathAttrTable,
245 bgpVersion (struct variable *v, oid name[], size_t *length, int exact,
246 size_t *var_len, WriteMethod **write_method)
248 static u_char version;
250 if (smux_header_generic(v, name, length, exact, var_len, write_method)
254 /* Retrun BGP version. Zebra bgpd only support version 4. */
255 version = (0x80 >> (BGP_VERSION_4 - 1));
257 /* Return octet string length 1. */
259 return (u_char *)&version;
263 bgpLocalAs (struct variable *v, oid name[], size_t *length,
264 int exact, size_t *var_len, WriteMethod **write_method)
268 if (smux_header_generic(v, name, length, exact, var_len, write_method)
272 /* Get BGP structure. */
273 bgp = bgp_get_default ();
277 return SNMP_INTEGER (bgp->as);
281 peer_lookup_addr_ipv4 (struct in_addr *src)
285 struct listnode *node;
289 bgp = bgp_get_default ();
293 for (ALL_LIST_ELEMENTS_RO (bgp->peer, node, peer))
295 ret = inet_pton (AF_INET, peer->host, &addr);
298 if (IPV4_ADDR_SAME (&addr, src))
306 bgp_peer_lookup_next (struct in_addr *src)
310 struct listnode *node;
315 memset (&su, 0, sizeof (union sockunion));
317 bgp = bgp_get_default ();
321 for (ALL_LIST_ELEMENTS_RO (bgp->peer, node, peer))
323 ret = inet_pton (AF_INET, peer->host, &su.sin.sin_addr);
326 p = &su.sin.sin_addr;
328 if (ntohl (p->s_addr) > ntohl (src->s_addr))
330 src->s_addr = p->s_addr;
338 /* 1.3.6.1.2.1.15.3.1.x = 10 */
339 #define PEERTAB_NAMELEN 10
342 bgpPeerTable_lookup (struct variable *v, oid name[], size_t *length,
343 struct in_addr *addr, int exact)
345 struct peer *peer = NULL;
346 size_t namelen = v ? v->namelen : PEERTAB_NAMELEN;
351 /* Check the length. */
352 if (*length - namelen != sizeof (struct in_addr))
355 oid2in_addr (name + namelen, IN_ADDR_SIZE, addr);
357 peer = peer_lookup_addr_ipv4 (addr);
362 len = *length - namelen;
363 if (len > 4) len = 4;
365 oid2in_addr (name + namelen, len, addr);
367 peer = bgp_peer_lookup_next (addr);
372 oid_copy_addr (name + namelen, addr, sizeof (struct in_addr));
373 *length = sizeof (struct in_addr) + namelen;
380 /* BGP write methods. */
382 write_bgpPeerTable (int action, u_char *var_val,
383 u_char var_val_type, size_t var_val_len,
384 u_char *statP, oid *name, size_t length)
390 if (var_val_type != ASN_INTEGER)
392 return SNMP_ERR_WRONGTYPE;
394 if (var_val_len != sizeof (long))
396 return SNMP_ERR_WRONGLENGTH;
399 intval = *(long *)var_val;
401 memset (&addr, 0, sizeof (struct in_addr));
403 peer = bgpPeerTable_lookup (NULL, name, &length, &addr, 1);
405 return SNMP_ERR_NOSUCHNAME;
407 if (action != SNMP_MSG_INTERNAL_SET_COMMIT)
408 return SNMP_ERR_NOERROR;
410 zlog_info ("%s: SNMP write .%ld = %ld",
411 peer->host, (long)name[PEERTAB_NAMELEN - 1], intval);
413 switch (name[PEERTAB_NAMELEN - 1])
415 case BGPPEERADMINSTATUS:
416 #define BGP_PeerAdmin_stop 1
417 #define BGP_PeerAdmin_start 2
418 /* When the peer is established, */
419 if (intval == BGP_PeerAdmin_stop)
420 BGP_EVENT_ADD (peer, BGP_Stop);
421 else if (intval == BGP_PeerAdmin_start)
424 return SNMP_ERR_NOSUCHNAME;
426 case BGPPEERCONNECTRETRYINTERVAL:
427 SET_FLAG (peer->config, PEER_CONFIG_CONNECT);
428 peer->connect = intval;
429 peer->v_connect = intval;
431 case BGPPEERHOLDTIMECONFIGURED:
432 SET_FLAG (peer->config, PEER_CONFIG_TIMER);
433 peer->holdtime = intval;
434 peer->v_holdtime = intval;
436 case BGPPEERKEEPALIVECONFIGURED:
437 SET_FLAG (peer->config, PEER_CONFIG_TIMER);
438 peer->keepalive = intval;
439 peer->v_keepalive = intval;
441 case BGPPEERMINROUTEADVERTISEMENTINTERVAL:
442 peer->v_routeadv = intval;
445 return SNMP_ERR_NOERROR;
449 bgpPeerTable (struct variable *v, oid name[], size_t *length,
450 int exact, size_t *var_len, WriteMethod **write_method)
452 static struct in_addr addr;
455 if (smux_header_table(v, name, length, exact, var_len, write_method)
458 memset (&addr, 0, sizeof (struct in_addr));
460 peer = bgpPeerTable_lookup (v, name, length, &addr, exact);
466 case BGPPEERIDENTIFIER:
467 return SNMP_IPADDRESS (peer->remote_id);
470 return SNMP_INTEGER (peer->status);
472 case BGPPEERADMINSTATUS:
473 *write_method = write_bgpPeerTable;
474 #define BGP_PeerAdmin_stop 1
475 #define BGP_PeerAdmin_start 2
476 if (CHECK_FLAG (peer->flags, PEER_FLAG_SHUTDOWN))
477 return SNMP_INTEGER (BGP_PeerAdmin_stop);
479 return SNMP_INTEGER (BGP_PeerAdmin_start);
481 case BGPPEERNEGOTIATEDVERSION:
482 return SNMP_INTEGER (BGP_VERSION_4);
484 case BGPPEERLOCALADDR:
486 return SNMP_IPADDRESS (peer->su_local->sin.sin_addr);
488 return SNMP_IPADDRESS (bgp_empty_addr);
490 case BGPPEERLOCALPORT:
492 return SNMP_INTEGER (ntohs (peer->su_local->sin.sin_port));
494 return SNMP_INTEGER (0);
496 case BGPPEERREMOTEADDR:
498 return SNMP_IPADDRESS (peer->su_remote->sin.sin_addr);
500 return SNMP_IPADDRESS (bgp_empty_addr);
502 case BGPPEERREMOTEPORT:
504 return SNMP_INTEGER (ntohs (peer->su_remote->sin.sin_port));
506 return SNMP_INTEGER (0);
508 case BGPPEERREMOTEAS:
509 return SNMP_INTEGER (peer->as);
511 case BGPPEERINUPDATES:
512 return SNMP_INTEGER (peer->update_in);
514 case BGPPEEROUTUPDATES:
515 return SNMP_INTEGER (peer->update_out);
517 case BGPPEERINTOTALMESSAGES:
518 return SNMP_INTEGER (peer->open_in + peer->update_in
519 + peer->keepalive_in + peer->notify_in
520 + peer->refresh_in + peer->dynamic_cap_in);
522 case BGPPEEROUTTOTALMESSAGES:
523 return SNMP_INTEGER (peer->open_out + peer->update_out
524 + peer->keepalive_out + peer->notify_out
525 + peer->refresh_out + peer->dynamic_cap_out);
527 case BGPPEERLASTERROR:
529 static u_char lasterror[2];
530 lasterror[0] = peer->notify.code;
531 lasterror[1] = peer->notify.subcode;
533 return (u_char *)&lasterror;
536 case BGPPEERFSMESTABLISHEDTRANSITIONS:
537 return SNMP_INTEGER (peer->established);
539 case BGPPEERFSMESTABLISHEDTIME:
540 if (peer->uptime == 0)
541 return SNMP_INTEGER (0);
543 return SNMP_INTEGER (bgp_clock () - peer->uptime);
545 case BGPPEERCONNECTRETRYINTERVAL:
546 *write_method = write_bgpPeerTable;
547 return SNMP_INTEGER (peer->v_connect);
549 case BGPPEERHOLDTIME:
550 return SNMP_INTEGER (peer->v_holdtime);
552 case BGPPEERKEEPALIVE:
553 return SNMP_INTEGER (peer->v_keepalive);
555 case BGPPEERHOLDTIMECONFIGURED:
556 *write_method = write_bgpPeerTable;
557 if (CHECK_FLAG (peer->config, PEER_CONFIG_TIMER))
558 return SNMP_INTEGER (peer->holdtime);
560 return SNMP_INTEGER (peer->v_holdtime);
562 case BGPPEERKEEPALIVECONFIGURED:
563 *write_method = write_bgpPeerTable;
564 if (CHECK_FLAG (peer->config, PEER_CONFIG_TIMER))
565 return SNMP_INTEGER (peer->keepalive);
567 return SNMP_INTEGER (peer->v_keepalive);
569 case BGPPEERMINROUTEADVERTISEMENTINTERVAL:
570 *write_method = write_bgpPeerTable;
571 return SNMP_INTEGER (peer->v_routeadv);
573 case BGPPEERINUPDATEELAPSEDTIME:
574 if (peer->update_time == 0)
575 return SNMP_INTEGER (0);
577 return SNMP_INTEGER (bgp_clock () - peer->update_time);
587 bgpIdentifier (struct variable *v, oid name[], size_t *length,
588 int exact, size_t *var_len, WriteMethod **write_method)
592 if (smux_header_generic(v, name, length, exact, var_len, write_method)
596 bgp = bgp_get_default ();
600 return SNMP_IPADDRESS (bgp->router_id);
604 bgpRcvdPathAttrTable (struct variable *v, oid name[], size_t *length,
605 int exact, size_t *var_len, WriteMethod **write_method)
607 /* Received Path Attribute Table. This table contains, one entry
608 per path to a network, path attributes received from all peers
609 running BGP version 3 or less. This table is obsolete, having
610 been replaced in functionality with the bgp4PathAttrTable. */
614 static struct bgp_info *
615 bgp4PathAttrLookup (struct variable *v, oid name[], size_t *length,
616 struct bgp *bgp, struct prefix_ipv4 *addr, int exact)
620 struct bgp_info *binfo;
621 struct bgp_info *min;
625 struct in_addr paddr;
627 #define BGP_PATHATTR_ENTRY_OFFSET \
628 (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE)
632 if (*length - v->namelen != BGP_PATHATTR_ENTRY_OFFSET)
635 /* Set OID offset for prefix. */
636 offset = name + v->namelen;
637 oid2in_addr (offset, IN_ADDR_SIZE, &addr->prefix);
638 offset += IN_ADDR_SIZE;
641 addr->prefixlen = *offset;
645 su.sin.sin_family = AF_INET;
646 oid2in_addr (offset, IN_ADDR_SIZE, &su.sin.sin_addr);
649 rn = bgp_node_lookup (bgp->rib[AFI_IP][SAFI_UNICAST],
650 (struct prefix *) addr);
653 bgp_unlock_node (rn);
655 for (binfo = rn->info; binfo; binfo = binfo->next)
656 if (sockunion_same (&binfo->peer->su, &su))
662 offset = name + v->namelen;
663 offsetlen = *length - v->namelen;
667 rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_UNICAST]);
670 if (len > IN_ADDR_SIZE)
673 oid2in_addr (offset, len, &addr->prefix);
675 offset += IN_ADDR_SIZE;
676 offsetlen -= IN_ADDR_SIZE;
679 addr->prefixlen = *offset;
681 addr->prefixlen = len * 8;
683 rn = bgp_node_get (bgp->rib[AFI_IP][SAFI_UNICAST],
684 (struct prefix *) addr);
693 if (len > IN_ADDR_SIZE)
696 oid2in_addr (offset, len, &paddr);
708 for (binfo = rn->info; binfo; binfo = binfo->next)
710 if (binfo->peer->su.sin.sin_family == AF_INET
711 && ntohl (paddr.s_addr)
712 < ntohl (binfo->peer->su.sin.sin_addr.s_addr))
716 if (ntohl (binfo->peer->su.sin.sin_addr.s_addr)
717 < ntohl (min->peer->su.sin.sin_addr.s_addr))
727 *length = v->namelen + BGP_PATHATTR_ENTRY_OFFSET;
729 offset = name + v->namelen;
730 oid_copy_addr (offset, &rn->p.u.prefix4, IN_ADDR_SIZE);
731 offset += IN_ADDR_SIZE;
732 *offset = rn->p.prefixlen;
734 oid_copy_addr (offset, &min->peer->su.sin.sin_addr,
736 addr->prefix = rn->p.u.prefix4;
737 addr->prefixlen = rn->p.prefixlen;
739 bgp_unlock_node (rn);
746 while ((rn = bgp_route_next (rn)) != NULL);
752 bgp4PathAttrTable (struct variable *v, oid name[], size_t *length,
753 int exact, size_t *var_len, WriteMethod **write_method)
756 struct bgp_info *binfo;
757 struct prefix_ipv4 addr;
759 bgp = bgp_get_default ();
763 if (smux_header_table(v, name, length, exact, var_len, write_method)
766 memset (&addr, 0, sizeof (struct prefix_ipv4));
768 binfo = bgp4PathAttrLookup (v, name, length, bgp, &addr, exact);
774 case BGP4PATHATTRPEER: /* 1 */
775 return SNMP_IPADDRESS (binfo->peer->su.sin.sin_addr);
777 case BGP4PATHATTRIPADDRPREFIXLEN: /* 2 */
778 return SNMP_INTEGER (addr.prefixlen);
780 case BGP4PATHATTRIPADDRPREFIX: /* 3 */
781 return SNMP_IPADDRESS (addr.prefix);
783 case BGP4PATHATTRORIGIN: /* 4 */
784 return SNMP_INTEGER (binfo->attr->origin);
786 case BGP4PATHATTRASPATHSEGMENT: /* 5 */
787 return aspath_snmp_pathseg (binfo->attr->aspath, var_len);
789 case BGP4PATHATTRNEXTHOP: /* 6 */
790 return SNMP_IPADDRESS (binfo->attr->nexthop);
792 case BGP4PATHATTRMULTIEXITDISC: /* 7 */
793 return SNMP_INTEGER (binfo->attr->med);
795 case BGP4PATHATTRLOCALPREF: /* 8 */
796 return SNMP_INTEGER (binfo->attr->local_pref);
798 case BGP4PATHATTRATOMICAGGREGATE: /* 9 */
799 return SNMP_INTEGER (1);
801 case BGP4PATHATTRAGGREGATORAS: /* 10 */
802 if (binfo->attr->extra)
803 return SNMP_INTEGER (binfo->attr->extra->aggregator_as);
805 return SNMP_INTEGER (0);
807 case BGP4PATHATTRAGGREGATORADDR: /* 11 */
808 if (binfo->attr->extra)
809 return SNMP_IPADDRESS (binfo->attr->extra->aggregator_addr);
811 return SNMP_INTEGER (0);
813 case BGP4PATHATTRCALCLOCALPREF: /* 12 */
814 return SNMP_INTEGER (-1);
816 case BGP4PATHATTRBEST: /* 13 */
817 #define BGP4_PathAttrBest_false 1
818 #define BGP4_PathAttrBest_true 2
819 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
820 return SNMP_INTEGER (BGP4_PathAttrBest_true);
822 return SNMP_INTEGER (BGP4_PathAttrBest_false);
824 case BGP4PATHATTRUNKNOWN: /* 14 */
833 struct trap_object bgpTrapList[] =
835 {3, {3, 1, BGPPEERLASTERROR}},
836 {3, {3, 1, BGPPEERSTATE}}
840 bgpTrapEstablished (struct peer *peer)
844 oid index[sizeof (oid) * IN_ADDR_SIZE];
846 ret = inet_aton (peer->host, &addr);
850 oid_copy_addr (index, &addr, IN_ADDR_SIZE);
852 smux_trap (bgp_variables, sizeof bgp_variables / sizeof (struct variable),
853 bgp_trap_oid, sizeof bgp_trap_oid / sizeof (oid),
854 bgp_oid, sizeof bgp_oid / sizeof (oid),
856 bgpTrapList, sizeof bgpTrapList / sizeof (struct trap_object),
861 bgpTrapBackwardTransition (struct peer *peer)
865 oid index[sizeof (oid) * IN_ADDR_SIZE];
867 ret = inet_aton (peer->host, &addr);
871 oid_copy_addr (index, &addr, IN_ADDR_SIZE);
873 smux_trap (bgp_variables, sizeof bgp_variables / sizeof (struct variable),
874 bgp_trap_oid, sizeof bgp_trap_oid / sizeof (oid),
875 bgp_oid, sizeof bgp_oid / sizeof (oid),
877 bgpTrapList, sizeof bgpTrapList / sizeof (struct trap_object),
878 BGPBACKWARDTRANSITION);
884 smux_init (bm->master);
885 REGISTER_MIB("mibII/bgp", bgp_variables, variable, bgp_oid);
887 #endif /* HAVE_SNMP */