summaryrefslogtreecommitdiffstats
path: root/ip6t_MAP66.c
diff options
context:
space:
mode:
Diffstat (limited to 'ip6t_MAP66.c')
-rw-r--r--ip6t_MAP66.c53
1 files changed, 24 insertions, 29 deletions
diff --git a/ip6t_MAP66.c b/ip6t_MAP66.c
index afcc57c..6060871 100644
--- a/ip6t_MAP66.c
+++ b/ip6t_MAP66.c
@@ -61,7 +61,24 @@ static void map16(
# define __read_mostly
# define xt_register_target ip6t_register_target
# define xt_unregister_target ip6t_unregister_target
-# define pr_devel(fmt, ...) ({ if (0); })
+# ifdef DEBUG
+# define pr_devel(fmt, ...) printk(fmt, ##__VA_ARGS__)
+# else
+# define pr_devel(fmt, ...) ({ if (0); })
+# endif
+#endif
+
+#ifndef NIP6_FMT
+#define NIP6_FMT "%04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x"
+#define NIP6(addr) \
+ ntohs((addr).s6_addr16[0]), \
+ ntohs((addr).s6_addr16[1]), \
+ ntohs((addr).s6_addr16[2]), \
+ ntohs((addr).s6_addr16[3]), \
+ ntohs((addr).s6_addr16[4]), \
+ ntohs((addr).s6_addr16[5]), \
+ ntohs((addr).s6_addr16[6]), \
+ ntohs((addr).s6_addr16[7])
#endif
#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,24)
@@ -87,20 +104,12 @@ static bool is_my_ipv6_addr(
const struct net_device *dev,
const struct in6_addr *addr)
{
-#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
pr_devel("MAP66: is_my_ipv6_addr(%s, " NIP6_FMT ")\n", NULL != dev ? dev->name : "", NIP6(*addr));
-#else
- pr_devel("MAP66: is_my_ipv6_addr(%s, %pI6)\n", NULL != dev ? dev->name : "", addr);
-#endif
if (NULL != dev) {
const struct inet6_ifaddr *ifa;
const struct inet6_dev *idev = rcu_dereference(dev->ip6_ptr);
for (ifa = idev->addr_list; NULL != ifa; ifa = ifa->if_next) {
-#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
pr_devel("MAP66: cmp " NIP6_FMT "\n", NIP6(ifa->addr));
-#else
- pr_devel("MAP66: cmp %pI6\n", &ifa->addr);
-#endif
if (ipv6_addr_equal(&ifa->addr, addr)) return true;
}
}
@@ -114,17 +123,10 @@ static unsigned int MAP66_tg6(
struct ipv6hdr *hdr = ipv6_hdr(skb);
const struct ip6t_MAP66_info *info = par->targinfo;
-#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
pr_devel("MAP66: enter in=%s, out=%s, saddr=" NIP6_FMT ", daddr=" NIP6_FMT "\n",
NULL != par->in ? par->in->name : "",
NULL != par->out ? par->out->name : "",
NIP6(hdr->saddr), NIP6(hdr->daddr));
-#else
- pr_devel("MAP66: enter in=%s, out=%s, saddr=%pI6, daddr=%pI6\n",
- NULL != par->in ? par->in->name : "",
- NULL != par->out ? par->out->name : "",
- &hdr->saddr, &hdr->daddr);
-#endif
#if 0
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
@@ -147,9 +149,9 @@ static unsigned int MAP66_tg6(
#endif
if (0 != (IP6T_MAP66_OPT_DST_TO & info->mapflags)) {
- pr_devel("MAP66 DST, nocheck=%d, ip_summed=%d\n", 0 != (IP6T_MAP66_OPT_NOCHECK & info->mapflags), skb->ip_summed);
- if (0 != (IP6T_MAP66_OPT_NOCHECK & info->mapflags) ||
- !is_my_ipv6_addr(par->in, &hdr->daddr))
+ pr_devel("MAP66: DST_TO, ip_summed=%d\n", skb->ip_summed);
+ if (0 != (IP6T_MAP66_OPT_NOCHECK & info->mapflags) || !is_my_ipv6_addr(
+ NF_INET_PRE_ROUTING == par->hooknum ? par->in : par->out, &hdr->daddr))
{
if (0 != (IP6T_MAP66_OPT_UNBALANCED & info->mapflags)) {
memcpy(&hdr->daddr, &info->pfix_dst_to, sizeof(u_int16_t) * info->pfix_dst_len);
@@ -161,31 +163,24 @@ static unsigned int MAP66_tg6(
}
if (0 != (IP6T_MAP66_OPT_SRC_TO & info->mapflags)) {
- pr_devel("MAP66 SRC, nocheck=%d, ip_summed=%d\n", 0 != (IP6T_MAP66_OPT_NOCHECK & info->mapflags), skb->ip_summed);
+ pr_devel("MAP66: SRC_TO, ip_summed=%d\n", skb->ip_summed);
if (0 != (IP6T_MAP66_OPT_UNBALANCED & info->mapflags)) {
memcpy(&hdr->saddr, &info->pfix_src_to, sizeof(u_int16_t) * info->pfix_src_len);
}
else {
map16(&hdr->saddr, &info->pfix_src_to, info->pfix_src_len, info->pfix_src_csum);
}
- if (0 == (IP6T_MAP66_OPT_NOCHECK & info->mapflags) &&
- is_my_ipv6_addr(par->out, &hdr->saddr))
+ if (0 == (IP6T_MAP66_OPT_NOCHECK & info->mapflags) && is_my_ipv6_addr(
+ NF_INET_PRE_ROUTING == par->hooknum ? par->in : par->out, &hdr->saddr))
{
return NF_DROP;
}
}
-#if LINUX_VERSION_CODE <= KERNEL_VERSION(2,6,28)
pr_devel("MAP66: exit in=%s, out=%s, saddr=" NIP6_FMT ", daddr=" NIP6_FMT "\n",
NULL != par->in ? par->in->name : "",
NULL != par->out ? par->out->name : "",
NIP6(hdr->saddr), NIP6(hdr->daddr));
-#else
- pr_devel("MAP66: exit in=%s, out=%s, saddr=%pI6, daddr=%pI6\n",
- NULL != par->in ? par->in->name : "",
- NULL != par->out ? par->out->name : "",
- &hdr->saddr, &hdr->daddr);
-#endif
return IP6T_CONTINUE;
}