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 */ /**