1 /* Set TOS field in header to any value
3 * (C) 2000 by Matthew G. Marsh <mgm@paktronix.com>
5 * This software is distributed under GNU GPL v2, 1991
7 * ipt_FTOS.c borrowed heavily from ipt_TOS.c 11/09/2000
9 * Updated 3/4/02 - added in Rusty's skb_clone fix
10 * - added MODULE Political License
11 * - redid checksum routine somewhat
14 #include <linux/module.h>
15 #include <linux/skbuff.h>
17 #include <net/checksum.h>
19 #include <linux/netfilter_ipv4/ip_tables.h>
20 #include <linux/netfilter_ipv4/ipt_FTOS.h>
23 target(struct sk_buff **pskb,
25 const struct net_device *in,
26 const struct net_device *out,
30 struct iphdr *iph = (*pskb)->nh.iph;
31 const struct ipt_FTOS_info *ftosinfo = targinfo;
33 if ((iph->tos & IPTOS_TOS_MASK) != ftosinfo->ftos) {
36 /* raw socket (tcpdump) may have clone of incoming
37 skb: don't disturb it --RR */
38 if (skb_cloned(*pskb) && !(*pskb)->sk) {
39 struct sk_buff *nskb = skb_copy(*pskb, GFP_ATOMIC);
44 iph = (*pskb)->nh.iph;
47 diffs[0] = htons(iph->tos) ^ 0xFFFF;
48 iph->tos = ftosinfo->ftos;
49 diffs[1] = htons(iph->tos);
50 iph->check = csum_fold(csum_partial((char *)diffs,
53 (*pskb)->nfcache |= NFC_ALTERED;
59 checkentry(const char *tablename,
60 const struct ipt_entry *e,
62 unsigned int targinfosize,
63 unsigned int hook_mask)
65 const u_int8_t ftos = ((struct ipt_FTOS_info *)targinfo)->ftos;
67 if (targinfosize != IPT_ALIGN(sizeof(struct ipt_FTOS_info))) {
68 printk(KERN_WARNING "FTOS: targinfosize %u != %Zu\n",
70 IPT_ALIGN(sizeof(struct ipt_FTOS_info)));
74 if (strcmp(tablename, "mangle") != 0) {
75 printk(KERN_WARNING "FTOS: can only be called from \"mangle\" table, not \"%s\"\n", tablename);
82 #if defined(CONFIG_MIPS_BRCM)
83 static struct ipt_target ipt_ftos_reg = {
86 .checkentry = checkentry,
90 static struct ipt_target ipt_ftos_reg
91 = { { NULL, NULL }, "FTOS", target, checkentry, NULL, THIS_MODULE };
94 static int __init init(void)
96 if (ipt_register_target(&ipt_ftos_reg))
102 static void __exit fini(void)
104 ipt_unregister_target(&ipt_ftos_reg);
109 MODULE_LICENSE("GPL");