All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net] net_sched: do not broadcast RTM_GETTFILTER result
@ 2016-10-10  3:25 Eric Dumazet
  2016-10-10 13:16 ` Jamal Hadi Salim
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Eric Dumazet @ 2016-10-10  3:25 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, Jamal Hadi Salim

From: Eric Dumazet <edumazet@google.com>

There are two ways to get tc filters from kernel to user space.

1) Full dump (tc_dump_tfilter())
2) RTM_GETTFILTER to get one precise filter, reducing overhead.

The second operation is unfortunately broadcasting its result,
polluting "tc monitor" users.

This patch makes sure only the requester gets the result, using
netlink_unicast() instead of rtnetlink_send()

Jamal cooked an iproute2 patch to implement "tc filter get" operation,
but other user space libraries already use RTM_GETTFILTER when a single
filter is queried, instead of dumping all filters.

Signed-off-by: Eric Dumazet <edumazet@google.com>
Cc: Jamal Hadi Salim <jhs@mojatatu.com>
---
 net/sched/cls_api.c |   18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/net/sched/cls_api.c b/net/sched/cls_api.c
index 11da7da0b7c4..2ee29a3375f6 100644
--- a/net/sched/cls_api.c
+++ b/net/sched/cls_api.c
@@ -101,7 +101,7 @@ EXPORT_SYMBOL(unregister_tcf_proto_ops);
 
 static int tfilter_notify(struct net *net, struct sk_buff *oskb,
 			  struct nlmsghdr *n, struct tcf_proto *tp,
-			  unsigned long fh, int event);
+			  unsigned long fh, int event, bool unicast);
 
 static void tfilter_notify_chain(struct net *net, struct sk_buff *oskb,
 				 struct nlmsghdr *n,
@@ -112,7 +112,7 @@ static void tfilter_notify_chain(struct net *net, struct sk_buff *oskb,
 
 	for (it_chain = chain; (tp = rtnl_dereference(*it_chain)) != NULL;
 	     it_chain = &tp->next)
-		tfilter_notify(net, oskb, n, tp, 0, event);
+		tfilter_notify(net, oskb, n, tp, 0, event, false);
 }
 
 /* Select new prio value from the range, managed by kernel. */
@@ -319,7 +319,8 @@ replay:
 
 			RCU_INIT_POINTER(*back, next);
 
-			tfilter_notify(net, skb, n, tp, fh, RTM_DELTFILTER);
+			tfilter_notify(net, skb, n, tp, fh,
+				       RTM_DELTFILTER, false);
 			tcf_destroy(tp, true);
 			err = 0;
 			goto errout;
@@ -345,14 +346,14 @@ replay:
 				struct tcf_proto *next = rtnl_dereference(tp->next);
 
 				tfilter_notify(net, skb, n, tp, fh,
-					       RTM_DELTFILTER);
+					       RTM_DELTFILTER, false);
 				if (tcf_destroy(tp, false))
 					RCU_INIT_POINTER(*back, next);
 			}
 			goto errout;
 		case RTM_GETTFILTER:
 			err = tfilter_notify(net, skb, n, tp, fh,
-					     RTM_NEWTFILTER);
+					     RTM_NEWTFILTER, true);
 			goto errout;
 		default:
 			err = -EINVAL;
@@ -367,7 +368,7 @@ replay:
 			RCU_INIT_POINTER(tp->next, rtnl_dereference(*back));
 			rcu_assign_pointer(*back, tp);
 		}
-		tfilter_notify(net, skb, n, tp, fh, RTM_NEWTFILTER);
+		tfilter_notify(net, skb, n, tp, fh, RTM_NEWTFILTER, false);
 	} else {
 		if (tp_created)
 			tcf_destroy(tp, true);
@@ -419,7 +420,7 @@ nla_put_failure:
 
 static int tfilter_notify(struct net *net, struct sk_buff *oskb,
 			  struct nlmsghdr *n, struct tcf_proto *tp,
-			  unsigned long fh, int event)
+			  unsigned long fh, int event, bool unicast)
 {
 	struct sk_buff *skb;
 	u32 portid = oskb ? NETLINK_CB(oskb).portid : 0;
@@ -433,6 +434,9 @@ static int tfilter_notify(struct net *net, struct sk_buff *oskb,
 		return -EINVAL;
 	}
 
+	if (unicast)
+		return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
+
 	return rtnetlink_send(skb, net, portid, RTNLGRP_TC,
 			      n->nlmsg_flags & NLM_F_ECHO);
 }

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

* Re: [PATCH net] net_sched: do not broadcast RTM_GETTFILTER result
  2016-10-10  3:25 [PATCH net] net_sched: do not broadcast RTM_GETTFILTER result Eric Dumazet
@ 2016-10-10 13:16 ` Jamal Hadi Salim
  2016-10-12 16:36 ` Cong Wang
  2016-10-13 13:54 ` David Miller
  2 siblings, 0 replies; 7+ messages in thread
From: Jamal Hadi Salim @ 2016-10-10 13:16 UTC (permalink / raw)
  To: Eric Dumazet, David Miller; +Cc: netdev

On 16-10-09 11:25 PM, Eric Dumazet wrote:
> From: Eric Dumazet <edumazet@google.com>
>
> There are two ways to get tc filters from kernel to user space.
>
> 1) Full dump (tc_dump_tfilter())
> 2) RTM_GETTFILTER to get one precise filter, reducing overhead.
>
> The second operation is unfortunately broadcasting its result,
> polluting "tc monitor" users.
>
> This patch makes sure only the requester gets the result, using
> netlink_unicast() instead of rtnetlink_send()
>
> Jamal cooked an iproute2 patch to implement "tc filter get" operation,
> but other user space libraries already use RTM_GETTFILTER when a single
> filter is queried, instead of dumping all filters.
>
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Acked-by: Jamal Hadi Salim <jhs@mojatatu.com>

