227
#if !defined(DISABLE_SNMPV1) || !defined(DISABLE_SNMPV2C)
229
create_trap_session(char *sink, u_short sinkport,
230
char *com, int version, int pdutype)
228
#if !defined(NETSNMP_DISABLE_SNMPV1) || !defined(NETSNMP_DISABLE_SNMPV2C)
230
create_trap_session2(const char *sink, const char* sinkport,
231
char *com, int version, int pdutype)
233
netsnmp_transport *t;
232
234
netsnmp_session session, *sesp;
233
char *peername = NULL;
236
len = strlen(sink) + 4 + 32;
237
if ((peername = malloc(len)) == NULL) {
239
} else if (NULL != strchr(sink,':')) {
240
snprintf(peername, len, "%s", sink);
242
snprintf(peername, len, "udp:%s:%hu", sink, sinkport);
245
236
memset(&session, 0, sizeof(netsnmp_session));
246
session.peername = peername;
247
237
session.version = version;
249
239
session.community = (u_char *) com;
265
255
NETSNMP_DS_LIB_CLIENT_ADDR)) &&
266
256
((0 == strcmp("localhost",sink)) || (0 == strcmp("127.0.0.1",sink))))
267
257
session.localname = "localhost";
268
sesp = snmp_open(&session);
272
return add_trap_session(sesp, pdutype,
273
(pdutype == SNMP_MSG_INFORM), version);
259
t = netsnmp_tdomain_transport_full("snmptrap", sink, 0, NULL, sinkport);
261
sesp = snmp_add(&session, t, NULL, NULL);
264
return add_trap_session(sesp, pdutype,
265
(pdutype == SNMP_MSG_INFORM), version);
277
269
* diagnose snmp_open errors with the input netsnmp_session pointer
279
271
snmp_sess_perror("snmpd: create_trap_session", &session);
276
create_trap_session(char *sink, u_short sinkport,
277
char *com, int version, int pdutype)
279
char buf[sizeof(sinkport) * 3 + 2];
281
sprintf(buf, ":%hu", sinkport);
283
"Using a separate port number is deprecated, please correct "
284
"the sink specification instead");
286
return create_trap_session2(sink, sinkport ? buf : NULL, com, version,
282
290
#endif /* support for community based SNMP */
284
#ifndef DISABLE_SNMPV1
292
#ifndef NETSNMP_DISABLE_SNMPV1
286
create_v1_trap_session(char *sink, u_short sinkport, char *com)
294
create_v1_trap_session(char *sink, const char *sinkport, char *com)
288
return create_trap_session(sink, sinkport, com,
289
SNMP_VERSION_1, SNMP_MSG_TRAP);
296
return create_trap_session2(sink, sinkport, com,
297
SNMP_VERSION_1, SNMP_MSG_TRAP);
293
#ifndef DISABLE_SNMPV2C
301
#ifndef NETSNMP_DISABLE_SNMPV2C
295
create_v2_trap_session(char *sink, u_short sinkport, char *com)
303
create_v2_trap_session(const char *sink, const char *sinkport, char *com)
297
return create_trap_session(sink, sinkport, com,
298
SNMP_VERSION_2c, SNMP_MSG_TRAP2);
305
return create_trap_session2(sink, sinkport, com,
306
SNMP_VERSION_2c, SNMP_MSG_TRAP2);
302
create_v2_inform_session(char *sink, u_short sinkport, char *com)
310
create_v2_inform_session(const char *sink, const char *sinkport, char *com)
304
return create_trap_session(sink, sinkport, com,
305
SNMP_VERSION_2c, SNMP_MSG_INFORM);
312
return create_trap_session2(sink, sinkport, com,
313
SNMP_VERSION_2c, SNMP_MSG_INFORM);
385
* Check the v2 varbind list for any varbinds
386
* that are not valid in an SNMPv1 trap.
387
* This basically means Counter64 values.
389
* RFC 2089 said to omit such varbinds from the list.
390
* RFC 2576/3584 say to drop the trap completely.
392
for (var = vblist->next_variable; var; var = var->next_variable) {
393
if ( var->type == ASN_COUNTER64 ) {
394
snmp_log(LOG_WARNING,
395
"send_trap: v1 traps can't carry Counter64 varbinds\n");
396
snmp_free_pdu(template_v1pdu);
377
402
* Set the generic & specific trap types,
378
403
* and the enterprise field from the v2 varbind list.
379
404
* If there's an agentIPAddress varbind, set the agent_addr too
746
774
if (!template_v2pdu) {
747
775
snmp_log(LOG_WARNING,
748
776
"send_trap: failed to convert v1->v2 template PDU\n");
749
snmp_free_pdu(template_v1pdu);
755
781
* Check whether we're ignoring authFail traps
757
if (template_v1pdu->trap_type == SNMP_TRAP_AUTHFAIL &&
783
if (template_v1pdu) {
784
if (template_v1pdu->trap_type == SNMP_TRAP_AUTHFAIL &&
758
785
snmp_enableauthentraps == SNMP_AUTHENTICATED_TRAPS_DISABLED) {
759
786
snmp_free_pdu(template_v1pdu);
760
787
snmp_free_pdu(template_v2pdu);
765
792
* Ensure that the v1 trap PDU includes the local IP address
767
pdu_in_addr_t = (in_addr_t *) template_v1pdu->agent_addr;
768
*pdu_in_addr_t = get_myaddr();
794
pdu_in_addr_t = (in_addr_t *) template_v1pdu->agent_addr;
795
*pdu_in_addr_t = get_myaddr();
774
802
* providing an appropriately formatted PDU in each case
776
804
for (sink = sinks; sink; sink = sink->next) {
777
#ifndef DISABLE_SNMPV1
805
#ifndef NETSNMP_DISABLE_SNMPV1
778
806
if (sink->version == SNMP_VERSION_1) {
807
if (template_v1pdu) {
779
808
send_trap_to_sess(sink->sesp, template_v1pdu);
812
if (template_v2pdu) {
782
813
template_v2pdu->command = sink->pdutype;
783
814
send_trap_to_sess(sink->sesp, template_v2pdu);
784
#ifndef DISABLE_SNMPV1
816
#ifndef NETSNMP_DISABLE_SNMPV1
788
snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
821
snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
789
822
SNMPD_CALLBACK_SEND_TRAP1, template_v1pdu);
790
snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
824
snmp_call_callbacks(SNMP_CALLBACK_APPLICATION,
791
825
SNMPD_CALLBACK_SEND_TRAP2, template_v2pdu);
792
826
snmp_free_pdu(template_v1pdu);
793
827
snmp_free_pdu(template_v2pdu);
862
899
DEBUGMSGTL(("trap", "sending trap type=%d, version=%d\n",
863
900
template_pdu->command, sess->version));
865
#ifndef DISABLE_SNMPV1
902
#ifndef NETSNMP_DISABLE_SNMPV1
866
903
if (sess->version == SNMP_VERSION_1 &&
867
904
(template_pdu->command != SNMP_MSG_TRAP))
868
905
return; /* Skip v1 sinks for v2 only traps */
906
if (sess->version != SNMP_VERSION_1 &&
907
(template_pdu->command == SNMP_MSG_TRAP))
908
return; /* Skip v2+ sinks for v1 only traps */
870
910
template_pdu->version = sess->version;
871
911
pdu = snmp_clone_pdu(template_pdu);
880
920
snmp_async_send(sess, pdu, &handle_inform_response, NULL);
923
if ((sess->version == SNMP_VERSION_3) &&
924
(pdu->command == SNMP_MSG_TRAP2) &&
925
(pdu->securityEngineIDLen == 0)) {
926
len = snmpv3_get_engineID(tmp, sizeof(tmp));
927
memdup(&pdu->securityEngineID, tmp, len);
928
pdu->securityEngineIDLen = len;
883
931
result = snmp_send(sess, pdu);
941
989
* This function eventually calls send_enterprise_trap_vars. If the
942
990
* trap type is not set to SNMP_TRAP_ENTERPRISESPECIFIC the enterprise
943
* and enterprise_length paramater is set to the pre defined SYSTEM_MIB
991
* and enterprise_length paramater is set to the pre defined NETSNMP_SYSTEM_MIB
944
992
* oid and length respectively. If the trap type is set to
945
993
* SNMP_TRAP_ENTERPRISESPECIFIC the enterprise and enterprise_length
946
* parameters are set to the pre-defined NOTIFICATION_MIB oid and length
994
* parameters are set to the pre-defined NETSNMP_NOTIFICATION_MIB oid and length
949
997
* @param vars is used to supply list of variable bindings to form an SNMPv2
1038
1085
cp = strtok_r(NULL, " \t\n", &st);
1040
1087
pp = strtok_r(NULL, " \t\n", &st);
1042
sinkport = atoi(pp);
1043
if ((sinkport < 1) || (sinkport > 0xffff)) {
1044
config_perror("trapsink port out of range");
1045
sinkport = SNMP_TRAP_PORT;
1048
sinkport = SNMP_TRAP_PORT;
1050
if (create_v1_trap_session(sp, (u_short)sinkport,
1051
cp ? cp : snmp_trapcommunity) == 0) {
1089
config_pwarn("The separate port argument to trapsink is deprecated");
1090
if (create_v1_trap_session(sp, pp, cp ? cp : snmp_trapcommunity) == 0) {
1052
1091
snprintf(tmpbuf, sizeof(tmpbuf), "cannot create trapsink: %s", cptr);
1053
1092
tmpbuf[sizeof(tmpbuf)-1] = '\0';
1054
1093
config_perror(tmpbuf);
1071
1110
cp = strtok_r(NULL, " \t\n", &st);
1073
1112
pp = strtok_r(NULL, " \t\n", &st);
1075
sinkport = atoi(pp);
1076
if ((sinkport < 1) || (sinkport > 0xffff)) {
1077
config_perror("trapsink port out of range");
1078
sinkport = SNMP_TRAP_PORT;
1081
sinkport = SNMP_TRAP_PORT;
1083
if (create_v2_trap_session(sp, (u_short)sinkport,
1084
cp ? cp : snmp_trapcommunity) == 0) {
1114
config_pwarn("The separate port argument to trapsink2 is deprecated");
1115
if (create_v2_trap_session(sp, pp, cp ? cp : snmp_trapcommunity) == 0) {
1085
1116
snprintf(tmpbuf, sizeof(tmpbuf), "cannot create trap2sink: %s", cptr);
1086
1117
tmpbuf[sizeof(tmpbuf)-1] = '\0';
1087
1118
config_perror(tmpbuf);
1102
1133
cp = strtok_r(NULL, " \t\n", &st);
1104
1135
pp = strtok_r(NULL, " \t\n", &st);
1106
sinkport = atoi(pp);
1107
if ((sinkport < 1) || (sinkport > 0xffff)) {
1108
config_perror("trapsink port out of range");
1109
sinkport = SNMP_TRAP_PORT;
1112
sinkport = SNMP_TRAP_PORT;
1114
if (create_v2_inform_session(sp, (u_short)sinkport,
1115
cp ? cp : snmp_trapcommunity) == 0) {
1137
config_pwarn("The separate port argument to informsink is deprecated");
1138
if (create_v2_inform_session(sp, pp, cp ? cp : snmp_trapcommunity) == 0) {
1116
1139
snprintf(tmpbuf, sizeof(tmpbuf), "cannot create informsink: %s", cptr);
1117
1140
tmpbuf[sizeof(tmpbuf)-1] = '\0';
1118
1141
config_perror(tmpbuf);
1185
#ifndef DISABLE_SNMPV1
1212
* If this is an SNMPv3 TRAP session, then the agent is
1213
* the authoritative engine, so set the engineID accordingly
1215
if (ss->version == SNMP_VERSION_3 &&
1216
traptype != SNMP_MSG_INFORM &&
1217
ss->securityEngineIDLen == 0) {
1218
len = snmpv3_get_engineID( tmp, sizeof(tmp));
1219
memdup(&ss->securityEngineID, tmp, len);
1220
ss->securityEngineIDLen = len;
1223
#ifndef NETSNMP_DISABLE_SNMPV1
1186
1224
if (ss->version == SNMP_VERSION_1) {
1187
1225
add_trap_session(ss, SNMP_MSG_TRAP, 0, SNMP_VERSION_1);
1190
1228
add_trap_session(ss, traptype, (traptype == SNMP_MSG_INFORM),
1192
#ifndef DISABLE_SNMPV1
1230
#ifndef NETSNMP_DISABLE_SNMPV1
1197
#if !defined(DISABLE_SNMPV1) || !defined(DISABLE_SNMPV2C)
1235
#if !defined(NETSNMP_DISABLE_SNMPV1) || !defined(NETSNMP_DISABLE_SNMPV2C)
1199
1237
snmpd_parse_config_trapcommunity(const char *word, char *cptr)