Netfilter target: CLASSIFY (was Re: [LARTC] QoS in Linux: Project
Quoted 10 lines · Patrick McHardy
Quoted 7 lines · Chris Wilson
My proposed solution is a new Netfilter table which packets pass through on their way out to a device.There would be just a single terminal target, CLASSIFY, which would enqueue the packet in the specified classifier. Unclassified packets which drop off the end of the entry chain would pass on to the old-style tc filtering system, for backwards compatibility.
Quoted 4 lines
i think with netfilter table you mean iptables table. iptables can only see ip, so you still have the need for tc filters as they exist. The classify target can easily be made, just set
skb->priorityto the class id and the qdisc will take care of the rest. if your company wishes to sponsor me for writing one for you, go ahead ;)
sorry if my last mail sounded arrogant, i think you deserve honour for beeing willing to sponsor linux QoS development. As sign of my appologies, take this CLASSIFY target patch against latest netfiler CVS ;) It is untested, but despite possible easy-to-fix typos i hope it works. chmod +x userspace/extensions/.CLASSIFY-test after applying the patch. Usage is:
-j CLASSIFY --set-class MAJOR:MINOR
Bye,
Patrick
patch-o-matic/extra/CLASSIFY.patch +83 -0
@@ -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 "MARK: 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
@@ -0,0 +1,2 @@ + dep_tristate ' MIRROR target support (EXPERIMENTAL)' CONFIG_IP_NF_TARGET_MIRROR $CONFIG_IP_NF_FILTER + dep_tristate ' CLASSIFY target support (EXPERIMENTAL)' CONFIG_IP_NF_TARGET_CLASSIFY $CONFIG_IP_NF_FILTER
patch-o-matic/extra/CLASSIFY.patch.help +5 -0
@@ -0,0 +1,5 @@ +Author: Patrick McHardy <[email protected]> +Status: untested + +This patch adds support for the CLASSIFY target which sets skb->priority. +Some qdiscs can use this value for classifying packets.
patch-o-matic/extra/CLASSIFY.patch.makefile +2 -0
@@ -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
@@ -0,0 +1,3 @@ +#! /bin/sh +[ -f $KERNEL_DIR/net/ipv4/netfilter/ipt_CLASSIFY.c ] && echo CLASSIFY +
userspace/extensions/libipt_CLASSIFY.c +125 -0
125 lines not on this page · raw message
Quoted 18 lines · Patrick McHardy
Quoted 10 lines · Patrick McHardy
Quoted 7 lines · Chris Wilson
My proposed solution is a new Netfilter table which packets pass through on their way out to a device.There would be just a single terminal target, CLASSIFY, which would enqueue the packet in the specified classifier. Unclassified packets which drop off the end of the entry chain would pass on to the old-style tc filtering system, for backwards compatibility.
Quoted 4 lines
i think with netfilter table you mean iptables table. iptables can only see ip, so you still have the need for tc filters as they exist. The classify target can easily be made, just set
skb->priorityto the class id and the qdisc will take care of the rest. if your company wishes to sponsor me for writing one for you, go ahead ;)
Quoted 9 lines
sorry if my last mail sounded arrogant, i think you deserve honour for beeing willing to sponsor linux QoS development. As sign of my appologies, take this CLASSIFY target patch against latest netfiler CVS ;) It is untested, but despite possible easy-to-fix typos i hope it works. chmod +x userspace/extensions/.CLASSIFY-test after applying the patch. Usage is:
-j CLASSIFY --set-class MAJOR:MINORBye,
Patrick
sorry last one had obvious class value parsing error (treated as integer instead of hex), i hope this one is fine. patrick
patch-o-matic/extra/CLASSIFY.patch +83 -0
@@ -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 "MARK: 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
@@ -0,0 +1,2 @@ + dep_tristate ' MIRROR target support (EXPERIMENTAL)' CONFIG_IP_NF_TARGET_MIRROR $CONFIG_IP_NF_FILTER + dep_tristate ' CLASSIFY target support (EXPERIMENTAL)' CONFIG_IP_NF_TARGET_CLASSIFY $CONFIG_IP_NF_FILTER
patch-o-matic/extra/CLASSIFY.patch.help +5 -0
@@ -0,0 +1,5 @@ +Author: Patrick McHardy <[email protected]> +Status: untested + +This patch adds support for the CLASSIFY target which sets skb->priority. +Some qdiscs can use this value for classifying packets.
patch-o-matic/extra/CLASSIFY.patch.makefile +2 -0
@@ -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
@@ -0,0 +1,3 @@ +#! /bin/sh +[ -f $KERNEL_DIR/net/ipv4/netfilter/ipt_CLASSIFY.c ] && echo CLASSIFY +
userspace/extensions/libipt_CLASSIFY.c +128 -0
128 lines not on this page · raw message
ok this one actually compiles ;)
patrick
patch-o-matic/extra/CLASSIFY.patch +83 -0
@@ -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 "MARK: 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
@@ -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 +5 -0
@@ -0,0 +1,5 @@ +Author: Patrick McHardy <[email protected]> +Status: untested + +This patch adds support for the CLASSIFY target which sets skb->priority. +Some qdiscs can use this value for classifying packets.
patch-o-matic/extra/CLASSIFY.patch.makefile +2 -0
@@ -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
@@ -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
Quoted 12 lines · Abraham van der Merwe
Hi Patrick!
Quoted 3 lines
ok this one actually compiles ;)
just a small bug in your code:
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +1
-0+ *p = TC_H_MAKE(i, j);that should be changed to
TC_H_MAKE(i<<16, j)
thanks, i've attached a changed diff. have you actually tested it ? does it work ? ;)
bye,
patrick
patch-o-matic/extra/CLASSIFY.patch +83 -0
@@ -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
@@ -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 +5 -0
@@ -0,0 +1,5 @@ +Author: Patrick McHardy <[email protected]> +Status: untested + +This patch adds support for the CLASSIFY target which sets skb->priority. +Some qdiscs can use this value for classifying packets.
patch-o-matic/extra/CLASSIFY.patch.makefile +2 -0
@@ -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
@@ -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