Skip to contentSkip to conversation

CLASSIFY target

PATCH In review Patrick McHardy 4 participants 8 messages Apr 8, 2003 – Apr 13, 2003 netfilter

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 CLASSIFY target

This patch adds a new target "CLASSIFY" which sets skb->priority. Several qdiscs can use this for classification. A list of the qdiscs currently capable of doing so is in the help text. Please consider for inclusion.

Bye,
Patrick

patch-o-matic/extra/CLASSIFY.patch +83 -0
diff -urN a/patch-o-matic/extra/CLASSIFY.patch b/patch-o-matic/extra/CLASSIFY.patch
@@ -0,0 +1,83 @@
+diff -urN linux-2.4.20-clean/include/linux/netfilter_ipv4/ipt_CLASSIFY.h linux-2.4.20_nfclassify/include/linux/netfilter_ipv4/ipt_CLASSIFY.h
+--- linux-2.4.20-clean/include/linux/netfilter_ipv4/ipt_CLASSIFY.h	1970-01-01 01:00:00.000000000 +0100
++++ linux-2.4.20_nfclassify/include/linux/netfilter_ipv4/ipt_CLASSIFY.h	2003-01-25 02:11:35.000000000 +0100
+@@ -0,0 +1,8 @@
++#ifndef _IPT_CLASSIFY_H
++#define _IPT_CLASSIFY_H
++
++struct ipt_classify_target_info {
++	unsigned int priority;
++};
++
++#endif /*_IPT_CLASSIFY_H */
+diff -urN linux-2.4.20-clean/net/ipv4/netfilter/ipt_CLASSIFY.c linux-2.4.20_nfclassify/net/ipv4/netfilter/ipt_CLASSIFY.c
+--- linux-2.4.20-clean/net/ipv4/netfilter/ipt_CLASSIFY.c	1970-01-01 01:00:00.000000000 +0100
++++ linux-2.4.20_nfclassify/net/ipv4/netfilter/ipt_CLASSIFY.c	2003-01-25 02:09:36.000000000 +0100
+@@ -0,0 +1,67 @@
++/* This is a module which is used for setting the skb->priority field of an skb for qdisc classification. */
++#include <linux/module.h>
++#include <linux/skbuff.h>
++#include <linux/ip.h>
++#include <net/checksum.h>
++
++#include <linux/netfilter_ipv4/ip_tables.h>
++#include <linux/netfilter_ipv4/ipt_CLASSIFY.h>
++
++static unsigned int
++target(struct sk_buff **pskb,
++       unsigned int hooknum,
++       const struct net_device *in,
++       const struct net_device *out,
++       const void *targinfo,
++       void *userinfo)
++{
++	const struct ipt_classify_target_info *clinfo = targinfo;
++
++	if((*pskb)->priority != clinfo->priority) {
++		(*pskb)->priority = clinfo->priority;
++		(*pskb)->nfcache |= NFC_ALTERED;
++	}
++	return IPT_CONTINUE;
++}
++
++static int
++checkentry(const char *tablename,
++	   const struct ipt_entry *e,
++           void *targinfo,
++           unsigned int targinfosize,
++           unsigned int hook_mask)
++{
++	if (targinfosize != IPT_ALIGN(sizeof(struct ipt_classify_target_info))) {
++		printk(KERN_WARNING "CLASSIFY: targinfosize %u != %Zu\n",
++		       targinfosize,
++		       IPT_ALIGN(sizeof(struct ipt_classify_target_info)));
++		return 0;
++	}
++
++	if (strcmp(tablename, "mangle") != 0) {
++		printk(KERN_WARNING "CLASSIFY: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
++		return 0;
++	}
++
++	return 1;
++}
++
++static struct ipt_target ipt_classify_reg
++= { { NULL, NULL }, "CLASSIFY", target, checkentry, NULL, THIS_MODULE };
++
++static int __init init(void)
++{
++	if (ipt_register_target(&ipt_classify_reg))
++		return -EINVAL;
++
++	return 0;
++}
++
++static void __exit fini(void)
++{
++	ipt_unregister_target(&ipt_classify_reg);
++}
++
++module_init(init);
++module_exit(fini);
++MODULE_LICENSE("GPL");
patch-o-matic/extra/CLASSIFY.patch.config.in +2 -0
diff -urN a/patch-o-matic/extra/CLASSIFY.patch.config.in b/patch-o-matic/extra/CLASSIFY.patch.config.in
@@ -0,0 +1,2 @@
+    dep_tristate '    MARK target support' CONFIG_IP_NF_TARGET_MARK $CONFIG_IP_NF_MANGLE
+    dep_tristate '    CLASSIFY target support (EXPERIMENTAL)' CONFIG_IP_NF_TARGET_CLASSIFY $CONFIG_IP_NF_FILTER
patch-o-matic/extra/CLASSIFY.patch.help +16 -0
diff -urN a/patch-o-matic/extra/CLASSIFY.patch.help b/patch-o-matic/extra/CLASSIFY.patch.help
@@ -0,0 +1,16 @@
+Author: Patrick McHardy <[email protected]>
+Status: working
+
+This patch adds support for the CLASSIFY target which sets skb->priority.
+Some qdiscs can use this value for classification, among these are
+
+- atm
+- cbq
+- dsmark
+- pfifo_fast
+- htb
+- prio
+
+Usage:
+	iptables -t mangle ... -j CLASSIFY --set-class MAJOR:MINOR
+
patch-o-matic/extra/CLASSIFY.patch.makefile +2 -0
diff -urN a/patch-o-matic/extra/CLASSIFY.patch.makefile b/patch-o-matic/extra/CLASSIFY.patch.makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_IP_NF_TARGET_MIRROR) += ipt_MIRROR.o
+obj-$(CONFIG_IP_NF_TARGET_CLASSIFY) += ipt_CLASSIFY.o
userspace/extensions/.CLASSIFY-test +3 -0
diff -urN a/userspace/extensions/.CLASSIFY-test b/userspace/extensions/.CLASSIFY-test
@@ -0,0 +1,3 @@
+#! /bin/sh
+[ -f $KERNEL_DIR/net/ipv4/netfilter/ipt_CLASSIFY.c ] && echo CLASSIFY
+
userspace/extensions/libipt_CLASSIFY.c +130 -0

