sctp: added sctp_enable and sctp auto mode
authorAndrei Pelinescu-Onciul <andrei@iptel.org>
Tue, 7 Oct 2008 11:22:05 +0000 (11:22 +0000)
committerAndrei Pelinescu-Onciul <andrei@iptel.org>
Tue, 7 Oct 2008 11:22:05 +0000 (11:22 +0000)
- 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

NEWS
cfg.lex
cfg.y
main.c
sctp_server.c
sctp_server.h

diff --git a/NEWS b/NEWS
index 4a90b28..6320b01 100644 (file)
--- a/NEWS
+++ b/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
diff --git a/cfg.lex b/cfg.lex
index 72edf01..62abe43 100644 (file)
--- a/cfg.lex
+++ b/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;
diff --git a/cfg.y b/cfg.y
index ee37aba..757bbc8 100644 (file)
--- a/cfg.y
+++ b/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;
diff --git a/main.c b/main.c
index 5771811..e9802cf 100644 (file)
--- a/main.c
+++ b/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;
        }
index ff041f8..6ecda95 100644 (file)
 
 
 
+/* 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)
index cdead9f..13b6fd7 100644 (file)
@@ -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);