]> git.ipfire.org Git - people/ms/mstpd.git/blob - ctl_functions.h
driver hooks for creating/deleting new MSTI
[people/ms/mstpd.git] / ctl_functions.h
1 /*****************************************************************************
2 Copyright (c) 2006 EMC Corporation.
3 Copyright (c) 2011 Factor-SPE
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2 of the License, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc., 59
17 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19 The full GNU General Public License is included in this distribution in the
20 file called LICENSE.
21
22 Authors: Srinivas Aji <Aji_Srinivas@emc.com>
23 Authors: Vitalii Demianets <vitas@nppfactor.kiev.ua>
24
25 ******************************************************************************/
26
27 #ifndef CTL_SOCKET_H
28 #define CTL_SOCKET_H
29
30 #include <linux/if_bridge.h>
31 #include <asm/byteorder.h>
32
33 #include "mstp.h"
34
35 struct ctl_msg_hdr
36 {
37 int cmd;
38 int lin;
39 int lout;
40 int llog;
41 int res;
42 };
43
44 #define LOG_STRING_LEN 256
45
46 typedef struct _log_string
47 {
48 char buf[LOG_STRING_LEN];
49 } LogString;
50
51 #define set_socket_address(sa, string) do{ \
52 struct sockaddr_un * tmp_sa = (sa); \
53 memset(tmp_sa, 0, sizeof(*tmp_sa)); \
54 tmp_sa->sun_family = AF_UNIX; \
55 strcpy(tmp_sa->sun_path + 1, (string)); \
56 }while(0)
57
58 #define MSTP_SERVER_SOCK_NAME ".mstp_server"
59
60 /* COMMANDS */
61 #define CTL_DECLARE(name) \
62 int CTL_ ## name name ## _ARGS
63
64 /* get_cist_bridge_status */
65 #define CMD_CODE_get_cist_bridge_status 101
66 #define get_cist_bridge_status_ARGS (int br_index, CIST_BridgeStatus *status, \
67 char *root_port_name)
68 struct get_cist_bridge_status_IN
69 {
70 int br_index;
71 };
72 struct get_cist_bridge_status_OUT
73 {
74 CIST_BridgeStatus status;
75 char root_port_name[IFNAMSIZ];
76 };
77 #define get_cist_bridge_status_COPY_IN ({ in->br_index = br_index; })
78 #define get_cist_bridge_status_COPY_OUT ({ *status = out->status; \
79 strncpy(root_port_name, out->root_port_name, IFNAMSIZ); })
80 #define get_cist_bridge_status_CALL (in->br_index, &out->status, \
81 out->root_port_name)
82 CTL_DECLARE(get_cist_bridge_status);
83
84 /* get_msti_bridge_status */
85 #define CMD_CODE_get_msti_bridge_status 102
86 #define get_msti_bridge_status_ARGS (int br_index, __u16 mstid, \
87 MSTI_BridgeStatus *status, \
88 char *root_port_name)
89 struct get_msti_bridge_status_IN
90 {
91 int br_index;
92 __u16 mstid;
93 };
94 struct get_msti_bridge_status_OUT
95 {
96 MSTI_BridgeStatus status;
97 char root_port_name[IFNAMSIZ];
98 };
99 #define get_msti_bridge_status_COPY_IN \
100 ({ in->br_index = br_index; in->mstid = mstid; })
101 #define get_msti_bridge_status_COPY_OUT ({ *status = out->status; \
102 strncpy(root_port_name, out->root_port_name, IFNAMSIZ); })
103 #define get_msti_bridge_status_CALL (in->br_index, in->mstid, &out->status, \
104 out->root_port_name)
105 CTL_DECLARE(get_msti_bridge_status);
106
107 /* set_cist_bridge_config */
108 #define CMD_CODE_set_cist_bridge_config 103
109 #define set_cist_bridge_config_ARGS (int br_index, CIST_BridgeConfig *cfg)
110 struct set_cist_bridge_config_IN
111 {
112 int br_index;
113 CIST_BridgeConfig cfg;
114 };
115 struct set_cist_bridge_config_OUT
116 {
117 };
118 #define set_cist_bridge_config_COPY_IN \
119 ({ in->br_index = br_index; in->cfg = *cfg; })
120 #define set_cist_bridge_config_COPY_OUT ({ (void)0; })
121 #define set_cist_bridge_config_CALL (in->br_index, &in->cfg)
122 CTL_DECLARE(set_cist_bridge_config);
123
124 /* set_msti_bridge_config */
125 #define CMD_CODE_set_msti_bridge_config 104
126 #define set_msti_bridge_config_ARGS (int br_index, __u16 mstid, \
127 __u8 bridge_priority)
128 struct set_msti_bridge_config_IN
129 {
130 int br_index;
131 __u16 mstid;
132 __u8 bridge_priority;
133 };
134 struct set_msti_bridge_config_OUT
135 {
136 };
137 #define set_msti_bridge_config_COPY_IN \
138 ({ in->br_index = br_index; in->mstid = mstid; \
139 in->bridge_priority = bridge_priority; })
140 #define set_msti_bridge_config_COPY_OUT ({ (void)0; })
141 #define set_msti_bridge_config_CALL (in->br_index, in->mstid, \
142 in->bridge_priority)
143 CTL_DECLARE(set_msti_bridge_config);
144
145 /* get_cist_port_status */
146 #define CMD_CODE_get_cist_port_status 105
147 #define get_cist_port_status_ARGS (int br_index, int port_index, \
148 CIST_PortStatus *status)
149 struct get_cist_port_status_IN
150 {
151 int br_index;
152 int port_index;
153 };
154 struct get_cist_port_status_OUT
155 {
156 CIST_PortStatus status;
157 };
158 #define get_cist_port_status_COPY_IN \
159 ({ in->br_index = br_index; in->port_index = port_index; })
160 #define get_cist_port_status_COPY_OUT ({ *status = out->status; })
161 #define get_cist_port_status_CALL (in->br_index, in->port_index, &out->status)
162 CTL_DECLARE(get_cist_port_status);
163
164 /* get_msti_port_status */
165 #define CMD_CODE_get_msti_port_status 106
166 #define get_msti_port_status_ARGS (int br_index, int port_index, __u16 mstid, \
167 MSTI_PortStatus *status)
168 struct get_msti_port_status_IN
169 {
170 int br_index;
171 int port_index;
172 __u16 mstid;
173 };
174 struct get_msti_port_status_OUT
175 {
176 MSTI_PortStatus status;
177 };
178 #define get_msti_port_status_COPY_IN \
179 ({ in->br_index = br_index; in->port_index = port_index; \
180 in->mstid = mstid; })
181 #define get_msti_port_status_COPY_OUT ({ *status = out->status; })
182 #define get_msti_port_status_CALL (in->br_index, in->port_index, in->mstid, \
183 &out->status)
184 CTL_DECLARE(get_msti_port_status);
185
186 /* set_cist_port_config */
187 #define CMD_CODE_set_cist_port_config 107
188 #define set_cist_port_config_ARGS (int br_index, int port_index, \
189 CIST_PortConfig *cfg)
190 struct set_cist_port_config_IN
191 {
192 int br_index;
193 int port_index;
194 CIST_PortConfig cfg;
195 };
196 struct set_cist_port_config_OUT
197 {
198 };
199 #define set_cist_port_config_COPY_IN \
200 ({ in->br_index = br_index; in->port_index = port_index; in->cfg = *cfg; })
201 #define set_cist_port_config_COPY_OUT ({ (void)0; })
202 #define set_cist_port_config_CALL (in->br_index, in->port_index, &in->cfg)
203 CTL_DECLARE(set_cist_port_config);
204
205 /* set_msti_port_config */
206 #define CMD_CODE_set_msti_port_config 108
207 #define set_msti_port_config_ARGS (int br_index, int port_index, __u16 mstid, \
208 MSTI_PortConfig *cfg)
209 struct set_msti_port_config_IN
210 {
211 int br_index;
212 int port_index;
213 __u16 mstid;
214 MSTI_PortConfig cfg;
215 };
216 struct set_msti_port_config_OUT
217 {
218 };
219 #define set_msti_port_config_COPY_IN \
220 ({ in->br_index = br_index; in->port_index = port_index; \
221 in->mstid = mstid; in->cfg = *cfg; })
222 #define set_msti_port_config_COPY_OUT ({ (void)0; })
223 #define set_msti_port_config_CALL (in->br_index, in->port_index, in->mstid, \
224 &in->cfg)
225 CTL_DECLARE(set_msti_port_config);
226
227 /* port_mcheck */
228 #define CMD_CODE_port_mcheck 109
229 #define port_mcheck_ARGS (int br_index, int port_index)
230 struct port_mcheck_IN
231 {
232 int br_index;
233 int port_index;
234 };
235 struct port_mcheck_OUT
236 {
237 };
238 #define port_mcheck_COPY_IN \
239 ({ in->br_index = br_index; in->port_index = port_index; })
240 #define port_mcheck_COPY_OUT ({ (void)0; })
241 #define port_mcheck_CALL (in->br_index, in->port_index)
242 CTL_DECLARE(port_mcheck);
243
244 /* set_debug_level */
245 #define CMD_CODE_set_debug_level 110
246 #define set_debug_level_ARGS (int level)
247 struct set_debug_level_IN
248 {
249 int level;
250 };
251 struct set_debug_level_OUT
252 {
253 };
254 #define set_debug_level_COPY_IN ({ in->level = level; })
255 #define set_debug_level_COPY_OUT ({ (void)0; })
256 #define set_debug_level_CALL (in->level)
257 CTL_DECLARE(set_debug_level);
258
259 /* get_mstilist */
260 #define CMD_CODE_get_mstilist 111
261 #define get_mstilist_ARGS (int br_index, int *num_mstis, __u16 *mstids)
262 struct get_mstilist_IN
263 {
264 int br_index;
265 };
266 struct get_mstilist_OUT
267 {
268 int num_mstis;
269 __u16 mstids[MAX_IMPLEMENTATION_MSTIS + 1]; /* +1 - for the CIST */
270 };
271 #define get_mstilist_COPY_IN \
272 ({ in->br_index = br_index; })
273 #define get_mstilist_COPY_OUT ({ *num_mstis = out->num_mstis; \
274 memcpy(mstids, out->mstids, (*num_mstis) * sizeof(out->mstids[0])); })
275 #define get_mstilist_CALL (in->br_index, &out->num_mstis, out->mstids)
276 CTL_DECLARE(get_mstilist);
277
278 /* create_msti */
279 #define CMD_CODE_create_msti 112
280 #define create_msti_ARGS (int br_index, __u16 mstid)
281 struct create_msti_IN
282 {
283 int br_index;
284 __u16 mstid;
285 };
286 struct create_msti_OUT
287 {
288 };
289 #define create_msti_COPY_IN \
290 ({ in->br_index = br_index; in->mstid = mstid; })
291 #define create_msti_COPY_OUT ({ (void)0; })
292 #define create_msti_CALL (in->br_index, in->mstid)
293 CTL_DECLARE(create_msti);
294
295 /* delete_msti */
296 #define CMD_CODE_delete_msti 113
297 #define delete_msti_ARGS (int br_index, __u16 mstid)
298 struct delete_msti_IN
299 {
300 int br_index;
301 __u16 mstid;
302 };
303 struct delete_msti_OUT
304 {
305 };
306 #define delete_msti_COPY_IN \
307 ({ in->br_index = br_index; in->mstid = mstid; })
308 #define delete_msti_COPY_OUT ({ (void)0; })
309 #define delete_msti_CALL (in->br_index, in->mstid)
310 CTL_DECLARE(delete_msti);
311
312 /* get_mstconfid */
313 #define CMD_CODE_get_mstconfid 114
314 #define get_mstconfid_ARGS (int br_index, mst_configuration_identifier_t *cfg)
315 struct get_mstconfid_IN
316 {
317 int br_index;
318 };
319 struct get_mstconfid_OUT
320 {
321 mst_configuration_identifier_t cfg;
322 };
323 #define get_mstconfid_COPY_IN ({ in->br_index = br_index; })
324 #define get_mstconfid_COPY_OUT ({ *cfg = out->cfg; })
325 #define get_mstconfid_CALL (in->br_index, &out->cfg)
326 CTL_DECLARE(get_mstconfid);
327
328 /* set_mstconfid */
329 #define CMD_CODE_set_mstconfid 115
330 #define set_mstconfid_ARGS (int br_index, __u16 revision, char *name)
331 struct set_mstconfid_IN
332 {
333 int br_index;
334 __u16 revision;
335 __u8 name[CONFIGURATION_NAME_LEN];
336 };
337 struct set_mstconfid_OUT
338 {
339 };
340 #define set_mstconfid_COPY_IN ({ in->br_index = br_index; \
341 in->revision = revision; strncpy(in->name, name, sizeof(in->name)); })
342 #define set_mstconfid_COPY_OUT ({ (void)0; })
343 #define set_mstconfid_CALL (in->br_index, in->revision, in->name)
344 CTL_DECLARE(set_mstconfid);
345
346 /* get_vids2fids */
347 #define CMD_CODE_get_vids2fids 116
348 #define get_vids2fids_ARGS (int br_index, __u16 *vids2fids)
349 struct get_vids2fids_IN
350 {
351 int br_index;
352 };
353 struct get_vids2fids_OUT
354 {
355 __u16 vids2fids[MAX_VID + 1];
356 };
357 #define get_vids2fids_COPY_IN ({ in->br_index = br_index; })
358 #define get_vids2fids_COPY_OUT ({ \
359 memcpy(vids2fids, out->vids2fids, sizeof(out->vids2fids)); })
360 #define get_vids2fids_CALL (in->br_index, out->vids2fids)
361 CTL_DECLARE(get_vids2fids);
362
363 /* get_fids2mstids */
364 #define CMD_CODE_get_fids2mstids 117
365 #define get_fids2mstids_ARGS (int br_index, __u16 *fids2mstids)
366 struct get_fids2mstids_IN
367 {
368 int br_index;
369 };
370 struct get_fids2mstids_OUT
371 {
372 __u16 fids2mstids[MAX_FID + 1];
373 };
374 #define get_fids2mstids_COPY_IN ({ in->br_index = br_index; })
375 #define get_fids2mstids_COPY_OUT ({ \
376 memcpy(fids2mstids, out->fids2mstids, sizeof(out->fids2mstids)); })
377 #define get_fids2mstids_CALL (in->br_index, out->fids2mstids)
378 CTL_DECLARE(get_fids2mstids);
379
380 /* set_vid2fid */
381 #define CMD_CODE_set_vid2fid 118
382 #define set_vid2fid_ARGS (int br_index, __u16 vid, __u16 fid)
383 struct set_vid2fid_IN
384 {
385 int br_index;
386 __u16 vid, fid;
387 };
388 struct set_vid2fid_OUT
389 {
390 };
391 #define set_vid2fid_COPY_IN ({ in->br_index = br_index; in->vid = vid; \
392 in->fid = fid; })
393 #define set_vid2fid_COPY_OUT ({ (void)0; })
394 #define set_vid2fid_CALL (in->br_index, in->vid, in->fid)
395 CTL_DECLARE(set_vid2fid);
396
397 /* set_fid2mstid */
398 #define CMD_CODE_set_fid2mstid 119
399 #define set_fid2mstid_ARGS (int br_index, __u16 fid, __u16 mstid)
400 struct set_fid2mstid_IN
401 {
402 int br_index;
403 __u16 fid, mstid;
404 };
405 struct set_fid2mstid_OUT
406 {
407 };
408 #define set_fid2mstid_COPY_IN ({ in->br_index = br_index; in->fid = fid; \
409 in->mstid = mstid; })
410 #define set_fid2mstid_COPY_OUT ({ (void)0; })
411 #define set_fid2mstid_CALL (in->br_index, in->fid, in->mstid)
412 CTL_DECLARE(set_fid2mstid);
413
414 /* set_vids2fids */
415 #define CMD_CODE_set_vids2fids 120
416 #define set_vids2fids_ARGS (int br_index, __u16 *vids2fids)
417 struct set_vids2fids_IN
418 {
419 int br_index;
420 __u16 vids2fids[MAX_VID + 1];
421 };
422 struct set_vids2fids_OUT
423 {
424 };
425 #define set_vids2fids_COPY_IN ({ in->br_index = br_index; \
426 memcpy(in->vids2fids, vids2fids, sizeof(in->vids2fids)); })
427 #define set_vids2fids_COPY_OUT ({ (void)0; })
428 #define set_vids2fids_CALL (in->br_index, in->vids2fids)
429 CTL_DECLARE(set_vids2fids);
430
431 /* set_fids2mstids */
432 #define CMD_CODE_set_fids2mstids 121
433 #define set_fids2mstids_ARGS (int br_index, __u16 *fids2mstids)
434 struct set_fids2mstids_IN
435 {
436 int br_index;
437 __u16 fids2mstids[MAX_FID + 1];
438 };
439 struct set_fids2mstids_OUT
440 {
441 };
442 #define set_fids2mstids_COPY_IN ({ in->br_index = br_index; \
443 memcpy(in->fids2mstids, fids2mstids, sizeof(in->fids2mstids)); })
444 #define set_fids2mstids_COPY_OUT ({ (void)0; })
445 #define set_fids2mstids_CALL (in->br_index, in->fids2mstids)
446 CTL_DECLARE(set_fids2mstids);
447
448 /* General case part in ctl command server switch */
449 #define SERVER_MESSAGE_CASE(name) \
450 case CMD_CODE_ ## name : do \
451 { \
452 struct name ## _IN in0, *in = &in0; \
453 struct name ## _OUT out0, *out = &out0; \
454 if(sizeof(*in) != lin || sizeof(*out) != lout) \
455 { \
456 LOG("Bad sizes lin %d != %zd or lout %d != %zd", \
457 lin, sizeof(*in), lout, sizeof(*out)); \
458 return -1; \
459 } \
460 memcpy(in, inbuf, lin); \
461 int r = CTL_ ## name name ## _CALL; \
462 if(r) \
463 return r; \
464 if(outbuf) \
465 memcpy(outbuf, out, lout); \
466 return r; \
467 }while(0)
468
469 /* Wraper for the control functions in the control command client */
470 #define CLIENT_SIDE_FUNCTION(name) \
471 CTL_DECLARE(name) \
472 { \
473 struct name ## _IN in0, *in = &in0; \
474 struct name ## _OUT out0, *out = &out0; \
475 name ## _COPY_IN; \
476 int res = 0; \
477 LogString log = { .buf = "" }; \
478 int r = send_ctl_message(CMD_CODE_ ## name, in, sizeof(*in), \
479 out, sizeof(*out), &log, &res); \
480 if(r || res) \
481 LOG("Got return code %d, %d\n%s", r, res, log.buf); \
482 if(r) \
483 return r; \
484 if(res) \
485 return res; \
486 name ## _COPY_OUT; \
487 return 0; \
488 }
489
490 #endif /* CTL_SOCKET_H */