Sfoglia il codice sorgente

Merge trunk revision 2409:
r2409 | asalkeld | 2009-09-09 11:55:17 -0700 (Wed, 09 Sep 2009) | 11 lines

don't return the ip address when the mask is not found

Currently totemip_copy (boundto,&ipaddr) is called even when the
required mask is not found.

This patch changes the behavior to only copy the ipaddr when the
mask is found.

The current behavior makes debugging an incorrect config really
confusing.



git-svn-id: http://svn.fedorahosted.org/svn/corosync/branches/flatiron@2456 fd59a12c-fef9-0310-b244-a6a79926bd2f

Steven Dake 16 anni fa
parent
commit
8ba9e75648
1 ha cambiato i file con 23 aggiunte e 21 eliminazioni
  1. 23 21
      exec/totemip.c

+ 23 - 21
exec/totemip.c

@@ -474,6 +474,7 @@ int totemip_iface_check(struct totem_ip_address *bindnet,
 			int mask_high_bit)
 {
 	int fd;
+	int res = -1;
 	struct {
                 struct nlmsghdr nlh;
                 struct rtgenmsg g;
@@ -591,17 +592,33 @@ int totemip_iface_check(struct totem_ip_address *bindnet,
 					/* SIOCGIFFLAGS needs an interface name */
 					status = ioctl(ioctl_fd, SIOCGIFNAME, &ifr);
 					status = ioctl(ioctl_fd, SIOCGIFFLAGS, &ifr);
+					close(ioctl_fd);
 					if (status) {
-						close(ioctl_fd);
-						close(fd);
-						return -1;
+						res = -1;
+						goto finished;
 					}
 
 					if (ifr.ifr_flags & IFF_UP)
 						*interface_up = 1;
 
 					*interface_num = ifa->ifa_index;
-					close(ioctl_fd);
+					/*
+					 * Mask 32nd bit off to workaround bugs in other peoples code
+					 * (if configuration requests it).
+					 */
+					if (ipaddr.family == AF_INET && ipaddr.nodeid == 0) {
+						unsigned int nodeid = 0;
+						memcpy (&nodeid, ipaddr.addr, sizeof (int));
+#if __BYTE_ORDER == __BIG_ENDIAN
+                                                nodeid = swab32 (nodeid);
+#endif
+						if (mask_high_bit) {
+							nodeid &= 0x7FFFFFFF;
+						}
+						ipaddr.nodeid = nodeid;
+					}
+					totemip_copy (boundto, &ipaddr);
+					res = 0;
 					goto finished;
 				}
 			}
@@ -609,24 +626,9 @@ int totemip_iface_check(struct totem_ip_address *bindnet,
 			h = NLMSG_NEXT(h, status);
 		}
 	}
+	res = -1; /* address not found */
 finished:
-	/*
-	 * Mask 32nd bit off to workaround bugs in other poeples code
-	 * if configuration requests it.
-	 */
-	if (ipaddr.family == AF_INET && ipaddr.nodeid == 0) {
-                unsigned int nodeid = 0;
-                memcpy (&nodeid, ipaddr.addr, sizeof (int));
-#if __BYTE_ORDER == __BIG_ENDIAN
-		nodeid = swab32 (nodeid);
-#endif
-		if (mask_high_bit) {
-                        nodeid &= 0x7FFFFFFF;
-		}
-                ipaddr.nodeid = nodeid;
-        }
-	totemip_copy (boundto, &ipaddr);
 	close(fd);
-	return 0;
+	return res;
 }
 #endif /* COROSYNC_LINUX */