[NETFILTER]: x_tables: consistent and unique symbol names
[safe/jmp/linux-2.6] / net / netfilter / xt_DSCP.c
1 /* x_tables module for setting the IPv4/IPv6 DSCP field, Version 1.8
2  *
3  * (C) 2002 by Harald Welte <laforge@netfilter.org>
4  * based on ipt_FTOS.c (C) 2000 by Matthew G. Marsh <mgm@paktronix.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * See RFC2474 for a description of the DSCP field within the IP Header.
11 */
12
13 #include <linux/module.h>
14 #include <linux/skbuff.h>
15 #include <linux/ip.h>
16 #include <linux/ipv6.h>
17 #include <net/dsfield.h>
18
19 #include <linux/netfilter/x_tables.h>
20 #include <linux/netfilter/xt_DSCP.h>
21
22 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
23 MODULE_DESCRIPTION("x_tables DSCP modification module");
24 MODULE_LICENSE("GPL");
25 MODULE_ALIAS("ipt_DSCP");
26 MODULE_ALIAS("ip6t_DSCP");
27
28 static unsigned int
29 dscp_tg(struct sk_buff *skb, const struct net_device *in,
30         const struct net_device *out, unsigned int hooknum,
31         const struct xt_target *target, const void *targinfo)
32 {
33         const struct xt_DSCP_info *dinfo = targinfo;
34         u_int8_t dscp = ipv4_get_dsfield(ip_hdr(skb)) >> XT_DSCP_SHIFT;
35
36         if (dscp != dinfo->dscp) {
37                 if (!skb_make_writable(skb, sizeof(struct iphdr)))
38                         return NF_DROP;
39
40                 ipv4_change_dsfield(ip_hdr(skb), (__u8)(~XT_DSCP_MASK),
41                                     dinfo->dscp << XT_DSCP_SHIFT);
42
43         }
44         return XT_CONTINUE;
45 }
46
47 static unsigned int
48 dscp_tg6(struct sk_buff *skb, const struct net_device *in,
49          const struct net_device *out, unsigned int hooknum,
50          const struct xt_target *target, const void *targinfo)
51 {
52         const struct xt_DSCP_info *dinfo = targinfo;
53         u_int8_t dscp = ipv6_get_dsfield(ipv6_hdr(skb)) >> XT_DSCP_SHIFT;
54
55         if (dscp != dinfo->dscp) {
56                 if (!skb_make_writable(skb, sizeof(struct ipv6hdr)))
57                         return NF_DROP;
58
59                 ipv6_change_dsfield(ipv6_hdr(skb), (__u8)(~XT_DSCP_MASK),
60                                     dinfo->dscp << XT_DSCP_SHIFT);
61         }
62         return XT_CONTINUE;
63 }
64
65 static bool
66 dscp_tg_check(const char *tablename, const void *e_void,
67               const struct xt_target *target, void *targinfo,
68               unsigned int hook_mask)
69 {
70         const u_int8_t dscp = ((struct xt_DSCP_info *)targinfo)->dscp;
71
72         if (dscp > XT_DSCP_MAX) {
73                 printk(KERN_WARNING "DSCP: dscp %x out of range\n", dscp);
74                 return false;
75         }
76         return true;
77 }
78
79 static struct xt_target dscp_tg_reg[] __read_mostly = {
80         {
81                 .name           = "DSCP",
82                 .family         = AF_INET,
83                 .checkentry     = dscp_tg_check,
84                 .target         = dscp_tg,
85                 .targetsize     = sizeof(struct xt_DSCP_info),
86                 .table          = "mangle",
87                 .me             = THIS_MODULE,
88         },
89         {
90                 .name           = "DSCP",
91                 .family         = AF_INET6,
92                 .checkentry     = dscp_tg_check,
93                 .target         = dscp_tg6,
94                 .targetsize     = sizeof(struct xt_DSCP_info),
95                 .table          = "mangle",
96                 .me             = THIS_MODULE,
97         },
98 };
99
100 static int __init dscp_tg_init(void)
101 {
102         return xt_register_targets(dscp_tg_reg, ARRAY_SIZE(dscp_tg_reg));
103 }
104
105 static void __exit dscp_tg_exit(void)
106 {
107         xt_unregister_targets(dscp_tg_reg, ARRAY_SIZE(dscp_tg_reg));
108 }
109
110 module_init(dscp_tg_init);
111 module_exit(dscp_tg_exit);