1 // SPDX-License-Identifier: GPL-2.0
2 #include <net/genetlink.h>
4 #include <net/netns/generic.h>
5 #include <uapi/linux/genetlink.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
[] = {
19 .doit
= ila_xlat_nl_cmd_add_mapping
,
20 .policy
= ila_nl_policy
,
21 .flags
= GENL_ADMIN_PERM
,
25 .doit
= ila_xlat_nl_cmd_del_mapping
,
26 .policy
= ila_nl_policy
,
27 .flags
= GENL_ADMIN_PERM
,
31 .doit
= ila_xlat_nl_cmd_flush
,
32 .policy
= ila_nl_policy
,
33 .flags
= GENL_ADMIN_PERM
,
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
= {
49 .name
= ILA_GENL_NAME
,
50 .version
= ILA_GENL_VERSION
,
51 .maxattr
= ILA_ATTR_MAX
,
54 .module
= THIS_MODULE
,
56 .n_ops
= ARRAY_SIZE(ila_nl_ops
),
59 static __net_init
int ila_init_net(struct net
*net
)
63 err
= ila_xlat_init_net(net
);
65 goto ila_xlat_init_fail
;
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
= {
82 .size
= sizeof(struct ila_net
),
85 static int __init
ila_init(void)
89 ret
= register_pernet_device(&ila_net_ops
);
91 goto register_device_fail
;
93 ret
= genl_register_family(&ila_nl_family
);
95 goto register_family_fail
;
104 genl_unregister_family(&ila_nl_family
);
105 register_family_fail
:
106 unregister_pernet_device(&ila_net_ops
);
107 register_device_fail
:
111 static void __exit
ila_fini(void)
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");