All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next 1/2] ipv4: provide addr and netconf dump consistency info
@ 2013-03-22 14:42 Nicolas Dichtel
  2013-03-22 14:42 ` [PATCH net-next 2/2] ipv6: " Nicolas Dichtel
  0 siblings, 1 reply; 15+ messages in thread
From: Nicolas Dichtel @ 2013-03-22 14:42 UTC (permalink / raw)
  To: netdev; +Cc: davem, junwei.zhang, hongjun.li, Nicolas Dichtel

This patch takes benefit of dev_addr_genid and dev_base_seq to check if a change
occurs during a netlink dump. If a change is detected, the flag NLM_F_DUMP_INTR
is set in the first message after the dump was interrupted.

Reported-by: Junwei Zhang <junwei.zhang@6wind.com>
Reported-by: Hongjun Li <hongjun.li@6wind.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 net/ipv4/devinet.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index af57bba..158ca5e 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1499,6 +1499,8 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
 		idx = 0;
 		head = &net->dev_index_head[h];
 		rcu_read_lock();
+		cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
+			  net->dev_base_seq;
 		hlist_for_each_entry_rcu(dev, head, index_hlist) {
 			if (idx < s_idx)
 				goto cont;
@@ -1519,6 +1521,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
 					rcu_read_unlock();
 					goto done;
 				}
+				nl_dump_check_consistent(cb, nlmsg_hdr(skb));
 			}
 cont:
 			idx++;
@@ -1808,6 +1811,8 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
 		idx = 0;
 		head = &net->dev_index_head[h];
 		rcu_read_lock();
+		cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
+			  net->dev_base_seq;
 		hlist_for_each_entry_rcu(dev, head, index_hlist) {
 			if (idx < s_idx)
 				goto cont;
@@ -1825,6 +1830,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
 				rcu_read_unlock();
 				goto done;
 			}
+			nl_dump_check_consistent(cb, nlmsg_hdr(skb));
 cont:
 			idx++;
 		}
-- 
1.8.0.1

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

* [PATCH net-next 2/2] ipv6: provide addr and netconf dump consistency info
  2013-03-22 14:42 [PATCH net-next 1/2] ipv4: " Nicolas Dichtel
@ 2013-03-22 14:42 ` Nicolas Dichtel
  2013-03-22 16:22   ` Nicolas Dichtel
  0 siblings, 1 reply; 15+ messages in thread
From: Nicolas Dichtel @ 2013-03-22 14:42 UTC (permalink / raw)
  To: netdev; +Cc: davem, junwei.zhang, hongjun.li, Nicolas Dichtel

This patch adds a dev_addr_genid for IPv6. The goal is to use it, combined with
dev_base_seq to check if a change occurs during a netlink dump.
If a change is detected, the flag NLM_F_DUMP_INTR is set in the first message
after the dump was interrupted.

Note that only dump of unicast addresses is checked (multicast and anycast are
not checked).

Reported-by: Junwei Zhang <junwei.zhang@6wind.com>
Reported-by: Hongjun Li <hongjun.li@6wind.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 include/net/netns/ipv6.h | 1 +
 net/ipv6/addrconf.c      | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
index 1242f37..005e2c2 100644
--- a/include/net/netns/ipv6.h
+++ b/include/net/netns/ipv6.h
@@ -71,6 +71,7 @@ struct netns_ipv6 {
 	struct fib_rules_ops	*mr6_rules_ops;
 #endif
 #endif
+	atomic_t		dev_addr_genid;
 };
 
 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index fa36a67..d0e40d4 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -622,6 +622,8 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
 		idx = 0;
 		head = &net->dev_index_head[h];
 		rcu_read_lock();
+		cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
+			  net->dev_base_seq;
 		hlist_for_each_entry_rcu(dev, head, index_hlist) {
 			if (idx < s_idx)
 				goto cont;
@@ -639,6 +641,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
 				rcu_read_unlock();
 				goto done;
 			}
+			nl_dump_check_consistent(cb, nlmsg_hdr(skb));
 cont:
 			idx++;
 		}
@@ -3875,6 +3878,7 @@ static int in6_dump_addrs(struct inet6_dev *idev, struct sk_buff *skb,
 						NLM_F_MULTI);
 			if (err <= 0)
 				break;
+			nl_dump_check_consistent(cb, nlmsg_hdr(skb));
 		}
 		break;
 	}
@@ -3932,6 +3936,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
 	s_ip_idx = ip_idx = cb->args[2];
 
 	rcu_read_lock();
+	cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
 	for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
 		idx = 0;
 		head = &net->dev_index_head[h];
@@ -4409,6 +4414,8 @@ errout:
 
 static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
 {
+	struct net *net = dev_net(ifp->idev->dev);
+
 	inet6_ifa_notify(event ? : RTM_NEWADDR, ifp);
 
 	switch (event) {
@@ -4434,6 +4441,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
 			dst_free(&ifp->rt->dst);
 		break;
 	}
+	atomic_inc(&net->ipv6.dev_addr_genid);
 }
 
 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
-- 
1.8.0.1

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

* [PATCH iproute2] libnetlink: check flag NLM_F_DUMP_INTR during dumps
@ 2013-03-22 14:45 Nicolas Dichtel
  2013-03-22 14:59 ` Eric Dumazet
  0 siblings, 1 reply; 15+ messages in thread
