1 |
27 |
unneback |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// snmp/snmpagent/current/src/mibgroup/mibII/tcp.c
|
4 |
|
|
//
|
5 |
|
|
//
|
6 |
|
|
//==========================================================================
|
7 |
|
|
//####ECOSGPLCOPYRIGHTBEGIN####
|
8 |
|
|
// -------------------------------------------
|
9 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
10 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
11 |
|
|
//
|
12 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
13 |
|
|
// the terms of the GNU General Public License as published by the Free
|
14 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
15 |
|
|
//
|
16 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
17 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
18 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
19 |
|
|
// for more details.
|
20 |
|
|
//
|
21 |
|
|
// You should have received a copy of the GNU General Public License along
|
22 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
23 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
24 |
|
|
//
|
25 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
26 |
|
|
// or inline functions from this file, or you compile this file and link it
|
27 |
|
|
// with other works to produce a work based on this file, this file does not
|
28 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
29 |
|
|
// License. However the source code for this file must still be made available
|
30 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
31 |
|
|
//
|
32 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
33 |
|
|
// this file might be covered by the GNU General Public License.
|
34 |
|
|
//
|
35 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
36 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//####UCDSNMPCOPYRIGHTBEGIN####
|
40 |
|
|
//
|
41 |
|
|
// -------------------------------------------
|
42 |
|
|
//
|
43 |
|
|
// Portions of this software may have been derived from the UCD-SNMP
|
44 |
|
|
// project, <http://ucd-snmp.ucdavis.edu/> from the University of
|
45 |
|
|
// California at Davis, which was originally based on the Carnegie Mellon
|
46 |
|
|
// University SNMP implementation. Portions of this software are therefore
|
47 |
|
|
// covered by the appropriate copyright disclaimers included herein.
|
48 |
|
|
//
|
49 |
|
|
// The release used was version 4.1.2 of May 2000. "ucd-snmp-4.1.2"
|
50 |
|
|
// -------------------------------------------
|
51 |
|
|
//
|
52 |
|
|
//####UCDSNMPCOPYRIGHTEND####
|
53 |
|
|
//==========================================================================
|
54 |
|
|
//#####DESCRIPTIONBEGIN####
|
55 |
|
|
//
|
56 |
|
|
// Author(s): hmt
|
57 |
|
|
// Contributors: hmt, Andrew Lunn
|
58 |
|
|
// Date: 2000-05-30
|
59 |
|
|
// Purpose: Port of UCD-SNMP distribution to eCos.
|
60 |
|
|
// Description:
|
61 |
|
|
//
|
62 |
|
|
//
|
63 |
|
|
//####DESCRIPTIONEND####
|
64 |
|
|
//
|
65 |
|
|
//==========================================================================
|
66 |
|
|
/********************************************************************
|
67 |
|
|
Copyright 1989, 1991, 1992 by Carnegie Mellon University
|
68 |
|
|
|
69 |
|
|
Derivative Work -
|
70 |
|
|
Copyright 1996, 1998, 1999, 2000 The Regents of the University of California
|
71 |
|
|
|
72 |
|
|
All Rights Reserved
|
73 |
|
|
|
74 |
|
|
Permission to use, copy, modify and distribute this software and its
|
75 |
|
|
documentation for any purpose and without fee is hereby granted,
|
76 |
|
|
provided that the above copyright notice appears in all copies and
|
77 |
|
|
that both that copyright notice and this permission notice appear in
|
78 |
|
|
supporting documentation, and that the name of CMU and The Regents of
|
79 |
|
|
the University of California not be used in advertising or publicity
|
80 |
|
|
pertaining to distribution of the software without specific written
|
81 |
|
|
permission.
|
82 |
|
|
|
83 |
|
|
CMU AND THE REGENTS OF THE UNIVERSITY OF CALIFORNIA DISCLAIM ALL
|
84 |
|
|
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
|
85 |
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL CMU OR
|
86 |
|
|
THE REGENTS OF THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY SPECIAL,
|
87 |
|
|
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
|
88 |
|
|
FROM THE LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
|
89 |
|
|
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
90 |
|
|
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
91 |
|
|
*********************************************************************/
|
92 |
|
|
/* This file was generated by mib2c and is intended for use as a mib module
|
93 |
|
|
for the ucd-snmp snmpd agent. */
|
94 |
|
|
|
95 |
|
|
#include <pkgconf/system.h>
|
96 |
|
|
/* This should always be included first before anything else */
|
97 |
|
|
#include <config.h>
|
98 |
|
|
|
99 |
|
|
|
100 |
|
|
/* minimal include directives */
|
101 |
|
|
#include "mibincl.h"
|
102 |
|
|
#include "mibgroup/util_funcs.h"
|
103 |
|
|
#include "mibgroup/mibII/tcp.h"
|
104 |
|
|
|
105 |
|
|
#include <sys/protosw.h>
|
106 |
|
|
|
107 |
|
|
#define _KERNEL
|
108 |
|
|
#include <netinet/in.h>
|
109 |
|
|
#include <netinet/in_systm.h>
|
110 |
|
|
#include <netinet/ip.h>
|
111 |
|
|
#include <netinet/in_pcb.h>
|
112 |
|
|
#include <netinet/ip_var.h>
|
113 |
|
|
#include <netinet/tcp.h>
|
114 |
|
|
//#define TCPOUTFLAGS
|
115 |
|
|
#include <netinet/tcp_fsm.h>
|
116 |
|
|
#include <netinet/tcp_seq.h>
|
117 |
|
|
#include <netinet/tcp_timer.h>
|
118 |
|
|
#include <netinet/tcp_var.h>
|
119 |
|
|
#include <netinet/tcpip.h>
|
120 |
|
|
#include <netinet/tcp_debug.h>
|
121 |
|
|
|
122 |
|
|
/*
|
123 |
|
|
* tcp_variables_oid:
|
124 |
|
|
* this is the top level oid that we want to register under. This
|
125 |
|
|
* is essentially a prefix, with the suffix appearing in the
|
126 |
|
|
* variable below.
|
127 |
|
|
*/
|
128 |
|
|
|
129 |
|
|
|
130 |
|
|
oid tcp_variables_oid[] = { 1,3,6,1,2,1,6 };
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
/*
|
134 |
|
|
* variable4 tcp_variables:
|
135 |
|
|
* this variable defines function callbacks and type return information
|
136 |
|
|
* for the tcp mib section
|
137 |
|
|
*/
|
138 |
|
|
|
139 |
|
|
|
140 |
|
|
struct variable4 tcp_variables[] = {
|
141 |
|
|
/* magic number , variable type , ro/rw , callback fn , L, oidsuffix */
|
142 |
|
|
#define TCPRTOALGORITHM 1
|
143 |
|
|
{ TCPRTOALGORITHM , ASN_INTEGER , RONLY , var_tcp, 1, { 1 } },
|
144 |
|
|
#define TCPRTOMIN 2
|
145 |
|
|
{ TCPRTOMIN , ASN_INTEGER , RONLY , var_tcp, 1, { 2 } },
|
146 |
|
|
#define TCPRTOMAX 3
|
147 |
|
|
{ TCPRTOMAX , ASN_INTEGER , RONLY , var_tcp, 1, { 3 } },
|
148 |
|
|
#define TCPMAXCONN 4
|
149 |
|
|
{ TCPMAXCONN , ASN_INTEGER , RONLY , var_tcp, 1, { 4 } },
|
150 |
|
|
#define TCPACTIVEOPENS 5
|
151 |
|
|
{ TCPACTIVEOPENS , ASN_COUNTER , RONLY , var_tcp, 1, { 5 } },
|
152 |
|
|
#define TCPPASSIVEOPENS 6
|
153 |
|
|
{ TCPPASSIVEOPENS , ASN_COUNTER , RONLY , var_tcp, 1, { 6 } },
|
154 |
|
|
#define TCPATTEMPTFAILS 7
|
155 |
|
|
{ TCPATTEMPTFAILS , ASN_COUNTER , RONLY , var_tcp, 1, { 7 } },
|
156 |
|
|
#define TCPESTABRESETS 8
|
157 |
|
|
{ TCPESTABRESETS , ASN_COUNTER , RONLY , var_tcp, 1, { 8 } },
|
158 |
|
|
#define TCPCURRESTAB 9
|
159 |
|
|
{ TCPCURRESTAB , ASN_GAUGE , RONLY , var_tcp, 1, { 9 } },
|
160 |
|
|
#define TCPINSEGS 10
|
161 |
|
|
{ TCPINSEGS , ASN_COUNTER , RONLY , var_tcp, 1, { 10 } },
|
162 |
|
|
#define TCPOUTSEGS 11
|
163 |
|
|
{ TCPOUTSEGS , ASN_COUNTER , RONLY , var_tcp, 1, { 11 } },
|
164 |
|
|
#define TCPRETRANSSEGS 12
|
165 |
|
|
{ TCPRETRANSSEGS , ASN_COUNTER , RONLY , var_tcp, 1, { 12 } },
|
166 |
|
|
#define TCPCONNSTATE 15
|
167 |
|
|
{ TCPCONNSTATE , ASN_INTEGER , RWRITE, var_tcpConnTable, 3, { 13,1,1 } },
|
168 |
|
|
#define TCPCONNLOCALADDRESS 16
|
169 |
|
|
{ TCPCONNLOCALADDRESS , ASN_IPADDRESS , RONLY , var_tcpConnTable, 3, { 13,1,2 } },
|
170 |
|
|
#define TCPCONNLOCALPORT 17
|
171 |
|
|
{ TCPCONNLOCALPORT , ASN_INTEGER , RONLY , var_tcpConnTable, 3, { 13,1,3 } },
|
172 |
|
|
#define TCPCONNREMADDRESS 18
|
173 |
|
|
{ TCPCONNREMADDRESS , ASN_IPADDRESS , RONLY , var_tcpConnTable, 3, { 13,1,4 } },
|
174 |
|
|
#define TCPCONNREMPORT 19
|
175 |
|
|
{ TCPCONNREMPORT , ASN_INTEGER , RONLY , var_tcpConnTable, 3, { 13,1,5 } },
|
176 |
|
|
#define TCPINERRS 20
|
177 |
|
|
{ TCPINERRS , ASN_COUNTER , RONLY , var_tcp, 1, { 14 } },
|
178 |
|
|
#define TCPOUTRSTS 21
|
179 |
|
|
{ TCPOUTRSTS , ASN_COUNTER , RONLY , var_tcp, 1, { 15 } },
|
180 |
|
|
//#define IPV6TCPCONNSTATE 29
|
181 |
|
|
// { IPV6TCPCONNSTATE , ASN_INTEGER , RWRITE, var_ipv6TcpConnTable, 3, { 16,1,6 } },
|
182 |
|
|
|
183 |
|
|
};
|
184 |
|
|
/* (L = length of the oidsuffix) */
|
185 |
|
|
|
186 |
|
|
|
187 |
|
|
/*
|
188 |
|
|
* init_tcp():
|
189 |
|
|
* Initialization routine. This is called when the agent starts up.
|
190 |
|
|
* At a minimum, registration of your variables should take place here.
|
191 |
|
|
*/
|
192 |
|
|
void init_tcp(void) {
|
193 |
|
|
|
194 |
|
|
|
195 |
|
|
/* register ourselves with the agent to handle our mib tree */
|
196 |
|
|
REGISTER_MIB("tcp", tcp_variables, variable4,
|
197 |
|
|
tcp_variables_oid);
|
198 |
|
|
|
199 |
|
|
|
200 |
|
|
/* place any other initialization junk you need here */
|
201 |
|
|
}
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
/*
|
205 |
|
|
* var_tcp():
|
206 |
|
|
* This function is called every time the agent gets a request for
|
207 |
|
|
* a scalar variable that might be found within your mib section
|
208 |
|
|
* registered above. It is up to you to do the right thing and
|
209 |
|
|
* return the correct value.
|
210 |
|
|
* You should also correct the value of "var_len" if necessary.
|
211 |
|
|
*
|
212 |
|
|
* Please see the documentation for more information about writing
|
213 |
|
|
* module extensions, and check out the examples in the examples
|
214 |
|
|
* and mibII directories.
|
215 |
|
|
*/
|
216 |
|
|
unsigned char *
|
217 |
|
|
var_tcp(struct variable *vp,
|
218 |
|
|
oid *name,
|
219 |
|
|
size_t *length,
|
220 |
|
|
int exact,
|
221 |
|
|
size_t *var_len,
|
222 |
|
|
WriteMethod **write_method)
|
223 |
|
|
{
|
224 |
|
|
static long long_ret;
|
225 |
|
|
|
226 |
|
|
if (header_generic(vp,name,length,exact,var_len,write_method)
|
227 |
|
|
== MATCH_FAILED )
|
228 |
|
|
return NULL;
|
229 |
|
|
|
230 |
|
|
switch(vp->magic) {
|
231 |
|
|
|
232 |
|
|
case TCPRTOALGORITHM:
|
233 |
|
|
long_ret = 1; // meaning "other"
|
234 |
|
|
return (unsigned char *) &long_ret;
|
235 |
|
|
|
236 |
|
|
case TCPRTOMIN:
|
237 |
|
|
long_ret = TCPTV_MIN / PR_SLOWHZ * 1000;;
|
238 |
|
|
return (unsigned char *) &long_ret;
|
239 |
|
|
|
240 |
|
|
case TCPRTOMAX:
|
241 |
|
|
long_ret = TCPTV_REXMTMAX / PR_SLOWHZ * 1000;;
|
242 |
|
|
return (unsigned char *) &long_ret;
|
243 |
|
|
|
244 |
|
|
case TCPMAXCONN:
|
245 |
|
|
long_ret = -1; // It is dynamic.
|
246 |
|
|
return (unsigned char *) &long_ret;
|
247 |
|
|
|
248 |
|
|
case TCPACTIVEOPENS:
|
249 |
|
|
long_ret = tcpstat.tcps_connattempt;
|
250 |
|
|
return (unsigned char *) &long_ret;
|
251 |
|
|
|
252 |
|
|
case TCPPASSIVEOPENS:
|
253 |
|
|
long_ret = tcpstat.tcps_accepts;
|
254 |
|
|
return (unsigned char *) &long_ret;
|
255 |
|
|
|
256 |
|
|
case TCPATTEMPTFAILS:
|
257 |
|
|
long_ret = tcpstat.tcps_conndrops;
|
258 |
|
|
return (unsigned char *) &long_ret;
|
259 |
|
|
|
260 |
|
|
case TCPESTABRESETS:
|
261 |
|
|
long_ret = tcpstat.tcps_drops;
|
262 |
|
|
return (unsigned char *) &long_ret;
|
263 |
|
|
|
264 |
|
|
case TCPCURRESTAB: {
|
265 |
|
|
struct inpcb *inp;
|
266 |
|
|
long_ret = 0;
|
267 |
|
|
for (
|
268 |
|
|
#ifdef CYGPKG_NET_OPENBSD_STACK
|
269 |
|
|
inp = tcbtable.inpt_queue.cqh_first;
|
270 |
|
|
inp != (struct inpcb *)&tcbtable.inpt_queue;
|
271 |
|
|
inp = inp->inp_queue.cqe_next
|
272 |
|
|
#endif
|
273 |
|
|
#ifdef CYGPKG_NET_FREEBSD_STACK
|
274 |
|
|
inp = tcb.lh_first;
|
275 |
|
|
inp;
|
276 |
|
|
inp = inp->inp_list.le_next
|
277 |
|
|
#endif
|
278 |
|
|
) {
|
279 |
|
|
struct tcpcb *tp = intotcpcb( inp );
|
280 |
|
|
if ( tp && (TCPS_ESTABLISHED == tp->t_state ||
|
281 |
|
|
TCPS_CLOSE_WAIT == tp->t_state) )
|
282 |
|
|
long_ret++;
|
283 |
|
|
}
|
284 |
|
|
return (unsigned char *) &long_ret;
|
285 |
|
|
}
|
286 |
|
|
|
287 |
|
|
case TCPINSEGS:
|
288 |
|
|
long_ret = tcpstat.tcps_rcvtotal;
|
289 |
|
|
return (unsigned char *) &long_ret;
|
290 |
|
|
|
291 |
|
|
case TCPOUTSEGS:
|
292 |
|
|
long_ret = tcpstat.tcps_sndtotal - tcpstat.tcps_sndrexmitpack;
|
293 |
|
|
if ( long_ret < 0 )
|
294 |
|
|
long_ret = 0;
|
295 |
|
|
return (unsigned char *) &long_ret;
|
296 |
|
|
|
297 |
|
|
case TCPRETRANSSEGS:
|
298 |
|
|
long_ret = tcpstat.tcps_sndrexmitpack;
|
299 |
|
|
return (unsigned char *) &long_ret;
|
300 |
|
|
|
301 |
|
|
case TCPINERRS:
|
302 |
|
|
long_ret = tcpstat.tcps_rcvbadsum
|
303 |
|
|
+ tcpstat.tcps_rcvbadoff
|
304 |
|
|
+ tcpstat.tcps_rcvshort
|
305 |
|
|
+ tcpstat.tcps_rcvmemdrop; // Is that last one an input error?
|
306 |
|
|
return (unsigned char *) &long_ret;
|
307 |
|
|
|
308 |
|
|
case TCPOUTRSTS:
|
309 |
|
|
long_ret = tcpstat.tcps_sndctrl - tcpstat.tcps_closed;
|
310 |
|
|
if ( long_ret < 0 )
|
311 |
|
|
long_ret = 0;
|
312 |
|
|
return (unsigned char *) &long_ret;
|
313 |
|
|
|
314 |
|
|
default:
|
315 |
|
|
ERROR_MSG("");
|
316 |
|
|
}
|
317 |
|
|
return NULL;
|
318 |
|
|
}
|
319 |
|
|
|
320 |
|
|
|
321 |
|
|
|
322 |
|
|
|
323 |
|
|
/*
|
324 |
|
|
* var_tcpConnTable():
|
325 |
|
|
* Handle this table separately from the scalar value case.
|
326 |
|
|
* The workings of this are basically the same as for var_tcpConnTable above.
|
327 |
|
|
*/
|
328 |
|
|
unsigned char *
|
329 |
|
|
var_tcpConnTable(struct variable *vp,
|
330 |
|
|
oid *name,
|
331 |
|
|
size_t *length,
|
332 |
|
|
int exact,
|
333 |
|
|
size_t *var_len,
|
334 |
|
|
WriteMethod **write_method)
|
335 |
|
|
{
|
336 |
|
|
static long long_ret;
|
337 |
|
|
static unsigned char string[SPRINT_MAX_LEN];
|
338 |
|
|
register struct inpcb *inp;
|
339 |
|
|
register struct inpcb *low_inp = NULL;
|
340 |
|
|
oid lowest[24];
|
341 |
|
|
oid newname[24];
|
342 |
|
|
u_char *cp;
|
343 |
|
|
oid *op;
|
344 |
|
|
struct tcpcb *tp;
|
345 |
|
|
|
346 |
|
|
// This is indexed by local-address, local-port, remote-address, remport
|
347 |
|
|
// at 1,3,6,1,2,1,6,13,1
|
348 |
|
|
// so we get 1,3,6,1,2,1,6,13,1,?,A,B,C,D,lport,P,Q,R,S,rport
|
349 |
|
|
// initial length is 10, out-length is 20,
|
350 |
|
|
// Local address is offsets 10-13, port is offset 14.
|
351 |
|
|
// Remote address is offsets 15-18, port is offset 19.
|
352 |
|
|
|
353 |
|
|
// starting from udbtable, look in
|
354 |
|
|
// low_pcb->inp_laddr.s_addr
|
355 |
|
|
// and low_pcb->inp_lport
|
356 |
|
|
// /_l/_f/ for foreign port,address.
|
357 |
|
|
|
358 |
|
|
/* fill in object part of name for current (less sizeof instance part) */
|
359 |
|
|
memcpy((char *)newname, (char *)vp->name, (int)vp->namelen * sizeof(oid));
|
360 |
|
|
|
361 |
|
|
for (
|
362 |
|
|
#ifdef CYGPKG_NET_OPENBSD_STACK
|
363 |
|
|
inp = tcbtable.inpt_queue.cqh_first;
|
364 |
|
|
inp != (struct inpcb *)&tcbtable.inpt_queue;
|
365 |
|
|
inp = inp->inp_queue.cqe_next
|
366 |
|
|
#endif
|
367 |
|
|
#ifdef CYGPKG_NET_FREEBSD_STACK
|
368 |
|
|
inp = tcb.lh_first;
|
369 |
|
|
inp;
|
370 |
|
|
inp = inp->inp_list.le_next
|
371 |
|
|
#endif
|
372 |
|
|
) {
|
373 |
|
|
|
374 |
|
|
cp = (u_char *)&inp->inp_laddr.s_addr;
|
375 |
|
|
op = newname + 10;
|
376 |
|
|
*op++ = *cp++;
|
377 |
|
|
*op++ = *cp++;
|
378 |
|
|
*op++ = *cp++;
|
379 |
|
|
*op++ = *cp++;
|
380 |
|
|
|
381 |
|
|
newname[14] = ntohs(inp->inp_lport);
|
382 |
|
|
|
383 |
|
|
cp = (u_char *)&inp->inp_faddr.s_addr;
|
384 |
|
|
op = newname + 15;
|
385 |
|
|
*op++ = *cp++;
|
386 |
|
|
*op++ = *cp++;
|
387 |
|
|
*op++ = *cp++;
|
388 |
|
|
*op++ = *cp++;
|
389 |
|
|
|
390 |
|
|
newname[19] = ntohs(inp->inp_fport);
|
391 |
|
|
|
392 |
|
|
if (exact){
|
393 |
|
|
if (snmp_oid_compare(newname, 20, name, *length) == 0){
|
394 |
|
|
memcpy( (char *)lowest,(char *)newname, 20 * sizeof(oid));
|
395 |
|
|
low_inp = inp;
|
396 |
|
|
break; /* no need to search further */
|
397 |
|
|
}
|
398 |
|
|
} else {
|
399 |
|
|
if ((snmp_oid_compare(newname, 20, name, *length) > 0) &&
|
400 |
|
|
(!low_inp || (snmp_oid_compare(newname, 20, lowest, 20) < 0))){
|
401 |
|
|
/*
|
402 |
|
|
* if new one is greater than input and closer to input than
|
403 |
|
|
* previous lowest, save this one as the "next" one.
|
404 |
|
|
*/
|
405 |
|
|
memcpy( (char *)lowest,(char *)newname, 20 * sizeof(oid));
|
406 |
|
|
low_inp = inp;
|
407 |
|
|
}
|
408 |
|
|
}
|
409 |
|
|
}
|
410 |
|
|
|
411 |
|
|
if ( ! low_inp )
|
412 |
|
|
return NULL;
|
413 |
|
|
|
414 |
|
|
tp = intotcpcb( low_inp );
|
415 |
|
|
if ( ! tp )
|
416 |
|
|
return NULL; // Shouldn't happen
|
417 |
|
|
|
418 |
|
|
memcpy( (char *)name,(char *)lowest, 20 * sizeof(oid));
|
419 |
|
|
*length = 20;
|
420 |
|
|
*var_len = sizeof( long_ret );
|
421 |
|
|
*write_method = 0;
|
422 |
|
|
|
423 |
|
|
switch(vp->magic) {
|
424 |
|
|
case TCPCONNSTATE:
|
425 |
|
|
// NOTSUPPORTED: *write_method = write_tcpConnState;
|
426 |
|
|
switch ( tp->t_state ) {
|
427 |
|
|
case TCPS_CLOSED : // 0 /* closed */
|
428 |
|
|
long_ret = 1; break;
|
429 |
|
|
case TCPS_LISTEN : // 1 /* listening for connection */
|
430 |
|
|
long_ret = 2; break;
|
431 |
|
|
case TCPS_SYN_SENT : // 2 /* active, have sent syn */
|
432 |
|
|
long_ret = 3; break;
|
433 |
|
|
case TCPS_SYN_RECEIVED : // 3 /* have sent and received syn */
|
434 |
|
|
long_ret = 4; break;
|
435 |
|
|
case TCPS_ESTABLISHED : // 4 /* established */
|
436 |
|
|
long_ret = 5; break;
|
437 |
|
|
case TCPS_CLOSE_WAIT : // 5 /* rcvd fin, waiting for close */
|
438 |
|
|
long_ret = 8; break;
|
439 |
|
|
case TCPS_FIN_WAIT_1 : // 6 /* have closed, sent fin */
|
440 |
|
|
long_ret = 6; break;
|
441 |
|
|
case TCPS_CLOSING : // 7 /* closed xchd FIN; await ACK */
|
442 |
|
|
long_ret = 10; break;
|
443 |
|
|
case TCPS_LAST_ACK : // 8 /* had fin and close; await FIN ACK */
|
444 |
|
|
long_ret = 9; break;
|
445 |
|
|
case TCPS_FIN_WAIT_2 : // 9 /* have closed, fin is acked */
|
446 |
|
|
long_ret = 7; break;
|
447 |
|
|
case TCPS_TIME_WAIT : // 10 /* in 2*msl quiet wait after close */
|
448 |
|
|
long_ret = 11; break;
|
449 |
|
|
default:
|
450 |
|
|
long_ret = 1;
|
451 |
|
|
}
|
452 |
|
|
return (unsigned char *) &long_ret;
|
453 |
|
|
|
454 |
|
|
case TCPCONNLOCALADDRESS:
|
455 |
|
|
cp = (u_char *)&low_inp->inp_laddr.s_addr;
|
456 |
|
|
string[0] = *cp++;
|
457 |
|
|
string[1] = *cp++;
|
458 |
|
|
string[2] = *cp++;
|
459 |
|
|
string[3] = *cp++;
|
460 |
|
|
*var_len = 4;
|
461 |
|
|
return (unsigned char *) string;
|
462 |
|
|
|
463 |
|
|
case TCPCONNLOCALPORT:
|
464 |
|
|
long_ret = (long)ntohs(low_inp->inp_lport);
|
465 |
|
|
return (unsigned char *) &long_ret;
|
466 |
|
|
|
467 |
|
|
case TCPCONNREMADDRESS:
|
468 |
|
|
cp = (u_char *)&low_inp->inp_faddr.s_addr;
|
469 |
|
|
string[0] = *cp++;
|
470 |
|
|
string[1] = *cp++;
|
471 |
|
|
string[2] = *cp++;
|
472 |
|
|
string[3] = *cp++;
|
473 |
|
|
*var_len = 4;
|
474 |
|
|
return (unsigned char *) string;
|
475 |
|
|
|
476 |
|
|
case TCPCONNREMPORT:
|
477 |
|
|
long_ret = (long)ntohs(low_inp->inp_fport);
|
478 |
|
|
return (unsigned char *) &long_ret;
|
479 |
|
|
|
480 |
|
|
default:
|
481 |
|
|
ERROR_MSG("");
|
482 |
|
|
}
|
483 |
|
|
return NULL;
|
484 |
|
|
}
|
485 |
|
|
|
486 |
|
|
|
487 |
|
|
#if 0 // NOTSUPPORTED:
|
488 |
|
|
int
|
489 |
|
|
write_tcpConnState(int action,
|
490 |
|
|
u_char *var_val,
|
491 |
|
|
u_char var_val_type,
|
492 |
|
|
size_t var_val_len,
|
493 |
|
|
u_char *statP,
|
494 |
|
|
oid *name,
|
495 |
|
|
size_t name_len)
|
496 |
|
|
{
|
497 |
|
|
static long *long_ret;
|
498 |
|
|
int size;
|
499 |
|
|
|
500 |
|
|
|
501 |
|
|
switch ( action ) {
|
502 |
|
|
case RESERVE1:
|
503 |
|
|
if (var_val_type != ASN_INTEGER){
|
504 |
|
|
fprintf(stderr, "write to tcpConnState not ASN_INTEGER\n");
|
505 |
|
|
return SNMP_ERR_WRONGTYPE;
|
506 |
|
|
}
|
507 |
|
|
if (var_val_len > sizeof(long_ret)){
|
508 |
|
|
fprintf(stderr,"write to tcpConnState: bad length\n");
|
509 |
|
|
return SNMP_ERR_WRONGLENGTH;
|
510 |
|
|
}
|
511 |
|
|
break;
|
512 |
|
|
|
513 |
|
|
|
514 |
|
|
case RESERVE2:
|
515 |
|
|
size = var_val_len;
|
516 |
|
|
long_ret = (long *) var_val;
|
517 |
|
|
|
518 |
|
|
|
519 |
|
|
break;
|
520 |
|
|
|
521 |
|
|
|
522 |
|
|
case FREE:
|
523 |
|
|
/* Release any resources that have been allocated */
|
524 |
|
|
break;
|
525 |
|
|
|
526 |
|
|
|
527 |
|
|
case ACTION:
|
528 |
|
|
/* The variable has been stored in long_ret for
|
529 |
|
|
you to use, and you have just been asked to do something with
|
530 |
|
|
it. Note that anything done here must be reversable in the UNDO case */
|
531 |
|
|
break;
|
532 |
|
|
|
533 |
|
|
|
534 |
|
|
case UNDO:
|
535 |
|
|
/* Back out any changes made in the ACTION case */
|
536 |
|
|
break;
|
537 |
|
|
|
538 |
|
|
|
539 |
|
|
case COMMIT:
|
540 |
|
|
/* Things are working well, so it's now safe to make the change
|
541 |
|
|
permanently. Make sure that anything done here can't fail! */
|
542 |
|
|
break;
|
543 |
|
|
}
|
544 |
|
|
return SNMP_ERR_NOERROR;
|
545 |
|
|
}
|
546 |
|
|
|
547 |
|
|
#endif
|
548 |
|
|
|
549 |
|
|
|
550 |
|
|
|
551 |
|
|
|
552 |
|
|
#if 0 // NOTSUPPORTED:
|
553 |
|
|
/*
|
554 |
|
|
* var_ipv6TcpConnTable():
|
555 |
|
|
* Handle this table separately from the scalar value case.
|
556 |
|
|
* The workings of this are basically the same as for var_tcp above.
|
557 |
|
|
*/
|
558 |
|
|
unsigned char *
|
559 |
|
|
var_ipv6TcpConnTable(struct variable *vp,
|
560 |
|
|
oid *name,
|
561 |
|
|
size_t *length,
|
562 |
|
|
int exact,
|
563 |
|
|
size_t *var_len,
|
564 |
|
|
WriteMethod **write_method)
|
565 |
|
|
{
|
566 |
|
|
|
567 |
|
|
|
568 |
|
|
/* variables we may use later */
|
569 |
|
|
static long long_ret;
|
570 |
|
|
static unsigned char string[SPRINT_MAX_LEN];
|
571 |
|
|
static oid objid[MAX_OID_LEN];
|
572 |
|
|
static struct counter64 c64;
|
573 |
|
|
|
574 |
|
|
|
575 |
|
|
/*
|
576 |
|
|
* This assumes that the table is a 'simple' table.
|
577 |
|
|
* See the implementation documentation for the meaning of this.
|
578 |
|
|
* You will need to provide the correct value for the TABLE_SIZE parameter
|
579 |
|
|
*
|
580 |
|
|
* If this table does not meet the requirements for a simple table,
|
581 |
|
|
* you will need to provide the replacement code yourself.
|
582 |
|
|
* Mib2c is not smart enough to write this for you.
|
583 |
|
|
* Again, see the implementation documentation for what is required.
|
584 |
|
|
*/
|
585 |
|
|
// if (header_simple_table(vp,name,length,exact,var_len,write_method,
|
586 |
|
|
// IPV6TCPCONNTABLE_TABLE_SIZE)
|
587 |
|
|
// == MATCH_FAILED )
|
588 |
|
|
return NULL;
|
589 |
|
|
|
590 |
|
|
|
591 |
|
|
/*
|
592 |
|
|
* this is where we do the value assignments for the mib results.
|
593 |
|
|
*/
|
594 |
|
|
switch(vp->magic) {
|
595 |
|
|
|
596 |
|
|
|
597 |
|
|
case IPV6TCPCONNSTATE:
|
598 |
|
|
*write_method = write_ipv6TcpConnState;
|
599 |
|
|
long_ret = 0;
|
600 |
|
|
return (unsigned char *) &long_ret;
|
601 |
|
|
|
602 |
|
|
|
603 |
|
|
default:
|
604 |
|
|
ERROR_MSG("");
|
605 |
|
|
}
|
606 |
|
|
return NULL;
|
607 |
|
|
}
|
608 |
|
|
|
609 |
|
|
|
610 |
|
|
|
611 |
|
|
|
612 |
|
|
int
|
613 |
|
|
write_ipv6TcpConnState(int action,
|
614 |
|
|
u_char *var_val,
|
615 |
|
|
u_char var_val_type,
|
616 |
|
|
size_t var_val_len,
|
617 |
|
|
u_char *statP,
|
618 |
|
|
oid *name,
|
619 |
|
|
size_t name_len)
|
620 |
|
|
{
|
621 |
|
|
static long *long_ret;
|
622 |
|
|
int size;
|
623 |
|
|
|
624 |
|
|
|
625 |
|
|
switch ( action ) {
|
626 |
|
|
case RESERVE1:
|
627 |
|
|
if (var_val_type != ASN_INTEGER){
|
628 |
|
|
fprintf(stderr, "write to tcpConnState not ASN_INTEGER\n");
|
629 |
|
|
return SNMP_ERR_WRONGTYPE;
|
630 |
|
|
}
|
631 |
|
|
if (var_val_len > sizeof(long_ret)){
|
632 |
|
|
fprintf(stderr,"write to tcpConnState: bad length\n");
|
633 |
|
|
return SNMP_ERR_WRONGLENGTH;
|
634 |
|
|
}
|
635 |
|
|
break;
|
636 |
|
|
|
637 |
|
|
|
638 |
|
|
case RESERVE2:
|
639 |
|
|
size = var_val_len;
|
640 |
|
|
long_ret = (long *) var_val;
|
641 |
|
|
|
642 |
|
|
|
643 |
|
|
break;
|
644 |
|
|
|
645 |
|
|
|
646 |
|
|
case FREE:
|
647 |
|
|
/* Release any resources that have been allocated */
|
648 |
|
|
break;
|
649 |
|
|
|
650 |
|
|
|
651 |
|
|
case ACTION:
|
652 |
|
|
/* The variable has been stored in long_ret for
|
653 |
|
|
you to use, and you have just been asked to do something with
|
654 |
|
|
it. Note that anything done here must be reversable in the UNDO case */
|
655 |
|
|
break;
|
656 |
|
|
|
657 |
|
|
|
658 |
|
|
case UNDO:
|
659 |
|
|
/* Back out any changes made in the ACTION case */
|
660 |
|
|
break;
|
661 |
|
|
|
662 |
|
|
|
663 |
|
|
case COMMIT:
|
664 |
|
|
/* Things are working well, so it's now safe to make the change
|
665 |
|
|
permanently. Make sure that anything done here can't fail! */
|
666 |
|
|
break;
|
667 |
|
|
}
|
668 |
|
|
return SNMP_ERR_NOERROR;
|
669 |
|
|
}
|
670 |
|
|
|
671 |
|
|
#endif // NOTSUPPORTED: ipv6
|
672 |
|
|
|
673 |
|
|
// EOF tcp.c
|