changeset 332:436975f6ef4d

Fixed call to setsockopt(ASCONF) for SCTP under FreeBSD
author Sebastien Decugis <sdecugis@nict.go.jp>
date Tue, 31 Mar 2009 15:58:27 +0900
parents 91bba31a7706
children 70384e14ba9e
files waaad/peer-sctp.c
diffstat 1 files changed, 54 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/waaad/peer-sctp.c	Thu Mar 19 17:45:13 2009 +0900
+++ b/waaad/peer-sctp.c	Tue Mar 31 15:58:27 2009 +0900
@@ -53,7 +53,7 @@
 /*******************************************************************************************************/
 /* local functions */
 
-static int _sctp_setsockopt(int sk, uint16_t nstreams)
+static int _sctp_setsockopt_pre(int sk, uint16_t nstreams)
 {
 	#ifdef DEBUG_SCTP
 	socklen_t sz;
@@ -359,38 +359,6 @@
 	TRACE_DEBUG(FULL, "Skipping SCTP_FRAGMENT_INTERLEAVE");
 	#endif /* SCTP_FRAGMENT_INTERLEAVE */
 	
-	/* Set the ASCONF option */
-	#ifdef SCTP_AUTO_ASCONF
-	{
-		int asconf;
-		
-		#ifdef DEBUG_SCTP
-		sz = sizeof(asconf);
-		/* Read socket defaults */
-		CHECK_SYS(  getsockopt(sk, IPPROTO_SCTP, SCTP_AUTO_ASCONF, &asconf, &sz)  );
-		if (sz != sizeof(asconf))
-		{
-			TRACE_DEBUG(INFO, "Invalid size of socket option: %d / %d", sz, (socklen_t)sizeof(asconf));
-			return ENOTSUP;
-		}
-		TRACE_DEBUG(FULL, "Def SCTP_AUTO_ASCONF value : %s", asconf ? "true" : "false");
-		#endif /* DEBUG_SCTP */
-
-		asconf = 1;	/* allow automatic use of added or removed addresses in the association (for bound-all sockets) */
-		
-		/* Set the option to the socket */
-		CHECK_SYS(  setsockopt(sk, IPPROTO_SCTP, SCTP_AUTO_ASCONF, &asconf, sizeof(asconf))  );
-		
-		#ifdef DEBUG_SCTP
-		/* Check new values */
-		CHECK_SYS(  getsockopt(sk, IPPROTO_SCTP, SCTP_AUTO_ASCONF, &asconf, &sz)  );
-		TRACE_DEBUG(FULL, "New SCTP_AUTO_ASCONF value : %s", asconf ? "true" : "false");
-		#endif /* DEBUG_SCTP */
-	}
-	#else /* SCTP_AUTO_ASCONF */
-	TRACE_DEBUG(FULL, "Skipping SCTP_AUTO_ASCONF");
-	#endif /* SCTP_AUTO_ASCONF */
-	
 	/* Set the v4 mapped addresses option */
 	#ifdef SCTP_I_WANT_MAPPED_V4_ADDR
 	{
@@ -461,6 +429,52 @@
 	return 0;
 }	
 
+static int _sctp_setsockopt_post(int sk, int bound_all)
+{
+	#ifdef DEBUG_SCTP
+	socklen_t sz;
+	#endif /* DEBUG_SCTP */
+	
+	TRACE_ENTRY( "%d", sk);
+	
+	CHECK_PARAMS( (sk > 0) );
+	
+	/* Set the ASCONF option */
+	#ifdef SCTP_AUTO_ASCONF
+	if (bound_all) {
+		int asconf;
+		
+		#ifdef DEBUG_SCTP
+		sz = sizeof(asconf);
+		/* Read socket defaults */
+		CHECK_SYS(  getsockopt(sk, IPPROTO_SCTP, SCTP_AUTO_ASCONF, &asconf, &sz)  );
+		if (sz != sizeof(asconf))
+		{
+			TRACE_DEBUG(INFO, "Invalid size of socket option: %d / %d", sz, (socklen_t)sizeof(asconf));
+			return ENOTSUP;
+		}
+		TRACE_DEBUG(FULL, "Def SCTP_AUTO_ASCONF value : %s", asconf ? "true" : "false");
+		#endif /* DEBUG_SCTP */
+
+		asconf = 1;	/* allow automatic use of added or removed addresses in the association (for bound-all sockets) */
+		
+		/* Set the option to the socket */
+		CHECK_SYS(  setsockopt(sk, IPPROTO_SCTP, SCTP_AUTO_ASCONF, &asconf, sizeof(asconf))  );
+		
+		#ifdef DEBUG_SCTP
+		/* Check new values */
+		CHECK_SYS(  getsockopt(sk, IPPROTO_SCTP, SCTP_AUTO_ASCONF, &asconf, &sz)  );
+		TRACE_DEBUG(FULL, "New SCTP_AUTO_ASCONF value : %s", asconf ? "true" : "false");
+		#endif /* DEBUG_SCTP */
+	}
+	#else /* SCTP_AUTO_ASCONF */
+	TRACE_DEBUG(FULL, "Skipping SCTP_AUTO_ASCONF");
+	#endif /* SCTP_AUTO_ASCONF */
+	
+	return 0;
+}	
+	
+
 /* Read the list of bound addresses from a socket and save it to g_pconf->local_addr_sec_sa.
   Note that the local addresses (127.0.0.1, ::1) are not saved. */
 static int _sctp_getboundaddrs(int sk)
@@ -561,6 +575,7 @@
 {
 	int af;
 	int sk;
+	int bound_all = 0;
 	sSS * ss;
 	
 	TRACE_ENTRY("%p", sock);
@@ -576,7 +591,7 @@
 	CHECK_SYS( sk = socket(af, SOCK_STREAM, IPPROTO_SCTP) );
 	
 	/* Set the number of streams and other common options to the socket */
-	CHECK_FCT(  _sctp_setsockopt(sk, g_pconf->sctp_streams)  );
+	CHECK_FCT(  _sctp_setsockopt_pre(sk, g_pconf->sctp_streams)  );
 	
 	/* Now bind to all the requested addresses if specified, or default set otherwise */
 	if ((g_pconf->local_addr_pri_sa == NULL) && (g_pconf->local_addr_sec_sa == NULL)) {
@@ -594,6 +609,7 @@
 		CHECK_SYS(  bind(sk, (sSA *)&sin, sizeof(sin))  );
 		
 		/* And now save the list of addresses to which we are bound */
+		bound_all = 1;
 		CHECK_FCT(  _sctp_getboundaddrs(sk)  );
 	} else {
 		/* we have the list of addresses to bind to, use sctp_bindx */
@@ -736,6 +752,8 @@
 		TRACE_DEBUG(FULL, "SCTP socket created: %d", sk);
 	}
 	#endif /* DEBUG_SCTP */
+
+	CHECK_FCT(  _sctp_setsockopt_post(sk, bound_all)  );
 	
 	*sock = sk;
 	return 0;
@@ -842,13 +860,14 @@
 	CHECK_SYS(  sk = socket(af, SOCK_STREAM, IPPROTO_SCTP)  );
 	
 	/* Set the number of streams and other common options to the socket */
-	CHECK_FCT(  _sctp_setsockopt(sk, *ostreams)  );
+	CHECK_FCT(  _sctp_setsockopt_pre(sk, *ostreams)  );
 	
 	sSA_DUMP( FULL, "Connecting to SCTP server: ", addr );
 	
 	CHECK_SYS(  connect(sk, addr, addrlen)  );
 	
 	/* Now that we are connected, retrieve the number of streams */
+	CHECK_FCT(  _sctp_setsockopt_post(sk, 1)  );
 	
 	/* Read the association parameters */
 	memset(&status, 0, sizeof(status));
"Welcome to our mercurial repository"