SOURCES (LINUX_2_6): linux-2.6-nf-IPMARK.patch (NEW) - [extra] IPM...

cieciwa cieciwa at pld-linux.org
Thu Sep 15 11:22:52 CEST 2005


Author: cieciwa                      Date: Thu Sep 15 09:22:52 2005 GMT
Module: SOURCES                       Tag: LINUX_2_6
---- Log message:
- [extra] IPMARK - kernel patch.

---- Files affected:
SOURCES:
   linux-2.6-nf-IPMARK.patch (NONE -> 1.1.2.1)  (NEW)

---- Diffs:

================================================================
Index: SOURCES/linux-2.6-nf-IPMARK.patch
diff -u /dev/null SOURCES/linux-2.6-nf-IPMARK.patch:1.1.2.1
--- /dev/null	Thu Sep 15 11:22:52 2005
+++ SOURCES/linux-2.6-nf-IPMARK.patch	Thu Sep 15 11:22:46 2005
@@ -0,0 +1,134 @@
+ include/linux/netfilter_ipv4/ipt_IPMARK.h |   13 ++++
+ net/ipv4/netfilter/Kconfig                |   12 ++++
+ net/ipv4/netfilter/Makefile               |    1 
+ net/ipv4/netfilter/ipt_IPMARK.c           |   81 ++++++++++++++++++++++++++++++
+ 4 files changed, 107 insertions(+)
+
+diff -Nur --exclude '*.orig' linux-2.6.13.1.org/include/linux/netfilter_ipv4/ipt_IPMARK.h linux-2.6.13.1/include/linux/netfilter_ipv4/ipt_IPMARK.h
+--- linux-2.6.13.1.org/include/linux/netfilter_ipv4/ipt_IPMARK.h	1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.13.1/include/linux/netfilter_ipv4/ipt_IPMARK.h	2005-09-15 11:14:29.000000000 +0200
+@@ -0,0 +1,13 @@
++#ifndef _IPT_IPMARK_H_target
++#define _IPT_IPMARK_H_target
++
++struct ipt_ipmark_target_info {
++	unsigned long andmask;
++	unsigned long ormask;
++	unsigned int addr;
++};
++
++#define IPT_IPMARK_SRC    0
++#define IPT_IPMARK_DST    1
++
++#endif /*_IPT_IPMARK_H_target*/
+diff -Nur --exclude '*.orig' linux-2.6.13.1.org/net/ipv4/netfilter/Kconfig linux-2.6.13.1/net/ipv4/netfilter/Kconfig
+--- linux-2.6.13.1.org/net/ipv4/netfilter/Kconfig	2005-09-10 04:42:58.000000000 +0200
++++ linux-2.6.13.1/net/ipv4/netfilter/Kconfig	2005-09-15 11:14:29.000000000 +0200
+@@ -692,5 +692,17 @@
+ 	  Allows altering the ARP packet payload: source and destination
+ 	  hardware and network addresses.
+ 
++config IP_NF_TARGET_IPMARK
++	tristate  'IPMARK target support'
++	depends on IP_NF_MANGLE
++	help
++	  This option adds a `IPMARK' target, which allows you to create rules
++	  in the `mangle' table which alter the netfilter mark (nfmark) field
++	  basing on the source or destination ip address of the packet.
++	  This is very useful for very fast massive mangling and marking.
++	
++	  If you want to compile it as a module, say M here and read
++	  <file:Documentation/modules.txt>.  If unsure, say `N'.
++
+ endmenu
+ 
+diff -Nur --exclude '*.orig' linux-2.6.13.1.org/net/ipv4/netfilter/Makefile linux-2.6.13.1/net/ipv4/netfilter/Makefile
+--- linux-2.6.13.1.org/net/ipv4/netfilter/Makefile	2005-09-10 04:42:58.000000000 +0200
++++ linux-2.6.13.1/net/ipv4/netfilter/Makefile	2005-09-15 11:14:29.000000000 +0200
+@@ -0,0 +0,1 @@
++obj-$(CONFIG_IP_NF_TARGET_IPMARK) += ipt_IPMARK.o
+diff -Nur --exclude '*.orig' linux-2.6.13.1.org/net/ipv4/netfilter/ipt_IPMARK.c linux-2.6.13.1/net/ipv4/netfilter/ipt_IPMARK.c
+--- linux-2.6.13.1.org/net/ipv4/netfilter/ipt_IPMARK.c	1970-01-01 01:00:00.000000000 +0100
++++ linux-2.6.13.1/net/ipv4/netfilter/ipt_IPMARK.c	2005-09-15 11:14:29.000000000 +0200
+@@ -0,0 +1,81 @@
++/* This is a module which is used for setting the NFMARK field of an skb. */
++#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_IPMARK.h>
++
++MODULE_AUTHOR("Grzegorz Janoszka <Grzegorz.Janoszka at pro.onet.pl>");
++MODULE_DESCRIPTION("IP tables IPMARK: mark based on ip address");
++MODULE_LICENSE("GPL");
++
++static unsigned int
++target(struct sk_buff **pskb,
++       const struct net_device *in,
++       const struct net_device *out,
++       unsigned int hooknum,
++       const void *targinfo,
++       void *userinfo)
++{
++	const struct ipt_ipmark_target_info *ipmarkinfo = targinfo;
++	struct iphdr *iph = (*pskb)->nh.iph;
++	unsigned long mark;
++
++	if (ipmarkinfo->addr == IPT_IPMARK_SRC)
++		mark = (unsigned long) ntohl(iph->saddr);
++	else
++		mark = (unsigned long) ntohl(iph->daddr);
++
++	mark &= ipmarkinfo->andmask;
++	mark |= ipmarkinfo->ormask;
++	
++	if ((*pskb)->nfmark != mark) {
++		(*pskb)->nfmark = mark;
++		(*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_ipmark_target_info))) {
++		printk(KERN_WARNING "IPMARK: targinfosize %u != %Zu\n",
++		       targinfosize,
++		       IPT_ALIGN(sizeof(struct ipt_ipmark_target_info)));
++		return 0;
++	}
++
++	if (strcmp(tablename, "mangle") != 0) {
++		printk(KERN_WARNING "IPMARK: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
++		return 0;
++	}
++
++	return 1;
++}
++
++static struct ipt_target ipt_ipmark_reg = { 
++	.name = "IPMARK",
++	.target = target,
++	.checkentry = checkentry,
++	.me = THIS_MODULE
++};
++
++static int __init init(void)
++{
++	return ipt_register_target(&ipt_ipmark_reg);
++}
++
++static void __exit fini(void)
++{
++	ipt_unregister_target(&ipt_ipmark_reg);
++}
++
++module_init(init);
++module_exit(fini);
================================================================



More information about the pld-cvs-commit mailing list