]> nv-tegra.nvidia Code Review - linux-3.10.git/blob - net/ipv4/netfilter/ipt_dscp.c
e7889ba22f4c860db6858dc82ef242bc7c932b11
[linux-3.10.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, unsigned int protoff, 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 struct ipt_match dscp_match = {
35         .name           = "dscp",
36         .match          = match,
37         .matchsize      = sizeof(struct ipt_dscp_info),
38         .me             = THIS_MODULE,
39 };
40
41 static int __init init(void)
42 {
43         return ipt_register_match(&dscp_match);
44 }
45
46 static void __exit fini(void)
47 {
48         ipt_unregister_match(&dscp_match);
49
50 }
51
52 module_init(init);
53 module_exit(fini);