Netdev List
 help / color / mirror / Atom feed
* question about nla_nest_cancel
@ 2011-01-27 17:08 Julia Lawall
  2011-01-27 17:21 ` Kurt Van Dijck
  2011-01-27 17:52 ` Ben Pfaff
  0 siblings, 2 replies; 5+ messages in thread
From: Julia Lawall @ 2011-01-27 17:08 UTC (permalink / raw)
  To: hadi, netdev

I find numerous occurrences of code like the following, in which nest ends 
up with the value NULL and then nla_nest_cancel is called with nest as the 
second argument.  But nla_nest_cancel just calls nlmsg_trim with the same 
second argument, and nlmsg_trim does nothing if its second argument is 
NULL.  Is there any reason to keep these calls?

thanks,
julia



static int tbf_dump(struct Qdisc *sch, struct sk_buff *skb)
{
	struct tbf_sched_data *q = qdisc_priv(sch);
	struct nlattr *nest;
	struct tc_tbf_qopt opt;

	nest = nla_nest_start(skb, TCA_OPTIONS);
	if (nest == NULL)
		goto nla_put_failure;

	opt.limit = q->limit;
	opt.rate = q->R_tab->rate;
	if (q->P_tab)
		opt.peakrate = q->P_tab->rate;
	else
		memset(&opt.peakrate, 0, sizeof(opt.peakrate));
	opt.mtu = q->mtu;
	opt.buffer = q->buffer;
	NLA_PUT(skb, TCA_TBF_PARMS, sizeof(opt), &opt);

	nla_nest_end(skb, nest);
	return skb->len;

nla_put_failure:
	nla_nest_cancel(skb, nest);
	return -1;
}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: question about nla_nest_cancel
  2011-01-27 17:08 question about nla_nest_cancel Julia Lawall
@ 2011-01-27 17:21 ` Kurt Van Dijck
  2011-01-27 17:25   ` Julia Lawall
  2011-01-27 17:52 ` Ben Pfaff
  1 sibling, 1 reply; 5+ messages in thread
From: Kurt Van Dijck @ 2011-01-27 17:21 UTC (permalink / raw)
  To: Julia Lawall; +Cc: hadi, netdev

On Thu, Jan 27, 2011 at 06:08:34PM +0100, Julia Lawall wrote:
> 
> I find numerous occurrences of code like the following, in which nest ends 
> up with the value NULL and then nla_nest_cancel is called with nest as the 
> second argument.  But nla_nest_cancel just calls nlmsg_trim with the same 
> second argument, and nlmsg_trim does nothing if its second argument is 
> NULL.  Is there any reason to keep these calls?
I just learned this:
nla_nest_start() adds data to the skb.
nla_nest_end() 'commits' the proper length.
nla_nest_cancel() reverts skb to the state before nla_nest_start(),
as if nothing happened.

Kurt

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: question about nla_nest_cancel
  2011-01-27 17:21 ` Kurt Van Dijck
@ 2011-01-27 17:25   ` Julia Lawall
  0 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2011-01-27 17:25 UTC (permalink / raw)
  To: Kurt Van Dijck; +Cc: hadi, netdev

On Thu, 27 Jan 2011, Kurt Van Dijck wrote:

> On Thu, Jan 27, 2011 at 06:08:34PM +0100, Julia Lawall wrote:
> > 
> > I find numerous occurrences of code like the following, in which nest ends 
> > up with the value NULL and then nla_nest_cancel is called with nest as the 
> > second argument.  But nla_nest_cancel just calls nlmsg_trim with the same 
> > second argument, and nlmsg_trim does nothing if its second argument is 
> > NULL.  Is there any reason to keep these calls?
> I just learned this:
> nla_nest_start() adds data to the skb.
> nla_nest_end() 'commits' the proper length.
> nla_nest_cancel() reverts skb to the state before nla_nest_start(),
> as if nothing happened.

Yes, I can see this as well.  But in this case, it seems to me taht 
nothing has happened, because nla_nest_star has returned NULL?

julia

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: question about nla_nest_cancel
  2011-01-27 17:08 question about nla_nest_cancel Julia Lawall
  2011-01-27 17:21 ` Kurt Van Dijck
@ 2011-01-27 17:52 ` Ben Pfaff
  2011-01-27 18:18   ` Julia Lawall
  1 sibling, 1 reply; 5+ messages in thread
From: Ben Pfaff @ 2011-01-27 17:52 UTC (permalink / raw)
  To: Julia Lawall; +Cc: hadi, netdev

Julia Lawall <julia@diku.dk> writes:

> I find numerous occurrences of code like the following, in which nest ends 
> up with the value NULL and then nla_nest_cancel is called with nest as the 
> second argument.  But nla_nest_cancel just calls nlmsg_trim with the same 
> second argument, and nlmsg_trim does nothing if its second argument is 
> NULL.  Is there any reason to keep these calls?

I think that you are missing that NLA_PUT() contains an internal
"goto nla_put_failure;".  If that branch is taken, then
nla_nest_cancel() trims off the nested attribute.  So just
removing the call to nla_nest_cancel() would change behavior in
that case.
-- 
Ben Pfaff 
http://benpfaff.org

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: question about nla_nest_cancel
  2011-01-27 17:52 ` Ben Pfaff
@ 2011-01-27 18:18   ` Julia Lawall
  0 siblings, 0 replies; 5+ messages in thread
From: Julia Lawall @ 2011-01-27 18:18 UTC (permalink / raw)
  To: Ben Pfaff; +Cc: hadi, netdev

On Thu, 27 Jan 2011, Ben Pfaff wrote:

> Julia Lawall <julia@diku.dk> writes:
> 
> > I find numerous occurrences of code like the following, in which nest ends 
> > up with the value NULL and then nla_nest_cancel is called with nest as the 
> > second argument.  But nla_nest_cancel just calls nlmsg_trim with the same 
> > second argument, and nlmsg_trim does nothing if its second argument is 
> > NULL.  Is there any reason to keep these calls?
> 
> I think that you are missing that NLA_PUT() contains an internal
> "goto nla_put_failure;".  If that branch is taken, then
> nla_nest_cancel() trims off the nested attribute.  So just
> removing the call to nla_nest_cancel() would change behavior in
> that case.

Indeed.  Thank you for the explanation.

julia

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-01-27 18:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-01-27 17:08 question about nla_nest_cancel Julia Lawall
2011-01-27 17:21 ` Kurt Van Dijck
2011-01-27 17:25   ` Julia Lawall
2011-01-27 17:52 ` Ben Pfaff
2011-01-27 18:18   ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox