0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #include <linux/module.h>
0018 #include <linux/netfilter/x_tables.h>
0019 #include <linux/netfilter_bridge/ebtables.h>
0020 #include <linux/netfilter_bridge/ebt_mark_t.h>
0021
0022 static unsigned int
0023 ebt_mark_tg(struct sk_buff *skb, const struct xt_action_param *par)
0024 {
0025 const struct ebt_mark_t_info *info = par->targinfo;
0026 int action = info->target & -16;
0027
0028 if (action == MARK_SET_VALUE)
0029 skb->mark = info->mark;
0030 else if (action == MARK_OR_VALUE)
0031 skb->mark |= info->mark;
0032 else if (action == MARK_AND_VALUE)
0033 skb->mark &= info->mark;
0034 else
0035 skb->mark ^= info->mark;
0036
0037 return info->target | ~EBT_VERDICT_BITS;
0038 }
0039
0040 static int ebt_mark_tg_check(const struct xt_tgchk_param *par)
0041 {
0042 const struct ebt_mark_t_info *info = par->targinfo;
0043 int tmp;
0044
0045 tmp = info->target | ~EBT_VERDICT_BITS;
0046 if (BASE_CHAIN && tmp == EBT_RETURN)
0047 return -EINVAL;
0048 if (ebt_invalid_target(tmp))
0049 return -EINVAL;
0050 tmp = info->target & ~EBT_VERDICT_BITS;
0051 if (tmp != MARK_SET_VALUE && tmp != MARK_OR_VALUE &&
0052 tmp != MARK_AND_VALUE && tmp != MARK_XOR_VALUE)
0053 return -EINVAL;
0054 return 0;
0055 }
0056 #ifdef CONFIG_NETFILTER_XTABLES_COMPAT
0057 struct compat_ebt_mark_t_info {
0058 compat_ulong_t mark;
0059 compat_uint_t target;
0060 };
0061
0062 static void mark_tg_compat_from_user(void *dst, const void *src)
0063 {
0064 const struct compat_ebt_mark_t_info *user = src;
0065 struct ebt_mark_t_info *kern = dst;
0066
0067 kern->mark = user->mark;
0068 kern->target = user->target;
0069 }
0070
0071 static int mark_tg_compat_to_user(void __user *dst, const void *src)
0072 {
0073 struct compat_ebt_mark_t_info __user *user = dst;
0074 const struct ebt_mark_t_info *kern = src;
0075
0076 if (put_user(kern->mark, &user->mark) ||
0077 put_user(kern->target, &user->target))
0078 return -EFAULT;
0079 return 0;
0080 }
0081 #endif
0082
0083 static struct xt_target ebt_mark_tg_reg __read_mostly = {
0084 .name = "mark",
0085 .revision = 0,
0086 .family = NFPROTO_BRIDGE,
0087 .target = ebt_mark_tg,
0088 .checkentry = ebt_mark_tg_check,
0089 .targetsize = sizeof(struct ebt_mark_t_info),
0090 #ifdef CONFIG_NETFILTER_XTABLES_COMPAT
0091 .compatsize = sizeof(struct compat_ebt_mark_t_info),
0092 .compat_from_user = mark_tg_compat_from_user,
0093 .compat_to_user = mark_tg_compat_to_user,
0094 #endif
0095 .me = THIS_MODULE,
0096 };
0097
0098 static int __init ebt_mark_init(void)
0099 {
0100 return xt_register_target(&ebt_mark_tg_reg);
0101 }
0102
0103 static void __exit ebt_mark_fini(void)
0104 {
0105 xt_unregister_target(&ebt_mark_tg_reg);
0106 }
0107
0108 module_init(ebt_mark_init);
0109 module_exit(ebt_mark_fini);
0110 MODULE_DESCRIPTION("Ebtables: Packet mark modification");
0111 MODULE_LICENSE("GPL");