]> git.ipfire.org Git - thirdparty/libnl.git/commitdiff
genl: Provide internal function to resolve name to id
authorThomas Graf <tgraf@suug.ch>
Mon, 1 Apr 2013 09:14:49 +0000 (11:14 +0200)
committerThomas Graf <tgraf@suug.ch>
Mon, 1 Apr 2013 09:14:49 +0000 (11:14 +0200)
Like genl_ops_resolve() but uses its own socket.

Signed-off-by: Thomas Graf <tgraf@suug.ch>
include/netlink-private/genl.h
lib/genl/mngt.c

index 0aca6d736a3b3b620390ebc66bc6309fbe40150e..5b93db3c8efc68f4ac0692ef901087bae4145d56 100644 (file)
@@ -17,4 +17,6 @@
 
 #define GENL_HDRSIZE(hdrlen) (GENL_HDRLEN + (hdrlen))
 
+extern int             genl_resolve_id(struct genl_ops *ops);
+
 #endif
index a3faaf23ebf93ba16b0af0ea9de0d72551fab09f..35bbb121ea35793275a3adfe1cd6ccd393ea645a 100644 (file)
@@ -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 */
 
 /**