130 lines not on this page · raw message

#1 lore raw
Quoted 4 lines · Patrick McHardy

This patch adds a new target "CLASSIFY" which sets skb->priority. Several qdiscs can use this for classification. A list of the qdiscs currently capable of doing so is in the help text. Please consider for inclusion.

Hi Patrick,

It's usually Harald who decides which patches go in or not. And Harald has been quite hard to get a response from during the last weeks :( He seems to have a lot of things in the air at the same time. I have a memory-corruption fix that havn't been OK'd yet...

Jozsef, do you feel like stepping in and adding some patches to p-o-m after you've approved them? I don't have commit-rights to the whole repository.

Regarding this patch... iirc, Bert Hubert wrote a similar target a while ago and I think he wanted a small change in the core QoS stuff and that was voted down, might be something to look into?

I think the discussion took place on the netdev list.

Signature · 1 line
/Martin
#2 lore raw

Hi Martin,
thanks for your response,

Quoted 6 lines · Martin Josefsson

Regarding this patch... iirc, Bert Hubert wrote a similar target a while ago and I think he wanted a small change in the core QoS stuff and that was voted down, might be something to look into?

I think the discussion took place on the netdev list.

Google found a discussion about moving "skb->priority = sk->priority" line to ip_queue_xmit2 to allow netfilter targets to override SO_PRIORITY value of local sockets. A quick check told me this change was never made, so the CLASSIFY target is only working correctly in the POST_ROUTING chain, which is what i have tested. This doesn't seem to affect usage of the target, worse would be if POST_ROUTING didn't work correctly. My suggestion is to restrict usage to POST_ROUTING chain, this seems like a natural place for QoS classification. What do you think ?

Thanks,
Patrick

#3 lore raw
Quoted 10 lines · Patrick McHardy

Google found a discussion about moving "skb->priority = sk->priority" line to
ip_queue_xmit2 to allow netfilter targets to override SO_PRIORITY value of local sockets. A quick check told me this change was never made, so the CLASSIFY target is only working correctly in the POST_ROUTING chain, which is what i have tested. This doesn't seem to affect usage of the target, worse
would be if POST_ROUTING didn't work correctly. My suggestion is to restrict usage to POST_ROUTING chain, this seems like a natural place for QoS classification. What do you think ?

