net/ceph/messenger: support IPv6 Link-Local with scope identifier
PATCH v4 1/1 net/ceph/messenger: support IPv6 Link-Local with scope identifier
Implement ceph_pton() using inet_pton_with_scope(). This minimal patch preserves the ceph_pton() API and thus requires copying the parameter to a null-terminated string.
Since struct sockaddr_storage is part of the Ceph wire protocol and a non-zero scope id can break the memcmp() checks in the banner handlers, we need to clear all scope ids before using memcmp(). Therefore, this patch introduces the helper function ceph_addr_equal_no_scope().
---v1->v2:
- check "ipend" before dereferencing it
v2->v3:
- fix indentation
- use the caller's network namespace instead of init_ns
- stop parsing at the port separator
v3->v4:
- fall back to DNS only on EINVAL
- use GFP_KERNEL instead of GFP_NOFS
- ignore the IPv6 scope id when checking the banner peer address
--- include/linux/ceph/messenger.h | 6 ++++ net/ceph/messenger.c | 64 ++++++++++++++++++++++++++++------ net/ceph/messenger_v1.c | 3 +- net/ceph/messenger_v2.c | 2 +- 4 files changed, 62 insertions(+), 13 deletions(-)
include/linux/ceph/messenger.h +6 -0
@@ -570,6 +570,12 @@ bool ceph_con_v2_opened(struct ceph_connection *con);void ceph_con_v2_reset_session (struct ceph_connection *con);void ceph_con_v2_reset_protocol (struct ceph_connection *con); +/** +* Check whether the two addresses are equal, but ignore different +* IPv6 scope identifiers. +*/ +bool ceph_addr_equal_no_scope (const struct ceph_entity_addr *lhs, +const struct ceph_entity_addr *rhs);extern const char *ceph_pr_addr (const struct ceph_entity_addr *addr);
net/ceph/messenger.c +54 -10
86 lines not on this page · raw message
net/ceph/messenger_v1.c +1 -2
@@ -708,8 +708,7 @@ static int process_banner(struct ceph_connection *con)* end may not yet know their ip address, so if it's 0.0.0.0, give * them the benefit of the doubt. */ -if (memcmp (&con->peer_addr, &con->v1.actual_peer_addr, -sizeof (con->peer_addr)) !=0 && +if (!ceph_addr_equal_no_scope (&con->peer_addr, &con->v1.actual_peer_addr) && !(ceph_addr_is_blank (&con->v1.actual_peer_addr) && con->v1.actual_peer_addr.nonce == con->peer_addr.nonce)) { pr_warn("wrong peer, want %s/%u, got %s/%u\n",
net/ceph/messenger_v2.c +1 -1
@@ -2504,7 +2504,7 @@ static int process_server_ident(struct ceph_connection *con, global_id, global_seq, features, required_features, flags, cookie);/* is this who we intended to talk to? */ -if (memcmp (&addr, &con->peer_addr,sizeof (con->peer_addr))) { +if (!ceph_addr_equal_no_scope (&addr, &con->peer_addr)) { pr_err("bad peer addr/nonce, want %s/%u, got %s/%u\n", ceph_pr_addr(&con->peer_addr), le32_to_cpu(con->peer_addr.nonce),
Signature · 1 line
2.47.3
Alex Markuze
maintainerHi Max,
The core issue from v3 is still present: sin6_scope_id is a local ifindex and must not go on the wire. v4 adds ceph_addr_equal_no_scope() for banner comparisons, but peer_addr still carries the scope from inet_pton_with_scope() and gets encoded into the msgr2 HELLO and client-ident. A peer with scope 0 or a different ifindex will still fail identity checks.
v4 also introduces new issues: the monmap update path drops scope when installing decoded addresses, so reconnect to link-local monitors breaks after the first map; ceph_addr_equal_no_type() still memcmps full addresses including scope, breaking monmap lookup; and ceph_addr_clear_scope() does an unaligned write through a cast on a const-qualified pointer.
The fix needs a clean wire/local split: scope lives only in the sockaddr used for kernel_connect(), cleared in everything that touches wire identity.
--
Alex Markuze