Jan Engelhardt | e0a812a | 2008-01-14 23:38:52 -0800 | [diff] [blame] | 1 | /* |
| 2 | * xt_MARK - Netfilter module to modify the NFMARK field of an skb |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
Jan Engelhardt | e0a812a | 2008-01-14 23:38:52 -0800 | [diff] [blame] | 4 | * (C) 1999-2001 Marc Boucher <marc@mbsi.ca> |
| 5 | * Copyright © CC Computer Consultants GmbH, 2007 - 2008 |
| 6 | * Jan Engelhardt <jengelh@computergmbh.de> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/skbuff.h> |
| 15 | #include <linux/ip.h> |
| 16 | #include <net/checksum.h> |
| 17 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 18 | #include <linux/netfilter/x_tables.h> |
| 19 | #include <linux/netfilter/xt_MARK.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
| 21 | MODULE_LICENSE("GPL"); |
| 22 | MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>"); |
Jan Engelhardt | 2ae15b6 | 2008-01-14 23:42:28 -0800 | [diff] [blame] | 23 | MODULE_DESCRIPTION("Xtables: packet mark modification"); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 24 | MODULE_ALIAS("ipt_MARK"); |
| 25 | MODULE_ALIAS("ip6t_MARK"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | static unsigned int |
Jan Engelhardt | 7eb3558 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 28 | mark_tg(struct sk_buff *skb, const struct xt_target_param *par) |
Jan Engelhardt | e0a812a | 2008-01-14 23:38:52 -0800 | [diff] [blame] | 29 | { |
Jan Engelhardt | 7eb3558 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 30 | const struct xt_mark_tginfo2 *info = par->targinfo; |
Jan Engelhardt | e0a812a | 2008-01-14 23:38:52 -0800 | [diff] [blame] | 31 | |
| 32 | skb->mark = (skb->mark & ~info->mask) ^ info->mark; |
| 33 | return XT_CONTINUE; |
| 34 | } |
| 35 | |
Jan Engelhardt | c8001f7 | 2009-06-12 18:47:32 +0200 | [diff] [blame] | 36 | static struct xt_target mark_tg_reg __read_mostly = { |
| 37 | .name = "MARK", |
| 38 | .revision = 2, |
| 39 | .family = NFPROTO_UNSPEC, |
| 40 | .target = mark_tg, |
| 41 | .targetsize = sizeof(struct xt_mark_tginfo2), |
| 42 | .me = THIS_MODULE, |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 43 | }; |
| 44 | |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 45 | static int __init mark_tg_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | { |
Jan Engelhardt | c8001f7 | 2009-06-12 18:47:32 +0200 | [diff] [blame] | 47 | return xt_register_target(&mark_tg_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 50 | static void __exit mark_tg_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
Jan Engelhardt | c8001f7 | 2009-06-12 18:47:32 +0200 | [diff] [blame] | 52 | xt_unregister_target(&mark_tg_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | } |
| 54 | |
Jan Engelhardt | d3c5ee6 | 2007-12-04 23:24:03 -0800 | [diff] [blame] | 55 | module_init(mark_tg_init); |
| 56 | module_exit(mark_tg_exit); |