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.
16 #include <linux/module.h>
17 #include <linux/netfilter/x_tables.h>
18 #include <linux/netfilter_bridge/ebtables.h>
19 #include <linux/netfilter_bridge/ebt_mark_t.h>
22 ebt_mark_tg(struct sk_buff *skb, const struct xt_action_param *par)
24 const struct ebt_mark_t_info *info = par->targinfo;
25 int action = info->target & -16;
27 if (action == MARK_SET_VALUE)
28 skb->mark = info->mark;
29 else if (action == MARK_OR_VALUE)
30 skb->mark |= info->mark;
31 else if (action == MARK_AND_VALUE)
32 skb->mark &= info->mark;
34 skb->mark ^= info->mark;
36 return info->target | ~EBT_VERDICT_BITS;
39 static int ebt_mark_tg_check(const struct xt_tgchk_param *par)
41 const struct ebt_mark_t_info *info = par->targinfo;
44 tmp = info->target | ~EBT_VERDICT_BITS;
45 if (BASE_CHAIN && tmp == EBT_RETURN)
47 if (tmp < -NUM_STANDARD_TARGETS || tmp >= 0)
49 tmp = info->target & ~EBT_VERDICT_BITS;
50 if (tmp != MARK_SET_VALUE && tmp != MARK_OR_VALUE &&
51 tmp != MARK_AND_VALUE && tmp != MARK_XOR_VALUE)
56 struct compat_ebt_mark_t_info {
61 static void mark_tg_compat_from_user(void *dst, const void *src)
63 const struct compat_ebt_mark_t_info *user = src;
64 struct ebt_mark_t_info *kern = dst;
66 kern->mark = user->mark;
67 kern->target = user->target;
70 static int mark_tg_compat_to_user(void __user *dst, const void *src)
72 struct compat_ebt_mark_t_info __user *user = dst;
73 const struct ebt_mark_t_info *kern = src;
75 if (put_user(kern->mark, &user->mark) ||
76 put_user(kern->target, &user->target))
82 static struct xt_target ebt_mark_tg_reg __read_mostly = {
85 .family = NFPROTO_BRIDGE,
86 .target = ebt_mark_tg,
87 .checkentry = ebt_mark_tg_check,
88 .targetsize = sizeof(struct ebt_mark_t_info),
90 .compatsize = sizeof(struct compat_ebt_mark_t_info),
91 .compat_from_user = mark_tg_compat_from_user,
92 .compat_to_user = mark_tg_compat_to_user,
97 static int __init ebt_mark_init(void)
99 return xt_register_target(&ebt_mark_tg_reg);
102 static void __exit ebt_mark_fini(void)
104 xt_unregister_target(&ebt_mark_tg_reg);
107 module_init(ebt_mark_init);
108 module_exit(ebt_mark_fini);
109 MODULE_DESCRIPTION("Ebtables: Packet mark modification");
110 MODULE_LICENSE("GPL");