netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Miller <davem@davemloft.net>
To: mkubecek@suse.cz
Cc: netdev@vger.kernel.org, kuznet@ms2.inr.ac.ru, jmorris@namei.org,
	yoshfuji@linux-ipv6.org, kaber@trash.net
Subject: Re: [PATCH net] ipv6: do not overwrite inetpeer metrics prematurely
Date: Thu, 06 Mar 2014 14:24:25 -0500 (EST)	[thread overview]
Message-ID: <20140306.142425.1675660751208500651.davem@davemloft.net> (raw)
In-Reply-To: <20140306095054.EEC5EE6E04@unicorn.suse.cz>

From: Michal Kubecek <mkubecek@suse.cz>
Date: Thu,  6 Mar 2014 10:50:54 +0100 (CET)

> If an IPv6 host route with metrics exists, an attempt to add a
> new route for the same target with different metrics fails but
> rewrites the metrics anyway:
> 
> 12sp0:~ # ip route add fec0::1 dev eth0 rto_min 1000
> 12sp0:~ # ip -6 route show
> fe80::/64 dev eth0  proto kernel  metric 256
> fec0::1 dev eth0  metric 1024  rto_min lock 1s
> 12sp0:~ # ip route add fec0::1 dev eth0 rto_min 1500
> RTNETLINK answers: File exists
> 12sp0:~ # ip -6 route show
> fe80::/64 dev eth0  proto kernel  metric 256
> fec0::1 dev eth0  metric 1024  rto_min lock 1.5s
> 
> This is caused by all IPv6 host routes using the metrics in
> their inetpeer (or the shared default). This also holds for the
> new route created in ip6_route_add() which shares the metrics
> with the already existing route and thus ip6_route_add()
> rewrites the metrics even if the new route ends up not being
> used at all.
> 
> Allocate separate metrics in ip6_route_add() and copy them into
> inetpeer (and update dst->_metrics) just before the new route is
> actually inserted in fib6_add_rt2node().
> 
> Signed-off-by: Michal Kubecek <mkubecek@suse.cz>

Thanks for working on this.

> +static void rt6_metrics_to_peer(struct rt6_info *rt)
> +{
> +	struct inet_peer *peer = rt6_has_peer(rt) ? rt6_peer_ptr(rt) : NULL;
> +	struct dst_entry *dst = &rt->dst;
> +	unsigned long old = dst->_metrics;
> +
> +	if (!(rt->dst.flags & DST_HOST) || dst_metrics_read_only(dst))
> +		return;
> +	if (peer && dst_metrics_ptr(dst) == peer->metrics)
> +		return;
> +
> +	dst->ops->cow_metrics(dst, old);
> +	if (dst->_metrics != old) {
> +		u32 *old_p = __DST_METRICS_PTR(old);
> +
> +		memcpy(dst_metrics_ptr(dst), old_p, RTAX_MAX * sizeof(u32));
> +		kfree(old_p);
> +	}
> +}

Hmmm...  if inet_metrics_new() is true then ->cow_metrics() will copy the
metrics from old to new.  So you therefore shouldn't have to do the copy
explicitly here.

If inet_metrics_new() is not true, you are overwriting non-new metrics.

If there is some reason why what rt6_metrics_to_peer() is doing is OK, I'd
like you to explain this in the commit message.

Thanks!

  reply	other threads:[~2014-03-06 19:24 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-06  9:50 [PATCH net] ipv6: do not overwrite inetpeer metrics prematurely Michal Kubecek
2014-03-06 19:24 ` David Miller [this message]
2014-03-06 20:06   ` Michal Kubecek
2014-03-07 12:36     ` [PATCH net v2] " Michal Kubecek
2014-03-07 20:52     ` [PATCH net] " David Miller
2014-03-07 21:38       ` Michal Kubecek
2014-03-08  8:34         ` Hannes Frederic Sowa
2014-03-08  8:06       ` Hannes Frederic Sowa
2014-03-10  0:26         ` David Miller
2014-03-10  0:52           ` Hannes Frederic Sowa
2014-03-10  5:03             ` David Miller
2014-03-10  8:15               ` Michal Kubecek
2014-03-10 12:00                 ` Hannes Frederic Sowa
2014-03-10 13:15                   ` Michal Kubecek
2014-03-11  2:38                   ` David Miller
2014-03-11  9:53                     ` Michal Kubecek
2014-03-11 15:08                       ` Michal Kubecek
2014-03-11 15:20                         ` Hannes Frederic Sowa
2014-03-11 15:39                         ` Michal Kubecek
2014-03-25 19:11                           ` Hannes Frederic Sowa
2014-03-26 15:09                             ` Michal Kubecek
2014-03-26 15:42                             ` [PATCH net-next v3] " Michal Kubecek
2014-03-26 15:50                               ` Hannes Frederic Sowa
2014-03-26 15:56                                 ` Michal Kubecek
2014-03-26 16:05                                 ` [PATCH net-next v4] " Michal Kubecek
2014-03-27  5:06                                   ` Hannes Frederic Sowa
2014-03-27  7:43                                     ` Michal Kubecek
2014-03-27 12:04                                     ` [PATCH net-next v5] " Michal Kubecek
2014-03-27 16:30                                       ` Hannes Frederic Sowa
2014-03-27 19:09                                         ` David Miller
2014-03-12 20:54                         ` [PATCH net] " David Miller

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=20140306.142425.1675660751208500651.davem@davemloft.net \
    --to=davem@davemloft.net \
    --cc=jmorris@namei.org \
    --cc=kaber@trash.net \
    --cc=kuznet@ms2.inr.ac.ru \
    --cc=mkubecek@suse.cz \
    --cc=netdev@vger.kernel.org \
    --cc=yoshfuji@linux-ipv6.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).