Blame view
net/netfilter/xt_pkttype.c
1.65 KB
1da177e4c Linux-2.6.12-rc2 |
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 [NETFILTER]: xt_p... |
12 13 |
#include <linux/in.h> #include <linux/ip.h> |
57de0abbf [NETFILTER]: xt_p... |
14 |
#include <linux/ipv6.h> |
1da177e4c Linux-2.6.12-rc2 |
15 |
|
2e4e6a17a [NETFILTER] x_tab... |
16 17 |
#include <linux/netfilter/xt_pkttype.h> #include <linux/netfilter/x_tables.h> |
1da177e4c Linux-2.6.12-rc2 |
18 19 20 |
MODULE_LICENSE("GPL"); MODULE_AUTHOR("Michal Ludvig <michal@logix.cz>"); |
2ae15b64e [NETFILTER]: Upda... |
21 |
MODULE_DESCRIPTION("Xtables: link layer packet type match"); |
2e4e6a17a [NETFILTER] x_tab... |
22 23 |
MODULE_ALIAS("ipt_pkttype"); MODULE_ALIAS("ip6t_pkttype"); |
1da177e4c Linux-2.6.12-rc2 |
24 |
|
d3c5ee6d5 [NETFILTER]: x_ta... |
25 |
static bool |
62fc80510 netfilter: xtable... |
26 |
pkttype_mt(const struct sk_buff *skb, struct xt_action_param *par) |
1da177e4c Linux-2.6.12-rc2 |
27 |
{ |
f7108a20d netfilter: xtable... |
28 |
const struct xt_pkttype_info *info = par->matchinfo; |
57de0abbf [NETFILTER]: xt_p... |
29 |
u_int8_t type; |
1da177e4c Linux-2.6.12-rc2 |
30 |
|
57de0abbf [NETFILTER]: xt_p... |
31 |
if (skb->pkt_type != PACKET_LOOPBACK) |
28658c896 [NETFILTER]: xt_p... |
32 |
type = skb->pkt_type; |
92f3b2b1b netfilter: xtable... |
33 |
else if (par->family == NFPROTO_IPV4 && |
57de0abbf [NETFILTER]: xt_p... |
34 35 |
ipv4_is_multicast(ip_hdr(skb)->daddr)) type = PACKET_MULTICAST; |
92f3b2b1b netfilter: xtable... |
36 |
else if (par->family == NFPROTO_IPV6 && |
57de0abbf [NETFILTER]: xt_p... |
37 38 39 40 |
ipv6_hdr(skb)->daddr.s6_addr[0] == 0xFF) type = PACKET_MULTICAST; else type = PACKET_BROADCAST; |
28658c896 [NETFILTER]: xt_p... |
41 42 |
return (type == info->pkttype) ^ info->invert; |
1da177e4c Linux-2.6.12-rc2 |
43 |
} |
92f3b2b1b netfilter: xtable... |
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 [NETFILTER] x_tab... |
51 |
}; |
d3c5ee6d5 [NETFILTER]: x_ta... |
52 |
static int __init pkttype_mt_init(void) |
1da177e4c Linux-2.6.12-rc2 |
53 |
{ |
92f3b2b1b netfilter: xtable... |
54 |
return xt_register_match(&pkttype_mt_reg); |
1da177e4c Linux-2.6.12-rc2 |
55 |
} |
d3c5ee6d5 [NETFILTER]: x_ta... |
56 |
static void __exit pkttype_mt_exit(void) |
1da177e4c Linux-2.6.12-rc2 |
57 |
{ |
92f3b2b1b netfilter: xtable... |
58 |
xt_unregister_match(&pkttype_mt_reg); |
1da177e4c Linux-2.6.12-rc2 |
59 |
} |
d3c5ee6d5 [NETFILTER]: x_ta... |
60 61 |
module_init(pkttype_mt_init); module_exit(pkttype_mt_exit); |