blob: 00bef6cdd3f8e3c6b164bea7142b8dba81448be9 [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
13#include <linux/netfilter_ipv4/ipt_mark.h>
14#include <linux/netfilter_ipv4/ip_tables.h>
15
16MODULE_LICENSE("GPL");
17MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
18MODULE_DESCRIPTION("iptables mark matching module");
19
20static int
21match(const struct sk_buff *skb,
22 const struct net_device *in,
23 const struct net_device *out,
24 const void *matchinfo,
25 int offset,
26 int *hotdrop)
27{
28 const struct ipt_mark_info *info = matchinfo;
29
30 return ((skb->nfmark & info->mask) == info->mark) ^ info->invert;
31}
32
33static int
34checkentry(const char *tablename,
35 const struct ipt_ip *ip,
36 void *matchinfo,
37 unsigned int matchsize,
38 unsigned int hook_mask)
39{
Harald Weltebf3a46a2005-08-09 19:22:01 -070040 struct ipt_mark_info *minfo = (struct ipt_mark_info *) matchinfo;
41
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 if (matchsize != IPT_ALIGN(sizeof(struct ipt_mark_info)))
43 return 0;
44
Harald Weltebf3a46a2005-08-09 19:22:01 -070045 if (minfo->mark > 0xffffffff || minfo->mask > 0xffffffff) {
46 printk(KERN_WARNING "mark: only supports 32bit mark\n");
47 return 0;
48 }
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 return 1;
51}
52
53static struct ipt_match mark_match = {
54 .name = "mark",
55 .match = &match,
56 .checkentry = &checkentry,
57 .me = THIS_MODULE,
58};
59
60static int __init init(void)
61{
62 return ipt_register_match(&mark_match);
63}
64
65static void __exit fini(void)
66{
67 ipt_unregister_match(&mark_match);
68}
69
70module_init(init);
71module_exit(fini);