From: Nicolas Dichtel @ 2013-03-22 14:45 UTC (permalink / raw)
  To: shemminger; +Cc: netdev, Nicolas Dichtel

When this flag is set, it means that dump was interrupted and result may be
wrong. Ask user to restart.

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 lib/libnetlink.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index f262959..91991cf 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -230,6 +230,12 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth,
 				    h->nlmsg_seq != rth->dump)
 					goto skip_it;
 
+				if (h->nlmsg_flags & NLM_F_DUMP_INTR) {
+					fprintf(stderr,
+						"Dump was interrupted, please restart.\n");
+					return -1;
+				}
+
 				if (h->nlmsg_type == NLMSG_DONE) {
 					found_done = 1;
 					break; /* process next filter */
-- 
1.8.0.1

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

* Re: [PATCH iproute2] libnetlink: check flag NLM_F_DUMP_INTR during dumps
  2013-03-22 14:45 [PATCH iproute2] libnetlink: check flag NLM_F_DUMP_INTR during dumps Nicolas Dichtel
@ 2013-03-22 14:59 ` Eric Dumazet
  2013-03-22 15:03   ` Nicolas Dichtel
  0 siblings, 1 reply; 15+ messages in thread
From: Eric Dumazet @ 2013-03-22 14:59 UTC (permalink / raw)
  To: Nicolas Dichtel; +Cc: shemminger, netdev

On Fri, 2013-03-22 at 15:45 +0100, Nicolas Dichtel wrote:
> When this flag is set, it means that dump was interrupted and result may be
> wrong. Ask user to restart.
> 
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>


Do we have a guarantee this will complete eventually, on some hosts
constantly adding removing entries ?

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

* Re: [PATCH iproute2] libnetlink: check flag NLM_F_DUMP_INTR during dumps
  2013-03-22 14:59 ` Eric Dumazet
@ 2013-03-22 15:03   ` Nicolas Dichtel
  2013-03-22 15:14     ` Eric Dumazet
  0 siblings, 1 reply; 15+ messages in thread
From: Nicolas Dichtel @ 2013-03-22 15:03 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: shemminger, netdev

Le 22/03/2013 15:59, Eric Dumazet a écrit :
> On Fri, 2013-03-22 at 15:45 +0100, Nicolas Dichtel wrote:
>> When this flag is set, it means that dump was interrupted and result may be
>> wrong. Ask user to restart.
>>
>> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
>
>
> Do we have a guarantee this will complete eventually, on some hosts
> constantly adding removing entries ?
>

No. You mean it will be better to just print a warning and continue the dump?

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

* Re: [PATCH iproute2] libnetlink: check flag NLM_F_DUMP_INTR during dumps
  2013-03-22 15:03   ` Nicolas Dichtel
@ 2013-03-22 15:14     ` Eric Dumazet
  2013-03-22 15:22       ` Thomas Graf
  0 siblings, 1 reply; 15+ messages in thread
From: Eric Dumazet @ 2013-03-22 15:14 UTC (permalink / raw)
  To: nicolas.dichtel; +Cc: shemminger, netdev

On Fri, 2013-03-22 at 16:03 +0100, Nicolas Dichtel wrote:
> Le 22/03/2013 15:59, Eric Dumazet a écrit :
> > On Fri, 2013-03-22 at 15:45 +0100, Nicolas Dichtel wrote:
> >> When this flag is set, it means that dump was interrupted and result may be
> >> wrong. Ask user to restart.
> >>
> >> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> >
> >
> > Do we have a guarantee this will complete eventually, on some hosts
> > constantly adding removing entries ?
> >
> 
> No. You mean it will be better to just print a warning and continue the dump?
> --

I would not break the dump, return the indication, so that caller can
chose to restart the loop one or two times.

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

* Re: [PATCH iproute2] libnetlink: check flag NLM_F_DUMP_INTR during dumps
  2013-03-22 15:14     ` Eric Dumazet
@ 2013-03-22 15:22       ` Thomas Graf
  2013-03-22 15:42         ` [PATCH iproute2 v2] " Nicolas Dichtel
  0 siblings, 1 reply; 15+ messages in thread
From: Thomas Graf @ 2013-03-22 15:22 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: nicolas.dichtel, shemminger, netdev

On 03/22/13 at 08:14am, Eric Dumazet wrote:
> On Fri, 2013-03-22 at 16:03 +0100, Nicolas Dichtel wrote:
> > Le 22/03/2013 15:59, Eric Dumazet a écrit :
> > > On Fri, 2013-03-22 at 15:45 +0100, Nicolas Dichtel wrote:
> > >> When this flag is set, it means that dump was interrupted and result may be
> > >> wrong. Ask user to restart.
> > >>
> > >> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> > >
> > >
> > > Do we have a guarantee this will complete eventually, on some hosts
> > > constantly adding removing entries ?
> > >
> > 
> > No. You mean it will be better to just print a warning and continue the dump?
> 
> I would not break the dump, return the indication, so that caller can
> chose to restart the loop one or two times.

Right, I would do it on an informal level at first. In fact libnl
will do an automatic restart of cache refills but I'm considering
to make it configurable for the application.

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

* [PATCH iproute2 v2] libnetlink: check flag NLM_F_DUMP_INTR during dumps
  2013-03-22 15:22       ` Thomas Graf
@ 2013-03-22 15:42         ` Nicolas Dichtel
  2013-03-22 15:49           ` Eric Dumazet
  0 siblings, 1 reply; 15+ messages in thread
From: Nicolas Dichtel @ 2013-03-22 15:42 UTC (permalink / raw)
  To: tgraf; +Cc: shemminger, netdev, eric.dumazet, Nicolas Dichtel

When this flag is set, it means that dump was interrupted and result may be
wrong. Inform the user and let him choose to restart or not.

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---

v2: do not stop the dump, only display a warning

 lib/libnetlink.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index f262959..1a882b2 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -230,6 +230,10 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth,
 				    h->nlmsg_seq != rth->dump)
 					goto skip_it;
 
