blob: 876bc57977381bc62ffd6c11c077cd3570428e1f [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
Harald Welte2e4e6a12006-01-12 13:30:04 -080054static struct xt_match mark_match = {
55 .name = "mark",
Patrick McHardy5d04bff2006-03-20 18:01:58 -080056 .match = match,
57 .matchsize = sizeof(struct xt_mark_info),
58 .checkentry = checkentry,
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -080059 .family = AF_INET,
Harald Welte2e4e6a12006-01-12 13:30:04 -080060 .me = THIS_MODULE,
61};
62
63static struct xt_match mark6_match = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 .name = "mark",
Patrick McHardy5d04bff2006-03-20 18:01:58 -080065 .match = match,
66 .matchsize = sizeof(struct xt_mark_info),
67 .checkentry = checkentry,
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -080068 .family = AF_INET6,
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 .me = THIS_MODULE,
70};
71
Andrew Morton65b4b4e2006-03-28 16:37:06 -080072static int __init xt_mark_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
Harald Welte2e4e6a12006-01-12 13:30:04 -080074 int ret;
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -080075 ret = xt_register_match(&mark_match);
Harald Welte2e4e6a12006-01-12 13:30:04 -080076 if (ret)
77 return ret;
78
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -080079 ret = xt_register_match(&mark6_match);
Harald Welte2e4e6a12006-01-12 13:30:04 -080080 if (ret)
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -080081 xt_unregister_match(&mark_match);
Harald Welte2e4e6a12006-01-12 13:30:04 -080082
83 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084}
85
Andrew Morton65b4b4e2006-03-28 16:37:06 -080086static void __exit xt_mark_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070087{
Pablo Neira Ayusoa45049c2006-03-22 13:55:40 -080088 xt_unregister_match(&mark_match);
89 xt_unregister_match(&mark6_match);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
Andrew Morton65b4b4e2006-03-28 16:37:06 -080092module_init(xt_mark_init);
93module_exit(xt_mark_fini);