summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Graf <tgraf@suug.ch>2013-04-01 11:14:49 +0200
committerThomas Graf <tgraf@suug.ch>2013-04-01 11:14:49 +0200
commitaad041c46f6f0720bff8e8727e8ff39f2196d2a8 (patch)
treecb6f1a9bd7d4d65fb15a5f5c486492c64e65e564
parent6c9be5a31681ddf9a669ecf643092928ab0f2138 (diff)
genl: Provide internal function to resolve name to id
Like genl_ops_resolve() but uses its own socket. Signed-off-by: Thomas Graf <tgraf@suug.ch>
-rw-r--r--include/netlink-private/genl.h2
-rw-r--r--lib/genl/mngt.c26
2 files changed, 28 insertions, 0 deletions
diff --git a/include/netlink-private/genl.h b/include/netlink-private/genl.h
index 0aca6d7..5b93db3 100644
--- a/include/netlink-private/genl.h
+++ b/include/netlink-private/genl.h
@@ -17,4 +17,6 @@
#define GENL_HDRSIZE(hdrlen) (GENL_HDRLEN + (hdrlen))
+extern int genl_resolve_id(struct genl_ops *ops);
+
#endif
diff --git a/lib/genl/mngt.c b/lib/genl/mngt.c
index a3faaf2..35bbb12 100644
--- a/lib/genl/mngt.c
+++ b/lib/genl/mngt.c
@@ -302,6 +302,32 @@ static int __genl_ops_resolve(struct nl_cache *ctrl, struct genl_ops *ops)
return -NLE_OBJ_NOTFOUND;
}
+
+int genl_resolve_id(struct genl_ops *ops)
+{
+ struct nl_sock *sk;
+ int err = 0;
+
+ /* Check if resolved already */
+ if (ops->o_id != GENL_ID_GENERATE)
+ return 0;
+
+ if (!ops->o_name)
+ return -NLE_INVAL;
+
+ if (!(sk = nl_socket_alloc()))
+ return -NLE_NOMEM;
+
+ if ((err = genl_connect(sk)) < 0)
+ goto errout_free;
+
+ err = genl_ops_resolve(sk, ops);
+
+errout_free:
+ nl_socket_free(sk);
+
+ return err;
+}
/** @endcond */
/**