+				if (h->nlmsg_flags & NLM_F_DUMP_INTR)
+					fprintf(stderr,
+						"Dump was interrupted and may be wrong.\n");
+
 				if (h->nlmsg_type == NLMSG_DONE) {
 					found_done = 1;
 					break; /* process next filter */
-- 
1.8.0.1

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

* Re: [PATCH iproute2 v2] libnetlink: check flag NLM_F_DUMP_INTR during dumps
  2013-03-22 15:42         ` [PATCH iproute2 v2] " Nicolas Dichtel
@ 2013-03-22 15:49           ` Eric Dumazet
  2013-03-22 16:34             ` [PATCH iproute2 v3] " Nicolas Dichtel
  0 siblings, 1 reply; 15+ messages in thread
From: Eric Dumazet @ 2013-03-22 15:49 UTC (permalink / raw)
  To: Nicolas Dichtel; +Cc: tgraf, shemminger, netdev

On Fri, 2013-03-22 at 16:42 +0100, Nicolas Dichtel wrote:
> When this flag is set, it means that dump was interrupted and result may be
> wrong. Inform the user and let him choose to restart or not.
> 
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> ---
> 
> v2: do not stop the dump, only display a warning
> 
>  lib/libnetlink.c | 4 ++++
>  1 file changed, 4 insertions(+)
> 
> diff --git a/lib/libnetlink.c b/lib/libnetlink.c
> index f262959..1a882b2 100644
> --- a/lib/libnetlink.c
> +++ b/lib/libnetlink.c
> @@ -230,6 +230,10 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth,
>  				    h->nlmsg_seq != rth->dump)
>  					goto skip_it;
>  
> +				if (h->nlmsg_flags & NLM_F_DUMP_INTR)
> +					fprintf(stderr,
> +						"Dump was interrupted and may be wrong.\n");
> +
>  				if (h->nlmsg_type == NLMSG_DONE) {
>  					found_done = 1;
>  					break; /* process next filter */


How many times this will be displayed ?

Please try to cook something that wont emit one warning per 8KB fetched
from the kernel ;)

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

* Re: [PATCH net-next 2/2] ipv6: provide addr and netconf dump consistency info
  2013-03-22 14:42 ` [PATCH net-next 2/2] ipv6: " Nicolas Dichtel
@ 2013-03-22 16:22   ` Nicolas Dichtel
  2013-03-22 16:28     ` [PATCH net-next v2 1/2] ipv4: " Nicolas Dichtel
  0 siblings, 1 reply; 15+ messages in thread
From: Nicolas Dichtel @ 2013-03-22 16:22 UTC (permalink / raw)
  To: Nicolas Dichtel; +Cc: netdev, davem, junwei.zhang, hongjun.li

Please, drop both patches. If we dump addresses via rtnl_dump_all(), seq is not 
reset and thus NLM_F_DUMP_INTR is always set when switching from ipv4 to ipv6 
family.

I will send a new patch.

Nicolas

Le 22/03/2013 15:42, Nicolas Dichtel a écrit :
> This patch adds a dev_addr_genid for IPv6. The goal is to use it, combined with
> dev_base_seq to check if a change occurs during a netlink dump.
> If a change is detected, the flag NLM_F_DUMP_INTR is set in the first message
> after the dump was interrupted.
>
> Note that only dump of unicast addresses is checked (multicast and anycast are
> not checked).
>
> Reported-by: Junwei Zhang <junwei.zhang@6wind.com>
> Reported-by: Hongjun Li <hongjun.li@6wind.com>
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
> ---
>   include/net/netns/ipv6.h | 1 +
>   net/ipv6/addrconf.c      | 8 ++++++++
>   2 files changed, 9 insertions(+)
>
> diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
> index 1242f37..005e2c2 100644
> --- a/include/net/netns/ipv6.h
> +++ b/include/net/netns/ipv6.h
> @@ -71,6 +71,7 @@ struct netns_ipv6 {
>   	struct fib_rules_ops	*mr6_rules_ops;
>   #endif
>   #endif
> +	atomic_t		dev_addr_genid;
>   };
>
>   #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
> diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
> index fa36a67..d0e40d4 100644
> --- a/net/ipv6/addrconf.c
> +++ b/net/ipv6/addrconf.c
> @@ -622,6 +622,8 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
>   		idx = 0;
>   		head = &net->dev_index_head[h];
>   		rcu_read_lock();
> +		cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
> +			  net->dev_base_seq;
>   		hlist_for_each_entry_rcu(dev, head, index_hlist) {
>   			if (idx < s_idx)
>   				goto cont;
> @@ -639,6 +641,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
>   				rcu_read_unlock();
>   				goto done;
>   			}
> +			nl_dump_check_consistent(cb, nlmsg_hdr(skb));
>   cont:
>   			idx++;
>   		}
> @@ -3875,6 +3878,7 @@ static int in6_dump_addrs(struct inet6_dev *idev, struct sk_buff *skb,
>   						NLM_F_MULTI);
>   			if (err <= 0)
>   				break;
> +			nl_dump_check_consistent(cb, nlmsg_hdr(skb));
>   		}
>   		break;
>   	}
> @@ -3932,6 +3936,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
>   	s_ip_idx = ip_idx = cb->args[2];
>
>   	rcu_read_lock();
> +	cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
>   	for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
>   		idx = 0;
>   		head = &net->dev_index_head[h];
> @@ -4409,6 +4414,8 @@ errout:
>
>   static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
>   {
> +	struct net *net = dev_net(ifp->idev->dev);
> +
>   	inet6_ifa_notify(event ? : RTM_NEWADDR, ifp);
>
>   	switch (event) {
> @@ -4434,6 +4441,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
>   			dst_free(&ifp->rt->dst);
>   		break;
>   	}
> +	atomic_inc(&net->ipv6.dev_addr_genid);
>   }
>
>   static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
>

-- 
Nicolas DICHTEL
6WIND
R&D Engineer

Tel: +33 1 39 30 92 41
Fax: +33 1 39 30 92 11
nicolas.dichtel@6wind.com
www.6wind.com
www.6windblog.com
Twitter: http://twitter.com/6windsoftware

Ce courriel ainsi que toutes les pièces jointes, est uniquement destiné à son ou 
ses destinataires. Il contient des informations confidentielles qui sont la 
propriété de 6WIND. Toute révélation, distribution ou copie des informations 
qu'il contient est strictement interdite. Si vous avez reçu ce message par 
erreur, veuillez immédiatement le signaler à l'émetteur et détruire toutes les 
données reçues.

This e-mail message, including any attachments, is for the sole use of the 
intended recipient(s) and contains information that is confidential and 
proprietary to 6WIND. All unauthorized review, use, disclosure or distribution 
is prohibited. If you are not the intended recipient, please contact the sender 
by reply e-mail and destroy all copies of the original message.

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

* [PATCH net-next v2 1/2] ipv4: provide addr and netconf dump consistency info
  2013-03-22 16:22   ` Nicolas Dichtel
@ 2013-03-22 16:28     ` Nicolas Dichtel
  2013-03-22 16:28       ` [PATCH net-next v2 2/2] ipv6: " Nicolas Dichtel
  2013-03-24 21:16       ` [PATCH net-next v2 1/2] ipv4: " David Miller
  0 siblings, 2 replies; 15+ messages in thread
From: Nicolas Dichtel @ 2013-03-22 16:28 UTC (permalink / raw)
  To: netdev; +Cc: davem, junwei.zhang, hongjun.li, Nicolas Dichtel

This patch takes benefit of dev_addr_genid and dev_base_seq to check if a change
occurs during a netlink dump. If a change is detected, the flag NLM_F_DUMP_INTR
is set in the first message after the dump was interrupted.

Note that seq and prev_seq must be reset between each family in rtnl_dump_all()
because they are specific to each family.

Reported-by: Junwei Zhang <junwei.zhang@6wind.com>
Reported-by: Hongjun Li <hongjun.li@6wind.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---

v2: reset seq and prev_seq in rtnl_dump_all()

 net/core/rtnetlink.c | 5 ++++-
 net/ipv4/devinet.c   | 6 ++++++
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 9a9b99e..4493d7a 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1955,8 +1955,11 @@ static int rtnl_dump_all(struct sk_buff *skb, struct netlink_callback *cb)
 		if (rtnl_msg_handlers[idx] == NULL ||
 		    rtnl_msg_handlers[idx][type].dumpit == NULL)
 			continue;
-		if (idx > s_idx)
+		if (idx > s_idx) {
 			memset(&cb->args[0], 0, sizeof(cb->args));
+			cb->prev_seq = 0;
+			cb->seq = 0;
+		}
 		if (rtnl_msg_handlers[idx][type].dumpit(skb, cb))
 			break;
 	}
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index af57bba..158ca5e 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -1499,6 +1499,8 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
 		idx = 0;
 		head = &net->dev_index_head[h];
 		rcu_read_lock();
+		cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
+			  net->dev_base_seq;
 		hlist_for_each_entry_rcu(dev, head, index_hlist) {
 			if (idx < s_idx)
 				goto cont;
@@ -1519,6 +1521,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
 					rcu_read_unlock();
 					goto done;
 				}
+				nl_dump_check_consistent(cb, nlmsg_hdr(skb));
 			}
 cont:
 			idx++;
@@ -1808,6 +1811,8 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
 		idx = 0;
 		head = &net->dev_index_head[h];
 		rcu_read_lock();
+		cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
+			  net->dev_base_seq;
 		hlist_for_each_entry_rcu(dev, head, index_hlist) {
 			if (idx < s_idx)
 				goto cont;
@@ -1825,6 +1830,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
 				rcu_read_unlock();
 				goto done;
 			}
+			nl_dump_check_consistent(cb, nlmsg_hdr(skb));
 cont:
 			idx++;
 		}
-- 
1.8.0.1

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

* [PATCH net-next v2 2/2] ipv6: provide addr and netconf dump consistency info
  2013-03-22 16:28     ` [PATCH net-next v2 1/2] ipv4: " Nicolas Dichtel
@ 2013-03-22 16:28       ` Nicolas Dichtel
  2013-03-24 21:16       ` [PATCH net-next v2 1/2] ipv4: " David Miller
  1 sibling, 0 replies; 15+ messages in thread
From: Nicolas Dichtel @ 2013-03-22 16:28 UTC (permalink / raw)
  To: netdev; +Cc: davem, junwei.zhang, hongjun.li, Nicolas Dichtel

This patch adds a dev_addr_genid for IPv6. The goal is to use it, combined with
dev_base_seq to check if a change occurs during a netlink dump.
If a change is detected, the flag NLM_F_DUMP_INTR is set in the first message
after the dump was interrupted.

Note that only dump of unicast addresses is checked (multicast and anycast are
not checked).

Reported-by: Junwei Zhang <junwei.zhang@6wind.com>
Reported-by: Hongjun Li <hongjun.li@6wind.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
 include/net/netns/ipv6.h | 1 +
 net/ipv6/addrconf.c      | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
index 1242f37..005e2c2 100644
--- a/include/net/netns/ipv6.h
+++ b/include/net/netns/ipv6.h
@@ -71,6 +71,7 @@ struct netns_ipv6 {
 	struct fib_rules_ops	*mr6_rules_ops;
 #endif
 #endif
+	atomic_t		dev_addr_genid;
 };
 
 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index fa36a67..d0e40d4 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -622,6 +622,8 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
 		idx = 0;
 		head = &net->dev_index_head[h];
 		rcu_read_lock();
+		cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
+			  net->dev_base_seq;
 		hlist_for_each_entry_rcu(dev, head, index_hlist) {
 			if (idx < s_idx)
 				goto cont;
@@ -639,6 +641,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
 				rcu_read_unlock();
 				goto done;
 			}
+			nl_dump_check_consistent(cb, nlmsg_hdr(skb));
 cont:
 			idx++;
 		}
@@ -3875,6 +3878,7 @@ static int in6_dump_addrs(struct inet6_dev *idev, struct sk_buff *skb,
 						NLM_F_MULTI);
 			if (err <= 0)
 				break;
+			nl_dump_check_consistent(cb, nlmsg_hdr(skb));
 		}
 		break;
 	}
@@ -3932,6 +3936,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
 	s_ip_idx = ip_idx = cb->args[2];
 
 	rcu_read_lock();
+	cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
 	for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
 		idx = 0;
 		head = &net->dev_index_head[h];
@@ -4409,6 +4414,8 @@ errout:
 
 static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
 {
+	struct net *net = dev_net(ifp->idev->dev);
+
 	inet6_ifa_notify(event ? : RTM_NEWADDR, ifp);
 
 	switch (event) {
@@ -4434,6 +4441,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
 			dst_free(&ifp->rt->dst);
 		break;
 	}
+	atomic_inc(&net->ipv6.dev_addr_genid);
 }
 
 static void ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
-- 
1.8.0.1

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

* [PATCH iproute2 v3] libnetlink: check flag NLM_F_DUMP_INTR during dumps
  2013-03-22 15:49           ` Eric Dumazet
@ 2013-03-22 16:34             ` Nicolas Dichtel
  2013-03-24 21:17               ` [PATCH net-next v2 2/2] ipv6: provide addr and netconf dump consistency info David Miller
  0 siblings, 1 reply; 15+ messages in thread
From: Nicolas Dichtel @ 2013-03-22 16:34 UTC (permalink / raw)
  To: eric.dumazet; +Cc: shemminger, netdev, tgraf, Nicolas Dichtel

When this flag is set, it means that dump was interrupted and result may be
inconsistent.

Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---

v3: display the warning only once
v2: do not stop the dump, only display a warning

 lib/libnetlink.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/lib/libnetlink.c b/lib/libnetlink.c
index f262959..04201cd 100644
--- a/lib/libnetlink.c
+++ b/lib/libnetlink.c
@@ -194,6 +194,7 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth,
 		.msg_iovlen = 1,
 	};
 	char buf[16384];
