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>
37 ebt_ip6_mt(const struct sk_buff
*skb
, struct xt_action_param
*par
)
39 const struct ebt_ip6_info
*info
= par
->matchinfo
;
40 const struct ipv6hdr
*ih6
;
42 const union pkthdr
*pptr
;
45 ih6
= skb_header_pointer(skb
, 0, sizeof(_ip6h
), &_ip6h
);
48 if (info
->bitmask
& EBT_IP6_TCLASS
&&
49 FWINV(info
->tclass
!= ipv6_get_dsfield(ih6
), EBT_IP6_TCLASS
))
51 if (FWINV(ipv6_masked_addr_cmp(&ih6
->saddr
, &info
->smsk
,
52 &info
->saddr
), EBT_IP6_SOURCE
) ||
53 FWINV(ipv6_masked_addr_cmp(&ih6
->daddr
, &info
->dmsk
,
54 &info
->daddr
), EBT_IP6_DEST
))
56 if (info
->bitmask
& EBT_IP6_PROTO
) {
57 uint8_t nexthdr
= ih6
->nexthdr
;
60 offset_ph
= ipv6_skip_exthdr(skb
, sizeof(_ip6h
), &nexthdr
);
63 if (FWINV(info
->protocol
!= nexthdr
, EBT_IP6_PROTO
))
65 if (!(info
->bitmask
& ( EBT_IP6_DPORT
|
66 EBT_IP6_SPORT
| EBT_IP6_ICMP6
)))
69 /* min icmpv6 headersize is 4, so sizeof(_pkthdr) is ok. */
70 pptr
= skb_header_pointer(skb
, offset_ph
, sizeof(_pkthdr
),
74 if (info
->bitmask
& EBT_IP6_DPORT
) {
75 u16 dst
= ntohs(pptr
->tcpudphdr
.dst
);
76 if (FWINV(dst
< info
->dport
[0] ||
77 dst
> info
->dport
[1], EBT_IP6_DPORT
))
80 if (info
->bitmask
& EBT_IP6_SPORT
) {
81 u16 src
= ntohs(pptr
->tcpudphdr
.src
);
82 if (FWINV(src
< info
->sport
[0] ||
83 src
> info
->sport
[1], EBT_IP6_SPORT
))
86 if ((info
->bitmask
& EBT_IP6_ICMP6
) &&
87 FWINV(pptr
->icmphdr
.type
< info
->icmpv6_type
[0] ||
88 pptr
->icmphdr
.type
> info
->icmpv6_type
[1] ||
89 pptr
->icmphdr
.code
< info
->icmpv6_code
[0] ||
90 pptr
->icmphdr
.code
> info
->icmpv6_code
[1],
97 static int ebt_ip6_mt_check(const struct xt_mtchk_param
*par
)
99 const struct ebt_entry
*e
= par
->entryinfo
;
100 struct ebt_ip6_info
*info
= par
->matchinfo
;
102 if (e
->ethproto
!= htons(ETH_P_IPV6
) || e
->invflags
& EBT_IPROTO
)
104 if (info
->bitmask
& ~EBT_IP6_MASK
|| info
->invflags
& ~EBT_IP6_MASK
)
106 if (info
->bitmask
& (EBT_IP6_DPORT
| EBT_IP6_SPORT
)) {
107 if (info
->invflags
& EBT_IP6_PROTO
)
109 if (info
->protocol
!= IPPROTO_TCP
&&
110 info
->protocol
!= IPPROTO_UDP
&&
111 info
->protocol
!= IPPROTO_UDPLITE
&&
112 info
->protocol
!= IPPROTO_SCTP
&&
113 info
->protocol
!= IPPROTO_DCCP
)
116 if (info
->bitmask
& EBT_IP6_DPORT
&& info
->dport
[0] > info
->dport
[1])
118 if (info
->bitmask
& EBT_IP6_SPORT
&& info
->sport
[0] > info
->sport
[1])
120 if (info
->bitmask
& EBT_IP6_ICMP6
) {
121 if ((info
->invflags
& EBT_IP6_PROTO
) ||
122 info
->protocol
!= IPPROTO_ICMPV6
)
124 if (info
->icmpv6_type
[0] > info
->icmpv6_type
[1] ||
125 info
->icmpv6_code
[0] > info
->icmpv6_code
[1])
131 static struct xt_match ebt_ip6_mt_reg __read_mostly
= {
134 .family
= NFPROTO_BRIDGE
,
136 .checkentry
= ebt_ip6_mt_check
,
137 .matchsize
= sizeof(struct ebt_ip6_info
),
141 static int __init
ebt_ip6_init(void)
143 return xt_register_match(&ebt_ip6_mt_reg
);
146 static void __exit
ebt_ip6_fini(void)
148 xt_unregister_match(&ebt_ip6_mt_reg
);
151 module_init(ebt_ip6_init
);
152 module_exit(ebt_ip6_fini
);
153 MODULE_DESCRIPTION("Ebtables: IPv6 protocol packet match");
154 MODULE_AUTHOR("Kuo-Lang Tseng <kuo-lang.tseng@intel.com>");
155 MODULE_LICENSE("GPL");