Add .gitignore file
[s390-tools.git] / osasnmpd / ibmOSAMib.c
blob03e111f470ddf68f560e1104019e2134d998f8c4
1 /*
2 * File...........: ibmOSAMib.c
3 * Author(s)......: Thomas Weber <tweber@de.ibm.com>
4 * Copyright IBM Corp. 2002,2007
6 * History of changes:
7 * none
8 *
9 * Basic MIB implementation module for the OSA-E subagent.
10 * The code in this module is typical for a ucd-snmp MIB implementation
11 * information on how this works.
12 * Because the MIB layout is retrieved during startup of the subagent,
13 * the magic indentifier is not used within this implementation.
14 * The var_ function uses the vp->type instead to distinct the OIDs.
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2, or (at your option)
19 * any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 #include "ibmOSAMibUtil.h"
32 #include "ibmOSAMib.h"
33 #include "zt_common.h"
35 /* ptr to OSA Express MIB information stored in linked lists */
36 TABLE_OID* oid_list_head;
38 /* ptr to interface information on this system */
39 IF_LIST* if_list;
40 int ifNumber;
44 /**********************************************************************
45 * init_ibmOSAMib():
46 * Initialization routine. This function is called when the agent
47 * starts up.
48 * parameters:
49 * IN uses global MIB data
50 * OUT none
51 * returns: none
52 *********************************************************************/
53 void init_ibmOSAMib(void) {
55 int i,
56 sd, /* socket descriptor */
57 error_code, /* holds errno value */
58 osaexp_num, /* number of OSA Express devices */
59 retc; /* return code from register_tables */
61 struct ifreq ifr; /* request structure for ioctl */
62 IPA_CMD_REG* ipa_reg_mib; /* structure for IPA REGISTER MIB command header */
63 char* buffer; /* a data buffer */
64 char time_buf[TIME_BUF_SIZE]; /* date/time buffer */
66 /* init head for Toplevel OID linked list */
67 oid_list_head = init_oid_list();
68 if ( oid_list_head == NULL )
70 fprintf( stderr, "init_ibmOSAMib(): "
71 "malloc() for OID list head failed\n"
72 "Cannot start subagent...exiting...\n");
73 exit(1);
76 /* GET ucd-snmp ifNumber/ifIndex/ifDescr from IF-MIB for all interfaces */
77 /* on this system */
78 ifNumber = query_IF_MIB( &if_list );
79 if ( ifNumber < 0 )
81 fprintf( stderr, "init_ibmOSAMib(): "
82 "could not obtain interface info from IF-MIB\n"
83 "check if: snmpd daemon is started and subagent "
84 "access control is correct\n"
85 "see agent log file for more details\n"
86 "Cannot start subagent...exiting...\n");
87 exit(1);
89 else if ( ifNumber == 0 )
91 get_time( time_buf );
92 snmp_log( LOG_ERR, "%s init_ibmOSAMib(): "
93 "SNMP reports no devices within IF-MIB"
94 " - starting subagent anyway\n", time_buf );
95 return;
96 } /* end if */
98 /* query OSA-E device driver for OSA-E devices and mark them in IF-MIB interface list */
99 osaexp_num = query_OSA_EXP ( &if_list, ifNumber );
100 if ( osaexp_num < 0 )
102 fprintf( stderr, "init_ibmOSAMib(): "
103 "OSA-E device driver query interface ioctl() failed\n"
104 "check agent log file for more details\n"
105 "Cannot start subagent...exiting...\n");
106 exit(1);
108 else if ( osaexp_num == 0 )
110 fprintf( stderr, "init_ibmOSAMib(): bad or no OSA-E devices reported\n"
111 "check agent log file for more details\n"
112 "Cannot start subagent...exiting...\n");
113 exit(1);
115 /* end if */
117 /* allocate area, that should contain retrieved MIB data for a single interface */
118 buffer = (char*) malloc ( MIB_AREA_LEN );
119 if ( buffer == NULL )
121 fprintf( stderr, "init_ibmOSAMib(): "
122 "malloc() for REGISTER MIB data buffer "
123 "failed\ninit_ibmOSAMib(): requested %d bytes\n"
124 "Cannot start subagent...exiting...\n",
125 MIB_AREA_LEN );
126 exit(1);
127 } /* end if */
129 /* open socket for ioctl */
130 sd = socket( AF_INET, SOCK_STREAM, 0 );
131 if ( sd < 0 )
133 error_code = errno;
134 fprintf( stderr, "init_ibmOSAMIB(): "
135 "error opening socket() - reason %s\n"
136 "Cannot start subagent...exiting...\n",
137 strerror( error_code ) );
138 exit(1);
139 } /* end if */
141 /* walk through interface list and query MIB data for all OSA-E devices */
142 /* register MIB data with subagent driving code afterwards */
143 for ( i=0; i < ifNumber; i++ )
145 if ( if_list[i].is_OSAEXP == TRUE )
147 /* clear buffer */
148 memset( buffer, 0, MIB_AREA_LEN );
150 /* setup ioctl buffer with request and input parameters */
151 ipa_reg_mib = (IPA_CMD_REG*) buffer; /* map command structure */
152 ipa_reg_mib->ioctl_cmd.data_len = /* length of IPA data area */
153 MIB_AREA_LEN - offsetof( IOCTL_CMD_HDR, ipa_cmd_hdr );
154 ipa_reg_mib->ioctl_cmd.req_len = /* length of IPA subcommand */
155 sizeof( ipa_reg_mib->ioctl_cmd );
157 ipa_reg_mib->ioctl_cmd.ipa_cmd_hdr.request = IPA_REG_MIB; /* IPA subcommand code */
158 ipa_reg_mib->ioctl_cmd.ipa_cmd_hdr.ifIndex = if_list[i].ifIndex; /* assign IF-MIB ifIndex */
159 ipa_reg_mib->ioctl_cmd.ipa_cmd_hdr.ret_code = 0;
160 ipa_reg_mib->ioctl_cmd.ipa_cmd_hdr.seq_num = 0; /* sequence number not used */
162 /* do ioctl */
163 strcpy( ifr.ifr_name, if_list[i].if_Name ); /* add interface name */
164 ifr.ifr_ifru.ifru_data = (char*) buffer; /* add data buffer */
166 if ( ioctl( sd, SIOC_QETH_ADP_SET_SNMP_CONTROL, &ifr ) < 0 )
168 error_code = errno;
170 /* see if we got a common I/O error */
171 if ( error_code == -EIO )
173 get_time( time_buf );
174 snmp_log( LOG_ERR, "%s init_ibmOSAMib(): "
175 "ioctl() failed - reason %s for interface %s\n"
176 "init_ibmOSAMib(): start subagent anyway\n",
177 time_buf, strerror( error_code ), if_list[i].if_Name );
178 close( sd );
179 free( buffer );
180 return;
181 break;
182 } /* end if */
184 /* let's see, if we got a return code from IPAssists */
185 /* or if MIB buffer is exhausted */
186 switch ( ipa_reg_mib->ioctl_cmd.ipa_cmd_hdr.ret_code ) {
187 case IPA_FAILED:
188 fprintf( stderr, "init_ibmOSAMib(): "
189 "ioctl() failed - IPA command failed "
190 "init_ibmOSAMib(): "
191 "Can't get MIB information for network interface %s\n"
192 "Cannot start subagent...exiting...\n", if_list[i].if_Name );
193 break;
195 case IPA_NOT_SUPP:
196 fprintf( stderr, "init_ibmOSAMib(): "
197 "ioctl() failed - IPA command not supported "
198 "init_ibmOSAMib(): "
199 "Can't get MIB information for network interface %s\n"
200 "Cannot start subagent...exiting...\n", if_list[i].if_Name );
201 break;
203 case IPA_NO_DATA:
204 get_time( time_buf );
205 snmp_log( LOG_ERR, "%s init_ibmOSAMib(): "
206 "ioctl() failed - valid IPA command, but no"
207 " SNMP data is available for interface %s\n"
208 "init_ibmOSAMib(): start subagent anyway\n",
209 time_buf, if_list[i].if_Name );
210 close( sd );
211 free( buffer );
212 return;
213 break;
215 case -ENOMEM: /* should not happen in the near future ;-) */
216 fprintf( stderr, "init_ibmOSAMib(): "
217 "ioctl() failed - MIB data size > "
218 "constant MIB_AREA_LEN\n"
219 "init_ibmOSAMib(): "
220 "Enlarge constant for MIB_AREA_LEN within "
221 "ibmOSAMibDefs.h and recompile the subagent\n"
222 "init_ibmOSAMib(): "
223 "Can't get MIB information for network interfaces\n"
224 "Cannot start subagent...exiting...\n" );
225 break;
226 default:
227 fprintf( stderr, "init_ibmOSAMib(): "
228 "ioctl() failed - reason %s\n"
229 "init_ibmOSAMib(): "
230 "Can't get MIB information for network interface %s\n"
231 "Cannot start subagent...exiting...\n",
232 strerror( error_code ), if_list[i].if_Name );
233 break;
234 } /* end switch */
236 exit(1);
238 else if( ipa_reg_mib->ioctl_cmd.ipa_cmd_hdr.ret_code != 0 )
240 /* now check IPA SNMP subcommand return code */
241 switch ( ipa_reg_mib->ioctl_cmd.ipa_cmd_hdr.ret_code ) {
243 case IPA_SNMP_INV_TOPOID:
244 case IPA_SNMP_INV_GROUP:
245 case IPA_SNMP_INV_SUFFIX:
246 case IPA_SNMP_INV_INST:
247 case IPA_SNMP_OID_NREAD:
248 case IPA_SNMP_OID_NWRIT:
249 get_time( time_buf );
250 snmp_log( LOG_ERR, "%s init_ibmOSAMib(): "
251 "IPA SNMP subcommand failed\n"
252 "init_ibmOSAMib(): "
253 "IPA SNMP subcommand return code 0x%x\n"
254 "init_ibmOSAMib(): "
255 "Can't get MIB information for network interface %s\n"
256 "Cannot start subagent...exiting...\n", time_buf,
257 ipa_reg_mib->ioctl_cmd.ipa_cmd_hdr.ret_code,
258 if_list[i].if_Name );
259 break;
261 case IPA_SNMP_NOT_SUPP:
262 get_time( time_buf );
263 snmp_log( LOG_ERR, "%s init_ibmOSAMib(): "
264 "IPA SNMP subcommand failed - subcommand 0x%x "
265 "not supported\ninit_ibmOSAMib(): "
266 "Can't get MIB information for network interface %s\n"
267 "Cannot start subagent...exiting...\n", time_buf,
268 ipa_reg_mib->ioctl_cmd.ipa_cmd_hdr.request,
269 if_list[i].if_Name );
270 break;
272 case IPA_SNMP_NO_DATA:
273 get_time( time_buf );
274 snmp_log( LOG_ERR, "%s init_ibmOSAMib(): "
275 "IPA SNMP subcommand failed - no data available\n"
276 "init_ibmOSAMib(): "
277 "Can't get MIB information for network interface %s\n"
278 "Cannot start subagent...exiting...\n", time_buf,
279 if_list[i].if_Name );
280 break;
282 default:
283 get_time( time_buf );
284 snmp_log( LOG_ERR, "%s init_ibmOSAMib(): "
285 "IPA SNMP subcommand failed - undefined return code"
286 " 0x%x\ninit_ibmOSAMib(): "
287 "Can't get MIB information for network interface %s\n"
288 "Cannot start subagent...exiting...\n", time_buf,
289 ipa_reg_mib->ioctl_cmd.ipa_cmd_hdr.ret_code,
290 if_list[i].if_Name );
291 break;
293 } /* end switch */
295 exit(1);
297 } /* end if */
299 /* save microcode level */
300 if_list[i].ipa_ver = ipa_reg_mib->ioctl_cmd.ipa_cmd_hdr.ipa_ver;
303 /* register initial table information, that we got from IPAssists */
304 retc = register_tables ( buffer, oid_list_head );
305 if ( retc != 0 )
307 fprintf( stderr, "init_ibmOSAMib(): "
308 "register MIB data with subagent driving "
309 "code failed\ninit_ibmOSAMib(): for ifIndex %d ifDescr %s\n"
310 "check agent log file for more details\n"
311 "Cannot start subagent...exiting...\n",
312 if_list[i].ifIndex, if_list[i].if_Name );
313 exit(1);
314 } /* end if */
315 } /* end if */
317 } /* end for */
319 /* log IPA microcode level per interface */
320 for ( i=0; i < ifNumber; i++ )
322 if ( if_list[i].is_OSAEXP == TRUE )
323 snmp_log( LOG_INFO, "OSA-E microcode level is %x for interface %s\n",
324 if_list[i].ipa_ver,
325 if_list[i].if_Name );
326 } /* end for */
328 /* free resources */
329 close( sd );
330 free( buffer );
332 } /* end init_ibmOSAMib */
335 /**********************************************************************
336 * var_ibmOSAMib():
337 * This function is called every time the agent gets a request for
338 * any MIB data for the IBM OSA express MIB. It's up to this function
339 * to return the appropriate data back to the subagent driving code.
340 * This function supports all standard SNMIv2 data types.
341 * parameters:
342 * IN variable vp - entry in variableN array
343 * INOUT oid *name - OID from original request/OID being returned
344 * INOUT size_t *length - length of orig. OID/length of ret. OID
345 * IN int exact - exact/inexact request
346 * OUT size_t *var_len - length of answer being returned
347 * OUT WriteMethod **write_method - unused
348 * returns: NULL - vp entry does not match or instance wrong
349 * - something within ioctl handling failed
350 * else data returned as answer
351 *********************************************************************/
352 unsigned char* var_ibmOSAMib( struct variable *vp,
353 oid *name,
354 size_t *length,
355 int exact,
356 size_t *var_len,
357 WriteMethod **write_method)
359 /* variables for returning data back to the subagent driving code */
360 static long long_ret;
361 static unsigned char octetstr_buf[MAX_GET_DATA];
362 static oid objid[MAX_OID_LEN];
363 static struct counter64 osa_counter64;
364 long *ptr_long;
365 int *ptr_int;
366 unsigned char *ptr_uchar;
368 int ifIndex; /* IF-MIB ifIndex of the OSA device that is queried for data */
369 int offset; /* offset to returned data portion within GET command area */
370 char time_buf[TIME_BUF_SIZE]; /* date/time buffer */
372 IPA_CMD_GET *get_cmd; /* area for GET command */
373 IPA_GET_DATA *get_res; /* pointer to offset where data portion starts */
374 void *tmp_ptr;
377 * This function compares the full OID that is passed in to the registered
378 * OIDs from this subagent.
379 * It is the IBM OSA Express specific version of the default
380 * header_simple_table() function, that is normally used in case of a simple
381 * table. Place a mutual exlusion lock around this operation to avoid
382 * interfering threads, when updating the internal MIB table thru thread
383 * update_mib_info()
386 ifIndex = header_osa_table( vp, name, length, exact, var_len, write_method,
387 oid_list_head );
389 if ( ifIndex == MATCH_FAILED )
390 return NULL;
393 /* issue ioctl to query Get/Getnext request data */
394 offset = do_GET_ioctl ( ifIndex, name, *length, &get_cmd );
395 if ( offset < 0 )
397 return NULL;
401 * return the result to subagent driving code
404 /* map data portion returned by IPAssists */
405 /* # ptr GET command area + offset returned data portion */
406 /* # align PTR to 4 byte bdy where data portion starts */
407 tmp_ptr = (char*) get_cmd;
408 tmp_ptr += offset;
409 get_res = (IPA_GET_DATA*) (PTR_ALIGN4( tmp_ptr ));
411 switch( vp->type ) {
413 case ASN_INTEGER: case ASN_COUNTER: case ASN_GAUGE: case ASN_TIMETICKS:
414 /* ASN_UNSIGNED is same as ASN_GAUGE (RFC1902) */
416 if ( get_res->len == sizeof(int) )
418 ptr_int = (int*) get_res->data;
419 long_ret = (long) *ptr_int;
421 else
423 ptr_long = (long*) get_res->data;
424 long_ret = (long) *ptr_long;
425 } /* end if */
427 free( get_cmd );
429 return (unsigned char *) &long_ret;
430 break;
432 case ASN_COUNTER64:
434 if ( get_res->len > 8 )
436 get_time( time_buf );
437 snmp_log( LOG_ERR, "%s var_ibmOSAMib(): "
438 "IPA data length for ASN_COUNTER64 > 8 bytes\n"
439 "var_ibmOSAMib(): rejected Get/Getnext request\n", time_buf );
440 free( get_cmd );
441 return NULL;
442 } /* end if */
444 /* IPA returns 8 bytes for COUNTER64 */
445 ptr_int = (int*) get_res->data;
446 osa_counter64.high = (int) *ptr_int;
447 ptr_int++;
448 osa_counter64.low = (int) *ptr_int;
450 *var_len = sizeof( osa_counter64 );
451 free( get_cmd );
453 return (unsigned char *) &osa_counter64;
454 break;
456 case ASN_OPAQUE: /* old v1 type/included for compability */
457 case ASN_OCTET_STR: /* used for Binary data */
458 /* case Display String is handled within var_DisplayStr() */
460 if ( get_res->len > MAX_GET_DATA )
462 get_time( time_buf );
463 snmp_log( LOG_ERR, "%s var_ibmOSAMib(): "
464 "IPA data length %d for ASN_OCTET_STR > "
465 "MAX_GET_DATA (%d bytes)\n"
466 "var_ibmOSAMib(): rejected Get/Getnext request\n",
467 time_buf, get_res->len, MAX_GET_DATA );
468 free( get_cmd );
469 return NULL;
470 } /* end if */
472 *var_len = get_res->len;
473 ptr_uchar = (unsigned char*) get_res->data;
474 memcpy( octetstr_buf, ptr_uchar, *var_len );
475 free( get_cmd );
477 return (unsigned char *) octetstr_buf;
478 break;
480 case ASN_IPADDRESS:
482 /* IPA IpAddress within 4 bytes hex data */
483 ptr_int = (int*) get_res->data;
484 long_ret = (long) *ptr_int;
485 free( get_cmd );
487 return (unsigned char *) &long_ret;
488 break;
490 case ASN_OBJECT_ID:
492 /* IPA returned ObjectId as character string, have to convert... */
493 *var_len = str_to_oid_conv ( get_res->data, objid );
494 if ( *var_len == 0 )
496 get_time( time_buf );
497 snmp_log( LOG_ERR, "%s var_ibmOSAMib(): IPA returned bad ObjectId - "
498 "cannot convert ucd-snmp oid type\n"
499 "var_ibmOSAMib(): rejected Get/Getnext request\n", time_buf );
500 free( get_cmd );
501 return NULL;
502 } /* end if */
504 *var_len = (*var_len) * sizeof( oid );
505 free( get_cmd );
507 return (unsigned char *) &objid;
508 break;
510 default:
511 get_time( time_buf );
512 snmp_log( LOG_ERR, "%s var_ibmOSAMib(): "
513 "got a not known ASN data type %x\n"
514 "var_ibmOSAMib(): "
515 "rejected Get/Getnext request\n", time_buf, vp->type );
517 } /* end switch */
519 free( get_cmd );
521 return NULL;
523 } /* end var_ibmOSAMib */
526 /**********************************************************************
527 * var_DisplayStr():
528 * This function handles the special case for Display Strings, which are
529 * a textual convention to Octet Strings. The binary data case for
530 * Octet Strings is handled within var_ibmOSAMib().
531 * It's up to this function to return the appropriate data back to the
532 * subagent driving code.
533 * parameters:
534 * IN variable vp - entry in variableN array
535 * INOUT oid *name - OID from original request/OID being returned
536 * INOUT size_t *length - length of orig. OID/length of ret. OID
537 * IN int exact - exact/inexact request
538 * OUT size_t *var_len - length of answer being returned
539 * OUT WriteMethod **write_method - unused
540 * returns: NULL - vp entry does not match or instance wrong
541 * - something within ioctl handling failed
542 * else data returned as answer
543 *********************************************************************/
544 unsigned char* var_DisplayStr( struct variable *vp,
545 oid *name,
546 size_t *length,
547 int exact,
548 size_t *var_len,
549 WriteMethod **write_method)
551 /* variables for returning a display string to the subagent driving code */
552 static char string[SPRINT_MAX_LEN];
553 char time_buf[TIME_BUF_SIZE]; /* date/time buffer */
555 int ifIndex; /* IF-MIB ifIndex of the OSA device that is queried for data */
556 int offset; /* offset to returned data portion within GET command area */
558 IPA_CMD_GET *get_cmd; /* area for GET command */
559 IPA_GET_DATA *get_res; /* pointer to offset where data portion starts */
560 void *tmp_ptr;
563 * This function compares the full OID that is passed in to the registered
564 * OIDs from this subagent.
565 * It is the IBM OSA Express specific version of the default
566 * header_simple_table() function, that is normally used in case of a simple
567 * table. Place a mutual exlusion lock around this operation to avoid
568 * interfering threads, when updating the internal MIB table thru thread
569 * update_mib_info()
572 ifIndex = header_osa_table( vp, name, length, exact, var_len, write_method,
573 oid_list_head );
575 if ( ifIndex == MATCH_FAILED )
576 return NULL;
579 /* issue ioctl to query Get/Getnext request data */
580 offset = do_GET_ioctl ( ifIndex, name, *length, &get_cmd );
581 if ( offset < 0 )
583 return NULL;
587 * return the result to subagent driving code
590 /* map data portion returned by IPAssists */
591 /* # ptr GET command area + offset returned data portion */
592 /* # align PTR to 4 byte bdy where data portion starts */
593 tmp_ptr = (char*) get_cmd;
594 tmp_ptr += offset;
595 get_res = (IPA_GET_DATA*) (PTR_ALIGN4( tmp_ptr ));
597 if ( vp->type == ASN_OCTET_STR)
599 if ( get_res->len >= SPRINT_MAX_LEN )
601 get_time( time_buf );
602 snmp_log( LOG_ERR, "%s var_DisplayStr(): "
603 "IPA data length %d for Display "
604 "String >= SPRINT_MAX_LEN (%d bytes)\n"
605 "var_ibmOSAMib(): rejected Get/Getnext request\n"
606 ,time_buf, get_res->len, SPRINT_MAX_LEN );
607 free( get_cmd );
608 return NULL;
609 } /* end if */
611 strncpy( string, get_res->data, get_res->len );
612 string[ get_res->len ] = '\0';
613 *var_len = strlen( string );
614 free( get_cmd );
616 return (unsigned char *) string;
618 else
620 get_time( time_buf );
621 snmp_log( LOG_ERR, "%s var_DisplayStr(): "
622 "expected a Display String here, "
623 "but got a different ASN data type: %x\n"
624 "var_DisplayStr(): "
625 "rejected Get/Getnext request\n", time_buf, vp->type );
626 } /* end if */
628 free( get_cmd );
630 return NULL;
632 } /* end var_DisplayStr */
635 /**********************************************************************
636 * do_GET_ioctl()
637 * This function handles the communication with an OSA Express Card
638 * to query the appropriate MIB information from IPAssists.
639 * An ioctl is used in order to qet the appropriate information.
640 * parameters:
641 * IN int ifIndex - IF-MIB interface index
642 * IN oid *name - OID being returned
643 * IN size_t len - length of ret. OID
644 * INOUT IPA_CMD_GET** cmd - GET command area
645 * returns: cmd_len - return offset to returned data
646 * -1 - ioctl() was not successful
647 *********************************************************************/
648 int do_GET_ioctl ( int ifIndex, oid *name, size_t len, IPA_CMD_GET **cmd )
650 int sd; /* socket descriptor */
651 int i, error_code;
652 char oid_str[MAX_OID_STR_LEN]; /* may hold an OID as string */
653 char time_buf[TIME_BUF_SIZE]; /* date/time buffer */
654 char device[IFNAME_MAXLEN] = "not_found"; /* device name for ioctl */
655 struct ifreq ifr; /* request structure for ioctl */
658 /* search device name in in global interface list for ifIndex */
659 for ( i=0; i < ifNumber; i++ )
661 if ( if_list[i].ifIndex == ifIndex )
663 strcpy( device, if_list[i].if_Name );
664 break;
666 } /* end for */
668 if ( strcmp( device, "not_found" ) == 0 )
670 get_time( time_buf );
671 snmp_log( LOG_ERR, "%s do_GET_ioctl(): "
672 "ifIndex %d is not recorded in "
673 "interface list\n"
674 "OSA Subagent MIB information may be incomplete!\n"
675 ,time_buf, ifIndex );
676 return -1;
680 * query IPAssists for data appropriate to the OID that we just validated
683 /* convert Get/GetNext OID to a string used by IPA */
684 if( oid_to_str_conv ( name, len, oid_str ) == FALSE )
686 get_time( time_buf );
687 snmp_log( LOG_ERR, "%s do_GET_ioctl(): "
688 "cannot convert OID to string object\n"
689 "do_GET_ioctl(): rejected request\n", time_buf );
690 return -1;
693 /* allocate memory for Get/GetNext command area */
694 *cmd = ( IPA_CMD_GET* ) malloc( GET_AREA_LEN );
695 if ( *cmd == NULL )
697 get_time( time_buf );
698 snmp_log( LOG_ERR,
699 "%s do_GET_ioctl(): "
700 "malloc() for GET command area failed\n"
701 "do_GET_ioctl(): rejected request for .%s\n",
702 time_buf, oid_str );
703 return -1;
704 } /* end if */
706 /* set up input parameters in Get/GetNext command area */
707 /* size of IPA data area */
708 (*cmd)->ioctl_cmd.data_len =
709 GET_AREA_LEN - offsetof( IOCTL_CMD_HDR, ipa_cmd_hdr );
711 /* size of IPA GET subcommand padded to 4-byte bdy */
712 (*cmd)->ioctl_cmd.req_len =
713 (sizeof((*cmd)->ioctl_cmd) + strlen( oid_str ) + 1 + 3)&(~3);
715 /* set up input parameters in Get/GetNext command area */
716 (*cmd)->ioctl_cmd.ipa_cmd_hdr.request = IPA_GET_OID; /* IPA subcommand code */
717 (*cmd)->ioctl_cmd.ipa_cmd_hdr.ifIndex = ifIndex; /* assign IF-MIB ifIndex */
718 (*cmd)->ioctl_cmd.ipa_cmd_hdr.ret_code = 0;
719 (*cmd)->ioctl_cmd.ipa_cmd_hdr.seq_num = 0; /* sequence# is not used */
720 strcpy( (*cmd)->full_oid, oid_str ); /* requested OID */
721 /* (fully qualified) */
724 * issue Get/GetNext command against IPAssists
727 /* create socket for ioctl */
728 sd = socket( AF_INET, SOCK_STREAM, 0 );
729 if ( sd < 0 )
731 error_code = errno;
732 get_time( time_buf );
733 snmp_log(LOG_ERR, "%s do_GET_ioctl(): "
734 "error opening socket() - reason %s\n"
735 "do_GET_ioctl(): rejected request for .%s\n",
736 time_buf, strerror( error_code ), oid_str );
737 free( *cmd );
738 return -1;
739 } /* end if */
741 /* do ioctl */
742 strcpy( ifr.ifr_name, device );
743 ifr.ifr_ifru.ifru_data = (char*) (*cmd);
744 if ( ioctl( sd, SIOC_QETH_ADP_SET_SNMP_CONTROL, &ifr ) < 0 )
746 error_code = errno;
747 get_time( time_buf );
749 /* see if we got a common I/O error */
750 if ( error_code == -EIO )
752 snmp_log( LOG_ERR, "%s do_GET_ioctl(): "
753 "ioctl() failed - reason %s\n"
754 "do_GET_ioctl(): rejected request for .%s\n",
755 time_buf, strerror( error_code ), oid_str );
756 close( sd );
757 free( *cmd );
758 return -1;
759 } /* end if */
761 /* let's see, if we got a return code from IPAssists */
762 /* or if MIB buffer is exhausted */
763 switch ( (*cmd)->ioctl_cmd.ipa_cmd_hdr.ret_code ) {
765 case IPA_FAILED:
766 snmp_log( LOG_ERR, "%s do_GET_ioctl(): "
767 "ioctl() failed - IPA command failed\n"
768 "do_GET_ioctl(): rejected request for .%s\n",
769 time_buf, oid_str );
770 break;
772 case IPA_NOT_SUPP:
773 snmp_log( LOG_ERR, "%s do_GET_ioctl(): "
774 "ioctl() failed - IPA command not supported\n"
775 "do_GET_ioctl(): rejected request for .%s\n",
776 time_buf, oid_str );
777 break;
779 case IPA_NO_DATA:
780 snmp_log( LOG_ERR, "%s do_GET_ioctl(): "
781 "ioctl() failed - valid IPA command, but no "
782 "SNMP data is available\n"
783 "do_GET_ioctl(): rejected request for .%s\n",
784 time_buf, oid_str );
785 break;
787 case -ENOMEM:
788 snmp_log( LOG_ERR, "%s do_GET_ioctl(): "
789 "ioctl() failed - response data > "
790 "constant MAX_GET_DATA %d\n"
791 "do_GET_ioctl(): rejected request for .%s\n",
792 time_buf, MAX_GET_DATA, oid_str );
793 break;
795 default:
796 snmp_log(LOG_ERR, "%s do_GET_ioctl(): "
797 "ioctl() failed - reason %s\n"
798 "do_GET_ioctl(): rejected request for .%s\n",
799 time_buf, strerror( error_code ), oid_str );
800 break;
801 } /* end switch */
803 close( sd );
804 free( *cmd );
805 return -1;
807 } /* end if */
809 /* close socket */
810 close( sd );
812 /* now check IPA SNMP subcommand return code */
813 switch ( (*cmd)->ioctl_cmd.ipa_cmd_hdr.ret_code ) {
815 case IPA_SNMP_SUCCESS:
816 /* return offset to data portion */
817 return ( sizeof( IPA_CMD_GET ) + strlen( oid_str ) + 1 );
818 break;
820 case IPA_SNMP_INV_TOPOID:
821 case IPA_SNMP_INV_GROUP:
822 case IPA_SNMP_INV_SUFFIX:
823 case IPA_SNMP_INV_INST:
824 case IPA_SNMP_OID_NREAD:
825 case IPA_SNMP_OID_NWRIT:
826 get_time( time_buf );
827 snmp_log( LOG_ERR, "%s do_GET_ioctl(): "
828 "IPA SNMP subcommand failed - cannot handle OID\n"
829 "do_GET_ioctl(): IPA SNMP subcommand return code 0x%x\n"
830 "do_GET_ioctl(): rejected request for .%s\n",
831 time_buf, (*cmd)->ioctl_cmd.ipa_cmd_hdr.ret_code, oid_str );
832 break;
834 case IPA_SNMP_NOT_SUPP:
835 get_time( time_buf );
836 snmp_log( LOG_ERR, "%s do_GET_ioctl(): "
837 "IPA SNMP subcommand failed - subcommand 0x%x not supported\n"
838 "do_GET_ioctl(): rejected request for .%s\n",
839 time_buf, (*cmd)->ioctl_cmd.ipa_cmd_hdr.request, oid_str );
840 break;
842 case IPA_SNMP_NO_DATA:
843 get_time( time_buf );
844 snmp_log( LOG_ERR, "%s do_GET_ioctl(): "
845 "IPA SNMP subcommand failed - no data available\n"
846 "do_GET_ioctl(): rejected request for .%s\n",
847 time_buf, oid_str );
848 break;
850 default:
851 get_time( time_buf );
852 snmp_log( LOG_ERR, "%s do_GET_ioctl(): "
853 "IPA SNMP subcommand failed - undefined return code 0x%x\n"
854 "do_GET_ioctl(): rejected request for .%s\n",
855 time_buf, (*cmd)->ioctl_cmd.ipa_cmd_hdr.ret_code, oid_str );
856 break;
858 } /* end switch */
860 /* return error */
861 free( *cmd );
862 return -1;
864 } /* end do_GET_ioctl */
867 /**********************************************************************
868 * write_ibmOSAMib():
869 * !!! Set processing is not supported in version 1.0.0 !!!
870 * !!! Function is defind as a skeleton for later use !!!
871 * This function handles any SET requests raised against the
872 * ibmOSAMib.
873 * The flow of actions is to preserve proper transaction handling
874 * with other transactions in the same set request.
875 * parameters:
876 * IN int action - current action state
877 * IN u_char *var_val - new variable value
878 * IN u_char var_val_type - data type of above variable
879 * IN size_t var_val_len - length of variable value
880 * IN u_char *statP - value that a GET request would return
881 * for this variable
882 * IN oid *name - OID to be set
883 * IN size_t name_len - len of OID to be set
884 * returns: SNMP_ERR_WRONGTYPE - wrong data type passed in
885 * SNMP_ERR_GENERR - general error occured
886 * SNMP_ERR_UNDOFAILED - undo operation failed
887 * SNMP_ERR_NOERROR - variable set sucessful
888 *********************************************************************/
889 int write_ibmOSAMib( int action,
890 u_char *UNUSED(var_val),
891 u_char UNUSED(var_val_type),
892 size_t UNUSED(var_val_len),
893 u_char *UNUSED(statP),
894 oid *UNUSED(name),
895 size_t UNUSED(name_len) )
897 /* static unsigned char string[SPRINT_MAX_LEN]; */
898 /* int size; */
900 switch ( action ) {
901 case RESERVE1:
902 /* check to see that everything is possible */
903 break;
906 case RESERVE2:
907 /* allocate needed memory here */
908 break;
911 case FREE:
912 /* Release any resources that have been allocated */
913 break;
916 case ACTION:
917 /* Actually make the change requested. Note that anything done
918 here must be reversable in the UNDO case */
919 break;
922 case UNDO:
923 /* Back out any changes made in the ACTION case */
924 break;
927 case COMMIT:
928 /* Things are working well, so it's now safe to make the change
929 permanently. Make sure that anything done here can't fail! */
930 break;
932 return SNMP_ERR_NOERROR;
933 } /* end write_ibmOSAMib */