+	int dump_intr = 0;
 
 	iov.iov_base = buf;
 	while (1) {
@@ -230,6 +231,9 @@ int rtnl_dump_filter_l(struct rtnl_handle *rth,
 				    h->nlmsg_seq != rth->dump)
 					goto skip_it;
 
+				if (h->nlmsg_flags & NLM_F_DUMP_INTR)
+					dump_intr = 1;
+
 				if (h->nlmsg_type == NLMSG_DONE) {
 					found_done = 1;
 					break; /* process next filter */
@@ -254,8 +258,12 @@ skip_it:
 			}
 		}
 
-		if (found_done)
+		if (found_done) {
+			if (dump_intr)
+				fprintf(stderr,
+					"Dump was interrupted and may be inconsistent.\n");
 			return 0;
+		}
 
 		if (msg.msg_flags & MSG_TRUNC) {
 			fprintf(stderr, "Message truncated\n");
-- 
1.8.0.1

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

* Re: [PATCH net-next v2 1/2] ipv4: provide addr and netconf dump consistency info
  2013-03-22 16:28     ` [PATCH net-next v2 1/2] ipv4: " Nicolas Dichtel
  2013-03-22 16:28       ` [PATCH net-next v2 2/2] ipv6: " Nicolas Dichtel
@ 2013-03-24 21:16       ` David Miller
  1 sibling, 0 replies; 15+ messages in thread
From: David Miller @ 2013-03-24 21:16 UTC (permalink / raw)
  To: nicolas.dichtel; +Cc: netdev, junwei.zhang, hongjun.li

From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Date: Fri, 22 Mar 2013 17:28:42 +0100

> This patch takes benefit of dev_addr_genid and dev_base_seq to check if a change
> occurs during a netlink dump. If a change is detected, the flag NLM_F_DUMP_INTR
> is set in the first message after the dump was interrupted.
> 
> Note that seq and prev_seq must be reset between each family in rtnl_dump_all()
> because they are specific to each family.
> 
> Reported-by: Junwei Zhang <junwei.zhang@6wind.com>
> Reported-by: Hongjun Li <hongjun.li@6wind.com>
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>

Applied.

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

* Re: [PATCH net-next v2 2/2] ipv6: provide addr and netconf dump consistency info
  2013-03-22 16:34             ` [PATCH iproute2 v3] " Nicolas Dichtel
@ 2013-03-24 21:17               ` David Miller
  0 siblings, 0 replies; 15+ messages in thread
From: David Miller @ 2013-03-24 21:17 UTC (permalink / raw)
  To: nicolas.dichtel; +Cc: netdev, junwei.zhang, hongjun.li

From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Date: Fri, 22 Mar 2013 17:34:02 +0100

> When this flag is set, it means that dump was interrupted and result may be
> inconsistent.
> 
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>

Applied.

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

end of thread, other threads:[~2013-03-24 21:17 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-22 14:45 [PATCH iproute2] libnetlink: check flag NLM_F_DUMP_INTR during dumps Nicolas Dichtel
2013-03-22 14:59 ` Eric Dumazet
2013-03-22 15:03   ` Nicolas Dichtel
2013-03-22 15:14     ` Eric Dumazet
2013-03-22 15:22       ` Thomas Graf
2013-03-22 15:42         ` [PATCH iproute2 v2] " Nicolas Dichtel
2013-03-22 15:49           ` Eric Dumazet
2013-03-22 16:34             ` [PATCH iproute2 v3] " Nicolas Dichtel
2013-03-24 21:17               ` [PATCH net-next v2 2/2] ipv6: provide addr and netconf dump consistency info David Miller
  -- strict thread matches above, loose matches on Subject: below --
2013-03-22 14:42 [PATCH net-next 1/2] ipv4: " Nicolas Dichtel
2013-03-22 14:42 ` [PATCH net-next 2/2] ipv6: " Nicolas Dichtel
2013-03-22 16:22   ` Nicolas Dichtel
2013-03-22 16:28     ` [PATCH net-next v2 1/2] ipv4: " Nicolas Dichtel
2013-03-22 16:28       ` [PATCH net-next v2 2/2] ipv6: " Nicolas Dichtel
2013-03-24 21:16       ` [PATCH net-next v2 1/2] ipv4: " David Miller

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.