summaryrefslogtreecommitdiff
path: root/net/smc/smc_netlink.c
blob: c5a62f6f52ba5fc092072899916c0d30971d6d26 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// SPDX-License-Identifier: GPL-2.0
/*
 *  Shared Memory Communications over RDMA (SMC-R) and RoCE
 *
 *  Generic netlink support functions to interact with SMC module
 *
 *  Copyright IBM Corp. 2020
 *
 *  Author(s):	Guvenc Gulce <guvenc@linux.ibm.com>
 */

#include <linux/module.h>
#include <linux/list.h>
#include <linux/ctype.h>
#include <linux/mutex.h>
#include <linux/if.h>
#include <linux/smc.h>

#include "smc_core.h"
#include "smc_ism.h"
#include "smc_ib.h"
#include "smc_clc.h"
#include "smc_stats.h"
#include "smc_netlink.h"

const struct nla_policy
smc_gen_ueid_policy[SMC_NLA_EID_TABLE_MAX + 1] = {
	[SMC_NLA_EID_TABLE_UNSPEC]	= { .type = NLA_UNSPEC },
	[SMC_NLA_EID_TABLE_ENTRY]	= { .type = NLA_STRING,
					    .len = SMC_MAX_EID_LEN,
					  },
};

#define SMC_CMD_MAX_ATTR 1
/* SMC_GENL generic netlink operation definition */
static const struct genl_ops smc_gen_nl_ops[] = {
	{
		.cmd = SMC_NETLINK_GET_SYS_INFO,
		/* can be retrieved by unprivileged users */
		.dumpit = smc_nl_get_sys_info,
	},
	{
		.cmd = SMC_NETLINK_GET_LGR_SMCR,
		/* can be retrieved by unprivileged users */
		.dumpit = smcr_nl_get_lgr,
	},
	{
		.cmd = SMC_NETLINK_GET_LINK_SMCR,
		/* can be retrieved by unprivileged users */
		.dumpit = smcr_nl_get_link,
	},
	{
		.cmd = SMC_NETLINK_GET_LGR_SMCD,
		/* can be retrieved by unprivileged users */
		.dumpit = smcd_nl_get_lgr,
	},
	{
		.cmd = SMC_NETLINK_GET_DEV_SMCD,
		/* can be retrieved by unprivileged users */
		.dumpit = smcd_nl_get_device,
	},
	{
		.cmd = SMC_NETLINK_GET_DEV_SMCR,
		/* can be retrieved by unprivileged users */
		.dumpit = smcr_nl_get_device,
	},
	{
		.cmd = SMC_NETLINK_GET_STATS,
		/* can be retrieved by unprivileged users */
		.dumpit = smc_nl_get_stats,
	},
	{
		.cmd = SMC_NETLINK_GET_FBACK_STATS,
		/* can be retrieved by unprivileged users */
		.dumpit = smc_nl_get_fback_stats,
	},
	{
		.cmd = SMC_NETLINK_DUMP_UEID,
		/* can be retrieved by unprivileged users */
		.dumpit = smc_nl_dump_ueid,
	},
	{
		.cmd = SMC_NETLINK_ADD_UEID,
		.flags = GENL_ADMIN_PERM,
		.doit = smc_nl_add_ueid,
		.policy = smc_gen_ueid_policy,
	},
	{
		.cmd = SMC_NETLINK_REMOVE_UEID,
		.flags = GENL_ADMIN_PERM,
		.doit = smc_nl_remove_ueid,
		.policy = smc_gen_ueid_policy,
	},
	{
		.cmd = SMC_NETLINK_FLUSH_UEID,
		.flags = GENL_ADMIN_PERM,
		.doit = smc_nl_flush_ueid,
	},
	{
		.cmd = SMC_NETLINK_DUMP_SEID,
		/* can be retrieved by unprivileged users */
		.dumpit = smc_nl_dump_seid,
	},
	{
		.cmd = SMC_NETLINK_ENABLE_SEID,
		.flags = GENL_ADMIN_PERM,
		.doit = smc_nl_enable_seid,
	},
	{
		.cmd = SMC_NETLINK_DISABLE_SEID,
		.flags = GENL_ADMIN_PERM,
		.doit = smc_nl_disable_seid,
	},
	{
		.cmd = SMC_NETLINK_DUMP_HS_LIMITATION,
		/* can be retrieved by unprivileged users */
		.dumpit = smc_nl_dump_hs_limitation,
	},
	{
		.cmd = SMC_NETLINK_ENABLE_HS_LIMITATION,
		.flags = GENL_ADMIN_PERM,
		.doit = smc_nl_enable_hs_limitation,
	},
	{
		.cmd = SMC_NETLINK_DISABLE_HS_LIMITATION,
		.flags = GENL_ADMIN_PERM,
		.doit = smc_nl_disable_hs_limitation,
	},
};

static const struct nla_policy smc_gen_nl_policy[2] = {
	[SMC_CMD_MAX_ATTR]	= { .type = NLA_REJECT, },
};

/* SMC_GENL family definition */
struct genl_family smc_gen_nl_family __ro_after_init = {
	.hdrsize =	0,
	.name =		SMC_GENL_FAMILY_NAME,
	.version =	SMC_GENL_FAMILY_VERSION,
	.maxattr =	SMC_CMD_MAX_ATTR,
	.policy =	smc_gen_nl_policy,
	.netnsok =	true,
	.module =	THIS_MODULE,
	.ops =		smc_gen_nl_ops,
	.n_ops =	ARRAY_SIZE(smc_gen_nl_ops)
};

int __init smc_nl_init(void)
{
	return genl_register_family(&smc_gen_nl_family);
}

void smc_nl_exit(void)
{
	genl_unregister_family(&smc_gen_nl_family);
}