[PATCH] genl: modify genl_ctrl_resolve and friends to allow for module auto-loading

Neil Horman nhorman at tuxdriver.com
Fri Jun 1 06:37:54 EDT 2012


On Fri, Jun 01, 2012 at 02:24:58AM -0400, Thomas Graf wrote:
> On Thu, May 31, 2012 at 03:09:05PM -0400, Neil Horman wrote:
> > Generic netlink has the ability to autoload modules in response to a request for
> > a family.  Currently libnl uses a GETFAMILY call with the NLM_F_DUMP flag to
> > list all the available families, but doing so neglects the possibility of an
> > autoloaded module.  This patch modifies the genl code to probe the kernel for a
> > specific family rather than dumping a list of all the currenlty available ones,
> > making autoload work properly.
> 
> Nice work Neil
> 
Thanks

> > Signed-off-by: Neil Horman <nhorman at tuxdriver.com>
> > CC: Thomas Graf <tgraf at redhat.com>
> > ---
> >  lib/genl/ctrl.c |  133 +++++++++++++++++++++++++++++++++++++++++++++++++------
> >  1 files changed, 119 insertions(+), 14 deletions(-)
> > 
> > diff --git a/lib/genl/ctrl.c b/lib/genl/ctrl.c
> > index 107a4fa..9b29000 100644
> > --- a/lib/genl/ctrl.c
> > +++ b/lib/genl/ctrl.c
> > @@ -250,6 +250,120 @@ struct genl_family *genl_ctrl_search_by_name(struct nl_cache *cache,
> >  /** @} */
> >  
> >  /**
> > + * process responses from from the query sent by genl_ctrl_probe_by_name 
> > + * @arg nl_msg		Returned message.
> > + * @arg name		genl_family structure to fill out.
> > + *
> > + * Process returned messages, filling out the missing informatino in the
> > + * genl_family structure
> > + *
> > + * @return Indicator to keep processing frames or not
> > + *
> > + */
> > +static int probe_response(struct nl_msg *msg, void *arg)
> > +{
> > +	struct nlattr *tb[__CTRL_ATTR_MAX+1];
> > +	struct nlmsghdr *nlh = nlmsg_hdr(msg);
> > +	struct genl_family *ret = (struct genl_family *)arg;
> > +
> > +	if (genlmsg_parse(nlh, 0, tb, __CTRL_ATTR_MAX, ctrl_policy))
> 
> Looks like you have to use CTRL_ATTR_MAX here.
> 
> > + */
> > +static struct genl_family *genl_ctrl_probe_by_name(struct nl_sock *sk, const char *name)
> > +{
> > +	struct nl_msg *msg;
> > +	struct genl_family *ret = NULL;
> > +	int rc;
> > +	void *hdr;
> 
> hdr seems unused
> 
> >  
> > @@ -337,6 +440,8 @@ static struct genl_cmd genl_cmds[] = {
> >  	{
> >  		.c_id		= CTRL_CMD_GETFAMILY,
> >  		.c_name		= "GETFAMILY" ,
> > +		.c_maxattr	= CTRL_ATTR_MAX,
> > +		.c_attr_policy	= ctrl_policy,
> >  	},
> 
> This seems unneeded, c_maxattr and c_attr_policy should only be used on
> rx and the reply should come as CTRL_CMD_NEWFAMILY.
> 
Ack, sorry I missed these, I'll have a respin for you later today.
Thanks!
Neil




More information about the libnl mailing list