11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
12 #include <linux/kernel.h>
13 #include <linux/module.h>
15 #include <linux/netdevice.h>
19 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
26 #include <linux/netfilter/x_tables.h>
34 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
38 const struct nf_afinfo *afinfo;
44 memset(&flow, 0,
sizeof(flow));
53 route_err = afinfo->route(net, (
struct dst_entry **)&rt,
54 flowi6_to_flowi(&flow), !!dev);
78 static bool match_type6(
struct net *net,
const struct net_device *dev,
81 int addr_type = ipv6_addr_type(addr);
93 return !!(mask & match_lookup_rt6(net, dev, addr));
98 addrtype_mt6(
struct net *net,
const struct net_device *dev,
101 const struct ipv6hdr *iph = ipv6_hdr(skb);
105 ret &= match_type6(net, dev, &iph->
saddr, info->
source) ^
107 if (ret && info->
dest)
108 ret &= match_type6(net, dev, &iph->
daddr, info->
dest) ^
114 static inline bool match_type(
struct net *net,
const struct net_device *dev,
123 struct net *net = dev_net(par->
in ? par->
in : par->
out);
125 const struct iphdr *iph = ip_hdr(skb);
141 struct net *net = dev_net(par->
in ? par->
in : par->
out);
143 const struct iphdr *iph;
152 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
154 return addrtype_mt6(net, dev, skb, info);
158 ret &= match_type(net, dev, iph->
saddr, info->
source) ^
160 if (ret && info->
dest)
161 ret &= match_type(net, dev, iph->
daddr, info->
dest) ^
166 static int addrtype_mt_checkentry_v1(
const struct xt_mtchk_param *par)
172 pr_info(
"both incoming and outgoing "
173 "interface limitation cannot be selected\n");
180 pr_info(
"output interface limitation "
181 "not valid in PREROUTING and INPUT\n");
188 pr_info(
"input interface limitation "
189 "not valid in POSTROUTING and OUTPUT\n");
193 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
196 pr_err(
"ipv6 BLACKHOLE matching not supported\n");
200 pr_err(
"ipv6 PROHIBT (THROW, NAT ..) matching not supported\n");
204 pr_err(
"ipv6 does not support BROADCAST matching\n");
216 .match = addrtype_mt_v0,
224 .match = addrtype_mt_v1,
225 .checkentry = addrtype_mt_checkentry_v1,
231 static int __init addrtype_mt_init(
void)
237 static void __exit addrtype_mt_exit(
void)