Skip to content

Commit 44be6fd

Browse files
committed
dlm: fix address compare
Compare only the addr and port fields of sockaddr structures. Fixes a problem with ipv6 where sin6_scope_id does not match. Signed-off-by: David Teigland <teigland@redhat.com>
1 parent c1dcf65 commit 44be6fd

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

‎fs/dlm/config.c‎

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#include <linux/kernel.h>
1515
#include <linux/module.h>
1616
#include <linux/configfs.h>
17+
#include <linux/in.h>
18+
#include <linux/in6.h>
19+
#include <net/ipv6.h>
1720
#include <net/sock.h>
1821

1922
#include "config.h"
@@ -776,6 +779,33 @@ static void put_space(struct dlm_space *sp)
776779
config_item_put(&sp->group.cg_item);
777780
}
778781

782+
static int addr_compare(struct sockaddr_storage *x, struct sockaddr_storage *y)
783+
{
784+
switch (x->ss_family) {
785+
case AF_INET: {
786+
struct sockaddr_in *sinx = (struct sockaddr_in *)x;
787+
struct sockaddr_in *siny = (struct sockaddr_in *)y;
788+
if (sinx->sin_addr.s_addr != siny->sin_addr.s_addr)
789+
return 0;
790+
if (sinx->sin_port != siny->sin_port)
791+
return 0;
792+
break;
793+
}
794+
case AF_INET6: {
795+
struct sockaddr_in6 *sinx = (struct sockaddr_in6 *)x;
796+
struct sockaddr_in6 *siny = (struct sockaddr_in6 *)y;
797+
if (!ipv6_addr_equal(&sinx->sin6_addr, &siny->sin6_addr))
798+
return 0;
799+
if (sinx->sin6_port != siny->sin6_port)
800+
return 0;
801+
break;
802+
}
803+
default:
804+
return 0;
805+
}
806+
return 1;
807+
}
808+
779809
static struct dlm_comm *get_comm(int nodeid, struct sockaddr_storage *addr)
780810
{
781811
struct config_item *i;
@@ -797,8 +827,7 @@ static struct dlm_comm *get_comm(int nodeid, struct sockaddr_storage *addr)
797827
config_item_get(i);
798828
break;
799829
} else {
800-
if (!cm->addr_count ||
801-
memcmp(cm->addr[0], addr, sizeof(*addr)))
830+
if (!cm->addr_count || !addr_compare(cm->addr[0], addr))
802831
continue;
803832
found = 1;
804833
config_item_get(i);

0 commit comments

Comments
 (0)