]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - net/bridge/netfilter/ebt_mark.c
netfilter: move Ebtables to use Xtables
[mirror_ubuntu-zesty-kernel.git] / net / bridge / netfilter / ebt_mark.c
CommitLineData
1da177e4
LT
1/*
2 * ebt_mark
3 *
4 * Authors:
5 * Bart De Schuymer <bdschuym@pandora.be>
6 *
7 * July, 2002
8 *
9 */
10
11/* The mark target can be used in any chain,
12 * I believe adding a mangle table just for marking is total overkill.
13 * Marking a frame doesn't really change anything in the frame anyway.
14 */
15
18219d3f
JE
16#include <linux/module.h>
17#include <linux/netfilter/x_tables.h>
1da177e4
LT
18#include <linux/netfilter_bridge/ebtables.h>
19#include <linux/netfilter_bridge/ebt_mark_t.h>
1da177e4 20
2d06d4a5
JE
21static unsigned int
22ebt_mark_tg(struct sk_buff *skb, const struct net_device *in,
23 const struct net_device *out, unsigned int hook_nr,
24 const struct xt_target *target, const void *data)
1da177e4 25{
abfdf1c4 26 const struct ebt_mark_t_info *info = data;
b18dfa90 27 int action = info->target & -16;
1da177e4 28
b18dfa90 29 if (action == MARK_SET_VALUE)
3db05fea 30 skb->mark = info->mark;
b18dfa90 31 else if (action == MARK_OR_VALUE)
3db05fea 32 skb->mark |= info->mark;
b18dfa90 33 else if (action == MARK_AND_VALUE)
3db05fea 34 skb->mark &= info->mark;
b18dfa90 35 else
3db05fea 36 skb->mark ^= info->mark;
6869c4d8 37
d12cdc3c 38 return info->target | ~EBT_VERDICT_BITS;
1da177e4
LT
39}
40
2d06d4a5
JE
41static bool
42ebt_mark_tg_check(const char *table, const void *e,
43 const struct xt_target *target, void *data,
44 unsigned int hookmask)
1da177e4 45{
abfdf1c4 46 const struct ebt_mark_t_info *info = data;
b18dfa90 47 int tmp;
1da177e4 48
d12cdc3c 49 tmp = info->target | ~EBT_VERDICT_BITS;
b18dfa90 50 if (BASE_CHAIN && tmp == EBT_RETURN)
19eda879 51 return false;
1da177e4 52 CLEAR_BASE_CHAIN_BIT;
b18dfa90 53 if (tmp < -NUM_STANDARD_TARGETS || tmp >= 0)
19eda879 54 return false;
d12cdc3c 55 tmp = info->target & ~EBT_VERDICT_BITS;
b18dfa90
BDS
56 if (tmp != MARK_SET_VALUE && tmp != MARK_OR_VALUE &&
57 tmp != MARK_AND_VALUE && tmp != MARK_XOR_VALUE)
19eda879
JE
58 return false;
59 return true;
1da177e4
LT
60}
61
043ef46c
JE
62static struct xt_target ebt_mark_tg_reg __read_mostly = {
63 .name = "mark",
001a18d3
JE
64 .revision = 0,
65 .family = NFPROTO_BRIDGE,
2d06d4a5
JE
66 .target = ebt_mark_tg,
67 .checkentry = ebt_mark_tg_check,
18219d3f 68 .targetsize = XT_ALIGN(sizeof(struct ebt_mark_t_info)),
1da177e4
LT
69 .me = THIS_MODULE,
70};
71
65b4b4e8 72static int __init ebt_mark_init(void)
1da177e4 73{
043ef46c 74 return xt_register_target(&ebt_mark_tg_reg);
1da177e4
LT
75}
76
65b4b4e8 77static void __exit ebt_mark_fini(void)
1da177e4 78{
043ef46c 79 xt_unregister_target(&ebt_mark_tg_reg);
1da177e4
LT
80}
81
65b4b4e8
AM
82module_init(ebt_mark_init);
83module_exit(ebt_mark_fini);
f776c4cd 84MODULE_DESCRIPTION("Ebtables: Packet mark modification");
1da177e4 85MODULE_LICENSE("GPL");