netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: Brian Pomerantz <bapper@piratehaven.org>
Cc: netdev@vger.kernel.org, davem@davemloft.net,
	kuznet@ms2.inr.ac.ru, pekkas@netcore.fi, jmorris@namei.org,
	yoshfuji@linux-ipv6.org, kaber@coreworks.de,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] [IPV4] Fix secondary IP addresses after promotion
Date: Sat, 05 Nov 2005 01:34:16 +0100	[thread overview]
Message-ID: <436BFE08.6030906@trash.net> (raw)
In-Reply-To: <20051104184633.GA16256@skull.piratehaven.org>

[-- Attachment #1: Type: text/plain, Size: 1427 bytes --]

Brian Pomerantz wrote:
> When 3 or more IP addresses in the same subnet exist on a device and the
> first one is removed, only the promoted IP address can be reached.  Just
> after promotion of the next IP address, this fix spins through any more
> IP addresses on the interface and sends a NETDEV_UP notification for
> that address.  This repopulates the FIB with the proper route
> information.
> 
> @@ -294,7 +294,13 @@ static void inet_del_ifa(struct in_devic
>  		/* not sure if we should send a delete notify first? */
>  		promote->ifa_flags &= ~IFA_F_SECONDARY;
>  		rtmsg_ifa(RTM_NEWADDR, promote);
> -		notifier_call_chain(&inetaddr_chain, NETDEV_UP, promote);
> +
> +		/* update fib in the rest of this address list */
> +		ifa = promote;
> +		while (ifa != NULL) {
> +			notifier_call_chain(&inetaddr_chain, NETDEV_UP, ifa);
> +			ifa = ifa->ifa_next;
> +		}
>  	}
>  }

You assume all addresses following the primary addresses are secondary
addresses of the primary, which is not true with multiple primaries.
This patch (untested) makes sure only to send notification for real
secondaries of the deleted address. It also removes a racy double-
check for IN_DEV_PROMOTE_SECONDARIES - once we've decided to promote
an address checking again opens a window in which address promotion
could be disabled and we end up with only secondaries without a
primary address.

Signed-off-by: Patrick McHardy <kaber@trash.net>


[-- Attachment #2: x --]
[-- Type: text/plain, Size: 1535 bytes --]

diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 4ec4b2c..beb02cc 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -234,7 +234,7 @@ static void inet_del_ifa(struct in_devic
 			 int destroy)
 {
 	struct in_ifaddr *promote = NULL;
-	struct in_ifaddr *ifa1 = *ifap;
+	struct in_ifaddr *ifa, *ifa1 = *ifap;
 
 	ASSERT_RTNL();
 
@@ -243,7 +243,6 @@ static void inet_del_ifa(struct in_devic
 	 **/
 
 	if (!(ifa1->ifa_flags & IFA_F_SECONDARY)) {
-		struct in_ifaddr *ifa;
 		struct in_ifaddr **ifap1 = &ifa1->ifa_next;
 
 		while ((ifa = *ifap1) != NULL) {
@@ -283,19 +282,25 @@ static void inet_del_ifa(struct in_devic
 	 */
 	rtmsg_ifa(RTM_DELADDR, ifa1);
 	notifier_call_chain(&inetaddr_chain, NETDEV_DOWN, ifa1);
+
+	if (promote) {
+		/* not sure if we should send a delete notify first? */
+		promote->ifa_flags &= ~IFA_F_SECONDARY;
+		rtmsg_ifa(RTM_NEWADDR, promote);
+		for (ifa = promote; ifa; ifa = ifa->ifa_next) {
+			if (ifa1->ifa_mask != ifa->ifa_mask ||
+			    !inet_ifa_match(ifa1->ifa_address, ifa))
+				continue;
+			notifier_call_chain(&inetaddr_chain, NETDEV_UP, ifa);
+		}
+	}
+
 	if (destroy) {
 		inet_free_ifa(ifa1);
 
 		if (!in_dev->ifa_list)
 			inetdev_destroy(in_dev);
 	}
-
-	if (promote && IN_DEV_PROMOTE_SECONDARIES(in_dev)) {
-		/* not sure if we should send a delete notify first? */
-		promote->ifa_flags &= ~IFA_F_SECONDARY;
-		rtmsg_ifa(RTM_NEWADDR, promote);
-		notifier_call_chain(&inetaddr_chain, NETDEV_UP, promote);
-	}
 }
 
 static int inet_insert_ifa(struct in_ifaddr *ifa)

  reply	other threads:[~2005-11-05  0:34 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-04 18:46 [PATCH] [IPV4] Fix secondary IP addresses after promotion Brian Pomerantz
2005-11-05  0:34 ` Patrick McHardy [this message]
2005-11-05  0:58   ` Brian Pomerantz
2005-11-05  1:07   ` Thomas Graf
2005-11-05  1:21     ` Patrick McHardy
2005-11-05  4:28       ` Patrick McHardy
2005-11-05 13:46         ` Thomas Graf
2005-11-07 21:50           ` Thomas Graf
2005-11-08 14:11             ` Patrick McHardy
2005-11-09  0:56               ` Thomas Graf
2005-11-11 13:16                 ` Patrick McHardy
2005-11-16 19:21               ` Brian Pomerantz
2005-11-05 18:39     ` Alexey Kuznetsov
2005-11-05 19:06       ` Thomas Graf

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=436BFE08.6030906@trash.net \
    --to=kaber@trash.net \
    --cc=bapper@piratehaven.org \
    --cc=davem@davemloft.net \
    --cc=jmorris@namei.org \
    --cc=kaber@coreworks.de \
    --cc=kuznet@ms2.inr.ac.ru \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pekkas@netcore.fi \
    --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).