rpc: add support for announcement tracking of uint16_t values

This will be used for the RPC port number.

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
1 files changed, 28 insertions(+), 5 deletions(-)

M rpc/announce-track.c
M rpc/announce-track.c +28 -5
@@ 205,6 205,32 @@ struct info_mapping {
 	size_t size;
 };
 
+static void __set_info_int(struct info_mapping *entry, uint64_t v)
+{
+	union {
+		uint64_t *u64;
+		uint16_t *u16;
+		void *v;
+	} ptr = {
+		.v = entry->ptr,
+	};
+
+	switch (entry->size) {
+		case sizeof(uint16_t):
+			if (v > UINT16_MAX)
+				return;
+
+			*ptr.u16 = v;
+			break;
+		case sizeof(uint64_t):
+			*ptr.u64 = v;
+			break;
+		default:
+			panic("unhandled %s size of %zu", __func__,
+			      entry->size);
+	}
+}
+
 static void announce_track_info_msg(struct instance *inst,
 				    struct announce_msg *msg)
 {

          
@@ 263,13 289,10 @@ static void announce_track_info_msg(stru
 				case VT_INT: {
 					struct val *v;
 
-					ASSERT3U(map[i].size, ==, sizeof(uint64_t));
-
 					v = nvpair_value(cur);
+					__set_info_int(&map[i], v->i);
+					val_putref(v);
 
-					*((uint64_t *) map[i].ptr) = v->i;
-
-					val_putref(v);
 					break;
 				}
 				case VT_NULL: