Re: [PATCH] [TRY2] Use nfmark as a key in u32 classifier

Linux Advanced Routing and Traffic Control

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



* Catalin(ux aka Dino) BOIE <Pine.LNX.4.61.0411091406570.20094@xxxxxxxxxxxxxxxxxxx> 2004-11-09 14:27
This is the try number two.
What was changed:
- Added selectable choice in Kconfig file (thanks Jamal!)
- Don't abuse tc_u32_sel to not break backward compatibility (thanks
Patrick!).

Your patchs looks fine except for missing dependcy on CONFIG_NETFILTER. Either make CLS_U32_MARK dependant on it or #ifdef the references to skb->nfmark.

Patch updated and attached.

It might be fair to tell you that this code is likely to be removed
again once we have the metadata match.

Jamal already warned me about this. Is somebody already working on it?

Cheers

Thank you! --- Catalin(ux aka Dino) BOIE catab at deuroconsult.ro http://kernel.umbrella.ro/
--- linux.orig/net/sched/Kconfig	2004-10-19 00:55:06.000000000 +0300
+++ linux/net/sched/Kconfig	2004-11-09 15:39:47.000000000 +0200
@@ -334,6 +334,18 @@ config NET_CLS_IND
 	  Requires a new iproute2
 	  You MUST NOT turn this on if you dont have an update iproute2.
 
+config CLS_U32_MARK
+	bool "Use nfmark as a key in U32 classifier"
+	depends on NET_CLS_U32 && NETFILTER
+	help
+	  This allows you to match mark in a u32 filter.
+	  Example:
+	  tc filter add dev eth0 protocol ip parent 1:0 prio 5 u32 \
+		match mark 0x0090 0xffff \
+		match ip dst 4.4.4.4 \
+		flowid 1:90
+	  You must use a new iproute2 to use this feature.
+
 config NET_CLS_RSVP
 	tristate "Special RSVP classifier"
 	depends on NET_CLS && NET_QOS
--- linux.orig/net/sched/cls_u32.c	2004-10-19 00:53:45.000000000 +0300
+++ linux/net/sched/cls_u32.c	2004-11-09 13:56:42.000000000 +0200
@@ -27,6 +27,7 @@
  *	JHS: We should remove the CONFIG_NET_CLS_IND from here
  *	eventually when the meta match extension is made available
  *
+ *	nfmark match added by Catalin(ux aka Dino) BOIE <catab at umbrella.ro>
  */
 
 #include <asm/uaccess.h>
@@ -57,6 +58,13 @@
 #include <net/pkt_sched.h>
 
 
+struct tc_u32_mark
+{
+	__u32		val;
+	__u32		mask;
+	__u32		success;
+};
+
 struct tc_u_knode
 {
 	struct tc_u_knode	*next;
@@ -78,6 +86,9 @@ struct tc_u_knode
 #ifdef CONFIG_CLS_U32_PERF
 	struct tc_u32_pcnt	*pf;
 #endif
+#ifdef CONFIG_CLS_U32_MARK
+	struct tc_u32_mark	mark;
+#endif
 	struct tc_u32_sel	sel;
 };
 
@@ -139,6 +150,16 @@ next_knode:
 		n->pf->rcnt +=1;
 		j = 0;
 #endif
+
+#ifdef CONFIG_CLS_U32_MARK
+		if ((skb->nfmark & n->mark.mask) != n->mark.val) {
+			n = n->next;
+			goto next_knode;
+		} else {
+			n->mark.success++;
+		}
+#endif
+
 		for (i = n->sel.nkeys; i>0; i--, key++) {
 
 			if ((*(u32*)(ptr+key->off+(off2&key->offmask))^key->val)&key->mask) {
@@ -615,6 +636,7 @@ static int u32_change(struct tcf_proto *
 	struct tc_u_hnode *ht;
 	struct tc_u_knode *n;
 	struct tc_u32_sel *s;
+	struct tc_u32_mark *mark;
 	struct rtattr *opt = tca[TCA_OPTIONS-1];
 	struct rtattr *tb[TCA_U32_MAX];
 	u32 htid;
@@ -718,6 +740,16 @@ static int u32_change(struct tcf_proto *
 	}
 	n->fshift = i;
 }
+
+#ifdef CONFIG_CLS_U32_MARK
+	if (tb[TCA_U32_MARK-1] == 0 ||
+		RTA_PAYLOAD(tb[TCA_U32_MARK-1]) < sizeof(struct tc_u32_mark))
+		return -EINVAL;
+	mark = RTA_DATA(tb[TCA_U32_MARK-1]);
+	memcpy(&n->mark, mark, sizeof(struct tc_u32_mark));
+	n->mark.success = 0;
+#endif
+
 	err = u32_set_parms(tp->q, base, ht, n, tb, tca[TCA_RATE-1]);
 	if (err == 0) {
 		struct tc_u_knode **ins;
@@ -805,6 +837,12 @@ static int u32_dump(struct tcf_proto *tp
 			RTA_PUT(skb, TCA_U32_CLASSID, 4, &n->res.classid);
 		if (n->ht_down)
 			RTA_PUT(skb, TCA_U32_LINK, 4, &n->ht_down->handle);
+
+#ifdef CONFIG_CLS_U32_MARK
+		if (n->mark.val || n->mark.mask)
+			RTA_PUT(skb, TCA_U32_MARK, sizeof(n->mark), &n->mark);
+#endif
+
 #ifdef CONFIG_NET_CLS_ACT
 		/* again for backward compatible mode - we want
 		*  to work with both old and new modes of entering
--- linux.orig/include/linux/pkt_cls.h	2004-10-19 00:53:07.000000000 +0300
+++ linux/include/linux/pkt_cls.h	2004-11-09 09:50:45.000000000 +0200
@@ -190,6 +190,7 @@ enum
 	TCA_U32_ACT,   
 	TCA_U32_INDEV,
 	TCA_U32_PCNT,
+	TCA_U32_MARK,
 	__TCA_U32_MAX
 };
 

[Index of Archives]     [LARTC Home Page]     [Netfilter]     [Netfilter Development]     [Network Development]     [Bugtraq]     [GCC Help]     [Yosemite News]     [Linux Kernel]     [Fedora Users]
  Powered by Linux