ila_main.c 2.4 KB

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