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.
13 #include <linux/module.h>
14 #include <linux/skbuff.h>
16 #include <linux/ipv6.h>
17 #include <net/dsfield.h>
19 #include <linux/netfilter/x_tables.h>
20 #include <linux/netfilter/xt_DSCP.h>
22 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
23 MODULE_DESCRIPTION("x_tables DSCP modification module");
24 MODULE_LICENSE("GPL");
25 MODULE_ALIAS("ipt_DSCP");
26 MODULE_ALIAS("ip6t_DSCP");
29 dscp_tg(struct sk_buff *skb, const struct net_device *in,
30 const struct net_device *out, unsigned int hooknum,
31 const struct xt_target *target, const void *targinfo)
33 const struct xt_DSCP_info *dinfo = targinfo;
34 u_int8_t dscp = ipv4_get_dsfield(ip_hdr(skb)) >> XT_DSCP_SHIFT;
36 if (dscp != dinfo->dscp) {
37 if (!skb_make_writable(skb, sizeof(struct iphdr)))
40 ipv4_change_dsfield(ip_hdr(skb), (__u8)(~XT_DSCP_MASK),
41 dinfo->dscp << XT_DSCP_SHIFT);
48 dscp_tg6(struct sk_buff *skb, const struct net_device *in,
49 const struct net_device *out, unsigned int hooknum,
50 const struct xt_target *target, const void *targinfo)
52 const struct xt_DSCP_info *dinfo = targinfo;
53 u_int8_t dscp = ipv6_get_dsfield(ipv6_hdr(skb)) >> XT_DSCP_SHIFT;
55 if (dscp != dinfo->dscp) {
56 if (!skb_make_writable(skb, sizeof(struct ipv6hdr)))
59 ipv6_change_dsfield(ipv6_hdr(skb), (__u8)(~XT_DSCP_MASK),
60 dinfo->dscp << XT_DSCP_SHIFT);
66 dscp_tg_check(const char *tablename, const void *e_void,
67 const struct xt_target *target, void *targinfo,
68 unsigned int hook_mask)
70 const u_int8_t dscp = ((struct xt_DSCP_info *)targinfo)->dscp;
72 if (dscp > XT_DSCP_MAX) {
73 printk(KERN_WARNING "DSCP: dscp %x out of range\n", dscp);
79 static struct xt_target dscp_tg_reg[] __read_mostly = {
83 .checkentry = dscp_tg_check,
85 .targetsize = sizeof(struct xt_DSCP_info),
92 .checkentry = dscp_tg_check,
94 .targetsize = sizeof(struct xt_DSCP_info),
100 static int __init dscp_tg_init(void)
102 return xt_register_targets(dscp_tg_reg, ARRAY_SIZE(dscp_tg_reg));
105 static void __exit dscp_tg_exit(void)
107 xt_unregister_targets(dscp_tg_reg, ARRAY_SIZE(dscp_tg_reg));
110 module_init(dscp_tg_init);
111 module_exit(dscp_tg_exit);