5 * Manohar Castelino <manohar.r.castelino@intel.com>
6 * Kuo-Lang Tseng <kuo-lang.tseng@intel.com>
7 * Jan Engelhardt <jengelh@medozas.de>
10 * This is just a modification of the IPv4 code written by
11 * Bart De Schuymer <bdschuym@pandora.be>
12 * with the changes required to support IPv6
16 #include <linux/ipv6.h>
19 #include <linux/module.h>
20 #include <net/dsfield.h>
21 #include <linux/netfilter/x_tables.h>
22 #include <linux/netfilter_bridge/ebtables.h>
23 #include <linux/netfilter_bridge/ebt_ip6.h>
31 ebt_ip6_mt(const struct sk_buff
*skb
, struct xt_action_param
*par
)
33 const struct ebt_ip6_info
*info
= par
->matchinfo
;
34 const struct ipv6hdr
*ih6
;
36 const struct tcpudphdr
*pptr
;
37 struct tcpudphdr _ports
;
39 ih6
= skb_header_pointer(skb
, 0, sizeof(_ip6h
), &_ip6h
);
42 if (info
->bitmask
& EBT_IP6_TCLASS
&&
43 FWINV(info
->tclass
!= ipv6_get_dsfield(ih6
), EBT_IP6_TCLASS
))
45 if (FWINV(ipv6_masked_addr_cmp(&ih6
->saddr
, &info
->smsk
,
46 &info
->saddr
), EBT_IP6_SOURCE
) ||
47 FWINV(ipv6_masked_addr_cmp(&ih6
->daddr
, &info
->dmsk
,
48 &info
->daddr
), EBT_IP6_DEST
))
50 if (info
->bitmask
& EBT_IP6_PROTO
) {
51 uint8_t nexthdr
= ih6
->nexthdr
;
54 offset_ph
= ipv6_skip_exthdr(skb
, sizeof(_ip6h
), &nexthdr
);
57 if (FWINV(info
->protocol
!= nexthdr
, EBT_IP6_PROTO
))
59 if (!(info
->bitmask
& EBT_IP6_DPORT
) &&
60 !(info
->bitmask
& EBT_IP6_SPORT
))
62 pptr
= skb_header_pointer(skb
, offset_ph
, sizeof(_ports
),
66 if (info
->bitmask
& EBT_IP6_DPORT
) {
67 u32 dst
= ntohs(pptr
->dst
);
68 if (FWINV(dst
< info
->dport
[0] ||
69 dst
> info
->dport
[1], EBT_IP6_DPORT
))
72 if (info
->bitmask
& EBT_IP6_SPORT
) {
73 u32 src
= ntohs(pptr
->src
);
74 if (FWINV(src
< info
->sport
[0] ||
75 src
> info
->sport
[1], EBT_IP6_SPORT
))
83 static int ebt_ip6_mt_check(const struct xt_mtchk_param
*par
)
85 const struct ebt_entry
*e
= par
->entryinfo
;
86 struct ebt_ip6_info
*info
= par
->matchinfo
;
88 if (e
->ethproto
!= htons(ETH_P_IPV6
) || e
->invflags
& EBT_IPROTO
)
90 if (info
->bitmask
& ~EBT_IP6_MASK
|| info
->invflags
& ~EBT_IP6_MASK
)
92 if (info
->bitmask
& (EBT_IP6_DPORT
| EBT_IP6_SPORT
)) {
93 if (info
->invflags
& EBT_IP6_PROTO
)
95 if (info
->protocol
!= IPPROTO_TCP
&&
96 info
->protocol
!= IPPROTO_UDP
&&
97 info
->protocol
!= IPPROTO_UDPLITE
&&
98 info
->protocol
!= IPPROTO_SCTP
&&
99 info
->protocol
!= IPPROTO_DCCP
)
102 if (info
->bitmask
& EBT_IP6_DPORT
&& info
->dport
[0] > info
->dport
[1])
104 if (info
->bitmask
& EBT_IP6_SPORT
&& info
->sport
[0] > info
->sport
[1])
109 static struct xt_match ebt_ip6_mt_reg __read_mostly
= {
112 .family
= NFPROTO_BRIDGE
,
114 .checkentry
= ebt_ip6_mt_check
,
115 .matchsize
= sizeof(struct ebt_ip6_info
),
119 static int __init
ebt_ip6_init(void)
121 return xt_register_match(&ebt_ip6_mt_reg
);
124 static void __exit
ebt_ip6_fini(void)
126 xt_unregister_match(&ebt_ip6_mt_reg
);
129 module_init(ebt_ip6_init
);
130 module_exit(ebt_ip6_fini
);
131 MODULE_DESCRIPTION("Ebtables: IPv6 protocol packet match");
132 MODULE_AUTHOR("Kuo-Lang Tseng <kuo-lang.tseng@intel.com>");
133 MODULE_LICENSE("GPL");