Linux-2.6.12-rc2
[GitHub/mt8127/android_kernel_alcatel_ttab.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, const struct net_device *in,
23 const struct net_device *out, const void *matchinfo,
24 int offset, int *hotdrop)
25 {
26 const struct ipt_dscp_info *info = matchinfo;
27 const struct iphdr *iph = skb->nh.iph;
28
29 u_int8_t sh_dscp = ((info->dscp << IPT_DSCP_SHIFT) & IPT_DSCP_MASK);
30
31 return ((iph->tos&IPT_DSCP_MASK) == sh_dscp) ^ info->invert;
32 }
33
34 static int checkentry(const char *tablename, const struct ipt_ip *ip,
35 void *matchinfo, unsigned int matchsize,
36 unsigned int hook_mask)
37 {
38 if (matchsize != IPT_ALIGN(sizeof(struct ipt_dscp_info)))
39 return 0;
40
41 return 1;
42 }
43
44 static struct ipt_match dscp_match = {
45 .name = "dscp",
46 .match = &match,
47 .checkentry = &checkentry,
48 .me = THIS_MODULE,
49 };
50
51 static int __init init(void)
52 {
53 return ipt_register_match(&dscp_match);
54 }
55
56 static void __exit fini(void)
57 {
58 ipt_unregister_match(&dscp_match);
59
60 }
61
62 module_init(init);
63 module_exit(fini);