blob: 39f9b079f5d4ac7d1254442bc991876f881a7c00 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Kernel module to match NFMARK values. */
2
3/* (C) 1999-2001 Marc Boucher <marc@mbsi.ca>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 */
9
10#include <linux/module.h>
11#include <linux/skbuff.h>
12
Harald Welte2e4e6a12006-01-12 13:30:04 -080013#include <linux/netfilter/xt_mark.h>
14#include <linux/netfilter/x_tables.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16MODULE_LICENSE("GPL");
17MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
18MODULE_DESCRIPTION("iptables mark matching module");
Harald Welte2e4e6a12006-01-12 13:30:04 -080019MODULE_ALIAS("ipt_mark");
20MODULE_ALIAS("ip6t_mark");
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22static int
23match(const struct sk_buff *skb,
24 const struct net_device *in,
25 const struct net_device *out,
Patrick McHardyc4986732006-03-20 18:02:56 -080026 const struct xt_match *match,
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 const void *matchinfo,
28 int offset,
Harald Welte2e4e6a12006-01-12 13:30:04 -080029 unsigned int protoff,
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 int *hotdrop)
31{
Harald Welte2e4e6a12006-01-12 13:30:04 -080032 const struct xt_mark_info *info = matchinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34 return ((skb->nfmark & info->mask) == info->mark) ^ info->invert;
35}
36
37static int
38checkentry(const char *tablename,
Harald Welte2e4e6a12006-01-12 13:30:04 -080039 const void *entry,
Patrick McHardyc4986732006-03-20 18:02:56 -080040 const struct xt_match *match,
Linus Torvalds1da177e2005-04-16 15:20:36 -070041 void *matchinfo,
42 unsigned int matchsize,
43 unsigned int hook_mask)
44{
Patrick McHardy3e72b2f2006-05-29 18:19:19 -070045 const struct xt_mark_info *minfo = matchinfo;
Harald Weltebf3a46a2005-08-09 19:22:01 -070046
Harald Weltebf3a46a2005-08-09 19:22:01 -070047 if (minfo->mark > 0xffffffff || minfo->mask > 0xffffffff) {
48 printk(KERN_WARNING "mark: only supports 32bit mark\n");
49 return 0;
50 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 return 1;
52}
53
Patrick McHardy4470bbc2006-08-22 00:34:04 -070054static struct xt_match xt_mark_match[] = {
55 {
56 .name = "mark",
57 .family = AF_INET,
58 .checkentry = checkentry,
59 .match = match,
60 .matchsize = sizeof(struct xt_mark_info),
61 .me = THIS_MODULE,
62 },
63 {
64 .name = "mark",
65 .family = AF_INET6,
66 .checkentry = checkentry,
67 .match = match,
68 .matchsize = sizeof(struct xt_mark_info),
69 .me = THIS_MODULE,
70 },
Linus Torvalds1da177e2005-04-16 15:20:36 -070071};
72
Andrew Morton65b4b4e2006-03-28 16:37:06 -080073static int __init xt_mark_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070074{
Patrick McHardy4470bbc2006-08-22 00:34:04 -070075 return xt_register_matches(xt_mark_match, ARRAY_SIZE(xt_mark_match));
Linus Torvalds1da177e2005-04-16 15:20:36 -070076}
77
Andrew Morton65b4b4e2006-03-28 16:37:06 -080078static void __exit xt_mark_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070079{
Patrick McHardy4470bbc2006-08-22 00:34:04 -070080 xt_unregister_matches(xt_mark_match, ARRAY_SIZE(xt_mark_match));
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
82
Andrew Morton65b4b4e2006-03-28 16:37:06 -080083module_init(xt_mark_init);
84module_exit(xt_mark_fini);