[NETFILTER]: x_tables: add xt_{match,target} arguments to match/target functions
[deliverable/linux.git] / net / ipv4 / netfilter / ipt_TOS.c
CommitLineData
1da177e4
LT
1/* This is a module which is used for setting the TOS field of a packet. */
2
3/* (C) 1999-2001 Paul `Rusty' Russell
4 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
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
11#include <linux/module.h>
12#include <linux/skbuff.h>
13#include <linux/ip.h>
14#include <net/checksum.h>
15
16#include <linux/netfilter_ipv4/ip_tables.h>
17#include <linux/netfilter_ipv4/ipt_TOS.h>
18
19MODULE_LICENSE("GPL");
20MODULE_AUTHOR("Netfilter Core Team <coreteam@netfilter.org>");
21MODULE_DESCRIPTION("iptables TOS mangling module");
22
23static unsigned int
24target(struct sk_buff **pskb,
25 const struct net_device *in,
26 const struct net_device *out,
27 unsigned int hooknum,
c4986734 28 const struct xt_target *target,
1da177e4
LT
29 const void *targinfo,
30 void *userinfo)
31{
32 const struct ipt_tos_target_info *tosinfo = targinfo;
33
34 if (((*pskb)->nh.iph->tos & IPTOS_TOS_MASK) != tosinfo->tos) {
35 u_int16_t diffs[2];
36
089af26c 37 if (!skb_make_writable(pskb, sizeof(struct iphdr)))
1da177e4
LT
38 return NF_DROP;
39
40 diffs[0] = htons((*pskb)->nh.iph->tos) ^ 0xFFFF;
41 (*pskb)->nh.iph->tos
42 = ((*pskb)->nh.iph->tos & IPTOS_PREC_MASK)
43 | tosinfo->tos;
44 diffs[1] = htons((*pskb)->nh.iph->tos);
45 (*pskb)->nh.iph->check
46 = csum_fold(csum_partial((char *)diffs,
47 sizeof(diffs),
48 (*pskb)->nh.iph->check
49 ^0xFFFF));
1da177e4
LT
50 }
51 return IPT_CONTINUE;
52}
53
54static int
55checkentry(const char *tablename,
2e4e6a17 56 const void *e_void,
c4986734 57 const struct xt_target *target,
1da177e4
LT
58 void *targinfo,
59 unsigned int targinfosize,
60 unsigned int hook_mask)
61{
62 const u_int8_t tos = ((struct ipt_tos_target_info *)targinfo)->tos;
63
1da177e4
LT
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);
70 return 0;
71 }
1da177e4
LT
72 return 1;
73}
74
75static struct ipt_target ipt_tos_reg = {
76 .name = "TOS",
77 .target = target,
1d5cd909
PM
78 .targetsize = sizeof(struct ipt_tos_target_info),
79 .table = "mangle",
1da177e4
LT
80 .checkentry = checkentry,
81 .me = THIS_MODULE,
82};
83
84static int __init init(void)
85{
86 return ipt_register_target(&ipt_tos_reg);
87}
88
89static void __exit fini(void)
90{
91 ipt_unregister_target(&ipt_tos_reg);
92}
93
94module_init(init);
95module_exit(fini);
This page took 0.100326 seconds and 5 git commands to generate.