2 * $Id: snmp_bgp.c,v 5.0 2002/04/20 07:30:06 hardaker Exp $
6 * Smux module authored by Rohit Dube.
9 #include <net-snmp/net-snmp-config.h>
26 #if TIME_WITH_SYS_TIME
27 # include <sys/time.h>
31 # include <sys/time.h>
40 #include <sys/socket.h>
42 #include <sys/filio.h>
46 #include <netinet/in.h>
49 #include <net-snmp/net-snmp-includes.h>
50 #include <net-snmp/agent/net-snmp-agent-includes.h>
54 struct variable13 bgp_variables[] = {
55 {BGPVERSION, ASN_OCTET_STR, RONLY, var_bgp, 1, {1}},
56 {BGPLOCALAS, ASN_INTEGER, RONLY, var_bgp, 1, {2}},
57 {BGPIDENTIFIER, ASN_IPADDRESS, RONLY, var_bgp, 1, {4}},
58 {BGPPEERIDENTIFIER, ASN_IPADDRESS, RONLY, var_bgp, 3, {3, 1, 1}},
59 {BGPPEERSTATE, ASN_INTEGER, RONLY, var_bgp, 3, {3, 1, 2}},
60 {BGPPEERADMINSTATUS, ASN_INTEGER, RONLY, var_bgp, 3, {3, 1, 3}},
61 {BGPPEERNEGOTIATEDVERSION, ASN_INTEGER, RONLY, var_bgp, 3, {3, 1, 4}},
62 {BGPPEERLOCALADDR, ASN_IPADDRESS, RONLY, var_bgp, 3, {3, 1, 5}},
63 {BGPPEERLOCALPORT, ASN_INTEGER, RONLY, var_bgp, 3, {3, 1, 6}},
64 {BGPPEERREMOTEADDR, ASN_IPADDRESS, RONLY, var_bgp, 3, {3, 1, 7}},
65 {BGPPEERREMOTEPORT, ASN_INTEGER, RONLY, var_bgp, 3, {3, 1, 8}},
66 {BGPPEERREMOTEAS, ASN_INTEGER, RONLY, var_bgp, 3, {3, 1, 9}},
67 {BGPPEERINUPDATES, ASN_COUNTER, RONLY, var_bgp, 3, {3, 1, 10}},
68 {BGPPEEROUTUPDATES, ASN_COUNTER, RONLY, var_bgp, 3, {3, 1, 11}},
69 {BGPPEERINTOTALMESSAGES, ASN_COUNTER, RONLY, var_bgp, 3, {3, 1, 12}},
70 {BGPPEEROUTTOTALMESSAGES, ASN_COUNTER, RONLY, var_bgp, 3, {3, 1, 13}},
71 {BGPPEERLASTERROR, ASN_OCTET_STR, RONLY, var_bgp, 3, {3, 1, 14}},
72 {BGPPATHATTRPEER, ASN_IPADDRESS, RONLY, var_bgp, 3, {5, 1, 1}},
73 {BGPPATHATTRDESTNETWORK, ASN_IPADDRESS, RONLY, var_bgp, 3, {5, 1, 2}},
74 {BGPPATHATTRORIGIN, ASN_INTEGER, RONLY, var_bgp, 3, {5, 1, 3}},
75 {BGPPATHATTRASPATH, ASN_OCTET_STR, RONLY, var_bgp, 3, {5, 1, 4}},
76 {BGPPATHATTRNEXTHOP, ASN_INTEGER, RONLY, var_bgp, 3, {5, 1, 5}},
77 {BGPPATHATTRINTERASMETRIC, ASN_OCTET_STR, RONLY, var_bgp, 3, {5, 1, 6}}
80 oid bgp_variables_oid[] = { MIB, 15 };
85 REGISTER_MIB("smux/snmp_bgp", bgp_variables, variable13,
91 static oid max_bgp_mib[] =
92 { 1, 3, 6, 1, 2, 1, 15, 5, 1, 6, 255, 255, 255, 255 };
93 static oid min_bgp_mib[] = { 1, 3, 6, 1, 2, 1, 15, 1, 0 };
94 extern u_char smux_type;
97 var_bgp(struct variable *vp,
99 int *length, int exact, int *var_len, WriteMethod ** write_method)
104 DEBUGMSGTL(("smux/snmp_bgp",
105 "[var_bgp] var len %d, oid requested Len %d-", *var_len,
107 DEBUGMSGOID(("smux/snmp_bgp", name, *length));
108 DEBUGMSG(("smux/snmp_bgp", "\n"));
111 * Pass on the request to Gated.
112 * If the request sent out was a get next, check to see if
113 * it lies in the bgp range. If it doesn't, return NULL.
114 * In either case, make sure that errors are checked on the
121 *write_method = NULL;
124 * Donot allow access to the peer stuff as it crashes gated.
125 * However A GetNext on the last 23.3.1.9 variable will force gated into
126 * the peer stuff and cause it to crash.
127 * The only way to fix this is to either solve the Gated problem, or
128 * remove the peer variables from Gated itself and cause it to return
129 * NULL at the crossing. Currently doing the later.
133 * Reject GET and GETNEXT for anything above bgpifconf range
135 result = snmp_oid_compare(name, *length, max_bgp_mib,
136 sizeof(max_bgp_mib) / sizeof(u_int));
139 DEBUGMSGTL(("smux/snmp_bgp", "Over shot\n"));
144 * for GETs we need to be in the bgp range so reject anything below
146 result = snmp_oid_compare(name, *length, min_bgp_mib,
147 sizeof(min_bgp_mib) / sizeof(u_int));
148 if (exact && (result < 0)) {
149 DEBUGMSGTL(("smux/snmp_bgp",
150 "Exact but doesn't match length %d, size %d\n",
151 *length, sizeof(min_bgp_mib)));
156 * On return, 'var' points to the value returned which is of length
157 * '*var_len'. 'name' points to the new (same as the one passed in for
158 * GETs) oid which has 'length' suboids.
159 * 'smux_type' contains the type of the variable.
161 var = smux_snmp_process(exact, name, length, var_len);
163 DEBUGMSGTL(("smux/snmp_bgp",
164 "[var_bgp] var len %d, oid obtained Len %d-", *var_len,
166 DEBUGMSGOID(("smux/snmp_bgp", name, *length));
167 DEBUGMSG(("smux/snmp_bgp", "\n"));
169 vp->type = smux_type;
172 * XXX Need a mechanism to return errors in gated's responses
179 * Any resullt returned should be within the bgp tree.
180 * bgp_mib - static u_int bgp_mib[] = {1, 3, 6, 1, 2, 1, 15};
182 if (memcmp(bgp_mib, name, sizeof(bgp_mib)) != 0) {