1 /* IP tables module for matching the value of the IPv4/IPv6 DSCP field
3 * (C) 2002 by Harald Welte <laforge@netfilter.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
10 #include <linux/module.h>
11 #include <linux/skbuff.h>
13 #include <linux/ipv6.h>
14 #include <net/dsfield.h>
16 #include <linux/netfilter/xt_dscp.h>
17 #include <linux/netfilter/x_tables.h>
19 MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
20 MODULE_DESCRIPTION("x_tables DSCP matching module");
21 MODULE_LICENSE("GPL");
22 MODULE_ALIAS("ipt_dscp");
23 MODULE_ALIAS("ip6t_dscp");
25 static int match(const struct sk_buff *skb,
26 const struct net_device *in,
27 const struct net_device *out,
28 const struct xt_match *match,
29 const void *matchinfo,
34 const struct xt_dscp_info *info = matchinfo;
35 u_int8_t dscp = ipv4_get_dsfield(ip_hdr(skb)) >> XT_DSCP_SHIFT;
37 return (dscp == info->dscp) ^ !!info->invert;
40 static int match6(const struct sk_buff *skb,
41 const struct net_device *in,
42 const struct net_device *out,
43 const struct xt_match *match,
44 const void *matchinfo,
49 const struct xt_dscp_info *info = matchinfo;
50 u_int8_t dscp = ipv6_get_dsfield(ipv6_hdr(skb)) >> XT_DSCP_SHIFT;
52 return (dscp == info->dscp) ^ !!info->invert;
55 static int checkentry(const char *tablename,
57 const struct xt_match *match,
59 unsigned int hook_mask)
61 const u_int8_t dscp = ((struct xt_dscp_info *)matchinfo)->dscp;
63 if (dscp > XT_DSCP_MAX) {
64 printk(KERN_ERR "xt_dscp: dscp %x out of range\n", dscp);
71 static struct xt_match xt_dscp_match[] = {
75 .checkentry = checkentry,
77 .matchsize = sizeof(struct xt_dscp_info),
83 .checkentry = checkentry,
85 .matchsize = sizeof(struct xt_dscp_info),
90 static int __init xt_dscp_match_init(void)
92 return xt_register_matches(xt_dscp_match, ARRAY_SIZE(xt_dscp_match));
95 static void __exit xt_dscp_match_fini(void)
97 xt_unregister_matches(xt_dscp_match, ARRAY_SIZE(xt_dscp_match));
100 module_init(xt_dscp_match_init);
101 module_exit(xt_dscp_match_fini);