From: Greg Farnum Date: Mon, 25 Oct 2021 19:53:04 +0000 (+0000) Subject: msg: common: allow entity_addr_t to store a CIDR address range X-Git-Tag: v17.2.1~15^2~24 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=741170536d90b09e2dd67e0aa84efb6432b102c0;p=ceph.git 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) --- diff --git a/src/msg/msg_types.h b/src/msg/msg_types.h index 9c92188734465..6e0ee1261de4d 100644 --- a/src/msg/msg_types.h +++ b/src/msg/msg_types.h @@ -197,7 +197,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 { @@ -205,6 +207,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) { @@ -213,6 +216,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 "???"; } }; @@ -245,6 +249,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; }