blob: 0accac98dea784d48d764794b872669019721dfb [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * This is a module which is used for setting the skb->priority field
4 * of an skb for qdisc classification.
5 */
6
7/* (C) 2001-2002 Patrick McHardy <kaber@trash.net>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 */
9
10#include <linux/module.h>
11#include <linux/skbuff.h>
12#include <linux/ip.h>
13#include <net/checksum.h>
14
Patrick McHardy891350c2007-02-12 11:14:43 -080015#include <linux/netfilter_ipv4.h>
16#include <linux/netfilter_ipv6.h>
Harald Welte2e4e6a12006-01-12 13:30:04 -080017#include <linux/netfilter/x_tables.h>
18#include <linux/netfilter/xt_CLASSIFY.h>
Frédéric Leroy98116002010-11-15 13:57:56 +010019#include <linux/netfilter_arp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020
21MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
22MODULE_LICENSE("GPL");
Jan Engelhardt2ae15b62008-01-14 23:42:28 -080023MODULE_DESCRIPTION("Xtables: Qdisc classification");
Harald Welte2e4e6a12006-01-12 13:30:04 -080024MODULE_ALIAS("ipt_CLASSIFY");
Jan Engelhardt73aaf932007-10-11 14:36:40 -070025MODULE_ALIAS("ip6t_CLASSIFY");
Frédéric Leroy98116002010-11-15 13:57:56 +010026MODULE_ALIAS("arpt_CLASSIFY");
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
28static unsigned int
Jan Engelhardt4b560b42009-07-05 19:43:26 +020029classify_tg(struct sk_buff *skb, const struct xt_action_param *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030{
Jan Engelhardt7eb35582008-10-08 11:35:19 +020031 const struct xt_classify_target_info *clinfo = par->targinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Herbert Xu3db05fea2007-10-15 00:53:15 -070033 skb->priority = clinfo->priority;
Harald Welte2e4e6a12006-01-12 13:30:04 -080034 return XT_CONTINUE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035}
36
Frédéric Leroy98116002010-11-15 13:57:56 +010037static struct xt_target classify_tg_reg[] __read_mostly = {
38 {
39 .name = "CLASSIFY",
40 .revision = 0,
41 .family = NFPROTO_UNSPEC,
42 .hooks = (1 << NF_INET_LOCAL_OUT) | (1 << NF_INET_FORWARD) |
43 (1 << NF_INET_POST_ROUTING),
44 .target = classify_tg,
45 .targetsize = sizeof(struct xt_classify_target_info),
46 .me = THIS_MODULE,
47 },
48 {
49 .name = "CLASSIFY",
50 .revision = 0,
51 .family = NFPROTO_ARP,
52 .hooks = (1 << NF_ARP_OUT) | (1 << NF_ARP_FORWARD),
53 .target = classify_tg,
54 .targetsize = sizeof(struct xt_classify_target_info),
55 .me = THIS_MODULE,
56 },
Harald Welte2e4e6a12006-01-12 13:30:04 -080057};
Harald Welte2e4e6a12006-01-12 13:30:04 -080058
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080059static int __init classify_tg_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Frédéric Leroy98116002010-11-15 13:57:56 +010061 return xt_register_targets(classify_tg_reg, ARRAY_SIZE(classify_tg_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -070062}
63
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080064static void __exit classify_tg_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070065{
Frédéric Leroy98116002010-11-15 13:57:56 +010066 xt_unregister_targets(classify_tg_reg, ARRAY_SIZE(classify_tg_reg));
Linus Torvalds1da177e2005-04-16 15:20:36 -070067}
68
Jan Engelhardtd3c5ee62007-12-04 23:24:03 -080069module_init(classify_tg_init);
70module_exit(classify_tg_exit);