Browse code

ipv6: avoid using as default socket a loopback addr.

- prefer non-loopback and non-multicast addresses as default sockets for ipv6

Andrei Pelinescu-Onciul authored on 16/10/2008 18:02:50
Showing 1 changed files
... ...
@@ -1112,8 +1112,10 @@ int main_loop()
1112 1112
 		/* only one address, we ignore all the others */
1113 1113
 		if (udp_init(udp_listen)==-1) goto error;
1114 1114
 		bind_address=udp_listen;
1115
-		sendipv4=bind_address;
1116
-		sendipv6=bind_address; /*FIXME*/
1115
+		if (bind_address->address.af==AF_INET)
1116
+			sendipv4=bind_address;
1117
+		else
1118
+			sendipv6=bind_address;
1117 1119
 		if (udp_listen->next){
1118 1120
 			LOG(L_WARN, "WARNING: using only the first listen address"
1119 1121
 						" (no fork)\n");
... ...
@@ -1209,7 +1211,8 @@ int main_loop()
1209 1209
 					((sendipv4==0)||(sendipv4->flags&(SI_IS_LO|SI_IS_MCAST))))
1210 1210
 				sendipv4=si;
1211 1211
 	#ifdef USE_IPV6
1212
-			if((sendipv6==0)&&(si->address.af==AF_INET6))
1212
+			if ( ((sendipv6==0)||(sendipv6->flags&(SI_IS_LO|SI_IS_MCAST))) &&
1213
+					(si->address.af==AF_INET6))
1213 1214
 				sendipv6=si;
1214 1215
 	#endif
1215 1216
 		}
... ...
@@ -1218,12 +1221,14 @@ int main_loop()
1218 1218
 			for(si=sctp_listen; si; si=si->next){
1219 1219
 				if (sctp_init_sock(si)==-1)  goto error;
1220 1220
 				/* get first ipv4/ipv6 socket*/
1221
-				if ((si->address.af==AF_INET)&&
1222
-						((sendipv4_sctp==0)||
1223
-						 	(sendipv4_sctp->flags&(SI_IS_LO|SI_IS_MCAST))))
1221
+				if ((si->address.af==AF_INET) &&
1222
+						((sendipv4_sctp==0) ||
1223
+							(sendipv4_sctp->flags&(SI_IS_LO|SI_IS_MCAST))))
1224 1224
 					sendipv4_sctp=si;
1225 1225
 		#ifdef USE_IPV6
1226
-				if((sendipv6_sctp==0)&&(si->address.af==AF_INET6))
1226
+				if( ((sendipv6_sctp==0) || 
1227
+							(sendipv6_sctp->flags&(SI_IS_LO|SI_IS_MCAST))) &&
1228
+						(si->address.af==AF_INET6))
1227 1229
 					sendipv6_sctp=si;
1228 1230
 		#endif
1229 1231
 			}
... ...
@@ -1236,11 +1241,13 @@ int main_loop()
1236 1236
 				if (tcp_init(si)==-1)  goto error;
1237 1237
 				/* get first ipv4/ipv6 socket*/
1238 1238
 				if ((si->address.af==AF_INET)&&
1239
-						((sendipv4_tcp==0)||
1240
-						 	(sendipv4_tcp->flags&(SI_IS_LO|SI_IS_MCAST))))
1239
+						((sendipv4_tcp==0) ||
1240
+							(sendipv4_tcp->flags&(SI_IS_LO|SI_IS_MCAST))))
1241 1241
 					sendipv4_tcp=si;
1242 1242
 		#ifdef USE_IPV6
1243
-				if((sendipv6_tcp==0)&&(si->address.af==AF_INET6))
1243
+				if( ((sendipv6_tcp==0) ||
1244
+							(sendipv6_tcp->flags&(SI_IS_LO|SI_IS_MCAST))) &&
1245
+						(si->address.af==AF_INET6))
1244 1246
 					sendipv6_tcp=si;
1245 1247
 		#endif
1246 1248
 			}
... ...
@@ -1252,11 +1259,13 @@ int main_loop()
1252 1252
 				if (tls_init(si)==-1)  goto error;
1253 1253
 				/* get first ipv4/ipv6 socket*/
1254 1254
 				if ((si->address.af==AF_INET)&&
1255
-						((sendipv4_tls==0)||
1256
-						 	(sendipv4_tls->flags&(SI_IS_LO|SI_IS_MCAST))))
1255
+						((sendipv4_tls==0) ||
1256
+							(sendipv4_tls->flags&(SI_IS_LO|SI_IS_MCAST))))
1257 1257
 					sendipv4_tls=si;
1258 1258
 		#ifdef USE_IPV6
1259
-				if((sendipv6_tls==0)&&(si->address.af==AF_INET6))
1259
+				if( ((sendipv6_tls==0) ||
1260
+							(sendipv6_tls->flags&(SI_IS_LO|SI_IS_MCAST))) &&
1261
+						(si->address.af==AF_INET6))
1260 1262
 					sendipv6_tls=si;
1261 1263
 		#endif
1262 1264
 			}