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>
26 #include <net-snmp/net-snmp-includes.h>
30 #include <snmp_impl.h>
40 #include "bgpd/bgpd.h"
41 #include "bgpd/bgp_table.h"
42 #include "bgpd/bgp_aspath.h"
43 #include "bgpd/bgp_attr.h"
44 #include "bgpd/bgp_route.h"
45 #include "bgpd/bgp_fsm.h"
46 #include "bgpd/bgp_snmp.h"
48 /* BGP4-MIB described in RFC1657. */
49 #define BGP4MIB 1,3,6,1,2,1,15
52 #define BGPESTABLISHED 1
53 #define BGPBACKWARDTRANSITION 2
55 /* BGP MIB bgpVersion. */
58 /* BGP MIB bgpLocalAs. */
61 /* BGP MIB bgpPeerTable. */
62 #define BGPPEERIDENTIFIER 1
63 #define BGPPEERSTATE 2
64 #define BGPPEERADMINSTATUS 3
65 #define BGPPEERNEGOTIATEDVERSION 4
66 #define BGPPEERLOCALADDR 5
67 #define BGPPEERLOCALPORT 6
68 #define BGPPEERREMOTEADDR 7
69 #define BGPPEERREMOTEPORT 8
70 #define BGPPEERREMOTEAS 9
71 #define BGPPEERINUPDATES 10
72 #define BGPPEEROUTUPDATES 11
73 #define BGPPEERINTOTALMESSAGES 12
74 #define BGPPEEROUTTOTALMESSAGES 13
75 #define BGPPEERLASTERROR 14
76 #define BGPPEERFSMESTABLISHEDTRANSITIONS 15
77 #define BGPPEERFSMESTABLISHEDTIME 16
78 #define BGPPEERCONNECTRETRYINTERVAL 17
79 #define BGPPEERHOLDTIME 18
80 #define BGPPEERKEEPALIVE 19
81 #define BGPPEERHOLDTIMECONFIGURED 20
82 #define BGPPEERKEEPALIVECONFIGURED 21
83 #define BGPPEERMINASORIGINATIONINTERVAL 22
84 #define BGPPEERMINROUTEADVERTISEMENTINTERVAL 23
85 #define BGPPEERINUPDATEELAPSEDTIME 24
87 /* BGP MIB bgpIdentifier. */
88 #define BGPIDENTIFIER 0
90 /* BGP MIB bgpRcvdPathAttrTable */
91 #define BGPPATHATTRPEER 1
92 #define BGPPATHATTRDESTNETWORK 2
93 #define BGPPATHATTRORIGIN 3
94 #define BGPPATHATTRASPATH 4
95 #define BGPPATHATTRNEXTHOP 5
96 #define BGPPATHATTRINTERASMETRIC 6
98 /* BGP MIB bgp4PathAttrTable. */
99 #define BGP4PATHATTRPEER 1
100 #define BGP4PATHATTRIPADDRPREFIXLEN 2
101 #define BGP4PATHATTRIPADDRPREFIX 3
102 #define BGP4PATHATTRORIGIN 4
103 #define BGP4PATHATTRASPATHSEGMENT 5
104 #define BGP4PATHATTRNEXTHOP 6
105 #define BGP4PATHATTRMULTIEXITDISC 7
106 #define BGP4PATHATTRLOCALPREF 8
107 #define BGP4PATHATTRATOMICAGGREGATE 9
108 #define BGP4PATHATTRAGGREGATORAS 10
109 #define BGP4PATHATTRAGGREGATORADDR 11
110 #define BGP4PATHATTRCALCLOCALPREF 12
111 #define BGP4PATHATTRBEST 13
112 #define BGP4PATHATTRUNKNOWN 14
114 /* SNMP value hack. */
115 #define INTEGER ASN_INTEGER
116 #define INTEGER32 ASN_INTEGER
117 #define COUNTER32 ASN_COUNTER
118 #define OCTET_STRING ASN_OCTET_STR
119 #define IPADDRESS ASN_IPADDRESS
120 #define GAUGE32 ASN_UNSIGNED
122 /* Declare static local variables for convenience. */
125 /* BGP-MIB instances. */
126 oid bgp_oid
[] = { BGP4MIB
};
128 /* IP address 0.0.0.0. */
129 static struct in_addr bgp_empty_addr
= {0};
131 /* Hook functions. */
132 static u_char
*bgpVersion (struct variable
*, oid
[], size_t *, int,
133 size_t *, WriteMethod
**);
134 static u_char
*bgpLocalAs (struct variable
*, oid
[], size_t *,
135 int, size_t *, WriteMethod
**);
136 static u_char
*bgpPeerTable (struct variable
*, oid
[], size_t *,
137 int, size_t *, WriteMethod
**);
138 static u_char
*bgpRcvdPathAttrTable (struct variable
*, oid
[], size_t *,
139 int, size_t *, WriteMethod
**);
140 static u_char
*bgpIdentifier (struct variable
*, oid
[], size_t *,
141 int, size_t *, WriteMethod
**);
142 static u_char
*bgp4PathAttrTable (struct variable
*, oid
[], size_t *,
143 int, size_t *, WriteMethod
**);
144 /* static u_char *bgpTraps (); */
146 struct variable bgp_variables
[] =
149 {BGPVERSION
, OCTET_STRING
, RONLY
, bgpVersion
,
152 {BGPLOCALAS
, INTEGER
, RONLY
, bgpLocalAs
,
154 /* BGP peer table. */
155 {BGPPEERIDENTIFIER
, IPADDRESS
, RONLY
, bgpPeerTable
,
157 {BGPPEERSTATE
, INTEGER
, RONLY
, bgpPeerTable
,
159 {BGPPEERADMINSTATUS
, INTEGER
, RWRITE
, bgpPeerTable
,
161 {BGPPEERNEGOTIATEDVERSION
, INTEGER32
, RONLY
, bgpPeerTable
,
163 {BGPPEERLOCALADDR
, IPADDRESS
, RONLY
, bgpPeerTable
,
165 {BGPPEERLOCALPORT
, INTEGER
, RONLY
, bgpPeerTable
,
167 {BGPPEERREMOTEADDR
, IPADDRESS
, RONLY
, bgpPeerTable
,
169 {BGPPEERREMOTEPORT
, INTEGER
, RONLY
, bgpPeerTable
,
171 {BGPPEERREMOTEAS
, INTEGER
, RONLY
, bgpPeerTable
,
173 {BGPPEERINUPDATES
, COUNTER32
, RONLY
, bgpPeerTable
,
175 {BGPPEEROUTUPDATES
, COUNTER32
, RONLY
, bgpPeerTable
,
177 {BGPPEERINTOTALMESSAGES
, COUNTER32
, RONLY
, bgpPeerTable
,
179 {BGPPEEROUTTOTALMESSAGES
, COUNTER32
, RONLY
, bgpPeerTable
,
181 {BGPPEERLASTERROR
, OCTET_STRING
, RONLY
, bgpPeerTable
,
183 {BGPPEERFSMESTABLISHEDTRANSITIONS
, COUNTER32
, RONLY
, bgpPeerTable
,
185 {BGPPEERFSMESTABLISHEDTIME
, GAUGE32
, RONLY
, bgpPeerTable
,
187 {BGPPEERCONNECTRETRYINTERVAL
, INTEGER
, RWRITE
, bgpPeerTable
,
189 {BGPPEERHOLDTIME
, INTEGER
, RONLY
, bgpPeerTable
,
191 {BGPPEERKEEPALIVE
, INTEGER
, RONLY
, bgpPeerTable
,
193 {BGPPEERHOLDTIMECONFIGURED
, INTEGER
, RWRITE
, bgpPeerTable
,
195 {BGPPEERKEEPALIVECONFIGURED
, INTEGER
, RWRITE
, bgpPeerTable
,
197 {BGPPEERMINASORIGINATIONINTERVAL
, INTEGER
, RWRITE
, bgpPeerTable
,
199 {BGPPEERMINROUTEADVERTISEMENTINTERVAL
, INTEGER
, RWRITE
, bgpPeerTable
,
201 {BGPPEERINUPDATEELAPSEDTIME
, GAUGE32
, RONLY
, bgpPeerTable
,
203 /* BGP identifier. */
204 {BGPIDENTIFIER
, IPADDRESS
, RONLY
, bgpIdentifier
,
206 /* BGP received path attribute table. */
207 {BGPPATHATTRPEER
, IPADDRESS
, RONLY
, bgpRcvdPathAttrTable
,
209 {BGPPATHATTRDESTNETWORK
, IPADDRESS
, RONLY
, bgpRcvdPathAttrTable
,
211 {BGPPATHATTRORIGIN
, INTEGER
, RONLY
, bgpRcvdPathAttrTable
,
213 {BGPPATHATTRASPATH
, OCTET_STRING
, RONLY
, bgpRcvdPathAttrTable
,
215 {BGPPATHATTRNEXTHOP
, IPADDRESS
, RONLY
, bgpRcvdPathAttrTable
,
217 {BGPPATHATTRINTERASMETRIC
, INTEGER32
, RONLY
, bgpRcvdPathAttrTable
,
219 /* BGP-4 received path attribute table. */
220 {BGP4PATHATTRPEER
, IPADDRESS
, RONLY
, bgp4PathAttrTable
,
222 {BGP4PATHATTRIPADDRPREFIXLEN
, INTEGER
, RONLY
, bgp4PathAttrTable
,
224 {BGP4PATHATTRIPADDRPREFIX
, IPADDRESS
, RONLY
, bgp4PathAttrTable
,
226 {BGP4PATHATTRORIGIN
, INTEGER
, RONLY
, bgp4PathAttrTable
,
228 {BGP4PATHATTRASPATHSEGMENT
, OCTET_STRING
, RONLY
, bgp4PathAttrTable
,
230 {BGP4PATHATTRNEXTHOP
, IPADDRESS
, RONLY
, bgp4PathAttrTable
,
232 {BGP4PATHATTRMULTIEXITDISC
, INTEGER
, RONLY
, bgp4PathAttrTable
,
234 {BGP4PATHATTRLOCALPREF
, INTEGER
, RONLY
, bgp4PathAttrTable
,
236 {BGP4PATHATTRATOMICAGGREGATE
, INTEGER
, RONLY
, bgp4PathAttrTable
,
238 {BGP4PATHATTRAGGREGATORAS
, INTEGER
, RONLY
, bgp4PathAttrTable
,
240 {BGP4PATHATTRAGGREGATORADDR
, IPADDRESS
, RONLY
, bgp4PathAttrTable
,
242 {BGP4PATHATTRCALCLOCALPREF
, INTEGER
, RONLY
, bgp4PathAttrTable
,
244 {BGP4PATHATTRBEST
, INTEGER
, RONLY
, bgp4PathAttrTable
,
246 {BGP4PATHATTRUNKNOWN
, OCTET_STRING
, RONLY
, bgp4PathAttrTable
,
252 bgpVersion (struct variable
*v
, oid name
[], size_t *length
, int exact
,
253 size_t *var_len
, WriteMethod
**write_method
)
255 static u_char version
;
257 if (smux_header_generic(v
, name
, length
, exact
, var_len
, write_method
)
261 /* Retrun BGP version. Zebra bgpd only support version 4. */
262 version
= (0x80 >> (BGP_VERSION_4
- 1));
264 /* Return octet string length 1. */
266 return (u_char
*)&version
;
270 bgpLocalAs (struct variable
*v
, oid name
[], size_t *length
,
271 int exact
, size_t *var_len
, WriteMethod
**write_method
)
275 if (smux_header_generic(v
, name
, length
, exact
, var_len
, write_method
)
279 /* Get BGP structure. */
280 bgp
= bgp_get_default ();
284 return SNMP_INTEGER (bgp
->as
);
288 peer_lookup_addr_ipv4 (struct in_addr
*src
)
292 struct listnode
*node
;
296 bgp
= bgp_get_default ();
300 for (ALL_LIST_ELEMENTS_RO (bgp
->peer
, node
, peer
))
302 ret
= inet_pton (AF_INET
, peer
->host
, &addr
);
305 if (IPV4_ADDR_SAME (&addr
, src
))
313 bgp_peer_lookup_next (struct in_addr
*src
)
317 struct listnode
*node
;
322 memset (&su
, 0, sizeof (union sockunion
));
324 bgp
= bgp_get_default ();
328 for (ALL_LIST_ELEMENTS_RO (bgp
->peer
, node
, peer
))
330 ret
= inet_pton (AF_INET
, peer
->host
, &su
.sin
.sin_addr
);
333 p
= &su
.sin
.sin_addr
;
335 if (ntohl (p
->s_addr
) > ntohl (src
->s_addr
))
337 src
->s_addr
= p
->s_addr
;
346 bgpPeerTable_lookup (struct variable
*v
, oid name
[], size_t *length
,
347 struct in_addr
*addr
, int exact
)
349 struct peer
*peer
= NULL
;
354 /* Check the length. */
355 if (*length
- v
->namelen
!= sizeof (struct in_addr
))
358 oid2in_addr (name
+ v
->namelen
, IN_ADDR_SIZE
, addr
);
360 peer
= peer_lookup_addr_ipv4 (addr
);
365 len
= *length
- v
->namelen
;
366 if (len
> 4) len
= 4;
368 oid2in_addr (name
+ v
->namelen
, len
, addr
);
370 peer
= bgp_peer_lookup_next (addr
);
375 oid_copy_addr (name
+ v
->namelen
, addr
, sizeof (struct in_addr
));
376 *length
= sizeof (struct in_addr
) + v
->namelen
;
383 /* BGP write methods. */
385 write_bgpPeerTable (int action
, u_char
*var_val
,
386 u_char var_val_type
, size_t var_val_len
,
387 u_char
*statP
, oid
*name
, size_t length
,
393 size_t bigsize
= SNMP_MAX_LEN
;
395 if (var_val_type
!= ASN_INTEGER
)
397 return SNMP_ERR_WRONGTYPE
;
399 if (var_val_len
!= sizeof (long))
401 return SNMP_ERR_WRONGLENGTH
;
404 if (! asn_parse_int(var_val
, &bigsize
, &var_val_type
,
405 &intval
, sizeof(long)))
407 return SNMP_ERR_WRONGENCODING
;
410 memset (&addr
, 0, sizeof (struct in_addr
));
412 peer
= bgpPeerTable_lookup (v
, name
, &length
, &addr
, 1);
414 return SNMP_ERR_NOSUCHNAME
;
416 printf ("val: %ld\n", intval
);
420 case BGPPEERADMINSTATUS
:
421 #define BGP_PeerAdmin_stop 1
422 #define BGP_PeerAdmin_start 2
423 /* When the peer is established, */
424 if (intval
== BGP_PeerAdmin_stop
)
425 BGP_EVENT_ADD (peer
, BGP_Stop
);
426 else if (intval
== BGP_PeerAdmin_start
)
429 return SNMP_ERR_NOSUCHNAME
;
431 case BGPPEERCONNECTRETRYINTERVAL
:
432 SET_FLAG (peer
->config
, PEER_CONFIG_CONNECT
);
433 peer
->connect
= intval
;
434 peer
->v_connect
= intval
;
436 case BGPPEERHOLDTIMECONFIGURED
:
437 SET_FLAG (peer
->config
, PEER_CONFIG_TIMER
);
438 peer
->holdtime
= intval
;
439 peer
->v_holdtime
= intval
;
441 case BGPPEERKEEPALIVECONFIGURED
:
442 SET_FLAG (peer
->config
, PEER_CONFIG_TIMER
);
443 peer
->keepalive
= intval
;
444 peer
->v_keepalive
= intval
;
446 case BGPPEERMINASORIGINATIONINTERVAL
:
447 peer
->v_asorig
= intval
;
449 case BGPPEERMINROUTEADVERTISEMENTINTERVAL
:
450 peer
->v_routeadv
= intval
;
453 return SNMP_ERR_NOERROR
;
457 bgpPeerTable (struct variable
*v
, oid name
[], size_t *length
,
458 int exact
, size_t *var_len
, WriteMethod
**write_method
)
460 static struct in_addr addr
;
463 *write_method
= NULL
;
464 memset (&addr
, 0, sizeof (struct in_addr
));
466 peer
= bgpPeerTable_lookup (v
, name
, length
, &addr
, exact
);
472 case BGPPEERIDENTIFIER
:
473 return SNMP_IPADDRESS (peer
->remote_id
);
476 return SNMP_INTEGER (peer
->status
);
478 case BGPPEERADMINSTATUS
:
479 *write_method
= write_bgpPeerTable
;
480 #define BGP_PeerAdmin_stop 1
481 #define BGP_PeerAdmin_start 2
482 if (CHECK_FLAG (peer
->flags
, PEER_FLAG_SHUTDOWN
))
483 return SNMP_INTEGER (BGP_PeerAdmin_stop
);
485 return SNMP_INTEGER (BGP_PeerAdmin_start
);
487 case BGPPEERNEGOTIATEDVERSION
:
488 return SNMP_INTEGER (BGP_VERSION_4
);
490 case BGPPEERLOCALADDR
:
492 return SNMP_IPADDRESS (peer
->su_local
->sin
.sin_addr
);
494 return SNMP_IPADDRESS (bgp_empty_addr
);
496 case BGPPEERLOCALPORT
:
498 return SNMP_INTEGER (ntohs (peer
->su_local
->sin
.sin_port
));
500 return SNMP_INTEGER (0);
502 case BGPPEERREMOTEADDR
:
504 return SNMP_IPADDRESS (peer
->su_remote
->sin
.sin_addr
);
506 return SNMP_IPADDRESS (bgp_empty_addr
);
508 case BGPPEERREMOTEPORT
:
510 return SNMP_INTEGER (ntohs (peer
->su_remote
->sin
.sin_port
));
512 return SNMP_INTEGER (0);
514 case BGPPEERREMOTEAS
:
515 return SNMP_INTEGER (peer
->as
);
517 case BGPPEERINUPDATES
:
518 return SNMP_INTEGER (peer
->update_in
);
520 case BGPPEEROUTUPDATES
:
521 return SNMP_INTEGER (peer
->update_out
);
523 case BGPPEERINTOTALMESSAGES
:
524 return SNMP_INTEGER (peer
->open_in
+ peer
->update_in
525 + peer
->keepalive_in
+ peer
->notify_in
526 + peer
->refresh_in
+ peer
->dynamic_cap_in
);
528 case BGPPEEROUTTOTALMESSAGES
:
529 return SNMP_INTEGER (peer
->open_out
+ peer
->update_out
530 + peer
->keepalive_out
+ peer
->notify_out
531 + peer
->refresh_out
+ peer
->dynamic_cap_out
);
533 case BGPPEERLASTERROR
:
535 static u_char lasterror
[2];
536 lasterror
[0] = peer
->notify
.code
;
537 lasterror
[1] = peer
->notify
.subcode
;
539 return (u_char
*)&lasterror
;
542 case BGPPEERFSMESTABLISHEDTRANSITIONS
:
543 return SNMP_INTEGER (peer
->established
);
545 case BGPPEERFSMESTABLISHEDTIME
:
546 if (peer
->uptime
== 0)
547 return SNMP_INTEGER (0);
549 return SNMP_INTEGER (time (NULL
) - peer
->uptime
);
551 case BGPPEERCONNECTRETRYINTERVAL
:
552 *write_method
= write_bgpPeerTable
;
553 return SNMP_INTEGER (peer
->v_connect
);
555 case BGPPEERHOLDTIME
:
556 return SNMP_INTEGER (peer
->v_holdtime
);
558 case BGPPEERKEEPALIVE
:
559 return SNMP_INTEGER (peer
->v_keepalive
);
561 case BGPPEERHOLDTIMECONFIGURED
:
562 *write_method
= write_bgpPeerTable
;
563 if (CHECK_FLAG (peer
->config
, PEER_CONFIG_TIMER
))
564 return SNMP_INTEGER (peer
->holdtime
);
566 return SNMP_INTEGER (peer
->v_holdtime
);
568 case BGPPEERKEEPALIVECONFIGURED
:
569 *write_method
= write_bgpPeerTable
;
570 if (CHECK_FLAG (peer
->config
, PEER_CONFIG_TIMER
))
571 return SNMP_INTEGER (peer
->keepalive
);
573 return SNMP_INTEGER (peer
->v_keepalive
);
575 case BGPPEERMINASORIGINATIONINTERVAL
:
576 *write_method
= write_bgpPeerTable
;
577 return SNMP_INTEGER (peer
->v_asorig
);
579 case BGPPEERMINROUTEADVERTISEMENTINTERVAL
:
580 *write_method
= write_bgpPeerTable
;
581 return SNMP_INTEGER (peer
->v_routeadv
);
583 case BGPPEERINUPDATEELAPSEDTIME
:
584 if (peer
->update_time
== 0)
585 return SNMP_INTEGER (0);
587 return SNMP_INTEGER (time (NULL
) - peer
->update_time
);
597 bgpIdentifier (struct variable
*v
, oid name
[], size_t *length
,
598 int exact
, size_t *var_len
, WriteMethod
**write_method
)
602 if (smux_header_generic(v
, name
, length
, exact
, var_len
, write_method
)
606 bgp
= bgp_get_default ();
610 return SNMP_IPADDRESS (bgp
->router_id
);
614 bgpRcvdPathAttrTable (struct variable
*v
, oid name
[], size_t *length
,
615 int exact
, size_t *var_len
, WriteMethod
**write_method
)
617 /* Received Path Attribute Table. This table contains, one entry
618 per path to a network, path attributes received from all peers
619 running BGP version 3 or less. This table is obsolete, having
620 been replaced in functionality with the bgp4PathAttrTable. */
624 static struct bgp_info
*
625 bgp4PathAttrLookup (struct variable
*v
, oid name
[], size_t *length
,
626 struct bgp
*bgp
, struct prefix_ipv4
*addr
, int exact
)
630 struct bgp_info
*binfo
;
631 struct bgp_info
*min
;
635 struct in_addr paddr
;
637 #define BGP_PATHATTR_ENTRY_OFFSET \
638 (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE)
642 if (*length
- v
->namelen
!= BGP_PATHATTR_ENTRY_OFFSET
)
645 /* Set OID offset for prefix. */
646 offset
= name
+ v
->namelen
;
647 oid2in_addr (offset
, IN_ADDR_SIZE
, &addr
->prefix
);
648 offset
+= IN_ADDR_SIZE
;
651 addr
->prefixlen
= *offset
;
655 su
.sin
.sin_family
= AF_INET
;
656 oid2in_addr (offset
, IN_ADDR_SIZE
, &su
.sin
.sin_addr
);
659 rn
= bgp_node_lookup (bgp
->rib
[AFI_IP
][SAFI_UNICAST
],
660 (struct prefix
*) addr
);
663 bgp_unlock_node (rn
);
665 for (binfo
= rn
->info
; binfo
; binfo
= binfo
->next
)
666 if (sockunion_same (&binfo
->peer
->su
, &su
))
672 offset
= name
+ v
->namelen
;
673 offsetlen
= *length
- v
->namelen
;
677 rn
= bgp_table_top (bgp
->rib
[AFI_IP
][SAFI_UNICAST
]);
680 if (len
> IN_ADDR_SIZE
)
683 oid2in_addr (offset
, len
, &addr
->prefix
);
685 offset
+= IN_ADDR_SIZE
;
686 offsetlen
-= IN_ADDR_SIZE
;
689 addr
->prefixlen
= *offset
;
691 addr
->prefixlen
= len
* 8;
693 rn
= bgp_node_get (bgp
->rib
[AFI_IP
][SAFI_UNICAST
],
694 (struct prefix
*) addr
);
703 if (len
> IN_ADDR_SIZE
)
706 oid2in_addr (offset
, len
, &paddr
);
718 for (binfo
= rn
->info
; binfo
; binfo
= binfo
->next
)
720 if (binfo
->peer
->su
.sin
.sin_family
== AF_INET
721 && ntohl (paddr
.s_addr
)
722 < ntohl (binfo
->peer
->su
.sin
.sin_addr
.s_addr
))
726 if (ntohl (binfo
->peer
->su
.sin
.sin_addr
.s_addr
)
727 < ntohl (min
->peer
->su
.sin
.sin_addr
.s_addr
))
737 *length
= v
->namelen
+ BGP_PATHATTR_ENTRY_OFFSET
;
739 offset
= name
+ v
->namelen
;
740 oid_copy_addr (offset
, &rn
->p
.u
.prefix4
, IN_ADDR_SIZE
);
741 offset
+= IN_ADDR_SIZE
;
742 *offset
= rn
->p
.prefixlen
;
744 oid_copy_addr (offset
, &min
->peer
->su
.sin
.sin_addr
,
746 addr
->prefix
= rn
->p
.u
.prefix4
;
747 addr
->prefixlen
= rn
->p
.prefixlen
;
749 bgp_unlock_node (rn
);
756 while ((rn
= bgp_route_next (rn
)) != NULL
);
762 bgp4PathAttrTable (struct variable
*v
, oid name
[], size_t *length
,
763 int exact
, size_t *var_len
, WriteMethod
**write_method
)
766 struct bgp_info
*binfo
;
767 struct prefix_ipv4 addr
;
769 bgp
= bgp_get_default ();
773 memset (&addr
, 0, sizeof (struct prefix_ipv4
));
775 binfo
= bgp4PathAttrLookup (v
, name
, length
, bgp
, &addr
, exact
);
781 case BGP4PATHATTRPEER
: /* 1 */
782 return SNMP_IPADDRESS (binfo
->peer
->su
.sin
.sin_addr
);
784 case BGP4PATHATTRIPADDRPREFIXLEN
: /* 2 */
785 return SNMP_INTEGER (addr
.prefixlen
);
787 case BGP4PATHATTRIPADDRPREFIX
: /* 3 */
788 return SNMP_IPADDRESS (addr
.prefix
);
790 case BGP4PATHATTRORIGIN
: /* 4 */
791 return SNMP_INTEGER (binfo
->attr
->origin
);
793 case BGP4PATHATTRASPATHSEGMENT
: /* 5 */
794 return aspath_snmp_pathseg (binfo
->attr
->aspath
, var_len
);
796 case BGP4PATHATTRNEXTHOP
: /* 6 */
797 return SNMP_IPADDRESS (binfo
->attr
->nexthop
);
799 case BGP4PATHATTRMULTIEXITDISC
: /* 7 */
800 return SNMP_INTEGER (binfo
->attr
->med
);
802 case BGP4PATHATTRLOCALPREF
: /* 8 */
803 return SNMP_INTEGER (binfo
->attr
->local_pref
);
805 case BGP4PATHATTRATOMICAGGREGATE
: /* 9 */
806 return SNMP_INTEGER (1);
808 case BGP4PATHATTRAGGREGATORAS
: /* 10 */
809 if (binfo
->attr
->extra
)
810 return SNMP_INTEGER (binfo
->attr
->extra
->aggregator_as
);
812 return SNMP_INTEGER (0);
814 case BGP4PATHATTRAGGREGATORADDR
: /* 11 */
815 if (binfo
->attr
->extra
)
816 return SNMP_IPADDRESS (binfo
->attr
->extra
->aggregator_addr
);
818 return SNMP_INTEGER (0);
820 case BGP4PATHATTRCALCLOCALPREF
: /* 12 */
821 return SNMP_INTEGER (-1);
823 case BGP4PATHATTRBEST
: /* 13 */
824 #define BGP4_PathAttrBest_false 1
825 #define BGP4_PathAttrBest_true 2
826 if (CHECK_FLAG (binfo
->flags
, BGP_INFO_SELECTED
))
827 return SNMP_INTEGER (BGP4_PathAttrBest_true
);
829 return SNMP_INTEGER (BGP4_PathAttrBest_false
);
831 case BGP4PATHATTRUNKNOWN
: /* 14 */
840 struct trap_object bgpTrapList
[] =
842 {bgpPeerTable
, 3, {3, 1, BGPPEERLASTERROR
}},
843 {bgpPeerTable
, 3, {3, 1, BGPPEERSTATE
}}
847 bgpTrapEstablished (struct peer
*peer
)
851 oid index
[sizeof (oid
) * IN_ADDR_SIZE
];
853 ret
= inet_aton (peer
->host
, &addr
);
857 oid_copy_addr (index
, &addr
, IN_ADDR_SIZE
);
859 smux_trap (bgp_oid
, sizeof bgp_oid
/ sizeof (oid
),
861 bgpTrapList
, sizeof bgpTrapList
/ sizeof (struct trap_object
),
862 bm
->start_time
- time (NULL
), BGPESTABLISHED
);
866 bgpTrapBackwardTransition (struct peer
*peer
)
870 oid index
[sizeof (oid
) * IN_ADDR_SIZE
];
872 ret
= inet_aton (peer
->host
, &addr
);
876 oid_copy_addr (index
, &addr
, IN_ADDR_SIZE
);
878 smux_trap (bgp_oid
, sizeof bgp_oid
/ sizeof (oid
),
880 bgpTrapList
, sizeof bgpTrapList
/ sizeof (struct trap_object
),
881 bm
->start_time
- time (NULL
), BGPBACKWARDTRANSITION
);
887 smux_init (bm
->master
);
888 REGISTER_MIB("mibII/bgp", bgp_variables
, variable
, bgp_oid
);
890 #endif /* HAVE_SNMP */