1 // SPDX-License-Identifier: GPL-2.0
2 #include <net/genetlink.h>
3 #include <net/netns/generic.h>
4 #include <uapi/linux/genetlink.h>
7 static const struct nla_policy ila_nl_policy
[ILA_ATTR_MAX
+ 1] = {
8 [ILA_ATTR_LOCATOR
] = { .type
= NLA_U64
, },
9 [ILA_ATTR_LOCATOR_MATCH
] = { .type
= NLA_U64
, },
10 [ILA_ATTR_IFINDEX
] = { .type
= NLA_U32
, },
11 [ILA_ATTR_CSUM_MODE
] = { .type
= NLA_U8
, },
12 [ILA_ATTR_IDENT_TYPE
] = { .type
= NLA_U8
, },
15 static const struct genl_ops ila_nl_ops
[] = {
18 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
19 .doit
= ila_xlat_nl_cmd_add_mapping
,
20 .flags
= GENL_ADMIN_PERM
,
24 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
25 .doit
= ila_xlat_nl_cmd_del_mapping
,
26 .flags
= GENL_ADMIN_PERM
,
30 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
31 .doit
= ila_xlat_nl_cmd_flush
,
32 .flags
= GENL_ADMIN_PERM
,
36 .validate
= GENL_DONT_VALIDATE_STRICT
| GENL_DONT_VALIDATE_DUMP
,
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
,
44 unsigned int ila_net_id
;
46 struct genl_family ila_nl_family __ro_after_init
= {
48 .name
= ILA_GENL_NAME
,
49 .version
= ILA_GENL_VERSION
,
50 .maxattr
= ILA_ATTR_MAX
,
51 .policy
= ila_nl_policy
,
54 .module
= THIS_MODULE
,
56 .n_ops
= ARRAY_SIZE(ila_nl_ops
),
57 .resv_start_op
= ILA_CMD_FLUSH
+ 1,
60 static __net_init
int ila_init_net(struct net
*net
)
64 err
= ila_xlat_init_net(net
);
66 goto ila_xlat_init_fail
;
74 static __net_exit
void ila_pre_exit_net(struct net
*net
)
76 ila_xlat_pre_exit_net(net
);
79 static __net_exit
void ila_exit_net(struct net
*net
)
81 ila_xlat_exit_net(net
);
84 static struct pernet_operations ila_net_ops
= {
86 .pre_exit
= ila_pre_exit_net
,
89 .size
= sizeof(struct ila_net
),
92 static int __init
ila_init(void)
96 ret
= register_pernet_device(&ila_net_ops
);
98 goto register_device_fail
;
100 ret
= genl_register_family(&ila_nl_family
);
102 goto register_family_fail
;
104 ret
= ila_lwt_init();
111 genl_unregister_family(&ila_nl_family
);
112 register_family_fail
:
113 unregister_pernet_device(&ila_net_ops
);
114 register_device_fail
:
118 static void __exit
ila_fini(void)
121 genl_unregister_family(&ila_nl_family
);
122 unregister_pernet_device(&ila_net_ops
);
125 module_init(ila_init
);
126 module_exit(ila_fini
);
127 MODULE_AUTHOR("Tom Herbert <tom@herbertland.com>");
128 MODULE_LICENSE("GPL");
129 MODULE_DESCRIPTION("IPv6: Identifier Locator Addressing (ILA)");