On sön, 2006-12-17 at 11:13 +0100, Magnus Fromreide wrote:
> On lör, 2006-12-16 at 16:28 +0100, Thomas Anders wrote:
> > Magnus Fromreide wrote:
> With the above said I have to admit that I am preparing a patch to give
> NETSNMP_DS_LIB_DEFAULT_PORT priority.
It was harder than I imagined to fix this properly. Attached is a pile
of patches that I think fixes the problem.
snmp_sess_add_ex-consistent-delete:
This adddresses that snmp_sess_add_ex is unclear regarding the
ownership of the transport argument. The patch clarifies the
ownership issue to be that snmp_sess_add_ex takes ownership of the
transport argument.
If the return on line 1574 or 1580 is taken then the transport stays
alive.
If the return on line 1600 is taken then the transport is deleted.
If the return on line 1606 is taken then the transport stays alive
and the newly created session is leaked.
snmp_sess_add_ex-clear-SNMP_FLAGS_DONT_PROBE:
_sess_open clears SNMP_FLAGS_DONT_PROBE after the probeing, that
was not done by snmp_sess_add_ex. This patch makes it do that.
_sess_open-by-snmp_sess_add:
This patch implements _sess_open by means of calling
snmp_sess_add since they have almost the same function. It can
also be seen as groundwork for a later reorganization of all
snmp_*_open* functions into a hierarchy similar to the
snmp_*_add* functions.
This patch doesn't correct any problem, it just removes some
code duplication.
give-NETSNMP_DS_LIB_DEFAULT_PORT-precedence:
This patch gives NETSNMP_DS_LIB_DEFAULT_PORT precedence over the
default_target argument to netsnmp_sockaddr_in2 and
netsnmp_sockaddr_in6_2 and additionally removes the setting of
it to 162 from _init_snmp in order to make the default_target
arguments have any use at all.
snmptrapd-wrong-port:
This patch removes the forced addition of :162 to the port
argument of snmptrapd, intead it uses the default domain from
netsnmp_transport_open_server("snmptrap", ...). The advantage is
that it makes it possible to configure other listen ports as
well as use other transports than the IP ones.
snmptrap_correct_port:
This patch removes the forced setting of
NETSNMP_DS_LIB_DEFAULT_PORT from snmptrap and replaces
snmp_open with netsnmp_transport_open_client followed by
snmp_add since a transport other than "snmp" is to be used for
traps (the original bug) In addition this have the same
advantages as explained for snmptrapd-wrong-port.
snmpUDPDomain-memory-leak:
netsnmp_udp_transport leaked an netsnmp_udp_addr_pair each time
it was called. Change that variable to be stack allocated as it
is local.
In addition there is a file, ALL that contains all the patches.
(How should I put a series of patches with interdependencies into the
patch tracker?)
/MF
Index: clean/snmplib/snmp_api.c
===================================================================
--- clean.orig/snmplib/snmp_api.c 2006-12-18 23:10:44.000000000 +0100
+++ clean/snmplib/snmp_api.c 2006-12-18 23:24:51.000000000 +0100
@@ -1570,13 +1570,18 @@
_init_snmp();
- if (in_session == NULL || transport == NULL) {
- return NULL;
+ if (transport == NULL)
+ return NULL;
+
+ if (in_session == NULL) {
+ netsnmp_transport_free(transport);
+ return NULL;
}
DEBUGMSGTL(("snmp_sess_add", "fd %d\n", transport->sock));
if ((slp = snmp_sess_copy(in_session)) == NULL) {
+ netsnmp_transport_free(transport);
return (NULL);
}
@@ -1602,8 +1607,10 @@
if (create_user_from_session(slp->session) != SNMPERR_SUCCESS) {
slp->session->s_snmp_errno = SNMPERR_UNKNOWN_USER_NAME;
DEBUGMSGTL(("snmp_api",
- "_sess_open(): failed(2) to create a new user from session\n"));
- return 0;
+ "_sess_open(): failed(2) to create a new user "
+ "from session\n"));
+ snmp_sess_close(slp);
+ return NULL;
}
}
@@ -5507,9 +5514,6 @@
(void)nslp->session->callback(NETSNMP_CALLBACK_OP_CONNECT,
nslp->session, 0, NULL,
sp->callback_magic);
- } else {
- new_transport->f_close(new_transport);
- netsnmp_transport_free(new_transport);
}
return 0;
} else {
Index: clean/snmplib/snmp_api.c
===================================================================
--- clean.orig/snmplib/snmp_api.c 2006-12-18 23:11:54.000000000 +0100
+++ clean/snmplib/snmp_api.c 2006-12-18 23:24:46.000000000 +0100
@@ -1612,6 +1612,7 @@
snmp_sess_close(slp);
return NULL;
}
+ slp->session->flags &= ~SNMP_FLAGS_DONT_PROBE;
}
return (void *) slp;
Index: clean/snmplib/snmp_api.c
===================================================================
--- clean.orig/snmplib/snmp_api.c 2006-12-18 23:14:12.000000000 +0100
+++ clean/snmplib/snmp_api.c 2006-12-18 23:24:12.000000000 +0100
@@ -1409,71 +1409,51 @@
static void *
_sess_open(netsnmp_session * in_session)
{
- struct session_list *slp;
- netsnmp_session *session;
- char *clientaddr_save = NULL;
+ netsnmp_transport *transport = NULL;
in_session->s_snmp_errno = 0;
in_session->s_errno = 0;
_init_snmp();
- if ((slp = snmp_sess_copy(in_session)) == NULL) {
- return (NULL);
- }
- session = slp->session;
- slp->transport = NULL;
+ {
+ char *clientaddr_save = NULL;
- if (NULL != session->localname) {
- clientaddr_save = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID,
- NETSNMP_DS_LIB_CLIENT_ADDR);
- netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID,
- NETSNMP_DS_LIB_CLIENT_ADDR, session->localname);
- }
+ if (NULL != in_session->localname) {
+ clientaddr_save =
+ netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID,
+ NETSNMP_DS_LIB_CLIENT_ADDR);
+ netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID,
+ NETSNMP_DS_LIB_CLIENT_ADDR,
+ in_session->localname);
+ }
+
+ if (in_session->flags & SNMP_FLAGS_STREAM_SOCKET) {
+ transport =
+ netsnmp_tdomain_transport_full("snmp", in_session->peername,
+ in_session->local_port, "tcp",
+ NULL);
+ } else {
+ transport =
+ netsnmp_tdomain_transport_full("snmp", in_session->peername,
+ in_session->local_port, "udp",
+ NULL);
+ }
- if (session->flags & SNMP_FLAGS_STREAM_SOCKET) {
- slp->transport =
- netsnmp_tdomain_transport_full("snmp", session->peername,
- session->local_port, "tcp", NULL);
- } else {
- slp->transport =
- netsnmp_tdomain_transport_full("snmp", session->peername,
- session->local_port, "udp", NULL);
+ if (NULL != clientaddr_save)
+ netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID,
+ NETSNMP_DS_LIB_CLIENT_ADDR, clientaddr_save);
}
-
- if (NULL != session->localname)
- netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID,
- NETSNMP_DS_LIB_CLIENT_ADDR, clientaddr_save);
-
- if (slp->transport == NULL) {
+ if (transport == NULL) {
DEBUGMSGTL(("_sess_open", "couldn't interpret peername\n"));
in_session->s_snmp_errno = SNMPERR_BAD_ADDRESS;
in_session->s_errno = errno;
- snmp_set_detail(session->peername);
- snmp_sess_close(slp);
+ snmp_set_detail(in_session->peername);
return NULL;
}
- session->rcvMsgMaxSize = slp->transport->msgMaxSize;
-
- if (!snmpv3_engineID_probe(slp, in_session)) {
- snmp_sess_close(slp);
- return 0;
- }
- if (create_user_from_session(slp->session) != SNMPERR_SUCCESS) {
- in_session->s_snmp_errno = SNMPERR_UNKNOWN_USER_NAME; /* XX?? */
- DEBUGMSGTL(("snmp_api",
- "_sess_open(): failed(2) to create a new user from session\n"));
- return 0;
- }
-
- session->flags &= ~SNMP_FLAGS_DONT_PROBE;
-
-
- return (void *) slp;
-} /* end snmp_sess_open() */
-
-
+ return snmp_sess_add(in_session, transport, NULL, NULL);
+}
/*
* EXPERIMENTAL API EXTENSIONS ------------------------------------------
Index: clean/snmplib/snmpUDPDomain.c
===================================================================
--- clean.orig/snmplib/snmpUDPDomain.c 2006-12-18 21:04:03.000000000 +0100
+++ clean/snmplib/snmpUDPDomain.c 2006-12-18 23:25:19.000000000 +0100
@@ -781,18 +781,19 @@
addr, inpeername ? inpeername : "[NIL]",
default_target ? default_target : "[NIL]"));
- if (default_target == NULL ||
- netsnmp_sockaddr_in2(addr, default_target, NULL) == 0) {
- int port;
-
- memset(addr, 0, sizeof(struct sockaddr_in));
- addr->sin_addr.s_addr = htonl(INADDR_ANY);
- addr->sin_family = AF_INET;
- port = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID,
- NETSNMP_DS_LIB_DEFAULT_PORT);
- if (port == 0)
- port = SNMP_PORT;
- addr->sin_port = htons((u_short)port);
+ memset(addr, 0, sizeof(struct sockaddr_in));
+ addr->sin_addr.s_addr = htonl(INADDR_ANY);
+ addr->sin_family = AF_INET;
+ addr->sin_port = htons((u_short)SNMP_PORT);
+
+ {
+ int port = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID,
+ NETSNMP_DS_LIB_DEFAULT_PORT);
+
+ if (port != 0) {
+ addr->sin_port = htons((u_short)port);
+ } else if (default_target != NULL)
+ netsnmp_sockaddr_in2(addr, default_target, NULL);
}
if (inpeername != NULL && *inpeername != '\0') {
Index: clean/snmplib/snmpUDPIPv6Domain.c
===================================================================
--- clean.orig/snmplib/snmpUDPIPv6Domain.c 2006-12-18 21:04:03.000000000 +0100
+++ clean/snmplib/snmpUDPIPv6Domain.c 2006-12-18 23:25:19.000000000 +0100
@@ -370,19 +370,18 @@
addr, inpeername ? inpeername : "[NIL]",
default_target ? default_target : "[NIL]"));
- if (default_target == NULL ||
- netsnmp_sockaddr_in6_2(addr, default_target, NULL) == 0) {
- int port;
- memset(addr, 0, sizeof(struct sockaddr_in6));
- addr->sin6_family = AF_INET6;
- addr->sin6_addr = in6addr_any;
-
- port = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID,
- NETSNMP_DS_LIB_DEFAULT_PORT);
- if (port <= 0)
- port = SNMP_PORT;
-
+ memset(addr, 0, sizeof(struct sockaddr_in6));
+ addr->sin6_family = AF_INET6;
+ addr->sin6_addr = in6addr_any;
+ addr->sin6_port = htons((u_short)SNMP_PORT);
+
+ {
+ int port = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID,
+ NETSNMP_DS_LIB_DEFAULT_PORT);
+ if (port != 0)
addr->sin6_port = htons((u_short)port);
+ else if (default_target == NULL)
+ netsnmp_sockaddr_in6_2(addr, default_target, NULL);
}
if (inpeername != NULL) {
Index: clean/snmplib/snmp_api.c
===================================================================
--- clean.orig/snmplib/snmp_api.c 2006-12-18 23:24:58.000000000 +0100
+++ clean/snmplib/snmp_api.c 2006-12-18 23:25:19.000000000 +0100
@@ -624,7 +624,6 @@
struct timeval tv;
long tmpReqid, tmpMsgid;
- u_short s_port = SNMP_PORT;
if (have_done_init)
return;
@@ -674,13 +673,17 @@
/*
* store it in host byte order
*/
- s_port = ntohs(servp->s_port);
+ char buf[32];
+ sprintf(buf, ":%hu", ntohs(servp->s_port));
+ netsnmp_register_default_target("snmp", "udp", buf);
+ netsnmp_register_default_target("snmp", "udp6", buf);
}
+#else
+ netsnmp_register_default_target("snmp", "udp", ":161");
+ netsnmp_register_default_target("snmp", "udp6", ":161");
#endif
- netsnmp_register_default_target("snmp", "udp", ":161");
netsnmp_register_default_target("snmp", "tcp", ":161");
- netsnmp_register_default_target("snmp", "udp6", ":161");
netsnmp_register_default_target("snmp", "tcp6", ":161");
netsnmp_register_default_target("snmp", "ipx", "/36879");
netsnmp_register_default_target("snmptrap", "udp", ":162");
@@ -690,8 +693,6 @@
netsnmp_register_default_target("snmptrap", "ipx", "/36880");
netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID,
- NETSNMP_DS_LIB_DEFAULT_PORT, s_port);
- netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID,
NETSNMP_DS_LIB_HEX_OUTPUT_LENGTH, 16);
#ifdef NETSNMP_USE_REVERSE_ASNENCODING
Index: clean/apps/snmptrapd.c
===================================================================
--- clean.orig/apps/snmptrapd.c 2006-12-17 02:56:38.000000000 +0100
+++ clean/apps/snmptrapd.c 2006-12-17 02:56:45.000000000 +0100
@@ -1283,26 +1283,15 @@
while (cp != NULL) {
char *sep = strchr(cp, ',');
- char listen_name[128];
- char *cp2 = strchr(cp, ':');
if (sep != NULL) {
*sep = 0;
}
- /*
- * Make sure this defaults to listening on port 162
- */
- if (!cp2) {
- snprintf(listen_name, sizeof(listen_name), "%s:162", cp);
- cp2 = listen_name;
- } else {
- cp2 = cp;
- }
- transport = netsnmp_transport_open_server("snmptrap", cp2);
+ transport = netsnmp_transport_open_server("snmptrap", cp);
if (transport == NULL) {
snmp_log(LOG_ERR, "couldn't open %s -- errno %d (\"%s\")\n",
- cp2, errno, strerror(errno));
+ cp, errno, strerror(errno));
snmptrapd_close_sessions(sess_list);
SOCK_CLEANUP;
exit(1);
Index: clean/apps/snmptrap.c
===================================================================
--- clean.orig/apps/snmptrap.c 2006-12-19 00:12:06.000000000 +0100
+++ clean/apps/snmptrap.c 2006-12-19 00:15:45.000000000 +0100
@@ -185,8 +185,6 @@
session.callback = snmp_input;
session.callback_magic = NULL;
- netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DEFAULT_PORT,
- SNMP_TRAP_PORT);
if (session.version == SNMP_VERSION_3 && !inform) {
/*
@@ -239,10 +237,13 @@
session.engineTime = get_uptime(); /* but it'll work. Sort of. */
}
- ss = snmp_open(&session);
+ ss = snmp_add(&session,
+ netsnmp_transport_open_client("snmptrap", session.peername),
+ NULL, NULL);
if (ss == NULL) {
/*
- * diagnose snmp_open errors with the input netsnmp_session pointer
+ * diagnose netsnmp_transport_open_client and snmp_add errors with
+ * the input netsnmp_session pointer
*/
snmp_sess_perror("snmptrap", &session);
SOCK_CLEANUP;
Index: clean/snmplib/snmpUDPDomain.c
===================================================================
--- clean.orig/snmplib/snmpUDPDomain.c 2006-12-17 23:42:43.000000000 +0100
+++ clean/snmplib/snmpUDPDomain.c 2006-12-17 23:42:52.000000000 +0100
@@ -586,28 +586,24 @@
int rc = 0;
char *str = NULL;
char *client_socket = NULL;
- netsnmp_udp_addr_pair *addr_pair = NULL;
+ netsnmp_udp_addr_pair addr_pair;
if (addr == NULL || addr->sin_family != AF_INET) {
return NULL;
}
- addr_pair = (netsnmp_udp_addr_pair *) malloc(sizeof(netsnmp_udp_addr_pair));
- if (addr_pair == NULL) {
- return NULL;
- }
- memset(addr_pair, 0, sizeof(netsnmp_udp_addr_pair));
- memcpy(&(addr_pair->remote_addr), addr, sizeof(struct sockaddr_in));
+ memset(&addr_pair, 0, sizeof(netsnmp_udp_addr_pair));
+ memcpy(&(addr_pair.remote_addr), addr, sizeof(struct sockaddr_in));
t = (netsnmp_transport *) malloc(sizeof(netsnmp_transport));
if (t == NULL) {
return NULL;
}
- str = netsnmp_udp_fmtaddr(NULL, (void *)addr_pair,
+ str = netsnmp_udp_fmtaddr(NULL, (void *)&addr_pair,
sizeof(netsnmp_udp_addr_pair));
- DEBUGMSGTL(("netsnmp_udp", "open %s %s:%d\n", local ? "local" : "remote",
- str,addr->sin_port));
+ DEBUGMSGTL(("netsnmp_udp", "open %s %s\n", local ? "local" : "remote",
+ str));
free(str);
memset(t, 0, sizeof(netsnmp_transport));
@@ -690,7 +686,7 @@
t->remote[4] = (htons(addr->sin_port) & 0xff00) >> 8;
t->remote[5] = (htons(addr->sin_port) & 0x00ff) >> 0;
t->remote_length = 6;
- memcpy(t->data, addr_pair, sizeof(netsnmp_udp_addr_pair));
+ memcpy(t->data, &addr_pair, sizeof(netsnmp_udp_addr_pair));
t->data_length = sizeof(netsnmp_udp_addr_pair);
}
Index: apps/snmptrap.c
===================================================================
RCS file: /cvsroot/net-snmp/net-snmp/apps/snmptrap.c,v
retrieving revision 5.4
diff -u -r5.4 snmptrap.c
--- apps/snmptrap.c 15 Sep 2006 00:48:43 -0000 5.4
+++ apps/snmptrap.c 18 Dec 2006 23:23:24 -0000
@@ -185,8 +185,6 @@
session.callback = snmp_input;
session.callback_magic = NULL;
- netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DEFAULT_PORT,
- SNMP_TRAP_PORT);
if (session.version == SNMP_VERSION_3 && !inform) {
/*
@@ -239,10 +237,13 @@
session.engineTime = get_uptime(); /* but it'll work. Sort of. */
}
- ss = snmp_open(&session);
+ ss = snmp_add(&session,
+ netsnmp_transport_open_client("snmptrap", session.peername),
+ NULL, NULL);
if (ss == NULL) {
/*
- * diagnose snmp_open errors with the input netsnmp_session pointer
+ * diagnose netsnmp_transport_open_client and snmp_add errors with
+ * the input netsnmp_session pointer
*/
snmp_sess_perror("snmptrap", &session);
SOCK_CLEANUP;
Index: apps/snmptrapd.c
===================================================================
RCS file: /cvsroot/net-snmp/net-snmp/apps/snmptrapd.c,v
retrieving revision 5.79
diff -u -r5.79 snmptrapd.c
--- apps/snmptrapd.c 22 Nov 2006 12:58:20 -0000 5.79
+++ apps/snmptrapd.c 18 Dec 2006 23:23:25 -0000
@@ -1283,26 +1283,15 @@
while (cp != NULL) {
char *sep = strchr(cp, ',');
- char listen_name[128];
- char *cp2 = strchr(cp, ':');
if (sep != NULL) {
*sep = 0;
}
- /*
- * Make sure this defaults to listening on port 162
- */
- if (!cp2) {
- snprintf(listen_name, sizeof(listen_name), "%s:162", cp);
- cp2 = listen_name;
- } else {
- cp2 = cp;
- }
- transport = netsnmp_transport_open_server("snmptrap", cp2);
+ transport = netsnmp_transport_open_server("snmptrap", cp);
if (transport == NULL) {
snmp_log(LOG_ERR, "couldn't open %s -- errno %d (\"%s\")\n",
- cp2, errno, strerror(errno));
+ cp, errno, strerror(errno));
snmptrapd_close_sessions(sess_list);
SOCK_CLEANUP;
exit(1);
Index: snmplib/snmpUDPDomain.c
===================================================================
RCS file: /cvsroot/net-snmp/net-snmp/snmplib/snmpUDPDomain.c,v
retrieving revision 5.44
diff -u -r5.44 snmpUDPDomain.c
--- snmplib/snmpUDPDomain.c 19 Sep 2006 23:42:17 -0000 5.44
+++ snmplib/snmpUDPDomain.c 18 Dec 2006 23:23:28 -0000
@@ -586,28 +586,24 @@
int rc = 0;
char *str = NULL;
char *client_socket = NULL;
- netsnmp_udp_addr_pair *addr_pair = NULL;
+ netsnmp_udp_addr_pair addr_pair;
if (addr == NULL || addr->sin_family != AF_INET) {
return NULL;
}
- addr_pair = (netsnmp_udp_addr_pair *) malloc(sizeof(netsnmp_udp_addr_pair));
- if (addr_pair == NULL) {
- return NULL;
- }
- memset(addr_pair, 0, sizeof(netsnmp_udp_addr_pair));
- memcpy(&(addr_pair->remote_addr), addr, sizeof(struct sockaddr_in));
+ memset(&addr_pair, 0, sizeof(netsnmp_udp_addr_pair));
+ memcpy(&(addr_pair.remote_addr), addr, sizeof(struct sockaddr_in));
t = (netsnmp_transport *) malloc(sizeof(netsnmp_transport));
if (t == NULL) {
return NULL;
}
- str = netsnmp_udp_fmtaddr(NULL, (void *)addr_pair,
+ str = netsnmp_udp_fmtaddr(NULL, (void *)&addr_pair,
sizeof(netsnmp_udp_addr_pair));
- DEBUGMSGTL(("netsnmp_udp", "open %s %s:%d\n", local ? "local" : "remote",
- str,addr->sin_port));
+ DEBUGMSGTL(("netsnmp_udp", "open %s %s\n", local ? "local" : "remote",
+ str));
free(str);
memset(t, 0, sizeof(netsnmp_transport));
@@ -690,7 +686,7 @@
t->remote[4] = (htons(addr->sin_port) & 0xff00) >> 8;
t->remote[5] = (htons(addr->sin_port) & 0x00ff) >> 0;
t->remote_length = 6;
- memcpy(t->data, addr_pair, sizeof(netsnmp_udp_addr_pair));
+ memcpy(t->data, &addr_pair, sizeof(netsnmp_udp_addr_pair));
t->data_length = sizeof(netsnmp_udp_addr_pair);
}
@@ -781,18 +777,19 @@
addr, inpeername ? inpeername : "[NIL]",
default_target ? default_target : "[NIL]"));
- if (default_target == NULL ||
- netsnmp_sockaddr_in2(addr, default_target, NULL) == 0) {
- int port;
-
- memset(addr, 0, sizeof(struct sockaddr_in));
- addr->sin_addr.s_addr = htonl(INADDR_ANY);
- addr->sin_family = AF_INET;
- port = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID,
- NETSNMP_DS_LIB_DEFAULT_PORT);
- if (port == 0)
- port = SNMP_PORT;
- addr->sin_port = htons((u_short)port);
+ memset(addr, 0, sizeof(struct sockaddr_in));
+ addr->sin_addr.s_addr = htonl(INADDR_ANY);
+ addr->sin_family = AF_INET;
+ addr->sin_port = htons((u_short)SNMP_PORT);
+
+ {
+ int port = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID,
+ NETSNMP_DS_LIB_DEFAULT_PORT);
+
+ if (port != 0) {
+ addr->sin_port = htons((u_short)port);
+ } else if (default_target != NULL)
+ netsnmp_sockaddr_in2(addr, default_target, NULL);
}
if (inpeername != NULL && *inpeername != '\0') {
Index: snmplib/snmpUDPIPv6Domain.c
===================================================================
RCS file: /cvsroot/net-snmp/net-snmp/snmplib/snmpUDPIPv6Domain.c,v
retrieving revision 5.37
diff -u -r5.37 snmpUDPIPv6Domain.c
--- snmplib/snmpUDPIPv6Domain.c 25 Sep 2006 21:33:43 -0000 5.37
+++ snmplib/snmpUDPIPv6Domain.c 18 Dec 2006 23:23:28 -0000
@@ -370,19 +370,18 @@
addr, inpeername ? inpeername : "[NIL]",
default_target ? default_target : "[NIL]"));
- if (default_target == NULL ||
- netsnmp_sockaddr_in6_2(addr, default_target, NULL) == 0) {
- int port;
- memset(addr, 0, sizeof(struct sockaddr_in6));
- addr->sin6_family = AF_INET6;
- addr->sin6_addr = in6addr_any;
-
- port = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID,
- NETSNMP_DS_LIB_DEFAULT_PORT);
- if (port <= 0)
- port = SNMP_PORT;
-
+ memset(addr, 0, sizeof(struct sockaddr_in6));
+ addr->sin6_family = AF_INET6;
+ addr->sin6_addr = in6addr_any;
+ addr->sin6_port = htons((u_short)SNMP_PORT);
+
+ {
+ int port = netsnmp_ds_get_int(NETSNMP_DS_LIBRARY_ID,
+ NETSNMP_DS_LIB_DEFAULT_PORT);
+ if (port != 0)
addr->sin6_port = htons((u_short)port);
+ else if (default_target == NULL)
+ netsnmp_sockaddr_in6_2(addr, default_target, NULL);
}
if (inpeername != NULL) {
Index: snmplib/snmp_api.c
===================================================================
RCS file: /cvsroot/net-snmp/net-snmp/snmplib/snmp_api.c,v
retrieving revision 5.116
diff -u -r5.116 snmp_api.c
--- snmplib/snmp_api.c 25 Oct 2006 16:16:24 -0000 5.116
+++ snmplib/snmp_api.c 18 Dec 2006 23:23:33 -0000
@@ -624,7 +624,6 @@
struct timeval tv;
long tmpReqid, tmpMsgid;
- u_short s_port = SNMP_PORT;
if (have_done_init)
return;
@@ -674,13 +673,17 @@
/*
* store it in host byte order
*/
- s_port = ntohs(servp->s_port);
+ char buf[32];
+ sprintf(buf, ":%hu", ntohs(servp->s_port));
+ netsnmp_register_default_target("snmp", "udp", buf);
+ netsnmp_register_default_target("snmp", "udp6", buf);
}
+#else
+ netsnmp_register_default_target("snmp", "udp", ":161");
+ netsnmp_register_default_target("snmp", "udp6", ":161");
#endif
- netsnmp_register_default_target("snmp", "udp", ":161");
netsnmp_register_default_target("snmp", "tcp", ":161");
- netsnmp_register_default_target("snmp", "udp6", ":161");
netsnmp_register_default_target("snmp", "tcp6", ":161");
netsnmp_register_default_target("snmp", "ipx", "/36879");
netsnmp_register_default_target("snmptrap", "udp", ":162");
@@ -690,8 +693,6 @@
netsnmp_register_default_target("snmptrap", "ipx", "/36880");
netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID,
- NETSNMP_DS_LIB_DEFAULT_PORT, s_port);
- netsnmp_ds_set_int(NETSNMP_DS_LIBRARY_ID,
NETSNMP_DS_LIB_HEX_OUTPUT_LENGTH, 16);
#ifdef NETSNMP_USE_REVERSE_ASNENCODING
@@ -1409,71 +1410,51 @@
static void *
_sess_open(netsnmp_session * in_session)
{
- struct session_list *slp;
- netsnmp_session *session;
- char *clientaddr_save = NULL;
+ netsnmp_transport *transport = NULL;
in_session->s_snmp_errno = 0;
in_session->s_errno = 0;
_init_snmp();
- if ((slp = snmp_sess_copy(in_session)) == NULL) {
- return (NULL);
- }
- session = slp->session;
- slp->transport = NULL;
+ {
+ char *clientaddr_save = NULL;
- if (NULL != session->localname) {
- clientaddr_save = netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID,
- NETSNMP_DS_LIB_CLIENT_ADDR);
- netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID,
- NETSNMP_DS_LIB_CLIENT_ADDR, session->localname);
- }
+ if (NULL != in_session->localname) {
+ clientaddr_save =
+ netsnmp_ds_get_string(NETSNMP_DS_LIBRARY_ID,
+ NETSNMP_DS_LIB_CLIENT_ADDR);
+ netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID,
+ NETSNMP_DS_LIB_CLIENT_ADDR,
+ in_session->localname);
+ }
+
+ if (in_session->flags & SNMP_FLAGS_STREAM_SOCKET) {
+ transport =
+ netsnmp_tdomain_transport_full("snmp", in_session->peername,
+ in_session->local_port, "tcp",
+ NULL);
+ } else {
+ transport =
+ netsnmp_tdomain_transport_full("snmp", in_session->peername,
+ in_session->local_port, "udp",
+ NULL);
+ }
- if (session->flags & SNMP_FLAGS_STREAM_SOCKET) {
- slp->transport =
- netsnmp_tdomain_transport_full("snmp", session->peername,
- session->local_port, "tcp", NULL);
- } else {
- slp->transport =
- netsnmp_tdomain_transport_full("snmp", session->peername,
- session->local_port, "udp", NULL);
+ if (NULL != clientaddr_save)
+ netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID,
+ NETSNMP_DS_LIB_CLIENT_ADDR, clientaddr_save);
}
-
- if (NULL != session->localname)
- netsnmp_ds_set_string(NETSNMP_DS_LIBRARY_ID,
- NETSNMP_DS_LIB_CLIENT_ADDR, clientaddr_save);
-
- if (slp->transport == NULL) {
+ if (transport == NULL) {
DEBUGMSGTL(("_sess_open", "couldn't interpret peername\n"));
in_session->s_snmp_errno = SNMPERR_BAD_ADDRESS;
in_session->s_errno = errno;
- snmp_set_detail(session->peername);
- snmp_sess_close(slp);
+ snmp_set_detail(in_session->peername);
return NULL;
}
- session->rcvMsgMaxSize = slp->transport->msgMaxSize;
-
- if (!snmpv3_engineID_probe(slp, in_session)) {
- snmp_sess_close(slp);
- return 0;
- }
- if (create_user_from_session(slp->session) != SNMPERR_SUCCESS) {
- in_session->s_snmp_errno = SNMPERR_UNKNOWN_USER_NAME; /* XX?? */
- DEBUGMSGTL(("snmp_api",
- "_sess_open(): failed(2) to create a new user from session\n"));
- return 0;
- }
-
- session->flags &= ~SNMP_FLAGS_DONT_PROBE;
-
-
- return (void *) slp;
-} /* end snmp_sess_open() */
-
-
+ return snmp_sess_add(in_session, transport, NULL, NULL);
+}
/*
* EXPERIMENTAL API EXTENSIONS ------------------------------------------
@@ -1570,13 +1551,18 @@
_init_snmp();
- if (in_session == NULL || transport == NULL) {
- return NULL;
+ if (transport == NULL)
+ return NULL;
+
+ if (in_session == NULL) {
+ netsnmp_transport_free(transport);
+ return NULL;
}
DEBUGMSGTL(("snmp_sess_add", "fd %d\n", transport->sock));
if ((slp = snmp_sess_copy(in_session)) == NULL) {
+ netsnmp_transport_free(transport);
return (NULL);
}
@@ -1602,9 +1588,12 @@
if (create_user_from_session(slp->session) != SNMPERR_SUCCESS) {
slp->session->s_snmp_errno = SNMPERR_UNKNOWN_USER_NAME;
DEBUGMSGTL(("snmp_api",
- "_sess_open(): failed(2) to create a new user from session\n"));
- return 0;
+ "_sess_open(): failed(2) to create a new user "
+ "from session\n"));
+ snmp_sess_close(slp);
+ return NULL;
}
+ slp->session->flags &= ~SNMP_FLAGS_DONT_PROBE;
}
return (void *) slp;
@@ -5507,9 +5496,6 @@
(void)nslp->session->callback(NETSNMP_CALLBACK_OP_CONNECT,
nslp->session, 0, NULL,
sp->callback_magic);
- } else {
- new_transport->f_close(new_transport);
- netsnmp_transport_free(new_transport);
}
return 0;
} else {
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders