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#ifndef __LIBCFS_IOCTL_H__
42#define __LIBCFS_IOCTL_H__
43
44#define LIBCFS_IOCTL_VERSION 0x0001000a
45#define LIBCFS_IOCTL_VERSION2 0x0001000b
46
47struct libcfs_ioctl_hdr {
48 __u32 ioc_len;
49 __u32 ioc_version;
50};
51
52struct libcfs_ioctl_data {
53 struct libcfs_ioctl_hdr ioc_hdr;
54
55 __u64 ioc_nid;
56 __u64 ioc_u64[1];
57
58 __u32 ioc_flags;
59 __u32 ioc_count;
60 __u32 ioc_net;
61 __u32 ioc_u32[7];
62
63 __u32 ioc_inllen1;
64 char *ioc_inlbuf1;
65 __u32 ioc_inllen2;
66 char *ioc_inlbuf2;
67
68 __u32 ioc_plen1;
69 void __user *ioc_pbuf1;
70 __u32 ioc_plen2;
71 void __user *ioc_pbuf2;
72
73 char ioc_bulk[0];
74};
75
76#define ioc_priority ioc_u32[0]
77
78struct libcfs_debug_ioctl_data {
79 struct libcfs_ioctl_hdr hdr;
80 unsigned int subs;
81 unsigned int debug;
82};
83
84#define LIBCFS_IOC_INIT(data) \
85do { \
86 memset(&data, 0, sizeof(data)); \
87 data.ioc_version = LIBCFS_IOCTL_VERSION; \
88 data.ioc_len = sizeof(data); \
89} while (0)
90
91struct libcfs_ioctl_handler {
92 struct list_head item;
93 int (*handle_ioctl)(unsigned int cmd, struct libcfs_ioctl_hdr *hdr);
94};
95
96#define DECLARE_IOCTL_HANDLER(ident, func) \
97 struct libcfs_ioctl_handler ident = { \
98 LIST_HEAD_INIT(ident.item), \
99 func \
100 }
101
102
103#define LIBCFS_IOC_DEBUG_MASK _IOWR('f', 250, long)
104
105#define IOC_LIBCFS_TYPE 'e'
106#define IOC_LIBCFS_MIN_NR 30
107
108#define IOC_LIBCFS_PANIC _IOWR('e', 30, long)
109#define IOC_LIBCFS_CLEAR_DEBUG _IOWR('e', 31, long)
110#define IOC_LIBCFS_MARK_DEBUG _IOWR('e', 32, long)
111#define IOC_LIBCFS_MEMHOG _IOWR('e', 36, long)
112
113#define IOC_LIBCFS_GET_NI _IOWR('e', 50, long)
114#define IOC_LIBCFS_FAIL_NID _IOWR('e', 51, long)
115#define IOC_LIBCFS_NOTIFY_ROUTER _IOWR('e', 55, long)
116#define IOC_LIBCFS_UNCONFIGURE _IOWR('e', 56, long)
117
118#define IOC_LIBCFS_LNET_DIST _IOWR('e', 58, long)
119#define IOC_LIBCFS_CONFIGURE _IOWR('e', 59, long)
120#define IOC_LIBCFS_TESTPROTOCOMPAT _IOWR('e', 60, long)
121#define IOC_LIBCFS_PING _IOWR('e', 61, long)
122
123#define IOC_LIBCFS_LNETST _IOWR('e', 63, long)
124#define IOC_LIBCFS_LNET_FAULT _IOWR('e', 64, long)
125
126#define IOC_LIBCFS_REGISTER_MYNID _IOWR('e', 70, long)
127#define IOC_LIBCFS_CLOSE_CONNECTION _IOWR('e', 71, long)
128#define IOC_LIBCFS_PUSH_CONNECTION _IOWR('e', 72, long)
129#define IOC_LIBCFS_GET_CONN _IOWR('e', 73, long)
130#define IOC_LIBCFS_DEL_PEER _IOWR('e', 74, long)
131#define IOC_LIBCFS_ADD_PEER _IOWR('e', 75, long)
132#define IOC_LIBCFS_GET_PEER _IOWR('e', 76, long)
133
134#define IOC_LIBCFS_ADD_INTERFACE _IOWR('e', 78, long)
135#define IOC_LIBCFS_DEL_INTERFACE _IOWR('e', 79, long)
136#define IOC_LIBCFS_GET_INTERFACE _IOWR('e', 80, long)
137
138
139
140
141
142
143
144#define IOCTL_CONFIG_SIZE struct lnet_ioctl_config_data
145#define IOC_LIBCFS_ADD_ROUTE _IOWR(IOC_LIBCFS_TYPE, 81, IOCTL_CONFIG_SIZE)
146#define IOC_LIBCFS_DEL_ROUTE _IOWR(IOC_LIBCFS_TYPE, 82, IOCTL_CONFIG_SIZE)
147#define IOC_LIBCFS_GET_ROUTE _IOWR(IOC_LIBCFS_TYPE, 83, IOCTL_CONFIG_SIZE)
148#define IOC_LIBCFS_ADD_NET _IOWR(IOC_LIBCFS_TYPE, 84, IOCTL_CONFIG_SIZE)
149#define IOC_LIBCFS_DEL_NET _IOWR(IOC_LIBCFS_TYPE, 85, IOCTL_CONFIG_SIZE)
150#define IOC_LIBCFS_GET_NET _IOWR(IOC_LIBCFS_TYPE, 86, IOCTL_CONFIG_SIZE)
151#define IOC_LIBCFS_CONFIG_RTR _IOWR(IOC_LIBCFS_TYPE, 87, IOCTL_CONFIG_SIZE)
152#define IOC_LIBCFS_ADD_BUF _IOWR(IOC_LIBCFS_TYPE, 88, IOCTL_CONFIG_SIZE)
153#define IOC_LIBCFS_GET_BUF _IOWR(IOC_LIBCFS_TYPE, 89, IOCTL_CONFIG_SIZE)
154#define IOC_LIBCFS_GET_PEER_INFO _IOWR(IOC_LIBCFS_TYPE, 90, IOCTL_CONFIG_SIZE)
155#define IOC_LIBCFS_GET_LNET_STATS _IOWR(IOC_LIBCFS_TYPE, 91, IOCTL_CONFIG_SIZE)
156#define IOC_LIBCFS_MAX_NR 91
157
158static inline int libcfs_ioctl_packlen(struct libcfs_ioctl_data *data)
159{
160 int len = sizeof(*data);
161
162 len += cfs_size_round(data->ioc_inllen1);
163 len += cfs_size_round(data->ioc_inllen2);
164 return len;
165}
166
167static inline bool libcfs_ioctl_is_invalid(struct libcfs_ioctl_data *data)
168{
169 if (data->ioc_hdr.ioc_len > (1 << 30)) {
170 CERROR("LIBCFS ioctl: ioc_len larger than 1<<30\n");
171 return 1;
172 }
173 if (data->ioc_inllen1 > (1<<30)) {
174 CERROR("LIBCFS ioctl: ioc_inllen1 larger than 1<<30\n");
175 return 1;
176 }
177 if (data->ioc_inllen2 > (1<<30)) {
178 CERROR("LIBCFS ioctl: ioc_inllen2 larger than 1<<30\n");
179 return 1;
180 }
181 if (data->ioc_inlbuf1 && !data->ioc_inllen1) {
182 CERROR("LIBCFS ioctl: inlbuf1 pointer but 0 length\n");
183 return 1;
184 }
185 if (data->ioc_inlbuf2 && !data->ioc_inllen2) {
186 CERROR("LIBCFS ioctl: inlbuf2 pointer but 0 length\n");
187 return 1;
188 }
189 if (data->ioc_pbuf1 && !data->ioc_plen1) {
190 CERROR("LIBCFS ioctl: pbuf1 pointer but 0 length\n");
191 return 1;
192 }
193 if (data->ioc_pbuf2 && !data->ioc_plen2) {
194 CERROR("LIBCFS ioctl: pbuf2 pointer but 0 length\n");
195 return 1;
196 }
197 if (data->ioc_plen1 && !data->ioc_pbuf1) {
198 CERROR("LIBCFS ioctl: plen1 nonzero but no pbuf1 pointer\n");
199 return 1;
200 }
201 if (data->ioc_plen2 && !data->ioc_pbuf2) {
202 CERROR("LIBCFS ioctl: plen2 nonzero but no pbuf2 pointer\n");
203 return 1;
204 }
205 if ((__u32)libcfs_ioctl_packlen(data) != data->ioc_hdr.ioc_len) {
206 CERROR("LIBCFS ioctl: packlen != ioc_len\n");
207 return 1;
208 }
209 if (data->ioc_inllen1 &&
210 data->ioc_bulk[data->ioc_inllen1 - 1] != '\0') {
211 CERROR("LIBCFS ioctl: inlbuf1 not 0 terminated\n");
212 return 1;
213 }
214 if (data->ioc_inllen2 &&
215 data->ioc_bulk[cfs_size_round(data->ioc_inllen1) +
216 data->ioc_inllen2 - 1] != '\0') {
217 CERROR("LIBCFS ioctl: inlbuf2 not 0 terminated\n");
218 return 1;
219 }
220 return 0;
221}
222
223int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand);
224int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand);
225int libcfs_ioctl_getdata_len(const struct libcfs_ioctl_hdr __user *arg,
226 __u32 *buf_len);
227int libcfs_ioctl_popdata(void __user *arg, void *buf, int size);
228int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data);
229
230#endif
231