allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / net / netfilter / xt_dscp.c
blob56b247ecc283b7dbc8f546526a80335b24c9dd80
1 /* IP tables module for matching the value of the IPv4/IPv6 DSCP field
3 * (C) 2002 by Harald Welte <laforge@netfilter.org>
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 */
10 #include <linux/module.h>
11 #include <linux/skbuff.h>
12 #include <linux/ip.h>
13 #include <linux/ipv6.h>
14 #include <net/dsfield.h>
16 #include <linux/netfilter/xt_dscp.h>
17 #include <linux/netfilter/x_tables.h>
19 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
20 MODULE_DESCRIPTION("x_tables DSCP matching module");
21 MODULE_LICENSE("GPL");
22 MODULE_ALIAS("ipt_dscp");
23 MODULE_ALIAS("ip6t_dscp");
25 static int match(const struct sk_buff *skb,
26 const struct net_device *in,
27 const struct net_device *out,
28 const struct xt_match *match,
29 const void *matchinfo,
30 int offset,
31 unsigned int protoff,
32 int *hotdrop)
34 const struct xt_dscp_info *info = matchinfo;
35 u_int8_t dscp = ipv4_get_dsfield(ip_hdr(skb)) >> XT_DSCP_SHIFT;
37 return (dscp == info->dscp) ^ !!info->invert;
40 static int match6(const struct sk_buff *skb,
41 const struct net_device *in,
42 const struct net_device *out,
43 const struct xt_match *match,
44 const void *matchinfo,
45 int offset,
46 unsigned int protoff,
47 int *hotdrop)
49 const struct xt_dscp_info *info = matchinfo;
50 u_int8_t dscp = ipv6_get_dsfield(ipv6_hdr(skb)) >> XT_DSCP_SHIFT;
52 return (dscp == info->dscp) ^ !!info->invert;
55 static int checkentry(const char *tablename,
56 const void *info,
57 const struct xt_match *match,
58 void *matchinfo,
59 unsigned int hook_mask)
61 const u_int8_t dscp = ((struct xt_dscp_info *)matchinfo)->dscp;
63 if (dscp > XT_DSCP_MAX) {
64 printk(KERN_ERR "xt_dscp: dscp %x out of range\n", dscp);
65 return 0;
68 return 1;
71 static struct xt_match xt_dscp_match[] = {
73 .name = "dscp",
74 .family = AF_INET,
75 .checkentry = checkentry,
76 .match = match,
77 .matchsize = sizeof(struct xt_dscp_info),
78 .me = THIS_MODULE,
81 .name = "dscp",
82 .family = AF_INET6,
83 .checkentry = checkentry,
84 .match = match6,
85 .matchsize = sizeof(struct xt_dscp_info),
86 .me = THIS_MODULE,
90 static int __init xt_dscp_match_init(void)
92 return xt_register_matches(xt_dscp_match, ARRAY_SIZE(xt_dscp_match));
95 static void __exit xt_dscp_match_fini(void)
97 xt_unregister_matches(xt_dscp_match, ARRAY_SIZE(xt_dscp_match));
100 module_init(xt_dscp_match_init);
101 module_exit(xt_dscp_match_fini);