]>
Commit | Line | Data |
---|---|---|
ad02a0eb SH |
1 | /***************************************************************************** |
2 | Copyright (c) 2006 EMC Corporation. | |
3 | ||
4 | This program is free software; you can redistribute it and/or modify it | |
5 | under the terms of the GNU General Public License as published by the Free | |
6 | Software Foundation; either version 2 of the License, or (at your option) | |
7 | any later version. | |
8 | ||
9 | This program is distributed in the hope that it will be useful, but WITHOUT | |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
12 | more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License along with | |
15 | this program; if not, write to the Free Software Foundation, Inc., 59 | |
16 | Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
17 | ||
18 | The full GNU General Public License is included in this distribution in the | |
19 | file called LICENSE. | |
20 | ||
21 | Authors: Srinivas Aji <Aji_Srinivas@emc.com> | |
22 | ||
23 | ******************************************************************************/ | |
24 | ||
25 | #ifndef CTL_SOCKET_H | |
26 | #define CTL_SOCKET_H | |
27 | ||
28 | #include <sys/types.h> | |
29 | #include <string.h> | |
30 | ||
31 | #include "ctl_functions.h" | |
32 | ||
11904a35 SH |
33 | struct ctl_msg_hdr { |
34 | int cmd; | |
35 | int lin; | |
36 | int lout; | |
b600a2c3 | 37 | int llog; |
11904a35 | 38 | int res; |
ad02a0eb SH |
39 | }; |
40 | ||
b600a2c3 SA |
41 | #define LOG_STRING_LEN 256 |
42 | ||
43 | typedef struct _log_string | |
44 | { | |
45 | char buf[LOG_STRING_LEN]; | |
46 | } LogString; | |
47 | ||
ad02a0eb SH |
48 | #define set_socket_address(sa, string) \ |
49 | do {\ | |
50 | (sa)->sun_family = AF_UNIX; \ | |
51 | memset((sa)->sun_path, 0, sizeof((sa)->sun_path)); \ | |
52 | strcpy((sa)->sun_path + 1, (string)); \ | |
53 | } while (0) | |
54 | ||
55 | #define RSTP_SERVER_SOCK_NAME ".rstp_server" | |
56 | ||
57 | /* COMMANDS */ | |
58 | ||
59 | #if 0 | |
60 | int CTL_enable_bridge_rstp(int br_index, int enable); | |
61 | #endif | |
62 | #define CMD_CODE_enable_bridge_rstp 101 | |
63 | #define enable_bridge_rstp_ARGS (int br_index, int enable) | |
11904a35 SH |
64 | struct enable_bridge_rstp_IN { |
65 | int br_index; | |
66 | int enable; | |
67 | }; | |
68 | struct enable_bridge_rstp_OUT { | |
69 | }; | |
ad02a0eb SH |
70 | #define enable_bridge_rstp_COPY_IN \ |
71 | ({ in->br_index = br_index; in->enable = enable; }) | |
72 | #define enable_bridge_rstp_COPY_OUT ({ (void)0; }) | |
73 | #define enable_bridge_rstp_CALL (in->br_index, in->enable) | |
74 | ||
75 | #if 0 | |
b600a2c3 | 76 | int CTL_get_bridge_status(int br_index, STP_BridgeStatus *status); |
ad02a0eb | 77 | #endif |
b600a2c3 SA |
78 | #define CMD_CODE_get_bridge_status 102 |
79 | #define get_bridge_status_ARGS (int br_index, STP_BridgeStatus *status) | |
80 | struct get_bridge_status_IN { | |
11904a35 SH |
81 | int br_index; |
82 | }; | |
b600a2c3 SA |
83 | struct get_bridge_status_OUT { |
84 | STP_BridgeStatus status; | |
11904a35 | 85 | }; |
b600a2c3 | 86 | #define get_bridge_status_COPY_IN \ |
ad02a0eb | 87 | ({ in->br_index = br_index; }) |
b600a2c3 SA |
88 | #define get_bridge_status_COPY_OUT ({ *status = out->status; }) |
89 | #define get_bridge_status_CALL (in->br_index, &out->status) | |
ad02a0eb SH |
90 | |
91 | #if 0 | |
b600a2c3 | 92 | int CTL_set_bridge_config(int br_index, STP_BridgeConfig *cfg); |
ad02a0eb SH |
93 | #endif |
94 | #define CMD_CODE_set_bridge_config 103 | |
b600a2c3 | 95 | #define set_bridge_config_ARGS (int br_index, STP_BridgeConfig *cfg) |
11904a35 SH |
96 | struct set_bridge_config_IN { |
97 | int br_index; | |
b600a2c3 | 98 | STP_BridgeConfig cfg; |
11904a35 SH |
99 | }; |
100 | struct set_bridge_config_OUT { | |
101 | }; | |
ad02a0eb SH |
102 | #define set_bridge_config_COPY_IN \ |
103 | ({ in->br_index = br_index; in->cfg = *cfg; }) | |
104 | #define set_bridge_config_COPY_OUT ({ (void)0; }) | |
105 | #define set_bridge_config_CALL (in->br_index, &in->cfg) | |
106 | ||
107 | #if 0 | |
b600a2c3 | 108 | int CTL_get_port_status(int br_index, int port_index, STP_PortStatus *status); |
ad02a0eb | 109 | #endif |
b600a2c3 SA |
110 | #define CMD_CODE_get_port_status 104 |
111 | #define get_port_status_ARGS (int br_index, int port_index, STP_PortStatus *status) | |
112 | struct get_port_status_IN { | |
11904a35 SH |
113 | int br_index; |
114 | int port_index; | |
115 | }; | |
b600a2c3 SA |
116 | struct get_port_status_OUT { |
117 | STP_PortStatus status; | |
11904a35 | 118 | }; |
b600a2c3 | 119 | #define get_port_status_COPY_IN \ |
ad02a0eb | 120 | ({ in->br_index = br_index; in->port_index = port_index; }) |
b600a2c3 SA |
121 | #define get_port_status_COPY_OUT ({ *status = out->status; }) |
122 | #define get_port_status_CALL (in->br_index, in->port_index, &out->status) | |
ad02a0eb SH |
123 | |
124 | #if 0 | |
b600a2c3 | 125 | int CTL_set_port_config(int br_index, int port_index, STP_PortConfig *cfg); |
ad02a0eb SH |
126 | #endif |
127 | #define CMD_CODE_set_port_config 105 | |
b600a2c3 | 128 | #define set_port_config_ARGS (int br_index, int port_index, STP_PortConfig *cfg) |
11904a35 SH |
129 | struct set_port_config_IN { |
130 | int br_index; | |
131 | int port_index; | |
b600a2c3 | 132 | STP_PortConfig cfg; |
11904a35 SH |
133 | }; |
134 | struct set_port_config_OUT { | |
135 | }; | |
ad02a0eb SH |
136 | #define set_port_config_COPY_IN \ |
137 | ({ in->br_index = br_index; in->port_index = port_index; in->cfg = *cfg; }) | |
138 | #define set_port_config_COPY_OUT ({ (void)0; }) | |
139 | #define set_port_config_CALL (in->br_index, in->port_index, &in->cfg) | |
140 | ||
b600a2c3 SA |
141 | #if 0 |
142 | int CTL_port_mcheck(int br_index, int port_index); | |
143 | #endif | |
144 | #define CMD_CODE_port_mcheck 106 | |
145 | #define port_mcheck_ARGS (int br_index, int port_index) | |
146 | struct port_mcheck_IN { | |
147 | int br_index; | |
148 | int port_index; | |
149 | }; | |
150 | struct port_mcheck_OUT { | |
151 | }; | |
152 | #define port_mcheck_COPY_IN \ | |
153 | ({ in->br_index = br_index; in->port_index = port_index; }) | |
154 | #define port_mcheck_COPY_OUT ({ (void)0; }) | |
155 | #define port_mcheck_CALL (in->br_index, in->port_index) | |
156 | ||
ad02a0eb SH |
157 | #if 0 |
158 | int CTL_set_debug_level(int level); | |
159 | #endif | |
b600a2c3 | 160 | #define CMD_CODE_set_debug_level 107 |
ad02a0eb | 161 | #define set_debug_level_ARGS (int level) |
11904a35 SH |
162 | struct set_debug_level_IN { |
163 | int level; | |
164 | }; | |
165 | struct set_debug_level_OUT { | |
166 | }; | |
ad02a0eb SH |
167 | #define set_debug_level_COPY_IN \ |
168 | ({ in->level = level; }) | |
169 | #define set_debug_level_COPY_OUT ({ (void)0; }) | |
170 | #define set_debug_level_CALL (in->level) | |
171 | ||
172 | /* General case part in ctl command server switch */ | |
173 | #define SERVER_MESSAGE_CASE(name) \ | |
174 | case CMD_CODE_ ## name : do { \ | |
175 | if (0) LOG("CTL command " #name); \ | |
176 | struct name ## _IN in0, *in = &in0; \ | |
177 | struct name ## _OUT out0, *out = &out0; \ | |
b600a2c3 | 178 | if (sizeof(*in) != lin || sizeof(*out) != lout) { \ |
ad02a0eb | 179 | LOG("Bad sizes lin %d != %zd or lout %d != %zd", \ |
b600a2c3 | 180 | lin, sizeof(*in), lout, sizeof(*out)); \ |
ad02a0eb SH |
181 | return -1; \ |
182 | } \ | |
183 | memcpy(in, inbuf, lin); \ | |
184 | int r = CTL_ ## name name ## _CALL; \ | |
185 | if (r) return r; \ | |
b600a2c3 | 186 | if (outbuf) memcpy(outbuf, out, lout); \ |
ad02a0eb SH |
187 | return r; \ |
188 | } while (0) | |
189 | ||
190 | /* Wraper for the control functions in the control command client */ | |
191 | #define CLIENT_SIDE_FUNCTION(name) \ | |
192 | int CTL_ ## name name ## _ARGS \ | |
193 | { \ | |
194 | struct name ## _IN in0, *in=&in0; \ | |
195 | struct name ## _OUT out0, *out = &out0; \ | |
ad02a0eb SH |
196 | name ## _COPY_IN; \ |
197 | int res = 0; \ | |
b600a2c3 SA |
198 | LogString log = { .buf = "" }; \ |
199 | int r = send_ctl_message(CMD_CODE_ ## name, in, sizeof(*in), \ | |
200 | out, sizeof(*out), &log, &res); \ | |
201 | if (r || res) LOG("Got return code %d, %d\n%s", r, res, log.buf); \ | |
ad02a0eb SH |
202 | if (r) return r; \ |
203 | if (res) return res; \ | |
204 | name ## _COPY_OUT; \ | |
b600a2c3 | 205 | return 0; \ |
ad02a0eb SH |
206 | } |
207 | ||
ad02a0eb | 208 | #endif |