]>
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; | |
37 | int res; | |
ad02a0eb SH |
38 | }; |
39 | ||
40 | #define set_socket_address(sa, string) \ | |
41 | do {\ | |
42 | (sa)->sun_family = AF_UNIX; \ | |
43 | memset((sa)->sun_path, 0, sizeof((sa)->sun_path)); \ | |
44 | strcpy((sa)->sun_path + 1, (string)); \ | |
45 | } while (0) | |
46 | ||
47 | #define RSTP_SERVER_SOCK_NAME ".rstp_server" | |
48 | ||
49 | /* COMMANDS */ | |
50 | ||
51 | #if 0 | |
52 | int CTL_enable_bridge_rstp(int br_index, int enable); | |
53 | #endif | |
54 | #define CMD_CODE_enable_bridge_rstp 101 | |
55 | #define enable_bridge_rstp_ARGS (int br_index, int enable) | |
11904a35 SH |
56 | struct enable_bridge_rstp_IN { |
57 | int br_index; | |
58 | int enable; | |
59 | }; | |
60 | struct enable_bridge_rstp_OUT { | |
61 | }; | |
ad02a0eb SH |
62 | #define enable_bridge_rstp_COPY_IN \ |
63 | ({ in->br_index = br_index; in->enable = enable; }) | |
64 | #define enable_bridge_rstp_COPY_OUT ({ (void)0; }) | |
65 | #define enable_bridge_rstp_CALL (in->br_index, in->enable) | |
66 | ||
67 | #if 0 | |
68 | int CTL_get_bridge_state(int br_index, | |
11904a35 | 69 | UID_STP_CFG_T * cfg, UID_STP_STATE_T * state); |
ad02a0eb SH |
70 | #endif |
71 | #define CMD_CODE_get_bridge_state 102 | |
72 | #define get_bridge_state_ARGS (int br_index, UID_STP_CFG_T *cfg, UID_STP_STATE_T *state) | |
11904a35 SH |
73 | struct get_bridge_state_IN { |
74 | int br_index; | |
75 | }; | |
76 | struct get_bridge_state_OUT { | |
77 | UID_STP_CFG_T cfg; | |
78 | UID_STP_STATE_T state; | |
79 | }; | |
ad02a0eb SH |
80 | #define get_bridge_state_COPY_IN \ |
81 | ({ in->br_index = br_index; }) | |
82 | #define get_bridge_state_COPY_OUT ({ *cfg = out->cfg; *state = out->state; }) | |
83 | #define get_bridge_state_CALL (in->br_index, &out->cfg, &out->state) | |
84 | ||
85 | #if 0 | |
11904a35 | 86 | int CTL_set_bridge_config(int br_index, UID_STP_CFG_T * cfg); |
ad02a0eb SH |
87 | #endif |
88 | #define CMD_CODE_set_bridge_config 103 | |
89 | #define set_bridge_config_ARGS (int br_index, UID_STP_CFG_T *cfg) | |
11904a35 SH |
90 | struct set_bridge_config_IN { |
91 | int br_index; | |
92 | UID_STP_CFG_T cfg; | |
93 | }; | |
94 | struct set_bridge_config_OUT { | |
95 | }; | |
ad02a0eb SH |
96 | #define set_bridge_config_COPY_IN \ |
97 | ({ in->br_index = br_index; in->cfg = *cfg; }) | |
98 | #define set_bridge_config_COPY_OUT ({ (void)0; }) | |
99 | #define set_bridge_config_CALL (in->br_index, &in->cfg) | |
100 | ||
101 | #if 0 | |
102 | int CTL_get_port_state(int br_index, int port_index, | |
11904a35 | 103 | UID_STP_PORT_CFG_T * cfg, UID_STP_PORT_STATE_T * state); |
ad02a0eb SH |
104 | #endif |
105 | #define CMD_CODE_get_port_state 104 | |
106 | #define get_port_state_ARGS (int br_index, int port_index, UID_STP_PORT_CFG_T *cfg, UID_STP_PORT_STATE_T *state) | |
11904a35 SH |
107 | struct get_port_state_IN { |
108 | int br_index; | |
109 | int port_index; | |
110 | }; | |
111 | struct get_port_state_OUT { | |
112 | UID_STP_PORT_CFG_T cfg; | |
113 | UID_STP_PORT_STATE_T state; | |
114 | }; | |
ad02a0eb SH |
115 | #define get_port_state_COPY_IN \ |
116 | ({ in->br_index = br_index; in->port_index = port_index; }) | |
117 | #define get_port_state_COPY_OUT ({ *cfg = out->cfg; *state = out->state; }) | |
118 | #define get_port_state_CALL (in->br_index, in->port_index, &out->cfg, &out->state) | |
119 | ||
120 | #if 0 | |
11904a35 | 121 | int CTL_set_port_config(int br_index, int port_index, UID_STP_PORT_CFG_T * cfg); |
ad02a0eb SH |
122 | #endif |
123 | #define CMD_CODE_set_port_config 105 | |
124 | #define set_port_config_ARGS (int br_index, int port_index, UID_STP_PORT_CFG_T *cfg) | |
11904a35 SH |
125 | struct set_port_config_IN { |
126 | int br_index; | |
127 | int port_index; | |
128 | UID_STP_PORT_CFG_T cfg; | |
129 | }; | |
130 | struct set_port_config_OUT { | |
131 | }; | |
ad02a0eb SH |
132 | #define set_port_config_COPY_IN \ |
133 | ({ in->br_index = br_index; in->port_index = port_index; in->cfg = *cfg; }) | |
134 | #define set_port_config_COPY_OUT ({ (void)0; }) | |
135 | #define set_port_config_CALL (in->br_index, in->port_index, &in->cfg) | |
136 | ||
ad02a0eb SH |
137 | #if 0 |
138 | int CTL_set_debug_level(int level); | |
139 | #endif | |
140 | #define CMD_CODE_set_debug_level 106 | |
141 | #define set_debug_level_ARGS (int level) | |
11904a35 SH |
142 | struct set_debug_level_IN { |
143 | int level; | |
144 | }; | |
145 | struct set_debug_level_OUT { | |
146 | }; | |
ad02a0eb SH |
147 | #define set_debug_level_COPY_IN \ |
148 | ({ in->level = level; }) | |
149 | #define set_debug_level_COPY_OUT ({ (void)0; }) | |
150 | #define set_debug_level_CALL (in->level) | |
151 | ||
152 | /* General case part in ctl command server switch */ | |
153 | #define SERVER_MESSAGE_CASE(name) \ | |
154 | case CMD_CODE_ ## name : do { \ | |
155 | if (0) LOG("CTL command " #name); \ | |
156 | struct name ## _IN in0, *in = &in0; \ | |
157 | struct name ## _OUT out0, *out = &out0; \ | |
158 | if (sizeof(*in) != lin || sizeof(*out) != (outbuf?*lout:0)) { \ | |
159 | LOG("Bad sizes lin %d != %zd or lout %d != %zd", \ | |
160 | lin, sizeof(*in), lout?*lout:0, sizeof(*out)); \ | |
161 | return -1; \ | |
162 | } \ | |
163 | memcpy(in, inbuf, lin); \ | |
164 | int r = CTL_ ## name name ## _CALL; \ | |
165 | if (r) return r; \ | |
166 | if (outbuf) memcpy(outbuf, out, *lout); \ | |
167 | return r; \ | |
168 | } while (0) | |
169 | ||
170 | /* Wraper for the control functions in the control command client */ | |
171 | #define CLIENT_SIDE_FUNCTION(name) \ | |
172 | int CTL_ ## name name ## _ARGS \ | |
173 | { \ | |
174 | struct name ## _IN in0, *in=&in0; \ | |
175 | struct name ## _OUT out0, *out = &out0; \ | |
176 | int l = sizeof(*out); \ | |
177 | name ## _COPY_IN; \ | |
178 | int res = 0; \ | |
179 | int r = send_ctl_message(CMD_CODE_ ## name, in, sizeof(*in), out, &l, \ | |
180 | &res); \ | |
181 | if (r || res) LOG("Got return code %d, %d", r, res); \ | |
182 | if (r) return r; \ | |
183 | if (res) return res; \ | |
184 | name ## _COPY_OUT; \ | |
185 | return r; \ | |
186 | } | |
187 | ||
ad02a0eb | 188 | #endif |