001: /*_############################################################################
002: _##
003: _## SNMP4J-Agent - SnmpCommunityMIB.java
004: _##
005: _## Copyright (C) 2005-2007 Frank Fock (SNMP4J.org)
006: _##
007: _## Licensed under the Apache License, Version 2.0 (the "License");
008: _## you may not use this file except in compliance with the License.
009: _## You may obtain a copy of the License at
010: _##
011: _## http://www.apache.org/licenses/LICENSE-2.0
012: _##
013: _## Unless required by applicable law or agreed to in writing, software
014: _## distributed under the License is distributed on an "AS IS" BASIS,
015: _## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016: _## See the License for the specific language governing permissions and
017: _## limitations under the License.
018: _##
019: _##########################################################################*/
020:
021: package org.snmp4j.agent.mo.snmp;
022:
023: //--AgentGen BEGIN=_BEGIN
024: //--AgentGen END
025:
026: import org.snmp4j.smi.*;
027: import org.snmp4j.mp.SnmpConstants;
028: import org.snmp4j.agent.*;
029: import org.snmp4j.agent.mo.*;
030: import org.snmp4j.agent.mo.snmp.*;
031: import java.util.Map;
032: import java.util.Collections;
033: import java.util.HashMap;
034: import java.util.List;
035: import java.util.*;
036: import org.snmp4j.agent.mo.snmp.SnmpTargetMIB.SnmpTargetAddrEntryRow;
037: import org.snmp4j.log.LogAdapter;
038: import org.snmp4j.log.LogFactory;
039:
040: //--AgentGen BEGIN=_IMPORT
041: //--AgentGen END
042:
043: public class SnmpCommunityMIB
044:
045: //--AgentGen BEGIN=_EXTENDS
046: //--AgentGen END
047: implements MOGroup
048: //--AgentGen BEGIN=_IMPLEMENTS
049: , CoexistenceInfoProvider
050: //--AgentGen END
051: {
052:
053: // Factory
054: private static MOFactory moFactory = DefaultMOFactory.getInstance();
055:
056: // Constants
057:
058: private static final OID oidSnmpCommunityEntry = new OID(new int[] {
059: 1, 3, 6, 1, 6, 3, 18, 1, 1, 1 });
060:
061: // Column sub-identifer defintions for snmpCommunityEntry:
062: private static final int colSnmpCommunityName = 2;
063: private static final int colSnmpCommunitySecurityName = 3;
064: private static final int colSnmpCommunityContextEngineID = 4;
065: private static final int colSnmpCommunityContextName = 5;
066: private static final int colSnmpCommunityTransportTag = 6;
067: private static final int colSnmpCommunityStorageType = 7;
068: private static final int colSnmpCommunityStatus = 8;
069:
070: // Column index defintions for snmpCommunityEntry:
071: private static final int idxSnmpCommunityName = 0;
072: private static final int idxSnmpCommunitySecurityName = 1;
073: private static final int idxSnmpCommunityContextEngineID = 2;
074: private static final int idxSnmpCommunityContextName = 3;
075: private static final int idxSnmpCommunityTransportTag = 4;
076: private static final int idxSnmpCommunityStorageType = 5;
077: private static final int idxSnmpCommunityStatus = 6;
078: private static MOTableSubIndex[] snmpCommunityEntryIndexes = new MOTableSubIndex[] { moFactory
079: .createSubIndex(SMIConstants.SYNTAX_OCTET_STRING, 1, 32) };
080:
081: private static MOTableIndex snmpCommunityEntryIndex = moFactory
082: .createIndex(snmpCommunityEntryIndexes, true);
083:
084: private MOTable snmpCommunityEntry;
085: private MOMutableTableModel snmpCommunityEntryModel;
086: private static final OID oidSnmpTargetAddrExtEntry = new OID(
087: new int[] { 1, 3, 6, 1, 6, 3, 18, 1, 2, 1 });
088:
089: // Column sub-identifer defintions for snmpTargetAddrExtEntry:
090: private static final int colSnmpTargetAddrTMask = 1;
091: private static final int colSnmpTargetAddrMMS = 2;
092:
093: // Column index defintions for snmpTargetAddrExtEntry:
094: private static final int idxSnmpTargetAddrTMask = 0;
095: private static final int idxSnmpTargetAddrMMS = 1;
096: private static MOTableSubIndex[] snmpTargetAddrExtEntryIndexes = new MOTableSubIndex[] { moFactory
097: .createSubIndex(SMIConstants.SYNTAX_OCTET_STRING, 1, 32) };
098:
099: private static MOTableIndex snmpTargetAddrExtEntryIndex = moFactory
100: .createIndex(snmpTargetAddrExtEntryIndexes, true);
101:
102: private MOTable snmpTargetAddrExtEntry;
103: private MOMutableTableModel snmpTargetAddrExtEntryModel;
104:
105: private MOTableRelation snmpTargetAddrEntryRelation;
106:
107: //--AgentGen BEGIN=_MEMBERS
108: private static final LogAdapter logger = LogFactory
109: .getLogger(SnmpCommunityMIB.class);
110:
111: private Map coexistenceInfo;
112: private Map communityInfo;
113: private SnmpTargetMIB targetMIB;
114: private boolean sourceAddressFiltering;
115:
116: public SnmpCommunityMIB(SnmpTargetMIB targetMIB) {
117: this ();
118: this .targetMIB = targetMIB;
119: setBaseTableSnmpTargetAddrEntry(targetMIB
120: .getSnmpTargetAddrEntry());
121: }
122:
123: //--AgentGen END
124:
125: private SnmpCommunityMIB() {
126: createSnmpCommunityEntry();
127: createSnmpTargetAddrExtEntry();
128: }
129:
130: public MOTable getSnmpCommunityEntry() {
131: return snmpCommunityEntry;
132: }
133:
134: private void createSnmpCommunityEntry() {
135: MOColumn[] snmpCommunityEntryColumns = new MOColumn[7];
136: snmpCommunityEntryColumns[idxSnmpCommunityName] = new MOMutableColumn(
137: colSnmpCommunityName, SMIConstants.SYNTAX_OCTET_STRING,
138: MOAccessImpl.ACCESS_READ_CREATE, null, true);
139: snmpCommunityEntryColumns[idxSnmpCommunitySecurityName] = new MOMutableColumn(
140: colSnmpCommunitySecurityName,
141: SMIConstants.SYNTAX_OCTET_STRING,
142: MOAccessImpl.ACCESS_READ_CREATE, null, true);
143: ((MOMutableColumn) snmpCommunityEntryColumns[idxSnmpCommunitySecurityName])
144: .addMOValueValidationListener(new SnmpCommunitySecurityNameValidator());
145: snmpCommunityEntryColumns[idxSnmpCommunityContextEngineID] = new MOMutableColumn(
146: colSnmpCommunityContextEngineID,
147: SMIConstants.SYNTAX_OCTET_STRING,
148: MOAccessImpl.ACCESS_READ_CREATE, null, true);
149: ((MOMutableColumn) snmpCommunityEntryColumns[idxSnmpCommunityContextEngineID])
150: .addMOValueValidationListener(new SnmpCommunityContextEngineIDValidator());
151: snmpCommunityEntryColumns[idxSnmpCommunityContextName] = new MOMutableColumn(
152: colSnmpCommunityContextName,
153: SMIConstants.SYNTAX_OCTET_STRING,
154: MOAccessImpl.ACCESS_READ_CREATE, new OctetString(
155: new byte[] {}), true);
156: ((MOMutableColumn) snmpCommunityEntryColumns[idxSnmpCommunityContextName])
157: .addMOValueValidationListener(new SnmpCommunityContextNameValidator());
158: snmpCommunityEntryColumns[idxSnmpCommunityTransportTag] = new MOMutableColumn(
159: colSnmpCommunityTransportTag,
160: SMIConstants.SYNTAX_OCTET_STRING,
161: MOAccessImpl.ACCESS_READ_CREATE, new OctetString(
162: new byte[] {}), true);
163: ((MOMutableColumn) snmpCommunityEntryColumns[idxSnmpCommunityTransportTag])
164: .addMOValueValidationListener(new SnmpCommunityTransportTagValidator());
165: snmpCommunityEntryColumns[idxSnmpCommunityStorageType] = new StorageType(
166: colSnmpCommunityStorageType,
167: MOAccessImpl.ACCESS_READ_CREATE, null, true);
168: snmpCommunityEntryColumns[idxSnmpCommunityStatus] = new RowStatus(
169: colSnmpCommunityStatus);
170:
171: snmpCommunityEntryModel = new DefaultMOMutableTableModel();
172: snmpCommunityEntryModel
173: .setRowFactory(new SnmpCommunityEntryRowFactory());
174: snmpCommunityEntry = moFactory.createTable(
175: oidSnmpCommunityEntry, snmpCommunityEntryIndex,
176: snmpCommunityEntryColumns, snmpCommunityEntryModel);
177: }
178:
179: public MOTable getSnmpTargetAddrExtEntry() {
180: return snmpTargetAddrExtEntry;
181: }
182:
183: public void setBaseTableSnmpTargetAddrEntry(MOTable baseTable) {
184: snmpTargetAddrEntryRelation = moFactory.createTableRelation(
185: baseTable, snmpTargetAddrExtEntry);
186: snmpTargetAddrEntryRelation.createRelationShip();
187: }
188:
189: private void createSnmpTargetAddrExtEntry() {
190: MOColumn[] snmpTargetAddrExtEntryColumns = new MOColumn[2];
191: snmpTargetAddrExtEntryColumns[idxSnmpTargetAddrTMask] = new MOMutableColumn(
192: colSnmpTargetAddrTMask,
193: SMIConstants.SYNTAX_OCTET_STRING,
194: MOAccessImpl.ACCESS_READ_CREATE, new OctetString(
195: new byte[] {}), true);
196: ((MOMutableColumn) snmpTargetAddrExtEntryColumns[idxSnmpTargetAddrTMask])
197: .addMOValueValidationListener(new SnmpTargetAddrTMaskValidator());
198: snmpTargetAddrExtEntryColumns[idxSnmpTargetAddrMMS] = new MOMutableColumn(
199: colSnmpTargetAddrMMS, SMIConstants.SYNTAX_INTEGER32,
200: MOAccessImpl.ACCESS_READ_CREATE, new Integer32(484),
201: true);
202: ((MOMutableColumn) snmpTargetAddrExtEntryColumns[idxSnmpTargetAddrMMS])
203: .addMOValueValidationListener(new SnmpTargetAddrMMSValidator());
204:
205: snmpTargetAddrExtEntryModel = new DefaultMOMutableTableModel();
206: snmpTargetAddrExtEntryModel
207: .setRowFactory(new SnmpTargetAddrExtEntryRowFactory());
208: snmpTargetAddrExtEntry = moFactory.createTable(
209: oidSnmpTargetAddrExtEntry, snmpTargetAddrExtEntryIndex,
210: snmpTargetAddrExtEntryColumns,
211: snmpTargetAddrExtEntryModel);
212: }
213:
214: public void registerMOs(MOServer server, OctetString context)
215: throws DuplicateRegistrationException {
216: // Scalar Objects
217: server.register(this .snmpCommunityEntry, context);
218: server.register(this .snmpTargetAddrExtEntry, context);
219: //--AgentGen BEGIN=_registerMOs
220: //--AgentGen END
221: }
222:
223: public void unregisterMOs(MOServer server, OctetString context) {
224: // Scalar Objects
225: server.unregister(this .snmpCommunityEntry, context);
226: server.unregister(this .snmpTargetAddrExtEntry, context);
227: //--AgentGen BEGIN=_unregisterMOs
228: //--AgentGen END
229: }
230:
231: // Notifications
232:
233: // Scalars
234:
235: // Value Validators
236:
237: /**
238: * The <code>SnmpCommunitySecurityNameValidator</code> implements the value
239: * validation for <code>SnmpCommunitySecurityName</code>.
240: */
241: static class SnmpCommunitySecurityNameValidator implements
242: MOValueValidationListener {
243:
244: public void validate(MOValueValidationEvent validationEvent) {
245: Variable newValue = validationEvent.getNewValue();
246: OctetString os = (OctetString) newValue;
247: if (!(((os.length() >= 1) && (os.length() <= 32)))) {
248: validationEvent
249: .setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_LENGTH);
250: return;
251: }
252: //--AgentGen BEGIN=snmpCommunitySecurityName::validate
253: //--AgentGen END
254: }
255: }
256:
257: /**
258: * The <code>SnmpCommunityContextEngineIDValidator</code> implements the value
259: * validation for <code>SnmpCommunityContextEngineID</code>.
260: */
261: static class SnmpCommunityContextEngineIDValidator implements
262: MOValueValidationListener {
263:
264: public void validate(MOValueValidationEvent validationEvent) {
265: Variable newValue = validationEvent.getNewValue();
266: OctetString os = (OctetString) newValue;
267: if (!(((os.length() >= 5) && (os.length() <= 32)))) {
268: validationEvent
269: .setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_LENGTH);
270: return;
271: }
272: //--AgentGen BEGIN=snmpCommunityContextEngineID::validate
273: //--AgentGen END
274: }
275: }
276:
277: /**
278: * The <code>SnmpCommunityContextNameValidator</code> implements the value
279: * validation for <code>SnmpCommunityContextName</code>.
280: */
281: static class SnmpCommunityContextNameValidator implements
282: MOValueValidationListener {
283:
284: public void validate(MOValueValidationEvent validationEvent) {
285: Variable newValue = validationEvent.getNewValue();
286: OctetString os = (OctetString) newValue;
287: if (!(((os.length() >= 0) && (os.length() <= 32)))) {
288: validationEvent
289: .setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_LENGTH);
290: return;
291: }
292: //--AgentGen BEGIN=snmpCommunityContextName::validate
293: //--AgentGen END
294: }
295: }
296:
297: /**
298: * The <code>SnmpCommunityTransportTagValidator</code> implements the value
299: * validation for <code>SnmpCommunityTransportTag</code>.
300: */
301: static class SnmpCommunityTransportTagValidator implements
302: MOValueValidationListener {
303:
304: public void validate(MOValueValidationEvent validationEvent) {
305: Variable newValue = validationEvent.getNewValue();
306: OctetString os = (OctetString) newValue;
307: if (!(((os.length() >= 0) && (os.length() <= 255)))) {
308: validationEvent
309: .setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_LENGTH);
310: return;
311: }
312: //--AgentGen BEGIN=snmpCommunityTransportTag::validate
313: //--AgentGen END
314: }
315: }
316:
317: /**
318: * The <code>SnmpTargetAddrTMaskValidator</code> implements the value
319: * validation for <code>SnmpTargetAddrTMask</code>.
320: */
321: static class SnmpTargetAddrTMaskValidator implements
322: MOValueValidationListener {
323:
324: public void validate(MOValueValidationEvent validationEvent) {
325: Variable newValue = validationEvent.getNewValue();
326: OctetString os = (OctetString) newValue;
327: if (!(((os.length() >= 0) && (os.length() <= 255)))) {
328: validationEvent
329: .setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_LENGTH);
330: return;
331: }
332: //--AgentGen BEGIN=snmpTargetAddrTMask::validate
333: //--AgentGen END
334: }
335: }
336:
337: /**
338: * The <code>SnmpTargetAddrMMSValidator</code> implements the value
339: * validation for <code>SnmpTargetAddrMMS</code>.
340: */
341: static class SnmpTargetAddrMMSValidator implements
342: MOValueValidationListener {
343:
344: public void validate(MOValueValidationEvent validationEvent) {
345: Variable newValue = validationEvent.getNewValue();
346: long v = ((Integer32) newValue).getValue();
347: if (!(((v >= 0L) && (v <= 0L)) || ((v >= 484L)))) {
348: validationEvent
349: .setValidationStatus(SnmpConstants.SNMP_ERROR_WRONG_VALUE);
350: return;
351: }
352: //--AgentGen BEGIN=snmpTargetAddrMMS::validate
353: //--AgentGen END
354: }
355: }
356:
357: // Rows and Factories
358: class SnmpCommunityEntryRowFactory extends
359: DefaultMOMutableRow2PCFactory {
360: public synchronized MOTableRow createRow(OID index,
361: Variable[] values) throws UnsupportedOperationException {
362: SnmpCommunityEntryRow row = new SnmpCommunityEntryRow(
363: index, values);
364: //--AgentGen BEGIN=snmpCommunityEntry::createRow
365: if (coexistenceInfo == null) {
366: coexistenceInfo = Collections
367: .synchronizedMap(new HashMap());
368: }
369: coexistenceInfo.put(values[idxSnmpCommunityName], row);
370: if (communityInfo == null) {
371: communityInfo = Collections
372: .synchronizedMap(new HashMap());
373: }
374: List l = (List) communityInfo
375: .get(values[idxSnmpCommunitySecurityName]);
376: if (l == null) {
377: l = new LinkedList();
378: communityInfo.put(values[idxSnmpCommunitySecurityName],
379: l);
380: }
381: l.add(row);
382: //--AgentGen END
383: return row;
384: }
385:
386: public synchronized void freeRow(MOTableRow row) {
387: //--AgentGen BEGIN=snmpCommunityEntry::freeRow
388: coexistenceInfo.remove(row.getValue(idxSnmpCommunityName));
389: List l = (List) communityInfo.get(row
390: .getValue(idxSnmpCommunitySecurityName));
391: if (l != null) {
392: l.remove(row);
393: if (l.size() == 0) {
394: communityInfo.remove(row
395: .getValue(idxSnmpCommunitySecurityName));
396: }
397: }
398: //--AgentGen END
399: }
400: }
401:
402: class SnmpCommunityEntryRow extends DefaultMOMutableRow2PC {
403: public SnmpCommunityEntryRow(OID index, Variable[] values) {
404: super (index, values);
405: }
406:
407: public OctetString getSnmpCommunityName() {
408: return (OctetString) getValue(idxSnmpCommunityName);
409: }
410:
411: public void setSnmpCommunityName(OctetString newValue) {
412: setValue(idxSnmpCommunityName, newValue);
413: }
414:
415: public OctetString getSnmpCommunitySecurityName() {
416: return (OctetString) getValue(idxSnmpCommunitySecurityName);
417: }
418:
419: public void setSnmpCommunitySecurityName(OctetString newValue) {
420: setValue(idxSnmpCommunitySecurityName, newValue);
421: }
422:
423: public OctetString getSnmpCommunityContextEngineID() {
424: return (OctetString) getValue(idxSnmpCommunityContextEngineID);
425: }
426:
427: public void setSnmpCommunityContextEngineID(OctetString newValue) {
428: setValue(idxSnmpCommunityContextEngineID, newValue);
429: }
430:
431: public OctetString getSnmpCommunityContextName() {
432: return (OctetString) getValue(idxSnmpCommunityContextName);
433: }
434:
435: public void setSnmpCommunityContextName(OctetString newValue) {
436: setValue(idxSnmpCommunityContextName, newValue);
437: }
438:
439: public OctetString getSnmpCommunityTransportTag() {
440: return (OctetString) getValue(idxSnmpCommunityTransportTag);
441: }
442:
443: public void setSnmpCommunityTransportTag(OctetString newValue) {
444: setValue(idxSnmpCommunityTransportTag, newValue);
445: }
446:
447: public Integer32 getSnmpCommunityStorageType() {
448: return (Integer32) getValue(idxSnmpCommunityStorageType);
449: }
450:
451: public void setSnmpCommunityStorageType(Integer32 newValue) {
452: setValue(idxSnmpCommunityStorageType, newValue);
453: }
454:
455: public Integer32 getSnmpCommunityStatus() {
456: return (Integer32) getValue(idxSnmpCommunityStatus);
457: }
458:
459: public void setSnmpCommunityStatus(Integer32 newValue) {
460: setValue(idxSnmpCommunityStatus, newValue);
461: }
462:
463: //--AgentGen BEGIN=snmpCommunityEntry::RowFactory
464: //--AgentGen END
465: }
466:
467: class SnmpTargetAddrExtEntryRowFactory extends
468: DefaultMOMutableRow2PCFactory {
469: public MOTableRow createRow(OID index, Variable[] values)
470: throws UnsupportedOperationException {
471: SnmpTargetAddrExtEntryRow row = new SnmpTargetAddrExtEntryRow(
472: index, values);
473: //--AgentGen BEGIN=snmpTargetAddrExtEntry::createRow
474: //--AgentGen END
475: return row;
476: }
477:
478: public void freeRow(MOTableRow row) {
479: //--AgentGen BEGIN=snmpTargetAddrExtEntry::freeRow
480: //--AgentGen END
481: }
482: }
483:
484: class SnmpTargetAddrExtEntryRow extends DefaultMOMutableRow2PC {
485: public SnmpTargetAddrExtEntryRow(OID index, Variable[] values) {
486: super (index, values);
487: }
488:
489: public OctetString getSnmpTargetAddrTMask() {
490: return (OctetString) getValue(idxSnmpTargetAddrTMask);
491: }
492:
493: public void setSnmpTargetAddrTMask(OctetString newValue) {
494: setValue(idxSnmpTargetAddrTMask, newValue);
495: }
496:
497: public Integer32 getSnmpTargetAddrMMS() {
498: return (Integer32) getValue(idxSnmpTargetAddrMMS);
499: }
500:
501: public void setSnmpTargetAddrMMS(Integer32 newValue) {
502: setValue(idxSnmpTargetAddrMMS, newValue);
503: }
504:
505: //--AgentGen BEGIN=snmpTargetAddrExtEntry::RowFactory
506: //--AgentGen END
507: }
508:
509: //--AgentGen BEGIN=_METHODS
510:
511: public CoexistenceInfo getCoexistenceInfo(OctetString community) {
512: if (logger.isDebugEnabled()) {
513: logger.debug("Looking up coexistence info for '"
514: + community + "'");
515: }
516: if (coexistenceInfo == null) {
517: return null;
518: }
519: SnmpCommunityEntryRow row = (SnmpCommunityEntryRow) coexistenceInfo
520: .get(community);
521: if (row != null) {
522: CoexistenceInfo info = new CoexistenceInfo(row
523: .getSnmpCommunitySecurityName(), row
524: .getSnmpCommunityContextEngineID(), row
525: .getSnmpCommunityContextName(), row
526: .getSnmpCommunityTransportTag());
527: if (logger.isDebugEnabled()) {
528: logger.debug("Found coexistence info for '" + community
529: + "'=" + info);
530: }
531: return info;
532: }
533: return null;
534: }
535:
536: /**
537: * Checks whether the supplied address passes the source address filter
538: * configured for the supplied transport tag. The tag identifies a set of
539: * addresses configured in the snmpTargetAddrTable which is extended by
540: * the snmpTargetAddrExtTable. The transport address mask allows entries
541: * in the snmpTargetAddrTable to define a set of addresses instead of
542: * just a single address.
543: *
544: * @param address
545: * the address of the incoming packet to check.
546: * @param coexistenceInfo
547: * a set of coexistence information that provides the transport tag that
548: * is used to identify allowed source addresses. On return, the maximum
549: * message size attribute of the coexistence info set will be set
550: * according to the values defined for the matched source address in
551: * the snmpTargetAddrExtTable.
552: * @return boolean
553: */
554: public boolean passesFilter(Address address,
555: CoexistenceInfo coexistenceInfo) {
556: if (!isSourceAddressFiltering()) {
557: if (logger.isDebugEnabled()) {
558: logger
559: .debug("Address "
560: + address
561: + " passes filter, "
562: + "because source address filtering is disabled");
563: }
564: return true;
565: }
566: if ((coexistenceInfo.getTransportTag() == null)
567: || (coexistenceInfo.getTransportTag().length() == 0)) {
568: if (logger.isDebugEnabled()) {
569: logger
570: .debug("Address "
571: + address
572: + " passes filter, because transportTag is null");
573: }
574: return true;
575: }
576: Collection matches = targetMIB
577: .getTargetAddrRowsForTag(coexistenceInfo
578: .getTransportTag());
579: for (Iterator it = matches.iterator(); it.hasNext();) {
580: SnmpTargetAddrEntryRow row = (SnmpTargetAddrEntryRow) it
581: .next();
582: SnmpTargetAddrExtEntryRow extRow = (SnmpTargetAddrExtEntryRow) snmpTargetAddrExtEntryModel
583: .getRow(row.getIndex());
584: OctetString filterTAddress = (OctetString) row
585: .getValue(SnmpTargetMIB.idxSnmpTargetAddrTAddress);
586: if (extRow != null) {
587: OctetString mask = extRow.getSnmpTargetAddrTMask();
588: OctetString matchAddress = row.getTAddress(address);
589: if ((mask.length() == 0) && (matchAddress != null)
590: && (matchAddress.equals(filterTAddress))) {
591: coexistenceInfo.setMaxMessageSize(extRow
592: .getSnmpTargetAddrMMS().getValue());
593: return true;
594: } else if ((matchAddress != null)
595: && (mask.length() == matchAddress.length())
596: && (matchAddress.length() == filterTAddress
597: .length())) {
598: OctetString maskedFilterTAddress = filterTAddress
599: .mask(mask);
600: OctetString maskedMatchTAddress = matchAddress
601: .mask(mask);
602: if (maskedFilterTAddress
603: .equals(maskedMatchTAddress)) {
604: coexistenceInfo.setMaxMessageSize(extRow
605: .getSnmpTargetAddrMMS().getValue());
606: return true;
607: }
608: }
609: }
610: }
611: return false;
612: }
613:
614: /**
615: * Enables or disables source address filtering for incoming SNMPv1 or SNMPv2c
616: * packets. By default source address filtering is disabled! If enabled, only
617: * messages received for community based security models are processed, that
618: * match an address in the snmpTargetAddressTable with the transport tag
619: * associated with the community used.
620: *
621: * @param sourceAddressFiltering
622: * if <code>true</code> source address filtering is enabled, otherwise
623: * it is disabled.
624: */
625: public void setSourceAddressFiltering(boolean sourceAddressFiltering) {
626: this .sourceAddressFiltering = sourceAddressFiltering;
627: }
628:
629: /**
630: * Returns <code>true</code> if source address filtering is enabled. In that
631: * case a call to {@link #passesFilter} will always return <code>true</code>.
632: * @return
633: * <code>true</code> if source address filtering is enabled,
634: * <code>false</code> otherwise.
635: */
636: public boolean isSourceAddressFiltering() {
637: return sourceAddressFiltering;
638: }
639:
640: public OctetString getCommunity(OctetString securityName,
641: OctetString contextEngineID, OctetString contextName) {
642: List l = (List) communityInfo.get(securityName);
643: if (l != null) {
644: for (Iterator it = l.iterator(); it.hasNext();) {
645: SnmpCommunityEntryRow row = (SnmpCommunityEntryRow) it
646: .next();
647: if (row.getSnmpCommunityStatus().getValue() == RowStatus.active) {
648: if (((contextEngineID == null) || (contextEngineID
649: .equals(row
650: .getSnmpCommunityContextEngineID())))
651: && ((row.getSnmpCommunityContextName()
652: .equals(contextName)))) {
653: return row.getSnmpCommunityName();
654: }
655: }
656: }
657: }
658: return null;
659: }
660:
661: //--AgentGen END
662:
663: //--AgentGen BEGIN=_CLASSES
664: //--AgentGen END
665:
666: //--AgentGen BEGIN=_END
667: //--AgentGen END
668: }
|