netlink.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Netlink routines for CIFS
  4. *
  5. * Copyright (c) 2020 Samuel Cabrero <[email protected]>
  6. */
  7. #include <net/genetlink.h>
  8. #include <uapi/linux/cifs/cifs_netlink.h>
  9. #include "netlink.h"
  10. #include "cifsglob.h"
  11. #include "cifs_debug.h"
  12. #include "cifs_swn.h"
  13. static const struct nla_policy cifs_genl_policy[CIFS_GENL_ATTR_MAX + 1] = {
  14. [CIFS_GENL_ATTR_SWN_REGISTRATION_ID] = { .type = NLA_U32 },
  15. [CIFS_GENL_ATTR_SWN_NET_NAME] = { .type = NLA_STRING },
  16. [CIFS_GENL_ATTR_SWN_SHARE_NAME] = { .type = NLA_STRING },
  17. [CIFS_GENL_ATTR_SWN_IP] = { .len = sizeof(struct sockaddr_storage) },
  18. [CIFS_GENL_ATTR_SWN_NET_NAME_NOTIFY] = { .type = NLA_FLAG },
  19. [CIFS_GENL_ATTR_SWN_SHARE_NAME_NOTIFY] = { .type = NLA_FLAG },
  20. [CIFS_GENL_ATTR_SWN_IP_NOTIFY] = { .type = NLA_FLAG },
  21. [CIFS_GENL_ATTR_SWN_KRB_AUTH] = { .type = NLA_FLAG },
  22. [CIFS_GENL_ATTR_SWN_USER_NAME] = { .type = NLA_STRING },
  23. [CIFS_GENL_ATTR_SWN_PASSWORD] = { .type = NLA_STRING },
  24. [CIFS_GENL_ATTR_SWN_DOMAIN_NAME] = { .type = NLA_STRING },
  25. [CIFS_GENL_ATTR_SWN_NOTIFICATION_TYPE] = { .type = NLA_U32 },
  26. [CIFS_GENL_ATTR_SWN_RESOURCE_STATE] = { .type = NLA_U32 },
  27. [CIFS_GENL_ATTR_SWN_RESOURCE_NAME] = { .type = NLA_STRING},
  28. };
  29. static const struct genl_ops cifs_genl_ops[] = {
  30. {
  31. .cmd = CIFS_GENL_CMD_SWN_NOTIFY,
  32. .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
  33. .doit = cifs_swn_notify,
  34. },
  35. };
  36. static const struct genl_multicast_group cifs_genl_mcgrps[] = {
  37. [CIFS_GENL_MCGRP_SWN] = { .name = CIFS_GENL_MCGRP_SWN_NAME },
  38. };
  39. struct genl_family cifs_genl_family = {
  40. .name = CIFS_GENL_NAME,
  41. .version = CIFS_GENL_VERSION,
  42. .hdrsize = 0,
  43. .maxattr = CIFS_GENL_ATTR_MAX,
  44. .module = THIS_MODULE,
  45. .policy = cifs_genl_policy,
  46. .ops = cifs_genl_ops,
  47. .n_ops = ARRAY_SIZE(cifs_genl_ops),
  48. .resv_start_op = CIFS_GENL_CMD_SWN_NOTIFY + 1,
  49. .mcgrps = cifs_genl_mcgrps,
  50. .n_mcgrps = ARRAY_SIZE(cifs_genl_mcgrps),
  51. };
  52. /**
  53. * cifs_genl_init - Register generic netlink family
  54. *
  55. * Return zero if initialized successfully, otherwise non-zero.
  56. */
  57. int cifs_genl_init(void)
  58. {
  59. int ret;
  60. ret = genl_register_family(&cifs_genl_family);
  61. if (ret < 0) {
  62. cifs_dbg(VFS, "%s: failed to register netlink family\n",
  63. __func__);
  64. return ret;
  65. }
  66. return 0;
  67. }
  68. /**
  69. * cifs_genl_exit - Unregister generic netlink family
  70. */
  71. void cifs_genl_exit(void)
  72. {
  73. int ret;
  74. ret = genl_unregister_family(&cifs_genl_family);
  75. if (ret < 0) {
  76. cifs_dbg(VFS, "%s: failed to unregister netlink family\n",
  77. __func__);
  78. }
  79. }