I will send the iproute2 patch

cheers,
jamal

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

* Re: [PATCH net] net_sched: do not broadcast RTM_GETTFILTER result
  2016-10-10  3:25 [PATCH net] net_sched: do not broadcast RTM_GETTFILTER result Eric Dumazet
  2016-10-10 13:16 ` Jamal Hadi Salim
@ 2016-10-12 16:36 ` Cong Wang
  2016-10-13  7:46   ` Eric Dumazet
  2016-10-13 13:54 ` David Miller
  2 siblings, 1 reply; 7+ messages in thread
From: Cong Wang @ 2016-10-12 16:36 UTC (permalink / raw)
  To: Eric Dumazet; +Cc: David Miller, netdev, Jamal Hadi Salim

On Sun, Oct 9, 2016 at 8:25 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> +       if (unicast)
> +               return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);

Nit: rtnl_unicast() is simpler.

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

* Re: [PATCH net] net_sched: do not broadcast RTM_GETTFILTER result
  2016-10-12 16:36 ` Cong Wang
@ 2016-10-13  7:46   ` Eric Dumazet
  2016-10-13 11:54     ` Jamal Hadi Salim
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Dumazet @ 2016-10-13  7:46 UTC (permalink / raw)
  To: Cong Wang; +Cc: David Miller, netdev, Jamal Hadi Salim

On Wed, 2016-10-12 at 09:36 -0700, Cong Wang wrote:
> On Sun, Oct 9, 2016 at 8:25 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
> > +       if (unicast)
> > +               return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
> 
> Nit: rtnl_unicast() is simpler.

I copied code in rtnetlink_send(), I guess we could use rtnl_unicast()
there as well.

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

* Re: [PATCH net] net_sched: do not broadcast RTM_GETTFILTER result
  2016-10-13  7:46   ` Eric Dumazet
@ 2016-10-13 11:54     ` Jamal Hadi Salim
  0 siblings, 0 replies; 7+ messages in thread
From: Jamal Hadi Salim @ 2016-10-13 11:54 UTC (permalink / raw)
  To: Eric Dumazet, Cong Wang; +Cc: David Miller, netdev

On 16-10-13 03:46 AM, Eric Dumazet wrote:
> On Wed, 2016-10-12 at 09:36 -0700, Cong Wang wrote:
>> On Sun, Oct 9, 2016 at 8:25 PM, Eric Dumazet <eric.dumazet@gmail.com> wrote:
>>> +       if (unicast)
>>> +               return netlink_unicast(net->rtnl, skb, portid, MSG_DONTWAIT);
>>
>> Nit: rtnl_unicast() is simpler.
>
> I copied code in rtnetlink_send(), I guess we could use rtnl_unicast()
> there as well.

I would toss a coin and if it lands on tail then make the change ;->
(probably in a separate patch).

cheers,
jamal

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

* Re: [PATCH net] net_sched: do not broadcast RTM_GETTFILTER result
  2016-10-10  3:25 [PATCH net] net_sched: do not broadcast RTM_GETTFILTER result Eric Dumazet
  2016-10-10 13:16 ` Jamal Hadi Salim
  2016-10-12 16:36 ` Cong Wang
@ 2016-10-13 13:54 ` David Miller
  2016-10-13 21:08   ` Eric Dumazet
  2 siblings, 1 reply; 7+ messages in thread
From: David Miller @ 2016-10-13 13:54 UTC (permalink / raw)
  To: eric.dumazet; +Cc: netdev, jhs

From: Eric Dumazet <eric.dumazet@gmail.com>
Date: Sun, 09 Oct 2016 20:25:55 -0700

> From: Eric Dumazet <edumazet@google.com>
> 
> There are two ways to get tc filters from kernel to user space.
> 
> 1) Full dump (tc_dump_tfilter())
> 2) RTM_GETTFILTER to get one precise filter, reducing overhead.
> 
> The second operation is unfortunately broadcasting its result,
> polluting "tc monitor" users.
> 
> This patch makes sure only the requester gets the result, using
> netlink_unicast() instead of rtnetlink_send()
> 
> Jamal cooked an iproute2 patch to implement "tc filter get" operation,
> but other user space libraries already use RTM_GETTFILTER when a single
> filter is queried, instead of dumping all filters.
> 
> Signed-off-by: Eric Dumazet <edumazet@google.com>

Applied, thanks Eric.

Want me to queue this up for -stable too?

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

* Re: [PATCH net] net_sched: do not broadcast RTM_GETTFILTER result
  2016-10-13 13:54 ` David Miller
@ 2016-10-13 21:08   ` Eric Dumazet
  0 siblings, 0 replies; 7+ messages in thread
From: Eric Dumazet @ 2016-10-13 21:08 UTC (permalink / raw)
  To: David Miller; +Cc: netdev, jhs

On Thu, 2016-10-13 at 09:54 -0400, David Miller wrote:
> Applied, thanks Eric.
> 
> Want me to queue this up for -stable too?

No thanks, it just occurred to me during a debugging session.

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

end of thread, other threads:[~2016-10-13 21:09 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-10  3:25 [PATCH net] net_sched: do not broadcast RTM_GETTFILTER result Eric Dumazet
2016-10-10 13:16 ` Jamal Hadi Salim
2016-10-12 16:36 ` Cong Wang
2016-10-13  7:46   ` Eric Dumazet
2016-10-13 11:54     ` Jamal Hadi Salim
2016-10-13 13:54 ` David Miller
2016-10-13 21:08   ` Eric Dumazet

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.