summaryrefslogtreecommitdiffstats
path: root/libip6t_DNPTV6.c
blob: c12ca4d8b84e1268feb964da4a7faf6617fb51e5 (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
63
64
65
66
/*
 * 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"


static void DNPTV6_help(void)
{
	printf(
"DNPTV6 target options\n"
"  --to-destination ipv6addr/prefixlength (Prefix to map IPv6 destination address to)\n");
	NPTV6_help_note();
}

static int DNPTV6_parse(int c, char **argv, int invert, unsigned int *flags, const void *entry, struct xt_entry_target **target)
{
	struct ip6t_nptv6_info* info = (struct ip6t_nptv6_info*)(*target)->data;

	switch(c) {
	case 0:
		if (!optarg) {
			xtables_error(PARAMETER_PROBLEM, "--to-destination: No prefix given");
		}
		if (invert) {
			xtables_error(PARAMETER_PROBLEM, "Unexpected `!' after --to-destination");
		}

		NPTV6_parse_to(optarg, info);
		return 1;
	}

	return 0;
}

static void DNPTV6_save(const void *ip, const struct xt_entry_target *target)
{
	const struct ip6t_nptv6_info* info = (struct ip6t_nptv6_info*)target->data;
	printf(" --to-destination %s/%d ", xtables_ip6addr_to_numeric(&info->nptv6_prefix), info->nptv6_prefix_len);
}

static const struct option DNPTV6_opts[] = {
	{.name = "to-destination", .has_arg = required_argument, .flag = NULL, .val = 0},
	{.name = NULL},
};

static struct xtables_target DNPTV6_tg6_reg = {
	.name 		= "DNPTV6",
	.version	= XTABLES_VERSION,
	.family		= NFPROTO_IPV6,
	.size		= XT_ALIGN(sizeof(struct ip6t_nptv6_info)),
	.userspacesize	= XT_ALIGN(sizeof(struct ip6t_nptv6_info)),
	.help		= DNPTV6_help,
	.parse		= DNPTV6_parse,
	.print          = NPTV6_print,
	.save		= DNPTV6_save,
	.extra_opts	= DNPTV6_opts,
};

void _init(void)
{
	xtables_register_target(&DNPTV6_tg6_reg);
}