[NETFILTER]: Convert x_tables matches/targets to centralized error checking
[deliverable/linux.git] / net / netfilter / xt_mark.c
CommitLineData
1da177e4
LT
1/* 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
2e4e6a17
HW
13#include <linux/netfilter/xt_mark.h>
14#include <linux/netfilter/x_tables.h>
1da177e4
LT
15
16MODULE_LICENSE("GPL");
17MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
18MODULE_DESCRIPTION("iptables mark matching module");
2e4e6a17
HW
19MODULE_ALIAS("ipt_mark");
20MODULE_ALIAS("ip6t_mark");
1da177e4
LT
21
22static int
23match(const struct sk_buff *skb,
24 const struct net_device *in,
25 const struct net_device *out,
26 const void *matchinfo,
27 int offset,
2e4e6a17 28 unsigned int protoff,
1da177e4
LT
29 int *hotdrop)
30{
2e4e6a17 31 const struct xt_mark_info *info = matchinfo;
1da177e4
LT
32
33 return ((skb->nfmark & info->mask) == info->mark) ^ info->invert;
34}
35
36static int
37checkentry(const char *tablename,
2e4e6a17 38 const void *entry,
1da177e4
LT
39 void *matchinfo,
40 unsigned int matchsize,
41 unsigned int hook_mask)
42{
2e4e6a17 43 struct xt_mark_info *minfo = (struct xt_mark_info *) matchinfo;
bf3a46aa 44
bf3a46aa
HW
45 if (minfo->mark > 0xffffffff || minfo->mask > 0xffffffff) {
46 printk(KERN_WARNING "mark: only supports 32bit mark\n");
47 return 0;
48 }
1da177e4
LT
49 return 1;
50}
51
2e4e6a17
HW
52static struct xt_match mark_match = {
53 .name = "mark",
5d04bff0
PM
54 .match = match,
55 .matchsize = sizeof(struct xt_mark_info),
56 .checkentry = checkentry,
2e4e6a17
HW
57 .me = THIS_MODULE,
58};
59
60static struct xt_match mark6_match = {
1da177e4 61 .name = "mark",
5d04bff0
PM
62 .match = match,
63 .matchsize = sizeof(struct xt_mark_info),
64 .checkentry = checkentry,
1da177e4
LT
65 .me = THIS_MODULE,
66};
67
68static int __init init(void)
69{
2e4e6a17
HW
70 int ret;
71 ret = xt_register_match(AF_INET, &mark_match);
72 if (ret)
73 return ret;
74
75 ret = xt_register_match(AF_INET6, &mark6_match);
76 if (ret)
77 xt_unregister_match(AF_INET, &mark_match);
78
79 return ret;
1da177e4
LT
80}
81
82static void __exit fini(void)
83{
2e4e6a17
HW
84 xt_unregister_match(AF_INET, &mark_match);
85 xt_unregister_match(AF_INET6, &mark6_match);
1da177e4
LT
86}
87
88module_init(init);
89module_exit(fini);
This page took 0.114185 seconds and 5 git commands to generate.