blob: 496a565153074e47286f928975898ad66326bcef [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ebt_pkttype
3 *
4 * Authors:
5 * Bart De Schuymer <bdschuym@pandora.be>
6 *
7 * April, 2003
8 *
9 */
Jan Engelhardt18219d32008-10-08 11:35:13 +020010#include <linux/module.h>
11#include <linux/netfilter/x_tables.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/netfilter_bridge/ebtables.h>
13#include <linux/netfilter_bridge/ebt_pkttype.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
Jan Engelhardt2d06d4a2008-10-08 11:35:15 +020015static bool
Jan Engelhardt62fc8052009-07-07 20:42:08 +020016ebt_pkttype_mt(const struct sk_buff *skb, struct xt_action_param *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -070017{
Jan Engelhardtf7108a22008-10-08 11:35:18 +020018 const struct ebt_pkttype_info *info = par->matchinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070019
Jan Engelhardt8cc784e2008-10-08 11:35:13 +020020 return (skb->pkt_type == info->pkt_type) ^ info->invert;
Linus Torvalds1da177e2005-04-16 15:20:36 -070021}
22
Jan Engelhardtb0f38452010-03-19 17:16:42 +010023static int ebt_pkttype_mt_check(const struct xt_mtchk_param *par)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024{
Jan Engelhardt9b4fce72008-10-08 11:35:18 +020025 const struct ebt_pkttype_info *info = par->matchinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 if (info->invert != 0 && info->invert != 1)
Jan Engelhardtbd414ee2010-03-23 16:35:56 +010028 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029 /* Allow any pkt_type value */
Jan Engelhardtbd414ee2010-03-23 16:35:56 +010030 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031}
32
Jan Engelhardt043ef462008-10-08 11:35:15 +020033static struct xt_match ebt_pkttype_mt_reg __read_mostly = {
34 .name = "pkttype",
Jan Engelhardt001a18d2008-10-08 11:35:14 +020035 .revision = 0,
36 .family = NFPROTO_BRIDGE,
Jan Engelhardt2d06d4a2008-10-08 11:35:15 +020037 .match = ebt_pkttype_mt,
38 .checkentry = ebt_pkttype_mt_check,
Florian Westphalfc0e3df2010-02-15 18:16:26 +010039 .matchsize = sizeof(struct ebt_pkttype_info),
Linus Torvalds1da177e2005-04-16 15:20:36 -070040 .me = THIS_MODULE,
41};
42
Andrew Morton65b4b4e2006-03-28 16:37:06 -080043static int __init ebt_pkttype_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070044{
Jan Engelhardt043ef462008-10-08 11:35:15 +020045 return xt_register_match(&ebt_pkttype_mt_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046}
47
Andrew Morton65b4b4e2006-03-28 16:37:06 -080048static void __exit ebt_pkttype_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070049{
Jan Engelhardt043ef462008-10-08 11:35:15 +020050 xt_unregister_match(&ebt_pkttype_mt_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051}
52
Andrew Morton65b4b4e2006-03-28 16:37:06 -080053module_init(ebt_pkttype_init);
54module_exit(ebt_pkttype_fini);
Jan Engelhardtf776c4c2008-01-31 04:00:30 -080055MODULE_DESCRIPTION("Ebtables: Link layer packet type match");
Linus Torvalds1da177e2005-04-16 15:20:36 -070056MODULE_LICENSE("GPL");