-
Notifications
You must be signed in to change notification settings - Fork 7
/
ctl_functions.h
506 lines (463 loc) · 16 KB
/
ctl_functions.h
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
/*****************************************************************************
Copyright (c) 2006 EMC Corporation.
Copyright (c) 2011 Factor-SPE
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the Free
Software Foundation; either version 2 of the License, or (at your option)
any later version.
This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
more details.
You should have received a copy of the GNU General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59
Temple Place - Suite 330, Boston, MA 02111-1307, USA.
The full GNU General Public License is included in this distribution in the
file called LICENSE.
Authors: Srinivas Aji <[email protected]>
Authors: Vitalii Demianets <[email protected]>
******************************************************************************/
#ifndef CTL_SOCKET_H
#define CTL_SOCKET_H
#include <string.h>
#include <netinet/in.h>
#include <linux/if_bridge.h>
#include <asm/byteorder.h>
#include "mstp.h"
struct ctl_msg_hdr
{
int cmd;
int lin;
int lout;
int llog;
int res;
};
#define LOG_STRING_LEN 256
typedef struct _log_string
{
char buf[LOG_STRING_LEN];
} LogString;
#define set_socket_address(sa, string) do{ \
struct sockaddr_un * tmp_sa = (sa); \
memset(tmp_sa, 0, sizeof(*tmp_sa)); \
tmp_sa->sun_family = AF_UNIX; \
strcpy(tmp_sa->sun_path + 1, (string)); \
}while(0)
#define MSTP_SERVER_SOCK_NAME ".mstp_server"
/* Commands sent from bridge-stp script need this flag */
#define RESPONSE_FIRST_HANDLE_LATER 0x10000
/* COMMANDS */
#define CTL_DECLARE(name) \
int CTL_ ## name name ## _ARGS
/* get_cist_bridge_status */
#define CMD_CODE_get_cist_bridge_status 101
#define get_cist_bridge_status_ARGS (int br_index, CIST_BridgeStatus *status, \
char *root_port_name)
struct get_cist_bridge_status_IN
{
int br_index;
};
struct get_cist_bridge_status_OUT
{
CIST_BridgeStatus status;
char root_port_name[IFNAMSIZ];
};
#define get_cist_bridge_status_COPY_IN ({ in->br_index = br_index; })
#define get_cist_bridge_status_COPY_OUT ({ *status = out->status; \
strncpy(root_port_name, out->root_port_name, IFNAMSIZ); })
#define get_cist_bridge_status_CALL (in->br_index, &out->status, \
out->root_port_name)
CTL_DECLARE(get_cist_bridge_status);
/* get_msti_bridge_status */
#define CMD_CODE_get_msti_bridge_status 102
#define get_msti_bridge_status_ARGS (int br_index, __u16 mstid, \
MSTI_BridgeStatus *status, \
char *root_port_name)
struct get_msti_bridge_status_IN
{
int br_index;
__u16 mstid;
};
struct get_msti_bridge_status_OUT
{
MSTI_BridgeStatus status;
char root_port_name[IFNAMSIZ];
};
#define get_msti_bridge_status_COPY_IN \
({ in->br_index = br_index; in->mstid = mstid; })
#define get_msti_bridge_status_COPY_OUT ({ *status = out->status; \
strncpy(root_port_name, out->root_port_name, IFNAMSIZ); })
#define get_msti_bridge_status_CALL (in->br_index, in->mstid, &out->status, \
out->root_port_name)
CTL_DECLARE(get_msti_bridge_status);
/* set_cist_bridge_config */
#define CMD_CODE_set_cist_bridge_config 103
#define set_cist_bridge_config_ARGS (int br_index, CIST_BridgeConfig *cfg)
struct set_cist_bridge_config_IN
{
int br_index;
CIST_BridgeConfig cfg;
};
struct set_cist_bridge_config_OUT
{
};
#define set_cist_bridge_config_COPY_IN \
({ in->br_index = br_index; in->cfg = *cfg; })
#define set_cist_bridge_config_COPY_OUT ({ (void)0; })
#define set_cist_bridge_config_CALL (in->br_index, &in->cfg)
CTL_DECLARE(set_cist_bridge_config);
/* set_msti_bridge_config */
#define CMD_CODE_set_msti_bridge_config 104
#define set_msti_bridge_config_ARGS (int br_index, __u16 mstid, \
__u8 bridge_priority)
struct set_msti_bridge_config_IN
{
int br_index;
__u16 mstid;
__u8 bridge_priority;
};
struct set_msti_bridge_config_OUT
{
};
#define set_msti_bridge_config_COPY_IN \
({ in->br_index = br_index; in->mstid = mstid; \
in->bridge_priority = bridge_priority; })
#define set_msti_bridge_config_COPY_OUT ({ (void)0; })
#define set_msti_bridge_config_CALL (in->br_index, in->mstid, \
in->bridge_priority)
CTL_DECLARE(set_msti_bridge_config);
/* get_cist_port_status */
#define CMD_CODE_get_cist_port_status 105
#define get_cist_port_status_ARGS (int br_index, int port_index, \
CIST_PortStatus *status)
struct get_cist_port_status_IN
{
int br_index;
int port_index;
};
struct get_cist_port_status_OUT
{
CIST_PortStatus status;
};
#define get_cist_port_status_COPY_IN \
({ in->br_index = br_index; in->port_index = port_index; })
#define get_cist_port_status_COPY_OUT ({ *status = out->status; })
#define get_cist_port_status_CALL (in->br_index, in->port_index, &out->status)
CTL_DECLARE(get_cist_port_status);
/* get_msti_port_status */
#define CMD_CODE_get_msti_port_status 106
#define get_msti_port_status_ARGS (int br_index, int port_index, __u16 mstid, \
MSTI_PortStatus *status)
struct get_msti_port_status_IN
{
int br_index;
int port_index;
__u16 mstid;
};
struct get_msti_port_status_OUT
{
MSTI_PortStatus status;
};
#define get_msti_port_status_COPY_IN \
({ in->br_index = br_index; in->port_index = port_index; \
in->mstid = mstid; })
#define get_msti_port_status_COPY_OUT ({ *status = out->status; })
#define get_msti_port_status_CALL (in->br_index, in->port_index, in->mstid, \
&out->status)
CTL_DECLARE(get_msti_port_status);
/* set_cist_port_config */
#define CMD_CODE_set_cist_port_config 107
#define set_cist_port_config_ARGS (int br_index, int port_index, \
CIST_PortConfig *cfg)
struct set_cist_port_config_IN
{
int br_index;
int port_index;
CIST_PortConfig cfg;
};
struct set_cist_port_config_OUT
{
};
#define set_cist_port_config_COPY_IN \
({ in->br_index = br_index; in->port_index = port_index; in->cfg = *cfg; })
#define set_cist_port_config_COPY_OUT ({ (void)0; })
#define set_cist_port_config_CALL (in->br_index, in->port_index, &in->cfg)
CTL_DECLARE(set_cist_port_config);
/* set_msti_port_config */
#define CMD_CODE_set_msti_port_config 108
#define set_msti_port_config_ARGS (int br_index, int port_index, __u16 mstid, \
MSTI_PortConfig *cfg)
struct set_msti_port_config_IN
{
int br_index;
int port_index;
__u16 mstid;
MSTI_PortConfig cfg;
};
struct set_msti_port_config_OUT
{
};
#define set_msti_port_config_COPY_IN \
({ in->br_index = br_index; in->port_index = port_index; \
in->mstid = mstid; in->cfg = *cfg; })
#define set_msti_port_config_COPY_OUT ({ (void)0; })
#define set_msti_port_config_CALL (in->br_index, in->port_index, in->mstid, \
&in->cfg)
CTL_DECLARE(set_msti_port_config);
/* port_mcheck */
#define CMD_CODE_port_mcheck 109
#define port_mcheck_ARGS (int br_index, int port_index)
struct port_mcheck_IN
{
int br_index;
int port_index;
};
struct port_mcheck_OUT
{
};
#define port_mcheck_COPY_IN \
({ in->br_index = br_index; in->port_index = port_index; })
#define port_mcheck_COPY_OUT ({ (void)0; })
#define port_mcheck_CALL (in->br_index, in->port_index)
CTL_DECLARE(port_mcheck);
/* set_debug_level */
#define CMD_CODE_set_debug_level 110
#define set_debug_level_ARGS (int level)
struct set_debug_level_IN
{
int level;
};
struct set_debug_level_OUT
{
};
#define set_debug_level_COPY_IN ({ in->level = level; })
#define set_debug_level_COPY_OUT ({ (void)0; })
#define set_debug_level_CALL (in->level)
CTL_DECLARE(set_debug_level);
/* get_mstilist */
#define CMD_CODE_get_mstilist 111
#define get_mstilist_ARGS (int br_index, int *num_mstis, __u16 *mstids)
struct get_mstilist_IN
{
int br_index;
};
struct get_mstilist_OUT
{
int num_mstis;
__u16 mstids[MAX_IMPLEMENTATION_MSTIS + 1]; /* +1 - for the CIST */
};
#define get_mstilist_COPY_IN \
({ in->br_index = br_index; })
#define get_mstilist_COPY_OUT ({ *num_mstis = out->num_mstis; \
memcpy(mstids, out->mstids, (*num_mstis) * sizeof(out->mstids[0])); })
#define get_mstilist_CALL (in->br_index, &out->num_mstis, out->mstids)
CTL_DECLARE(get_mstilist);
/* create_msti */
#define CMD_CODE_create_msti 112
#define create_msti_ARGS (int br_index, __u16 mstid)
struct create_msti_IN
{
int br_index;
__u16 mstid;
};
struct create_msti_OUT
{
};
#define create_msti_COPY_IN \
({ in->br_index = br_index; in->mstid = mstid; })
#define create_msti_COPY_OUT ({ (void)0; })
#define create_msti_CALL (in->br_index, in->mstid)
CTL_DECLARE(create_msti);
/* delete_msti */
#define CMD_CODE_delete_msti 113
#define delete_msti_ARGS (int br_index, __u16 mstid)
struct delete_msti_IN
{
int br_index;
__u16 mstid;
};
struct delete_msti_OUT
{
};
#define delete_msti_COPY_IN \
({ in->br_index = br_index; in->mstid = mstid; })
#define delete_msti_COPY_OUT ({ (void)0; })
#define delete_msti_CALL (in->br_index, in->mstid)
CTL_DECLARE(delete_msti);
/* get_mstconfid */
#define CMD_CODE_get_mstconfid 114
#define get_mstconfid_ARGS (int br_index, mst_configuration_identifier_t *cfg)
struct get_mstconfid_IN
{
int br_index;
};
struct get_mstconfid_OUT
{
mst_configuration_identifier_t cfg;
};
#define get_mstconfid_COPY_IN ({ in->br_index = br_index; })
#define get_mstconfid_COPY_OUT ({ *cfg = out->cfg; })
#define get_mstconfid_CALL (in->br_index, &out->cfg)
CTL_DECLARE(get_mstconfid);
/* set_mstconfid */
#define CMD_CODE_set_mstconfid 115
#define set_mstconfid_ARGS (int br_index, __u16 revision, __u8 *name)
struct set_mstconfid_IN
{
int br_index;
__u16 revision;
__u8 name[CONFIGURATION_NAME_LEN];
};
struct set_mstconfid_OUT
{
};
#define set_mstconfid_COPY_IN ({ in->br_index = br_index; \
in->revision = revision; strncpy((char *)in->name, (char *)name, sizeof(in->name)); })
#define set_mstconfid_COPY_OUT ({ (void)0; })
#define set_mstconfid_CALL (in->br_index, in->revision, in->name)
CTL_DECLARE(set_mstconfid);
/* get_vids2fids */
#define CMD_CODE_get_vids2fids 116
#define get_vids2fids_ARGS (int br_index, __u16 *vids2fids)
struct get_vids2fids_IN
{
int br_index;
};
struct get_vids2fids_OUT
{
__u16 vids2fids[MAX_VID + 1];
};
#define get_vids2fids_COPY_IN ({ in->br_index = br_index; })
#define get_vids2fids_COPY_OUT ({ \
memcpy(vids2fids, out->vids2fids, sizeof(out->vids2fids)); })
#define get_vids2fids_CALL (in->br_index, out->vids2fids)
CTL_DECLARE(get_vids2fids);
/* get_fids2mstids */
#define CMD_CODE_get_fids2mstids 117
#define get_fids2mstids_ARGS (int br_index, __u16 *fids2mstids)
struct get_fids2mstids_IN
{
int br_index;
};
struct get_fids2mstids_OUT
{
__u16 fids2mstids[MAX_FID + 1];
};
#define get_fids2mstids_COPY_IN ({ in->br_index = br_index; })
#define get_fids2mstids_COPY_OUT ({ \
memcpy(fids2mstids, out->fids2mstids, sizeof(out->fids2mstids)); })
#define get_fids2mstids_CALL (in->br_index, out->fids2mstids)
CTL_DECLARE(get_fids2mstids);
/* set_vid2fid */
#define CMD_CODE_set_vid2fid 118
#define set_vid2fid_ARGS (int br_index, __u16 vid, __u16 fid)
struct set_vid2fid_IN
{
int br_index;
__u16 vid, fid;
};
struct set_vid2fid_OUT
{
};
#define set_vid2fid_COPY_IN ({ in->br_index = br_index; in->vid = vid; \
in->fid = fid; })
#define set_vid2fid_COPY_OUT ({ (void)0; })
#define set_vid2fid_CALL (in->br_index, in->vid, in->fid)
CTL_DECLARE(set_vid2fid);
/* set_fid2mstid */
#define CMD_CODE_set_fid2mstid 119
#define set_fid2mstid_ARGS (int br_index, __u16 fid, __u16 mstid)
struct set_fid2mstid_IN
{
int br_index;
__u16 fid, mstid;
};
struct set_fid2mstid_OUT
{
};
#define set_fid2mstid_COPY_IN ({ in->br_index = br_index; in->fid = fid; \
in->mstid = mstid; })
#define set_fid2mstid_COPY_OUT ({ (void)0; })
#define set_fid2mstid_CALL (in->br_index, in->fid, in->mstid)
CTL_DECLARE(set_fid2mstid);
/* set_vids2fids */
#define CMD_CODE_set_vids2fids 120
#define set_vids2fids_ARGS (int br_index, __u16 *vids2fids)
struct set_vids2fids_IN
{
int br_index;
__u16 vids2fids[MAX_VID + 1];
};
struct set_vids2fids_OUT
{
};
#define set_vids2fids_COPY_IN ({ in->br_index = br_index; \
memcpy(in->vids2fids, vids2fids, sizeof(in->vids2fids)); })
#define set_vids2fids_COPY_OUT ({ (void)0; })
#define set_vids2fids_CALL (in->br_index, in->vids2fids)
CTL_DECLARE(set_vids2fids);
/* set_fids2mstids */
#define CMD_CODE_set_fids2mstids 121
#define set_fids2mstids_ARGS (int br_index, __u16 *fids2mstids)
struct set_fids2mstids_IN
{
int br_index;
__u16 fids2mstids[MAX_FID + 1];
};
struct set_fids2mstids_OUT
{
};
#define set_fids2mstids_COPY_IN ({ in->br_index = br_index; \
memcpy(in->fids2mstids, fids2mstids, sizeof(in->fids2mstids)); })
#define set_fids2mstids_COPY_OUT ({ (void)0; })
#define set_fids2mstids_CALL (in->br_index, in->fids2mstids)
CTL_DECLARE(set_fids2mstids);
/* add bridges */
#define CMD_CODE_add_bridges (122 | RESPONSE_FIRST_HANDLE_LATER)
#define add_bridges_ARGS (int *br_array, int* *ifaces_lists)
CTL_DECLARE(add_bridges);
/* delete bridges */
#define CMD_CODE_del_bridges (123 | RESPONSE_FIRST_HANDLE_LATER)
#define del_bridges_ARGS (int *br_array)
CTL_DECLARE(del_bridges);
/* General case part in ctl command server switch */
#define SERVER_MESSAGE_CASE(name) \
case CMD_CODE_ ## name : do \
{ \
struct name ## _IN in0, *in = &in0; \
struct name ## _OUT out0, *out = &out0; \
if(sizeof(*in) != lin || sizeof(*out) != lout) \
{ \
LOG("Bad sizes lin %d != %zd or lout %d != %zd", \
lin, sizeof(*in), lout, sizeof(*out)); \
return -1; \
} \
memcpy(in, inbuf, lin); \
int r = CTL_ ## name name ## _CALL; \
if(r) \
return r; \
if(outbuf) \
memcpy(outbuf, out, lout); \
return r; \
}while(0)
/* Wraper for the control functions in the control command client */
#define CLIENT_SIDE_FUNCTION(name) \
CTL_DECLARE(name) \
{ \
struct name ## _IN in0, *in = &in0; \
struct name ## _OUT out0, *out = &out0; \
name ## _COPY_IN; \
int res = 0; \
LogString log = { .buf = "" }; \
int r = send_ctl_message(CMD_CODE_ ## name, in, sizeof(*in), \
out, sizeof(*out), &log, &res); \
if(r || res) \
LOG("Got return code %d, %d\n%s", r, res, log.buf); \
if(r) \
return r; \
if(res) \
return res; \
name ## _COPY_OUT; \
return 0; \
}
#endif /* CTL_SOCKET_H */