]> git.ipfire.org Git - people/ms/rstp.git/blob - ctl_socket.h
Merge remote-tracking branch 'upstream/master'
[people/ms/rstp.git] / ctl_socket.h
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
33 struct ctl_msg_hdr {
34 int cmd;
35 int lin;
36 int lout;
37 int llog;
38 int res;
39 };
40
41 #define LOG_STRING_LEN 256
42
43 typedef struct _log_string
44 {
45 char buf[LOG_STRING_LEN];
46 } LogString;
47
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)
64 struct enable_bridge_rstp_IN {
65 int br_index;
66 int enable;
67 };
68 struct enable_bridge_rstp_OUT {
69 };
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
76 int CTL_get_bridge_status(int br_index, STP_BridgeStatus *status);
77 #endif
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 {
81 int br_index;
82 };
83 struct get_bridge_status_OUT {
84 STP_BridgeStatus status;
85 };
86 #define get_bridge_status_COPY_IN \
87 ({ in->br_index = br_index; })
88 #define get_bridge_status_COPY_OUT ({ *status = out->status; })
89 #define get_bridge_status_CALL (in->br_index, &out->status)
90
91 #if 0
92 int CTL_set_bridge_config(int br_index, STP_BridgeConfig *cfg);
93 #endif
94 #define CMD_CODE_set_bridge_config 103
95 #define set_bridge_config_ARGS (int br_index, STP_BridgeConfig *cfg)
96 struct set_bridge_config_IN {
97 int br_index;
98 STP_BridgeConfig cfg;
99 };
100 struct set_bridge_config_OUT {
101 };
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
108 int CTL_get_port_status(int br_index, int port_index, STP_PortStatus *status);
109 #endif
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 {
113 int br_index;
114 int port_index;
115 };
116 struct get_port_status_OUT {
117 STP_PortStatus status;
118 };
119 #define get_port_status_COPY_IN \
120 ({ in->br_index = br_index; in->port_index = port_index; })
121 #define get_port_status_COPY_OUT ({ *status = out->status; })
122 #define get_port_status_CALL (in->br_index, in->port_index, &out->status)
123
124 #if 0
125 int CTL_set_port_config(int br_index, int port_index, STP_PortConfig *cfg);
126 #endif
127 #define CMD_CODE_set_port_config 105
128 #define set_port_config_ARGS (int br_index, int port_index, STP_PortConfig *cfg)
129 struct set_port_config_IN {
130 int br_index;
131 int port_index;
132 STP_PortConfig cfg;
133 };
134 struct set_port_config_OUT {
135 };
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
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
157 #if 0
158 int CTL_set_debug_level(int level);
159 #endif
160 #define CMD_CODE_set_debug_level 107
161 #define set_debug_level_ARGS (int level)
162 struct set_debug_level_IN {
163 int level;
164 };
165 struct set_debug_level_OUT {
166 };
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; \
178 if (sizeof(*in) != lin || sizeof(*out) != lout) { \
179 LOG("Bad sizes lin %d != %zd or lout %d != %zd", \
180 lin, sizeof(*in), lout, sizeof(*out)); \
181 return -1; \
182 } \
183 memcpy(in, inbuf, lin); \
184 int r = CTL_ ## name name ## _CALL; \
185 if (r) return r; \
186 if (outbuf) memcpy(outbuf, out, lout); \
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; \
196 name ## _COPY_IN; \
197 int res = 0; \
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); \
202 if (r) return r; \
203 if (res) return res; \
204 name ## _COPY_OUT; \
205 return 0; \
206 }
207
208 #endif