summaryrefslogtreecommitdiffstats
path: root/libip6t_NPTV6.c
blob: 4c7aae75d2c75cf353ae08a83ff975a46f1b3c3e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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);
}