[PATCH 1/3] link: Add AF operation to append attributes to a GETLINK message

Thomas Haller thaller at redhat.com
Wed Dec 2 03:22:45 PST 2015


On Wed, 2015-11-25 at 11:14 -0800, David Ahern wrote:
> Upcoming bridge patch wants to add IFLA_EXT_MASK attribute to
> RTM_GETLINK
> requests to retrieve VLAN data. Expand request message to a full
> ifinfomsg
> header and call to hook to append attributes if it exists for an
> address
> family.
> 
> Signed-off-by: David Ahern <dsa at cumulusnetworks.com>
> ---
>  include/netlink-private/route/link/api.h |  4 ++++
>  lib/route/link.c                         | 26
> +++++++++++++++++++++++++-
>  2 files changed, 29 insertions(+), 1 deletion(-)
> 
> diff --git a/include/netlink-private/route/link/api.h
> b/include/netlink-private/route/link/api.h
> index 85f83f39539d..2d5665821477 100644
> --- a/include/netlink-private/route/link/api.h
> +++ b/include/netlink-private/route/link/api.h
> @@ -119,6 +119,10 @@ struct rtnl_link_af_ops
>  	int		      (*ao_fill_af)(struct rtnl_link *,
>  					    struct nl_msg *msg, void
> *);
>  
> +	/** Called for GETLINK message to the kernel. Used to append
> +	 * link address family specific attributes to the request
> message. */
> +	int		      (*ao_get_af)(struct nl_msg *msg);
> +
>  	/** Dump address family specific link attributes */
>  	void		      (*ao_dump[NL_DUMP_MAX+1])(struct
> rtnl_link *,
>  							struct
> nl_dump_params *,
> diff --git a/lib/route/link.c b/lib/route/link.c
> index cfe3779f41f4..3cb62df95d6a 100644
> --- a/lib/route/link.c
> +++ b/lib/route/link.c
> @@ -657,8 +657,32 @@ static int link_msg_parser(struct nl_cache_ops
> *ops, struct sockaddr_nl *who,
>  static int link_request_update(struct nl_cache *cache, struct
> nl_sock *sk)
>  {
>  	int family = cache->c_iarg1;
> +	struct ifinfomsg hdr = { .ifi_family = family };
> +	struct rtnl_link_af_ops *ops;
> +	struct nl_msg *msg;
> +	int err;
> +
> +	msg = nlmsg_alloc_simple(RTM_GETLINK, NLM_F_DUMP);
> +	if (!msg)
> +		return -NLE_NOMEM;
> +
> +	err = -NLE_MSGSIZE;
> +	if (nlmsg_append(msg, &hdr, sizeof(hdr), NLMSG_ALIGNTO) < 0)
> +		goto nla_put_failure;
>  
> -	return nl_rtgen_request(sk, RTM_GETLINK, family,
> NLM_F_DUMP);
> +	ops = rtnl_link_af_ops_lookup(family);
> +	if (ops && ops->ao_get_af) {
> +		err = ops->ao_get_af(msg);
> +		if (err)
> +			goto nla_put_failure;
> +	}
> +	err = nl_send_auto(sk, msg);
> +
> +        return err >= 0 ? 0 : err;

this causes @msg to leak.

How about:

-   return err >= 0 ? 0 : err;
+   if (err >= 0)
+       err = 0;


> +
> +nla_put_failure:
> +	nlmsg_free(msg);
> +	return err;
>  }
>  
>  static void link_dump_line(struct nl_object *obj, struct
> nl_dump_params *p)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/libnl/attachments/20151202/ffbc7d8e/attachment.sig>


More information about the libnl mailing list