2019-05-19 06:08:20 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-04-16 16:20:36 -06:00
|
|
|
/*
|
|
|
|
* ebt_mark
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Bart De Schuymer <bdschuym@pandora.be>
|
|
|
|
*
|
|
|
|
* July, 2002
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* The mark target can be used in any chain,
|
|
|
|
* I believe adding a mangle table just for marking is total overkill.
|
|
|
|
* Marking a frame doesn't really change anything in the frame anyway.
|
|
|
|
*/
|
|
|
|
|
2008-10-08 03:35:13 -06:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/netfilter/x_tables.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
#include <linux/netfilter_bridge/ebtables.h>
|
|
|
|
#include <linux/netfilter_bridge/ebt_mark_t.h>
|
|
|
|
|
2008-10-08 03:35:15 -06:00
|
|
|
static unsigned int
|
2009-07-05 11:43:26 -06:00
|
|
|
ebt_mark_tg(struct sk_buff *skb, const struct xt_action_param *par)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-10-08 03:35:19 -06:00
|
|
|
const struct ebt_mark_t_info *info = par->targinfo;
|
2006-10-02 17:12:52 -06:00
|
|
|
int action = info->target & -16;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-10-02 17:12:52 -06:00
|
|
|
if (action == MARK_SET_VALUE)
|
2007-10-15 01:53:15 -06:00
|
|
|
skb->mark = info->mark;
|
2006-10-02 17:12:52 -06:00
|
|
|
else if (action == MARK_OR_VALUE)
|
2007-10-15 01:53:15 -06:00
|
|
|
skb->mark |= info->mark;
|
2006-10-02 17:12:52 -06:00
|
|
|
else if (action == MARK_AND_VALUE)
|
2007-10-15 01:53:15 -06:00
|
|
|
skb->mark &= info->mark;
|
2006-10-02 17:12:52 -06:00
|
|
|
else
|
2007-10-15 01:53:15 -06:00
|
|
|
skb->mark ^= info->mark;
|
2005-08-09 20:24:19 -06:00
|
|
|
|
2006-11-28 18:35:40 -07:00
|
|
|
return info->target | ~EBT_VERDICT_BITS;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2010-03-19 10:16:42 -06:00
|
|
|
static int ebt_mark_tg_check(const struct xt_tgchk_param *par)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-10-08 03:35:19 -06:00
|
|
|
const struct ebt_mark_t_info *info = par->targinfo;
|
2006-10-02 17:12:52 -06:00
|
|
|
int tmp;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2006-11-28 18:35:40 -07:00
|
|
|
tmp = info->target | ~EBT_VERDICT_BITS;
|
2006-10-02 17:12:52 -06:00
|
|
|
if (BASE_CHAIN && tmp == EBT_RETURN)
|
2010-03-25 09:34:45 -06:00
|
|
|
return -EINVAL;
|
2017-05-31 02:55:43 -06:00
|
|
|
if (ebt_invalid_target(tmp))
|
2010-03-25 09:34:45 -06:00
|
|
|
return -EINVAL;
|
2006-11-28 18:35:40 -07:00
|
|
|
tmp = info->target & ~EBT_VERDICT_BITS;
|
2006-10-02 17:12:52 -06:00
|
|
|
if (tmp != MARK_SET_VALUE && tmp != MARK_OR_VALUE &&
|
|
|
|
tmp != MARK_AND_VALUE && tmp != MARK_XOR_VALUE)
|
2010-03-25 09:34:45 -06:00
|
|
|
return -EINVAL;
|
|
|
|
return 0;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
2010-01-27 06:39:05 -07:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
struct compat_ebt_mark_t_info {
|
|
|
|
compat_ulong_t mark;
|
|
|
|
compat_uint_t target;
|
|
|
|
};
|
|
|
|
|
|
|
|
static void mark_tg_compat_from_user(void *dst, const void *src)
|
|
|
|
{
|
|
|
|
const struct compat_ebt_mark_t_info *user = src;
|
|
|
|
struct ebt_mark_t_info *kern = dst;
|
|
|
|
|
|
|
|
kern->mark = user->mark;
|
|
|
|
kern->target = user->target;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mark_tg_compat_to_user(void __user *dst, const void *src)
|
|
|
|
{
|
|
|
|
struct compat_ebt_mark_t_info __user *user = dst;
|
|
|
|
const struct ebt_mark_t_info *kern = src;
|
|
|
|
|
|
|
|
if (put_user(kern->mark, &user->mark) ||
|
|
|
|
put_user(kern->target, &user->target))
|
|
|
|
return -EFAULT;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-10-08 03:35:15 -06:00
|
|
|
static struct xt_target ebt_mark_tg_reg __read_mostly = {
|
|
|
|
.name = "mark",
|
2008-10-08 03:35:14 -06:00
|
|
|
.revision = 0,
|
|
|
|
.family = NFPROTO_BRIDGE,
|
2008-10-08 03:35:15 -06:00
|
|
|
.target = ebt_mark_tg,
|
|
|
|
.checkentry = ebt_mark_tg_check,
|
2010-02-15 10:16:26 -07:00
|
|
|
.targetsize = sizeof(struct ebt_mark_t_info),
|
2010-01-27 06:39:05 -07:00
|
|
|
#ifdef CONFIG_COMPAT
|
|
|
|
.compatsize = sizeof(struct compat_ebt_mark_t_info),
|
|
|
|
.compat_from_user = mark_tg_compat_from_user,
|
|
|
|
.compat_to_user = mark_tg_compat_to_user,
|
|
|
|
#endif
|
2005-04-16 16:20:36 -06:00
|
|
|
.me = THIS_MODULE,
|
|
|
|
};
|
|
|
|
|
2006-03-28 17:37:06 -07:00
|
|
|
static int __init ebt_mark_init(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-10-08 03:35:15 -06:00
|
|
|
return xt_register_target(&ebt_mark_tg_reg);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-03-28 17:37:06 -07:00
|
|
|
static void __exit ebt_mark_fini(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-10-08 03:35:15 -06:00
|
|
|
xt_unregister_target(&ebt_mark_tg_reg);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2006-03-28 17:37:06 -07:00
|
|
|
module_init(ebt_mark_init);
|
|
|
|
module_exit(ebt_mark_fini);
|
2008-01-31 05:00:30 -07:00
|
|
|
MODULE_DESCRIPTION("Ebtables: Packet mark modification");
|
2005-04-16 16:20:36 -06:00
|
|
|
MODULE_LICENSE("GPL");
|