Rename and upgrade _genl_msg_create and _genl_msg_as_bytes from
-private.h functions (for unit test use only) to public library
functions, specifically to be usable in IWD for encoding and decoding
raw genl messages.
---
Makefile.am | 1 -
ell/ell.sym | 2 ++
ell/genl-private.h | 27 ----------------
ell/genl.c | 80 +++++++++++++++++++++++++++++-----------------
ell/genl.h | 5 +++
5 files changed, 57 insertions(+), 58 deletions(-)
delete mode 100644 ell/genl-private.h
diff --git a/Makefile.am b/Makefile.am
index 3ead678..8e025cb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -83,7 +83,6 @@ ell_libell_la_SOURCES = $(linux_headers) \
ell/checksum.c \
ell/netlink-private.h \
ell/netlink.c \
- ell/genl-private.h \
ell/genl.c \
ell/dbus-private.h \
ell/dbus.c \
diff --git a/ell/ell.sym b/ell/ell.sym
index 46df1bd..0c83b87 100644
--- a/ell/ell.sym
+++ b/ell/ell.sym
@@ -258,6 +258,8 @@ global:
l_genl_request_family;
l_genl_msg_new;
l_genl_msg_new_sized;
+ l_genl_msg_new_from_data;
+ l_genl_msg_to_data;
l_genl_msg_ref;
l_genl_msg_unref;
l_genl_msg_get_command;
diff --git a/ell/genl-private.h b/ell/genl-private.h
deleted file mode 100644
index 3c3e525..0000000
--- a/ell/genl-private.h
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- *
- * Embedded Linux library
- *
- * Copyright (C) 2011-2015 Intel Corporation. All rights reserved.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- *
- */
-
-struct l_genl_msg *_genl_msg_create(const struct nlmsghdr *nlmsg);
-const void *_genl_msg_as_bytes(struct l_genl_msg *msg, uint16_t type,
- uint16_t flags, uint32_t seq,
- uint32_t pid,
- size_t *out_size);
diff --git a/ell/genl.c b/ell/genl.c
index ca4fa62..815af90 100644
--- a/ell/genl.c
+++ b/ell/genl.c
@@ -34,7 +34,6 @@
#include "io.h"
#include "netlink-private.h"
#include "genl.h"
-#include "genl-private.h"
#include "private.h"
#define MAX_NESTING_LEVEL 4
@@ -767,7 +766,7 @@ static bool msg_grow(struct l_genl_msg *msg, uint32_t needed)
return true;
}
-struct l_genl_msg *_genl_msg_create(const struct nlmsghdr *nlmsg)
+static struct l_genl_msg *msg_create(const struct nlmsghdr *nlmsg)
{
struct l_genl_msg *msg;
@@ -796,6 +795,32 @@ done:
return l_genl_msg_ref(msg);
}
+static const void *msg_as_bytes(struct l_genl_msg *msg, uint16_t type,
+ uint16_t flags, uint32_t seq, uint32_t pid,
+ size_t *out_size)
+{
+ struct nlmsghdr *nlmsg;
+ struct genlmsghdr *genlmsg;
+
+ nlmsg = msg->data;
+
+ nlmsg->nlmsg_len = msg->len;
+ nlmsg->nlmsg_type = type;
+ nlmsg->nlmsg_flags = flags;
+ nlmsg->nlmsg_seq = seq;
+ nlmsg->nlmsg_pid = pid;
+
+ genlmsg = msg->data + NLMSG_HDRLEN;
+
+ genlmsg->cmd = msg->cmd;
+ genlmsg->version = msg->version;
+
+ if (out_size)
+ *out_size = msg->len;
+
+ return msg->data;
+}
+
static void write_watch_destroy(void *user_data)
{
struct l_genl *genl = user_data;
@@ -912,7 +937,7 @@ static void process_unicast(struct l_genl *genl, const struct nlmsghdr
*nlmsg)
nlmsg->nlmsg_type == NLMSG_OVERRUN)
return;
- msg = _genl_msg_create(nlmsg);
+ msg = msg_create(nlmsg);
if (!nlmsg->nlmsg_seq) {
if (msg)
dispatch_unicast_watches(genl, nlmsg->nlmsg_type, msg);
@@ -947,7 +972,7 @@ static void process_multicast(struct l_genl *genl, uint32_t group,
const struct nlmsghdr *nlmsg)
{
const struct l_queue_entry *entry;
- struct l_genl_msg *msg = _genl_msg_create(nlmsg);
+ struct l_genl_msg *msg = msg_create(nlmsg);
if (!msg)
return;
@@ -1492,41 +1517,36 @@ LIB_EXPORT bool l_genl_request_family(struct l_genl *genl, const
char *name,
return false;
}
-const void *_genl_msg_as_bytes(struct l_genl_msg *msg, uint16_t type,
- uint16_t flags, uint32_t seq,
- uint32_t pid,
- size_t *out_size)
+LIB_EXPORT struct l_genl_msg *l_genl_msg_new(uint8_t cmd)
{
- struct nlmsghdr *nlmsg;
- struct genlmsghdr *genlmsg;
-
- nlmsg = msg->data;
-
- nlmsg->nlmsg_len = msg->len;
- nlmsg->nlmsg_type = type;
- nlmsg->nlmsg_flags = flags;
- nlmsg->nlmsg_seq = seq;
- nlmsg->nlmsg_pid = pid;
+ return l_genl_msg_new_sized(cmd, 0);
+}
- genlmsg = msg->data + NLMSG_HDRLEN;
+LIB_EXPORT struct l_genl_msg *l_genl_msg_new_sized(uint8_t cmd, uint32_t size)
+{
+ return msg_alloc(cmd, 0x00, size);
+}
- genlmsg->cmd = msg->cmd;
- genlmsg->version = msg->version;
+LIB_EXPORT struct l_genl_msg *l_genl_msg_new_from_data(const void *data,
+ size_t size)
+{
+ const struct nlmsghdr *nlmsg = (const void *) data;
- if (out_size)
- *out_size = msg->len;
+ if (size < sizeof(struct nlmsghdr))
+ return NULL;
- return msg->data;
-}
+ if (size < nlmsg->nlmsg_len)
+ return NULL;
-LIB_EXPORT struct l_genl_msg *l_genl_msg_new(uint8_t cmd)
-{
- return l_genl_msg_new_sized(cmd, 0);
+ return msg_create(nlmsg);
}
-LIB_EXPORT struct l_genl_msg *l_genl_msg_new_sized(uint8_t cmd, uint32_t size)
+LIB_EXPORT const void *l_genl_msg_to_data(struct l_genl_msg *msg, uint16_t type,
+ uint16_t flags, uint32_t seq,
+ uint32_t pid,
+ size_t *out_size)
{
- return msg_alloc(cmd, 0x00, size);
+ return msg_as_bytes(msg, type, flags, seq, pid, out_size);
}
LIB_EXPORT struct l_genl_msg *l_genl_msg_ref(struct l_genl_msg *msg)
diff --git a/ell/genl.h b/ell/genl.h
index c3f641f..312a6b2 100644
--- a/ell/genl.h
+++ b/ell/genl.h
@@ -85,6 +85,11 @@ struct l_genl_attr {
struct l_genl_msg* l_genl_msg_new(uint8_t cmd);
struct l_genl_msg *l_genl_msg_new_sized(uint8_t cmd, uint32_t size);
+struct l_genl_msg *l_genl_msg_new_from_data(const void *data, size_t size);
+
+const void *l_genl_msg_to_data(struct l_genl_msg *msg, uint16_t type,
+ uint16_t flags, uint32_t seq, uint32_t pid,
+ size_t *out_size);
struct l_genl_msg *l_genl_msg_ref(struct l_genl_msg *msg);
void l_genl_msg_unref(struct l_genl_msg *msg);
--
2.20.1