Browse Source

sctp: added sctp_enable and sctp auto mode

- added a new ser.cfg option: sctp_enable = 0|1|2. 0 means disable
 (equivalent with sctp_disable=yes), 1 enable (sctp_disable=no) and
  2 is auto mode (sctp enabled only if supported by the OS).
- sctp is now by default in auto enable mode: enabled if supported by the OS
Andrei Pelinescu-Onciul 17 years ago
parent
commit
c8e955874e
6 changed files with 47 additions and 3 deletions
  1. 3 1
      NEWS
  2. 2 0
      cfg.lex
  3. 9 0
      cfg.y
  4. 17 2
      main.c
  5. 15 0
      sctp_server.c
  6. 1 0
      sctp_server.h

+ 3 - 1
NEWS

@@ -220,7 +220,9 @@ core:
                between the short name and long name in cache as CNAME record
 
 new config variables:
-  disable_sctp = yes/no - diable sctp support
+  disable_sctp = yes/no - disable sctp support (default auto, see enable_sctp)
+  enable_sctp = 0/1/2  - disable (0)/enable (1)/auto (2) sctp support, 
+                         default auto (2)
   sctp_children = number - sctp children no (similar to udp children)
   sctp_socket_rcvbuf = number - size for the sctp socket receive buffer
   sctp_socket_sndbuf = number - size for the sctp socket send buffer

+ 2 - 0
cfg.lex

@@ -324,6 +324,7 @@ TLS_CA_LIST		"tls_ca_list"
 TLS_HANDSHAKE_TIMEOUT	"tls_handshake_timeout"
 TLS_SEND_TIMEOUT	"tls_send_timeout"
 DISABLE_SCTP	"disable_sctp"
+ENABLE_SCTP	"enable_sctp"
 SCTP_CHILDREN	"sctp_children"
 SCTP_SOCKET_RCVBUF	"sctp_socket_rcvbuf"|"sctp_socket_receive_buffer"
 SCTP_SOCKET_SNDBUF	"sctp_socket_sndbuf"|"sctp_socket_send_buffer"
@@ -634,6 +635,7 @@ EAT_ABLE	[\ \t\b\r]
 <INITIAL>{TLS_SEND_TIMEOUT}	{ count(); yylval.strval=yytext;
 										return TLS_SEND_TIMEOUT; }
 <INITIAL>{DISABLE_SCTP}	{ count(); yylval.strval=yytext; return DISABLE_SCTP;}
+<INITIAL>{ENABLE_SCTP}	{ count(); yylval.strval=yytext; return ENABLE_SCTP;}
 <INITIAL>{SCTP_CHILDREN}	{ count(); yylval.strval=yytext;
 										return SCTP_CHILDREN; }
 <INITIAL>{SCTP_SOCKET_RCVBUF}	{ count(); yylval.strval=yytext;

+ 9 - 0
cfg.y

@@ -380,6 +380,7 @@ static void free_socket_id_lst(struct socket_id* i);
 %token TLS_PRIVATE_KEY
 %token TLS_CA_LIST
 %token DISABLE_SCTP
+%token ENABLE_SCTP
 %token SCTP_CHILDREN
 %token SCTP_SOCKET_RCVBUF
 %token SCTP_SOCKET_SNDBUF
@@ -1093,6 +1094,14 @@ assign_stm:
 		#endif
 	}
 	| DISABLE_SCTP EQUAL error { yyerror("boolean value expected"); }
+	| ENABLE_SCTP EQUAL NUMBER {
+		#ifdef USE_SCTP
+			sctp_disable=($3<=1)?!$3:$3;
+		#else
+			warn("sctp support not compiled in");
+		#endif
+	}
+	| ENABLE_SCTP EQUAL error { yyerror("boolean or number expected"); }
 	| SCTP_CHILDREN EQUAL NUMBER {
 		#ifdef USE_SCTP
 			sctp_children_no=$3;

+ 17 - 2
main.c

@@ -221,7 +221,7 @@ Options:\n\
     -W           poll method\n"
 #endif
 #ifdef USE_SCTP
-"    -S           Disable sctp\n\
+"    -S           disable sctp\n\
     -O            Number of sctp child processes (default: equal to `-n')\n"
 #endif /* USE_SCTP */
 "    -V           Version number\n\
@@ -303,7 +303,7 @@ int tls_disable = 1;  /* tls disabled by default */
 #endif /* USE_TLS */
 #ifdef USE_SCTP
 int sctp_children_no = 0;
-int sctp_disable = 0; /* 1 if sctp is disabled */
+int sctp_disable = 2; /* 1 if sctp is disabled, 2 if auto mode, 0 enabled */
 #endif /* USE_SCTP */
 
 struct process_table *pt=0;		/*array with children pids, 0= main proc,
@@ -1819,6 +1819,21 @@ try_again:
 	}
 #endif
 #ifdef USE_SCTP
+	if (sctp_disable!=1){
+		/* fix it */
+		if (sctp_check_support()==-1){
+			/* check if sctp support is auto, if not warn about disabling it */
+			if (sctp_disable!=2){
+				fprintf(stderr, "ERROR: " "sctp enabled, but not supported by"
+								" the OS\n");
+				goto error;
+			}
+			sctp_disable=1;
+		}else{
+			/* sctp_disable!=1 and sctp supported => enable sctp */
+			sctp_disable=0;
+		}
+	}
 	if (!sctp_disable){
 		if (sctp_children_no<=0) sctp_children_no=children_no;
 	}

+ 15 - 0
sctp_server.c

@@ -52,6 +52,21 @@
 
 
 
+/* check if the underlying OS supports sctp
+   returns 0 if yes, -1 on error */
+int sctp_check_support()
+{
+	int s;
+	s = socket(PF_INET, SOCK_SEQPACKET, IPPROTO_SCTP);
+	if (s!=-1){
+		close(s);
+		return 0;
+	}
+	return -1;
+}
+
+
+
 /* init all the sockaddr_union members of the socket_info struct
    returns 0 on success and -1 on error */
 inline static int sctp_init_su(struct socket_info* sock_info)

+ 1 - 0
sctp_server.h

@@ -29,6 +29,7 @@
 
 #include "ip_addr.h"
 
+int sctp_check_support();
 int sctp_init_sock(struct socket_info* sock_info);
 int sctp_rcv_loop();
 int sctp_msg_send(struct dest_info* dst, char* buf, unsigned len);