blob: 1c04ce5a52c77fda4ab3ba144998f2093dca804e [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
16ebt_pkttype_mt(const struct sk_buff *skb, const struct net_device *in,
17 const struct net_device *out, const struct xt_match *match,
18 const void *data, int offset, unsigned int protoff,
19 bool *hotdrop)
Linus Torvalds1da177e2005-04-16 15:20:36 -070020{
Jan Engelhardtabfdf1c2008-01-31 03:59:24 -080021 const struct ebt_pkttype_info *info = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Jan Engelhardt8cc784e2008-10-08 11:35:13 +020023 return (skb->pkt_type == info->pkt_type) ^ info->invert;
Linus Torvalds1da177e2005-04-16 15:20:36 -070024}
25
Jan Engelhardt2d06d4a2008-10-08 11:35:15 +020026static bool
27ebt_pkttype_mt_check(const char *table, const void *e,
28 const struct xt_match *match, void *data,
29 unsigned int hook_mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030{
Jan Engelhardtabfdf1c2008-01-31 03:59:24 -080031 const struct ebt_pkttype_info *info = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070032
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 if (info->invert != 0 && info->invert != 1)
Jan Engelhardt19eda872008-10-08 11:35:13 +020034 return false;
Linus Torvalds1da177e2005-04-16 15:20:36 -070035 /* Allow any pkt_type value */
Jan Engelhardt19eda872008-10-08 11:35:13 +020036 return true;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037}
38
Jan Engelhardt043ef462008-10-08 11:35:15 +020039static struct xt_match ebt_pkttype_mt_reg __read_mostly = {
40 .name = "pkttype",
Jan Engelhardt001a18d2008-10-08 11:35:14 +020041 .revision = 0,
42 .family = NFPROTO_BRIDGE,
Jan Engelhardt2d06d4a2008-10-08 11:35:15 +020043 .match = ebt_pkttype_mt,
44 .checkentry = ebt_pkttype_mt_check,
Jan Engelhardt18219d32008-10-08 11:35:13 +020045 .matchsize = XT_ALIGN(sizeof(struct ebt_pkttype_info)),
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 .me = THIS_MODULE,
47};
48
Andrew Morton65b4b4e2006-03-28 16:37:06 -080049static int __init ebt_pkttype_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070050{
Jan Engelhardt043ef462008-10-08 11:35:15 +020051 return xt_register_match(&ebt_pkttype_mt_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052}
53
Andrew Morton65b4b4e2006-03-28 16:37:06 -080054static void __exit ebt_pkttype_fini(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070055{
Jan Engelhardt043ef462008-10-08 11:35:15 +020056 xt_unregister_match(&ebt_pkttype_mt_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -070057}
58
Andrew Morton65b4b4e2006-03-28 16:37:06 -080059module_init(ebt_pkttype_init);
60module_exit(ebt_pkttype_fini);
Jan Engelhardtf776c4c2008-01-31 04:00:30 -080061MODULE_DESCRIPTION("Ebtables: Link layer packet type match");
Linus Torvalds1da177e2005-04-16 15:20:36 -070062MODULE_LICENSE("GPL");