Blame view

net/netfilter/xt_mark.c 2.04 KB
17b0d7ef6   Jan Engelhardt   [NETFILTER]: xt_m...
1
2
3
4
5
  /*
   *	xt_mark - Netfilter module to match NFMARK value
   *
   *	(C) 1999-2001 Marc Boucher <marc@mbsi.ca>
   *	Copyright © CC Computer Consultants GmbH, 2007 - 2008
4725c7287   Jan Engelhardt   netfilter: xtable...
6
   *	Jan Engelhardt <jengelh@medozas.de>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
7
   *
17b0d7ef6   Jan Engelhardt   [NETFILTER]: xt_m...
8
9
10
   *	This program is free software; you can redistribute it and/or modify
   *	it under the terms of the GNU General Public License version 2 as
   *	published by the Free Software Foundation.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
11
12
13
14
   */
  
  #include <linux/module.h>
  #include <linux/skbuff.h>
2e4e6a17a   Harald Welte   [NETFILTER] x_tab...
15
16
  #include <linux/netfilter/xt_mark.h>
  #include <linux/netfilter/x_tables.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17
18
19
  
  MODULE_LICENSE("GPL");
  MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
28b949885   Jan Engelhardt   netfilter: xtable...
20
  MODULE_DESCRIPTION("Xtables: packet mark operations");
2e4e6a17a   Harald Welte   [NETFILTER] x_tab...
21
22
  MODULE_ALIAS("ipt_mark");
  MODULE_ALIAS("ip6t_mark");
28b949885   Jan Engelhardt   netfilter: xtable...
23
24
25
26
  MODULE_ALIAS("ipt_MARK");
  MODULE_ALIAS("ip6t_MARK");
  
  static unsigned int
4b560b447   Jan Engelhardt   netfilter: xtable...
27
  mark_tg(struct sk_buff *skb, const struct xt_action_param *par)
28b949885   Jan Engelhardt   netfilter: xtable...
28
29
30
31
32
33
  {
  	const struct xt_mark_tginfo2 *info = par->targinfo;
  
  	skb->mark = (skb->mark & ~info->mask) ^ info->mark;
  	return XT_CONTINUE;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
34

1d93a9cba   Jan Engelhardt   [NETFILTER]: x_ta...
35
  static bool
62fc80510   Jan Engelhardt   netfilter: xtable...
36
  mark_mt(const struct sk_buff *skb, struct xt_action_param *par)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
  {
f7108a20d   Jan Engelhardt   netfilter: xtable...
38
  	const struct xt_mark_mtinfo1 *info = par->matchinfo;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
39

82e91ffef   Thomas Graf   [NET]: Turn nfmar...
40
  	return ((skb->mark & info->mask) == info->mark) ^ info->invert;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
41
  }
28b949885   Jan Engelhardt   netfilter: xtable...
42
43
44
45
46
47
48
49
  static struct xt_target mark_tg_reg __read_mostly = {
  	.name           = "MARK",
  	.revision       = 2,
  	.family         = NFPROTO_UNSPEC,
  	.target         = mark_tg,
  	.targetsize     = sizeof(struct xt_mark_tginfo2),
  	.me             = THIS_MODULE,
  };
4725c7287   Jan Engelhardt   netfilter: xtable...
50
51
52
53
54
55
56
  static struct xt_match mark_mt_reg __read_mostly = {
  	.name           = "mark",
  	.revision       = 1,
  	.family         = NFPROTO_UNSPEC,
  	.match          = mark_mt,
  	.matchsize      = sizeof(struct xt_mark_mtinfo1),
  	.me             = THIS_MODULE,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
57
  };
d3c5ee6d5   Jan Engelhardt   [NETFILTER]: x_ta...
58
  static int __init mark_mt_init(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
  {
28b949885   Jan Engelhardt   netfilter: xtable...
60
61
62
63
64
65
66
67
68
69
70
  	int ret;
  
  	ret = xt_register_target(&mark_tg_reg);
  	if (ret < 0)
  		return ret;
  	ret = xt_register_match(&mark_mt_reg);
  	if (ret < 0) {
  		xt_unregister_target(&mark_tg_reg);
  		return ret;
  	}
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71
  }
d3c5ee6d5   Jan Engelhardt   [NETFILTER]: x_ta...
72
  static void __exit mark_mt_exit(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73
  {
4725c7287   Jan Engelhardt   netfilter: xtable...
74
  	xt_unregister_match(&mark_mt_reg);
28b949885   Jan Engelhardt   netfilter: xtable...
75
  	xt_unregister_target(&mark_tg_reg);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
76
  }
d3c5ee6d5   Jan Engelhardt   [NETFILTER]: x_ta...
77
78
  module_init(mark_mt_init);
  module_exit(mark_mt_exit);