From 4ce530be32c73f6cc0bff917a59ce5ffddc8255c Mon Sep 17 00:00:00 2001 From: Greg Farnum Date: Mon, 25 Oct 2021 19:53:04 +0000 Subject: [PATCH] msg: common: allow entity_addr_t to store a CIDR address range This required very little change to the existing code. Use with care, because existing code expects an IP address instead of a range, but it saves on writing a new parser. Signed-off-by: Greg Farnum (cherry picked from commit 8941450ff17336b0ed60947e365a8bffcc4a32b0) --- src/msg/msg_types.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/msg/msg_types.h b/src/msg/msg_types.h index 77c9fcaab8fda..68967db3b43d3 100644 --- a/src/msg/msg_types.h +++ b/src/msg/msg_types.h @@ -228,7 +228,9 @@ static inline void decode(sockaddr_storage& a, * an entity's network address. * includes a random value that prevents it from being reused. * thus identifies a particular process instance. - * ipv4 for now. + * + * This also happens to work to support cidr ranges, in which + * case the nonce contains the netmask. It's great! */ struct entity_addr_t { typedef enum { @@ -236,6 +238,7 @@ struct entity_addr_t { TYPE_LEGACY = 1, ///< legacy msgr1 protocol (ceph jewel and older) TYPE_MSGR2 = 2, ///< msgr2 protocol (new in ceph kraken) TYPE_ANY = 3, ///< ambiguous + TYPE_CIDR = 4, } type_t; static const type_t TYPE_DEFAULT = TYPE_MSGR2; static std::string_view get_type_name(int t) { @@ -244,6 +247,7 @@ struct entity_addr_t { case TYPE_LEGACY: return "v1"; case TYPE_MSGR2: return "v2"; case TYPE_ANY: return "any"; + case TYPE_CIDR: return "cidr"; default: return "???"; } }; @@ -276,6 +280,8 @@ struct entity_addr_t { bool is_legacy() const { return type == TYPE_LEGACY; } bool is_msgr2() const { return type == TYPE_MSGR2; } bool is_any() const { return type == TYPE_ANY; } + // this isn't a guarantee; some client addrs will match it + bool maybe_cidr() const { return get_port() == 0 && nonce != 0; } __u32 get_nonce() const { return nonce; } void set_nonce(__u32 n) { nonce = n; } -- 2.39.5