Browse code

core: also set pmtu_discovery core parameter for IPv6, GH #3141

- also set pmtu_discovery core parameter for IPv6
- based on a patch from Rick van Rein <rick@openfortress.nl>
- probably to be extended further

Henning Westerholt authored on 14/08/2022 08:56:12
Showing 1 changed files
... ...
@@ -329,22 +329,45 @@ int udp_init(struct socket_info* sock_info)
329 329
 	}
330 330
 
331 331
 #if defined (__OS_linux) && defined(UDP_ERRORS)
332
+	/* Ask for the ability to recvmsg (...,MSG_ERRQUEUE) for immediate
333
+	 * resend when hitting Path MTU limits. */
332 334
 	optval=1;
333 335
 	/* enable error receiving on unconnected sockets */
334
-	if(setsockopt(sock_info->socket, SOL_IP, IP_RECVERR,
336
+	if (addr->s.sa_family==AF_INET){
337
+		if(setsockopt(sock_info->socket, SOL_IP, IP_RECVERR,
335 338
 					(void*)&optval, sizeof(optval)) ==-1){
336
-		LM_ERR("setsockopt: %s\n", strerror(errno));
337
-		goto error;
339
+			LM_ERR("setsockopt: %s\n", strerror(errno));
340
+			goto error;
341
+		}
342
+	} else if (addr->s.sa_family==AF_INET6){
343
+		if(setsockopt(sock_info->socket, SOL_IPV6, IPV6_RECVERR,
344
+					(void*)&optval, sizeof(optval)) ==-1){
345
+			LM_ERR("setsockopt: %s\n", strerror(errno));
346
+			goto error;
347
+		}
338 348
 	}
339 349
 #endif
340 350
 #if defined (__OS_linux)
341
-	/* if pmtu_discovery=1 then set DF bit and do Path MTU discovery
342
-	 * disabled by default */
343
-	optval= (pmtu_discovery) ? IP_PMTUDISC_DO : IP_PMTUDISC_DONT;
344
-	if(setsockopt(sock_info->socket, IPPROTO_IP, IP_MTU_DISCOVER,
345
-			(void*)&optval, sizeof(optval)) ==-1){
346
-		LM_ERR("setsockopt: %s\n", strerror(errno));
347
-		goto error;
351
+	if (addr->s.sa_family==AF_INET){
352
+		/* If pmtu_discovery=1 then set DF bit and do Path MTU discovery
353
+		 * disabled by default.  Specific to IPv4. */
354
+		optval= (pmtu_discovery) ? IP_PMTUDISC_DO : IP_PMTUDISC_DONT;
355
+		if(setsockopt(sock_info->socket, IPPROTO_IP, IP_MTU_DISCOVER,
356
+				(void*)&optval, sizeof(optval)) ==-1){
357
+			LM_ERR("setsockopt: %s\n", strerror(errno));
358
+			goto error;
359
+		}
360
+	} else if (addr->s.sa_family==AF_INET6){
361
+		/* IPv6 never fragments but sends ICMPv6 Packet too Big,
362
+		 * If pmtu_discovery=1 then set DF bit and do Path MTU discovery
363
+		 * disabled by default.  Specific to IPv6. */
364
+		optval= (pmtu_discovery) ? IPV6_PMTUDISC_DO : IPV6_PMTUDISC_DONT;
365
+		if(setsockopt(sock_info->socket, IPPROTO_IPV6,
366
+				IPV6_MTU_DISCOVER,
367
+				(void*)&optval, sizeof(optval)) ==-1){
368
+			LM_ERR("setsockopt: %s\n", strerror(errno));
369
+			goto error;
370
+		}
348 371
 	}
349 372
 #endif
350 373