comparison packages/net/snmp/agent/current/src/mibgroup/mibII/interfaces.c @ 117:bd1a71e3e476 ecos-sw-2000-08-25

Merge from eCos master repository on 2000-08-25-19:22:58-BST
author jlarmour
date Fri, 25 Aug 2000 19:17:22 +0000
parents 95f3e12a6327
children a9ac27ec7abc
comparison
equal deleted inserted replaced
116:a0f9581a3a09 117:bd1a71e3e476
96 #include <net/if_types.h> 96 #include <net/if_types.h>
97 97
98 // Get info about the device 98 // Get info about the device
99 #include <pkgconf/system.h> 99 #include <pkgconf/system.h>
100 100
101 // These two two acquire all the statistics.
101 #include <eth_drv.h> 102 #include <eth_drv.h>
102 103 #include <eth_drv_stats.h>
103 #ifdef CYGBLD_DEVS_ETH_DEVICE_H 104 #include <sys/sockio.h>
104 #include CYGBLD_DEVS_ETH_DEVICE_H
105 #endif
106
107 #ifdef CYGBLD_DEVS_ETH_INFO_H
108 #include CYGBLD_DEVS_ETH_INFO_H
109 #endif
110 105
111 /* 106 /*
112 * interfaces_variables_oid: 107 * interfaces_variables_oid:
113 * this is the top level oid that we want to register under. This 108 * this is the top level oid that we want to register under. This
114 * is essentially a prefix, with the suffix appearing in the 109 * is essentially a prefix, with the suffix appearing in the
264 size_t *var_len, 259 size_t *var_len,
265 WriteMethod **write_method) 260 WriteMethod **write_method)
266 { 261 {
267 262
268 263
269 /* variables we may use later */ 264 /* variables we may use later */
270 static long long_ret; 265 static long long_ret;
271 static unsigned char string[SPRINT_MAX_LEN]; 266 static unsigned char string[SPRINT_MAX_LEN];
272 static oid objid[MAX_OID_LEN]; 267 static oid objid[MAX_OID_LEN];
273 // static struct counter64 c64; 268 // static struct counter64 c64;
274 269
275 register struct ifnet *ifp; 270 register struct ifnet *ifp;
276 int interface_count = 0; 271 int interface_count = 0;
277 272
278 for (ifp = ifnet.tqh_first; ifp != 0; ifp = ifp->if_list.tqe_next) 273 for (ifp = ifnet.tqh_first; ifp != 0; ifp = ifp->if_list.tqe_next)
279 interface_count++; 274 interface_count++;
280 275
281 /* 276 /*
282 * This assumes that the table is a 'simple' table. 277 * This assumes that the table is a 'simple' table.
283 * See the implementation documentation for the meaning of this. 278 * See the implementation documentation for the meaning of this.
284 * You will need to provide the correct value for the TABLE_SIZE parameter 279 * You will need to provide the correct value for the TABLE_SIZE parameter
285 * 280 *
286 * If this table does not meet the requirements for a simple table, 281 * If this table does not meet the requirements for a simple table,
287 * you will need to provide the replacement code yourself. 282 * you will need to provide the replacement code yourself.
288 * Mib2c is not smart enough to write this for you. 283 * Mib2c is not smart enough to write this for you.
289 * Again, see the implementation documentation for what is required. 284 * Again, see the implementation documentation for what is required.
290 */ 285 */
291 if ( header_simple_table( vp,name,length,exact,var_len,write_method, 286 if ( header_simple_table( vp,name,length,exact,var_len,write_method,
292 interface_count) 287 interface_count)
293 == MATCH_FAILED ) 288 == MATCH_FAILED )
294 return NULL; 289 return NULL;
295 290
296 for ( interface_count = name[ (*length)-1 ], ifp = ifnet.tqh_first; 291 for ( interface_count = name[ (*length)-1 ], ifp = ifnet.tqh_first;
297 interface_count > 1 && ifp != 0; 292 interface_count > 1 && ifp != 0;
298 interface_count-- ) 293 interface_count-- )
299 ifp = ifp->if_list.tqe_next; 294 ifp = ifp->if_list.tqe_next;
300 295
301 if ( ! ifp ) 296 if ( ! ifp )
302 return NULL; 297 return NULL;
298
299 if ( IFT_ETHER == ifp->if_type &&
300 ((IFDESCR == vp->magic) ||
301 (IFSPEED == vp->magic) ||
302 (IFOUTDISCARDS == vp->magic) ||
303 (IFOUTQLEN == vp->magic) )
304 ) {
305 // then acquire up to date information and deal with the relevent
306 // keys (only):
307 int i = -1;
308 struct ether_drv_stats x;
309 bzero( &x, sizeof( x ) );
310
311 // Call the ioctl to get all the info.
312 // (We KNOW it's an ether dev here, it should have an ioctl())
313 if ( NULL != ifp->if_ioctl )
314 i = (*ifp->if_ioctl)(ifp, SIOCGIFSTATSUD, (caddr_t)&x);
315
316 switch(vp->magic) {
317 case IFDESCR:
318 if ( i || 0 == x.description[0] )
319 strcpy( string, "<Ethernet, details not available>" );
320 else
321 strcpy( string, x.description );
322 *var_len = strlen(string);
323 return (unsigned char *) string;
324
325 case IFSPEED:
326 long_ret = x.speed;
327 return (unsigned char *) &long_ret;
328
329 case IFOUTDISCARDS:
330 long_ret = x.tx_dropped;
331 return (unsigned char *) &long_ret;
332
333 case IFOUTQLEN:
334 long_ret = x.tx_queue_len;
335 return (unsigned char *) &long_ret;
336
337 default:
338 CYG_FAIL( "Bad magic; shouldn't be in here" );
339 break;
340 }
341 }
303 342
304 switch(vp->magic) { 343 switch(vp->magic) {
305 344
306 case IFINDEX: 345 case IFINDEX:
307 long_ret = name[(*length)-1]; 346 long_ret = name[(*length)-1];
308 return (unsigned char *) &long_ret; 347 return (unsigned char *) &long_ret;
309 348
310 case IFDESCR: 349 case IFDESCR:
311 if ( IFT_LOOP == ifp->if_type ) 350 switch ( ifp->if_type ) {
351 case IFT_LOOP:
312 strcpy( string, "(Loopback device)" ); 352 strcpy( string, "(Loopback device)" );
313 else { 353 break;
314 #ifdef CYGDAT_DEVS_ETH_DESCRIPTION 354 case IFT_PROPVIRTUAL:
315 strcpy( string, CYGDAT_DEVS_ETH_DESCRIPTION ); 355 strcpy( string, "(Proprietary Virtual/Internal)" );
316 #else 356 break;
317 strcpy( string, "Some shy Ethernet adaptor" ); 357 default:
318 #endif 358 strcpy( string, "Some shy network adaptor" );
359 break;
319 } 360 }
320 *var_len = strlen(string); 361 *var_len = strlen(string);
321 return (unsigned char *) string; 362 return (unsigned char *) string;
322 363
323 case IFTYPE: 364 case IFTYPE:
329 return (unsigned char *) &long_ret; 370 return (unsigned char *) &long_ret;
330 371
331 case IFSPEED: 372 case IFSPEED:
332 if ( IFT_LOOP == ifp->if_type ) 373 if ( IFT_LOOP == ifp->if_type )
333 long_ret = 0; 374 long_ret = 0;
375 else
376 long_ret = ifp->if_baudrate;
377 return (unsigned char *) &long_ret;
378
379 case IFPHYSADDRESS: {
380 if ( IFT_ETHER == ifp->if_type ) {
381 struct arpcom *ac = (struct arpcom *)ifp;
382 bcopy(&ac->ac_enaddr, string, ETHER_ADDR_LEN);
383 }
334 else { 384 else {
335 #ifdef ETH_DEV_IFSPEED
336 struct eth_drv_sc *sc = ifp->if_softc;
337 #ifdef ETH_STATS_INIT
338 ETH_STATS_INIT( sc );
339 #endif
340 long_ret = ETH_DEV_IFSPEED( sc );
341 #else
342 long_ret = ifp->if_baudrate;
343 #endif
344 }
345 return (unsigned char *) &long_ret;
346
347 case IFPHYSADDRESS: {
348 if ( IFT_LOOP == ifp->if_type )
349 bzero( string, ETHER_ADDR_LEN ); 385 bzero( string, ETHER_ADDR_LEN );
350 else {
351 struct eth_drv_sc *sc = ifp->if_softc;
352 bcopy(&sc->sc_arpcom.ac_enaddr, string, ETHER_ADDR_LEN);
353 } 386 }
354 *var_len = ETHER_ADDR_LEN; 387 *var_len = ETHER_ADDR_LEN;
355 return (unsigned char *) string; 388 return (unsigned char *) string;
356 } 389 }
357 case IFADMINSTATUS: 390 case IFADMINSTATUS:
402 case IFOUTNUCASTPKTS: 435 case IFOUTNUCASTPKTS:
403 long_ret = ifp->if_omcasts; 436 long_ret = ifp->if_omcasts;
404 return (unsigned char *) &long_ret; 437 return (unsigned char *) &long_ret;
405 438
406 case IFOUTDISCARDS: 439 case IFOUTDISCARDS:
407 if ( IFT_LOOP == ifp->if_type ) 440 long_ret = 0; // ETHER case dealt with above
408 long_ret = 0;
409 else {
410 #ifdef ETH_DEV_IFOUTDISCARDS
411 long_ret = ETH_DEV_IFOUTDISCARDS( (struct eth_drv_sc *)(ifp->if_softc) );
412 #else
413 long_ret = 0;
414 #endif
415 }
416 return (unsigned char *) &long_ret; 441 return (unsigned char *) &long_ret;
417 442
418 case IFOUTERRORS: 443 case IFOUTERRORS:
419 long_ret = ifp->if_oerrors; 444 long_ret = ifp->if_oerrors;
420 return (unsigned char *) &long_ret; 445 return (unsigned char *) &long_ret;
421 446
422 case IFOUTQLEN: 447 case IFOUTQLEN:
423 if ( IFT_LOOP == ifp->if_type ) 448 long_ret = 0; // ETHER case dealt with above
424 long_ret = 0;
425 else {
426 #ifdef ETH_DEV_IFOUTQLEN
427 long_ret = ETH_DEV_IFOUTQLEN( (struct eth_drv_sc *)(ifp->if_softc) );
428 #else
429 long_ret = 0;
430 #endif
431 }
432 return (unsigned char *) &long_ret; 449 return (unsigned char *) &long_ret;
433 450
434 case IFSPECIFIC: 451 case IFSPECIFIC:
435 objid[0] = 0; 452 objid[0] = 0;
436 objid[1] = 0; 453 objid[1] = 0;