aboutsummaryrefslogtreecommitdiff
path: root/net/ipv6/ila/ila_main.c
blob: 36c58aa257e88c9a918f6664e85dce7fe7e3d246 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
// SPDX-License-Identifier: GPL-2.0
#include <net/genetlink.h>
#include <net/ila.h>
#include <net/netns/generic.h>
#include <uapi/linux/genetlink.h>
#include "ila.h"

static const struct nla_policy ila_nl_policy[ILA_ATTR_MAX + 1] = {
	[ILA_ATTR_LOCATOR] = { .type = NLA_U64, },
	[ILA_ATTR_LOCATOR_MATCH] = { .type = NLA_U64, },
	[ILA_ATTR_IFINDEX] = { .type = NLA_U32, },
	[ILA_ATTR_CSUM_MODE] = { .type = NLA_U8, },
	[ILA_ATTR_IDENT_TYPE] = { .type = NLA_U8, },
};

static const struct genl_ops ila_nl_ops[] = {
	{
		.cmd = ILA_CMD_ADD,
		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
		.doit = ila_xlat_nl_cmd_add_mapping,
		.flags = GENL_ADMIN_PERM,
	},
	{
		.cmd = ILA_CMD_DEL,
		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
		.doit = ila_xlat_nl_cmd_del_mapping,
		.flags = GENL_ADMIN_PERM,
	},
	{
		.cmd = ILA_CMD_FLUSH,
		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
		.doit = ila_xlat_nl_cmd_flush,
		.flags = GENL_ADMIN_PERM,
	},
	{
		.cmd = ILA_CMD_GET,
		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
		.doit = ila_xlat_nl_cmd_get_mapping,
		.start = ila_xlat_nl_dump_start,
		.dumpit = ila_xlat_nl_dump,
		.done = ila_xlat_nl_dump_done,
	},
};

unsigned int ila_net_id;

struct genl_family ila_nl_family __ro_after_init = {
	.hdrsize	= 0,
	.name		= ILA_GENL_NAME,
	.version	= ILA_GENL_VERSION,
	.maxattr	= ILA_ATTR_MAX,
	.policy = ila_nl_policy,
	.netnsok	= true,
	.parallel_ops	= true,
	.module		= THIS_MODULE,
	.ops		= ila_nl_ops,
	.n_ops		= ARRAY_SIZE(ila_nl_ops),
};

static __net_init int ila_init_net(struct net *net)
{
	int err;

	err = ila_xlat_init_net(net);
	if (err)
		goto ila_xlat_init_fail;

	return 0;

ila_xlat_init_fail:
	return err;
}

static __net_exit void ila_exit_net(struct net *net)
{
	ila_xlat_exit_net(net);
}

static struct pernet_operations ila_net_ops = {
	.init = ila_init_net,
	.exit = ila_exit_net,
	.id   = &ila_net_id,
	.size = sizeof(struct ila_net),
};

static int __init ila_init(void)
{
	int ret;

	ret = register_pernet_device(&ila_net_ops);
	if (ret)
		goto register_device_fail;

	ret = genl_register_family(&ila_nl_family);
	if (ret)
		goto register_family_fail;

	ret = ila_lwt_init();
	if (ret)
		goto fail_lwt;

	return 0;

fail_lwt:
	genl_unregister_family(&ila_nl_family);
register_family_fail:
	unregister_pernet_device(&ila_net_ops);
register_device_fail:
	return ret;
}

static void __exit ila_fini(void)
{
	ila_lwt_fini();
	genl_unregister_family(&ila_nl_family);
	unregister_pernet_device(&ila_net_ops);
}

module_init(ila_init);
module_exit(ila_fini);
MODULE_AUTHOR("Tom Herbert <tom@herbertland.com>");
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("IPv6: Identifier Locator Addressing (ILA)");