]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* Kernel module to match NFMARK values. */ |
2 | ||
3 | /* (C) 1999-2001 Marc Boucher <[email protected]> | |
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 | ||
2e4e6a17 HW |
13 | #include <linux/netfilter/xt_mark.h> |
14 | #include <linux/netfilter/x_tables.h> | |
1da177e4 LT |
15 | |
16 | MODULE_LICENSE("GPL"); | |
17 | MODULE_AUTHOR("Marc Boucher <[email protected]>"); | |
18 | MODULE_DESCRIPTION("iptables mark matching module"); | |
2e4e6a17 HW |
19 | MODULE_ALIAS("ipt_mark"); |
20 | MODULE_ALIAS("ip6t_mark"); | |
1da177e4 LT |
21 | |
22 | static int | |
23 | match(const struct sk_buff *skb, | |
24 | const struct net_device *in, | |
25 | const struct net_device *out, | |
c4986734 | 26 | const struct xt_match *match, |
1da177e4 LT |
27 | const void *matchinfo, |
28 | int offset, | |
2e4e6a17 | 29 | unsigned int protoff, |
1da177e4 LT |
30 | int *hotdrop) |
31 | { | |
2e4e6a17 | 32 | const struct xt_mark_info *info = matchinfo; |
1da177e4 LT |
33 | |
34 | return ((skb->nfmark & info->mask) == info->mark) ^ info->invert; | |
35 | } | |
36 | ||
37 | static int | |
38 | checkentry(const char *tablename, | |
2e4e6a17 | 39 | const void *entry, |
c4986734 | 40 | const struct xt_match *match, |
1da177e4 | 41 | void *matchinfo, |
1da177e4 LT |
42 | unsigned int hook_mask) |
43 | { | |
3e72b2fe | 44 | const struct xt_mark_info *minfo = matchinfo; |
bf3a46aa | 45 | |
bf3a46aa HW |
46 | if (minfo->mark > 0xffffffff || minfo->mask > 0xffffffff) { |
47 | printk(KERN_WARNING "mark: only supports 32bit mark\n"); | |
48 | return 0; | |
49 | } | |
1da177e4 LT |
50 | return 1; |
51 | } | |
52 | ||
4470bbc7 PM |
53 | static struct xt_match xt_mark_match[] = { |
54 | { | |
55 | .name = "mark", | |
56 | .family = AF_INET, | |
57 | .checkentry = checkentry, | |
58 | .match = match, | |
59 | .matchsize = sizeof(struct xt_mark_info), | |
60 | .me = THIS_MODULE, | |
61 | }, | |
62 | { | |
63 | .name = "mark", | |
64 | .family = AF_INET6, | |
65 | .checkentry = checkentry, | |
66 | .match = match, | |
67 | .matchsize = sizeof(struct xt_mark_info), | |
68 | .me = THIS_MODULE, | |
69 | }, | |
1da177e4 LT |
70 | }; |
71 | ||
65b4b4e8 | 72 | static int __init xt_mark_init(void) |
1da177e4 | 73 | { |
4470bbc7 | 74 | return xt_register_matches(xt_mark_match, ARRAY_SIZE(xt_mark_match)); |
1da177e4 LT |
75 | } |
76 | ||
65b4b4e8 | 77 | static void __exit xt_mark_fini(void) |
1da177e4 | 78 | { |
4470bbc7 | 79 | xt_unregister_matches(xt_mark_match, ARRAY_SIZE(xt_mark_match)); |
1da177e4 LT |
80 | } |
81 | ||
65b4b4e8 AM |
82 | module_init(xt_mark_init); |
83 | module_exit(xt_mark_fini); |