1 /* x_tables module for setting the IPv4/IPv6 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 * xt_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 <linux/ipv6.h>
19 #include <net/dsfield.h>
21 #include <linux/netfilter/x_tables.h>
22 #include <linux/netfilter/xt_DSCP.h>
24 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
25 MODULE_DESCRIPTION("x_tables DSCP modification module");
26 MODULE_LICENSE("GPL");
27 MODULE_ALIAS("ipt_DSCP");
28 MODULE_ALIAS("ip6t_DSCP");
30 static unsigned int target(struct sk_buff **pskb,
31 const struct net_device *in,
32 const struct net_device *out,
34 const struct xt_target *target,
38 const struct xt_DSCP_info *dinfo = targinfo;
39 u_int8_t dscp = ipv4_get_dsfield((*pskb)->nh.iph) >> XT_DSCP_SHIFT;
41 if (dscp != dinfo->dscp) {
42 if (!skb_make_writable(pskb, sizeof(struct iphdr)))
45 ipv4_change_dsfield((*pskb)->nh.iph, (__u8)(~XT_DSCP_MASK),
46 dinfo->dscp << XT_DSCP_SHIFT);
52 static unsigned int target6(struct sk_buff **pskb,
53 const struct net_device *in,
54 const struct net_device *out,
56 const struct xt_target *target,
60 const struct xt_DSCP_info *dinfo = targinfo;
61 u_int8_t dscp = ipv6_get_dsfield((*pskb)->nh.ipv6h) >> XT_DSCP_SHIFT;
63 if (dscp != dinfo->dscp) {
64 if (!skb_make_writable(pskb, sizeof(struct ipv6hdr)))
67 ipv6_change_dsfield((*pskb)->nh.ipv6h, (__u8)(~XT_DSCP_MASK),
68 dinfo->dscp << XT_DSCP_SHIFT);
73 static int checkentry(const char *tablename,
75 const struct xt_target *target,
77 unsigned int targinfosize,
78 unsigned int hook_mask)
80 const u_int8_t dscp = ((struct xt_DSCP_info *)targinfo)->dscp;
82 if ((dscp > XT_DSCP_MAX)) {
83 printk(KERN_WARNING "DSCP: dscp %x out of range\n", dscp);
89 static struct xt_target xt_dscp_reg = {
92 .targetsize = sizeof(struct xt_DSCP_info),
94 .checkentry = checkentry,
99 static struct xt_target xt_dscp6_reg = {
102 .targetsize = sizeof(struct xt_DSCP_info),
104 .checkentry = checkentry,
109 static int __init xt_dscp_target_init(void)
112 ret = xt_register_target(&xt_dscp_reg);
116 ret = xt_register_target(&xt_dscp6_reg);
118 xt_unregister_target(&xt_dscp_reg);
123 static void __exit xt_dscp_target_fini(void)
125 xt_unregister_target(&xt_dscp_reg);
126 xt_unregister_target(&xt_dscp6_reg);
129 module_init(xt_dscp_target_init);
130 module_exit(xt_dscp_target_fini);