Sounds like a good idea since Bert's suggestion was shot down (I think). Better not upset the gods by including it in this patch :)

We want to touch as little outside code as possible and if someone really needs this they can google and maybe find this discussion and then find the original thread and the patch :)

You'll send an updated patch I hope?

Signature · 1 line
/Martin
#4 lore raw
Quoted 4 lines · Martin Josefsson

Sounds like a good idea since Bert's suggestion was shot down (I think). Better not upset the gods by including it in this patch :)

I'll sacifize a nice lamb on my grill tonight ;)

Quoted 6 lines

We want to touch as little outside code as possible and if someone really needs this they can google and maybe find this discussion and then find the original thread and the patch :)

You'll send an updated patch I hope?

An updated version is attached, this one checks if it is called in POST_ROUTING chain of mangle table.

Bye,
Patrick

patch-o-matic/extra/CLASSIFY.patch +89 -0
diff -urN a/patch-o-matic/extra/CLASSIFY.patch b/patch-o-matic/extra/CLASSIFY.patch
@@ -0,0 +1,89 @@
+diff -urN a/include/linux/netfilter_ipv4/ipt_CLASSIFY.h b/include/linux/netfilter_ipv4/ipt_CLASSIFY.h
+--- a/include/linux/netfilter_ipv4/ipt_CLASSIFY.h	1970-01-01 01:00:00.000000000 +0100
++++ b/include/linux/netfilter_ipv4/ipt_CLASSIFY.h	2003-04-09 02:50:19.000000000 +0200
+@@ -0,0 +1,8 @@
++#ifndef _IPT_CLASSIFY_H
++#define _IPT_CLASSIFY_H
++
++struct ipt_classify_target_info {
++	unsigned int priority;
++};
++
++#endif /*_IPT_CLASSIFY_H */
+diff -urN a/net/ipv4/netfilter/ipt_CLASSIFY.c b/net/ipv4/netfilter/ipt_CLASSIFY.c
+--- a/net/ipv4/netfilter/ipt_CLASSIFY.c	1970-01-01 01:00:00.000000000 +0100
++++ b/net/ipv4/netfilter/ipt_CLASSIFY.c	2003-04-09 02:58:08.000000000 +0200
+@@ -0,0 +1,73 @@
++/* This is a module which is used for setting the skb->priority field of an skb for qdisc classification. */
++#include <linux/module.h>
++#include <linux/skbuff.h>
++#include <linux/ip.h>
++#include <net/checksum.h>
++
++#include <linux/netfilter_ipv4/ip_tables.h>
++#include <linux/netfilter_ipv4/ipt_CLASSIFY.h>
++
++static unsigned int
++target(struct sk_buff **pskb,
++       unsigned int hooknum,
++       const struct net_device *in,
++       const struct net_device *out,
++       const void *targinfo,
++       void *userinfo)
++{
++	const struct ipt_classify_target_info *clinfo = targinfo;
++
++	if((*pskb)->priority != clinfo->priority) {
++		(*pskb)->priority = clinfo->priority;
++		(*pskb)->nfcache |= NFC_ALTERED;
++	}
++
++	return IPT_CONTINUE;
++}
++
++static int
++checkentry(const char *tablename,
++	   const struct ipt_entry *e,
++           void *targinfo,
++           unsigned int targinfosize,
++           unsigned int hook_mask)
++{
++	if (targinfosize != IPT_ALIGN(sizeof(struct ipt_classify_target_info))){
++		printk(KERN_ERR "CLASSIFY: invalid size (%u != %u).\n",
++		       targinfosize,
++		       IPT_ALIGN(sizeof(struct ipt_classify_target_info)));
++		return 0;
++	}
++	
++	if (hook_mask & ~(1 << NF_IP_POST_ROUTING)) {
++		printk(KERN_ERR "CLASSIFY: only valid in POST_ROUTING.\n");
++		return 0;
++	}
++
++	if (strcmp(tablename, "mangle") != 0) {
++		printk(KERN_WARNING "CLASSIFY: can only be called from \"mangle\" table, not \"%s\".\n", tablename);
++		return 0;
++	}
++
++	return 1;
++}
++
++static struct ipt_target ipt_classify_reg
++= { { NULL, NULL }, "CLASSIFY", target, checkentry, NULL, THIS_MODULE };
++
++static int __init init(void)
++{
++	if (ipt_register_target(&ipt_classify_reg))
++		return -EINVAL;
++
++	return 0;
++}
++
++static void __exit fini(void)
++{
++	ipt_unregister_target(&ipt_classify_reg);
++}
++
++module_init(init);
++module_exit(fini);
++MODULE_LICENSE("GPL");
patch-o-matic/extra/CLASSIFY.patch.config.in +2 -0
diff -urN a/patch-o-matic/extra/CLASSIFY.patch.config.in b/patch-o-matic/extra/CLASSIFY.patch.config.in
@@ -0,0 +1,2 @@
+    dep_tristate '    MARK target support' CONFIG_IP_NF_TARGET_MARK $CONFIG_IP_NF_MANGLE
+    dep_tristate '    CLASSIFY target support (EXPERIMENTAL)' CONFIG_IP_NF_TARGET_CLASSIFY $CONFIG_IP_NF_FILTER
patch-o-matic/extra/CLASSIFY.patch.help +18 -0
diff -urN a/patch-o-matic/extra/CLASSIFY.patch.help b/patch-o-matic/extra/CLASSIFY.patch.help
@@ -0,0 +1,18 @@
+Author: Patrick McHardy <[email protected]>
+Status: working
+
+This patch adds support for the CLASSIFY target which sets skb->priority.
+Some qdiscs can use this value for classification, among these are
+
+- atm
+- cbq
+- dsmark
+- pfifo_fast
+- htb
+- prio
+
+This target is only valid in the POST_ROUTING chain of the mangle table.
+
+Usage:
+	iptables -t mangle -A POSTROUTING .. -j CLASSIFY --set-class MAJOR:MINOR
+
patch-o-matic/extra/CLASSIFY.patch.makefile +2 -0
diff -urN a/patch-o-matic/extra/CLASSIFY.patch.makefile b/patch-o-matic/extra/CLASSIFY.patch.makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_IP_NF_TARGET_MIRROR) += ipt_MIRROR.o
+obj-$(CONFIG_IP_NF_TARGET_CLASSIFY) += ipt_CLASSIFY.o
userspace/extensions/.CLASSIFY-test +3 -0
diff -urN a/userspace/extensions/.CLASSIFY-test b/userspace/extensions/.CLASSIFY-test
@@ -0,0 +1,3 @@
+#! /bin/sh
+[ -f $KERNEL_DIR/net/ipv4/netfilter/ipt_CLASSIFY.c ] && echo CLASSIFY
+
userspace/extensions/libipt_CLASSIFY.c +130 -0

