snmpcom.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1992,1997-2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1990 Mentat Inc. */
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* This file contains common code for handling Options Management requests
*/
#define _SUN_TPI_VERSION 2
#define DEFAULT_LENGTH sizeof (long)
#define DATA_MBLK_SIZE 1024
#define TOAHDR_SIZE (sizeof (struct T_optmgmt_ack) +\
sizeof (struct opthdr))
/* SNMP Option Request Structure */
typedef struct sor_s {
int sor_group;
int sor_code; /* MIB2 index value */
int sor_size;
} sor_t;
/*
* Validation Table for set requests.
*/
{ MIB2_IP, 1, sizeof (int) },
{ MIB2_IP, 2, sizeof (int) },
};
/*
* Binary compatibility to what used to be T_CURRENT in older releases.
* Unfortunately, the binary chosen for it was different and used by
* T_PARTSUCCESS in the new name space. However T_PARTSUCESS is only
* anticiapted in new T_OPTMGM_REQ (and not O_T_OPTMGMT_REQ messages).
* Only a test for TBADFLAG which uses one of the MIB option levels
* may have trouble with this provision for binary compatibility.
*/
/*
* MIB info returned in data part of M_PROTO msg. All info for a single
* request is appended in a chain of mblk's off of the M_PROTO T_OPTMGMT_ACK
* ctl buffer.
*/
int
char *blob;
int len;
{
if (!mpdata)
return (0);
if (!mpdata)
return (0);
}
return (1);
}
/*
* Need a form which avoids O(n^2) behavior locating the end of the
* chain every time. This is it.
*/
int
{
if (!mpdata)
return (0);
}
if (!*last_mpp)
return (0);
}
return (1);
}
/*
* SNMP requests are issued using putmsg() on a stream containing all
* relevant modules. The ctl part contains a O_T_OPTMGMT_REQ message,
* and the data part is NULL
* to process this msg. If snmpcom_req() returns FALSE, then the module
* will try optcom_req to see if its some sort of SOCKET or IP option.
* snmpcom_req returns TRUE whenever the first option is recognized as
* an SNMP request, even if a bad one.
*
* "get" is done by a single O_T_OPTMGMT_REQ with MGMT_flags set to T_CURRENT.
* All modules respond with one or msg's about what they know. Responses
* is begin returned, the len field how big it is (in bytes). The info
* itself is in the data portion of the msg. Fixed length info returned
* in one msg; each table in a separate msg.
*
* setfn() returns 1 if things ok, 0 if set request invalid or otherwise
* messed up.
*
* If the passed q is at the bottom of the module chain (q_next == NULL,
* a ctl msg with req->name, level, len all zero is sent upstream. This
* is and EOD flag to the caller.
*
* IMPORTANT:
* - The msg type is M_PROTO, not M_PCPROTO!!! This is by design,
* since multiple messages will be sent to stream head and we want
* them queued for reading, not discarded.
* of each module. The functions must simply ignore requests not meant
* for them: getfn() returns 0, setfn() returns 1.
*/
queue_t *q;
{
struct T_optmgmt_ack *toa;
return (B_TRUE);
}
goto bad_req1;
if (! __TPI_OPT_ISALIGNED(req_start))
goto bad_req1;
/*
* if first option not in the MIB2 or EXPER range, return false so
* optcom_req can scope things out. Otherwise it's passed to each
* calling module to process or ignore as it sees fit.
*/
return (B_FALSE);
switch (tor->MGMT_flags) {
case T_NEGOTIATE:
return (B_TRUE);
}
tor->OPT_length);
next_req =
goto bad_req2;
break;
}
goto bad_req3;
goto bad_req4;
}
if (q->q_next)
else
return (B_TRUE);
case OLD_T_CURRENT:
case T_CURRENT:
if (!mpctl) {
return (B_TRUE);
}
return (B_TRUE);
}
/*
* all data for this module has now been sent upstream. If
* this is bottom module of stream, send up an EOD ctl msg,
* otherwise pass onto the next guy for processing.
*/
if (q->q_next) {
return (B_TRUE);
}
}
if (!mpctl) {
return (B_TRUE);
}
return (B_TRUE);
default:
return (B_TRUE);
}
bad_req1:;
printf("snmpcom bad_req1\n");
goto bad_req;
bad_req2:;
printf("snmpcom bad_req2\n");
goto bad_req;
bad_req3:;
printf("snmpcom bad_req3\n");
goto bad_req;
bad_req4:;
printf("snmpcom bad_req4\n");
/* FALLTHRU */
bad_req:;
return (B_TRUE);
}