Blame view
net/netfilter/xt_pkttype.c
1.65 KB
1da177e4c
|
1 2 3 4 5 6 7 8 9 10 11 |
/* (C) 1999-2001 Michal Ludvig <michal@logix.cz> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. */ #include <linux/module.h> #include <linux/skbuff.h> #include <linux/if_ether.h> #include <linux/if_packet.h> |
28658c896
|
12 13 |
#include <linux/in.h> #include <linux/ip.h> |
57de0abbf
|
14 |
#include <linux/ipv6.h> |
1da177e4c
|
15 |
|
2e4e6a17a
|
16 17 |
#include <linux/netfilter/xt_pkttype.h> #include <linux/netfilter/x_tables.h> |
1da177e4c
|
18 19 20 |
MODULE_LICENSE("GPL"); MODULE_AUTHOR("Michal Ludvig <michal@logix.cz>"); |
2ae15b64e
|
21 |
MODULE_DESCRIPTION("Xtables: link layer packet type match"); |
2e4e6a17a
|
22 23 |
MODULE_ALIAS("ipt_pkttype"); MODULE_ALIAS("ip6t_pkttype"); |
1da177e4c
|
24 |
|
d3c5ee6d5
|
25 |
static bool |
62fc80510
|
26 |
pkttype_mt(const struct sk_buff *skb, struct xt_action_param *par) |
1da177e4c
|
27 |
{ |
f7108a20d
|
28 |
const struct xt_pkttype_info *info = par->matchinfo; |
57de0abbf
|
29 |
u_int8_t type; |
1da177e4c
|
30 |
|
57de0abbf
|
31 |
if (skb->pkt_type != PACKET_LOOPBACK) |
28658c896
|
32 |
type = skb->pkt_type; |
92f3b2b1b
|
33 |
else if (par->family == NFPROTO_IPV4 && |
57de0abbf
|
34 35 |
ipv4_is_multicast(ip_hdr(skb)->daddr)) type = PACKET_MULTICAST; |
92f3b2b1b
|
36 |
else if (par->family == NFPROTO_IPV6 && |
57de0abbf
|
37 38 39 40 |
ipv6_hdr(skb)->daddr.s6_addr[0] == 0xFF) type = PACKET_MULTICAST; else type = PACKET_BROADCAST; |
28658c896
|
41 42 |
return (type == info->pkttype) ^ info->invert; |
1da177e4c
|
43 |
} |
92f3b2b1b
|
44 45 46 47 48 49 50 |
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, |
2e4e6a17a
|
51 |
}; |
d3c5ee6d5
|
52 |
static int __init pkttype_mt_init(void) |
1da177e4c
|
53 |
{ |
92f3b2b1b
|
54 |
return xt_register_match(&pkttype_mt_reg); |
1da177e4c
|
55 |
} |
d3c5ee6d5
|
56 |
static void __exit pkttype_mt_exit(void) |
1da177e4c
|
57 |
{ |
92f3b2b1b
|
58 |
xt_unregister_match(&pkttype_mt_reg); |
1da177e4c
|
59 |
} |
d3c5ee6d5
|
60 61 |
module_init(pkttype_mt_init); module_exit(pkttype_mt_exit); |