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" 7 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, }, 14 }; 15 16 static const struct genl_ops ila_nl_ops[] = { 17 { 18 .cmd = ILA_CMD_ADD, 19 .doit = ila_xlat_nl_cmd_add_mapping, 20 .flags = GENL_ADMIN_PERM, 21 }, 22 { 23 .cmd = ILA_CMD_DEL, 24 .doit = ila_xlat_nl_cmd_del_mapping, 25 .flags = GENL_ADMIN_PERM, 26 }, 27 { 28 .cmd = ILA_CMD_FLUSH, 29 .doit = ila_xlat_nl_cmd_flush, 30 .flags = GENL_ADMIN_PERM, 31 }, 32 { 33 .cmd = ILA_CMD_GET, 34 .doit = ila_xlat_nl_cmd_get_mapping, 35 .start = ila_xlat_nl_dump_start, 36 .dumpit = ila_xlat_nl_dump, 37 .done = ila_xlat_nl_dump_done, 38 }, 39 }; 40 41 unsigned int ila_net_id; 42 43 struct genl_family ila_nl_family __ro_after_init = { 44 .hdrsize = 0, 45 .name = ILA_GENL_NAME, 46 .version = ILA_GENL_VERSION, 47 .maxattr = ILA_ATTR_MAX, 48 .policy = ila_nl_policy, 49 .netnsok = true, 50 .parallel_ops = true, 51 .module = THIS_MODULE, 52 .ops = ila_nl_ops, 53 .n_ops = ARRAY_SIZE(ila_nl_ops), 54 }; 55 56 static __net_init int ila_init_net(struct net *net) 57 { 58 int err; 59 60 err = ila_xlat_init_net(net); 61 if (err) 62 goto ila_xlat_init_fail; 63 64 return 0; 65 66 ila_xlat_init_fail: 67 return err; 68 } 69 70 static __net_exit void ila_exit_net(struct net *net) 71 { 72 ila_xlat_exit_net(net); 73 } 74 75 static struct pernet_operations ila_net_ops = { 76 .init = ila_init_net, 77 .exit = ila_exit_net, 78 .id = &ila_net_id, 79 .size = sizeof(struct ila_net), 80 }; 81 82 static int __init ila_init(void) 83 { 84 int ret; 85 86 ret = register_pernet_device(&ila_net_ops); 87 if (ret) 88 goto register_device_fail; 89 90 ret = genl_register_family(&ila_nl_family); 91 if (ret) 92 goto register_family_fail; 93 94 ret = ila_lwt_init(); 95 if (ret) 96 goto fail_lwt; 97 98 return 0; 99 100 fail_lwt: 101 genl_unregister_family(&ila_nl_family); 102 register_family_fail: 103 unregister_pernet_device(&ila_net_ops); 104 register_device_fail: 105 return ret; 106 } 107 108 static void __exit ila_fini(void) 109 { 110 ila_lwt_fini(); 111 genl_unregister_family(&ila_nl_family); 112 unregister_pernet_device(&ila_net_ops); 113 } 114 115 module_init(ila_init); 116 module_exit(ila_fini); 117 MODULE_AUTHOR("Tom Herbert <tom@herbertland.com>"); 118 MODULE_LICENSE("GPL"); 119