changeset 337:c53934b11609

Allow compilation of waaad without SCTP support (DISABLE_SCTP). Based on a patch by Chris Brody.
author Sebastien Decugis <sdecugis@nict.go.jp>
date Wed, 01 Apr 2009 11:15:06 +0900
parents c4a1499164a3
children be43a4344cf9
files waaad/CMakeLists.txt waaad/peer-cer_cea.c waaad/peer-client.c waaad/peer-internal.h waaad/peer-secini.c waaad/peer-server.c waaad/peer.c waaad/tests/testpeer.c waaad/tests/testrt.c waaad/waaad.y
diffstat 10 files changed, 73 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/waaad/CMakeLists.txt	Wed Apr 01 10:38:16 2009 +0900
+++ b/waaad/CMakeLists.txt	Wed Apr 01 11:15:06 2009 +0900
@@ -116,7 +116,7 @@
 		peer-expire.c peer-events.c
 		peer-in.c peer-out.c
 		peer-secini.c
-		peer-sctp.c peer-tcp.c
+		peer-tcp.c
 		peer-server.c peer-client.c
 		peer-cer_cea.c
 		peer-dwr_dwa.c
@@ -130,6 +130,13 @@
 		dispatch.h dispatch.c
 		security.h security.c
 	)
+IF(NOT DISABLE_SCTP)
+	SET(WAAAD_COMMON_SRC
+		${WAAAD_COMMON_SRC}
+		peer-sctp.c
+		)
+ENDIF(NOT DISABLE_SCTP)	
+	
 SET(WAAAD_COMMON_GEN_SRC
 		lex.waaad.c
 		waaad.tab.c
--- a/waaad/peer-cer_cea.c	Wed Apr 01 10:38:16 2009 +0900
+++ b/waaad/peer-cer_cea.c	Wed Apr 01 11:15:06 2009 +0900
@@ -124,6 +124,7 @@
 			}
 			break;
 			
+#ifndef DISABLE_SCTP
 			case IPPROTO_SCTP: /* In SCTP, we send all the declared endpoints... will probably need change! */
 			{
 				sSS * ss;
@@ -157,6 +158,7 @@
 				}
 			}
 			break;
+#endif /* DISABLE_SCTP */
 			
 			default: /* ??? */
 				TRACE_DEBUG(INFO, "Unsupported proto for peer %s", peer->p_diamid);
@@ -650,7 +652,8 @@
 				CHECK_FCT( msg_avp_add( *cea, MSG_BRW_LAST_CHILD, avp ) );
 			}
 			break;
-			
+
+#ifndef DISABLE_SCTP
 			case IPPROTO_SCTP: /* In SCTP, we send all the declared endpoints... will probably need change! */
 			{
 				sSS * ss;
@@ -684,6 +687,7 @@
 				}
 			}
 			break;
+#endif /* DISABLE_SCTP */
 			
 			default: /* ??? */
 				TRACE_DEBUG(INFO, "Unsupported proto for peer %s", peer->p_diamid);
