summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremie Courreges-Anglas <jca@cvs.openbsd.org>2017-04-21 13:50:24 +0000
committerJeremie Courreges-Anglas <jca@cvs.openbsd.org>2017-04-21 13:50:24 +0000
commit012593b8fe9dfa1f026f22abd12ff45e0190cf7b (patch)
treebea36b659dd73a793f52ccf8672be2e013ad3374
parentf0f4f08b7e24a549b105d7df70239e193ed5c9af (diff)
Repair AgentX support.
which I broke when adding support for multiple listen address. SNMP data should be sent to the client using the appropriate socket, which we now store when we receive the query. Reported & fix tested by Rivo Nurges.
-rw-r--r--usr.sbin/snmpd/control.c4
-rw-r--r--usr.sbin/snmpd/snmpd.h5
-rw-r--r--usr.sbin/snmpd/snmpe.c17
3 files changed, 14 insertions, 12 deletions
diff --git a/usr.sbin/snmpd/control.c b/usr.sbin/snmpd/control.c
index a4d04dc835e..d332bd1f82f 100644
--- a/usr.sbin/snmpd/control.c
+++ b/usr.sbin/snmpd/control.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: control.c,v 1.41 2017/01/09 14:49:22 reyk Exp $ */
+/* $OpenBSD: control.c,v 1.42 2017/04/21 13:50:23 jca Exp $ */
/*
* Copyright (c) 2010-2013 Reyk Floeter <reyk@openbsd.org>
@@ -592,7 +592,7 @@ control_dispatch_agentx(int fd, short event, void *arg)
}
}
dispatch:
- snmpe_dispatchmsg(msg, fd);
+ snmpe_dispatchmsg(msg);
break;
}
diff --git a/usr.sbin/snmpd/snmpd.h b/usr.sbin/snmpd/snmpd.h
index 471f1f1bc44..91186f23e42 100644
--- a/usr.sbin/snmpd/snmpd.h
+++ b/usr.sbin/snmpd/snmpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: snmpd.h,v 1.74 2017/01/09 14:49:22 reyk Exp $ */
+/* $OpenBSD: snmpd.h,v 1.75 2017/04/21 13:50:23 jca Exp $ */
/*
* Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org>
@@ -401,6 +401,7 @@ struct pfr_buffer {
#define MSG_REPORT(m) (((m)->sm_flags & SNMP_MSGFLAG_REPORT) != 0)
struct snmp_message {
+ int sm_sock;
struct sockaddr_storage sm_ss;
socklen_t sm_slen;
char sm_host[HOST_NAME_MAX+1];
@@ -660,7 +661,7 @@ struct kif_arp *karp_getaddr(struct sockaddr *, u_short, int);
/* snmpe.c */
void snmpe(struct privsep *, struct privsep_proc *);
void snmpe_shutdown(void);
-void snmpe_dispatchmsg(struct snmp_message *, int);
+void snmpe_dispatchmsg(struct snmp_message *);
/* trap.c */
void trap_init(void);
diff --git a/usr.sbin/snmpd/snmpe.c b/usr.sbin/snmpd/snmpe.c
index 7bb2ea6ee32..ec50621a6eb 100644
--- a/usr.sbin/snmpd/snmpe.c
+++ b/usr.sbin/snmpd/snmpe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: snmpe.c,v 1.46 2016/11/18 16:16:39 jca Exp $ */
+/* $OpenBSD: snmpe.c,v 1.47 2017/04/21 13:50:23 jca Exp $ */
/*
* Copyright (c) 2007, 2008, 2012 Reyk Floeter <reyk@openbsd.org>
@@ -42,7 +42,7 @@
void snmpe_init(struct privsep *, struct privsep_proc *, void *);
int snmpe_parse(struct snmp_message *);
int snmpe_parsevarbinds(struct snmp_message *);
-void snmpe_response(int, struct snmp_message *);
+void snmpe_response(struct snmp_message *);
unsigned long
snmpe_application(struct ber_element *);
void snmpe_sig_handler(int sig, short, void *);
@@ -489,6 +489,7 @@ snmpe_recvmsg(int fd, short sig, void *arg)
if ((msg = calloc(1, sizeof(*msg))) == NULL)
return;
+ msg->sm_sock = fd;
msg->sm_slen = sizeof(msg->sm_ss);
if ((len = recvfromto(fd, msg->sm_data, sizeof(msg->sm_data), 0,
(struct sockaddr *)&msg->sm_ss, &msg->sm_slen,
@@ -520,7 +521,7 @@ snmpe_recvmsg(int fd, short sig, void *arg)
if (snmpe_parse(msg) == -1) {
if (msg->sm_usmerr != 0 && MSG_REPORT(msg)) {
usm_make_report(msg);
- snmpe_response(fd, msg);
+ snmpe_response(msg);
return;
} else {
snmp_msgfree(msg);
@@ -528,22 +529,22 @@ snmpe_recvmsg(int fd, short sig, void *arg)
}
}
- snmpe_dispatchmsg(msg, fd);
+ snmpe_dispatchmsg(msg);
}
void
-snmpe_dispatchmsg(struct snmp_message *msg, int sock)
+snmpe_dispatchmsg(struct snmp_message *msg)
{
if (snmpe_parsevarbinds(msg) == 1)
return;
/* not dispatched to subagent; respond directly */
msg->sm_context = SNMP_C_GETRESP;
- snmpe_response(sock, msg);
+ snmpe_response(msg);
}
void
-snmpe_response(int fd, struct snmp_message *msg)
+snmpe_response(struct snmp_message *msg)
{
struct snmp_stats *stats = &snmpd_env->sc_stats;
u_int8_t *ptr = NULL;
@@ -580,7 +581,7 @@ snmpe_response(int fd, struct snmp_message *msg)
goto done;
usm_finalize_digest(msg, ptr, len);
- len = sendtofrom(fd, ptr, len, 0,
+ len = sendtofrom(msg->sm_sock, ptr, len, 0,
(struct sockaddr *)&msg->sm_ss, msg->sm_slen,
(struct sockaddr *)&msg->sm_local_ss, msg->sm_local_slen);
if (len != -1)