Steven Dake pisze:
My take on this is that totemsrp swabs the nodeid when it receives the message in a cross endian system, and delivers the byte swabbed nodeid to cpg. When autogeneration of node ids is used, you may expect that the node id is the 32 bit ip address in network byte order. Instead the node id is autogenerated in host byte order.

We could ensure that the autogenerated node ids are always in little endian format (ie: swab them on big endian architectures) rather then a mix of little and big endian as is the case now in cross endian systems which makes understanding the content of the autogenerated nodeid impossible (and provides a possible collision of nodeids in an ipv4 network).

Try this patch. If this doesn't solve it, a swab may be required in testcpg -i operations on BE arches.
your patch + corrected typo + changes in testcpg -i on BE = OK
See attached patch.
I could be entirely wrong about all this though. I'm not sure whether the node id is in BE or LE when generated. Whatever it is now, we can't swab during creation on LE architectures because to date LE has been our main focus and it would cause all sorts of compatibility breakage.
I'm working on project where we had to take exactly the same decision :(.
We put client ip in int which was automaticly converted by protocol and woke up too late...

Regards,
Wojtek

Index: test/testcpg.c
===================================================================
--- test/testcpg.c      (wersja 2374)
+++ test/testcpg.c      (kopia robocza)
@@ -48,6 +48,7 @@
 
 #include <corosync/corotypes.h>
 #include <corosync/cpg.h>
+#include <corosync/swab.h>
 
 static int quit = 0;
 static int show_ip = 0;
@@ -61,6 +62,24 @@
        }
 }
 
+static char * FormatNode(unsigned int nodeid,int pid) {
+       static char buffer[100];
+       if (show_ip) {
+               struct in_addr saddr;
+#if __BYTE_ORDER == __BIG_ENDIAN
+               saddr.s_addr = swab32(nodeid);
+#else
+               saddr.s_addr = nodeid;
+#endif
+               sprintf(buffer, "node/pid %s/%d", inet_ntoa(saddr),pid);
+       } 
+       else {
+               sprintf(buffer, "node/pid %d/%d", nodeid, pid);
+       } 
+       return buffer;
+}
+
+
 static void DeliverCallback (
        cpg_handle_t handle,
        const struct cpg_name *groupName,
@@ -69,18 +88,9 @@
        void *msg,
        size_t msg_len)
 {
-       if (show_ip) {
-               struct in_addr saddr;
-               saddr.s_addr = nodeid;
-               printf("DeliverCallback: message (len=%lu)from node/pid %s/%d: 
'%s'\n",
-                      (unsigned long int) msg_len,
-                      inet_ntoa(saddr), pid, (const char *)msg);
-       }
-       else {
-               printf("DeliverCallback: message (len=%lu)from node/pid %d/%d: 
'%s'\n",
-                      (unsigned long int) msg_len, nodeid, pid,
+       printf("DeliverCallback: message (len=%lu)from %s: '%s'\n",
+                      (unsigned long int) msg_len, FormatNode(nodeid, pid),
                       (const char *)msg);
-       }
 }
 
 static void ConfchgCallback (
@@ -91,51 +101,27 @@
        const struct cpg_address *joined_list, size_t joined_list_entries)
 {
        int i;
-       struct in_addr saddr;
 
        printf("\nConfchgCallback: group '");
        print_cpgname(groupName);
        printf("'\n");
        for (i=0; i<joined_list_entries; i++) {
-               if (show_ip) {
-                       saddr.s_addr = joined_list[i].nodeid;
-                       printf("joined node/pid: %s/%d reason: %d\n",
-                              inet_ntoa (saddr), joined_list[i].pid,
-                              joined_list[i].reason);
-               }
-               else {
-                       printf("joined node/pid: %d/%d reason: %d\n",
-                              joined_list[i].nodeid, joined_list[i].pid,
-                              joined_list[i].reason);
-               }
+               printf("joined %s reason: %d\n",
+                               FormatNode(joined_list[i].nodeid, 
joined_list[i].pid),
+                               joined_list[i].reason);
        }
 
        for (i=0; i<left_list_entries; i++) {
-               if (show_ip) {
-                       saddr.s_addr = left_list[i].nodeid;
-                       printf("left node/pid: %s/%d reason: %d\n",
-                              inet_ntoa (saddr), left_list[i].pid,
-                              left_list[i].reason);
-               }
-               else {
-                       printf("left node/pid: %d/%d reason: %d\n",
-                              left_list[i].nodeid, left_list[i].pid,
-                              left_list[i].reason);
-               }
+               printf("left %s reason: %d\n",
+                               FormatNode(left_list[i].nodeid, 
left_list[i].pid),
+                               left_list[i].reason);
        }
 
        printf("nodes in group now %lu\n",
               (unsigned long int) member_list_entries);
        for (i=0; i<member_list_entries; i++) {
-               if (show_ip) {
-                       saddr.s_addr = member_list[i].nodeid;
-                       printf("node/pid: %s/%d\n",
-                              inet_ntoa (saddr), member_list[i].pid);
-               }
-               else {
-                       printf("node/pid: %d/%d\n",
-                              member_list[i].nodeid, member_list[i].pid);
-               }
+               printf("%s\n",
+                               FormatNode(member_list[i].nodeid, 
member_list[i].pid));
        }
 
        /* Is it us??
Index: exec/totemip.c
===================================================================
--- exec/totemip.c      (wersja 2374)
+++ exec/totemip.c      (kopia robocza)
@@ -376,6 +376,9 @@
                         */
                        totemip_sockaddr_to_totemip_convert((struct 
sockaddr_storage *)sockaddr_in, boundto);
                        boundto->nodeid = sockaddr_in->sin_addr.s_addr;
+#if __BYTE_ORDER == __BIG_ENDIAN
+                       boundto->nodeid = swab32 (boundto->nodeid);
+#endif
 
                        if (ioctl(id_fd, SIOCGLIFFLAGS, &lifreq[i]) < 0) {
                                printf ("couldn't do ioctl\n");
@@ -614,6 +617,9 @@
        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;
                }
_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to