#include <netlink/msg.h>
#include <netlink/utils.h>
#include <netlink/object.h>
+#include <netlink/cache-api.h>
#ifdef __cplusplus
extern "C" {
#endif
struct nl_cache;
-struct nl_cache_ops;
typedef void (*change_func_t)(struct nl_cache *, struct nl_object *, int);
/* Cache type management */
extern struct nl_cache_ops * nl_cache_ops_lookup(const char *);
-extern struct nl_cache_ops * nl_cache_ops_lookup_for_obj(struct nl_object_ops *);
-extern void nl_cache_mngt_foreach(void (*cb)(struct nl_cache_ops *, void *), void *);
+extern struct nl_cache_ops * nl_cache_ops_associate(int, int);
+extern struct nl_msgtype * nl_msgtype_lookup(struct nl_cache_ops *, int);
+extern void nl_cache_ops_foreach(void (*cb)(struct nl_cache_ops *, void *), void *);
extern int nl_cache_mngt_register(struct nl_cache_ops *);
extern int nl_cache_mngt_unregister(struct nl_cache_ops *);
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.
* @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;
}
/**
- * 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;
* @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;
{
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
{
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)
.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);
{
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);
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;