Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Netlink routines for CIFS
0004  *
0005  * Copyright (c) 2020 Samuel Cabrero <scabrero@suse.de>
0006  */
0007 
0008 #include <net/genetlink.h>
0009 #include <uapi/linux/cifs/cifs_netlink.h>
0010 
0011 #include "netlink.h"
0012 #include "cifsglob.h"
0013 #include "cifs_debug.h"
0014 #include "cifs_swn.h"
0015 
0016 static const struct nla_policy cifs_genl_policy[CIFS_GENL_ATTR_MAX + 1] = {
0017     [CIFS_GENL_ATTR_SWN_REGISTRATION_ID]    = { .type = NLA_U32 },
0018     [CIFS_GENL_ATTR_SWN_NET_NAME]       = { .type = NLA_STRING },
0019     [CIFS_GENL_ATTR_SWN_SHARE_NAME]     = { .type = NLA_STRING },
0020     [CIFS_GENL_ATTR_SWN_IP]         = { .len = sizeof(struct sockaddr_storage) },
0021     [CIFS_GENL_ATTR_SWN_NET_NAME_NOTIFY]    = { .type = NLA_FLAG },
0022     [CIFS_GENL_ATTR_SWN_SHARE_NAME_NOTIFY]  = { .type = NLA_FLAG },
0023     [CIFS_GENL_ATTR_SWN_IP_NOTIFY]      = { .type = NLA_FLAG },
0024     [CIFS_GENL_ATTR_SWN_KRB_AUTH]       = { .type = NLA_FLAG },
0025     [CIFS_GENL_ATTR_SWN_USER_NAME]      = { .type = NLA_STRING },
0026     [CIFS_GENL_ATTR_SWN_PASSWORD]       = { .type = NLA_STRING },
0027     [CIFS_GENL_ATTR_SWN_DOMAIN_NAME]    = { .type = NLA_STRING },
0028     [CIFS_GENL_ATTR_SWN_NOTIFICATION_TYPE]  = { .type = NLA_U32 },
0029     [CIFS_GENL_ATTR_SWN_RESOURCE_STATE] = { .type = NLA_U32 },
0030     [CIFS_GENL_ATTR_SWN_RESOURCE_NAME]  = { .type = NLA_STRING},
0031 };
0032 
0033 static const struct genl_ops cifs_genl_ops[] = {
0034     {
0035         .cmd = CIFS_GENL_CMD_SWN_NOTIFY,
0036         .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
0037         .doit = cifs_swn_notify,
0038     },
0039 };
0040 
0041 static const struct genl_multicast_group cifs_genl_mcgrps[] = {
0042     [CIFS_GENL_MCGRP_SWN] = { .name = CIFS_GENL_MCGRP_SWN_NAME },
0043 };
0044 
0045 struct genl_family cifs_genl_family = {
0046     .name       = CIFS_GENL_NAME,
0047     .version    = CIFS_GENL_VERSION,
0048     .hdrsize    = 0,
0049     .maxattr    = CIFS_GENL_ATTR_MAX,
0050     .module     = THIS_MODULE,
0051     .policy     = cifs_genl_policy,
0052     .ops        = cifs_genl_ops,
0053     .n_ops      = ARRAY_SIZE(cifs_genl_ops),
0054     .mcgrps     = cifs_genl_mcgrps,
0055     .n_mcgrps   = ARRAY_SIZE(cifs_genl_mcgrps),
0056 };
0057 
0058 /**
0059  * cifs_genl_init - Register generic netlink family
0060  *
0061  * Return zero if initialized successfully, otherwise non-zero.
0062  */
0063 int cifs_genl_init(void)
0064 {
0065     int ret;
0066 
0067     ret = genl_register_family(&cifs_genl_family);
0068     if (ret < 0) {
0069         cifs_dbg(VFS, "%s: failed to register netlink family\n",
0070                 __func__);
0071         return ret;
0072     }
0073 
0074     return 0;
0075 }
0076 
0077 /**
0078  * cifs_genl_exit - Unregister generic netlink family
0079  */
0080 void cifs_genl_exit(void)
0081 {
0082     int ret;
0083 
0084     ret = genl_unregister_family(&cifs_genl_family);
0085     if (ret < 0) {
0086         cifs_dbg(VFS, "%s: failed to unregister netlink family\n",
0087                 __func__);
0088     }
0089 }