[Spread-cvs] cvs commit: spread/daemon Readme.txt TODO config_gram.l config_parse.y configuration.c configuration.h data_link.c sample.spread.conf session.c
jonathan at spread.org
jonathan at spread.org
Mon Aug 26 21:10:53 EDT 2002
jonathan 02/08/27 01:10:53
Modified: daemon Readme.txt TODO config_gram.l config_parse.y
configuration.c configuration.h data_link.c
sample.spread.conf session.c
Log:
Apply Daniel Rall's SO_REUSEADDR patch from April.
The only changes were to improve an Alarm in datalink when a bind fails.
Tested on Linux and works.
Revision Changes Path
1.19 +9 -0 spread/daemon/Readme.txt
Index: Readme.txt
===================================================================
RCS file: /storage/cvsroot/spread/daemon/Readme.txt,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -r1.18 -r1.19
--- Readme.txt 26 Aug 2002 22:57:41 -0000 1.18
+++ Readme.txt 27 Aug 2002 01:10:52 -0000 1.19
@@ -42,6 +42,15 @@
XXX X, 2002 Ver 3.17.0
----------------------
+Features:
+*) Apply Daniel Rall's SO_REUSEADDR patch. This adds a new configuration
+ option SocketPortReuse that can either force SO_REUSEADDR on or off
+ for TCP server sockets, or set it to an auto mode that uses REUSEADDR
+ if specific interfaces are specified in the spread.conf file and
+ does not use it if the default of INADDR_ANY is used. If you force
+ this on, be aware that it can open up a security risk where other
+ processes can steal Spread's traffic.
+
Bugfixes:
*) Make sure service_type is set to 0 before using it in SP_receive calls
in sample programs (spuser, spflooder, simple_user).
1.14 +0 -1 spread/daemon/TODO
Index: TODO
===================================================================
RCS file: /storage/cvsroot/spread/daemon/TODO,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- TODO 26 Aug 2002 23:35:15 -0000 1.13
+++ TODO 27 Aug 2002 01:10:52 -0000 1.14
@@ -1,7 +1,6 @@
Features, ideas, and other things that might get done.
Those ending with (*break) break binary,source or client-server compatability
------------------------------------------------------
-* Improve REUSEADR_handling
* Allow entire class C subnet to be in config file--as long as no more then 128 are active.
* Improve stability under high load
done * Add better error checks to f* functions in log.c
1.2 +1 -0 spread/daemon/config_gram.l
Index: config_gram.l
===================================================================
RCS file: /storage/cvsroot/spread/daemon/config_gram.l,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- config_gram.l 21 Aug 2001 14:28:21 -0000 1.1
+++ config_gram.l 27 Aug 2002 01:10:52 -0000 1.2
@@ -76,6 +76,7 @@
EventTimeStamp { return EVENTTIMESTAMP; }
DebugFlags { return DEBUGFLAGS; }
DangerousMonitor { return DANGEROUSMONITOR; }
+SocketPortReuse { return SOCKETPORTREUSE; }
RequiredAuthMethods { return REQUIREDAUTHMETHODS; }
AllowedAuthMethods { return ALLOWEDAUTHMETHODS; }
AccessControlPolicy { return ACCESSCONTROLPOLICY; }
1.2 +21 -1 spread/daemon/config_parse.y
Index: config_parse.y
===================================================================
RCS file: /storage/cvsroot/spread/daemon/config_parse.y,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- config_parse.y 21 Aug 2001 14:28:21 -0000 1.1
+++ config_parse.y 27 Aug 2002 01:10:52 -0000 1.2
@@ -187,7 +187,7 @@
%token DDEBUG DEXIT DPRINT DDATA_LINK DNETWORK DPROTOCOL DSESSION
%token DCONF DMEMB DFLOW_CONTROL DSTATUS DEVENTS DGROUPS DMEMORY
%token DSKIPLIST DACM DALL DNONE
-%token DANGEROUSMONITOR ALLOWEDAUTHMETHODS REQUIREDAUTHMETHODS ACCESSCONTROLPOLICY
+%token DANGEROUSMONITOR SOCKETPORTREUSE ALLOWEDAUTHMETHODS REQUIREDAUTHMETHODS ACCESSCONTROLPOLICY
%token SP_BOOL LINKPROTOCOL PHOP PTCPHOP
%token IMONITOR ICLIENT IDAEMON
%token ROUTEMATRIX LINKCOST
@@ -271,6 +271,26 @@
Conf_set_dangerous_monitor_state($3.boolean);
}
}
+ | SOCKETPORTREUSE EQUALS STRING
+ {
+ port_reuse state;
+ char option[5];
+ strncpy(option, $3.string, 5);
+ if (strcasecmp(option, "on") == 0)
+ {
+ state = port_reuse_on;
+ }
+ else if (strcasecmp(option, "off") == 0)
+ {
+ state = port_reuse_off;
+ }
+ else
+ {
+ /* Default to AUTO. */
+ state = port_reuse_auto;
+ }
+ Conf_set_port_reuse_type(state);
+ }
| ALLOWEDAUTHMETHODS EQUALS STRING
{
char auth_list[MAX_AUTH_LIST_LEN];
1.3 +28 -1 spread/daemon/configuration.c
Index: configuration.c
===================================================================
RCS file: /storage/cvsroot/spread/daemon/configuration.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- configuration.c 3 Feb 2002 21:08:48 -0000 1.2
+++ configuration.c 27 Aug 2002 01:10:52 -0000 1.3
@@ -86,8 +86,10 @@
* False means to ignore requests for those actions. THIS IS THE SAFE SETTING
*/
static bool EnableDangerousMonitor = FALSE;
-static int Link_Protocol;
+static port_reuse SocketPortReuse = port_reuse_auto;
+
+static int Link_Protocol;
int Conf_init( char *file_name, char *my_name )
{
@@ -519,4 +521,29 @@
return;
}
EnableDangerousMonitor = new_state;
+}
+
+port_reuse Conf_get_port_reuse_type(void)
+{
+ return(SocketPortReuse);
+}
+
+void Conf_set_port_reuse_type(port_reuse state)
+{
+ switch (state)
+ {
+ case port_reuse_auto:
+ Alarm(PRINT, "Setting SO_REUSEADDR to auto\n");
+ break;
+ case port_reuse_on:
+ Alarm(PRINT, "Setting SO_REUSEADDR to always on -- make sure Spread daemon host is secured!\n");
+ break;
+ case port_reuse_off:
+ Alarm(PRINT, "Setting SO_REUSEADDR to always off\n");
+ break;
+ default:
+ /* Inavlid type -- ignored */
+ return;
+ }
+ SocketPortReuse = state;
}
1.2 +8 -0 spread/daemon/configuration.h
Index: configuration.h
===================================================================
RCS file: /storage/cvsroot/spread/daemon/configuration.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- configuration.h 21 Aug 2001 14:28:21 -0000 1.1
+++ configuration.h 27 Aug 2002 01:10:52 -0000 1.2
@@ -77,6 +77,12 @@
segment segments[MAX_SEGMENTS];
} configuration;
+typedef enum dummy_port_reuse {
+ port_reuse_auto,
+ port_reuse_on,
+ port_reuse_off
+} port_reuse;
+
int Conf_init( char *file_name, char *my_name );
configuration Conf(void);
proc Conf_my(void);
@@ -96,6 +102,8 @@
bool Conf_get_dangerous_monitor_state(void);
void Conf_set_dangerous_monitor_state(bool new_state);
+port_reuse Conf_get_port_reuse_type(void);
+void Conf_set_port_reuse_type(port_reuse state);
int Conf_get_link_protocol(void);
void Conf_set_link_protocol(int protocol);
1.6 +1 -2 spread/daemon/data_link.c
Index: data_link.c
===================================================================
RCS file: /storage/cvsroot/spread/daemon/data_link.c,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- data_link.c 5 Feb 2002 02:37:39 -0000 1.5
+++ data_link.c 27 Aug 2002 01:10:52 -0000 1.6
@@ -101,8 +101,7 @@
if(bind( chan, (struct sockaddr *) &soc_addr,
sizeof(soc_addr)) == -1)
{
- Alarm( PRINT, "DL_init_channel: bind error for port %d, already running \n",port);
- exit(0);
+ Alarm( EXIT, "DL_init_channel: bind error (%d): %s for port %d, with sockaddr (%d.%d.%d.%d: %d) probably already running \n", sock_errno, sock_strerror(sock_errno), port, IP1(soc_addr.sin_addr.s_addr),IP2(soc_addr.sin_addr.s_addr),IP3(soc_addr.sin_addr.s_addr),IP4(soc_addr.sin_addr.s_addr), soc_addr.sin_port );
}
Alarm( DATA_LINK, "DL_init_channel: bind for recv_channel for port %d with chan %d ok\n",
port, chan);
1.3 +12 -0 spread/daemon/sample.spread.conf
Index: sample.spread.conf
===================================================================
RCS file: /storage/cvsroot/spread/daemon/sample.spread.conf,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- sample.spread.conf 31 Aug 2001 03:03:59 -0000 1.2
+++ sample.spread.conf 27 Aug 2002 01:10:52 -0000 1.3
@@ -74,6 +74,18 @@
#DangerousMonitor = false
+#Set handling of SO_REUSEADDR socket option for the daemon's TCP
+# listener. This is useful for facilitating quick daemon restarts (OSes
+# often hold onto the interface/port combination for a short period of time
+# after daemon shut down).
+#
+# AUTO - Active when bound to specific interfaces (default).
+# ON - Always active, regardless of interface.
+# SECURITY RISK FOR ANY OS WHICH ALLOW DOUBLE BINDS BY DIFFERENT USERS
+# OFF - Always off.
+
+#SocketPortReuse = AUTO
+
#Set the list of authentication methods that the daemon will allow
# and those which are required in all cases.
# All of the methods listed in "RequiredAuthMethods" will be checked,
1.8 +14 -0 spread/daemon/session.c
Index: session.c
===================================================================
RCS file: /storage/cvsroot/spread/daemon/session.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -r1.7 -r1.8
--- session.c 5 Feb 2002 02:37:39 -0000 1.7
+++ session.c 27 Aug 2002 01:10:52 -0000 1.8
@@ -118,6 +118,12 @@
static void Sess_create_reject_message ( message_obj *msg );
static int Sess_get_p2p_dests( int num_groups, char groups[][MAX_GROUP_NAME], char dests[][MAX_GROUP_NAME] );
+#define ACTIVATE_PORT_REUSE(mbox) do { \
+ int on = 1; \
+ if (setsockopt(mbox, SOL_SOCKET, SO_REUSEADDR, (void *) &on, sizeof(on)) < 0) \
+ Alarm( EXIT, "Sess_init: Error setting SO_REUSEADDR socket option\n" ); \
+} while (0)
+
int Sess_get_session_index (int mbox)
{
session *tmp;
@@ -356,13 +362,21 @@
{
if (Is_IfType_Client(My.ifc[i].type) || Is_IfType_Any(My.ifc[i].type) )
{
+ port_reuse type;
if( (mbox = socket( AF_INET, SOCK_STREAM, 0 ) ) == -1)
Alarm( EXIT, "Sess_init: INET sock error\n" );
+ type = Conf_get_port_reuse_type();
+ if (type == port_reuse_on)
+ ACTIVATE_PORT_REUSE(mbox);
if (Is_IfType_Any(My.ifc[i].type) )
inet_addr.sin_addr.s_addr = INADDR_ANY;
else
+ {
+ if (type == port_reuse_auto)
+ ACTIVATE_PORT_REUSE(mbox);
inet_addr.sin_addr.s_addr = htonl(My.ifc[i].ip);
+ }
if( bind( mbox, (struct sockaddr *)&inet_addr, sizeof(inet_addr) ) == -1)
{
Alarm( PRINT, "Sess_init: INET unable to bind to port %d, already running \n" ,port );
More information about the Spread-cvs
mailing list