initial commit with v2.6.9
[linux-2.6.9-moxart.git] / net / ipv4 / netfilter / ipt_dscp.c
blob5df52a64a5d4016b43c6952d2a30177a69235e63
1 /* IP tables module for matching the value of the IPv4 DSCP field
3 * ipt_dscp.c,v 1.3 2002/08/05 19:00:21 laforge Exp
5 * (C) 2002 by Harald Welte <laforge@netfilter.org>
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.
12 #include <linux/module.h>
13 #include <linux/skbuff.h>
15 #include <linux/netfilter_ipv4/ipt_dscp.h>
16 #include <linux/netfilter_ipv4/ip_tables.h>
18 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
19 MODULE_DESCRIPTION("iptables DSCP matching module");
20 MODULE_LICENSE("GPL");
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)
26 const struct ipt_dscp_info *info = matchinfo;
27 const struct iphdr *iph = skb->nh.iph;
29 u_int8_t sh_dscp = ((info->dscp << IPT_DSCP_SHIFT) & IPT_DSCP_MASK);
31 return ((iph->tos&IPT_DSCP_MASK) == sh_dscp) ^ info->invert;
34 static int checkentry(const char *tablename, const struct ipt_ip *ip,
35 void *matchinfo, unsigned int matchsize,
36 unsigned int hook_mask)
38 if (matchsize != IPT_ALIGN(sizeof(struct ipt_dscp_info)))
39 return 0;
41 return 1;
44 static struct ipt_match dscp_match = {
45 .name = "dscp",
46 .match = &match,
47 .checkentry = &checkentry,
48 .me = THIS_MODULE,
51 static int __init init(void)
53 return ipt_register_match(&dscp_match);
56 static void __exit fini(void)
58 ipt_unregister_match(&dscp_match);
62 module_init(init);
63 module_exit(fini);