5 * Bart De Schuymer <bdschuym@pandora.be>
10 #include <linux/module.h>
11 #include <linux/netfilter/x_tables.h>
12 #include <linux/netfilter_bridge/ebtables.h>
13 #include <linux/netfilter_bridge/ebt_mark_m.h>
16 ebt_mark_mt(const struct sk_buff
*skb
, struct xt_action_param
*par
)
18 const struct ebt_mark_m_info
*info
= par
->matchinfo
;
20 if (info
->bitmask
& EBT_MARK_OR
)
21 return !!(skb
->mark
& info
->mask
) ^ info
->invert
;
22 return ((skb
->mark
& info
->mask
) == info
->mark
) ^ info
->invert
;
25 static int ebt_mark_mt_check(const struct xt_mtchk_param
*par
)
27 const struct ebt_mark_m_info
*info
= par
->matchinfo
;
29 if (info
->bitmask
& ~EBT_MARK_MASK
)
31 if ((info
->bitmask
& EBT_MARK_OR
) && (info
->bitmask
& EBT_MARK_AND
))
40 struct compat_ebt_mark_m_info
{
41 compat_ulong_t mark
, mask
;
42 uint8_t invert
, bitmask
;
45 static void mark_mt_compat_from_user(void *dst
, const void *src
)
47 const struct compat_ebt_mark_m_info
*user
= src
;
48 struct ebt_mark_m_info
*kern
= dst
;
50 kern
->mark
= user
->mark
;
51 kern
->mask
= user
->mask
;
52 kern
->invert
= user
->invert
;
53 kern
->bitmask
= user
->bitmask
;
56 static int mark_mt_compat_to_user(void __user
*dst
, const void *src
)
58 struct compat_ebt_mark_m_info __user
*user
= dst
;
59 const struct ebt_mark_m_info
*kern
= src
;
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
))
70 static struct xt_match ebt_mark_mt_reg __read_mostly
= {
73 .family
= NFPROTO_BRIDGE
,
75 .checkentry
= ebt_mark_mt_check
,
76 .matchsize
= sizeof(struct ebt_mark_m_info
),
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
,
85 static int __init
ebt_mark_m_init(void)
87 return xt_register_match(&ebt_mark_mt_reg
);
90 static void __exit
ebt_mark_m_fini(void)
92 xt_unregister_match(&ebt_mark_mt_reg
);
95 module_init(ebt_mark_m_init
);
96 module_exit(ebt_mark_m_fini
);
97 MODULE_DESCRIPTION("Ebtables: Packet mark match");
98 MODULE_LICENSE("GPL");