2019-06-04 02:11:33 -06:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2005-04-16 16:20:36 -06:00
|
|
|
/* (C) 1999-2001 Michal Ludvig <michal@logix.cz>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/skbuff.h>
|
|
|
|
#include <linux/if_ether.h>
|
|
|
|
#include <linux/if_packet.h>
|
2006-07-24 23:54:14 -06:00
|
|
|
#include <linux/in.h>
|
|
|
|
#include <linux/ip.h>
|
2008-01-15 00:41:50 -07:00
|
|
|
#include <linux/ipv6.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
[NETFILTER] x_tables: Abstraction layer for {ip,ip6,arp}_tables
This monster-patch tries to do the best job for unifying the data
structures and backend interfaces for the three evil clones ip_tables,
ip6_tables and arp_tables. In an ideal world we would never have
allowed this kind of copy+paste programming... but well, our world
isn't (yet?) ideal.
o introduce a new x_tables module
o {ip,arp,ip6}_tables depend on this x_tables module
o registration functions for tables, matches and targets are only
wrappers around x_tables provided functions
o all matches/targets that are used from ip_tables and ip6_tables
are now implemented as xt_FOOBAR.c files and provide module aliases
to ipt_FOOBAR and ip6t_FOOBAR
o header files for xt_matches are in include/linux/netfilter/,
include/linux/netfilter_{ipv4,ipv6} contains compatibility wrappers
around the xt_FOOBAR.h headers
Based on this patchset we're going to further unify the code,
gradually getting rid of all the layer 3 specific assumptions.
Signed-off-by: Harald Welte <laforge@netfilter.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2006-01-12 14:30:04 -07:00
|
|
|
#include <linux/netfilter/xt_pkttype.h>
|
|
|
|
#include <linux/netfilter/x_tables.h>
|
2005-04-16 16:20:36 -06:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Michal Ludvig <michal@logix.cz>");
|
2008-01-15 00:42:28 -07:00
|
|
|
MODULE_DESCRIPTION("Xtables: link layer packet type match");
|
[NETFILTER] x_tables: Abstraction layer for {ip,ip6,arp}_tables
This monster-patch tries to do the best job for unifying the data
structures and backend interfaces for the three evil clones ip_tables,
ip6_tables and arp_tables. In an ideal world we would never have
allowed this kind of copy+paste programming... but well, our world
isn't (yet?) ideal.
o introduce a new x_tables module
o {ip,arp,ip6}_tables depend on this x_tables module
o registration functions for tables, matches and targets are only
wrappers around x_tables provided functions
o all matches/targets that are used from ip_tables and ip6_tables
are now implemented as xt_FOOBAR.c files and provide module aliases
to ipt_FOOBAR and ip6t_FOOBAR
o header files for xt_matches are in include/linux/netfilter/,
include/linux/netfilter_{ipv4,ipv6} contains compatibility wrappers
around the xt_FOOBAR.h headers
Based on this patchset we're going to further unify the code,
gradually getting rid of all the layer 3 specific assumptions.
Signed-off-by: Harald Welte <laforge@netfilter.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2006-01-12 14:30:04 -07:00
|
|
|
MODULE_ALIAS("ipt_pkttype");
|
|
|
|
MODULE_ALIAS("ip6t_pkttype");
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2007-12-05 00:24:03 -07:00
|
|
|
static bool
|
2009-07-07 12:42:08 -06:00
|
|
|
pkttype_mt(const struct sk_buff *skb, struct xt_action_param *par)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-10-08 03:35:18 -06:00
|
|
|
const struct xt_pkttype_info *info = par->matchinfo;
|
2008-01-15 00:41:50 -07:00
|
|
|
u_int8_t type;
|
2005-04-16 16:20:36 -06:00
|
|
|
|
2008-01-15 00:41:50 -07:00
|
|
|
if (skb->pkt_type != PACKET_LOOPBACK)
|
2006-07-24 23:54:14 -06:00
|
|
|
type = skb->pkt_type;
|
2016-11-03 03:56:21 -06:00
|
|
|
else if (xt_family(par) == NFPROTO_IPV4 &&
|
2008-01-15 00:41:50 -07:00
|
|
|
ipv4_is_multicast(ip_hdr(skb)->daddr))
|
|
|
|
type = PACKET_MULTICAST;
|
2017-01-07 06:33:54 -07:00
|
|
|
else if (xt_family(par) == NFPROTO_IPV6)
|
2008-01-15 00:41:50 -07:00
|
|
|
type = PACKET_MULTICAST;
|
|
|
|
else
|
|
|
|
type = PACKET_BROADCAST;
|
2006-07-24 23:54:14 -06:00
|
|
|
|
|
|
|
return (type == info->pkttype) ^ info->invert;
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2008-10-08 03:35:20 -06:00
|
|
|
static struct xt_match pkttype_mt_reg __read_mostly = {
|
|
|
|
.name = "pkttype",
|
|
|
|
.revision = 0,
|
|
|
|
.family = NFPROTO_UNSPEC,
|
|
|
|
.match = pkttype_mt,
|
|
|
|
.matchsize = sizeof(struct xt_pkttype_info),
|
|
|
|
.me = THIS_MODULE,
|
[NETFILTER] x_tables: Abstraction layer for {ip,ip6,arp}_tables
This monster-patch tries to do the best job for unifying the data
structures and backend interfaces for the three evil clones ip_tables,
ip6_tables and arp_tables. In an ideal world we would never have
allowed this kind of copy+paste programming... but well, our world
isn't (yet?) ideal.
o introduce a new x_tables module
o {ip,arp,ip6}_tables depend on this x_tables module
o registration functions for tables, matches and targets are only
wrappers around x_tables provided functions
o all matches/targets that are used from ip_tables and ip6_tables
are now implemented as xt_FOOBAR.c files and provide module aliases
to ipt_FOOBAR and ip6t_FOOBAR
o header files for xt_matches are in include/linux/netfilter/,
include/linux/netfilter_{ipv4,ipv6} contains compatibility wrappers
around the xt_FOOBAR.h headers
Based on this patchset we're going to further unify the code,
gradually getting rid of all the layer 3 specific assumptions.
Signed-off-by: Harald Welte <laforge@netfilter.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2006-01-12 14:30:04 -07:00
|
|
|
};
|
|
|
|
|
2007-12-05 00:24:03 -07:00
|
|
|
static int __init pkttype_mt_init(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-10-08 03:35:20 -06:00
|
|
|
return xt_register_match(&pkttype_mt_reg);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-12-05 00:24:03 -07:00
|
|
|
static void __exit pkttype_mt_exit(void)
|
2005-04-16 16:20:36 -06:00
|
|
|
{
|
2008-10-08 03:35:20 -06:00
|
|
|
xt_unregister_match(&pkttype_mt_reg);
|
2005-04-16 16:20:36 -06:00
|
|
|
}
|
|
|
|
|
2007-12-05 00:24:03 -07:00
|
|
|
module_init(pkttype_mt_init);
|
|
|
|
module_exit(pkttype_mt_exit);
|