summaryrefslogtreecommitdiffstats
path: root/libip6t_NPTV6.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2011-11-10 07:53:52 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2011-11-10 07:53:52 +0100
commita95082117ad4813141f5733e5c3dda8efc5dec16 (patch)
tree61edab08d7390e0179fc6c2900234c040168500a /libip6t_NPTV6.c
parentc25768e4311eaf9e9d9166e42fe74e9c597c466d (diff)
downloadNPTv6-a95082117ad4813141f5733e5c3dda8efc5dec16.tar
NPTv6-a95082117ad4813141f5733e5c3dda8efc5dec16.zip
Make this work again.
Diffstat (limited to 'libip6t_NPTV6.c')
-rw-r--r--libip6t_NPTV6.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/libip6t_NPTV6.c b/libip6t_NPTV6.c
new file mode 100644
index 0000000..4c7aae7
--- /dev/null
+++ b/libip6t_NPTV6.c
@@ -0,0 +1,62 @@
+/*
+ * NATv6: IPv6-to-IPv6 Network Prefix Translation as
+ * proposed in RFC 6296.
+ * Based on MAP66 (c) 2010 sven-ola()gmx.de
+ * (c) 2011 mschiffer()universe-factory.net "I'm the one to blame for any problems with this version ;P"
+ */
+
+#include "libip6t_NPTV6.h"
+
+
+void NPTV6_help_note(void)
+{
+ printf(
+"\n"
+"Note: you need two ip6tables rules to map an internal network\n"
+"using ULAs to/from external network with official IPv6 address.\n"
+"\n"
+"Example:\n"
+"\n"
+"ip6tables -t mangle -I PREROUTING -i eth0 -d 2001:0DB8:0001::/48 -j DNPTV6 --to-destination FD01:0203:0405::/48\n"
+"ip6tables -t mangle -I POSTROUTING -o eth0 -s FD01:0203:0405::/48 -j SNPTV6 --to-source 2001:0DB8:0001::/48\n");
+}
+
+static void parse_to(const char *orig_arg, struct ip6t_nptv6_info *info)
+{
+ char *arg, *slash;
+
+ arg = strdup(orig_arg);
+ if (arg == NULL)
+ xtables_error(RESOURCE_PROBLEM, "strdup");
+
+ slash = strchr(arg, '/');
+ if (!slash)
+ xtables_error(PARAMETER_PROBLEM, "No prefix length given\n");
+
+ info->nptv6_prefix_len = atoi(slash+1);
+ if (info->nptv6_prefix_len <= 0 || info->nptv6_prefix_len > 64)
+ xtables_error(PARAMETER_PROBLEM, "Prefix length `%s' not valid\n", slash+1);
+
+ *slash = 0;
+ info->nptv6_prefix = *xtables_numeric_to_ip6addr(arg);
+
+ free(arg);
+}
+
+void NPTV6_parse(struct xt_option_call *cb)
+{
+ struct ip6t_nptv6_info* info = (struct ip6t_nptv6_info*)cb->data;
+
+ xtables_option_parse(cb);
+ switch(cb->entry->id) {
+ case 0:
+ parse_to(cb->arg, info);
+ break;
+ }
+}
+
+void NPTV6_print(const void *ip, const struct xt_entry_target *target, int numeric)
+{
+ const struct ip6t_nptv6_info* info = (struct ip6t_nptv6_info*)target->data;
+ printf(" to: %s/%d", xtables_ip6addr_to_numeric(&info->nptv6_prefix), info->nptv6_prefix_len);
+}