From 06bbba4783ce7c60f8368b077f3d08849da7633a Mon Sep 17 00:00:00 2001 From: Scott Lovenberg Date: Wed, 16 Sep 2015 22:43:11 -0500 Subject: [PATCH] libs : define unified socket timeout This patch removes redundant definitions for socket timeouts and puts them in a common header file. Signed-off-by: Scott Lovenberg --- lib/socket/socket_common.h | 33 +++++++++++++++++++++++++++++++++ source3/include/local.h | 8 +++----- source3/utils/smbfilter.c | 3 ++- source4/libcli/raw/clisocket.c | 3 ++- 4 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 lib/socket/socket_common.h diff --git a/lib/socket/socket_common.h b/lib/socket/socket_common.h new file mode 100644 index 000000000000..e81dac78837a --- /dev/null +++ b/lib/socket/socket_common.h @@ -0,0 +1,33 @@ +/* +Unix SMB/CIFS implementation. + +Common socket definitions and default values. + +Copyright (C) Andrew Tridgell 1992-1998 +Copyright (C) Luke Kenneth Casson Leighton 1996-1998 +Copyright (C) Jeremy Allison 1998 + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program. If not, see . +*/ + +#ifndef _SOCKET_COMMON_H +#define _SOCKET_COMMON_H + + +/* default socket connection timeouts */ +#define LONG_CONNECT_TIMEOUT_MS (30 * 1000) +#define SHORT_CONNECT_TIMEOUT_MS (5 * 1000) + + +#endif /* _SOCKET_COMMON_H */ diff --git a/source3/include/local.h b/source3/include/local.h index 7f97d4ece9c7..72ef293c4ad0 100644 --- a/source3/include/local.h +++ b/source3/include/local.h @@ -5,6 +5,8 @@ #ifndef _LOCAL_H #define _LOCAL_H +#include "lib/socket/socket_common.h" + /* Yves Gaige requested this set this */ /* to a maximum of 8 if old smb clients break because of long printer names. */ #define MAXPRINTERLEN 15 @@ -122,10 +124,6 @@ /* shall we support browse requests via a FIFO to nmbd? */ #define ENABLE_FIFO 1 -/* how long (in miliseconds) to wait for a socket connect to happen */ -#define LONG_CONNECT_TIMEOUT 30000 -#define SHORT_CONNECT_TIMEOUT 5000 - /* the default netbios keepalive timeout */ #define DEFAULT_KEEPALIVE 300 @@ -193,7 +191,7 @@ #define INVALID_SHARENAME_CHARS "%<>*?|/\\+=;:\"," /* Seconds between connection attempts to a remote server. */ -#define FAILED_CONNECTION_CACHE_TIMEOUT (LONG_CONNECT_TIMEOUT * 2 / 1000) +#define FAILED_CONNECTION_CACHE_TIMEOUT (LONG_CONNECT_TIMEOUT_MS * 2 / 1000) /* Default hash size for the winbindd cache. */ #define WINBINDD_CACHE_TDB_DEFAULT_HASH_SIZE 5000 diff --git a/source3/utils/smbfilter.c b/source3/utils/smbfilter.c index 9b871beda8e0..a54513d31370 100644 --- a/source3/utils/smbfilter.c +++ b/source3/utils/smbfilter.c @@ -23,6 +23,7 @@ #include "../lib/util/select.h" #include "libsmb/nmblib.h" #include "lib/sys_rw_data.h" +#include "lib/socket/socket_common.h" #define SECURITY_MASK 0 #define SECURITY_SET 0 @@ -182,7 +183,7 @@ static void filter_child(int c, struct sockaddr_storage *dest_ss) char packet[128*1024]; /* we have a connection from a new client, now connect to the server */ - status = open_socket_out(dest_ss, TCP_SMB_PORT, LONG_CONNECT_TIMEOUT, &s); + status = open_socket_out(dest_ss, TCP_SMB_PORT, LONG_CONNECT_TIMEOUT_MS, &s); if (!NT_STATUS_IS_OK(status)) { char addr[INET6_ADDRSTRLEN]; if (dest_ss) { diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 1959a933dde0..f49088093568 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -28,6 +28,7 @@ #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" #include "lib/socket/socket.h" +#include "lib/socket/socket_common.h" #include "libcli/resolve/resolve.h" #include "param/param.h" #include "libcli/raw/raw_proto.h" @@ -298,7 +299,7 @@ static struct tevent_req *smbcli_sock_establish_send(TALLOC_CTX *mem_ctx, struct sock_connect_state *state = talloc_get_type_abort(private_data, struct sock_connect_state); - uint32_t timeout_msec = 15 * 1000; + uint32_t timeout_msec = LONG_CONNECT_TIMEOUT_MS; return smbcli_transport_connect_send(state, ev,