Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) #include <net/genetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <net/ila.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <net/netns/generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <uapi/linux/genetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include "ila.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) static const struct nla_policy ila_nl_policy[ILA_ATTR_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 	[ILA_ATTR_LOCATOR] = { .type = NLA_U64, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 	[ILA_ATTR_LOCATOR_MATCH] = { .type = NLA_U64, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 	[ILA_ATTR_IFINDEX] = { .type = NLA_U32, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 	[ILA_ATTR_CSUM_MODE] = { .type = NLA_U8, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 	[ILA_ATTR_IDENT_TYPE] = { .type = NLA_U8, },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) static const struct genl_ops ila_nl_ops[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 		.cmd = ILA_CMD_ADD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 		.doit = ila_xlat_nl_cmd_add_mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 		.flags = GENL_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 		.cmd = ILA_CMD_DEL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 		.doit = ila_xlat_nl_cmd_del_mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 		.flags = GENL_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		.cmd = ILA_CMD_FLUSH,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 		.doit = ila_xlat_nl_cmd_flush,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		.flags = GENL_ADMIN_PERM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 		.cmd = ILA_CMD_GET,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 		.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 		.doit = ila_xlat_nl_cmd_get_mapping,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 		.start = ila_xlat_nl_dump_start,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 		.dumpit = ila_xlat_nl_dump,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 		.done = ila_xlat_nl_dump_done,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) unsigned int ila_net_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) struct genl_family ila_nl_family __ro_after_init = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	.hdrsize	= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	.name		= ILA_GENL_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	.version	= ILA_GENL_VERSION,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	.maxattr	= ILA_ATTR_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	.policy = ila_nl_policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	.netnsok	= true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	.parallel_ops	= true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	.module		= THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	.ops		= ila_nl_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	.n_ops		= ARRAY_SIZE(ila_nl_ops),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static __net_init int ila_init_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	err = ila_xlat_init_net(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		goto ila_xlat_init_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) ila_xlat_init_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) static __net_exit void ila_exit_net(struct net *net)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	ila_xlat_exit_net(net);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) static struct pernet_operations ila_net_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	.init = ila_init_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	.exit = ila_exit_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	.id   = &ila_net_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	.size = sizeof(struct ila_net),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static int __init ila_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	ret = register_pernet_device(&ila_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		goto register_device_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	ret = genl_register_family(&ila_nl_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		goto register_family_fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	ret = ila_lwt_init();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		goto fail_lwt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) fail_lwt:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	genl_unregister_family(&ila_nl_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) register_family_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	unregister_pernet_device(&ila_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) register_device_fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static void __exit ila_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	ila_lwt_fini();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	genl_unregister_family(&ila_nl_family);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	unregister_pernet_device(&ila_net_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) module_init(ila_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) module_exit(ila_fini);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) MODULE_AUTHOR("Tom Herbert <tom@herbertland.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) MODULE_DESCRIPTION("IPv6: Identifier Locator Addressing (ILA)");