[lldp-devel] [PATCH 3/4] vdpnl decode and construct netlink messages

John Fastabend john.fastabend at gmail.com
Tue Mar 5 18:28:41 UTC 2013


On 02/25/2013 07:36 AM, Thomas Richter wrote:
> This file decodes a received netlink message and fill
> the new vdpnl_vsi data structure.
> It also encodes a netlink message from a given vdpnl_vsi
> data structure.
>
> Signed-off-by: Thomas Richter <tmricht at linux.vnet.ibm.com>
> ---

[...]

> +
> +/*
> + * Construct the response as netlink message.
> + */
> +static void mynla_nest_end(struct nlmsghdr *nlh, struct nlattr *start)
> +{
> +	start->nla_type |= NLA_F_NESTED;
> +	start->nla_len = (void *)nlh + nlh->nlmsg_len - (void *)start;
> +}
> +
> +static struct nlattr *mynla_nest_start(struct nlmsghdr *nlh, int type)
> +{
> +	struct nlattr *ap = (struct nlattr *)((void *)nlh + nlh->nlmsg_len);
> +
> +	ap->nla_type = type;
> +	nlh->nlmsg_len += NLA_HDRLEN;
> +	return ap;
> +}
> +
> +void mynla_put(struct nlmsghdr *nlh, int type, size_t len, void *data)
> +{
> +	struct nlattr *ap = (struct nlattr *)((void *)nlh + nlh->nlmsg_len);
> +
> +	ap->nla_type = type;
> +	ap->nla_len = NLA_HDRLEN + len;
> +	memcpy(ap + 1, data, len);
> +	nlh->nlmsg_len += NLA_HDRLEN + NLA_ALIGN(len);
> +}
> +
> +void mynla_put_u16(struct nlmsghdr *nlh, int type, uint16_t data)
> +{
> +	mynla_put(nlh, type, sizeof data, &data);
> +}
> +
> +void mynla_put_u32(struct nlmsghdr *nlh, int type, uint32_t data)
> +{
> +	mynla_put(nlh, type, sizeof data, &data);
> +}
> +

Can these mynla routines be put in lldp_rtnl.c? Then I could consolidate
similar code in lldp_dcbxnl.c which is using its own dcbnl helpers.

.John

-- 
John Fastabend         Intel Corporation


More information about the lldp-devel mailing list