]> git.proxmox.com Git - mirror_frr.git/blob - bgpd/bgp_snmp_bgp4.c
Merge pull request #12728 from opensourcerouting/feature/bgp_neighbor_path-attribute_...
[mirror_frr.git] / bgpd / bgp_snmp_bgp4.c
1 /* BGP4 SNMP support
2 * Copyright (C) 1999, 2000 Kunihiro Ishiguro
3 *
4 * This file is part of GNU Zebra.
5 *
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
9 * later version.
10 *
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.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <zebra.h>
22
23 #include <net-snmp/net-snmp-config.h>
24 #include <net-snmp/net-snmp-includes.h>
25
26 #include "if.h"
27 #include "log.h"
28 #include "prefix.h"
29 #include "command.h"
30 #include "thread.h"
31 #include "smux.h"
32 #include "filter.h"
33 #include "hook.h"
34 #include "libfrr.h"
35
36 #include "bgpd/bgpd.h"
37 #include "bgpd/bgp_table.h"
38 #include "bgpd/bgp_aspath.h"
39 #include "bgpd/bgp_attr.h"
40 #include "bgpd/bgp_route.h"
41 #include "bgpd/bgp_fsm.h"
42 #include "bgpd/bgp_snmp.h"
43 #include "bgpd/bgp_snmp_bgp4.h"
44 #include "bgpd/bgp_mplsvpn_snmp.h"
45
46 /* Declare static local variables for convenience. */
47 SNMP_LOCAL_VARIABLES
48
49 /* BGP-MIB instances. */
50 static oid bgp_oid[] = {BGP4MIB};
51 static oid bgp_trap_oid[] = {BGP4MIB, 0};
52
53 /* IP address 0.0.0.0. */
54 static struct in_addr bgp_empty_addr = {.s_addr = 0};
55
56 static uint8_t *bgpVersion(struct variable *v, oid name[], size_t *length,
57 int exact, size_t *var_len,
58 WriteMethod **write_method)
59 {
60 static uint8_t version;
61
62 if (smux_header_generic(v, name, length, exact, var_len,
63 write_method) == MATCH_FAILED)
64 return NULL;
65
66 /* Return BGP version. Zebra bgpd only support version 4. */
67 version = (0x80 >> (BGP_VERSION_4 - 1));
68
69 /* Return octet string length 1. */
70 *var_len = 1;
71 return &version;
72 }
73
74 static uint8_t *bgpLocalAs(struct variable *v, oid name[], size_t *length,
75 int exact, size_t *var_len,
76 WriteMethod **write_method)
77 {
78 struct bgp *bgp;
79
80 if (smux_header_generic(v, name, length, exact, var_len,
81 write_method) == MATCH_FAILED)
82 return NULL;
83
84 /* Get BGP structure. */
85 bgp = bgp_get_default();
86 if (!bgp)
87 return NULL;
88
89 return SNMP_INTEGER(bgp->as);
90 }
91
92 static struct peer *peer_lookup_addr_ipv4(struct in_addr *src)
93 {
94 struct bgp *bgp;
95 struct peer *peer;
96 struct listnode *node;
97 struct listnode *bgpnode;
98
99 for (ALL_LIST_ELEMENTS_RO(bm->bgp, bgpnode, bgp)) {
100 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) {
101 if (sockunion_family(&peer->su) != AF_INET)
102 continue;
103
104 if (sockunion2ip(&peer->su) == src->s_addr)
105 return peer;
106 }
107 }
108
109 return NULL;
110 }
111
112 static struct peer *bgp_peer_lookup_next(struct in_addr *src)
113 {
114 struct bgp *bgp;
115 struct peer *peer;
116 struct peer *next_peer = NULL;
117 struct listnode *node;
118 struct listnode *bgpnode;
119
120 for (ALL_LIST_ELEMENTS_RO(bm->bgp, bgpnode, bgp)) {
121 for (ALL_LIST_ELEMENTS_RO(bgp->peer, node, peer)) {
122 if (sockunion_family(&peer->su) != AF_INET)
123 continue;
124 if (ntohl(sockunion2ip(&peer->su)) <=
125 ntohl(src->s_addr))
126 continue;
127
128 if (!next_peer ||
129 ntohl(sockunion2ip(&next_peer->su)) >
130 ntohl(sockunion2ip(&peer->su))) {
131 next_peer = peer;
132 }
133 }
134 }
135
136 if (next_peer) {
137 src->s_addr = sockunion2ip(&next_peer->su);
138 return next_peer;
139 }
140
141 return NULL;
142 }
143
144 /* 1.3.6.1.2.1.15.3.1.x = 10 */
145 #define PEERTAB_NAMELEN 10
146
147 static struct peer *bgpPeerTable_lookup(struct variable *v, oid name[],
148 size_t *length, struct in_addr *addr,
149 int exact)
150 {
151 struct peer *peer = NULL;
152 size_t namelen = v ? v->namelen : PEERTAB_NAMELEN;
153 int len;
154
155 if (exact) {
156 /* Check the length. */
157 if (*length - namelen != sizeof(struct in_addr))
158 return NULL;
159
160 oid2in_addr(name + namelen, IN_ADDR_SIZE, addr);
161
162 peer = peer_lookup_addr_ipv4(addr);
163 return peer;
164 } else {
165 len = *length - namelen;
166 if (len > 4)
167 len = 4;
168
169 oid2in_addr(name + namelen, len, addr);
170
171 peer = bgp_peer_lookup_next(addr);
172
173 if (peer == NULL)
174 return NULL;
175
176 oid_copy_in_addr(name + namelen, addr);
177 *length = sizeof(struct in_addr) + namelen;
178
179 return peer;
180 }
181 return NULL;
182 }
183
184 /* BGP write methods. */
185 static int write_bgpPeerTable(int action, uint8_t *var_val,
186 uint8_t var_val_type, size_t var_val_len,
187 uint8_t *statP, oid *name, size_t length)
188 {
189 struct in_addr addr;
190 struct peer *peer;
191 long intval;
192
193 if (var_val_type != ASN_INTEGER) {
194 return SNMP_ERR_WRONGTYPE;
195 }
196 if (var_val_len != sizeof(long)) {
197 return SNMP_ERR_WRONGLENGTH;
198 }
199
200 intval = *(long *)var_val;
201
202 memset(&addr, 0, sizeof(addr));
203
204 peer = bgpPeerTable_lookup(NULL, name, &length, &addr, 1);
205 if (!peer)
206 return SNMP_ERR_NOSUCHNAME;
207
208 if (action != SNMP_MSG_INTERNAL_SET_COMMIT)
209 return SNMP_ERR_NOERROR;
210
211 zlog_info("%s: SNMP write .%ld = %ld", peer->host,
212 (long)name[PEERTAB_NAMELEN - 1], intval);
213
214 switch (name[PEERTAB_NAMELEN - 1]) {
215 case BGPPEERADMINSTATUS:
216 #define BGP_PeerAdmin_stop 1
217 #define BGP_PeerAdmin_start 2
218 /* When the peer is established, */
219 if (intval == BGP_PeerAdmin_stop)
220 BGP_EVENT_ADD(peer, BGP_Stop);
221 else if (intval == BGP_PeerAdmin_start)
222 ; /* Do nothing. */
223 else
224 return SNMP_ERR_NOSUCHNAME;
225 break;
226 case BGPPEERCONNECTRETRYINTERVAL:
227 peer_flag_set(peer, PEER_FLAG_TIMER_CONNECT);
228 peer->connect = intval;
229 peer->v_connect = intval;
230 break;
231 case BGPPEERHOLDTIMECONFIGURED:
232 peer_flag_set(peer, PEER_FLAG_TIMER);
233 peer->holdtime = intval;
234 peer->v_holdtime = intval;
235 break;
236 case BGPPEERKEEPALIVECONFIGURED:
237 peer_flag_set(peer, PEER_FLAG_TIMER);
238 peer->keepalive = intval;
239 peer->v_keepalive = intval;
240 break;
241 case BGPPEERMINROUTEADVERTISEMENTINTERVAL:
242 peer->v_routeadv = intval;
243 break;
244 }
245 return SNMP_ERR_NOERROR;
246 }
247
248 static uint8_t *bgpPeerTable(struct variable *v, oid name[], size_t *length,
249 int exact, size_t *var_len,
250 WriteMethod **write_method)
251 {
252 static struct in_addr addr;
253 struct peer *peer;
254 uint32_t ui, uo;
255
256 if (smux_header_table(v, name, length, exact, var_len, write_method) ==
257 MATCH_FAILED)
258 return NULL;
259 memset(&addr, 0, sizeof(addr));
260
261 peer = bgpPeerTable_lookup(v, name, length, &addr, exact);
262 if (!peer)
263 return NULL;
264
265 switch (v->magic) {
266 case BGPPEERIDENTIFIER:
267 return SNMP_IPADDRESS(peer->remote_id);
268 case BGPPEERSTATE:
269 return SNMP_INTEGER(peer->status);
270 case BGPPEERADMINSTATUS:
271 *write_method = write_bgpPeerTable;
272 #define BGP_PeerAdmin_stop 1
273 #define BGP_PeerAdmin_start 2
274 if (CHECK_FLAG(peer->flags, PEER_FLAG_SHUTDOWN))
275 return SNMP_INTEGER(BGP_PeerAdmin_stop);
276 else
277 return SNMP_INTEGER(BGP_PeerAdmin_start);
278 case BGPPEERNEGOTIATEDVERSION:
279 return SNMP_INTEGER(BGP_VERSION_4);
280 case BGPPEERLOCALADDR:
281 if (peer->su_local)
282 return SNMP_IPADDRESS(peer->su_local->sin.sin_addr);
283 else
284 return SNMP_IPADDRESS(bgp_empty_addr);
285 case BGPPEERLOCALPORT:
286 if (peer->su_local)
287 return SNMP_INTEGER(
288 ntohs(peer->su_local->sin.sin_port));
289 else
290 return SNMP_INTEGER(0);
291 case BGPPEERREMOTEADDR:
292 if (peer->su_remote)
293 return SNMP_IPADDRESS(peer->su_remote->sin.sin_addr);
294 else
295 return SNMP_IPADDRESS(bgp_empty_addr);
296 case BGPPEERREMOTEPORT:
297 if (peer->su_remote)
298 return SNMP_INTEGER(
299 ntohs(peer->su_remote->sin.sin_port));
300 else
301 return SNMP_INTEGER(0);
302 case BGPPEERREMOTEAS:
303 return SNMP_INTEGER(peer->as);
304 case BGPPEERINUPDATES:
305 ui = atomic_load_explicit(&peer->update_in,
306 memory_order_relaxed);
307 return SNMP_INTEGER(ui);
308 case BGPPEEROUTUPDATES:
309 uo = atomic_load_explicit(&peer->update_out,
310 memory_order_relaxed);
311 return SNMP_INTEGER(uo);
312 case BGPPEERINTOTALMESSAGES:
313 return SNMP_INTEGER(PEER_TOTAL_RX(peer));
314 case BGPPEEROUTTOTALMESSAGES:
315 return SNMP_INTEGER(PEER_TOTAL_TX(peer));
316 case BGPPEERLASTERROR: {
317 static uint8_t lasterror[2];
318 lasterror[0] = peer->notify.code;
319 lasterror[1] = peer->notify.subcode;
320 *var_len = 2;
321 return (uint8_t *)&lasterror;
322 }
323 case BGPPEERFSMESTABLISHEDTRANSITIONS:
324 return SNMP_INTEGER(peer->established);
325 case BGPPEERFSMESTABLISHEDTIME:
326 if (peer->uptime == 0)
327 return SNMP_INTEGER(0);
328 else
329 return SNMP_INTEGER(monotime(NULL) - peer->uptime);
330 case BGPPEERCONNECTRETRYINTERVAL:
331 *write_method = write_bgpPeerTable;
332 return SNMP_INTEGER(peer->v_connect);
333 case BGPPEERHOLDTIME:
334 return SNMP_INTEGER(peer->v_holdtime);
335 case BGPPEERKEEPALIVE:
336 return SNMP_INTEGER(peer->v_keepalive);
337 case BGPPEERHOLDTIMECONFIGURED:
338 *write_method = write_bgpPeerTable;
339 if (CHECK_FLAG(peer->flags, PEER_FLAG_TIMER))
340 return SNMP_INTEGER(peer->holdtime);
341 else
342 return SNMP_INTEGER(peer->v_holdtime);
343 case BGPPEERKEEPALIVECONFIGURED:
344 *write_method = write_bgpPeerTable;
345 if (CHECK_FLAG(peer->flags, PEER_FLAG_TIMER))
346 return SNMP_INTEGER(peer->keepalive);
347 else
348 return SNMP_INTEGER(peer->v_keepalive);
349 case BGPPEERMINROUTEADVERTISEMENTINTERVAL:
350 *write_method = write_bgpPeerTable;
351 return SNMP_INTEGER(peer->v_routeadv);
352 case BGPPEERINUPDATEELAPSEDTIME:
353 if (peer->update_time == 0)
354 return SNMP_INTEGER(0);
355 else
356 return SNMP_INTEGER(monotime(NULL) - peer->update_time);
357 default:
358 return NULL;
359 }
360 return NULL;
361 }
362
363 static uint8_t *bgpIdentifier(struct variable *v, oid name[], size_t *length,
364 int exact, size_t *var_len,
365 WriteMethod **write_method)
366 {
367 struct bgp *bgp;
368
369 if (smux_header_generic(v, name, length, exact, var_len,
370 write_method) == MATCH_FAILED)
371 return NULL;
372
373 bgp = bgp_get_default();
374 if (!bgp)
375 return NULL;
376
377 return SNMP_IPADDRESS(bgp->router_id);
378 }
379
380 static uint8_t *bgpRcvdPathAttrTable(struct variable *v, oid name[],
381 size_t *length, int exact, size_t *var_len,
382 WriteMethod **write_method)
383 {
384 /* Received Path Attribute Table. This table contains, one entry
385 per path to a network, path attributes received from all peers
386 running BGP version 3 or less. This table is obsolete, having
387 been replaced in functionality with the bgp4PathAttrTable. */
388 return NULL;
389 }
390
391 static struct bgp_path_info *bgp4PathAttrLookup(struct variable *v, oid name[],
392 size_t *length, struct bgp *bgp,
393 struct prefix_ipv4 *addr,
394 int exact)
395 {
396 oid *offset;
397 int offsetlen;
398 struct bgp_path_info *path;
399 struct bgp_path_info *min;
400 struct bgp_dest *dest;
401 union sockunion su;
402 unsigned int len;
403 struct in_addr paddr;
404
405 sockunion_init(&su);
406
407 #define BGP_PATHATTR_ENTRY_OFFSET (IN_ADDR_SIZE + 1 + IN_ADDR_SIZE)
408
409 if (exact) {
410 if (*length - v->namelen != BGP_PATHATTR_ENTRY_OFFSET)
411 return NULL;
412
413 /* Set OID offset for prefix. */
414 offset = name + v->namelen;
415 oid2in_addr(offset, IN_ADDR_SIZE, &addr->prefix);
416 offset += IN_ADDR_SIZE;
417
418 /* Prefix length. */
419 addr->prefixlen = *offset;
420 offset++;
421
422 /* Peer address. */
423 su.sin.sin_family = AF_INET;
424 oid2in_addr(offset, IN_ADDR_SIZE, &su.sin.sin_addr);
425
426 /* Lookup node. */
427 dest = bgp_node_lookup(bgp->rib[AFI_IP][SAFI_UNICAST],
428 (struct prefix *)addr);
429 if (dest) {
430 for (path = bgp_dest_get_bgp_path_info(dest); path;
431 path = path->next)
432 if (sockunion_same(&path->peer->su, &su))
433 return path;
434
435 bgp_dest_unlock_node(dest);
436 }
437 } else {
438 offset = name + v->namelen;
439 offsetlen = *length - v->namelen;
440 len = offsetlen;
441
442 if (offsetlen == 0)
443 dest = bgp_table_top(bgp->rib[AFI_IP][SAFI_UNICAST]);
444 else {
445 if (len > IN_ADDR_SIZE)
446 len = IN_ADDR_SIZE;
447
448 oid2in_addr(offset, len, &addr->prefix);
449
450 offset += IN_ADDR_SIZE;
451 offsetlen -= IN_ADDR_SIZE;
452
453 if (offsetlen > 0)
454 addr->prefixlen = *offset;
455 else
456 addr->prefixlen = len * 8;
457
458 dest = bgp_node_get(bgp->rib[AFI_IP][SAFI_UNICAST],
459 (struct prefix *)addr);
460
461 offset++;
462 offsetlen--;
463 }
464
465 if (offsetlen > 0) {
466 len = offsetlen;
467 if (len > IN_ADDR_SIZE)
468 len = IN_ADDR_SIZE;
469
470 oid2in_addr(offset, len, &paddr);
471 } else
472 paddr.s_addr = INADDR_ANY;
473
474 if (!dest)
475 return NULL;
476
477 do {
478 min = NULL;
479
480 for (path = bgp_dest_get_bgp_path_info(dest); path;
481 path = path->next) {
482 if (path->peer->su.sin.sin_family == AF_INET &&
483 ntohl(paddr.s_addr) <
484 ntohl(path->peer->su.sin.sin_addr
485 .s_addr)) {
486 if (min) {
487 if (ntohl(path->peer->su.sin
488 .sin_addr
489 .s_addr) <
490 ntohl(min->peer->su.sin
491 .sin_addr
492 .s_addr))
493 min = path;
494 } else
495 min = path;
496 }
497 }
498
499 if (min) {
500 const struct prefix *rn_p =
501 bgp_dest_get_prefix(dest);
502
503 *length =
504 v->namelen + BGP_PATHATTR_ENTRY_OFFSET;
505
506 offset = name + v->namelen;
507 oid_copy_in_addr(offset, &rn_p->u.prefix4);
508 offset += IN_ADDR_SIZE;
509 *offset = rn_p->prefixlen;
510 offset++;
511 oid_copy_in_addr(offset,
512 &min->peer->su.sin.sin_addr);
513 addr->prefix = rn_p->u.prefix4;
514 addr->prefixlen = rn_p->prefixlen;
515
516 bgp_dest_unlock_node(dest);
517
518 return min;
519 }
520
521 paddr.s_addr = INADDR_ANY;
522 } while ((dest = bgp_route_next(dest)) != NULL);
523 }
524 return NULL;
525 }
526
527 static uint8_t *bgp4PathAttrTable(struct variable *v, oid name[],
528 size_t *length, int exact, size_t *var_len,
529 WriteMethod **write_method)
530 {
531 struct bgp *bgp;
532 struct bgp_path_info *path;
533 struct prefix_ipv4 addr;
534
535 bgp = bgp_get_default();
536 if (!bgp)
537 return NULL;
538
539 if (smux_header_table(v, name, length, exact, var_len, write_method) ==
540 MATCH_FAILED)
541 return NULL;
542 memset(&addr, 0, sizeof(addr));
543
544 path = bgp4PathAttrLookup(v, name, length, bgp, &addr, exact);
545 if (!path)
546 return NULL;
547
548 switch (v->magic) {
549 case BGP4PATHATTRPEER: /* 1 */
550 return SNMP_IPADDRESS(path->peer->su.sin.sin_addr);
551 case BGP4PATHATTRIPADDRPREFIXLEN: /* 2 */
552 return SNMP_INTEGER(addr.prefixlen);
553 case BGP4PATHATTRIPADDRPREFIX: /* 3 */
554 return SNMP_IPADDRESS(addr.prefix);
555 case BGP4PATHATTRORIGIN: /* 4 */
556 return SNMP_INTEGER(path->attr->origin);
557 case BGP4PATHATTRASPATHSEGMENT: /* 5 */
558 return aspath_snmp_pathseg(path->attr->aspath, var_len);
559 case BGP4PATHATTRNEXTHOP: /* 6 */
560 return SNMP_IPADDRESS(path->attr->nexthop);
561 case BGP4PATHATTRMULTIEXITDISC: /* 7 */
562 return SNMP_INTEGER(path->attr->med);
563 case BGP4PATHATTRLOCALPREF: /* 8 */
564 return SNMP_INTEGER(path->attr->local_pref);
565 case BGP4PATHATTRATOMICAGGREGATE: /* 9 */
566 return SNMP_INTEGER(1);
567 case BGP4PATHATTRAGGREGATORAS: /* 10 */
568 return SNMP_INTEGER(path->attr->aggregator_as);
569 case BGP4PATHATTRAGGREGATORADDR: /* 11 */
570 return SNMP_IPADDRESS(path->attr->aggregator_addr);
571 case BGP4PATHATTRCALCLOCALPREF: /* 12 */
572 return SNMP_INTEGER(-1);
573 case BGP4PATHATTRBEST: /* 13 */
574 #define BGP4_PathAttrBest_false 1
575 #define BGP4_PathAttrBest_true 2
576 if (CHECK_FLAG(path->flags, BGP_PATH_SELECTED))
577 return SNMP_INTEGER(BGP4_PathAttrBest_true);
578 else
579 return SNMP_INTEGER(BGP4_PathAttrBest_false);
580 case BGP4PATHATTRUNKNOWN: /* 14 */
581 *var_len = 0;
582 return NULL;
583 }
584 return NULL;
585 }
586
587 /* BGP Traps. */
588 static struct trap_object bgpTrapList[] = {{3, {3, 1, BGPPEERREMOTEADDR}},
589 {3, {3, 1, BGPPEERLASTERROR}},
590 {3, {3, 1, BGPPEERSTATE}}};
591
592 static struct variable bgp_variables[] = {
593 /* BGP version. */
594 {BGPVERSION, OCTET_STRING, RONLY, bgpVersion, 1, {1}},
595 /* BGP local AS. */
596 {BGPLOCALAS, INTEGER, RONLY, bgpLocalAs, 1, {2}},
597 /* BGP peer table. */
598 {BGPPEERIDENTIFIER, IPADDRESS, RONLY, bgpPeerTable, 3, {3, 1, 1}},
599 {BGPPEERSTATE, INTEGER, RONLY, bgpPeerTable, 3, {3, 1, 2}},
600 {BGPPEERADMINSTATUS, INTEGER, RWRITE, bgpPeerTable, 3, {3, 1, 3}},
601 {BGPPEERNEGOTIATEDVERSION,
602 INTEGER32,
603 RONLY,
604 bgpPeerTable,
605 3,
606 {3, 1, 4}},
607 {BGPPEERLOCALADDR, IPADDRESS, RONLY, bgpPeerTable, 3, {3, 1, 5}},
608 {BGPPEERLOCALPORT, INTEGER, RONLY, bgpPeerTable, 3, {3, 1, 6}},
609 {BGPPEERREMOTEADDR, IPADDRESS, RONLY, bgpPeerTable, 3, {3, 1, 7}},
610 {BGPPEERREMOTEPORT, INTEGER, RONLY, bgpPeerTable, 3, {3, 1, 8}},
611 {BGPPEERREMOTEAS, INTEGER, RONLY, bgpPeerTable, 3, {3, 1, 9}},
612 {BGPPEERINUPDATES, COUNTER32, RONLY, bgpPeerTable, 3, {3, 1, 10}},
613 {BGPPEEROUTUPDATES, COUNTER32, RONLY, bgpPeerTable, 3, {3, 1, 11}},
614 {BGPPEERINTOTALMESSAGES, COUNTER32, RONLY, bgpPeerTable, 3, {3, 1, 12}},
615 {BGPPEEROUTTOTALMESSAGES,
616 COUNTER32,
617 RONLY,
618 bgpPeerTable,
619 3,
620 {3, 1, 13}},
621 {BGPPEERLASTERROR, OCTET_STRING, RONLY, bgpPeerTable, 3, {3, 1, 14}},
622 {BGPPEERFSMESTABLISHEDTRANSITIONS,
623 COUNTER32,
624 RONLY,
625 bgpPeerTable,
626 3,
627 {3, 1, 15}},
628 {BGPPEERFSMESTABLISHEDTIME,
629 GAUGE32,
630 RONLY,
631 bgpPeerTable,
632 3,
633 {3, 1, 16}},
634 {BGPPEERCONNECTRETRYINTERVAL,
635 INTEGER,
636 RWRITE,
637 bgpPeerTable,
638 3,
639 {3, 1, 17}},
640 {BGPPEERHOLDTIME, INTEGER, RONLY, bgpPeerTable, 3, {3, 1, 18}},
641 {BGPPEERKEEPALIVE, INTEGER, RONLY, bgpPeerTable, 3, {3, 1, 19}},
642 {BGPPEERHOLDTIMECONFIGURED,
643 INTEGER,
644 RWRITE,
645 bgpPeerTable,
646 3,
647 {3, 1, 20}},
648 {BGPPEERKEEPALIVECONFIGURED,
649 INTEGER,
650 RWRITE,
651 bgpPeerTable,
652 3,
653 {3, 1, 21}},
654 {BGPPEERMINROUTEADVERTISEMENTINTERVAL,
655 INTEGER,
656 RWRITE,
657 bgpPeerTable,
658 3,
659 {3, 1, 23}},
660 {BGPPEERINUPDATEELAPSEDTIME,
661 GAUGE32,
662 RONLY,
663 bgpPeerTable,
664 3,
665 {3, 1, 24}},
666 /* BGP identifier. */
667 {BGPIDENTIFIER, IPADDRESS, RONLY, bgpIdentifier, 1, {4}},
668 /* BGP received path attribute table. */
669 {BGPPATHATTRPEER, IPADDRESS, RONLY, bgpRcvdPathAttrTable, 3, {5, 1, 1}},
670 {BGPPATHATTRDESTNETWORK,
671 IPADDRESS,
672 RONLY,
673 bgpRcvdPathAttrTable,
674 3,
675 {5, 1, 2}},
676 {BGPPATHATTRORIGIN, INTEGER, RONLY, bgpRcvdPathAttrTable, 3, {5, 1, 3}},
677 {BGPPATHATTRASPATH,
678 OCTET_STRING,
679 RONLY,
680 bgpRcvdPathAttrTable,
681 3,
682 {5, 1, 4}},
683 {BGPPATHATTRNEXTHOP,
684 IPADDRESS,
685 RONLY,
686 bgpRcvdPathAttrTable,
687 3,
688 {5, 1, 5}},
689 {BGPPATHATTRINTERASMETRIC,
690 INTEGER32,
691 RONLY,
692 bgpRcvdPathAttrTable,
693 3,
694 {5, 1, 6}},
695 /* BGP-4 received path attribute table. */
696 {BGP4PATHATTRPEER, IPADDRESS, RONLY, bgp4PathAttrTable, 3, {6, 1, 1}},
697 {BGP4PATHATTRIPADDRPREFIXLEN,
698 INTEGER,
699 RONLY,
700 bgp4PathAttrTable,
701 3,
702 {6, 1, 2}},
703 {BGP4PATHATTRIPADDRPREFIX,
704 IPADDRESS,
705 RONLY,
706 bgp4PathAttrTable,
707 3,
708 {6, 1, 3}},
709 {BGP4PATHATTRORIGIN, INTEGER, RONLY, bgp4PathAttrTable, 3, {6, 1, 4}},
710 {BGP4PATHATTRASPATHSEGMENT,
711 OCTET_STRING,
712 RONLY,
713 bgp4PathAttrTable,
714 3,
715 {6, 1, 5}},
716 {BGP4PATHATTRNEXTHOP,
717 IPADDRESS,
718 RONLY,
719 bgp4PathAttrTable,
720 3,
721 {6, 1, 6}},
722 {BGP4PATHATTRMULTIEXITDISC,
723 INTEGER,
724 RONLY,
725 bgp4PathAttrTable,
726 3,
727 {6, 1, 7}},
728 {BGP4PATHATTRLOCALPREF,
729 INTEGER,
730 RONLY,
731 bgp4PathAttrTable,
732 3,
733 {6, 1, 8}},
734 {BGP4PATHATTRATOMICAGGREGATE,
735 INTEGER,
736 RONLY,
737 bgp4PathAttrTable,
738 3,
739 {6, 1, 9}},
740 {BGP4PATHATTRAGGREGATORAS,
741 INTEGER,
742 RONLY,
743 bgp4PathAttrTable,
744 3,
745 {6, 1, 10}},
746 {BGP4PATHATTRAGGREGATORADDR,
747 IPADDRESS,
748 RONLY,
749 bgp4PathAttrTable,
750 3,
751 {6, 1, 11}},
752 {BGP4PATHATTRCALCLOCALPREF,
753 INTEGER,
754 RONLY,
755 bgp4PathAttrTable,
756 3,
757 {6, 1, 12}},
758 {BGP4PATHATTRBEST, INTEGER, RONLY, bgp4PathAttrTable, 3, {6, 1, 13}},
759 {BGP4PATHATTRUNKNOWN,
760 OCTET_STRING,
761 RONLY,
762 bgp4PathAttrTable,
763 3,
764 {6, 1, 14}},
765 };
766
767 int bgpTrapEstablished(struct peer *peer)
768 {
769 int ret;
770 struct in_addr addr;
771 oid index[sizeof(oid) * IN_ADDR_SIZE];
772
773 /* Check if this peer just went to Established */
774 if ((peer->ostatus != OpenConfirm) || !(peer_established(peer)))
775 return 0;
776
777 ret = inet_aton(peer->host, &addr);
778 if (ret == 0)
779 return 0;
780
781 oid_copy_in_addr(index, &addr);
782
783 smux_trap(bgp_variables, array_size(bgp_variables), bgp_trap_oid,
784 array_size(bgp_trap_oid), bgp_oid,
785 sizeof(bgp_oid) / sizeof(oid), index, IN_ADDR_SIZE,
786 bgpTrapList, array_size(bgpTrapList), BGPESTABLISHED);
787 return 0;
788 }
789
790 int bgpTrapBackwardTransition(struct peer *peer)
791 {
792 int ret;
793 struct in_addr addr;
794 oid index[sizeof(oid) * IN_ADDR_SIZE];
795
796 ret = inet_aton(peer->host, &addr);
797 if (ret == 0)
798 return 0;
799
800 oid_copy_in_addr(index, &addr);
801
802 smux_trap(bgp_variables, array_size(bgp_variables), bgp_trap_oid,
803 array_size(bgp_trap_oid), bgp_oid,
804 sizeof(bgp_oid) / sizeof(oid), index, IN_ADDR_SIZE,
805 bgpTrapList, array_size(bgpTrapList), BGPBACKWARDTRANSITION);
806 return 0;
807 }
808
809 int bgp_snmp_bgp4_init(struct thread_master *tm)
810 {
811 REGISTER_MIB("mibII/bgp", bgp_variables, variable, bgp_oid);
812 return 0;
813 }