All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH net-next] tc: cls_bpf: make ingress and egress qdiscs consistent
@ 2015-04-03 21:16 Alexei Starovoitov
       [not found] ` <1428095784-7091-1-git-send-email-ast-uqk4Ao+rVK5Wk0Htik3J/w@public.gmane.org>
  0 siblings, 1 reply; 13+ messages in thread
From: Alexei Starovoitov @ 2015-04-03 21:16 UTC (permalink / raw)
  To: David S. Miller
  Cc: Daniel Borkmann, Jiri Pirko, Jamal Hadi Salim, linux-api, netdev

BPF programs attached to ingress and egress qdiscs see inconsistent skb->data.
For ingress L2 header is already pulled, whereas for egress it's present.
That makes writing programs more difficult.
Make them consistent by pushing L2 before running the programs and pulling
it back afterwards.
Similar approach is taken by skb_defer_rx_timestamp() which does push/pull
before calling ptp_classify_raw()->BPF_PROG_RUN().

Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
---

Looks like noone has tried bpf with ingress qdisc before, otherwise this
problem would have been found sooner.
This patch is probably not needed for 'net', since tc+bpf infra only starting
to come alive.

 net/sched/cls_bpf.c |    9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/net/sched/cls_bpf.c b/net/sched/cls_bpf.c
index 5c4171c5d2bd..b1cefd2037c9 100644
--- a/net/sched/cls_bpf.c
+++ b/net/sched/cls_bpf.c
@@ -66,6 +66,12 @@ static int cls_bpf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
 	struct cls_bpf_prog *prog;
 	int ret = -1;
 
+	if (tp->q->flags & TCQ_F_INGRESS) {
+		if (skb_headroom(skb) < ETH_HLEN)
+			return -1;
+		__skb_push(skb, ETH_HLEN);
+	}
+
 	/* Needed here for accessing maps. */
 	rcu_read_lock();
 	list_for_each_entry_rcu(prog, &head->plist, link) {
@@ -86,6 +92,9 @@ static int cls_bpf_classify(struct sk_buff *skb, const struct tcf_proto *tp,
 	}
 	rcu_read_unlock();
 
+	if (tp->q->flags & TCQ_F_INGRESS)
+		__skb_pull(skb, ETH_HLEN);
+
 	return ret;
 }
 
-- 
1.7.9.5

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

end of thread, other threads:[~2015-04-07 18:51 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-04-03 21:16 [PATCH net-next] tc: cls_bpf: make ingress and egress qdiscs consistent Alexei Starovoitov
     [not found] ` <1428095784-7091-1-git-send-email-ast-uqk4Ao+rVK5Wk0Htik3J/w@public.gmane.org>
2015-04-03 21:46   ` Daniel Borkmann
     [not found]     ` <551F0A1B.3000100-FeC+5ew28dpmcu3hnIyYJQ@public.gmane.org>
2015-04-03 21:52       ` Alexei Starovoitov
     [not found]         ` <551F0B96.2090403-uqk4Ao+rVK5Wk0Htik3J/w@public.gmane.org>
2015-04-03 22:10           ` Daniel Borkmann
     [not found]             ` <551F0FE2.8000502-FeC+5ew28dpmcu3hnIyYJQ@public.gmane.org>
2015-04-03 22:17               ` Alexei Starovoitov
2015-04-03 22:54                 ` Daniel Borkmann
     [not found]                   ` <551F1A14.7080205-FeC+5ew28dpmcu3hnIyYJQ@public.gmane.org>
2015-04-03 23:04                     ` Alexei Starovoitov
2015-04-03 23:11                       ` Alexei Starovoitov
     [not found]                         ` <551F1E13.8050508-uqk4Ao+rVK5Wk0Htik3J/w@public.gmane.org>
2015-04-03 23:26                           ` Daniel Borkmann
2015-04-03 23:48                             ` Daniel Borkmann
2015-04-04  0:14                               ` Alexei Starovoitov
     [not found]                                 ` <551F2CD4.2080502-uqk4Ao+rVK5Wk0Htik3J/w@public.gmane.org>
2015-04-04  6:34                                   ` Daniel Borkmann
2015-04-07 18:51   ` 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.