/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
// java import
//
// jmx imports
//
// RI imports
//
// SNMP runtime import
//
//import com.sun.jmx.snmp.IPAcl.IPAcl;
/**
* Contains the list of sub-requests associated to the current request.
*/
/**
* Reference on the MIBS
*/
/**
* Full constructor
*/
DatagramSocket s, DatagramPacket p,
MBeanServer f, ObjectName n)
{
// Need a reference on SnmpAdaptorServer for getNext & getBulk,
// in case of oid equality (mib overlapping).
//
socket = s;
packet = p;
ipacl = a;
pduFactory = factory ;
//thread.start();
}
/**
* Treat the request available in 'packet' and send the result
* back to the client.
* Note: we overwrite 'packet' with the response bytes.
*/
public void doRun() {
// Trace the input packet
//
"doRun","Packet received:\n" +
}
// Let's build the response packet
//
// Trace the output packet
//
"doRun","Packet to be sent:\n" +
}
// Send the response packet if any
//
if (respPacket != null) {
try {
} catch (SocketException e) {
"doRun", "interrupted");
} else {
"doRun", "I/O exception", e);
}
}
} catch(InterruptedIOException e) {
"doRun", "interrupted");
}
} catch(Exception e) {
"doRun", "failure when sending response", e);
}
}
}
}
/**
* Here we make a response packet from a request packet.
* We return null if there no response packet to sent.
*/
// Transform the request packet into a request SnmpMessage
//
try {
}
catch(SnmpStatusException x) {
"makeResponsePacket", "packet decoding failed", x);
}
}
// Make the response SnmpMessage if any
//
}
// Try to transform the response SnmpMessage into response packet.
// NOTE: we overwrite the request packet.
//
try {
respPacket = reqPacket ;
}
catch(SnmpTooBigException x) {
"makeResponsePacket", "response message is too big");
}
try {
respPacket = reqPacket ;
}
catch(SnmpTooBigException xx) {
"makeResponsePacket", "'too big' is 'too big' !!!");
}
}
}
}
return respPacket ;
}
/**
* Here we make a response message from a request message.
* We return null if there is no message to reply.
*/
// Transform the request message into a request pdu
//
try {
}
catch(SnmpStatusException x) {
"makeResponseMessage", "message decoding failed", x);
}
}
// Make the response pdu if any
//
try {
if (userDataFactory != null)
} catch (SnmpStatusException x) {
}
}
// Try to transform the response pdu into a response message if any
//
try {
}
catch(SnmpStatusException x) {
"makeResponseMessage", "failure when encoding the response message", x);
}
}
catch(SnmpTooBigException x) {
"makeResponseMessage", "response message is too big");
}
try {
// if the PDU is too small, why should we try to do
// recovery ?
//
throw x;
int pos= x.getVarBindCount();
}
int old= 0;
while (true) {
try {
break;
} catch (SnmpTooBigException xx) {
"makeResponseMessage", "response message is still too big");
}
}
// we can not go any further in trying to
// reduce the message !
//
throw xx;
}
}
}// end of loop
} catch(SnmpStatusException xx) {
}
}
catch(SnmpTooBigException xx) {
try {
}
catch(SnmpTooBigException xxx) {
"makeResponseMessage", "'too big' is 'too big' !!!");
}
}
}
}
}
}
}
}
}
return respMsg ;
}
/**
* Here we make a response pdu from a request pdu.
* We return null if there is no pdu to reply.
*/
if (checkPduType(reqPdu)) {
" received but no MIB registered.");
}
}
userData) ;
break ;
userData) ;
break ;
}
}
else { // reqPdu is rejected by ACLs
// respPdu contains the error response to be sent.
// We send this response only if authResEnabled is true.
}
try {
new SnmpVarBindList()) ;
}
catch(Exception x) {
"makeResponsePdu", "Failure when sending authentication trap", x);
}
}
}
}
}
return respPdu ;
}
//
// Generates a response packet, filling the values in the
// varbindlist with one of endOfMibView, noSuchObject, noSuchInstance
// according to the value of <code>status</code>
//
// @param statusTag should be one of:
// <li>SnmpDataTypeEnums.errEndOfMibViewTag</li>
// <li>SnmpDataTypeEnums.errNoSuchObjectTag</li>
// <li>SnmpDataTypeEnums.errNoSuchInstanceTag</li>
//
switch (statusTag) {
for (int i=0 ; i<length ; i++)
break;
for (int i=0 ; i<length ; i++)
break;
for (int i=0 ; i<length ; i++)
break;
default:
}
}
// Generates an appropriate response when no mib is registered in
// the adaptor.
//
// <li>If the version is V1:</li>
// <ul><li>Generates a NoSuchName error V1 response PDU</li></ul>
// <li>If the version is V2:</li>
// <ul><li>If the request is a GET, fills the varbind list with
// NoSuchObject's</li>
// list with EndOfMibView's</li>
// <li>If the request is a SET, generates a NoAccess error V2
// response PDU</li>
// </ul>
//
//
// There is no agent registered
//
// Version 1: => NoSuchName
return
// Version 2: => depends on PDU type
case pduSetRequestPdu :
case pduWalkRequest :
// SET request => NoAccess
return
case pduGetRequestPdu :
// GET request => NoSuchObject
return
case pduGetNextRequestPdu :
case pduGetBulkRequestPdu :
// GET-NEXT or GET-BULK => EndOfMibView
return
default:
}
}
// Something wrong here: => snmpRspGenErr
}
/**
* At this level, the result is never null.
*/
// Create the trhead group specific for handling sub-requests
// associated to the current request. Use the invoke id
//
// Nice idea to use a thread group on a request basis.
// However the impact on performance is terrible !
// theGroup= new ThreadGroup(thread.getThreadGroup(),
// "request " + String.valueOf(req.requestId));
// Let's build the varBindList for the response pdu
//
// Good ! Let's make a full response pdu.
//
}
// First we need to split the request into subrequests
//
if (nbSubRequest == 1)
// Execute all the subrequests resulting from the split of the
// varbind list.
//
// It means that an error occured. The error is already
// formatted by the executeSubRequest
// method.
return result;
// So far so good. So we need to concatenate all the answers.
//
"makeGetSetResponsePdu",
}
return mergeResponses(req);
}
/**
* The method runs all the sub-requests associated to the current
* instance of SnmpRequestHandler.
*/
int i=0;
// If it's a set request, we must first check any varBind
//
i=0;
// Indicate to the sub request that a check must be invoked ...
// OK we should have defined out own tag for that !
//
e.nextElement();
// No point to go any further.
//
"executeSubRequest", "an error occurs");
}
}
}
}// end processing check operation for a set PDU.
// Let's start the sub-requests.
//
i=0;
/* NPCTE fix for bugId 4492741, esc 0, 16-August 2001 */
/* end of NPCTE fix for bugId 4492741 */
// No point to go any further.
//
"executeSubRequest", "an error occurs");
}
}
}
// everything is ok
//
return null;
}
/**
* Optimize when there is only one sub request
*/
// Indicate to the sub request that a check must be invoked ...
// OK we should have defined out own tag for that !
//
// Check the error status.
//
// No point to go any further.
//
}
}
// process the operation
//
// No point to go any further.
//
"turboProcessingGetSet", "an error occurs");
}
}
// So far so good. So we need to concatenate all the answers.
//
"turboProcessingGetSet", "build the unified response for request "
}
return mergeResponses(req);
}
/**
* Here we make the response pdu for a bulk request.
* At this level, the result is never null.
*/
// RFC 1905, Section 4.2.3, p14
int R = L - N ;
// Good ! Let's make a full response pdu.
//
}
// Split the request into subrequests.
//
splitBulkRequest(req, N, M, R);
return result;
respVarBindList= mergeBulkResponses(N + (M * R));
// Now we remove useless trailing endOfMibView.
//
int m2 ; // respVarBindList[m2] item and next are going to be removed
int t = respVarBindList.length ;
while ((t > N) && (respVarBindList[t-1].
t-- ;
}
if (t == N)
m2 = N + R ;
else
for (int i = 0 ; i < m2 ; i++) {
truncatedList[i] = respVarBindList[i] ;
}
}
// Good ! Let's make a full response pdu.
//
}
/**
* are accepted.
*/
boolean result = true ;
result = true ;
break;
default:
"checkPduType", "cannot respond to this kind of PDU");
}
result = false ;
break;
}
return result ;
}
/**
* Check if the specified pdu is conform to the ACL.
* This method returns null if the pdu is ok. If not, it returns
* the response pdu to be replied.
*/
// We check the pdu type and create an error response if
// the check failed.
//
if (!((InetAddressAcl)ipacl).
}
int err = SnmpSubRequestHandler.
}
else {
}
}
}
else {
}
int err = SnmpSubRequestHandler.
err,
0);
}
else {
}
}
}
}
// If the response is not null, this means the pdu is rejected.
// So let's update the statistics.
//
}
return response ;
}
/**
* Make a response pdu with the specified error status and index.
* NOTE: the response pdu share its varBindList with the request pdu.
*/
SnmpVarBind[] varBindList) {
return result ;
}
/**
* Make a response pdu with the specified error status and index.
* NOTE: the response pdu share its varBindList with the request pdu.
*/
result.errorStatus = s ;
result.errorIndex = i ;
return result ;
}
throws SnmpTooBigException {
try {
}
}
catch(SnmpStatusException x) {
// This should not occur because decodeIncomingRequest has normally
// been successfully called before.
"newTooBigMessage", "Internal error", x);
}
throw new InternalError() ;
}
return result ;
}
return result ;
}
int acceptedVbCount)
throws SnmpTooBigException {
// Reduction can be attempted only on bulk response
//
"reduceResponsePdu", "cannot remove anything");
}
throw new SnmpTooBigException(acceptedVbCount) ;
}
// We're going to reduce the varbind list.
// First determine which items should be removed.
// Next duplicate and replace the existing list by the reduced one.
//
// acceptedVbCount is the number of varbind which have been
// successfully encoded before reaching bufferSize:
// * when it is >= 2, we split the varbindlist at this
// position (-1 to be safe),
// * when it is 1, we only put one (big?) item in the varbindlist
// * when it is 0 (in fact, acceptedVbCount is not available),
// we split the varbindlist by 2.
//
if (acceptedVbCount >= 3)
else if (acceptedVbCount == 1)
vbCount = 1 ;
else // acceptedCount == 0 ie it is unknown
if (vbCount < 1) {
"reduceResponsePdu", "cannot remove anything");
}
throw new SnmpTooBigException(acceptedVbCount) ;
}
else {
for (int i = 0 ; i < vbCount ; i++) {
}
" items have been removed");
}
}
return resp ;
}
/**
* The method takes the incoming requests and split it into subrequests.
*/
if (nbAgents == 1) {
// Take all the oids contained in the request and
//
return;
}
// For the get next operation we are going to send the varbind list
// to all agents
//
}
return;
}
for(int i=0; i < nbReqs; i++) {
// We need to create the sub request handler and update
// the hashtable
//
}
// Update the translation table within the subrequest
//
}
}
/**
* The method takes the incoming get bulk requests and split it into
* subrequests.
*/
int nonRepeaters,
int maxRepetitions,
int R) {
// Send the getBulk to all agents
//
}
req,
R));
}
return;
}
return mergeNextResponses(req);
}
// Go through the list of subrequests and concatenate.
// Hopefully, by now all the sub-requests should be finished
//
}
}
// Go through the list of subrequests and concatenate.
// Hopefully, by now all the sub-requests should be finished
//
}
}
// In v1 make sure there is no endOfMibView ...
//
for(int i=0; i < max; i++) {
return newErrorResponsePdu(req,
}
// So far so good ...
//
}
// Let's allocate the array for storing the result
//
result[i]= new SnmpVarBind();
}
// Go through the list of subrequests and concatenate.
// Hopefully, by now all the sub-requests should be finished
//
}
return result;
}
}
return null;
}
"Interrupted system call";
}