1 /*****************************************************************************
2 Copyright (c) 2006 EMC Corporation.
3 Copyright (c) 2011 Factor-SPE
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)
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
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.
19 The full GNU General Public License is included in this distribution in the
22 Authors: Srinivas Aji <Aji_Srinivas@emc.com>
23 Authors: Vitalii Demianets <vitas@nppfactor.kiev.ua>
25 ******************************************************************************/
30 #include <linux/if_bridge.h>
31 #include <asm/byteorder.h>
44 #define LOG_STRING_LEN 256
46 typedef struct _log_string
48 char buf
[LOG_STRING_LEN
];
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)); \
58 #define MSTP_SERVER_SOCK_NAME ".mstp_server"
61 #define CTL_DECLARE(name) \
62 int CTL_ ## name name ## _ARGS
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, \
68 struct get_cist_bridge_status_IN
72 struct get_cist_bridge_status_OUT
74 CIST_BridgeStatus status
;
75 char root_port_name
[IFNAMSIZ
];
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, \
82 CTL_DECLARE(get_cist_bridge_status
);
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, \
89 struct get_msti_bridge_status_IN
94 struct get_msti_bridge_status_OUT
96 MSTI_BridgeStatus status
;
97 char root_port_name
[IFNAMSIZ
];
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, \
105 CTL_DECLARE(get_msti_bridge_status
);
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
113 CIST_BridgeConfig cfg
;
115 struct set_cist_bridge_config_OUT
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
);
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
132 __u8 bridge_priority
;
134 struct set_msti_bridge_config_OUT
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, \
143 CTL_DECLARE(set_msti_bridge_config
);
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
154 struct get_cist_port_status_OUT
156 CIST_PortStatus status
;
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
);
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
174 struct get_msti_port_status_OUT
176 MSTI_PortStatus status
;
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, \
184 CTL_DECLARE(get_msti_port_status
);
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
196 struct set_cist_port_config_OUT
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
);
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
216 struct set_msti_port_config_OUT
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, \
225 CTL_DECLARE(set_msti_port_config
);
228 #define CMD_CODE_port_mcheck 109
229 #define port_mcheck_ARGS (int br_index, int port_index)
230 struct port_mcheck_IN
235 struct port_mcheck_OUT
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
);
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
251 struct set_debug_level_OUT
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
);
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
266 struct get_mstilist_OUT
269 __u16 mstids
[MAX_IMPLEMENTATION_MSTIS
+ 1]; /* +1 - for the CIST */
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
);
279 #define CMD_CODE_create_msti 112
280 #define create_msti_ARGS (int br_index, __u16 mstid)
281 struct create_msti_IN
286 struct create_msti_OUT
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
);
296 #define CMD_CODE_delete_msti 113
297 #define delete_msti_ARGS (int br_index, __u16 mstid)
298 struct delete_msti_IN
303 struct delete_msti_OUT
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
);
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
319 struct get_mstconfid_OUT
321 mst_configuration_identifier_t cfg
;
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
);
329 #define CMD_CODE_set_mstconfid 115
330 #define set_mstconfid_ARGS (int br_index, __u16 revision, char *name)
331 struct set_mstconfid_IN
335 __u8 name
[CONFIGURATION_NAME_LEN
];
337 struct set_mstconfid_OUT
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
);
347 #define CMD_CODE_get_vids2fids 116
348 #define get_vids2fids_ARGS (int br_index, __u16 *vids2fids)
349 struct get_vids2fids_IN
353 struct get_vids2fids_OUT
355 __u16 vids2fids
[MAX_VID
+ 1];
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
);
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
370 struct get_fids2mstids_OUT
372 __u16 fids2mstids
[MAX_FID
+ 1];
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
);
381 #define CMD_CODE_set_vid2fid 118
382 #define set_vid2fid_ARGS (int br_index, __u16 vid, __u16 fid)
383 struct set_vid2fid_IN
388 struct set_vid2fid_OUT
391 #define set_vid2fid_COPY_IN ({ in->br_index = br_index; in->vid = vid; \
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
);
398 #define CMD_CODE_set_fid2mstid 119
399 #define set_fid2mstid_ARGS (int br_index, __u16 fid, __u16 mstid)
400 struct set_fid2mstid_IN
405 struct set_fid2mstid_OUT
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
);
415 #define CMD_CODE_set_vids2fids 120
416 #define set_vids2fids_ARGS (int br_index, __u16 *vids2fids)
417 struct set_vids2fids_IN
420 __u16 vids2fids
[MAX_VID
+ 1];
422 struct set_vids2fids_OUT
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
);
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
437 __u16 fids2mstids
[MAX_FID
+ 1];
439 struct set_fids2mstids_OUT
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
);
448 /* General case part in ctl command server switch */
449 #define SERVER_MESSAGE_CASE(name) \
450 case CMD_CODE_ ## name : do \
452 struct name ## _IN in0, *in = &in0; \
453 struct name ## _OUT out0, *out = &out0; \
454 if(sizeof(*in) != lin || sizeof(*out) != lout) \
456 LOG("Bad sizes lin %d != %zd or lout %d != %zd", \
457 lin, sizeof(*in), lout, sizeof(*out)); \
460 memcpy(in, inbuf, lin); \
461 int r = CTL_ ## name name ## _CALL; \
465 memcpy(outbuf, out, lout); \
469 /* Wraper for the control functions in the control command client */
470 #define CLIENT_SIDE_FUNCTION(name) \
473 struct name ## _IN in0, *in = &in0; \
474 struct name ## _OUT out0, *out = &out0; \
477 LogString log = { .buf = "" }; \
478 int r = send_ctl_message(CMD_CODE_ ## name, in, sizeof(*in), \
479 out, sizeof(*out), &log, &res); \
481 LOG("Got return code %d, %d\n%s", r, res, log.buf); \
490 #endif /* CTL_SOCKET_H */