--- a/waaad/peer-client.c	Wed Apr 01 10:38:16 2009 +0900
+++ b/waaad/peer-client.c	Wed Apr 01 11:15:06 2009 +0900
@@ -61,10 +61,12 @@
 	
 	/* Now attempt the connection... we'll succeed or be canceled */
 	switch (infos->pa_proto) {
+#ifndef DISABLE_SCTP
 		case IPPROTO_SCTP:
 			out = infos->pa_streams;
 			ret = _peer_sctp_connect( (sSA *) &infos->pa_ss, sSSlen(&infos->pa_ss), &sock, &out, &in );
 			break;
+#endif /* DISABLE_SCTP */
 			
 		case IPPROTO_TCP:
 			ret = _peer_tcp_connect( (sSA *) &infos->pa_ss, sSSlen(&infos->pa_ss), &sock );
--- a/waaad/peer-internal.h	Wed Apr 01 10:38:16 2009 +0900
+++ b/waaad/peer-internal.h	Wed Apr 01 11:15:06 2009 +0900
@@ -459,12 +459,32 @@
 int _peer_out_stop(_peer_t * peer);
 int _peer_out_sendmsg(_peer_t * peer, msg_t * msg);
 
+#ifndef DISABLE_SCTP
+
 int _peer_sctp_create_server( int * sock );
 int _peer_sctp_accept( int sock, int * new_sd, uint16_t *ostreams, uint16_t *istreams );
 int _peer_sctp_connect( const sSA *addr, socklen_t addrlen, int *sock, uint16_t *ostreams, uint16_t *istreams );
 ssize_t _peer_sctp_send(sec_session_t * sess, int *streamid, const void * data, size_t len);
 ssize_t _peer_sctp_recv(sec_session_t * sess, uint16_t * streamid, void ** data, size_t *len);
 
+#else /* DISABLE_SCTP */
+
+# ifndef IPPROTO_SCTP
+#  define IPPROTO_SCTP 132
+# endif /* IPPROTO_SCTP */
+
+ static inline ssize_t _peer_sctp_send(sec_session_t * sess, int *streamid, const void * data, size_t len)
+ {
+	TRACE_HERE();
+	return -1;
+ }
+ static inline ssize_t _peer_sctp_recv(sec_session_t * sess, uint16_t * streamid, void ** data, size_t *len)
+ {
+	TRACE_HERE();
+	return -1;
+ }
+#endif /* DISABLE_SCTP */
+
 int _peer_tcp_create_server( int * sock, sSA *addr, socklen_t salen );
 int _peer_tcp_connect( const sSA *addr, socklen_t addrlen, int *sock );
 ssize_t _peer_tcp_send( sec_session_t * sess, void *data, size_t len);
--- a/waaad/peer-secini.c	Wed Apr 01 10:38:16 2009 +0900
+++ b/waaad/peer-secini.c	Wed Apr 01 11:15:06 2009 +0900
@@ -70,10 +70,12 @@
 			case IPPROTO_TCP:
 				ret = (*session->cbs.tcp.send_data) (session, ((char *)data) + sent, length - sent);
 				break;
-				
+
+#ifndef DISABLE_SCTP				
 			case IPPROTO_SCTP:
 				ret = (*session->cbs.sctp.send_data) (session, &stream, ((char *)data) + sent, length - sent);
 				break;
+#endif /* DISABLE_SCTP */
 			
 			default:
 				TRACE_DEBUG(INFO, "Invalid proto");
@@ -154,6 +156,7 @@
 	return 0;
 }
 
+#ifndef DISABLE_SCTP
 /* Receive from a SCTP connection: the message boundaries are preserved, so we have very few to do here */
 static int _peer_secini_recv_sctp (sec_session_t * session, void ** data, size_t *length)
 {
@@ -171,6 +174,7 @@
 	TRACE_DEBUG(FULL, "Received a message of %d bytes on stream %d", *length, stream);
 	return 0;
 }
+#endif /* DISABLE_SCTP */
 
 /* We just receive the buffer on the connection object, and rebuild a message (boundaries are lost with TCP) */
 int _peer_secini_recv (sec_session_t * session, void ** ext_session, void ** data, size_t *length)
@@ -184,9 +188,11 @@
 			CHECK_FCT( _peer_secini_recv_tcp(session, data, length) );
 			break;
 
+#ifndef DISABLE_SCTP
 		case IPPROTO_SCTP:
 			CHECK_FCT( _peer_secini_recv_sctp(session, data, length) );
 			break;
+#endif /* DISABLE_SCTP */
 
 		default:
 			TRACE_DEBUG(INFO, "Invalid proto");
--- a/waaad/peer-server.c	Wed Apr 01 10:38:16 2009 +0900
+++ b/waaad/peer-server.c	Wed Apr 01 11:15:06 2009 +0900
@@ -387,11 +387,13 @@
 				/* we use a simple accept */
 				CHECK_SYS_DO(  ci->sock = accept(si->sock, NULL, NULL),  goto error  );
 				break;
-			
+
+#ifndef DISABLE_SCTP			
 			case IPPROTO_SCTP:
 				/* We use our wrapper */
 				CHECK_FCT_DO(  _peer_sctp_accept( si->sock, &ci->sock, &ci->ostr, &ci->istr ),  goto error  );
 				break;
+#endif /* DISABLE_SCTP */
 			
 			default:
 				assert(0);
@@ -459,7 +461,11 @@
 	TRACE_ENTRY( );
 	
 	/* First, count the number of sockets we will have to create, in addition to the SCTP one */
-	_psi_cnt = 1 /* sctp */ + _count_tcp_servers();
+	_psi_cnt = 0;
+#ifndef DISABLE_SCTP
+	_psi_cnt = 1; /* sctp */
+#endif /* DISABLE_SCTP */
+	_psi_cnt += _count_tcp_servers();
 	
 	/* Allocate the _psi array */
 	CHECK_MALLOC( _psi = calloc(_psi_cnt, sizeof(_peer_servinfo_t)) );
