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.
11 #include <linux/module.h>
12 #include <linux/skbuff.h>
14 #include <net/checksum.h>
16 #include <linux/netfilter_ipv4/ip_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");
24 target(struct sk_buff **pskb,
25 const struct net_device *in,
26 const struct net_device *out,
28 const struct xt_target *target,
32 const struct ipt_tos_target_info *tosinfo = targinfo;
34 if (((*pskb)->nh.iph->tos & IPTOS_TOS_MASK) != tosinfo->tos) {
37 if (!skb_make_writable(pskb, sizeof(struct iphdr)))
40 diffs[0] = htons((*pskb)->nh.iph->tos) ^ 0xFFFF;
42 = ((*pskb)->nh.iph->tos & IPTOS_PREC_MASK)
44 diffs[1] = htons((*pskb)->nh.iph->tos);
45 (*pskb)->nh.iph->check
46 = csum_fold(csum_partial((char *)diffs,
48 (*pskb)->nh.iph->check
55 checkentry(const char *tablename,
57 const struct xt_target *target,
59 unsigned int targinfosize,
60 unsigned int hook_mask)
62 const u_int8_t tos = ((struct ipt_tos_target_info *)targinfo)->tos;
64 if (tos != IPTOS_LOWDELAY
65 && tos != IPTOS_THROUGHPUT
66 && tos != IPTOS_RELIABILITY
67 && tos != IPTOS_MINCOST
68 && tos != IPTOS_NORMALSVC) {
69 printk(KERN_WARNING "TOS: bad tos value %#x\n", tos);
75 static struct ipt_target ipt_tos_reg = {
78 .targetsize = sizeof(struct ipt_tos_target_info),
80 .checkentry = checkentry,
84 static int __init ipt_tos_init(void)
86 return ipt_register_target(&ipt_tos_reg);
89 static void __exit ipt_tos_fini(void)
91 ipt_unregister_target(&ipt_tos_reg);
94 module_init(ipt_tos_init);
95 module_exit(ipt_tos_fini);