Browse code

core: attempt harder to filter loopback addresses

- on startup detect not only loopback interfaces (e.g. -l lo) but also
ipv4 and ipv6 loopback addresses (e.g. 127.0.0.1, ::1). This helps filtering
them out when choosing the default socket for each of the protocols.

Andrei Pelinescu-Onciul authored on 16/10/2008 15:17:44
Showing 3 changed files
... ...
@@ -190,7 +190,7 @@ int is_mcast(struct ip_addr* ip)
190 190
 		return IN_MULTICAST(htonl(ip->u.addr32[0]));
191 191
 #ifdef USE_IPV6
192 192
 	} else if (ip->af==AF_INET6){
193
-		return IN6_IS_ADDR_MULTICAST((struct in6_addr *)ip->u.addr);
193
+		return IN6_IS_ADDR_MULTICAST((struct in6_addr *)&ip->u.addr);
194 194
 #endif /* USE_IPV6 */
195 195
 	} else {
196 196
 		LOG(L_ERR, "ERROR: is_mcast: Unsupported protocol family\n");
... ...
@@ -234,6 +234,21 @@ inline static int ip_addr_any(struct ip_addr* ip)
234 234
 
235 235
 
236 236
 
237
+/* returns 1 if the given ip address is a loopback address
238
+ * 0 otherwise */
239
+inline static int ip_addr_loopback(struct ip_addr* ip)
240
+{
241
+	if (ip->af==AF_INET){
242
+		return ip->u.addr32[0]==htonl(INADDR_LOOPBACK);
243
+#ifdef USE_IPV6
244
+	} else if (ip->af==AF_INET6)
245
+		return IN6_IS_ADDR_LOOPBACK((struct in6_addr *)&ip->u.addr32);
246
+#endif /* USE_IPV6 */
247
+	return 0;
248
+}
249
+
250
+
251
+
237 252
 /* creates an ANY ip_addr (filled with 0, af and len properly set) */
238 253
 inline static void ip_addr_mk_any(int af, struct ip_addr* ip)
239 254
 {
... ...
@@ -849,6 +849,8 @@ static int fix_hostname(str* name, struct ip_addr* address, str* address_str,
849 849
 	/* check if INADDR_ANY */
850 850
 	if (ip_addr_any(address))
851 851
 		*flags|=SI_IS_ANY;
852
+	else if (ip_addr_loopback(address)) /* check for loopback */
853
+		*flags|=SI_IS_LO;
852 854
 	
853 855
 	return 0;
854 856
 error: