1 |
27 |
unneback |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// snmp/snmpagent/current/src/mibgroup/mibII/udp.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 |
|
|
|
97 |
|
|
/* This should always be included first before anything else */
|
98 |
|
|
#include <config.h>
|
99 |
|
|
|
100 |
|
|
/* minimal include directives */
|
101 |
|
|
#include "mibincl.h"
|
102 |
|
|
#include "mibgroup/util_funcs.h"
|
103 |
|
|
#include "mibgroup/mibII/udp.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/udp.h>
|
114 |
|
|
#include <netinet/udp_var.h>
|
115 |
|
|
|
116 |
|
|
/*
|
117 |
|
|
* udp_variables_oid:
|
118 |
|
|
* this is the top level oid that we want to register under. This
|
119 |
|
|
* is essentially a prefix, with the suffix appearing in the
|
120 |
|
|
* variable below.
|
121 |
|
|
*/
|
122 |
|
|
|
123 |
|
|
|
124 |
|
|
oid udp_variables_oid[] = { 1,3,6,1,2,1,7 };
|
125 |
|
|
|
126 |
|
|
|
127 |
|
|
/*
|
128 |
|
|
* variable4 udp_variables:
|
129 |
|
|
* this variable defines function callbacks and type return information
|
130 |
|
|
* for the udp mib section
|
131 |
|
|
*/
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
struct variable4 udp_variables[] = {
|
135 |
|
|
/* magic number , variable type , ro/rw , callback fn , L, oidsuffix */
|
136 |
|
|
#define UDPINDATAGRAMS 1
|
137 |
|
|
{ UDPINDATAGRAMS , ASN_COUNTER , RONLY , var_udp, 1, { 1 } },
|
138 |
|
|
#define UDPNOPORTS 2
|
139 |
|
|
{ UDPNOPORTS , ASN_COUNTER , RONLY , var_udp, 1, { 2 } },
|
140 |
|
|
#define UDPINERRORS 3
|
141 |
|
|
{ UDPINERRORS , ASN_COUNTER , RONLY , var_udp, 1, { 3 } },
|
142 |
|
|
#define UDPOUTDATAGRAMS 4
|
143 |
|
|
{ UDPOUTDATAGRAMS , ASN_COUNTER , RONLY , var_udp, 1, { 4 } },
|
144 |
|
|
#define UDPLOCALADDRESS 7
|
145 |
|
|
{ UDPLOCALADDRESS , ASN_IPADDRESS , RONLY , var_udpTable, 3, { 5,1,1 } },
|
146 |
|
|
#define UDPLOCALPORT 8
|
147 |
|
|
{ UDPLOCALPORT , ASN_INTEGER , RONLY , var_udpTable, 3, { 5,1,2 } },
|
148 |
|
|
|
149 |
|
|
//#define IPV6UDPIFINDEX 13
|
150 |
|
|
// { IPV6UDPIFINDEX , ASN_INTEGER , RONLY , var_ipv6UdpTable, 3, { 6,1,3 } },
|
151 |
|
|
|
152 |
|
|
};
|
153 |
|
|
/* (L = length of the oidsuffix) */
|
154 |
|
|
|
155 |
|
|
|
156 |
|
|
/*
|
157 |
|
|
* init_udp():
|
158 |
|
|
* Initialization routine. This is called when the agent starts up.
|
159 |
|
|
* At a minimum, registration of your variables should take place here.
|
160 |
|
|
*/
|
161 |
|
|
void init_udp(void) {
|
162 |
|
|
|
163 |
|
|
|
164 |
|
|
/* register ourselves with the agent to handle our mib tree */
|
165 |
|
|
REGISTER_MIB("udp", udp_variables, variable4,
|
166 |
|
|
udp_variables_oid);
|
167 |
|
|
|
168 |
|
|
|
169 |
|
|
/* place any other initialization junk you need here */
|
170 |
|
|
}
|
171 |
|
|
|
172 |
|
|
|
173 |
|
|
/*
|
174 |
|
|
* var_udp():
|
175 |
|
|
* This function is called every time the agent gets a request for
|
176 |
|
|
* a scalar variable that might be found within your mib section
|
177 |
|
|
* registered above. It is up to you to do the right thing and
|
178 |
|
|
* return the correct value.
|
179 |
|
|
* You should also correct the value of "var_len" if necessary.
|
180 |
|
|
*
|
181 |
|
|
* Please see the documentation for more information about writing
|
182 |
|
|
* module extensions, and check out the examples in the examples
|
183 |
|
|
* and mibII directories.
|
184 |
|
|
*/
|
185 |
|
|
unsigned char *
|
186 |
|
|
var_udp(struct variable *vp,
|
187 |
|
|
oid *name,
|
188 |
|
|
size_t *length,
|
189 |
|
|
int exact,
|
190 |
|
|
size_t *var_len,
|
191 |
|
|
WriteMethod **write_method)
|
192 |
|
|
{
|
193 |
|
|
static long long_ret;
|
194 |
|
|
|
195 |
|
|
if (header_generic(vp,name,length,exact,var_len,write_method)
|
196 |
|
|
== MATCH_FAILED )
|
197 |
|
|
return NULL;
|
198 |
|
|
|
199 |
|
|
switch(vp->magic) {
|
200 |
|
|
case UDPINDATAGRAMS:
|
201 |
|
|
long_ret = udpstat.udps_ipackets;
|
202 |
|
|
return (u_char *) &long_ret;
|
203 |
|
|
case UDPNOPORTS:
|
204 |
|
|
long_ret = udpstat.udps_noport;
|
205 |
|
|
return (u_char *) &long_ret;
|
206 |
|
|
case UDPOUTDATAGRAMS:
|
207 |
|
|
long_ret = udpstat.udps_opackets;
|
208 |
|
|
return (u_char *) &long_ret;
|
209 |
|
|
case UDPINERRORS:
|
210 |
|
|
long_ret = udpstat.udps_hdrops + udpstat.udps_badsum +
|
211 |
|
|
udpstat.udps_badlen;
|
212 |
|
|
return (u_char *) &long_ret;
|
213 |
|
|
default:
|
214 |
|
|
ERROR_MSG("");
|
215 |
|
|
}
|
216 |
|
|
return NULL;
|
217 |
|
|
}
|
218 |
|
|
|
219 |
|
|
|
220 |
|
|
/*
|
221 |
|
|
* var_udpTable():
|
222 |
|
|
* Handle this table separately from the scalar value case.
|
223 |
|
|
* The workings of this are basically the same as for var_udpTable above.
|
224 |
|
|
*/
|
225 |
|
|
unsigned char *
|
226 |
|
|
var_udpTable(struct variable *vp,
|
227 |
|
|
oid *name,
|
228 |
|
|
size_t *length,
|
229 |
|
|
int exact,
|
230 |
|
|
size_t *var_len,
|
231 |
|
|
WriteMethod **write_method)
|
232 |
|
|
{
|
233 |
|
|
static long long_ret;
|
234 |
|
|
static unsigned char string[SPRINT_MAX_LEN];
|
235 |
|
|
register struct inpcb *inp;
|
236 |
|
|
register struct inpcb *low_inp = NULL;
|
237 |
|
|
oid lowest[16];
|
238 |
|
|
oid newname[16];
|
239 |
|
|
u_char *cp;
|
240 |
|
|
oid *op;
|
241 |
|
|
|
242 |
|
|
// This is indexed by local-address, local-port, at 1,3,6,1,2,1,7,5,1,1,
|
243 |
|
|
// so we get 1,3,6,1,2,1,7,5,1,?,A,B,C,D,port
|
244 |
|
|
// initial length is 10, out-length is 15,
|
245 |
|
|
// Address is offsets 10-13, port is offset 14.
|
246 |
|
|
|
247 |
|
|
// starting from udbtable, look in
|
248 |
|
|
// low_pcb->inp_laddr.s_addr
|
249 |
|
|
// and low_pcb->inp_lport
|
250 |
|
|
|
251 |
|
|
/* fill in object part of name for current (less sizeof instance part) */
|
252 |
|
|
memcpy((char *)newname, (char *)vp->name, (int)vp->namelen * sizeof(oid));
|
253 |
|
|
|
254 |
|
|
for (
|
255 |
|
|
#ifdef CYGPKG_NET_OPENBSD_STACK
|
256 |
|
|
inp = udbtable.inpt_queue.cqh_first;
|
257 |
|
|
inp != (struct inpcb *)&udbtable.inpt_queue;
|
258 |
|
|
inp = inp->inp_queue.cqe_next
|
259 |
|
|
#endif
|
260 |
|
|
#ifdef CYGPKG_NET_FREEBSD_STACK
|
261 |
|
|
inp = udb.lh_first;
|
262 |
|
|
inp;
|
263 |
|
|
inp = inp->inp_list.le_next
|
264 |
|
|
#endif
|
265 |
|
|
) {
|
266 |
|
|
cp = (u_char *)&inp->inp_laddr.s_addr;
|
267 |
|
|
op = newname + 10;
|
268 |
|
|
*op++ = *cp++;
|
269 |
|
|
*op++ = *cp++;
|
270 |
|
|
*op++ = *cp++;
|
271 |
|
|
*op++ = *cp++;
|
272 |
|
|
|
273 |
|
|
newname[14] = ntohs(inp->inp_lport);
|
274 |
|
|
|
275 |
|
|
if (exact){
|
276 |
|
|
if (snmp_oid_compare(newname, 15, name, *length) == 0){
|
277 |
|
|
memcpy( (char *)lowest,(char *)newname, 15 * sizeof(oid));
|
278 |
|
|
low_inp = inp;
|
279 |
|
|
break; /* no need to search further */
|
280 |
|
|
}
|
281 |
|
|
} else {
|
282 |
|
|
if ((snmp_oid_compare(newname, 15, name, *length) > 0) &&
|
283 |
|
|
(!low_inp || (snmp_oid_compare(newname, 15, lowest, 15) < 0))){
|
284 |
|
|
/*
|
285 |
|
|
* if new one is greater than input and closer to input than
|
286 |
|
|
* previous lowest, save this one as the "next" one.
|
287 |
|
|
*/
|
288 |
|
|
memcpy( (char *)lowest,(char *)newname, 15 * sizeof(oid));
|
289 |
|
|
low_inp = inp;
|
290 |
|
|
}
|
291 |
|
|
}
|
292 |
|
|
}
|
293 |
|
|
|
294 |
|
|
if ( ! low_inp )
|
295 |
|
|
return NULL;
|
296 |
|
|
|
297 |
|
|
memcpy( (char *)name,(char *)lowest, 15 * sizeof(oid));
|
298 |
|
|
*length = 15;
|
299 |
|
|
*var_len = sizeof( long_ret );
|
300 |
|
|
*write_method = 0;
|
301 |
|
|
|
302 |
|
|
switch(vp->magic) {
|
303 |
|
|
|
304 |
|
|
case UDPLOCALADDRESS:
|
305 |
|
|
cp = (u_char *)&low_inp->inp_laddr.s_addr;
|
306 |
|
|
string[0] = *cp++;
|
307 |
|
|
string[1] = *cp++;
|
308 |
|
|
string[2] = *cp++;
|
309 |
|
|
string[3] = *cp++;
|
310 |
|
|
*var_len = 4;
|
311 |
|
|
return (unsigned char *) string;
|
312 |
|
|
|
313 |
|
|
case UDPLOCALPORT:
|
314 |
|
|
long_ret = (long)ntohs(low_inp->inp_lport);
|
315 |
|
|
return (unsigned char *) &long_ret;
|
316 |
|
|
|
317 |
|
|
default:
|
318 |
|
|
ERROR_MSG("");
|
319 |
|
|
}
|
320 |
|
|
return NULL;
|
321 |
|
|
}
|
322 |
|
|
|
323 |
|
|
|
324 |
|
|
// EOF udp.c
|