| 1 |
/* |
| 2 |
* $Id$ |
| 3 |
*/ |
| 4 |
|
| 5 |
/* |
| 6 |
* Smux module authored by Rohit Dube. |
| 7 |
*/ |
| 8 |
|
| 9 |
#include <net-snmp/net-snmp-config.h> |
| 10 |
|
| 11 |
#include <stdio.h> |
| 12 |
#ifdef HAVE_STDLIB_H |
| 13 |
#include <stdlib.h> |
| 14 |
#endif |
| 15 |
#ifdef HAVE_STRING_H |
| 16 |
#include <string.h> |
| 17 |
#else |
| 18 |
#include <strings.h> |
| 19 |
#endif |
| 20 |
#ifdef HAVE_UNISTD_H |
| 21 |
#include <unistd.h> |
| 22 |
#endif |
| 23 |
#ifdef HAVE_ERR_H |
| 24 |
#include <err.h> |
| 25 |
#endif |
| 26 |
#ifdef TIME_WITH_SYS_TIME |
| 27 |
# include <sys/time.h> |
| 28 |
# include <time.h> |
| 29 |
#else |
| 30 |
# ifdef HAVE_SYS_TIME_H |
| 31 |
# include <sys/time.h> |
| 32 |
# else |
| 33 |
# include <time.h> |
| 34 |
# endif |
| 35 |
#endif |
| 36 |
#include <errno.h> |
| 37 |
#include <netdb.h> |
| 38 |
|
| 39 |
#include <sys/stat.h> |
| 40 |
#include <sys/socket.h> |
| 41 |
#ifdef HAVE_SYS_FILIO_H |
| 42 |
#include <sys/filio.h> |
| 43 |
#endif |
| 44 |
|
| 45 |
#ifdef HAVE_NETINET_IN_H |
| 46 |
#include <netinet/in.h> |
| 47 |
#endif |
| 48 |
|
| 49 |
#include <net-snmp/net-snmp-includes.h> |
| 50 |
#include <net-snmp/agent/net-snmp-agent-includes.h> |
| 51 |
#include "smux.h" |
| 52 |
#include "snmp_bgp.h" |
| 53 |
|
| 54 |
struct variable13 bgp_variables[] = { |
| 55 |
{BGPVERSION, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, |
| 56 |
var_bgp, 1, {1}}, |
| 57 |
{BGPLOCALAS, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, |
| 58 |
var_bgp, 1, {2}}, |
| 59 |
{BGPIDENTIFIER, ASN_IPADDRESS, NETSNMP_OLDAPI_RONLY, |
| 60 |
var_bgp, 1, {4}}, |
| 61 |
{BGPPEERIDENTIFIER, ASN_IPADDRESS, NETSNMP_OLDAPI_RONLY, |
| 62 |
var_bgp, 3, {3, 1, 1}}, |
| 63 |
{BGPPEERSTATE, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, |
| 64 |
var_bgp, 3, {3, 1, 2}}, |
| 65 |
{BGPPEERADMINSTATUS, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, |
| 66 |
var_bgp, 3, {3, 1, 3}}, |
| 67 |
{BGPPEERNEGOTIATEDVERSION, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, |
| 68 |
var_bgp, 3, {3, 1, 4}}, |
| 69 |
{BGPPEERLOCALADDR, ASN_IPADDRESS, NETSNMP_OLDAPI_RONLY, |
| 70 |
var_bgp, 3, {3, 1, 5}}, |
| 71 |
{BGPPEERLOCALPORT, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, |
| 72 |
var_bgp, 3, {3, 1, 6}}, |
| 73 |
{BGPPEERREMOTEADDR, ASN_IPADDRESS, NETSNMP_OLDAPI_RONLY, |
| 74 |
var_bgp, 3, {3, 1, 7}}, |
| 75 |
{BGPPEERREMOTEPORT, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, |
| 76 |
var_bgp, 3, {3, 1, 8}}, |
| 77 |
{BGPPEERREMOTEAS, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, |
| 78 |
var_bgp, 3, {3, 1, 9}}, |
| 79 |
{BGPPEERINUPDATES, ASN_COUNTER, NETSNMP_OLDAPI_RONLY, |
| 80 |
var_bgp, 3, {3, 1, 10}}, |
| 81 |
{BGPPEEROUTUPDATES, ASN_COUNTER, NETSNMP_OLDAPI_RONLY, |
| 82 |
var_bgp, 3, {3, 1, 11}}, |
| 83 |
{BGPPEERINTOTALMESSAGES, ASN_COUNTER, NETSNMP_OLDAPI_RONLY, |
| 84 |
var_bgp, 3, {3, 1, 12}}, |
| 85 |
{BGPPEEROUTTOTALMESSAGES, ASN_COUNTER, NETSNMP_OLDAPI_RONLY, |
| 86 |
var_bgp, 3, {3, 1, 13}}, |
| 87 |
{BGPPEERLASTERROR, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, |
| 88 |
var_bgp, 3, {3, 1, 14}}, |
| 89 |
{BGPPATHATTRPEER, ASN_IPADDRESS, NETSNMP_OLDAPI_RONLY, |
| 90 |
var_bgp, 3, {5, 1, 1}}, |
| 91 |
{BGPPATHATTRDESTNETWORK, ASN_IPADDRESS, NETSNMP_OLDAPI_RONLY, |
| 92 |
var_bgp, 3, {5, 1, 2}}, |
| 93 |
{BGPPATHATTRORIGIN, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, |
| 94 |
var_bgp, 3, {5, 1, 3}}, |
| 95 |
{BGPPATHATTRASPATH, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, |
| 96 |
var_bgp, 3, {5, 1, 4}}, |
| 97 |
{BGPPATHATTRNEXTHOP, ASN_INTEGER, NETSNMP_OLDAPI_RONLY, |
| 98 |
var_bgp, 3, {5, 1, 5}}, |
| 99 |
{BGPPATHATTRINTERASMETRIC, ASN_OCTET_STR, NETSNMP_OLDAPI_RONLY, |
| 100 |
var_bgp, 3, {5, 1, 6}} |
| 101 |
}; |
| 102 |
|
| 103 |
oid bgp_variables_oid[] = { NETSNMP_MIB2_OID, 15 }; |
| 104 |
|
| 105 |
void |
| 106 |
init_snmp_bdp(void) |
| 107 |
{ |
| 108 |
REGISTER_MIB("smux/snmp_bgp", bgp_variables, variable13, |
| 109 |
bgp_variables_oid); |
| 110 |
} |
| 111 |
|
| 112 |
static oid max_bgp_mib[] = |
| 113 |
{ 1, 3, 6, 1, 2, 1, 15, 5, 1, 6, 255, 255, 255, 255 }; |
| 114 |
static oid min_bgp_mib[] = { 1, 3, 6, 1, 2, 1, 15, 1, 0 }; |
| 115 |
|
| 116 |
u_char * |
| 117 |
var_bgp(struct variable *vp, |
| 118 |
oid * name, |
| 119 |
int *length, int exact, int *var_len, WriteMethod ** write_method) |
| 120 |
{ |
| 121 |
u_char *var; |
| 122 |
int result; |
| 123 |
|
| 124 |
DEBUGMSGTL(("smux/snmp_bgp", |
| 125 |
"[var_bgp] var len %d, oid requested Len %d-", *var_len, |
| 126 |
*length)); |
| 127 |
DEBUGMSGOID(("smux/snmp_bgp", name, *length)); |
| 128 |
DEBUGMSG(("smux/snmp_bgp", "\n")); |
| 129 |
|
| 130 |
/* |
| 131 |
* Pass on the request to Gated. |
| 132 |
* If the request sent out was a get next, check to see if |
| 133 |
* it lies in the bgp range. If it doesn't, return NULL. |
| 134 |
* In either case, make sure that errors are checked on the |
| 135 |
* returned packets. |
| 136 |
*/ |
| 137 |
|
| 138 |
/* |
| 139 |
* No writes for now |
| 140 |
*/ |
| 141 |
*write_method = NULL; |
| 142 |
|
| 143 |
/* |
| 144 |
* Donot allow access to the peer stuff as it crashes gated. |
| 145 |
* However A GetNext on the last 23.3.1.9 variable will force gated into |
| 146 |
* the peer stuff and cause it to crash. |
| 147 |
* The only way to fix this is to either solve the Gated problem, or |
| 148 |
* remove the peer variables from Gated itself and cause it to return |
| 149 |
* NULL at the crossing. Currently doing the later. |
| 150 |
*/ |
| 151 |
|
| 152 |
/* |
| 153 |
* Reject GET and GETNEXT for anything above bgpifconf range |
| 154 |
*/ |
| 155 |
result = snmp_oid_compare(name, *length, max_bgp_mib, |
| 156 |
sizeof(max_bgp_mib) / sizeof(u_int)); |
| 157 |
|
| 158 |
if (result >= 0) { |
| 159 |
DEBUGMSGTL(("smux/snmp_bgp", "Over shot\n")); |
| 160 |
return NULL; |
| 161 |
} |
| 162 |
|
| 163 |
/* |
| 164 |
* for GETs we need to be in the bgp range so reject anything below |
| 165 |
*/ |
| 166 |
result = snmp_oid_compare(name, *length, min_bgp_mib, |
| 167 |
sizeof(min_bgp_mib) / sizeof(u_int)); |
| 168 |
if (exact && (result < 0)) { |
| 169 |
DEBUGMSGTL(("smux/snmp_bgp", |
| 170 |
"Exact but doesn't match length %d, size %d\n", |
| 171 |
*length, sizeof(min_bgp_mib))); |
| 172 |
return NULL; |
| 173 |
} |
| 174 |
|
| 175 |
/* |
| 176 |
* On return, 'var' points to the value returned which is of length |
| 177 |
* '*var_len'. 'name' points to the new (same as the one passed in for |
| 178 |
* GETs) oid which has 'length' suboids. |
| 179 |
* 'smux_type' contains the type of the variable. |
| 180 |
*/ |
| 181 |
var = smux_snmp_process(exact, name, length, var_len); |
| 182 |
|
| 183 |
DEBUGMSGTL(("smux/snmp_bgp", |
| 184 |
"[var_bgp] var len %d, oid obtained Len %d-", *var_len, |
| 185 |
*length)); |
| 186 |
DEBUGMSGOID(("smux/snmp_bgp", name, *length)); |
| 187 |
DEBUGMSG(("smux/snmp_bgp", "\n")); |
| 188 |
|
| 189 |
vp->type = smux_type; |
| 190 |
|
| 191 |
/* |
| 192 |
* XXX Need a mechanism to return errors in gated's responses |
| 193 |
*/ |
| 194 |
|
| 195 |
if (var == NULL) |
| 196 |
return NULL; |
| 197 |
|
| 198 |
/* |
| 199 |
* Any resullt returned should be within the bgp tree. |
| 200 |
* bgp_mib - static u_int bgp_mib[] = {1, 3, 6, 1, 2, 1, 15}; |
| 201 |
*/ |
| 202 |
if (memcmp(bgp_mib, name, sizeof(bgp_mib)) != 0) { |
| 203 |
return NULL; |
| 204 |
} else { |
| 205 |
return var; |
| 206 |
} |
| 207 |
} |