]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - net/bridge/netfilter/ebt_mark_m.c
netfilter: xtables: change matches to return error code
[mirror_ubuntu-bionic-kernel.git] / net / bridge / netfilter / ebt_mark_m.c
CommitLineData
1da177e4
LT
1/*
2 * ebt_mark_m
3 *
4 * Authors:
5 * Bart De Schuymer <bdschuym@pandora.be>
6 *
7 * July, 2002
8 *
9 */
18219d3f
JE
10#include <linux/module.h>
11#include <linux/netfilter/x_tables.h>
1da177e4
LT
12#include <linux/netfilter_bridge/ebtables.h>
13#include <linux/netfilter_bridge/ebt_mark_m.h>
1da177e4 14
2d06d4a5 15static bool
f7108a20 16ebt_mark_mt(const struct sk_buff *skb, const struct xt_match_param *par)
1da177e4 17{
f7108a20 18 const struct ebt_mark_m_info *info = par->matchinfo;
1da177e4
LT
19
20 if (info->bitmask & EBT_MARK_OR)
8cc784ee
JE
21 return !!(skb->mark & info->mask) ^ info->invert;
22 return ((skb->mark & info->mask) == info->mark) ^ info->invert;
1da177e4
LT
23}
24
b0f38452 25static int ebt_mark_mt_check(const struct xt_mtchk_param *par)
1da177e4 26{
9b4fce7a 27 const struct ebt_mark_m_info *info = par->matchinfo;
1da177e4 28
1da177e4 29 if (info->bitmask & ~EBT_MARK_MASK)
bd414ee6 30 return -EINVAL;
1da177e4 31 if ((info->bitmask & EBT_MARK_OR) && (info->bitmask & EBT_MARK_AND))
bd414ee6 32 return -EINVAL;
1da177e4 33 if (!info->bitmask)
bd414ee6
JE
34 return -EINVAL;
35 return 0;
1da177e4
LT
36}
37
6e705f56
FW
38
39#ifdef CONFIG_COMPAT
40struct compat_ebt_mark_m_info {
41 compat_ulong_t mark, mask;
42 uint8_t invert, bitmask;
43};
44
45static void mark_mt_compat_from_user(void *dst, const void *src)
46{
47 const struct compat_ebt_mark_m_info *user = src;
48 struct ebt_mark_m_info *kern = dst;
49
50 kern->mark = user->mark;
51 kern->mask = user->mask;
52 kern->invert = user->invert;
53 kern->bitmask = user->bitmask;
54}
55
56static int mark_mt_compat_to_user(void __user *dst, const void *src)
57{
58 struct compat_ebt_mark_m_info __user *user = dst;
59 const struct ebt_mark_m_info *kern = src;
60
61 if (put_user(kern->mark, &user->mark) ||
62 put_user(kern->mask, &user->mask) ||
63 put_user(kern->invert, &user->invert) ||
64 put_user(kern->bitmask, &user->bitmask))
65 return -EFAULT;
66 return 0;
67}
68#endif
69
043ef46c
JE
70static struct xt_match ebt_mark_mt_reg __read_mostly = {
71 .name = "mark_m",
001a18d3
JE
72 .revision = 0,
73 .family = NFPROTO_BRIDGE,
2d06d4a5
JE
74 .match = ebt_mark_mt,
75 .checkentry = ebt_mark_mt_check,
fc0e3df4 76 .matchsize = sizeof(struct ebt_mark_m_info),
6e705f56
FW
77#ifdef CONFIG_COMPAT
78 .compatsize = sizeof(struct compat_ebt_mark_m_info),
79 .compat_from_user = mark_mt_compat_from_user,
80 .compat_to_user = mark_mt_compat_to_user,
81#endif
1da177e4
LT
82 .me = THIS_MODULE,
83};
84
65b4b4e8 85static int __init ebt_mark_m_init(void)
1da177e4 86{
043ef46c 87 return xt_register_match(&ebt_mark_mt_reg);
1da177e4
LT
88}
89
65b4b4e8 90static void __exit ebt_mark_m_fini(void)
1da177e4 91{
043ef46c 92 xt_unregister_match(&ebt_mark_mt_reg);
1da177e4
LT
93}
94
65b4b4e8
AM
95module_init(ebt_mark_m_init);
96module_exit(ebt_mark_m_fini);
f776c4cd 97MODULE_DESCRIPTION("Ebtables: Packet mark match");
1da177e4 98MODULE_LICENSE("GPL");