Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / net / ipv4 / netfilter / ipt_dscp.c
1 /* IP tables module for matching the value of the IPv4 DSCP field
2  *
3  * ipt_dscp.c,v 1.3 2002/08/05 19:00:21 laforge Exp
4  *
5  * (C) 2002 by Harald Welte <laforge@netfilter.org>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11
12 #include <linux/module.h>
13 #include <linux/skbuff.h>
14
15 #include <linux/netfilter_ipv4/ipt_dscp.h>
16 #include <linux/netfilter_ipv4/ip_tables.h>
17
18 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
19 MODULE_DESCRIPTION("iptables DSCP matching module");
20 MODULE_LICENSE("GPL");
21
22 static int match(const struct sk_buff *skb,
23                  const struct net_device *in, const struct net_device *out,
24                  const struct xt_match *match, const void *matchinfo,
25                  int offset, unsigned int protoff, int *hotdrop)
26 {
27         const struct ipt_dscp_info *info = matchinfo;
28         const struct iphdr *iph = skb->nh.iph;
29
30         u_int8_t sh_dscp = ((info->dscp << IPT_DSCP_SHIFT) & IPT_DSCP_MASK);
31
32         return ((iph->tos&IPT_DSCP_MASK) == sh_dscp) ^ info->invert;
33 }
34
35 static struct ipt_match dscp_match = {
36         .name           = "dscp",
37         .match          = match,
38         .matchsize      = sizeof(struct ipt_dscp_info),
39         .me             = THIS_MODULE,
40 };
41
42 static int __init ipt_dscp_init(void)
43 {
44         return ipt_register_match(&dscp_match);
45 }
46
47 static void __exit ipt_dscp_fini(void)
48 {
49         ipt_unregister_match(&dscp_match);
50
51 }
52
53 module_init(ipt_dscp_init);
54 module_exit(ipt_dscp_fini);