/* * "Notification" handler for implementing NOTIFICATION-MIB * (presumably) */ int notification_handler(netsnmp_pdu *pdu, netsnmp_transport *transport, netsnmp_trapd_handler *handler) { DEBUGMSGTL(( "snmptrapd", "notification_handler\n")); log_notification(pdu, transport); return NETSNMPTRAPD_HANDLER_OK; }
int send_notifications(int major, int minor, void *serverarg, void *clientarg) { struct header_complex_index *hptr; struct snmpNotifyTable_data *nptr; netsnmp_session *sess, *sptr; netsnmp_pdu *template_pdu = (netsnmp_pdu *) serverarg; int count = 0, send = 0; DEBUGMSGTL(("send_notifications", "starting: pdu=%p, vars=%p\n", template_pdu, template_pdu->variables)); for (hptr = snmpNotifyTableStorage; hptr; hptr = hptr->next) { nptr = (struct snmpNotifyTable_data *) hptr->data; if (nptr->snmpNotifyRowStatus != RS_ACTIVE) continue; if (!nptr->snmpNotifyTag) continue; sess = get_target_sessions(nptr->snmpNotifyTag, NULL, NULL); /* * filter appropriately, per section 6 of RFC 3413 */ for (sptr = sess; sptr; sptr = sptr->next) { send = 0; #ifndef NETSNMP_DISABLE_SNMPV1 if (sptr->version == SNMP_VERSION_1 && minor == SNMPD_CALLBACK_SEND_TRAP1) { send = 1; } else #endif if ((sptr->version == SNMP_VERSION_3 #ifndef NETSNMP_DISABLE_SNMPV2C || sptr->version == SNMP_VERSION_2c #endif ) && minor == SNMPD_CALLBACK_SEND_TRAP2) { if (nptr->snmpNotifyType == SNMPNOTIFYTYPE_INFORM) { template_pdu->command = SNMP_MSG_INFORM; } else { template_pdu->command = SNMP_MSG_TRAP2; } send = 1; } if (send && sess->paramName) { int filter = _checkFilter(sess->paramName, template_pdu); if (filter) send = 0; } if (send) { send_trap_to_sess(sptr, template_pdu); ++count; } /* session to send to */ } /* for(sptr) */ } /* for(hptr) */ DEBUGMSGTL(("send_notifications", "sent %d notifications\n", count)); #ifdef USING_NOTIFICATION_LOG_MIB_NOTIFICATION_LOG_MODULE if (count) log_notification(template_pdu, NULL); #endif return 0; }