Linux 4.19.133
[linux/fpc-iii.git] / net / ipv6 / ila / ila_main.c
blob18fac76b952052367309ee2ff4b226d7d10415d7
1 // SPDX-License-Identifier: GPL-2.0
2 #include <net/genetlink.h>
3 #include <net/ila.h>
4 #include <net/netns/generic.h>
5 #include <uapi/linux/genetlink.h>
6 #include "ila.h"
8 static const struct nla_policy ila_nl_policy[ILA_ATTR_MAX + 1] = {
9 [ILA_ATTR_LOCATOR] = { .type = NLA_U64, },
10 [ILA_ATTR_LOCATOR_MATCH] = { .type = NLA_U64, },
11 [ILA_ATTR_IFINDEX] = { .type = NLA_U32, },
12 [ILA_ATTR_CSUM_MODE] = { .type = NLA_U8, },
13 [ILA_ATTR_IDENT_TYPE] = { .type = NLA_U8, },
16 static const struct genl_ops ila_nl_ops[] = {
18 .cmd = ILA_CMD_ADD,
19 .doit = ila_xlat_nl_cmd_add_mapping,
20 .policy = ila_nl_policy,
21 .flags = GENL_ADMIN_PERM,
24 .cmd = ILA_CMD_DEL,
25 .doit = ila_xlat_nl_cmd_del_mapping,
26 .policy = ila_nl_policy,
27 .flags = GENL_ADMIN_PERM,
30 .cmd = ILA_CMD_FLUSH,
31 .doit = ila_xlat_nl_cmd_flush,
32 .policy = ila_nl_policy,
33 .flags = GENL_ADMIN_PERM,
36 .cmd = ILA_CMD_GET,
37 .doit = ila_xlat_nl_cmd_get_mapping,
38 .start = ila_xlat_nl_dump_start,
39 .dumpit = ila_xlat_nl_dump,
40 .done = ila_xlat_nl_dump_done,
41 .policy = ila_nl_policy,
45 unsigned int ila_net_id;
47 struct genl_family ila_nl_family __ro_after_init = {
48 .hdrsize = 0,
49 .name = ILA_GENL_NAME,
50 .version = ILA_GENL_VERSION,
51 .maxattr = ILA_ATTR_MAX,
52 .netnsok = true,
53 .parallel_ops = true,
54 .module = THIS_MODULE,
55 .ops = ila_nl_ops,
56 .n_ops = ARRAY_SIZE(ila_nl_ops),
59 static __net_init int ila_init_net(struct net *net)
61 int err;
63 err = ila_xlat_init_net(net);
64 if (err)
65 goto ila_xlat_init_fail;
67 return 0;
69 ila_xlat_init_fail:
70 return err;
73 static __net_exit void ila_exit_net(struct net *net)
75 ila_xlat_exit_net(net);
78 static struct pernet_operations ila_net_ops = {
79 .init = ila_init_net,
80 .exit = ila_exit_net,
81 .id = &ila_net_id,
82 .size = sizeof(struct ila_net),
85 static int __init ila_init(void)
87 int ret;
89 ret = register_pernet_device(&ila_net_ops);
90 if (ret)
91 goto register_device_fail;
93 ret = genl_register_family(&ila_nl_family);
94 if (ret)
95 goto register_family_fail;
97 ret = ila_lwt_init();
98 if (ret)
99 goto fail_lwt;
101 return 0;
103 fail_lwt:
104 genl_unregister_family(&ila_nl_family);
105 register_family_fail:
106 unregister_pernet_device(&ila_net_ops);
107 register_device_fail:
108 return ret;
111 static void __exit ila_fini(void)
113 ila_lwt_fini();
114 genl_unregister_family(&ila_nl_family);
115 unregister_pernet_device(&ila_net_ops);
118 module_init(ila_init);
119 module_exit(ila_fini);
120 MODULE_AUTHOR("Tom Herbert <tom@herbertland.com>");
121 MODULE_LICENSE("GPL");