2018-06-28 05:39:01 +08:00
|
|
|
// 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,
|
2019-04-26 20:07:31 +08:00
|
|
|
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
|
2018-06-28 05:39:01 +08:00
|
|
|
.doit = ila_xlat_nl_cmd_add_mapping,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.cmd = ILA_CMD_DEL,
|
2019-04-26 20:07:31 +08:00
|
|
|
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
|
2018-06-28 05:39:01 +08:00
|
|
|
.doit = ila_xlat_nl_cmd_del_mapping,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
},
|
2018-06-28 05:39:02 +08:00
|
|
|
{
|
|
|
|
.cmd = ILA_CMD_FLUSH,
|
2019-04-26 20:07:31 +08:00
|
|
|
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
|
2018-06-28 05:39:02 +08:00
|
|
|
.doit = ila_xlat_nl_cmd_flush,
|
|
|
|
.flags = GENL_ADMIN_PERM,
|
|
|
|
},
|
2018-06-28 05:39:01 +08:00
|
|
|
{
|
|
|
|
.cmd = ILA_CMD_GET,
|
2019-04-26 20:07:31 +08:00
|
|
|
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
|
2018-06-28 05:39:01 +08:00
|
|
|
.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,
|
genetlink: make policy common to family
Since maxattr is common, the policy can't really differ sanely,
so make it common as well.
The only user that did in fact manage to make a non-common policy
is taskstats, which has to be really careful about it (since it's
still using a common maxattr!). This is no longer supported, but
we can fake it using pre_doit.
This reduces the size of e.g. nl80211.o (which has lots of commands):
text data bss dec hex filename
398745 14323 2240 415308 6564c net/wireless/nl80211.o (before)
397913 14331 2240 414484 65314 net/wireless/nl80211.o (after)
--------------------------------
-832 +8 0 -824
Which is obviously just 8 bytes for each command, and an added 8
bytes for the new policy pointer. I'm not sure why the ops list is
counted as .text though.
Most of the code transformations were done using the following spatch:
@ops@
identifier OPS;
expression POLICY;
@@
struct genl_ops OPS[] = {
...,
{
- .policy = POLICY,
},
...
};
@@
identifier ops.OPS;
expression ops.POLICY;
identifier fam;
expression M;
@@
struct genl_family fam = {
.ops = OPS,
.maxattr = M,
+ .policy = POLICY,
...
};
This also gets rid of devlink_nl_cmd_region_read_dumpit() accessing
the cb->data as ops, which we want to change in a later genl patch.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-03-22 05:51:02 +08:00
|
|
|
.policy = ila_nl_policy,
|
2018-06-28 05:39:01 +08:00
|
|
|
.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");
|