All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 net-next] net:sched: add action inheritdsfield to skbedit
@ 2018-05-28  5:40 Fu, Qiaobin
  2018-05-28 15:42 ` Marcelo Ricardo Leitner
  2018-06-09 22:35 ` [PATCH v3 " Fu, Qiaobin
  0 siblings, 2 replies; 20+ messages in thread
From: Fu, Qiaobin @ 2018-05-28  5:40 UTC (permalink / raw)
  To: davem
  Cc: netdev, jhs, Michel Machado, Marcelo Ricardo Leitner, xiyou.wangcong

The new action inheritdsfield copies the field DS of
IPv4 and IPv6 packets into skb->priority. This enables
later classification of packets based on the DS field.

Original idea by Jamal Hadi Salim <jhs@mojatatu.com>

Signed-off-by: Qiaobin Fu <qiaobinf@bu.edu>
Reviewed-by: Michel Machado <michel@digirati.com.br>
---

Note that the motivation for this patch is found in the following discussion:
https://www.spinics.net/lists/netdev/msg501061.html
---

diff --git a/include/uapi/linux/tc_act/tc_skbedit.h b/include/uapi/linux/tc_act/tc_skbedit.h
index fbcfe27..432ad2f 100644
--- a/include/uapi/linux/tc_act/tc_skbedit.h
+++ b/include/uapi/linux/tc_act/tc_skbedit.h
@@ -30,9 +30,11 @@
 #define SKBEDIT_F_MARK			0x4
 #define SKBEDIT_F_PTYPE			0x8
 #define SKBEDIT_F_MASK			0x10
+#define SKBEDIT_F_INHERITDSFIELD	0x20
 
 struct tc_skbedit {
 	tc_gen;
+	__u64 flags;
 };
 
 enum {
diff --git a/net/sched/act_skbedit.c b/net/sched/act_skbedit.c
index 6138d1d7..c3e9d03 100644
--- a/net/sched/act_skbedit.c
+++ b/net/sched/act_skbedit.c
@@ -23,6 +23,9 @@
 #include <linux/rtnetlink.h>
 #include <net/netlink.h>
 #include <net/pkt_sched.h>
+#include <net/ip.h>
+#include <net/ipv6.h>
+#include <net/dsfield.h>
 
 #include <linux/tc_act/tc_skbedit.h>
 #include <net/tc_act/tc_skbedit.h>
@@ -39,8 +42,32 @@ static int tcf_skbedit(struct sk_buff *skb, const struct tc_action *a,
 	tcf_lastuse_update(&d->tcf_tm);
 	bstats_update(&d->tcf_bstats, skb);
 
-	if (d->flags & SKBEDIT_F_PRIORITY)
-		skb->priority = d->priority;
+	if (d->flags & SKBEDIT_F_INHERITDSFIELD) {
+		int wlen = skb_network_offset(skb);
+
+		switch (tc_skb_protocol(skb)) {
+		case htons(ETH_P_IP):
+			wlen += sizeof(struct iphdr);
+			if (!pskb_may_pull(skb, wlen))
+				goto err;
+			skb->priority = ipv4_get_dsfield(ip_hdr(skb)) >> 2;
+			break;
+
+		case htons(ETH_P_IPV6):
+			wlen += sizeof(struct ipv6hdr);
+			if (!pskb_may_pull(skb, wlen))
+				goto err;
+			skb->priority = ipv6_get_dsfield(ipv6_hdr(skb)) >> 2;
+			break;
+
+		default:
+			goto default_priority;
+		}
+	} else {
+default_priority:
+		if (d->flags & SKBEDIT_F_PRIORITY)
+			skb->priority = d->priority;
+	}
 	if (d->flags & SKBEDIT_F_QUEUE_MAPPING &&
 	    skb->dev->real_num_tx_queues > d->queue_mapping)
 		skb_set_queue_mapping(skb, d->queue_mapping);
@@ -53,6 +80,10 @@ static int tcf_skbedit(struct sk_buff *skb, const struct tc_action *a,
 
 	spin_unlock(&d->tcf_lock);
 	return d->tcf_action;
+
+err:
+	spin_unlock(&d->tcf_lock);
+	return TC_ACT_SHOT;
 }
 
 static const struct nla_policy skbedit_policy[TCA_SKBEDIT_MAX + 1] = {
@@ -115,6 +146,8 @@ static int tcf_skbedit_init(struct net *net, struct nlattr *nla,
 	}
 
 	parm = nla_data(tb[TCA_SKBEDIT_PARMS]);
+	if (parm->flags & SKBEDIT_F_INHERITDSFIELD)
+		flags |= SKBEDIT_F_INHERITDSFIELD;
 
 	exists = tcf_idr_check(tn, parm->index, a, bind);
 	if (exists && bind)

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

end of thread, other threads:[~2018-06-28  7:05 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-28  5:40 [PATCH v2 net-next] net:sched: add action inheritdsfield to skbedit Fu, Qiaobin
2018-05-28 15:42 ` Marcelo Ricardo Leitner
2018-05-28 16:01   ` Jamal Hadi Salim
2018-06-09 22:35 ` [PATCH v3 " Fu, Qiaobin
2018-06-09 22:51   ` Marcelo Ricardo Leitner
2018-06-12 15:42   ` [PATCH v4 " Fu, Qiaobin
2018-06-19 12:01     ` Jamal Hadi Salim
2018-06-19 12:39       ` Michel Machado
2018-06-20 11:53         ` Jamal Hadi Salim
2018-06-20 12:42           ` Michel Machado
2018-06-20 14:45     ` Marcelo Ricardo Leitner
2018-06-20 16:08     ` Davide Caratti
2018-06-20 16:47       ` Michel Machado
2018-06-20 17:02         ` Davide Caratti
2018-06-20 18:40           ` Marcelo Ricardo Leitner
2018-06-21 15:46             ` Fu, Qiaobin
2018-06-21 15:50               ` [PATCH v5 " Fu, Qiaobin
2018-06-21 16:13                 ` Davide Caratti
2018-06-26 15:58                 ` Fu, Qiaobin
2018-06-28  7:05                   ` 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.