1 /* iptables module for setting the IPv4 DSCP field, Version 1.8
3 * (C) 2002 by Harald Welte <laforge@netfilter.org>
4 * based on ipt_FTOS.c (C) 2000 by Matthew G. Marsh <mgm@paktronix.com>
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.
10 * See RFC2474 for a description of the DSCP field within the IP Header.
12 * ipt_DSCP.c,v 1.8 2002/08/06 18:41:57 laforge Exp
15 #include <linux/module.h>
16 #include <linux/skbuff.h>
18 #include <net/checksum.h>
20 #include <linux/netfilter_ipv4/ip_tables.h>
21 #include <linux/netfilter_ipv4/ipt_DSCP.h>
23 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
24 MODULE_DESCRIPTION("iptables DSCP modification module");
25 MODULE_LICENSE("GPL");
28 target(struct sk_buff
**pskb
,
29 const struct net_device
*in
,
30 const struct net_device
*out
,
32 const struct xt_target
*target
,
36 const struct ipt_DSCP_info
*dinfo
= targinfo
;
37 u_int8_t sh_dscp
= ((dinfo
->dscp
<< IPT_DSCP_SHIFT
) & IPT_DSCP_MASK
);
40 if (((*pskb
)->nh
.iph
->tos
& IPT_DSCP_MASK
) != sh_dscp
) {
43 if (!skb_make_writable(pskb
, sizeof(struct iphdr
)))
46 diffs
[0] = htons((*pskb
)->nh
.iph
->tos
) ^ 0xFFFF;
47 (*pskb
)->nh
.iph
->tos
= ((*pskb
)->nh
.iph
->tos
& ~IPT_DSCP_MASK
)
49 diffs
[1] = htons((*pskb
)->nh
.iph
->tos
);
50 (*pskb
)->nh
.iph
->check
51 = csum_fold(csum_partial((char *)diffs
,
53 (*pskb
)->nh
.iph
->check
60 checkentry(const char *tablename
,
62 const struct xt_target
*target
,
64 unsigned int targinfosize
,
65 unsigned int hook_mask
)
67 const u_int8_t dscp
= ((struct ipt_DSCP_info
*)targinfo
)->dscp
;
69 if ((dscp
> IPT_DSCP_MAX
)) {
70 printk(KERN_WARNING
"DSCP: dscp %x out of range\n", dscp
);
76 static struct ipt_target ipt_dscp_reg
= {
79 .targetsize
= sizeof(struct ipt_DSCP_info
),
81 .checkentry
= checkentry
,
85 static int __init
ipt_dscp_init(void)
87 return ipt_register_target(&ipt_dscp_reg
);
90 static void __exit
ipt_dscp_fini(void)
92 ipt_unregister_target(&ipt_dscp_reg
);
95 module_init(ipt_dscp_init
);
96 module_exit(ipt_dscp_fini
);