hc
2024-08-16 62c46c9150c4afde7e5b25436263fddf79d66f0b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// SPDX-License-Identifier: GPL-2.0-only
/*
 *  ebt_mark_m
 *
 *    Authors:
 *    Bart De Schuymer <bdschuym@pandora.be>
 *
 *  July, 2002
 *
 */
#include <linux/module.h>
#include <linux/netfilter/x_tables.h>
#include <linux/netfilter_bridge/ebtables.h>
#include <linux/netfilter_bridge/ebt_mark_m.h>
 
static bool
ebt_mark_mt(const struct sk_buff *skb, struct xt_action_param *par)
{
   const struct ebt_mark_m_info *info = par->matchinfo;
 
   if (info->bitmask & EBT_MARK_OR)
       return !!(skb->mark & info->mask) ^ info->invert;
   return ((skb->mark & info->mask) == info->mark) ^ info->invert;
}
 
static int ebt_mark_mt_check(const struct xt_mtchk_param *par)
{
   const struct ebt_mark_m_info *info = par->matchinfo;
 
   if (info->bitmask & ~EBT_MARK_MASK)
       return -EINVAL;
   if ((info->bitmask & EBT_MARK_OR) && (info->bitmask & EBT_MARK_AND))
       return -EINVAL;
   if (!info->bitmask)
       return -EINVAL;
   return 0;
}
 
 
#ifdef CONFIG_COMPAT
struct compat_ebt_mark_m_info {
   compat_ulong_t mark, mask;
   uint8_t invert, bitmask;
};
 
static void mark_mt_compat_from_user(void *dst, const void *src)
{
   const struct compat_ebt_mark_m_info *user = src;
   struct ebt_mark_m_info *kern = dst;
 
   kern->mark = user->mark;
   kern->mask = user->mask;
   kern->invert = user->invert;
   kern->bitmask = user->bitmask;
}
 
static int mark_mt_compat_to_user(void __user *dst, const void *src)
{
   struct compat_ebt_mark_m_info __user *user = dst;
   const struct ebt_mark_m_info *kern = src;
 
   if (put_user(kern->mark, &user->mark) ||
       put_user(kern->mask, &user->mask) ||
       put_user(kern->invert, &user->invert) ||
       put_user(kern->bitmask, &user->bitmask))
       return -EFAULT;
   return 0;
}
#endif
 
static struct xt_match ebt_mark_mt_reg __read_mostly = {
   .name        = "mark_m",
   .revision    = 0,
   .family        = NFPROTO_BRIDGE,
   .match        = ebt_mark_mt,
   .checkentry    = ebt_mark_mt_check,
   .matchsize    = sizeof(struct ebt_mark_m_info),
#ifdef CONFIG_COMPAT
   .compatsize    = sizeof(struct compat_ebt_mark_m_info),
   .compat_from_user = mark_mt_compat_from_user,
   .compat_to_user    = mark_mt_compat_to_user,
#endif
   .me        = THIS_MODULE,
};
 
static int __init ebt_mark_m_init(void)
{
   return xt_register_match(&ebt_mark_mt_reg);
}
 
static void __exit ebt_mark_m_fini(void)
{
   xt_unregister_match(&ebt_mark_mt_reg);
}
 
module_init(ebt_mark_m_init);
module_exit(ebt_mark_m_fini);
MODULE_DESCRIPTION("Ebtables: Packet mark match");
MODULE_LICENSE("GPL");