version 1.1, 2012/02/21 17:26:12
|
version 1.1.1.3, 2016/11/02 10:09:10
|
Line 21 Software Foundation, Inc., 59 Temple Place - Suite 330
|
Line 21 Software Foundation, Inc., 59 Temple Place - Suite 330
|
#include <zebra.h> |
#include <zebra.h> |
|
|
#ifdef HAVE_SNMP |
#ifdef HAVE_SNMP |
#ifdef HAVE_NETSNMP |
|
#include <net-snmp/net-snmp-config.h> |
#include <net-snmp/net-snmp-config.h> |
#include <net-snmp/net-snmp-includes.h> |
#include <net-snmp/net-snmp-includes.h> |
#else |
|
#include <asn1.h> |
|
#include <snmp.h> |
|
#include <snmp_impl.h> |
|
#endif |
|
|
|
#include "if.h" |
#include "if.h" |
#include "log.h" |
#include "log.h" |
Line 36 Software Foundation, Inc., 59 Temple Place - Suite 330
|
Line 30 Software Foundation, Inc., 59 Temple Place - Suite 330
|
#include "command.h" |
#include "command.h" |
#include "thread.h" |
#include "thread.h" |
#include "smux.h" |
#include "smux.h" |
|
#include "filter.h" |
|
|
#include "bgpd/bgpd.h" |
#include "bgpd/bgpd.h" |
#include "bgpd/bgp_table.h" |
#include "bgpd/bgp_table.h" |
Line 44 Software Foundation, Inc., 59 Temple Place - Suite 330
|
Line 39 Software Foundation, Inc., 59 Temple Place - Suite 330
|
#include "bgpd/bgp_route.h" |
#include "bgpd/bgp_route.h" |
#include "bgpd/bgp_fsm.h" |
#include "bgpd/bgp_fsm.h" |
#include "bgpd/bgp_snmp.h" |
#include "bgpd/bgp_snmp.h" |
| |
/* BGP4-MIB described in RFC1657. */ |
/* BGP4-MIB described in RFC1657. */ |
#define BGP4MIB 1,3,6,1,2,1,15 |
#define BGP4MIB 1,3,6,1,2,1,15 |
|
|
Line 80 Software Foundation, Inc., 59 Temple Place - Suite 330
|
Line 75 Software Foundation, Inc., 59 Temple Place - Suite 330
|
#define BGPPEERKEEPALIVE 19 |
#define BGPPEERKEEPALIVE 19 |
#define BGPPEERHOLDTIMECONFIGURED 20 |
#define BGPPEERHOLDTIMECONFIGURED 20 |
#define BGPPEERKEEPALIVECONFIGURED 21 |
#define BGPPEERKEEPALIVECONFIGURED 21 |
#define BGPPEERMINASORIGINATIONINTERVAL 22 | #define BGPPEERMINROUTEADVERTISEMENTINTERVAL 22 |
#define BGPPEERMINROUTEADVERTISEMENTINTERVAL 23 | #define BGPPEERINUPDATEELAPSEDTIME 23 |
#define BGPPEERINUPDATEELAPSEDTIME 24 | |
|
|
/* BGP MIB bgpIdentifier. */ |
/* BGP MIB bgpIdentifier. */ |
#define BGPIDENTIFIER 0 |
#define BGPIDENTIFIER 0 |
Line 118 Software Foundation, Inc., 59 Temple Place - Suite 330
|
Line 112 Software Foundation, Inc., 59 Temple Place - Suite 330
|
#define OCTET_STRING ASN_OCTET_STR |
#define OCTET_STRING ASN_OCTET_STR |
#define IPADDRESS ASN_IPADDRESS |
#define IPADDRESS ASN_IPADDRESS |
#define GAUGE32 ASN_UNSIGNED |
#define GAUGE32 ASN_UNSIGNED |
| |
/* Declare static local variables for convenience. */ |
/* Declare static local variables for convenience. */ |
SNMP_LOCAL_VARIABLES |
SNMP_LOCAL_VARIABLES |
|
|
/* BGP-MIB instances. */ |
/* BGP-MIB instances. */ |
oid bgp_oid [] = { BGP4MIB }; |
oid bgp_oid [] = { BGP4MIB }; |
|
oid bgp_trap_oid [] = { BGP4MIB, 0 }; |
|
|
/* IP address 0.0.0.0. */ |
/* IP address 0.0.0.0. */ |
static struct in_addr bgp_empty_addr = {0}; | static struct in_addr bgp_empty_addr = { .s_addr = 0 }; |
|
|
/* Hook functions. */ |
/* Hook functions. */ |
static u_char *bgpVersion (struct variable *, oid [], size_t *, int, |
static u_char *bgpVersion (struct variable *, oid [], size_t *, int, |
Line 194 struct variable bgp_variables[] =
|
Line 189 struct variable bgp_variables[] =
|
3, {3, 1, 20}}, |
3, {3, 1, 20}}, |
{BGPPEERKEEPALIVECONFIGURED, INTEGER, RWRITE, bgpPeerTable, |
{BGPPEERKEEPALIVECONFIGURED, INTEGER, RWRITE, bgpPeerTable, |
3, {3, 1, 21}}, |
3, {3, 1, 21}}, |
{BGPPEERMINASORIGINATIONINTERVAL, INTEGER, RWRITE, bgpPeerTable, |
|
3, {3, 1, 22}}, |
|
{BGPPEERMINROUTEADVERTISEMENTINTERVAL, INTEGER, RWRITE, bgpPeerTable, |
{BGPPEERMINROUTEADVERTISEMENTINTERVAL, INTEGER, RWRITE, bgpPeerTable, |
3, {3, 1, 23}}, |
3, {3, 1, 23}}, |
{BGPPEERINUPDATEELAPSEDTIME, GAUGE32, RONLY, bgpPeerTable, |
{BGPPEERINUPDATEELAPSEDTIME, GAUGE32, RONLY, bgpPeerTable, |
Line 247 struct variable bgp_variables[] =
|
Line 240 struct variable bgp_variables[] =
|
3, {6, 1, 14}}, |
3, {6, 1, 14}}, |
}; |
}; |
|
|
| |
static u_char * |
static u_char * |
bgpVersion (struct variable *v, oid name[], size_t *length, int exact, |
bgpVersion (struct variable *v, oid name[], size_t *length, int exact, |
size_t *var_len, WriteMethod **write_method) |
size_t *var_len, WriteMethod **write_method) |
Line 342 bgp_peer_lookup_next (struct in_addr *src)
|
Line 335 bgp_peer_lookup_next (struct in_addr *src)
|
return NULL; |
return NULL; |
} |
} |
|
|
|
/* 1.3.6.1.2.1.15.3.1.x = 10 */ |
|
#define PEERTAB_NAMELEN 10 |
|
|
static struct peer * |
static struct peer * |
bgpPeerTable_lookup (struct variable *v, oid name[], size_t *length, |
bgpPeerTable_lookup (struct variable *v, oid name[], size_t *length, |
struct in_addr *addr, int exact) |
struct in_addr *addr, int exact) |
{ |
{ |
struct peer *peer = NULL; |
struct peer *peer = NULL; |
|
size_t namelen = v ? v->namelen : PEERTAB_NAMELEN; |
int len; |
int len; |
|
|
if (exact) |
if (exact) |
{ |
{ |
/* Check the length. */ |
/* Check the length. */ |
if (*length - v->namelen != sizeof (struct in_addr)) | if (*length - namelen != sizeof (struct in_addr)) |
return NULL; |
return NULL; |
|
|
oid2in_addr (name + v->namelen, IN_ADDR_SIZE, addr); | oid2in_addr (name + namelen, IN_ADDR_SIZE, addr); |
|
|
peer = peer_lookup_addr_ipv4 (addr); |
peer = peer_lookup_addr_ipv4 (addr); |
return peer; |
return peer; |
} |
} |
else |
else |
{ |
{ |
len = *length - v->namelen; | len = *length - namelen; |
if (len > 4) len = 4; |
if (len > 4) len = 4; |
|
|
oid2in_addr (name + v->namelen, len, addr); | oid2in_addr (name + namelen, len, addr); |
|
|
peer = bgp_peer_lookup_next (addr); |
peer = bgp_peer_lookup_next (addr); |
|
|
if (peer == NULL) |
if (peer == NULL) |
return NULL; |
return NULL; |
|
|
oid_copy_addr (name + v->namelen, addr, sizeof (struct in_addr)); | oid_copy_addr (name + namelen, addr, sizeof (struct in_addr)); |
*length = sizeof (struct in_addr) + v->namelen; | *length = sizeof (struct in_addr) + namelen; |
|
|
return peer; |
return peer; |
} |
} |
Line 384 bgpPeerTable_lookup (struct variable *v, oid name[], s
|
Line 381 bgpPeerTable_lookup (struct variable *v, oid name[], s
|
static int |
static int |
write_bgpPeerTable (int action, u_char *var_val, |
write_bgpPeerTable (int action, u_char *var_val, |
u_char var_val_type, size_t var_val_len, |
u_char var_val_type, size_t var_val_len, |
u_char *statP, oid *name, size_t length, | u_char *statP, oid *name, size_t length) |
struct variable *v) | |
{ |
{ |
struct in_addr addr; |
struct in_addr addr; |
struct peer *peer; |
struct peer *peer; |
long intval; |
long intval; |
size_t bigsize = SNMP_MAX_LEN; | |
| |
if (var_val_type != ASN_INTEGER) |
if (var_val_type != ASN_INTEGER) |
{ |
{ |
return SNMP_ERR_WRONGTYPE; |
return SNMP_ERR_WRONGTYPE; |
Line 401 write_bgpPeerTable (int action, u_char *var_val,
|
Line 396 write_bgpPeerTable (int action, u_char *var_val,
|
return SNMP_ERR_WRONGLENGTH; |
return SNMP_ERR_WRONGLENGTH; |
} |
} |
|
|
if (! asn_parse_int(var_val, &bigsize, &var_val_type, | intval = *(long *)var_val; |
&intval, sizeof(long))) | |
{ | |
return SNMP_ERR_WRONGENCODING; | |
} | |
|
|
memset (&addr, 0, sizeof (struct in_addr)); |
memset (&addr, 0, sizeof (struct in_addr)); |
|
|
peer = bgpPeerTable_lookup (v, name, &length, &addr, 1); | peer = bgpPeerTable_lookup (NULL, name, &length, &addr, 1); |
if (! peer) |
if (! peer) |
return SNMP_ERR_NOSUCHNAME; |
return SNMP_ERR_NOSUCHNAME; |
|
|
printf ("val: %ld\n", intval); | if (action != SNMP_MSG_INTERNAL_SET_COMMIT) |
| return SNMP_ERR_NOERROR; |
|
|
switch (v->magic) | zlog_info ("%s: SNMP write .%ld = %ld", |
| peer->host, (long)name[PEERTAB_NAMELEN - 1], intval); |
| |
| switch (name[PEERTAB_NAMELEN - 1]) |
{ |
{ |
case BGPPEERADMINSTATUS: |
case BGPPEERADMINSTATUS: |
#define BGP_PeerAdmin_stop 1 |
#define BGP_PeerAdmin_stop 1 |
Line 443 write_bgpPeerTable (int action, u_char *var_val,
|
Line 438 write_bgpPeerTable (int action, u_char *var_val,
|
peer->keepalive = intval; |
peer->keepalive = intval; |
peer->v_keepalive = intval; |
peer->v_keepalive = intval; |
break; |
break; |
case BGPPEERMINASORIGINATIONINTERVAL: |
|
peer->v_asorig = intval; |
|
break; |
|
case BGPPEERMINROUTEADVERTISEMENTINTERVAL: |
case BGPPEERMINROUTEADVERTISEMENTINTERVAL: |
peer->v_routeadv = intval; |
peer->v_routeadv = intval; |
break; |
break; |
Line 460 bgpPeerTable (struct variable *v, oid name[], size_t *
|
Line 452 bgpPeerTable (struct variable *v, oid name[], size_t *
|
static struct in_addr addr; |
static struct in_addr addr; |
struct peer *peer; |
struct peer *peer; |
|
|
*write_method = NULL; | if (smux_header_table(v, name, length, exact, var_len, write_method) |
| == MATCH_FAILED) |
| return NULL; |
memset (&addr, 0, sizeof (struct in_addr)); |
memset (&addr, 0, sizeof (struct in_addr)); |
|
|
peer = bgpPeerTable_lookup (v, name, length, &addr, exact); |
peer = bgpPeerTable_lookup (v, name, length, &addr, exact); |
Line 572 bgpPeerTable (struct variable *v, oid name[], size_t *
|
Line 566 bgpPeerTable (struct variable *v, oid name[], size_t *
|
else |
else |
return SNMP_INTEGER (peer->v_keepalive); |
return SNMP_INTEGER (peer->v_keepalive); |
break; |
break; |
case BGPPEERMINASORIGINATIONINTERVAL: |
|
*write_method = write_bgpPeerTable; |
|
return SNMP_INTEGER (peer->v_asorig); |
|
break; |
|
case BGPPEERMINROUTEADVERTISEMENTINTERVAL: |
case BGPPEERMINROUTEADVERTISEMENTINTERVAL: |
*write_method = write_bgpPeerTable; |
*write_method = write_bgpPeerTable; |
return SNMP_INTEGER (peer->v_routeadv); |
return SNMP_INTEGER (peer->v_routeadv); |
Line 770 bgp4PathAttrTable (struct variable *v, oid name[], siz
|
Line 760 bgp4PathAttrTable (struct variable *v, oid name[], siz
|
if (! bgp) |
if (! bgp) |
return NULL; |
return NULL; |
|
|
|
if (smux_header_table(v, name, length, exact, var_len, write_method) |
|
== MATCH_FAILED) |
|
return NULL; |
memset (&addr, 0, sizeof (struct prefix_ipv4)); |
memset (&addr, 0, sizeof (struct prefix_ipv4)); |
|
|
binfo = bgp4PathAttrLookup (v, name, length, bgp, &addr, exact); |
binfo = bgp4PathAttrLookup (v, name, length, bgp, &addr, exact); |
Line 835 bgp4PathAttrTable (struct variable *v, oid name[], siz
|
Line 828 bgp4PathAttrTable (struct variable *v, oid name[], siz
|
} |
} |
return NULL; |
return NULL; |
} |
} |
| |
/* BGP Traps. */ |
/* BGP Traps. */ |
struct trap_object bgpTrapList[] = |
struct trap_object bgpTrapList[] = |
{ |
{ |
{bgpPeerTable, 3, {3, 1, BGPPEERLASTERROR}}, | {3, {3, 1, BGPPEERLASTERROR}}, |
{bgpPeerTable, 3, {3, 1, BGPPEERSTATE}} | {3, {3, 1, BGPPEERSTATE}} |
}; |
}; |
|
|
void |
void |
Line 856 bgpTrapEstablished (struct peer *peer)
|
Line 849 bgpTrapEstablished (struct peer *peer)
|
|
|
oid_copy_addr (index, &addr, IN_ADDR_SIZE); |
oid_copy_addr (index, &addr, IN_ADDR_SIZE); |
|
|
smux_trap (bgp_oid, sizeof bgp_oid / sizeof (oid), | smux_trap (bgp_variables, sizeof bgp_variables / sizeof (struct variable), |
| bgp_trap_oid, sizeof bgp_trap_oid / sizeof (oid), |
| bgp_oid, sizeof bgp_oid / sizeof (oid), |
index, IN_ADDR_SIZE, |
index, IN_ADDR_SIZE, |
bgpTrapList, sizeof bgpTrapList / sizeof (struct trap_object), |
bgpTrapList, sizeof bgpTrapList / sizeof (struct trap_object), |
bm->start_time - bgp_clock (), BGPESTABLISHED); | BGPESTABLISHED); |
} |
} |
|
|
void |
void |
Line 875 bgpTrapBackwardTransition (struct peer *peer)
|
Line 870 bgpTrapBackwardTransition (struct peer *peer)
|
|
|
oid_copy_addr (index, &addr, IN_ADDR_SIZE); |
oid_copy_addr (index, &addr, IN_ADDR_SIZE); |
|
|
smux_trap (bgp_oid, sizeof bgp_oid / sizeof (oid), | smux_trap (bgp_variables, sizeof bgp_variables / sizeof (struct variable), |
| bgp_trap_oid, sizeof bgp_trap_oid / sizeof (oid), |
| bgp_oid, sizeof bgp_oid / sizeof (oid), |
index, IN_ADDR_SIZE, |
index, IN_ADDR_SIZE, |
bgpTrapList, sizeof bgpTrapList / sizeof (struct trap_object), |
bgpTrapList, sizeof bgpTrapList / sizeof (struct trap_object), |
bm->start_time - bgp_clock (), BGPBACKWARDTRANSITION); | BGPBACKWARDTRANSITION); |
} |
} |
|
|
void |
void |