@@ -470,11 +476,13 @@
 		CHECK_POSIX(pthread_mutex_init(&_psi[i].climtx, NULL));
 	}
 	
+#ifndef DISABLE_SCTP
 	/* The first element is the SCTP server, create this one already */
 	_psi[0].proto = IPPROTO_SCTP;
 	CHECK_FCT(  _peer_sctp_create_server( &_psi[0].sock )  );
 	snprintf( &(_psi[0].servname[0]), DEBUG_NAME_LEN, "SCTP.Srv(%d)", _psi[0].sock);
 	i = 1;
+#endif /* DISABLE_SCTP */
 	
 	/* Now create the TCP servers */
 	if ( ! g_pconf->disable_tcp ) {
--- a/waaad/peer.c	Wed Apr 01 10:38:16 2009 +0900
+++ b/waaad/peer.c	Wed Apr 01 11:15:06 2009 +0900
@@ -156,7 +156,11 @@
 	CHECK_PARAMS(  diamid && len && data  );
 
 	/* Check the data */
+#ifdef DISABLE_SCTP
+	CHECK_PARAMS(  (data->pa_proto == IPPROTO_TCP)  );
+#else /* DISABLE_SCTP */
 	CHECK_PARAMS(  (data->pa_proto == IPPROTO_SCTP) || (data->pa_proto == IPPROTO_TCP)  );
+#endif /* DISABLE_SCTP */
 	
 	/* Create the diameter id string that will be saved */
 	CHECK_MALLOC(  di = (char *)malloc(len + 1)  );
--- a/waaad/tests/testpeer.c	Wed Apr 01 10:38:16 2009 +0900
+++ b/waaad/tests/testpeer.c	Wed Apr 01 11:15:06 2009 +0900
@@ -74,7 +74,11 @@
 		data.pa_proto = IPPROTO_TCP;
 		CHECK( 0, peer_add( p1, strlen(p1), &data ) );
 		
+#ifndef DISABLE_SCTP
 		data.pa_proto = IPPROTO_SCTP;
+#else /* DISABLE_SCTP */
+		data.pa_proto = IPPROTO_TCP;
+#endif /* DISABLE_SCTP */
 		data.pa_streams = 20;
 		CHECK( 0, peer_add( p2, strlen(p2), &data ) );
 		
--- a/waaad/tests/testrt.c	Wed Apr 01 10:38:16 2009 +0900
+++ b/waaad/tests/testrt.c	Wed Apr 01 11:15:06 2009 +0900
@@ -160,7 +160,11 @@
 		data.pa_proto = IPPROTO_TCP;
 		CHECK( 0, peer_add( p1, strlen(p1), &data ) );
 		
+#ifndef DISABLE_SCTP
 		data.pa_proto = IPPROTO_SCTP;
+#else /* DISABLE_SCTP */
+		data.pa_proto = IPPROTO_TCP;
+#endif /* DISABLE_SCTP */
 		data.pa_streams = 20;
 		CHECK( 0, peer_add( p2, strlen(p2), &data ) );
 		
--- a/waaad/waaad.y	Wed Apr 01 10:38:16 2009 +0900
+++ b/waaad/waaad.y	Wed Apr 01 11:15:06 2009 +0900
@@ -441,6 +441,9 @@
 gen_sctp_streams:	GEN_SCTP_STREAMS '=' gen_sctp_streams_val ';'
 			{
 				pconfig->pub.sctp_streams = $3;
+				#ifdef DISABLE_SCTP
+				log_error("*** Warning:\n\tThis daemon was compiled with DISABLE_SCTP option.\n\tThe number of streams will be ignored.\n");
+				#endif /* DISABLE_SCTP */
 			}
 			;
 			
@@ -707,6 +710,12 @@
 			
 peer_transport:		/* empty */
 			| PEER_TRANS_SCTP
+			{
+				#ifdef DISABLE_SCTP
+				yyerror(&yylloc, pconfig, "Transport is set to SCTP but this daemon was compiled with DISABLE_SCTP option.");
+				YYERROR;
+				#endif
+			}
 			| PEER_TRANS_TCP
 			{
 				if (pconfig->pub.disable_tcp) {
"Welcome to our mercurial repository"