All of lore.kernel.org
 help / color / mirror / Atom feed
From: Nikolay Aleksandrov <nikolay@cumulusnetworks.com>
To: David Ahern <dsa@cumulusnetworks.com>, netdev@vger.kernel.org
Cc: shm@cumulusnetworks.com
Subject: Re: [PATCH net-next] vrf: Add ip rules at vrf device create
Date: Tue, 8 Dec 2015 12:54:50 +0100	[thread overview]
Message-ID: <5666C50A.5080409@cumulusnetworks.com> (raw)
In-Reply-To: <1449546920-8617-1-git-send-email-dsa@cumulusnetworks.com>

Hi,
On 12/08/2015 04:55 AM, David Ahern wrote:
[snip]
>  
> +static inline size_t vrf_fib_rule_nl_size(bool have_pref)
> +{
> +	size_t sz;
> +
> +	sz = NLMSG_ALIGN(sizeof(struct fib_rule_hdr))
> +			 + nla_total_size(IFNAMSIZ) /* FRA_{I,O}IFNAME */
> +			 + nla_total_size(4); /* FRA_TABLE, u32 */
directly use sizeof(u32) and remove it from the comment ?

> +
> +	if (have_pref)
> +		sz += nla_total_size(4); /* FRA_PRIORITY, u32 */
Why not always add this to the size and remove the whole have_pref and sz ?

> +
> +	return sz;
> +}
> +
> +static int vrf_fib_rule(struct net_device *dev, __u8 family, int if_type,
> +			bool add_it)
I think dev can be constified.

> +{
> +	struct net_vrf *vrf = netdev_priv(dev);
vrf is only read and can be const

> +	struct fib_rule_hdr *frh;
> +	struct nlmsghdr *nlh;
> +	struct sk_buff *skb;
> +	int err;
> +
> +	skb = nlmsg_new(vrf_fib_rule_nl_size(!!vrf->pref), GFP_KERNEL);
> +	if (!skb)
> +		return -ENOMEM;
> +
> +	nlh = nlmsg_put(skb, 0, 0, 0, sizeof(*frh), 0);
> +	if (!nlh)
> +		return -EMSGSIZE;
Looks like the skb will be leaked here because nlmsg_put() doesn't free it.
In fact I can see this error in other places throughout the stack (probably
c&p errors), good that it's not supposed to happen. :-)

> +
> +	frh = nlmsg_data(nlh);
> +	memset(frh, 0, sizeof(*frh));
> +	frh->family = family;
> +	frh->action = FR_ACT_TO_TBL;
> +
> +	if (nla_put_u32(skb, FRA_TABLE, vrf->tb_id))
> +		goto nla_put_failure;
> +
> +	if (nla_put_string(skb, if_type, dev->name))
> +		goto nla_put_failure;
> +
> +	if (vrf->pref) {
> +		if (nla_put_u32(skb, FRA_PRIORITY, vrf->pref))
> +			goto nla_put_failure;
> +	}
> +
> +	nlmsg_end(skb, nlh);
> +
> +	/* fib_nl_{new,del}rule handling looks for net from skb->sk */
> +	skb->sk = dev_net(dev)->rtnl;
> +	if (add_it) {
> +		err = fib_nl_newrule(skb, nlh);
> +	} else {
> +		err = fib_nl_delrule(skb, nlh);
> +		if (err == -ENOENT)
> +			err = 0;
> +	}
> +
> +	kfree_skb(skb);
minor nit: instead of kfree_skb(), you can use nlmsg_free() which currently
does the same, but would be clearer that this is the nlmsg skb.

> +
> +	return err;
> +
> +nla_put_failure:
> +	nlmsg_cancel(skb, nlh);

Here you'll leak the skb, nlmsg_cancel() only trims it and removes
the message, but doesn't free the skb.

> +	return -EMSGSIZE;
> +}
> +
> +static void vrf_del_fib_rules(struct net_device *dev)
Same here for dev (const)

> +{
> +	if (vrf_fib_rule(dev, AF_INET,  FRA_IIFNAME, 0) ||
> +	    vrf_fib_rule(dev, AF_INET,  FRA_OIFNAME, 0) ||
> +	    vrf_fib_rule(dev, AF_INET6, FRA_IIFNAME, 0) ||
> +	    vrf_fib_rule(dev, AF_INET6, FRA_OIFNAME, 0)) {
> +		netdev_err(dev, "Failed to delete FIB rules for %s\n",
> +			   dev->name);

I've seen this use of netdev_err() elsewhere in vrf, too. I was going to
send a patch to change it because you get messages like:
<dev name>: Failed to add FIB rules for <dev name>
which is pointless. You can just drop the extra dev->name.

> +	}
> +}
> +
> +static int vrf_add_fib_rules(struct net_device *dev)
Same here for dev (const)

> +{
> +	int err;
> +
> +	err = vrf_fib_rule(dev, AF_INET,  FRA_IIFNAME, 1);
> +	if (err < 0)
> +		goto out_err;
> +
> +	err = vrf_fib_rule(dev, AF_INET,  FRA_OIFNAME, 1);
> +	if (err < 0)
> +		goto out_err;
> +
> +	err = vrf_fib_rule(dev, AF_INET6, FRA_IIFNAME, 1);
> +	if (err < 0)
> +		goto out_err;
> +
> +	err = vrf_fib_rule(dev, AF_INET6, FRA_OIFNAME, 1);
> +	if (err < 0)
> +		goto out_err;
> +
> +	return 0;
> +out_err:
> +	netdev_err(dev, "Failed to add FIB rules for %s\n", dev->name);
Same here for dev->name

> +	vrf_del_fib_rules(dev);
> +	return err;
> +}
> +
[snip]

  reply	other threads:[~2015-12-08 11:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-08  3:55 [PATCH net-next] vrf: Add ip rules at vrf device create David Ahern
2015-12-08 11:54 ` Nikolay Aleksandrov [this message]
2015-12-08 14:19   ` David Ahern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5666C50A.5080409@cumulusnetworks.com \
    --to=nikolay@cumulusnetworks.com \
    --cc=dsa@cumulusnetworks.com \
    --cc=netdev@vger.kernel.org \
    --cc=shm@cumulusnetworks.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.