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