/** * Sends a RESPONSE PDU to the source address of a INFORM request. * @param event * the <code>CommandResponderEvent</code> with the INFORM request. * @throws * MessageException if the response could not be created and sent. */ protected void sendInformResponse(CommandResponderEvent event) throws MessageException { PDU responsePDU = (PDU) event.getPDU().clone(); responsePDU.setType(PDU.RESPONSE); responsePDU.setErrorStatus(PDU.noError); responsePDU.setErrorIndex(0); messageDispatcher.returnResponsePdu(event.getMessageProcessingModel(), event.getSecurityModel(), event.getSecurityName(), event.getSecurityLevel(), responsePDU, event.getMaxSizeResponsePDU(), event.getStateReference(), new StatusInformation()); } }
/** * Creates shallow copy of the supplied <code>CommandResponderEvent</code> * but the source of the event is set to the supplied source. * * @param source * the (new) source of event copy to create. * @param other * the <code>CommandResponderEvent</code> to copy. * @since 1.1 */ public CommandResponderEvent(Object source, CommandResponderEvent other) { super(source); setTransportMapping(other.transportMapping); setMessageProcessingModel(other.messageProcessingModel); setSecurityModel(other.securityModel); setSecurityName(other.securityName); setSecurityLevel(other.securityLevel); setPduHandle(other.pduHandle); setPDU(other.pdu); setMaxSizeResponsePDU(other.maxSizeResponsePDU); setStateReference(other.stateReference); setPeerAddress(other.getPeerAddress()); }
protected OctetString getViewName(CommandResponderEvent req, CoexistenceInfo cinfo, int viewType) { OctetString viewName = vacm.getViewName(cinfo.getContextName(), cinfo.getSecurityName(), req.getSecurityModel(), req.getSecurityLevel(), viewType); return viewName; }
public void processPdu(CommandResponderEvent commandResponderEvent) { msg = commandResponderEvent.getPDU(); } }
public void processPdu(CommandResponderEvent event) { if (event.getPDU() != null) { CoexistenceInfo cinfo = null; OctetString sname = new OctetString(event.getSecurityName()); if (event.getPDU() instanceof ScopedPDU) { ScopedPDU spdu = (ScopedPDU) event.getPDU(); cinfo = new CoexistenceInfo(sname, spdu.getContextEngineID(), if ((cinfos != null) && (cinfos.length > 0)) { for (CoexistenceInfo cinfo1 : cinfos) { if (coexistenceProvider.passesFilter(event.getPeerAddress(), cinfo1)) { cinfo = cinfo1; logger.warn("Access attempt from " + event.getPeerAddress() + " denied because of source address filtering"); return; event.setMaxSizeResponsePDU(cinfo.getMaxMessageSize()); } else { if (logger.isInfoEnabled()) { event.setProcessed(true); Command command = new Command(event, cinfo); if (threadPool != null) {
PduHandle handle = event.getPduHandle(); PDU pdu = event.getPDU(); if (pdu.getType() == PDU.RESPONSE) { event.setProcessed(true); PendingRequest request; if (logger.isDebugEnabled()) { logger.warn("Received response that cannot be matched to any " + "outstanding request, address=" + event.getPeerAddress() + ", requestID=" + pdu.getRequestID()); if (l != null) { l.onResponse(new ResponseEvent(this, event.getPeerAddress(), request.pdu, pdu, event.setProcessed(true); reportHandler.processReport(handle, event); logger.debug("Fire process PDU event: " + event.toString());
@Override public void processPdu(CommandResponderEvent trap) { try { PDU pdu = trap.getPDU(); Address localaddr = trap.getTransportMapping().getListenAddress(); Address remoteaddr = trap.getPeerAddress(); ConnectionContext<?> ctx = ConnectionContext.EMPTY; if (localaddr instanceof TransportIpAddress && remoteaddr instanceof TransportIpAddress ) { if (trap.getMessageProcessingModel() == MessageProcessingModel.MPv2c) { Optional.ofNullable(trap.getSecurityName()) .filter( i -> i.length > 0) .map(i -> new String(i, StandardCharsets.UTF_8)) logger.catching(e); } finally { trap.setProcessed(true);
public void processReport(PduHandle handle, CommandResponderEvent e) { PDU pdu = e.getPDU(); logger.debug("Searching pending request with handle" + handle); PendingRequest request = (PendingRequest) pendingRequests.get(handle); if (request == null) { logger.warn("Unmatched report PDU received from " + e.getPeerAddress()); return; logger.error("Illegal report PDU received from " + e.getPeerAddress() + " missing report variable binding"); return; logger.error("Received illegal REPORT PDU from " + e.getPeerAddress()); return; sendMessage(request.pdu, request.target, e.getTransportMapping(), null); e.getPeerAddress(), reqPDU, pdu, e.getPeerAddress() + " with request ID " + pdu.getRequestID());
public void processPdu(CommandResponderEvent event) { try { PDU pdu = event.getPDU(); if( !(pdu.getType() == PDU.TRAP || pdu.getType() == PDU.V1TRAP) ) { LOGGER.warn("Not a trap."); return; } LOGGER.info("A Trap Received! " + pdu); SnmpTrapMsg trapMsg = new Snmp4JTrapMsg(event.getPeerAddress(), pdu); LOGGER.info("TrapMessage Created:" + trapMsg.toMap().toString()); SnmpTrapHandler[] handlers = getHandlers(); for (SnmpTrapHandler handler : handlers) { if(handler.onTrapMsg(trapMsg)) { event.setProcessed(true); return; } } } catch (Exception e) { LOGGER.error("Error happened when handling trap!", e); } }
protected boolean matchParameters(ProxyForwardRequest request, OctetString paramIn) { MOTableRow param2Match = targetMIB.getTargetParamsRow(paramIn, true); if (param2Match != null) { int mpModel = param2Match.getValue( SnmpTargetMIB.idxSnmpTargetParamsMPModel).toInt(); int secModel = param2Match.getValue( SnmpTargetMIB.idxSnmpTargetParamsSecurityModel).toInt(); int secLevel = param2Match.getValue( SnmpTargetMIB.idxSnmpTargetParamsSecurityLevel).toInt(); OctetString secName = (OctetString) param2Match.getValue( SnmpTargetMIB.idxSnmpTargetParamsSecurityName); if (logger.isDebugEnabled()) { logger.debug("Matching request " + request + " with mpModel=" + mpModel + ", secModel=" + secModel + ", secLevel=" + secLevel + ", secName=" + secName); } if ((mpModel == request.getCommandEvent().getMessageProcessingModel()) && (secName.equals(request.getSecurityName())) && ((secModel == 0) || (secModel == request.getCommandEvent().getSecurityModel())) && (secLevel == request.getCommandEvent().getSecurityLevel())) { return true; } } return false; }
protected VariableBinding checkReport(CommandResponderEvent e, PDU pdu, PendingRequest request) { if (request == null) { logger.warn("Unmatched report PDU received from " + e.getPeerAddress()); return null; logger.error("Illegal report PDU received from " + e.getPeerAddress() + " missing report variable binding"); return null; logger.error("Received illegal REPORT PDU from " + e.getPeerAddress()); return null; if (e.getSecurityModel() != request.target.getSecurityModel()) { logger.warn("RFC3412 §7.2.11.b: Received REPORT PDU with different security model than cached one: " + e); return null; if ((e.getSecurityLevel() == SecurityLevel.NOAUTH_NOPRIV) && (SNMP4JSettings.getReportSecurityLevelStrategy() != SNMP4JSettings.ReportSecurityLevelStrategy.noAuthNoPrivIfNeeded) && ((e.getSecurityLevel() != request.target.getSecurityLevel()) && (!SnmpConstants.usmStatsUnknownUserNames.equals(vb.getOid())) && (!SnmpConstants.usmStatsUnknownEngineIDs.equals(vb.getOid())))) {
private void sendUnknownPDUHandlersReport(CommandResponderEvent command) { logger.info("No PDU handler found for request "+command); CounterEvent counter = new CounterEvent(this, SnmpConstants.snmpUnknownPDUHandlers); fireIncrementCounter(counter); if ((command.getMessageProcessingModel() == MessageProcessingModel.MPv3) && (command.getPDU() instanceof ScopedPDU)) { ScopedPDU request = (ScopedPDU) command.getPDU(); ScopedPDU report = new ScopedPDU(); report.setContextEngineID(request.getContextEngineID()); report.setContextName(request.getContextName()); report.setType(PDU.REPORT); report.add(new VariableBinding(counter.getOid(), counter.getCurrentValue())); sendResponse(command, report); } else { PDU resp = (PDU) command.getPDU().clone(); resp.setErrorStatus(PDU.genErr); sendResponse(command, resp); } }
int pduType = request.getCommandEvent().getPDU().getType(); if (SnmpRequest.getViewType(pduType) == VACM.VIEW_NOTIFY) { return multipleForward(request); PDU respPDU = resp.getResponse(); PDU translatedResponse = DefaultPDUFactory.createPDU( request.getCommandEvent().getSecurityModel()); if (!translatedResponse.getClass().equals(respPDU.getClass())) { request.getCommandEvent().getPDU().getRequestID()); if ((translatedResponse instanceof ScopedPDU) && (request.getCommandEvent().getPDU() instanceof ScopedPDU)) { ScopedPDU scopedPDUReq = (ScopedPDU) request.getCommandEvent().getPDU(); ScopedPDU scopedPDUResp = (ScopedPDU) translatedResponse; scopedPDUResp.setContextEngineID(scopedPDUReq.getContextEngineID());
PDU reqPDU = requestEvent.getPDU(); if (reqPDU.getType() == PDU.GETBULK) { if (noAppending && (cursor >= subrequests.size())) { requestEvent.getMaxSizeResponsePDU());
/** * Will be called whenever a {@link PDU} is received on the given port * specified in the listen() method. It extracts a {@link Variable} * according to the configured OID prefix and sends its value to the event * bus. */ @Override public void processPdu(CommandResponderEvent event) { Address addr = event.getPeerAddress(); if (addr == null) { return; } String s = addr.toString().split("/")[0]; if (s == null) { logger.error("TRAP: failed to translate address {}", addr); dispatchPdu(addr, event.getPDU()); } else { // Need to change the port to 161, which is what the bindings are configured for since // at least some SNMP devices send traps from a random port number. Otherwise the trap // won't be found as the address check will fail. It feels like there should be a better // way to do this!!! Address address = GenericAddress.parse("udp:" + s + "/161"); dispatchPdu(address, event.getPDU()); } }
public SnmpMessage(CamelContext camelContext, PDU pdu, CommandResponderEvent event) { super(camelContext); this.pdu = pdu; this.setHeader("securityName", new OctetString(event.getSecurityName())); this.setHeader("peerAddress", event.getPeerAddress()); }
public void run() { if (forwarder.forward(request)) { PDU response = request.getResponsePDU(); if (response != null) { sendResponse(request.getCommandEvent(), response); } } else if (request.getProxyType() != ProxyForwarder.PROXY_TYPE_NOTIFY) { // proxy drop CounterEvent cevent = new CounterEvent(this, SnmpConstants.snmpProxyDrops); fireIncrementCounter(cevent); CommandResponderEvent cre = request.getCommandEvent(); if ((cre.getMessageProcessingModel() == MPv3.ID) && (cre.getStateReference() != null)) { ScopedPDU reportPDU = new ScopedPDU(); reportPDU.setType(PDU.REPORT); reportPDU.setContextEngineID(request.getContextEngineID()); reportPDU.setContextName(request.getContext()); reportPDU.add(new VariableBinding(SnmpConstants.snmpProxyDrops, cevent.getCurrentValue())); sendResponse(request.getCommandEvent(), reportPDU); } } }
public synchronized void processPdu(CommandResponderEvent event) { CommandResponder listener = (CommandResponder) notificationTransports.get(event.getTransportMapping()); if ((event.getPDU() != null) && (event.getPDU().getType() == PDU.INFORM)) { // try to send INFORM response try { sendInformResponse(event); } catch (MessageException mex) { if (logger.isWarnEnabled()) { logger.warn("Failed to send response on INFORM PDU event (" + event + "): " + mex.getMessage()); } } } if (listener != null) { listener.processPdu(event); } }
public int getMessageProcessingModel() { return this.requestEvent.getMessageProcessingModel(); }
public OctetString getSecurityName() { if (coexistenceInfo != null) { return coexistenceInfo.getSecurityName(); } return new OctetString(requestEvent.getSecurityName()); }