-
Notifications
You must be signed in to change notification settings - Fork 26
/
ctl_socket.h
188 lines (166 loc) · 5.63 KB
/
ctl_socket.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
/*****************************************************************************
Copyright (c) 2006 EMC Corporation.
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]>
******************************************************************************/
#ifndef CTL_SOCKET_H
#define CTL_SOCKET_H
#include <sys/types.h>
#include <string.h>
#include "ctl_functions.h"
struct ctl_msg_hdr {
int cmd;
int lin;
int lout;
int res;
};
#define set_socket_address(sa, string) \
do {\
(sa)->sun_family = AF_UNIX; \
memset((sa)->sun_path, 0, sizeof((sa)->sun_path)); \
strcpy((sa)->sun_path + 1, (string)); \
} while (0)
#define RSTP_SERVER_SOCK_NAME ".rstp_server"
/* COMMANDS */
#if 0
int CTL_enable_bridge_rstp(int br_index, int enable);
#endif
#define CMD_CODE_enable_bridge_rstp 101
#define enable_bridge_rstp_ARGS (int br_index, int enable)
struct enable_bridge_rstp_IN {
int br_index;
int enable;
};
struct enable_bridge_rstp_OUT {
};
#define enable_bridge_rstp_COPY_IN \
({ in->br_index = br_index; in->enable = enable; })
#define enable_bridge_rstp_COPY_OUT ({ (void)0; })
#define enable_bridge_rstp_CALL (in->br_index, in->enable)
#if 0
int CTL_get_bridge_state(int br_index,
UID_STP_CFG_T * cfg, UID_STP_STATE_T * state);
#endif
#define CMD_CODE_get_bridge_state 102
#define get_bridge_state_ARGS (int br_index, UID_STP_CFG_T *cfg, UID_STP_STATE_T *state)
struct get_bridge_state_IN {
int br_index;
};
struct get_bridge_state_OUT {
UID_STP_CFG_T cfg;
UID_STP_STATE_T state;
};
#define get_bridge_state_COPY_IN \
({ in->br_index = br_index; })
#define get_bridge_state_COPY_OUT ({ *cfg = out->cfg; *state = out->state; })
#define get_bridge_state_CALL (in->br_index, &out->cfg, &out->state)
#if 0
int CTL_set_bridge_config(int br_index, UID_STP_CFG_T * cfg);
#endif
#define CMD_CODE_set_bridge_config 103
#define set_bridge_config_ARGS (int br_index, UID_STP_CFG_T *cfg)
struct set_bridge_config_IN {
int br_index;
UID_STP_CFG_T cfg;
};
struct set_bridge_config_OUT {
};
#define set_bridge_config_COPY_IN \
({ in->br_index = br_index; in->cfg = *cfg; })
#define set_bridge_config_COPY_OUT ({ (void)0; })
#define set_bridge_config_CALL (in->br_index, &in->cfg)
#if 0
int CTL_get_port_state(int br_index, int port_index,
UID_STP_PORT_CFG_T * cfg, UID_STP_PORT_STATE_T * state);
#endif
#define CMD_CODE_get_port_state 104
#define get_port_state_ARGS (int br_index, int port_index, UID_STP_PORT_CFG_T *cfg, UID_STP_PORT_STATE_T *state)
struct get_port_state_IN {
int br_index;
int port_index;
};
struct get_port_state_OUT {
UID_STP_PORT_CFG_T cfg;
UID_STP_PORT_STATE_T state;
};
#define get_port_state_COPY_IN \
({ in->br_index = br_index; in->port_index = port_index; })
#define get_port_state_COPY_OUT ({ *cfg = out->cfg; *state = out->state; })
#define get_port_state_CALL (in->br_index, in->port_index, &out->cfg, &out->state)
#if 0
int CTL_set_port_config(int br_index, int port_index, UID_STP_PORT_CFG_T * cfg);
#endif
#define CMD_CODE_set_port_config 105
#define set_port_config_ARGS (int br_index, int port_index, UID_STP_PORT_CFG_T *cfg)
struct set_port_config_IN {
int br_index;
int port_index;
UID_STP_PORT_CFG_T cfg;
};
struct set_port_config_OUT {
};
#define set_port_config_COPY_IN \
({ in->br_index = br_index; in->port_index = port_index; in->cfg = *cfg; })
#define set_port_config_COPY_OUT ({ (void)0; })
#define set_port_config_CALL (in->br_index, in->port_index, &in->cfg)
#if 0
int CTL_set_debug_level(int level);
#endif
#define CMD_CODE_set_debug_level 106
#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)
/* General case part in ctl command server switch */
#define SERVER_MESSAGE_CASE(name) \
case CMD_CODE_ ## name : do { \
if (0) LOG("CTL command " #name); \
struct name ## _IN in0, *in = &in0; \
struct name ## _OUT out0, *out = &out0; \
if (sizeof(*in) != lin || sizeof(*out) != (outbuf?*lout:0)) { \
LOG("Bad sizes lin %d != %zd or lout %d != %zd", \
lin, sizeof(*in), lout?*lout:0, 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) \
int CTL_ ## name name ## _ARGS \
{ \
struct name ## _IN in0, *in=&in0; \
struct name ## _OUT out0, *out = &out0; \
int l = sizeof(*out); \
name ## _COPY_IN; \
int res = 0; \
int r = send_ctl_message(CMD_CODE_ ## name, in, sizeof(*in), out, &l, \
&res); \
if (r || res) LOG("Got return code %d, %d", r, res); \
if (r) return r; \
if (res) return res; \
name ## _COPY_OUT; \
return r; \
}
#endif