Commit 66be646b authored by David Howells's avatar David Howells

afs: Sort address lists so that they are in logical ascending order

Sort address lists so that they are in logical ascending order rather than
being partially in ascending order of the BE representations of those
values.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
parent 4c19bbdc
...@@ -232,22 +232,23 @@ struct afs_addr_list *afs_dns_query(struct afs_cell *cell, time64_t *_expiry) ...@@ -232,22 +232,23 @@ struct afs_addr_list *afs_dns_query(struct afs_cell *cell, time64_t *_expiry)
*/ */
void afs_merge_fs_addr4(struct afs_addr_list *alist, __be32 xdr, u16 port) void afs_merge_fs_addr4(struct afs_addr_list *alist, __be32 xdr, u16 port)
{ {
struct sockaddr_in6 *a; struct sockaddr_in6 *p;
__be16 xport = htons(port); u32 addr = ntohl(xdr);
int i; int i;
if (alist->nr_addrs >= alist->max_addrs) if (alist->nr_addrs >= alist->max_addrs)
return; return;
for (i = 0; i < alist->nr_ipv4; i++) { for (i = 0; i < alist->nr_ipv4; i++) {
a = &alist->addrs[i].transport.sin6; struct sockaddr_in6 *a = &alist->addrs[i].transport.sin6;
if (xdr == a->sin6_addr.s6_addr32[3] && u32 a_addr = ntohl(a->sin6_addr.s6_addr32[3]);
xport == a->sin6_port) u16 a_port = ntohs(a->sin6_port);
if (addr == a_addr && port == a_port)
return; return;
if (xdr == a->sin6_addr.s6_addr32[3] && if (addr == a_addr && port < a_port)
(u16 __force)xport < (u16 __force)a->sin6_port)
break; break;
if ((u32 __force)xdr < (u32 __force)a->sin6_addr.s6_addr32[3]) if (addr < a_addr)
break; break;
} }
...@@ -256,12 +257,12 @@ void afs_merge_fs_addr4(struct afs_addr_list *alist, __be32 xdr, u16 port) ...@@ -256,12 +257,12 @@ void afs_merge_fs_addr4(struct afs_addr_list *alist, __be32 xdr, u16 port)
alist->addrs + i, alist->addrs + i,
sizeof(alist->addrs[0]) * (alist->nr_addrs - i)); sizeof(alist->addrs[0]) * (alist->nr_addrs - i));
a = &alist->addrs[i].transport.sin6; p = &alist->addrs[i].transport.sin6;
a->sin6_port = xport; p->sin6_port = htons(port);
a->sin6_addr.s6_addr32[0] = 0; p->sin6_addr.s6_addr32[0] = 0;
a->sin6_addr.s6_addr32[1] = 0; p->sin6_addr.s6_addr32[1] = 0;
a->sin6_addr.s6_addr32[2] = htonl(0xffff); p->sin6_addr.s6_addr32[2] = htonl(0xffff);
a->sin6_addr.s6_addr32[3] = xdr; p->sin6_addr.s6_addr32[3] = xdr;
alist->nr_ipv4++; alist->nr_ipv4++;
alist->nr_addrs++; alist->nr_addrs++;
} }
...@@ -271,21 +272,20 @@ void afs_merge_fs_addr4(struct afs_addr_list *alist, __be32 xdr, u16 port) ...@@ -271,21 +272,20 @@ void afs_merge_fs_addr4(struct afs_addr_list *alist, __be32 xdr, u16 port)
*/ */
void afs_merge_fs_addr6(struct afs_addr_list *alist, __be32 *xdr, u16 port) void afs_merge_fs_addr6(struct afs_addr_list *alist, __be32 *xdr, u16 port)
{ {
struct sockaddr_in6 *a; struct sockaddr_in6 *p;
__be16 xport = htons(port);
int i, diff; int i, diff;
if (alist->nr_addrs >= alist->max_addrs) if (alist->nr_addrs >= alist->max_addrs)
return; return;
for (i = alist->nr_ipv4; i < alist->nr_addrs; i++) { for (i = alist->nr_ipv4; i < alist->nr_addrs; i++) {
a = &alist->addrs[i].transport.sin6; struct sockaddr_in6 *a = &alist->addrs[i].transport.sin6;
u16 a_port = ntohs(a->sin6_port);
diff = memcmp(xdr, &a->sin6_addr, 16); diff = memcmp(xdr, &a->sin6_addr, 16);
if (diff == 0 && if (diff == 0 && port == a_port)
xport == a->sin6_port)
return; return;
if (diff == 0 && if (diff == 0 && port < a_port)
(u16 __force)xport < (u16 __force)a->sin6_port)
break; break;
if (diff < 0) if (diff < 0)
break; break;
...@@ -296,12 +296,9 @@ void afs_merge_fs_addr6(struct afs_addr_list *alist, __be32 *xdr, u16 port) ...@@ -296,12 +296,9 @@ void afs_merge_fs_addr6(struct afs_addr_list *alist, __be32 *xdr, u16 port)
alist->addrs + i, alist->addrs + i,
sizeof(alist->addrs[0]) * (alist->nr_addrs - i)); sizeof(alist->addrs[0]) * (alist->nr_addrs - i));
a = &alist->addrs[i].transport.sin6; p = &alist->addrs[i].transport.sin6;
a->sin6_port = xport; p->sin6_port = htons(port);
a->sin6_addr.s6_addr32[0] = xdr[0]; memcpy(&p->sin6_addr, xdr, 16);
a->sin6_addr.s6_addr32[1] = xdr[1];
a->sin6_addr.s6_addr32[2] = xdr[2];
a->sin6_addr.s6_addr32[3] = xdr[3];
alist->nr_addrs++; alist->nr_addrs++;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment