diff mbox series

[09/12] netlink: Add additional helpers

Message ID 20240722190443.43196-9-denkenz@gmail.com (mailing list archive)
State New
Headers show
Series [01/12] useful: Add utility to find the next power of two | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success

Commit Message

Denis Kenzior July 22, 2024, 7:04 p.m. UTC
Helpers around l_netlink_message_append for use with common data types.
---
 ell/netlink.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 55 insertions(+)
diff mbox series

Patch

diff --git a/ell/netlink.h b/ell/netlink.h
index 593cddf1aee8..e7962b9932dc 100644
--- a/ell/netlink.h
+++ b/ell/netlink.h
@@ -62,6 +62,61 @@  int l_netlink_message_enter_nested(struct l_netlink_message *message,
 					uint16_t type);
 int l_netlink_message_leave_nested(struct l_netlink_message *message);
 
+static inline int l_netlink_message_append_u8(struct l_netlink_message *message,
+						uint16_t type, uint8_t u8)
+{
+	return l_netlink_message_append(message, type, &u8, sizeof(uint8_t));
+}
+
+static inline int l_netlink_message_append_u16(struct l_netlink_message *message,
+						uint16_t type, uint16_t u16)
+{
+	return l_netlink_message_append(message, type, &u16, sizeof(uint16_t));
+}
+
+static inline int l_netlink_message_append_u32(struct l_netlink_message *message,
+						uint16_t type, uint32_t u32)
+{
+	return l_netlink_message_append(message, type, &u32, sizeof(uint32_t));
+}
+
+static inline int l_netlink_message_append_u64(struct l_netlink_message *message,
+						uint16_t type, uint64_t u64)
+{
+	return l_netlink_message_append(message, type, &u64, sizeof(uint64_t));
+}
+
+static inline int l_netlink_message_append_s8(struct l_netlink_message *message,
+						uint16_t type, int8_t s8)
+{
+	return l_netlink_message_append(message, type, &s8, sizeof(int8_t));
+}
+
+static inline int l_netlink_message_append_s16(struct l_netlink_message *message,
+						uint16_t type, int16_t s16)
+{
+	return l_netlink_message_append(message, type, &s16, sizeof(int16_t));
+}
+
+static inline int l_netlink_message_append_s32(struct l_netlink_message *message,
+						uint16_t type, int32_t s32)
+{
+	return l_netlink_message_append(message, type, &s32, sizeof(int32_t));
+}
+
+static inline int l_netlink_message_append_s64(struct l_netlink_message *message,
+						uint16_t type, int64_t s64)
+{
+	return l_netlink_message_append(message, type, &s64, sizeof(int64_t));
+}
+
+static inline int l_netlink_message_append_mac(struct l_netlink_message *message,
+						uint16_t type,
+						const uint8_t mac[static 6])
+{
+	return l_netlink_message_append(message, type, mac, 6);
+}
+
 #ifdef __cplusplus
 }
 #endif