130 lines not on this page · raw message

#6 lore raw
In reply to Martin Josefsson
Quoted 2 lines · Martin Josefsson

Sounds like a good idea since Bert's suggestion was shot down (I think). Better not upset the gods by including it in this patch :)

actually, I don't mind this change.

As of now, I have no plan to submit the CLASSIFY target to the kernel, so there is no 'ideological/political' problem with the core networking change.

Quoted 3 lines

We want to touch as little outside code as possible and if someone really needs this they can google and maybe find this discussion and then find the original thread and the patch :)

although, there is the practical issue. Patching something in the core networking reliably over lots of 2.4.x and 2.5.x kernels seems to be almost impossible.

Quoted 1 line

/Martin

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie
#7 lore raw
In reply to Martin Josefsson
Quoted 6 lines · Martin Josefsson
Quoted 4 lines · Patrick McHardy

This patch adds a new target "CLASSIFY" which sets skb->priority. Several qdiscs can use this for classification. A list of the qdiscs currently capable of doing so is in the help text. Please consider for inclusion.

Quoted 6 lines

Hi Patrick,

It's usually Harald who decides which patches go in or not. And Harald has been quite hard to get a response from during the last weeks :( He seems to have a lot of things in the air at the same time. I have a memory-corruption fix that havn't been OK'd yet...

Just a quick note: I've re-appeared from the dark voids of again-being-two-months-too-late-with-a-commercial-project-and-not-wanting-to-be-any-later.

Quoted 1 line

/Martin

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie