Browse code

sctp: fix partial delivery point setting on linux

To disable partial delivery, the partial delivery point should be
set to the socket receive buffer size. However on linux SO_RCVBUF
will return twice the value (the "real" value, which is twice the
value used when setting SO_RCVBUF) and SCTP_PARTIAL_DELIVERY_POINT
expects value/2.

Andrei Pelinescu-Onciul authored on 21/05/2009 15:24:57
Showing 1 changed files
... ...
@@ -195,6 +195,8 @@ static int sctp_init_sock_opt_common(int s)
195 195
 {
196 196
 	struct sctp_event_subscribe es;
197 197
 	int optval;
198
+	int pd_point;
199
+	int saved_errno;
198 200
 	socklen_t optlen;
199 201
 	int sctp_err;
200 202
 	
... ...
@@ -267,13 +269,34 @@ static int sctp_init_sock_opt_common(int s)
267 267
 		/* try to continue */
268 268
 		optval=0;
269 269
 	}
270
-	if (setsockopt(s, IPPROTO_SCTP, SCTP_PARTIAL_DELIVERY_POINT,
271
-					(void*)&optval, sizeof(optval)) ==-1){
272
-		LOG(L_ERR, "ERROR: sctp_init_sock_opt_common: setsockopt: "
270
+#ifdef __OS_linux
271
+	optval/=2; /* in linux getsockopt() returns twice the set value */
272
+#endif
273
+	pd_point=optval;
274
+	saved_errno=0;
275
+	while(pd_point &&
276
+			setsockopt(s, IPPROTO_SCTP, SCTP_PARTIAL_DELIVERY_POINT,
277
+					(void*)&pd_point, sizeof(pd_point)) ==-1){
278
+		if (!saved_errno)
279
+			saved_errno=errno;
280
+		pd_point--;
281
+	}
282
+	
283
+	if (pd_point!=optval){
284
+		if (pd_point==0){
285
+			/* all attempts failed */
286
+			LOG(L_ERR, "ERROR: sctp_init_sock_opt_common: setsockopt: "
273 287
 						"SCTP_PARTIAL_DELIVERY_POINT (%d): %s\n",
274 288
 						optval, strerror(errno));
275
-		sctp_err++;
276
-		/* try to continue */
289
+			sctp_err++;
290
+			/* try to continue */
291
+		}else{
292
+			/* success but to a lower value (might not be disabled) */
293
+			LOG(L_WARN, "setsockopt SCTP_PARTIAL_DELIVERY_POINT set to %d, but"
294
+				" the socket rcvbuf is %d (higher values fail with"
295
+				" \"%s\" [%d])\n",
296
+				pd_point, optval, strerror(saved_errno), saved_errno);
297
+		}
277 298
 	}
278 299
 #else
279 300
 #warning no sctp lib support for SCTP_PARTIAL_DELIVERY_POINT, consider upgrading