]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
msg: common: allow entity_addr_t to store a CIDR address range
authorGreg Farnum <gfarnum@redhat.com>
Mon, 25 Oct 2021 19:53:04 +0000 (19:53 +0000)
committerGreg Farnum <gfarnum@redhat.com>
Tue, 31 May 2022 23:28:48 +0000 (23:28 +0000)
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 <gfarnum@redhat.com>
(cherry picked from commit 8941450ff17336b0ed60947e365a8bffcc4a32b0)

src/msg/msg_types.h

index 77c9fcaab8fda6321ceee3602f00ce35c9960b3f..68967db3b43d37d1dc88a8ddd4ab42204a1a98d3 100644 (file)
@@ -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; }