summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2007-10-11 21:09:49 (GMT)
committerThomas Graf <tgraf@suug.ch>2007-10-11 21:09:49 (GMT)
commitd36d396fd0ae94aa2269546a02b5973b4ec27775 (patch)
treee051a964e1a0fc46b73b436895b5084f1981b3b7 /lib
parent1a125f88d8f46cad4ecbb9d19cfaddec63a26d0a (diff)
downloadlibnl-d36d396fd0ae94aa2269546a02b5973b4ec27775.zip
libnl-d36d396fd0ae94aa2269546a02b5973b4ec27775.tar.gz
libnl-d36d396fd0ae94aa2269546a02b5973b4ec27775.tar.bz2
Cache message type association interface cleanups
Diffstat (limited to 'lib')
-rw-r--r--lib/cache_mngt.c98
-rw-r--r--lib/msg.c24
2 files changed, 55 insertions, 67 deletions
diff --git a/lib/cache_mngt.c b/lib/cache_mngt.c
index 7cf1a03..de2bf24 100644
--- a/lib/cache_mngt.c
+++ b/lib/cache_mngt.c
@@ -22,9 +22,32 @@
static struct nl_cache_ops *cache_ops;
/**
+ * @name Cache Operations Sets
+ * @{
+ */
+
+/**
+ * Lookup the set cache operations of a certain cache type
+ * @arg name name of the cache type
+ *
+ * @return The cache operations or NULL if no operations
+ * have been registered under the specified name.
+ */
+struct nl_cache_ops *nl_cache_ops_lookup(const char *name)
+{
+ struct nl_cache_ops *ops;
+
+ for (ops = cache_ops; ops; ops = ops->co_next)
+ if (!strcmp(ops->co_name, name))
+ return ops;
+
+ return NULL;
+}
+
+/**
* Associate a message type to a set of cache operations
* @arg protocol netlink protocol
- * @arg message_type netlink message type
+ * @arg msgtype netlink message type
*
* Associates the specified netlink message type with
* a registered set of cache operations.
@@ -32,14 +55,14 @@ static struct nl_cache_ops *cache_ops;
* @return The cache operations or NULL if no association
* could be made.
*/
-struct nl_cache_ops *nl_cache_mngt_associate(int protocol, int message_type)
+struct nl_cache_ops *nl_cache_ops_associate(int protocol, int msgtype)
{
int i;
struct nl_cache_ops *ops;
for (ops = cache_ops; ops; ops = ops->co_next)
for (i = 0; ops->co_msgtypes[i].mt_id >= 0; i++)
- if (ops->co_msgtypes[i].mt_id == message_type &&
+ if (ops->co_msgtypes[i].mt_id == msgtype &&
ops->co_protocol == protocol)
return ops;
@@ -47,68 +70,27 @@ struct nl_cache_ops *nl_cache_mngt_associate(int protocol, int message_type)
}
/**
- * Convert message type to character string.
- * @arg ops Cache operations.
- * @arg protocol Netlink Protocol.
- * @arg msgtype Message type.
- * @arg buf Destination buffer.
- * @arg len Size of destination buffer.
+ * Lookup message type cache association
+ * @arg ops cache operations
+ * @arg msgtype netlink message type
*
- * Converts a message type to a character string and stores it in the
- * provided buffer.
+ * Searches for a matching message type association ing the specified
+ * cache operations.
*
- * @return The destination buffer or the message type encoded in
- * hexidecimal form if no match was found.
+ * @return A message type association or NULL.
*/
-char *nl_cache_mngt_type2name(struct nl_cache_ops *ops, int protocol,
- int msgtype, char *buf, size_t len)
+struct nl_msgtype *nl_msgtype_lookup(struct nl_cache_ops *ops, int msgtype)
{
int i;
- for (i = 0; ops->co_msgtypes[i].mt_id >= 0; i++) {
- if (ops->co_msgtypes[i].mt_id == msgtype &&
- ops->co_protocol == protocol) {
- snprintf(buf, len, "%s::%s",
- ops->co_name,
- ops->co_msgtypes[i].mt_name);
- return buf;
- }
- }
-
- snprintf(buf, len, "%d:%s->0x%x()", protocol, ops->co_name, msgtype);
- return buf;
-}
-
-/**
- * @name Cache Type Management
- * @{
- */
-
-/**
- * Lookup the set cache operations of a certain cache type
- * @arg name name of the cache type
- *
- * @return The cache operations or NULL if no operations
- * have been registered under the specified name.
- */
-struct nl_cache_ops *nl_cache_ops_lookup(const char *name)
-{
- struct nl_cache_ops *ops;
-
- for (ops = cache_ops; ops; ops = ops->co_next)
- if (!strcmp(ops->co_name, name))
- return ops;
+ for (i = 0; ops->co_msgtypes[i].mt_id >= 0; i++)
+ if (ops->co_msgtypes[i].mt_id == msgtype)
+ return &ops->co_msgtypes[i];
return NULL;
}
-/**
- * Lookupt the set of cache operations responsible for a type of object
- * @arg obj_ops Object operations
- *
- * @return The cache operations or NULL if not found.
- */
-struct nl_cache_ops *nl_cache_ops_lookup_for_obj(struct nl_object_ops *obj_ops)
+static struct nl_cache_ops *cache_ops_lookup_for_obj(struct nl_object_ops *obj_ops)
{
struct nl_cache_ops *ops;
@@ -125,7 +107,7 @@ struct nl_cache_ops *nl_cache_ops_lookup_for_obj(struct nl_object_ops *obj_ops)
* @arg cb Callback function to be called
* @arg arg User specific argument.
*/
-void nl_cache_mngt_foreach(void (*cb)(struct nl_cache_ops *, void *), void *arg)
+void nl_cache_ops_foreach(void (*cb)(struct nl_cache_ops *, void *), void *arg)
{
struct nl_cache_ops *ops;
@@ -208,7 +190,7 @@ void nl_cache_mngt_provide(struct nl_cache *cache)
{
struct nl_cache_ops *ops;
- ops = nl_cache_ops_lookup_for_obj(cache->c_ops->co_obj_ops);
+ ops = cache_ops_lookup_for_obj(cache->c_ops->co_obj_ops);
if (!ops)
BUG();
else
@@ -227,7 +209,7 @@ void nl_cache_mngt_unprovide(struct nl_cache *cache)
{
struct nl_cache_ops *ops;
- ops = nl_cache_ops_lookup_for_obj(cache->c_ops->co_obj_ops);
+ ops = cache_ops_lookup_for_obj(cache->c_ops->co_obj_ops);
if (!ops)
BUG();
else if (ops->co_major_cache == cache)
diff --git a/lib/msg.c b/lib/msg.c
index caae744..d19ac08 100644
--- a/lib/msg.c
+++ b/lib/msg.c
@@ -752,8 +752,8 @@ int nl_msg_parse(struct nl_msg *msg, void (*cb)(struct nl_object *, void *),
.arg = arg,
};
- ops = nl_cache_mngt_associate(nlmsg_get_proto(msg),
- nlmsg_hdr(msg)->nlmsg_type);
+ ops = nl_cache_ops_associate(nlmsg_get_proto(msg),
+ nlmsg_hdr(msg)->nlmsg_type);
if (ops == NULL)
return nl_error(ENOENT, "Unknown message type %d",
nlmsg_hdr(msg)->nlmsg_type);
@@ -815,16 +815,22 @@ static void print_hdr(FILE *ofd, struct nl_msg *msg)
{
struct nlmsghdr *nlh = nlmsg_hdr(msg);
struct nl_cache_ops *ops;
+ struct nl_msgtype *mt;
char buf[128];
fprintf(ofd, " .nlmsg_len = %d\n", nlh->nlmsg_len);
- ops = nl_cache_mngt_associate(nlmsg_get_proto(msg), nlh->nlmsg_type);
+ ops = nl_cache_ops_associate(nlmsg_get_proto(msg), nlh->nlmsg_type);
+ if (ops) {
+ mt = nl_msgtype_lookup(ops, nlh->nlmsg_type);
+ if (!mt)
+ BUG();
- fprintf(ofd, " .nlmsg_type = %d <%s>\n", nlh->nlmsg_type,
- ops ? nl_cache_mngt_type2name(ops, msg->nm_protocol,
- nlh->nlmsg_type, buf, sizeof(buf))
- : nl_nlmsgtype2str(nlh->nlmsg_type, buf, sizeof(buf)));
+ snprintf(buf, sizeof(buf), "%s::%s", ops->co_name, mt->mt_name);
+ } else
+ nl_nlmsgtype2str(nlh->nlmsg_type, buf, sizeof(buf));
+
+ fprintf(ofd, " .nlmsg_type = %d <%s>\n", nlh->nlmsg_type, buf);
fprintf(ofd, " .nlmsg_flags = %d <%s>\n", nlh->nlmsg_flags,
nl_nlmsg_flags2str(nlh->nlmsg_flags, buf, sizeof(buf)));
fprintf(ofd, " .nlmsg_seq = %d\n", nlh->nlmsg_seq);
@@ -901,8 +907,8 @@ void nl_msg_dump(struct nl_msg *msg, FILE *ofd)
int payloadlen = nlmsg_len(hdr);
int attrlen = 0;
- ops = nl_cache_mngt_associate(nlmsg_get_proto(msg),
- hdr->nlmsg_type);
+ ops = nl_cache_ops_associate(nlmsg_get_proto(msg),
+ hdr->nlmsg_type);
if (ops) {
attrlen = nlmsg_attrlen(hdr, ops->co_hdrsize);
payloadlen -= attrlen;