netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laszlo Attila Toth <panther@balabit.hu>
To: David Miller <davem@davemloft.net>, Patrick McHardy <kaber@trash.net>
Cc: Jarek Poplawski <jarkao2@o2.pl>,
	netdev@vger.kernel.org, netfilter-devel@vger.kernel.org,
	Laszlo Attila Toth <panther@balabit.hu>
Subject: [PATCHv7 2/5][RESEND] rtnetlink: send a single notification on device state changes
Date: Tue, 18 Dec 2007 13:29:55 +0100	[thread overview]
Message-ID: <119798099767-git-send-email-panther@balabit.hu> (raw)
In-Reply-To: <11979809963141-git-send-email-panther@balabit.hu>
In-Reply-To: <1196352710402-git-send-email-panther@balabit.hu>

In do_setlink() a single notification is sent at the end of the function
if any modification occured. If the address has been changed, another
notification is sent.

Both of them is required because originally only the NETDEV_CHANGEADDR notification
was sent and although device state change implies address change, some programs may
expect the original notification. It remains for compatibity.

Signed-off-by: Laszlo Attila Toth <panther@balabit.hu>
---

 net/core/rtnetlink.c |   27 ++++++++++++++++++++-------
 1 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index f95c6c5..6be8608 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -542,7 +542,7 @@ int rtnl_put_cacheinfo(struct sk_buff *skb, struct dst_entry *dst, u32 id,
 
 EXPORT_SYMBOL_GPL(rtnl_put_cacheinfo);
 
-static void set_operstate(struct net_device *dev, unsigned char transition)
+static int set_operstate(struct net_device *dev, unsigned char transition)
 {
 	unsigned char operstate = dev->operstate;
 
@@ -563,8 +563,9 @@ static void set_operstate(struct net_device *dev, unsigned char transition)
 
 	if (dev->operstate != operstate) {
 		dev->operstate = operstate;
-		netdev_state_change(dev);
-	}
+		return 1;
+	} else
+		return 0;
 }
 
 static void copy_rtnl_link_stats(struct rtnl_link_stats *a,
@@ -858,6 +859,7 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
 	if (tb[IFLA_BROADCAST]) {
 		nla_memcpy(dev->broadcast, tb[IFLA_BROADCAST], dev->addr_len);
 		send_addr_notify = 1;
+		modified = 1;
 	}
 
 	if (ifm->ifi_flags || ifm->ifi_change) {
@@ -870,14 +872,21 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
 		dev_change_flags(dev, flags);
 	}
 
-	if (tb[IFLA_TXQLEN])
-		dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]);
+	if (tb[IFLA_TXQLEN]) {
+		if (dev->tx_queue_len != nla_get_u32(tb[IFLA_TXQLEN])) {
+			dev->tx_queue_len = nla_get_u32(tb[IFLA_TXQLEN]);
+			modified = 1;
+		}
+	}
 
 	if (tb[IFLA_OPERSTATE])
-		set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE]));
+		modified |= set_operstate(dev, nla_get_u8(tb[IFLA_OPERSTATE]));
 
 	if (tb[IFLA_LINKMODE]) {
-		dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]);
+		if (dev->link_mode != nla_get_u8(tb[IFLA_LINKMODE])) {
+			dev->link_mode = nla_get_u8(tb[IFLA_LINKMODE]);
+			modified = 1;
+		} 
 	}
 
 	err = 0;
@@ -891,6 +900,10 @@ errout:
 
 	if (send_addr_notify)
 		call_netdevice_notifiers(NETDEV_CHANGEADDR, dev);
+
+	if (modified)
+		netdev_state_change(dev);
+
 	return err;
 }
 

  parent reply	other threads:[~2007-12-18 12:29 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <ifgroup-20071129-165736-1196351856-panther@balabit.hu>
2007-11-29 16:11 ` [PATCHv7 0/5 + 3] Interface group patches Laszlo Attila Toth
2007-11-29 16:25   ` Patrick McHardy
2007-11-29 16:39     ` Laszlo Attila Toth
2007-11-29 16:11 ` [PATCHv7 1/5] Remove unnecessary locks from rtnetlink (in do_setlink) Laszlo Attila Toth
2007-11-30 22:13   ` Jarek Poplawski
2007-12-03 11:59     ` Laszlo Attila Toth
2007-12-18 12:29   ` [PATCHv7 1/5][RESEND] Remove unnecessary locks from rtnetlink Laszlo Attila Toth
2007-11-29 16:11 ` [PATCHv7 2/5] rtnetlink: send a single notification on device state changes Laszlo Attila Toth
2007-11-30 23:24   ` Jarek Poplawski
2007-12-03 11:40     ` Laszlo Attila Toth
2007-12-03 13:37       ` Jarek Poplawski
2007-12-18 12:29   ` Laszlo Attila Toth [this message]
2007-11-29 16:11 ` [PATCHv7 3/5] Interface group: core (netlink) part Laszlo Attila Toth
2007-11-29 16:11 ` [PATCHv7 4/5] Ifgroup read/write support in sysfs Laszlo Attila Toth
2007-11-29 16:11 ` [PATCHv7 5/5] Netfilter Interface group match Laszlo Attila Toth
2007-11-29 16:11 ` [PATCHv7 iptables] " Laszlo Attila Toth
2007-12-01 21:19   ` Jarek Poplawski
2007-12-01 21:23     ` Jarek Poplawski
2007-11-29 16:11 ` [PATCHv7 iproute2 1/2] Added IFLA_NET_NS_PID as in kernel v2.6.24-rc1 Laszlo Attila Toth
2007-11-29 16:11 ` [PATCHv7 iproute2 2/2] Interface group as new ip link option Laszlo Attila Toth
2007-12-01 22:10   ` Jarek Poplawski
2007-12-18 12:29   ` [PATCHv7 iproute2 2/2][RESEND] " Laszlo Attila Toth

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=119798099767-git-send-email-panther@balabit.hu \
    --to=panther@balabit.hu \
    --cc=davem@davemloft.net \
    --cc=jarkao2@o2.pl \
    --cc=kaber@trash.net \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@vger.kernel.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).