GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / net / ipv4 / netfilter / ipt_TOS.c
blob39c42ff8676db5789255578916eaea5605961752
1 /* This is a module which is used for setting the TOS field of a packet. */
3 /* (C) 1999-2001 Paul `Rusty' Russell
4 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
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 */
11 #include <linux/module.h>
12 #include <linux/skbuff.h>
13 #include <linux/ip.h>
14 #include <net/checksum.h>
16 #include <linux/netfilter/x_tables.h>
17 #include <linux/netfilter_ipv4/ipt_TOS.h>
19 MODULE_LICENSE("GPL");
20 MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
21 MODULE_DESCRIPTION("iptables TOS mangling module");
23 static unsigned int target(struct sk_buff *skb, const struct xt_action_param *par)
25 const struct ipt_tos_target_info *tosinfo = par->targinfo;
26 struct iphdr *iph = ip_hdr(skb);
28 if ((iph->tos & IPTOS_TOS_MASK) != tosinfo->tos) {
29 __u8 oldtos;
30 if (!skb_make_writable(skb, sizeof(struct iphdr)))
31 return NF_DROP;
32 iph = ip_hdr(skb);
33 oldtos = iph->tos;
34 iph->tos = (iph->tos & IPTOS_PREC_MASK) | tosinfo->tos;
35 csum_replace2(&iph->check, htons(oldtos), htons(iph->tos));
37 return XT_CONTINUE;
40 static int checkentry(const struct xt_tgchk_param *par)
42 const u_int8_t tos = ((struct ipt_tos_target_info *)par->targinfo)->tos;
44 if (tos != IPTOS_LOWDELAY
45 && tos != IPTOS_THROUGHPUT
46 && tos != IPTOS_RELIABILITY
47 && tos != IPTOS_MINCOST
48 && tos != IPTOS_NORMALSVC) {
49 printk(KERN_WARNING "TOS: bad tos value %#x\n", tos);
50 return -EINVAL;
52 return 0;
55 static struct xt_target ipt_tos_reg = {
56 .name = "TOS",
57 .family = NFPROTO_IPV4,
58 .target = target,
59 .targetsize = sizeof(struct ipt_tos_target_info),
60 .table = "mangle",
61 .checkentry = checkentry,
62 .me = THIS_MODULE,
65 static int __init ipt_tos_init(void)
67 return xt_register_target(&ipt_tos_reg);
70 static void __exit ipt_tos_fini(void)
72 xt_unregister_target(&ipt_tos_reg);
75 module_init(ipt_tos_init);
76 module_exit(ipt_tos_fini);